Skip to content

Commit

Permalink
support scoped pacakges close ubilabs#9
Browse files Browse the repository at this point in the history
  • Loading branch information
givanse committed Feb 15, 2019
1 parent 1d6ecde commit 0bacaf9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ const path = require('path'),
format: 'markdown'
};

function getPackageJsonPath(contextArray) {
const nodeModulesIndex = contextArray.indexOf('node_modules');
const moduleRootFolder = contextArray[nodeModulesIndex + 1];
const offset = moduleRootFolder.match(/^@/) ?
3 : // it is a scoped module
2; // it is a regular module
contextArray.splice(nodeModulesIndex + offset);

const context = contextArray.join(path.sep);
const packageJsonFile = path.join(context, 'package.json');

return packageJsonFile;
}

function ExportNodeModules(options) {
this.options = Object.assign({}, defaultOptions, options);
}
Expand All @@ -33,9 +47,7 @@ ExportNodeModules.prototype.apply = function(compiler) {

contextArray.splice(contextArray.indexOf('node_modules') + 2);

let context = contextArray.join(path.sep),
npmModule = contextArray[contextArray.indexOf('node_modules') + 1],
packageJsonFile = path.join(context, 'package.json'),
const packageJsonFile = getPackageJsonPath(contextArray),
packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'UTF-8'));

npmModules.set(packageJson.name, {
Expand Down

0 comments on commit 0bacaf9

Please sign in to comment.