Socket
Socket
Sign inDemoInstall

@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.0.5 to 4.1.0

16

changelog.md

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

## [4.1.0] 2022-09-06
### Added
- Added support for creating ESM (or CJS) handlers
### Changed
- Default to writing ESM handlers
- Only install Architect if project doesn't already have it installed
- Create handler files when the actual file is missing, not just when the folder is absent
- Updated dependencies
---
## [4.0.5] 2022-07-26

@@ -7,0 +23,0 @@

8

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

@@ -26,3 +26,3 @@ "main": "src/index.js",

"dependencies": {
"@architect/inventory": "~3.2.0",
"@architect/inventory": "~3.3.0",
"@architect/utils": "~3.1.2",

@@ -36,3 +36,3 @@ "chalk": "4.1.2",

"cross-env": "~7.0.3",
"eslint": "~8.21.0",
"eslint": "~8.23.0",
"fs-extra": "~10.1.0",

@@ -42,3 +42,3 @@ "nyc": "~15.1.0",

"tap-arc": "^0.3.5",
"tape": "~5.5.3"
"tape": "~5.6.0"
},

@@ -45,0 +45,0 @@ "eslintConfig": {

@@ -1,2 +0,4 @@

let spawn = require('child_process').spawn
let { join } = require('path')
let { existsSync, readFileSync } = require('fs')
let { spawn } = require('child_process')

@@ -9,2 +11,10 @@ /**

let canceled = false
let pkgFile = join(cwd, 'package.json')
if (existsSync(pkgFile)) {
let pkg = JSON.parse(readFileSync(pkgFile))
let arc = '@architect/architect'
if (pkg.dependencies[arc] || pkg.devDependencies[arc]) return callback()
}
update.start('Installing Architect...')

@@ -11,0 +21,0 @@

@@ -89,5 +89,2 @@ let { sep } = require('path')

// These are the boilerplate-enabled pragmas
let pragmas = [ 'http', 'events', 'queues', 'scheduled', 'static', 'tables-streams', 'ws', 'customLambdas' ]
// Re-seed the inventory since we may now have a new manifest

@@ -97,3 +94,3 @@ inventory = await _inventory({ cwd: folder })

// Create dirs (and necessary config.arc files) that do not yet exist
let dirs = writeConfigs({ ...params, pragmas, inventory })
let dirs = writeConfigs({ ...params, inventory })

@@ -100,0 +97,0 @@ if (dirs.length) {

@@ -6,3 +6,3 @@ let { join } = require('path')

module.exports = function writeArcConfigs (params) {
let { pragmas, inventory, update } = params
let { inventory, update } = params
let { inv } = inventory

@@ -21,29 +21,29 @@ let createRuntime = params.runtime // What the user requested, if anything

let dirs = []
pragmas.forEach(pragma => {
if (inv[pragma] && pragma !== 'static') {
inv[pragma].forEach(item => {
let { name, config, src } = item
if (!inv.lambdaSrcDirs.length) return dirs
// 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
Object.values(inv.lambdasBySrcDir).forEach(lambda => {
let { name, config, handlerFile, src, pragma } = lambda
if (existsSync(src)) 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
// 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 (existsSync(handlerFile)) 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}

@@ -54,6 +54,4 @@ # memory 1152

`
writeFileSync(configPath, arcConfig)
}
}
})
writeFileSync(configPath, arcConfig)
}
}

@@ -60,0 +58,0 @@ })

let learn = 'learn more about event functions here: https://arc.codes/events'
let node = `// ${learn}
exports.handler = async function subscribe (event) {
let nodeBody = `
console.log(JSON.stringify(event, null, 2))
return
}`
`
let node = {
esm: `// ${learn}
export async function handler (event) {${nodeBody}}`,
cjs: `// ${learn}
exports.handler = async function subscribe (event) {${nodeBody}}`
}

@@ -9,0 +14,0 @@ let deno = `// ${learn}

@@ -88,4 +88,3 @@ let learn = 'learn more about HTTP functions here: https://arc.codes/http'

let node = path => `// ${learn}
exports.handler = async function http (req) {
let nodeBody = path => `
return {

@@ -99,3 +98,9 @@ statusCode: 200,

}
}`
`
let node = {
esm: path => `// ${learn}
export async function handler (req) {${nodeBody(path)}}`,
cjs: path => `// ${learn}
exports.handler = async function http (req) {${nodeBody(path)}}`
}

@@ -102,0 +107,0 @@ let ruby = path => `# ${learn}

let learn = 'learn more about queue functions here: https://arc.codes/queues'
let node = `// ${learn}
exports.handler = async function queue (event) {
let nodeBody = `
console.log(JSON.stringify(event, null, 2))
return
}`
`
let node = {
esm: `// ${learn}
export async function handler (event) {${nodeBody}}`,
cjs: `// ${learn}
exports.handler = async function queue (event) {${nodeBody}}`
}
let deno = `// ${learn}

@@ -10,0 +16,0 @@ export async function handler (event: object) {

let learn = 'learn more about scheduled functions here: https://arc.codes/scheduled'
let node = `// ${learn}
exports.handler = async function scheduled (event) {
let nodeBody = `
console.log(JSON.stringify(event, null, 2))
return
}`
`
let node = {
esm: `// ${learn}
export async function handler (event) {${nodeBody}}`,
cjs: `// ${learn}
exports.handler = async function scheduled (event) {${nodeBody}}`
}

@@ -9,0 +14,0 @@ let deno = `// ${learn}

let learn = 'learn more about DynamoDB table stream functions here: https://arc.codes/tables-streams'
let node = `// ${learn}
exports.handler = async function table (event) {
let nodeBody = `
console.log(JSON.stringify(event, null, 2))
return
}`
`
let node = {
esm: `// ${learn}
export async function handler (event) {${nodeBody}}`,
cjs: `// ${learn}
exports.handler = async function tableStream (event) {${nodeBody}}`
}

@@ -9,0 +14,0 @@ let deno = `// ${learn}

let learn = 'learn more about WebSocket functions here: https://arc.codes/ws'
let node = `// ${learn}
exports.handler = async function ws (req) {
let nodeBody = `
console.log(JSON.stringify(req, null, 2))
return {statusCode: 200}
}`
return { statusCode: 200 }
`
let node = {
esm: `// ${learn}
export async function handler (req) {${nodeBody}}`,
cjs: `// ${learn}
exports.handler = async function ws (req) {${nodeBody}}`
}

@@ -9,0 +14,0 @@ let deno = `// ${learn}

@@ -12,3 +12,3 @@ let { sep } = require('path')

module.exports = function writeCode (lambda) {
let { src, build, handlerFile, pragma, config, body } = lambda
let { src, build, handlerFile, handlerModuleSystem, pragma, config, body } = lambda
let { runtime, runtimeConfig } = config

@@ -34,6 +34,13 @@

let types = { http, events, queues, ws, scheduled, 'tables-streams': tablesStreams, customLambdas: events }
if (!body) body = pragma === 'http'
? types[pragma][run](handler)
: types[pragma][run]
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)
}
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