From 86f521d5a07e0722ee604eb1c46b259ef219a3f0 Mon Sep 17 00:00:00 2001 From: guybedford Date: Mon, 17 Dec 2018 18:16:22 +0200 Subject: [PATCH 1/2] exclude js assets in directory emission, fixup core assets error --- scripts/build.js | 9 ++++----- src/loaders/relocate-loader.js | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index bb24629d..63aaa57b 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -44,18 +44,17 @@ async function main() { require.resolve("source-map-support/register") ); + // detect unexpected asset emissions from core build if ( Object.keys(cliAssets).length || - Object.keys(indexAssets).length || + Object.keys(indexAssets).some(asset => !asset.startsWith('locales/')) || Object.keys(nodeLoaderAssets).length || Object.keys(relocateLoaderAssets).length || Object.keys(shebangLoaderAssets).length || - Object.keys(tsLoaderAssets).length || + Object.keys(tsLoaderAssets).some(asset => !asset.startsWith('lib/')) || Object.keys(sourcemapAssets).length ) { - console.error( - "Assets emitted by core build, these need to be written into the dist directory" - ); + console.error("New assets are being emitted by the core build"); } writeFileSync(__dirname + "/../dist/ncc/cli.js", cli); diff --git a/src/loaders/relocate-loader.js b/src/loaders/relocate-loader.js index c8d3340c..556e346f 100644 --- a/src/loaders/relocate-loader.js +++ b/src/loaders/relocate-loader.js @@ -267,8 +267,8 @@ module.exports = function (code) { glob(assetDirPath + '/**/*', { mark: true, ignore: 'node_modules/**/*' }, (err, files) => err ? reject(err) : resolve(files)) ); await Promise.all(files.map(async file => { - // dont emit empty directories - if (file.endsWith('/')) + // dont emit empty directories or ".js" files + if (file.endsWith('/') || file.endsWith('.js')) return; const source = await new Promise((resolve, reject) => fs.readFile(file, (err, source) => err ? reject(err) : resolve(source)) From d3be145808384a46489180ab9427ed8c3408cb9d Mon Sep 17 00:00:00 2001 From: guybedford Date: Mon, 17 Dec 2018 18:25:52 +0200 Subject: [PATCH 2/2] disable loopback test --- test/index.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index 650ce90d..a8a29fa1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -56,6 +56,10 @@ function clearDir (dir) { for (const integrationTest of fs.readdirSync(__dirname + "/integration")) { // ignore e.g.: `.json` files if (!/\.(mjs|tsx?|js)$/.test(integrationTest)) continue; + + // disabled pending https://github.com/zeit/ncc/issues/141 + if (integrationTest.endsWith('loopback.js')) continue; + it(`should evaluate ${integrationTest} without errors`, async () => { const { code, map, assets } = await ncc( __dirname + "/integration/" + integrationTest,