Skip to content

Commit

Permalink
fix: When packaging do not crash on deps with no package.json (#7368)
Browse files Browse the repository at this point in the history
  • Loading branch information
darko1979 committed Feb 24, 2020
1 parent 2c71c06 commit 8518000
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions lib/plugins/package/lib/zipService.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,31 @@ function excludeNodeDevDependencies(servicePath) {
.filter(item => item.length > 0 && item.match(nodeModulesRegex))
.reduce((globs, item) => {
const packagePath = path.join(servicePath, item, 'package.json');
return fs.readFileAsync(packagePath, 'utf-8').then(packageJsonFile => {
const lastIndex = item.lastIndexOf(path.sep) + 1;
const moduleName = item.substr(lastIndex);
const modulePath = item.substr(0, lastIndex);

const packageJson = JSON.parse(packageJsonFile);
const bin = packageJson.bin;

const baseGlobs = [path.join(item, '**')];

// NOTE: pkg.bin can be object, string, or undefined
if (typeof bin === 'object') {
_.each(_.keys(bin), executable => {
baseGlobs.push(path.join(modulePath, '.bin', executable));
});
// only 1 executable with same name as lib
} else if (typeof bin === 'string') {
baseGlobs.push(path.join(modulePath, '.bin', moduleName));
}

return globs.concat(baseGlobs);
});
return fs.readFileAsync(packagePath, 'utf-8').then(
packageJsonFile => {
const lastIndex = item.lastIndexOf(path.sep) + 1;
const moduleName = item.substr(lastIndex);
const modulePath = item.substr(0, lastIndex);

const packageJson = JSON.parse(packageJsonFile);
const bin = packageJson.bin;

const baseGlobs = [path.join(item, '**')];

// NOTE: pkg.bin can be object, string, or undefined
if (typeof bin === 'object') {
_.each(_.keys(bin), executable => {
baseGlobs.push(path.join(modulePath, '.bin', executable));
});
// only 1 executable with same name as lib
} else if (typeof bin === 'string') {
baseGlobs.push(path.join(modulePath, '.bin', moduleName));
}

return globs.concat(baseGlobs);
},
() => globs
);
}, [])
.then(globs => {
exAndIn.exclude = exAndIn.exclude.concat(globs);
Expand Down

0 comments on commit 8518000

Please sign in to comment.