Skip to content

Commit

Permalink
Update: Add support for "//" comments in package.json dependencies (#…
Browse files Browse the repository at this point in the history
…3829)

**Summary**
Fixes #2484. Adds support for the `"//"` package in package.json, by deleting it before we resolve the dependencies.

**Test plan**

Adds a new integration test.
  • Loading branch information
jseminck authored and BYK committed Jul 6, 2017
1 parent ad1a4f5 commit fc6fb65
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __tests__/commands/install/integration.js
Expand Up @@ -471,6 +471,12 @@ test.concurrent('install should run install scripts in the order of dependencies
});
});

test.concurrent('install with comments in manifest', (): Promise<void> => {
return runInstall({noLockfile: true}, 'install-with-comments', async config => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js'))).toEqual('foobar;\n');
});
});

test.concurrent('run install scripts in the order when one dependency does not have install script', (): Promise<
void,
> => {
Expand Down
@@ -0,0 +1 @@
foobar;
@@ -0,0 +1,5 @@
{
"name": "bar",
"version": "0.0.0",
"main": "index.js"
}
10 changes: 10 additions & 0 deletions __tests__/fixtures/install/install-with-comments/package.json
@@ -0,0 +1,10 @@
{
"dependencies": {
"//": [
"This is a",
"multiline",
"comment"
],
"foo": "file:bar"
}
}
4 changes: 4 additions & 0 deletions __tests__/fixtures/install/install-with-comments/yarn.lock
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"foo@file:bar":
version "0.0.0"
7 changes: 7 additions & 0 deletions src/cli/commands/install.js
Expand Up @@ -227,6 +227,13 @@ export class Install {

this.rootManifestRegistries.push(registry);
const projectManifestJson = await this.config.readJson(loc);

['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'].forEach(dependencyKey => {
if (projectManifestJson[dependencyKey]) {
delete projectManifestJson[dependencyKey]['//'];
}
});

await normalizeManifest(projectManifestJson, this.config.cwd, this.config, true);

Object.assign(this.resolutions, projectManifestJson.resolutions);
Expand Down

0 comments on commit fc6fb65

Please sign in to comment.