Skip to content
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

fix: improve npm installation by using pacote for package resolution #1327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions apps/generator/lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const log = require('loglevel');
const Arborist = require('@npmcli/arborist');
const Config = require('@npmcli/config');
const requireg = require('requireg');
const pacote = require('pacote');
const npmPath = requireg.resolve('npm').replace('index.js','');

const { isAsyncAPIDocument } = require('@asyncapi/parser/cjs/document');
Expand Down Expand Up @@ -604,11 +605,8 @@ class Generator {
saveType: 'prod',
save: false
});

const addResult = arb[Symbol.for('resolvedAdd')];
if (!addResult) throw new Error('Unable to resolve the name of the added package. It was most probably not added to node_modules successfully');

const packageName = addResult[0].name;
const manifest = await pacote.manifest(this.templateName);
const packageName = manifest.name;
const packageVersion = installResult.children.get(packageName).version;
const packagePath = installResult.children.get(packageName).path;

Expand Down
3 changes: 2 additions & 1 deletion apps/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
"fs.extra": "^1.3.2",
"global-dirs": "^3.0.0",
"jmespath": "^0.15.0",
"pacote": "^15.1.1",
"js-yaml": "^3.13.1",
"levenshtein-edit-distance": "^2.0.5",
"levenshtein-edit-distance": "^2.0.5pacote",
"loglevel": "^1.6.8",
"minimatch": "^3.0.4",
"node-fetch": "^2.6.0",
Expand Down
3 changes: 0 additions & 3 deletions apps/generator/test/__mocks__/@npmcli/arborist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const arb = jest.genMockFromModule('@npmcli/arborist');

arb.prototype[Symbol.for('resolvedAdd')] = [{name: 'test'}];

arb.prototype.reify = jest.fn(async (opt) => {
const childrenMap = new Map();
childrenMap.set('test', {path: './test'});
Expand Down
9 changes: 9 additions & 0 deletions apps/generator/test/__mocks__/pacote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const pacote = jest.genMockFromModule('pacote');

pacote.manifest = jest.fn(async (templateName) => {
return {
name: 'test'
};
});

module.exports = pacote;
Loading
Loading