-
-
Notifications
You must be signed in to change notification settings - Fork 197
Install karma peer dependencies on test init
#2693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3299f82
0e89909
55f9806
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,25 @@ class TestInitCommand implements ICommand { | |
'save-dev': true, | ||
optional: false, | ||
}); | ||
|
||
const modulePath = path.join(projectDir, "node_modules", mod); | ||
const modulePackageJsonPath = path.join(modulePath, "package.json"); | ||
const modulePackageJsonContent = this.$fs.readJson(modulePackageJsonPath); | ||
const modulePeerDependencies = modulePackageJsonContent.peerDependencies || {}; | ||
|
||
for (let peerDependency in modulePeerDependencies) { | ||
let dependencyVersion = modulePeerDependencies[peerDependency] || "*"; | ||
|
||
// catch errors when a peerDependency is already installed | ||
// e.g karma is installed; karma-jasmine depends on karma and will try to install it again | ||
try { | ||
await this.$npm.install(`${peerDependency}@${dependencyVersion}`, projectDir, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have the dependencyVersion in quotes, so that it works for dependencies defined like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly adding quotes actually confused the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the |
||
'save-dev': true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we want to save it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand your point. Testing frameworks should be installed as devDependencies so they are not included in built projects, but so that they may still be installed subsequently, for example after removing node_modules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can disregard this. I didn't see the reason to duplicate them from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because otherwise the next time you decide to reinstall node_modules you would have to run |
||
}); | ||
} catch (e) { | ||
this.$logger.error(e.message); | ||
} | ||
} | ||
} | ||
|
||
await this.$pluginsService.add('nativescript-unit-test-runner', this.$projectData); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's already installed, why would it fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node-package-manager's install() that I used will fail the build - https://github.com/NativeScript/nativescript-cli/blob/master/lib/node-package-manager.ts#L78
I am unaware why that check is performed, even though the npm package is installed anyway at an earlier point - https://github.com/NativeScript/nativescript-cli/blob/master/lib/node-package-manager.ts#L42.
@rosen-vladimirov can you say what the reasons for that are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure why there's an error there. Maybe it should be just warning. The code there is trying to find the name of the installed package based on the difference in package.json before installing the package and after that. In case the package is already installed, there will be no difference in package.json, so we are unable to determine the real name of the installed package (in case you are installing from github url or tarball, you do not know the real name of the package).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the comment says, in case the dependency
karma
is already installed, the current implementation will reinstall it, but it may also change its version, which I do not think is expected. For example in case I have installedkarma
:1.6.0
, but the karma-jasmine has peerDependency:"karma":"~0.9"
, I'll end-up with the version~0.9
. Can we skip the installation of dependencies in case we already have the same dependency installed.