Skip to content

Commit

Permalink
Reduce asset emission and handle unexpected core assets (#166)
Browse files Browse the repository at this point in the history
* exclude js assets in directory emission, fixup core assets error

* disable loopback test
  • Loading branch information
guybedford authored and rauchg committed Dec 17, 2018
1 parent 4ab1f82 commit b83e921
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 4 additions & 5 deletions scripts/build.js
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/loaders/relocate-loader.js
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions test/index.test.js
Expand Up @@ -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,
Expand Down

0 comments on commit b83e921

Please sign in to comment.