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

@architect/create

Package Overview
Dependencies
Maintainers
6
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/create - npm Package Compare versions

Comparing version 4.2.0 to 4.2.1

8

changelog.md

@@ -5,2 +5,10 @@ # Architect Create changelog

## [4.2.1] 2023-06-21
### Fixed
- Fixed resource creation in projects with multi-tenant Lambdae; fixes #1432, thanks @andybee!
---
## [4.2.0] 2023-04-10

@@ -7,0 +15,0 @@

2

package.json
{
"name": "@architect/create",
"version": "4.2.0",
"version": "4.2.1",
"description": "Idempotently initialize Architect projects",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -22,30 +22,33 @@ let { join } = require('path')

Object.values(inv.lambdasBySrcDir).forEach(lambda => {
let { name, config, handlerFile, src, pragma } = lambda
Object.values(inv.lambdasBySrcDir).forEach(lambdae => {
if (!Array.isArray(lambdae)) lambdae = [ lambdae ] // Normalize possible multi-tenant Lambdas
// Lambda's runtime isn't yet fully reified, but may inherit its runtime from project manifest
// So don't trust it, but maybe also trust it
let lambdaRuntime = config.runtimeAlias || config.runtime
let runtimeType = config?.runtimeConfig?.type
lambdae.forEach(lambda => {
let { name, config, handlerFile, src, pragma } = lambda
if ((!runtimeType || runtimeType === 'interpreted') && existsSync(handlerFile)) return
// Don't try to (re)create handlers because the handlerFile isn't there; that may just mean it hasn't been compiled yet
else if (runtimeType !== 'interpreted' && existsSync(src) && readdirSync(src).length) return
else if (skip) {
update.status(`Ignoring @${pragma} ${name}, runtime not supported: ${createRuntime || projectRuntime}`)
}
else {
mkdirSync(src, { recursive: true })
dirs.push({ pragma, src })
// Lambda's runtime isn't yet fully reified, but may inherit its runtime from project manifest
// So don't trust it, but maybe also trust it
let lambdaRuntime = config.runtimeAlias || config.runtime
let runtimeType = config?.runtimeConfig?.type
// Only write a config file if necessary; namely, its runtime differs from the project default:
// Create runtime specified differs from Lambda's inherited runtime or runtime alias
let createDiffers = createRuntime && (createRuntime !== lambdaRuntime)
// Project has a default runtime, and the create runtime differs from it
let projectAndCreateDiffer = projectRuntime && createRuntime && (createRuntime !== projectRuntime)
if ((!runtimeType || runtimeType === 'interpreted') && existsSync(handlerFile)) return
// Don't try to (re)create handlers because the handlerFile isn't there; that may just mean it hasn't been compiled yet
else if (runtimeType !== 'interpreted' && existsSync(src) && readdirSync(src).length) return
else if (skip) {
update.status(`Ignoring @${pragma} ${name}, runtime not supported: ${createRuntime || projectRuntime}`)
}
else {
mkdirSync(src, { recursive: true })
dirs.push({ pragma, src })
if (createDiffers || projectAndCreateDiffer) {
let runtime = createRuntime || config.runtimeAlias || config.runtime
let configPath = join(src, 'config.arc')
let arcConfig = `@aws
// Only write a config file if necessary; namely, its runtime differs from the project default:
// Create runtime specified differs from Lambda's inherited runtime or runtime alias
let createDiffers = createRuntime && (createRuntime !== lambdaRuntime)
// Project has a default runtime, and the create runtime differs from it
let projectAndCreateDiffer = projectRuntime && createRuntime && (createRuntime !== projectRuntime)
if (createDiffers || projectAndCreateDiffer) {
let runtime = createRuntime || config.runtimeAlias || config.runtime
let configPath = join(src, 'config.arc')
let arcConfig = `@aws
runtime ${runtime}

@@ -56,7 +59,8 @@ # memory 1152

`
writeFileSync(configPath, arcConfig)
writeFileSync(configPath, arcConfig)
}
}
}
})
})
return [ ...new Set(dirs) ].filter(Boolean)
}

@@ -12,11 +12,11 @@ let writeTemplate = require('./write-template')

let { pragma, src } = dir
let lambda = lambdasBySrcDir[src]
let lambdae = lambdasBySrcDir[src]
let template = templates?.[pragma]
if (template) {
writeTemplate(lambda, template)
writeTemplate(lambdae, template)
}
else {
await writeCode(lambda, inventory)
await writeCode(lambdae, inventory)
}
}
}

@@ -12,75 +12,78 @@ let { dirname, join, sep } = require('path')

module.exports = async function writeCode (lambda, inventory) {
module.exports = async function writeCode (lambdae, inventory) {
let { _project, plugins } = inventory.inv
let { src, build, handlerFile, handlerModuleSystem, config, body } = lambda
let { runtime, runtimeConfig } = config
let pragma = lambda.pragma || 'customLambdas' // Lambdas generated by via set.customLambdas plugins have a null pragma
if (!Array.isArray(lambdae)) lambdae = [ lambdae ] // Normalize possible multi-tenant Lambdas
for (let lambda of lambdae) {
let { src, build, handlerFile, handlerModuleSystem, config, body } = lambda
let { runtime, runtimeConfig } = config
let pragma = lambda.pragma || 'customLambdas' // Lambdas generated by via set.customLambdas plugins have a null pragma
let filepath = handlerFile
if (handlerFile.includes(build)) {
filepath = filepath.replace(build, src)
}
let filepath = handlerFile
if (handlerFile.includes(build)) {
filepath = filepath.replace(build, src)
}
let handler = filepath.replace(process.cwd(), '')
if (handler[0] === sep) handler = handler.substr(1)
let handler = filepath.replace(process.cwd(), '')
if (handler[0] === sep) handler = handler.substr(1)
// Create handlers for registered + custom runtimes
let registered = plugins?._methods?.create?.register?.find(r => {
// We find the exact specified runtime, easy
if (r.includes(runtime)) return true
// Otherwise, we have to search the array for aliased values that match the runtime, ew
return r.find(i => runtimes[aliases[i]]?.includes(runtime))
})
if (_project.customRuntimes?.runtimes?.includes(runtime) || registered) {
let runtimePlugin = _project.customRuntimes.runtimePlugins[runtime] || registered._plugin
let createMethod = plugins[runtimePlugin]?.create?.handlers
if (!createMethod) {
throw ReferenceError(`No create.handlers method found for custom runtime plugin '${runtime}' (${runtimePlugin})`)
}
// Make sure the handler directory exists should plugin authors be relying on it
mkdirSync(lambda.src, { recursive: true })
// Create handlers for registered + custom runtimes
let registered = plugins?._methods?.create?.register?.find(r => {
// We find the exact specified runtime, easy
if (r.includes(runtime)) return true
// Otherwise, we have to search the array for aliased values that match the runtime, ew
return r.find(i => runtimes[aliases[i]]?.includes(runtime))
})
if (_project.customRuntimes?.runtimes?.includes(runtime) || registered) {
let runtimePlugin = _project.customRuntimes.runtimePlugins[runtime] || registered._plugin
let createMethod = plugins[runtimePlugin]?.create?.handlers
if (!createMethod) {
throw ReferenceError(`No create.handlers method found for custom runtime plugin '${runtime}' (${runtimePlugin})`)
}
// Make sure the handler directory exists should plugin authors be relying on it
mkdirSync(lambda.src, { recursive: true })
let frozen = deepFrozenCopy(inventory)
let { arc } = frozen.inv._project
let args = { arc, inventory: frozen, lambda: deepFrozenCopy(lambda) }
let result = await createMethod(args)
if (result) {
let files = Array.isArray(result) ? result : [ result ]
for (let file of files) {
let { filename, body } = file
if (!filename || !body) throw ReferenceError(`Cannot create handler file without 'filename' and 'body' properties (${runtimePlugin})`)
let path = join(src, filename)
let dir = dirname(path)
// Don't assume they requested the file to be in the root of the handler, eh?
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true })
let frozen = deepFrozenCopy(inventory)
let { arc } = frozen.inv._project
let args = { arc, inventory: frozen, lambda: deepFrozenCopy(lambda) }
let result = await createMethod(args)
if (result) {
let files = Array.isArray(result) ? result : [ result ]
for (let file of files) {
let { filename, body } = file
if (!filename || !body) throw ReferenceError(`Cannot create handler file without 'filename' and 'body' properties (${runtimePlugin})`)
let path = join(src, filename)
let dir = dirname(path)
// Don't assume they requested the file to be in the root of the handler, eh?
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true })
}
writeFileSync(path, body)
}
writeFileSync(path, body)
}
}
}
// Create handlers for built-in runtimes
else {
let configuredRuntime = runtimeConfig?.baseRuntime || aliases[runtime] || runtime
let run
if (configuredRuntime.startsWith('deno')) run = 'deno'
if (configuredRuntime.startsWith('node')) run = 'node'
if (configuredRuntime.startsWith('python')) run = 'python'
if (configuredRuntime.startsWith('ruby')) run = 'ruby'
if (!run) throw ReferenceError(`Valid runtime not found: ${configuredRuntime}`)
// Create handlers for built-in runtimes
else {
let configuredRuntime = runtimeConfig?.baseRuntime || aliases[runtime] || runtime
let run
if (configuredRuntime.startsWith('deno')) run = 'deno'
if (configuredRuntime.startsWith('node')) run = 'node'
if (configuredRuntime.startsWith('python')) run = 'python'
if (configuredRuntime.startsWith('ruby')) run = 'ruby'
if (!run) throw ReferenceError(`Valid runtime not found: ${configuredRuntime}`)
let types = { http, events, queues, ws, scheduled, 'tables-streams': tablesStreams, customLambdas: events }
if (!body && pragma === 'http') {
body = handlerModuleSystem
? types[pragma][run][handlerModuleSystem](handler)
: types[pragma][run](handler)
let types = { http, events, queues, ws, scheduled, 'tables-streams': tablesStreams, customLambdas: events }
if (!body && pragma === 'http') {
body = handlerModuleSystem
? types[pragma][run][handlerModuleSystem](handler)
: types[pragma][run](handler)
}
else if (!body) {
body = handlerModuleSystem
? types[pragma][run][handlerModuleSystem]
: types[pragma][run]
}
writeFileSync(filepath, body)
}
else if (!body) {
body = handlerModuleSystem
? types[pragma][run][handlerModuleSystem]
: types[pragma][run]
}
writeFileSync(filepath, body)
}
}

@@ -5,18 +5,21 @@ let { existsSync, readFileSync, writeFileSync } = require('fs')

module.exports = function writeTemplate (lambda, template) {
let { src, build, handlerFile } = lambda
module.exports = function writeTemplate (lambdae, template) {
if (!Array.isArray(lambdae)) lambdae = [ lambdae ] // Normalize possible multi-tenant Lambdas
lambdae.forEach(lambda => {
let { src, build, handlerFile } = lambda
let filepath = handlerFile
if (handlerFile.includes(build)) {
filepath = filepath.replace(build, src)
}
let filepath = handlerFile
if (handlerFile.includes(build)) {
filepath = filepath.replace(build, src)
}
let path = template[0] === '~'
? join(homedir(), template.substr(1))
: resolve(template)
if (!existsSync(path)) {
throw Error(`Custom function template not found: ${template}`)
}
let body = readFileSync(path).toString()
writeFileSync(filepath, body)
let path = template[0] === '~'
? join(homedir(), template.substr(1))
: resolve(template)
if (!existsSync(path)) {
throw Error(`Custom function template not found: ${template}`)
}
let body = readFileSync(path).toString()
writeFileSync(filepath, body)
})
}
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