@architect/plugin-bundles
Advanced tools
Comparing version 3.1.1 to 3.2.0-RC.0
{ | ||
"name": "@architect/plugin-bundles", | ||
"version": "3.1.1", | ||
"description": "plugin-bundles Plugin for exposing bundled modules to the browser from your Architect project.", | ||
"version": "3.2.0-RC.0", | ||
"description": "Architect plugin for exposing bundled modules to the browser from your Architect project.", | ||
"main": "src/index.js", | ||
@@ -14,3 +14,4 @@ "engines": { | ||
"lint": "eslint src test --fix", | ||
"test": "tape test/test.js | tap-arc" | ||
"tape": "tape test/test.js | tap-arc", | ||
"test": "npm run lint && npm run tape" | ||
}, | ||
@@ -21,3 +22,8 @@ "repository": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"Architect", | ||
"plugin", | ||
"bundles", | ||
"esbuild" | ||
], | ||
"author": "", | ||
@@ -30,3 +36,3 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"esbuild": "^0.15.7" | ||
"esbuild": "^0.15.8" | ||
}, | ||
@@ -37,5 +43,5 @@ "devDependencies": { | ||
"@architect/sandbox": "^5.3.4", | ||
"eslint": "^8.23.0", | ||
"eslint": "^8.23.1", | ||
"tap-arc": "^0.3.5", | ||
"tape": "^5.6.0", | ||
"tape": "^5.6.1", | ||
"tiny-json-http": "^7.4.2" | ||
@@ -42,0 +48,0 @@ }, |
153
src/index.js
@@ -5,2 +5,4 @@ const { existsSync } = require('fs') | ||
const CONFIG_FILENAME = 'esbuild.config.js' | ||
/** | ||
@@ -12,14 +14,8 @@ * @typedef BundlesConfig | ||
* @property {object} nameToPath output name to source path (w/o extension) | ||
* @property {object} esbuildConfig | ||
* @property {object | null} userConfig user provided esbuild config | ||
* @property {object | null} entryPoints bundle entry points, keyed by name | ||
*/ | ||
/** @type {BundlesConfig} */ | ||
const config = { | ||
paths: [], | ||
pathToName: {}, | ||
nameToPath: {}, | ||
esbuildConfig: {}, | ||
} | ||
async function createConfig (arc, inventory) { | ||
/** @return {BundlesConfig | null} */ | ||
function createConfig (arc, inventory) { | ||
/** @type {[[string, string]]} */ | ||
@@ -29,15 +25,22 @@ const entries = arc.bundles | ||
if (!entries) { return } | ||
if (!entries) { | ||
return null | ||
} | ||
const configPath = join(cwd, 'esbuild.config.js') | ||
/** @type {BundlesConfig} */ | ||
const config = { | ||
paths: [], | ||
pathToName: {}, | ||
nameToPath: {}, | ||
userConfig: null, | ||
entryPoints: null, | ||
} | ||
const configPath = join(cwd, CONFIG_FILENAME) | ||
if (existsSync(configPath)) { | ||
// eslint-disable-next-line global-require | ||
config.esbuildConfig = require(configPath) | ||
config.userConfig = require(configPath) | ||
} | ||
config.outDir = join( | ||
cwd, | ||
inventory.static?.folder || 'public', | ||
'bundles', | ||
) | ||
config.outDir = join(cwd, inventory.static?.folder || 'public', 'bundles') | ||
@@ -52,3 +55,5 @@ for (const entry of entries) { | ||
else if (typeof path !== 'string') { | ||
console.warn(` @bundles: invalid input path for "${name}": "${path}". Skipping.`) | ||
console.warn( | ||
` @bundles: invalid input path for "${name}": "${path}". Skipping.`, | ||
) | ||
} | ||
@@ -66,25 +71,50 @@ else { | ||
} | ||
return config | ||
} | ||
async function build (entryPoints) { | ||
await esbuild({ | ||
bundle: true, | ||
format: 'esm', | ||
target: 'es2022', | ||
platform: 'browser', | ||
outExtension: { '.js': '.mjs' }, | ||
external: [ 'fs', 'path' ], | ||
...config.esbuildConfig, // user config | ||
entryPoints, // do not allow entryPoints and outdir override | ||
outdir: config.outDir, | ||
}) | ||
/** @return {Promise<boolean | void>} */ | ||
async function build (config) { | ||
if (!config.entryPoints) { | ||
return | ||
} | ||
let success = false | ||
try { | ||
await esbuild({ | ||
bundle: true, | ||
format: 'esm', | ||
target: 'es2022', | ||
platform: 'browser', | ||
outExtension: { '.js': '.mjs' }, | ||
external: [ 'fs', 'path' ], | ||
...(config.userConfig || {}), | ||
entryPoints: config.entryPoints, // disallow override entryPoints and outdir | ||
outdir: config.outDir, | ||
}) | ||
success = true | ||
} | ||
catch (_error) { | ||
success = false | ||
} | ||
return success | ||
} | ||
async function buildAll () { | ||
if (!config.outDir) { return } | ||
/** @return {Promise<boolean | void>} */ | ||
async function buildAll (config) { | ||
if (config.userConfig) { | ||
console.log(` @bundles: Imported settings from ${CONFIG_FILENAME}.`) | ||
} | ||
await build(config.nameToPath) | ||
config.entryPoints = config.nameToPath | ||
const success = await build(config) | ||
const plural = config.paths.length > 1 ? 's' : '' | ||
console.log(` @bundles: built ${config.paths.length} file${plural}.`) | ||
if (success) { | ||
const plural = config.paths.length > 1 ? 's' : '' | ||
console.log(` @bundles: Bundled ${config.paths.length} file${plural}.`) | ||
} | ||
return success | ||
} | ||
@@ -94,31 +124,44 @@ | ||
sandbox: { | ||
async start ({ arc, inventory }) { | ||
await createConfig(arc, inventory.inv) | ||
async start ({ arc, inventory: { inv } }) { | ||
const config = createConfig(arc, inv) | ||
if (config.paths.length > 0){ | ||
await buildAll() | ||
console.log(` @bundles: watching ${config.paths.length} files...`) | ||
if (config && config.paths.length > 0) { | ||
const success = await buildAll(config) | ||
if (!success) { | ||
console.error(' @bundles: esbuild encountered an error.') | ||
} | ||
} | ||
}, | ||
async watcher ({ filename: path, event }) { | ||
if (config.outDir | ||
&& event === 'update' | ||
&& config.paths.includes(path) | ||
){ | ||
await build({ [config.pathToName[path]]: path }) | ||
console.log(` @bundles: rebuilt "${path.split('/').pop()}"`) | ||
async watcher ({ arc, filename: path, inventory: { inv } }) { | ||
const config = createConfig(arc, inv) | ||
if (config && config.paths.includes(path)) { | ||
config.entryPoints = { [config.pathToName[path]]: path } | ||
const success = await build(config) | ||
if (success) { | ||
console.log(` @bundles: Re-bundled "${path.split('/').pop()}"`) | ||
} | ||
else { | ||
console.error(' @bundles: esbuild encountered an error.') | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
deploy: { | ||
async start ({ arc, cloudformation, inventory }) { | ||
await createConfig(arc, inventory.inv) | ||
async start ({ arc, cloudformation, inventory: { inv } }) { | ||
const config = createConfig(arc, inv) | ||
if (config.paths.length > 0){ | ||
await buildAll() | ||
if (config && config.paths.length > 0) { | ||
const success = await buildAll(config) | ||
if (!success) { | ||
throw new Error('@bundles: esbuild encountered an error. Halting!') | ||
} | ||
} | ||
return cloudformation // always return cfn | ||
} | ||
} | ||
}, | ||
}, | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
17486
135
1
Updatedesbuild@^0.15.8