From a485d882d4614807637dc0ba48af580efcfe4b65 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 6 Sep 2022 12:17:27 +0200 Subject: [PATCH] feat: use systemjs property in package.json to control build output --- commands/build/lib/build.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/commands/build/lib/build.js b/commands/build/lib/build.js index 915107950..d571dbe06 100644 --- a/commands/build/lib/build.js +++ b/commands/build/lib/build.js @@ -80,6 +80,8 @@ const config = ({ getExternal = getExternalDefault, getOutputFile = getOutputFileDefault, getOutputName = getOutputNameDefault, + // Return false if no build should be done, otherwise true + enabled = () => true, } = {}, } = {}) => { const CWD = argv.cwd || cwd; @@ -99,7 +101,7 @@ const config = ({ dir = core; } - if (format === 'esm' && !pkg.module) { + if (!enabled({ pkg })) { return false; } const outputFile = getOutputFile({ pkg, config: argv }); @@ -203,6 +205,7 @@ const esm = async (argv, core) => { core, behaviours: { getOutputFile: ({ pkg }) => pkg.module, + enabled: ({ pkg }) => !!pkg.module, }, }); if (!c) { @@ -224,13 +227,14 @@ const systemjs = async (argv, core) => { const { external = [] } = cfg.systemjs || {}; return mergeArray(defaultExternal, external); }, - getOutputFile: ({ config: cfg }) => { - const { outputFile = 'systemjs/index.js' } = cfg.systemjs || {}; - return outputFile; - }, + getOutputFile: ({ pkg }) => pkg.systemjs, getOutputName: () => undefined, + enabled: ({ pkg }) => !!pkg.systemjs, }, }); + if (!c) { + return Promise.resolve(); + } const bundle = await rollup.rollup(c.input); return bundle.write(c.output); };