@enhance/arc-plugin-rollup
Advanced tools
Comparing version 1.0.5 to 1.1.0
{ | ||
"name": "@enhance/arc-plugin-rollup", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Use rollup.js to bundle pages for the browser in your Enhance project", | ||
@@ -14,3 +14,3 @@ "main": "src/index.js", | ||
"lint": "eslint src test --fix", | ||
"test": "tape test/test.js | tap-arc" | ||
"test": "tape test/**/*test.js | tap-arc" | ||
}, | ||
@@ -34,6 +34,18 @@ "repository": { | ||
"@architect/sandbox": "^5.4.1", | ||
"eslint": "^8.32.0", | ||
"tap-arc": "^0.3.5", | ||
"tape": "^5.6.1", | ||
"tiny-json-http": "^7.4.2" | ||
}, | ||
"eslintConfig": { | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"ignorePatterns": [], | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"ecmaVersion": 2022 | ||
} | ||
} | ||
} |
@@ -5,2 +5,3 @@ const { join } = require('path') | ||
const { rollup } = require('rollup') | ||
const { loadConfigFile } = require('rollup/loadConfigFile'); | ||
const resolve = require('@rollup/plugin-node-resolve') | ||
@@ -33,11 +34,8 @@ | ||
const bundle = await rollup({ | ||
input: inFile, | ||
plugins: [resolve()] | ||
}) | ||
await bundle.write({ | ||
file: outFile, | ||
format: 'es' | ||
}) | ||
const rollupFile = join(cwd, 'rollup.config.js') | ||
if(existsSync(rollupFile)) { | ||
await externalRollup(rollupFile, inFile, outFile); | ||
} else { | ||
await internalRollup(inFile, outFile); | ||
} | ||
} | ||
@@ -47,2 +45,49 @@ } | ||
const internalRollup = async (inFile, outFile) => { | ||
const bundle = await rollup({ | ||
input: inFile, | ||
plugins: [resolve()] | ||
}) | ||
await bundle.write({ | ||
file: outFile, | ||
format: 'es' | ||
}) | ||
} | ||
const externalRollup = async (rollupFile, inFile, outFile) => { | ||
let rollUpConfig = {} | ||
let grab = memoize(loadConfigFile) | ||
const { options, warnings } = await grab(rollupFile) | ||
if(!warnings?.count) { | ||
rollUpConfig = options | ||
} | ||
//eslint-disable-next-line no-undef | ||
await Promise.all(rollUpConfig.map(async config => { | ||
config.input = inFile | ||
config.plugins = [resolve()] | ||
const bundle = await rollup(config) | ||
config.output.forEach(o => { | ||
o.file = outFile | ||
o.format = 'es' | ||
}) | ||
//eslint-disable-next-line no-undef | ||
await Promise.all(config.output.map(bundle.write)) | ||
})) | ||
} | ||
const memoize = (fn) => { | ||
let cache = {}; | ||
return async (obj) => { | ||
if(obj in cache) { | ||
return cache[obj] | ||
} else { | ||
cache[obj] = await fn(obj) | ||
return cache[obj] | ||
} | ||
} | ||
} | ||
module.exports = { | ||
@@ -49,0 +94,0 @@ sandbox: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15226
98
5