Skip to content

Commit

Permalink
feat: Use npmcli config in asyncapi generator (fix lint)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierrick BOULÉ committed Feb 14, 2024
1 parent 35eb66c commit 69925f3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
9 changes: 4 additions & 5 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const {
const { parse, usesNewAPI, getProperApiDocument } = require('./parser');
const { registerFilters } = require('./filtersRegistry');
const { registerHooks } = require('./hooksRegistry');
const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions')
const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions');

const FILTERS_DIRNAME = 'filters';
const HOOKS_DIRNAME = 'hooks';
Expand Down Expand Up @@ -550,7 +550,6 @@ class Generator {
log.debug(`Using npm registry ${registryUrl} and authorization type ${authorizationName} to handle template installation.`);
}


/**
* Downloads and installs a template and its dependencies
*
Expand Down Expand Up @@ -591,13 +590,13 @@ class Generator {
flatten,
shorthands,
npmPath
})
});

await config.load()
await config.load();

const arbOptions = {...{path: ROOT_DIR}, ...config.flat};

if (!(Object.keys(this.registry).length === 0)) {
if (Object.keys(this.registry).length !== 0) {
this.initialiseArbOptions(arbOptions);
}
const arb = new Arborist(arbOptions);
Expand Down
9 changes: 0 additions & 9 deletions test/__mocks__/@npmcli/config.js

This file was deleted.

6 changes: 1 addition & 5 deletions test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,11 @@ describe('Generator', () => {
describe('#installTemplate', () => {
let ArboristMock;
let arboristMock;
let ConfigMock;
let configMock;
let utils;

beforeEach(() => {
ArboristMock = require('@npmcli/arborist');
arboristMock = new ArboristMock();
ConfigMock = require('@npmcli/arborist');
configMock = new ConfigMock();
utils = require('../lib/utils');
jest.mock(path.resolve('./testTemplate', 'package.json'), () => ({ name: 'nameOfTestTemplate' }), { virtual: true });
jest.mock(path.resolve(Generator.DEFAULT_TEMPLATES_DIR, 'nameOfTestTemplate', 'package.json'), () => ({ name: 'nameOfTestTemplate' }), { virtual: true });
Expand Down Expand Up @@ -432,7 +428,7 @@ describe('Generator', () => {
const t = () => new Generator('testTemplate', __dirname, {
url: 'some.url.com',
privateKey: 'some.key'

});
expect(t).toThrow('These options are not supported by the generator: privateKey');
});
Expand Down

0 comments on commit 69925f3

Please sign in to comment.