Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ module.exports = class LicensePlugin {
* @return {void}
*/
scanDependency(id) {
this.debug(`scanning ${id}`);
if (id.startsWith('\0')) {
id = id.replace(/^\0/, '');
this.debug(`scanning internal module ${id}`);
} else {
this.debug(`scanning ${id}`);
}

// Look for the `package.json` file
let dir = path.parse(id).dir;
Expand Down
29 changes: 29 additions & 0 deletions test/license-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,35 @@ describe('LicensePlugin', () => {
});
});

it('should try to load pkg without leading NULL character ', () => {
const plugin = new LicensePlugin();
const fakePackage = path.join(__dirname, 'fixtures', 'fake-package');
const idNoNull = path.join(fakePackage, 'src', 'index.js');
const id = '\0' + idNoNull;
const pkg = require(path.join(fakePackage, 'package.json'));

plugin.scanDependency(id);

expect(plugin._dependencies).toEqual({
'fake-package': {
name: 'fake-package',
version: '1.0.0',
description: 'Fake package used in unit tests',
license: 'MIT',
private: true,
author: {
name: 'Mickael Jeanroy',
email: '[email protected]',
},
},
});

expect(plugin._cache).toEqual({
[path.join(__dirname, 'fixtures', 'fake-package', 'src')]: pkg,
[path.join(__dirname, 'fixtures', 'fake-package')]: pkg,
});
});

it('should load pkg and use the cache if available', () => {
const plugin = new LicensePlugin();
const fakePackage = path.join(__dirname, 'fixtures', 'fake-package');
Expand Down