Skip to content

Commit 52a4d3b

Browse files
committed
Add in file check to make sure all entry points have equivalent files in ./npm folder.
Fail the build if any equivalent missing.
1 parent d044250 commit 52a4d3b

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

scripts/rollup/packaging.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const join = require('path').join;
66
const resolve = require('path').resolve;
77
const Bundles = require('./bundles');
88
const asyncCopyTo = require('./utils').asyncCopyTo;
9+
const glob = require('glob');
910

1011
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
1112
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
@@ -170,27 +171,35 @@ function copyNodePackageTemplate(packageName) {
170171
const whitelistedFiles = fs.existsSync(packageJson)
171172
? require(packageJson).files
172173
: null;
173-
if (whitelistedFiles && whitelistedFiles.length > 0) {
174-
const npmFiles = fs.readdirSync(npmFrom);
175-
const whitelistedNpmFiles = npmFiles.filter(file => {
176-
return (
177-
whitelistedFiles.includes(file) || whitelistedFiles.includes(`${file}/`)
178-
);
179-
});
180-
let whitelistedNpmFilesProxies = [];
181-
if (whitelistedNpmFiles.length > 0) {
182-
whitelistedNpmFilesProxies = whitelistedNpmFiles.reduce(
183-
(proxies, file) => {
184-
proxies.push(
185-
asyncCopyTo(resolve(`${npmFrom}/${file}`), `${to}/${file}`)
186-
);
187-
return proxies;
188-
},
189-
whitelistedNpmFilesProxies
174+
const npmRootFiles = fs.readdirSync(npmFrom);
175+
const packageRootEntries = glob.sync('*.js', {
176+
cwd: from,
177+
});
178+
packageRootEntries.forEach(entry => {
179+
// Terminate the build if any entry point in the package root does not have an equivalent in ./npm.
180+
// Exceptions: *.fb.js
181+
if (!npmRootFiles.includes(entry) && !/.fb.js$/.test(entry)) {
182+
console.error(
183+
`Entry point ${entry} in package ${packageName} does not have an equivalent in ./npm`
190184
);
185+
process.exit(1);
191186
}
187+
});
188+
if (whitelistedFiles && whitelistedFiles.length > 0) {
189+
let asyncCopyProxies = [];
190+
asyncCopyProxies = npmRootFiles.reduce((proxies, file) => {
191+
if (
192+
whitelistedFiles.includes(file) ||
193+
whitelistedFiles.includes(`${file}/`)
194+
) {
195+
proxies.push(
196+
asyncCopyTo(resolve(`${npmFrom}/${file}`), `${to}/${file}`)
197+
);
198+
}
199+
return proxies;
200+
}, asyncCopyProxies);
192201
return Promise.all([
193-
...whitelistedNpmFilesProxies,
202+
...asyncCopyProxies,
194203
asyncCopyTo(resolve(`${from}/package.json`), `${to}/package.json`),
195204
asyncCopyTo(resolve(`${from}/README.md`), `${to}/README.md`),
196205
asyncCopyTo(resolve('./LICENSE'), `${to}/LICENSE`),

0 commit comments

Comments
 (0)