Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@architect/plugin-bundles

Package Overview
Dependencies
Maintainers
6
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/plugin-bundles - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0-RC.0

20

package.json
{
"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 @@ },

@@ -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
}
}
},
},
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc