Skip to content

Commit

Permalink
Remove the else after the hard exit, make the code after unintended.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Tian committed Nov 13, 2017
1 parent e97dff1 commit 854373f
Showing 1 changed file with 40 additions and 42 deletions.
82 changes: 40 additions & 42 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,50 +192,48 @@ function copyNodePackageTemplate(packageName) {
`'files' field is missing from package.json in package ${packageName}`
);
process.exit(1);
} else {
// 'files' field exists in package.json,
fs.mkdirSync(to);
let existingDirCache = {};
// looping through entries(single file / directory / pattern) in `files`
const whitelistedFiles = whitelist.reduce((list, pattern) => {
const matchedFiles = glob.sync(pattern, {
cwd: npmFrom,
});
// copy matching files/directories from './npm' to build package.
matchedFiles.forEach(file => {
if (fs.lstatSync(`${npmFrom}/${file}`).isFile()) {
// copy source is a file, create all nesting directories ahead
// to avoid 'No such file or directory' error
const fileDirnameSegments = dirname(file).split('/');
fileDirnameSegments.reduce((prevPath, currentPath) => {
const fullPath = `${prevPath}/${currentPath}`;
if (!existingDirCache[fullPath] && !fs.existsSync(fullPath)) {
existingDirCache[fullPath] = true;
fs.mkdirSync(`${to}/${fullPath}`);
}
return fullPath;
}, '');
}
promisesForForwardingModules.push(
asyncCopyTo(`${npmFrom}/${file}`, `${to}/${file}`)
);
});
// return an array of whitelisted files
// for entry point check next.
// All patterns have been parsed to file/directory
return list.concat(matchedFiles);
}, []);
// terminate the build if any entry point(Exception: *.fb.js)
// is not whitelisted in the 'files' field in package.json.
packageEntries.forEach(entry => {
if (!whitelistedFiles.includes(entry)) {
console.error(
`Entry point ${entry} in package ${packageName} is not listed in the 'files' field in package.json`
);
process.exit(1);
}
fs.mkdirSync(to);
let existingDirCache = {};
// looping through entries(single file / directory / pattern) in `files`
const whitelistedFiles = whitelist.reduce((list, pattern) => {
const matchedFiles = glob.sync(pattern, {
cwd: npmFrom,
});
// copy matching files/directories from './npm' to build package.
matchedFiles.forEach(file => {
if (fs.lstatSync(`${npmFrom}/${file}`).isFile()) {
// copy source is a file, create all nesting directories ahead
// to avoid 'No such file or directory' error
const fileDirnameSegments = dirname(file).split('/');
fileDirnameSegments.reduce((prevPath, currentPath) => {
const fullPath = `${prevPath}/${currentPath}`;
if (!existingDirCache[fullPath] && !fs.existsSync(fullPath)) {
existingDirCache[fullPath] = true;
fs.mkdirSync(`${to}/${fullPath}`);
}
return fullPath;
}, '');
}
promisesForForwardingModules.push(
asyncCopyTo(`${npmFrom}/${file}`, `${to}/${file}`)
);
});
}
// return an array of whitelisted files
// for entry point check next.
// All patterns have been parsed to file/directory
return list.concat(matchedFiles);
}, []);
// terminate the build if any entry point(Exception: *.fb.js)
// is not whitelisted in the 'files' field in package.json.
packageEntries.forEach(entry => {
if (!whitelistedFiles.includes(entry)) {
console.error(
`Entry point ${entry} in package ${packageName} is not listed in the 'files' field in package.json`
);
process.exit(1);
}
});
return Promise.all([
...promisesForForwardingModules,
asyncCopyTo(resolve(`${from}/package.json`), `${to}/package.json`),
Expand Down

0 comments on commit 854373f

Please sign in to comment.