Skip to content

Commit

Permalink
fix: lockfile convert option (#466)
Browse files Browse the repository at this point in the history
> pick #465
  • Loading branch information
elrrrrrrr authored Sep 20, 2023
1 parent 6442f66 commit dee32a1
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 16 deletions.
4 changes: 3 additions & 1 deletion bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ debug('argv: %j, env: %j', argv, env);
if (lockfilePath) {
try {
const lockfileData = await fs.readFile(lockfilePath, 'utf8');
config.dependenciesTree = lockfileConverter(JSON.parse(lockfileData));
config.dependenciesTree = lockfileConverter(JSON.parse(lockfileData), {
ignoreOptionalDependencies: true,
});
} catch (error) {
console.warn(chalk.yellow('npminstall WARN load lockfile from %s error :%s'), lockfilePath, error.message);
}
Expand Down
185 changes: 174 additions & 11 deletions test/fixtures/lockfile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions test/fixtures/lockfile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"lodash.get": "3",
"lodash._baseget": "3.7.1",
"lodash._baseslice": "^3.0.1",
"lodash.has3": "npm:lodash.has@3"
}
}
"lodash.has3": "npm:lodash.has@3",
"chokidar": "^3"
},
"repository": "[email protected]:cnpm/npminstall.git"
}
3 changes: 2 additions & 1 deletion test/install-with-lockfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('test/install-with-lockfile.test.js', () => {
], { cwd })
.debug()
.expect('code', 0)
.notExpect('stdout', 'TypeError: Cannot read properties of undefined (reading \'ignoreOptionalDependencies\')')
.end();
assert.strictEqual(
await fs.readlink(path.join(cwd, 'node_modules', 'lodash.has3'), 'utf8'),
Expand All @@ -42,7 +43,7 @@ describe('test/install-with-lockfile.test.js', () => {
ignoreOptionalDependencies: true,
}, nested);

assert.strictEqual(Object.keys(dependenciesTree).length, 12);
assert.strictEqual(Object.keys(dependenciesTree).length, 29);
});
}
});

0 comments on commit dee32a1

Please sign in to comment.