Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce asset emission and handle unexpected core assets #166

Merged
merged 2 commits into from Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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