Skip to content

Commit

Permalink
Major: Change asset builds to opt-in with new option --asset-builds (
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Aug 27, 2021
1 parent d067202 commit 3015281
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Outputs the Node.js compact build of `input.js` into `dist/index.js`.
-m, --minify Minify output
-C, --no-cache Skip build cache population
-s, --source-map Generate source map
-a, --asset-builds Build nested JS assets recursively, useful for
when code is loaded as an asset eg for workers.
--no-source-map-register Skip source-map-register source map support
-e, --external [mod] Skip bundling 'mod'. Can be used many times
-q, --quiet Disable build summaries / non-error outputs
Expand Down Expand Up @@ -115,6 +117,7 @@ require('@vercel/ncc')('/path/to/input', {
filterAssetBase: process.cwd(), // default
minify: false, // default
sourceMap: false, // default
assetBuilds: false, // default
sourceMapBasePrefix: '../', // default treats sources as output-relative
// when outputting a sourcemap, automatically include
// source-map-support in the output file (increases output by 32kB).
Expand Down
4 changes: 3 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ async function runCmd (argv, stdout, stderr) {
let args;
try {
args = require("arg")({
"--asset-builds": Boolean,
'-a': '--asset-builds',
"--debug": Boolean,
"-d": "--debug",
"--external": [String],
Expand Down Expand Up @@ -240,7 +242,7 @@ async function runCmd (argv, stdout, stderr) {
externals: args["--external"],
sourceMap: args["--source-map"] || run,
sourceMapRegister: args["--no-source-map-register"] ? false : undefined,
noAssetBuilds: args["--no-asset-builds"] ? true : false,
assetBuilds: args["--asset-builds"] ? true : false,
cache: args["--no-cache"] ? false : undefined,
watch: args["--watch"],
v8cache: args["--v8-cache"],
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function ncc (
sourceMap = false,
sourceMapRegister = true,
sourceMapBasePrefix = '../',
noAssetBuilds = false,
assetBuilds = false,
watch = false,
v8cache = false,
filterAssetBase = process.cwd(),
Expand Down Expand Up @@ -564,7 +564,7 @@ function ncc (
}

// for each .js / .mjs / .cjs file in the asset list, build that file with ncc itself
if (!noAssetBuilds) {
if (assetBuilds) {
const compilation = compilationStack[compilationStack.length - 1];
let existingAssetNames = Object.keys(assets);
existingAssetNames.push(`${filename}${ext === '.cjs' ? '.js' : ''}`);
Expand Down Expand Up @@ -595,7 +595,7 @@ function ncc (
sourceMapBasePrefix,
// dont recursively asset build
// could be supported with seen tracking
noAssetBuilds: true,
assetBuilds: false,
v8cache,
filterAssetBase,
existingAssetNames,
Expand Down
6 changes: 3 additions & 3 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
expect: { code: 0 }
},
{
args: ["build", "test/fixtures/type-module/main.js", "-o", "tmp"],
args: ["build", "test/fixtures/type-module/main.js", "-a", "-o", "tmp"],
expect: { code: 0 }
},
{
Expand All @@ -22,7 +22,7 @@
}
},
{
args: ["run", "--v8-cache", "test/integration/test.ts"],
args: ["run", "--v8-cache", "-a", "test/integration/test.ts"],
expect: { code: 0 }
},
{
Expand All @@ -44,7 +44,7 @@
}
},
{
args: ["run", "--watch", "test/integration/test.ts"],
args: ["run", "--watch", "-a", "test/integration/test.ts"],
expect: { code: 2 }
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
const stdout = new StoreStream();
const stderr = new StoreStream();
try {
await nccRun(["run", "--no-cache", "--no-asset-builds", `${__dirname}/integration/${integrationTest}`], stdout, stderr);
await nccRun(["run", "--no-cache", `${__dirname}/integration/${integrationTest}`], stdout, stderr);
}
catch (e) {
if (e.silent) {
Expand Down
1 change: 1 addition & 0 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
// find the name of the input file (e.g input.ts)
const inputFile = fs.readdirSync(testDir).find(file => file.includes("input"));
await ncc(`${testDir}/${inputFile}`, Object.assign({
assetBuilds: true,
transpileOnly: true,
customEmit (path) {
if (path.endsWith('test.json'))
Expand Down
1 change: 1 addition & 0 deletions test/watcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ it('Should support custom watch API', async () => {

console.time('First Build');
const { handler, rebuild, close } = ncc(buildFile, {
assetBuilds: true,
watch: watcher
});

Expand Down

0 comments on commit 3015281

Please sign in to comment.