From b5caaa22f88b48add18d43ae04957130555a5549 Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Wed, 20 Sep 2023 15:27:43 +0800 Subject: [PATCH] fix: lockfile convert option --- bin/install.js | 4 +- test/fixtures/lockfile/package-lock.json | 185 +++++++++++++++++++++-- test/fixtures/lockfile/package.json | 8 +- test/install-with-lockfile.test.js | 3 +- 4 files changed, 184 insertions(+), 16 deletions(-) diff --git a/bin/install.js b/bin/install.js index dae6cd69..fc83679a 100755 --- a/bin/install.js +++ b/bin/install.js @@ -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); } diff --git a/test/fixtures/lockfile/package-lock.json b/test/fixtures/lockfile/package-lock.json index a79e1e77..37df0879 100644 --- a/test/fixtures/lockfile/package-lock.json +++ b/test/fixtures/lockfile/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "chokidar": "^3", "lodash._baseget": "3.7.1", "lodash._baseslice": "^3.0.1", "lodash.get": "3", @@ -12,19 +13,143 @@ "lodash.has3": "npm:lodash.has@3" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmmirror.com/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmmirror.com/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "engines": { + "node": ">=8" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmmirror.com/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmmirror.com/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmmirror.com/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmmirror.com/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmmirror.com/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmmirror.com/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmmirror.com/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/lodash._baseget": { "version": "3.7.1", - "resolved": "https://registry.npmjs.org/lodash._baseget/-/lodash._baseget-3.7.1.tgz", + "resolved": "https://registry.npmmirror.com/lodash._baseget/-/lodash._baseget-3.7.1.tgz", "integrity": "sha512-VFICYluEPRjeVlLDdg6tGNyYplqEC5aE3ZzN2mScC7aoD96mYYwzsalX8VLQFd7W0M9Vsp+JMp+TlDmIvVhXkA==" }, "node_modules/lodash._baseslice": { "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash._baseslice/-/lodash._baseslice-3.0.3.tgz", + "resolved": "https://registry.npmmirror.com/lodash._baseslice/-/lodash._baseslice-3.0.3.tgz", "integrity": "sha512-DkeB6ZDkxIAkBvfuaq4ZHE8vN/FW0tZxMERQxci1zP0oFH6xC1ogpebPNgANXSwwcpjZPDAGWd4EFyATAf7Nsw==" }, "node_modules/lodash._topath": { "version": "3.8.1", - "resolved": "https://registry.npmjs.org/lodash._topath/-/lodash._topath-3.8.1.tgz", + "resolved": "https://registry.npmmirror.com/lodash._topath/-/lodash._topath-3.8.1.tgz", "integrity": "sha512-QsF5c8A+Biv0oxuSCd05JqhXHPCjvFT0nMXVevfMgU1pp5iEHVSin2cKXi3lQe5+px285p7kAHVtOnbNE79syw==", "dependencies": { "lodash.isarray": "^3.0.0" @@ -32,7 +157,7 @@ }, "node_modules/lodash.get": { "version": "3.7.0", - "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-3.7.0.tgz", + "resolved": "https://registry.npmmirror.com/lodash.get/-/lodash.get-3.7.0.tgz", "integrity": "sha512-7iD0aRHu/B8gcCDNx53lJi33R4TzpbOB3Mfk4XpIN7WFUt+W5rI+6CtHhpJ52B6zhhRvogtuNSDFZc3xgcbClQ==", "dependencies": { "lodash._baseget": "^3.0.0", @@ -41,7 +166,7 @@ }, "node_modules/lodash.has": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.0.0.tgz", + "resolved": "https://registry.npmmirror.com/lodash.has/-/lodash.has-4.0.0.tgz", "integrity": "sha512-Xw3htH7ERWlsAkYbelC1I4ItQafDzLPP7h42GQjdxp4G7EyF7/gkEp1z3zGpw+6ceiKpDyq4lOX2dZqTk8qIfQ==", "dependencies": { "lodash._baseslice": "^4.0.0", @@ -50,18 +175,18 @@ }, "node_modules/lodash.has/node_modules/lodash._baseslice": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/lodash._baseslice/-/lodash._baseslice-4.0.0.tgz", + "resolved": "https://registry.npmmirror.com/lodash._baseslice/-/lodash._baseslice-4.0.0.tgz", "integrity": "sha512-gFMKGnEY/5cjMx2+x+yfKvrcm3w1PWWqUgWyo4r9xfTqVIaObWoTGoaIEp4ZWwEs/DQ3hoBzzW8W0Rus5+IcZw==" }, "node_modules/lodash.has/node_modules/lodash.get": { "version": "4.4.2", - "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "resolved": "https://registry.npmmirror.com/lodash.get/-/lodash.get-4.4.2.tgz", "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==" }, "node_modules/lodash.has3": { "name": "lodash.has", "version": "3.2.1", - "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-3.2.1.tgz", + "resolved": "https://registry.npmmirror.com/lodash.has/-/lodash.has-3.2.1.tgz", "integrity": "sha512-KL1Z/fbG2omhWTc90h1NzS/JDsW+/0rCfoBUQBIBZCRnaJxFwagpm/dtQppzstlXXVvRy9jqCWBxoyeAkFxsaw==", "dependencies": { "lodash._baseget": "^3.0.0", @@ -73,13 +198,51 @@ }, "node_modules/lodash.isarguments": { "version": "3.1.0", - "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", + "resolved": "https://registry.npmmirror.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", "integrity": "sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==" }, "node_modules/lodash.isarray": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", + "resolved": "https://registry.npmmirror.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz", "integrity": "sha512-JwObCrNJuT0Nnbuecmqr5DgtuBppuCvGD9lxjFpAzwnVtdGoDQ1zig+5W8k5/6Gcn0gZ3936HDAlGd28i7sOGQ==" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "engines": { + "node": ">=8.6" + } + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmmirror.com/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } } } -} \ No newline at end of file +} diff --git a/test/fixtures/lockfile/package.json b/test/fixtures/lockfile/package.json index adb92c6a..bbcecc04 100644 --- a/test/fixtures/lockfile/package.json +++ b/test/fixtures/lockfile/package.json @@ -4,6 +4,8 @@ "lodash.get": "3", "lodash._baseget": "3.7.1", "lodash._baseslice": "^3.0.1", - "lodash.has3": "npm:lodash.has@3" - } -} \ No newline at end of file + "lodash.has3": "npm:lodash.has@3", + "chokidar": "^3" + }, + "repository": "git@github.com:cnpm/npminstall.git" +} diff --git a/test/install-with-lockfile.test.js b/test/install-with-lockfile.test.js index fc626316..dcf0e383 100644 --- a/test/install-with-lockfile.test.js +++ b/test/install-with-lockfile.test.js @@ -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'), @@ -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); }); } });