@stacksjs/cloud 0.58.53 → 0.58.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -241
- package/package.json +4 -4
- package/src/cloud/aws-sdk-layer/nodejs/package-lock.json +6 -6
- package/src/cloud/aws-sdk-layer/nodejs/package.json +2 -2
- package/src/cloud/queue.ts +7 -6
- package/src/cloud/router-layer/nodejs/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/runtime/README.md +0 -116
- package/src/runtime/bootstrap +0 -3
- package/src/runtime/example/lambda.ts +0 -36
- package/src/runtime/runtime.ts +0 -830
- package/src/runtime/scripts/build-layer.ts +0 -104
- package/src/runtime/scripts/publish-layer.ts +0 -110
- package/src/runtime/server.ts +0 -39
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// HACK: https://github.com/oven-sh/bun/issues/2081
|
|
2
|
-
import { createReadStream, createWriteStream } from 'node:fs'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import { Command, Flags } from '@oclif/core'
|
|
5
|
-
import { path as p } from '@stacksjs/path'
|
|
6
|
-
import JSZip from 'jszip'
|
|
7
|
-
|
|
8
|
-
process.stdout.getWindowSize = () => [80, 80]
|
|
9
|
-
process.stderr.getWindowSize = () => [80, 80]
|
|
10
|
-
|
|
11
|
-
export class BuildCommand extends Command {
|
|
12
|
-
static summary = 'Build a custom Lambda layer for Stacks & Bun.'
|
|
13
|
-
|
|
14
|
-
static flags = {
|
|
15
|
-
arch: Flags.string({
|
|
16
|
-
description: 'The architecture type to support.',
|
|
17
|
-
options: ['x64', 'aarch64'],
|
|
18
|
-
default: 'aarch64',
|
|
19
|
-
}),
|
|
20
|
-
release: Flags.string({
|
|
21
|
-
description: 'The release of Bun to install.',
|
|
22
|
-
default: 'latest',
|
|
23
|
-
}),
|
|
24
|
-
url: Flags.string({
|
|
25
|
-
description: 'A custom URL to download Bun.',
|
|
26
|
-
exclusive: ['release'],
|
|
27
|
-
}),
|
|
28
|
-
output: Flags.file({
|
|
29
|
-
exists: false,
|
|
30
|
-
|
|
31
|
-
default: async () => ['bun-lambda-layer.zip'],
|
|
32
|
-
}),
|
|
33
|
-
layer: Flags.string({
|
|
34
|
-
description: 'The name of the Lambda layer.',
|
|
35
|
-
multiple: true,
|
|
36
|
-
default: ['stacks'],
|
|
37
|
-
}),
|
|
38
|
-
region: Flags.string({
|
|
39
|
-
description: 'The region to publish the layer.',
|
|
40
|
-
multiple: true,
|
|
41
|
-
default: [],
|
|
42
|
-
}),
|
|
43
|
-
public: Flags.boolean({
|
|
44
|
-
description: 'If the layer should be public.',
|
|
45
|
-
default: false,
|
|
46
|
-
}),
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async run() {
|
|
50
|
-
const result = await this.parse(BuildCommand)
|
|
51
|
-
const { flags } = result
|
|
52
|
-
this.debug('Options:', flags)
|
|
53
|
-
const { arch, release, url, output } = flags
|
|
54
|
-
const { href } = new URL(url ?? `https://bun.sh/download/${release}/linux/${arch}?avx2=true`)
|
|
55
|
-
this.log('Downloading...', href)
|
|
56
|
-
const response = await fetch(href, {
|
|
57
|
-
headers: {
|
|
58
|
-
'User-Agent': 'stacks-lambda',
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
if (response.url !== href)
|
|
62
|
-
this.debug('Redirected URL:', response.url)
|
|
63
|
-
|
|
64
|
-
this.debug('Response:', response.status, response.statusText)
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
const reason = await response.text()
|
|
67
|
-
this.error(reason, { exit: 1 })
|
|
68
|
-
}
|
|
69
|
-
this.log('Extracting...')
|
|
70
|
-
const buffer = await response.arrayBuffer()
|
|
71
|
-
let archive
|
|
72
|
-
try {
|
|
73
|
-
archive = await JSZip.loadAsync(buffer)
|
|
74
|
-
}
|
|
75
|
-
catch (cause) {
|
|
76
|
-
this.debug(cause)
|
|
77
|
-
this.error('Failed to unzip file:', { exit: 1 })
|
|
78
|
-
}
|
|
79
|
-
this.debug('Extracted archive:', Object.keys(archive.files))
|
|
80
|
-
const bun = archive.filter((_, { dir, name }) => !dir && name.endsWith('bun'))[0]
|
|
81
|
-
if (!bun)
|
|
82
|
-
this.error('Failed to find executable in zip', { exit: 1 })
|
|
83
|
-
|
|
84
|
-
const cwd = bun.name.split('/')[0]
|
|
85
|
-
archive = archive.folder(cwd) ?? archive
|
|
86
|
-
for (const filename of ['bootstrap', 'runtime.ts']) {
|
|
87
|
-
const path = p.join(__dirname, '..', filename)
|
|
88
|
-
archive.file(filename, createReadStream(path))
|
|
89
|
-
}
|
|
90
|
-
this.log('Saving...', output)
|
|
91
|
-
archive
|
|
92
|
-
.generateNodeStream({
|
|
93
|
-
streamFiles: true,
|
|
94
|
-
compression: 'DEFLATE',
|
|
95
|
-
compressionOptions: {
|
|
96
|
-
level: 9,
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
.pipe(createWriteStream(p.projectStoragePath(`framework/cloud/${output}`)))
|
|
100
|
-
this.log('Saved')
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
await BuildCommand.run(process.argv.slice(2))
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process'
|
|
2
|
-
import process from 'node:process'
|
|
3
|
-
import { BuildCommand } from './build-layer'
|
|
4
|
-
|
|
5
|
-
export class PublishCommand extends BuildCommand {
|
|
6
|
-
static summary = 'Publish a custom Lambda layer for Bun.'
|
|
7
|
-
|
|
8
|
-
#aws(args: string[]): string {
|
|
9
|
-
this.debug('$', 'aws', ...args)
|
|
10
|
-
const { status, stdout, stderr } = spawnSync('aws', args, {
|
|
11
|
-
stdio: 'pipe',
|
|
12
|
-
})
|
|
13
|
-
const result = stdout.toString('utf-8').trim()
|
|
14
|
-
if (status === 0)
|
|
15
|
-
return result
|
|
16
|
-
|
|
17
|
-
const reason = stderr.toString('utf-8').trim() || result
|
|
18
|
-
throw new Error(`aws ${args.join(' ')} exited with ${status}: ${reason}`)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async run() {
|
|
22
|
-
const { flags } = await this.parse(PublishCommand)
|
|
23
|
-
this.debug('Options:', flags)
|
|
24
|
-
try {
|
|
25
|
-
const version = this.#aws(['--version'])
|
|
26
|
-
this.debug('AWS CLI:', version)
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
this.debug(error)
|
|
30
|
-
this.error(
|
|
31
|
-
'Install the `aws` CLI to continue: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html',
|
|
32
|
-
{ exit: 1 },
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
const { layer, region, arch, output, public: _isPublic } = flags
|
|
36
|
-
if (region.includes('*')) {
|
|
37
|
-
// prettier-ignore
|
|
38
|
-
const result = this.#aws([
|
|
39
|
-
'ec2',
|
|
40
|
-
'describe-regions',
|
|
41
|
-
'--query',
|
|
42
|
-
'Regions[].RegionName',
|
|
43
|
-
'--output',
|
|
44
|
-
'json',
|
|
45
|
-
])
|
|
46
|
-
region.length = 0
|
|
47
|
-
for (const name of JSON.parse(result))
|
|
48
|
-
region.push(name)
|
|
49
|
-
}
|
|
50
|
-
else if (!region.length) {
|
|
51
|
-
// prettier-ignore
|
|
52
|
-
region.push(this.#aws([
|
|
53
|
-
'configure',
|
|
54
|
-
'get',
|
|
55
|
-
'region',
|
|
56
|
-
]))
|
|
57
|
-
}
|
|
58
|
-
this.log('Publishing...')
|
|
59
|
-
for (const regionName of region) {
|
|
60
|
-
for (const layerName of layer) {
|
|
61
|
-
// prettier-ignore
|
|
62
|
-
const result = this.#aws([
|
|
63
|
-
'lambda',
|
|
64
|
-
'publish-layer-version',
|
|
65
|
-
'--layer-name',
|
|
66
|
-
layerName,
|
|
67
|
-
'--region',
|
|
68
|
-
regionName,
|
|
69
|
-
'--description',
|
|
70
|
-
'Bun is an incredibly fast JavaScript runtime, bundler, transpiler, and package manager.',
|
|
71
|
-
'--license-info',
|
|
72
|
-
'MIT',
|
|
73
|
-
'--compatible-architectures',
|
|
74
|
-
arch === 'x64' ? 'x86_64' : 'arm64',
|
|
75
|
-
'--compatible-runtimes',
|
|
76
|
-
'provided.al2',
|
|
77
|
-
'provided',
|
|
78
|
-
'--zip-file',
|
|
79
|
-
`fileb://${output}`,
|
|
80
|
-
'--output',
|
|
81
|
-
'json',
|
|
82
|
-
])
|
|
83
|
-
const { LayerVersionArn } = JSON.parse(result)
|
|
84
|
-
this.log('Published', LayerVersionArn)
|
|
85
|
-
// if (isPublic) {
|
|
86
|
-
// prettier-ignore
|
|
87
|
-
this.#aws([
|
|
88
|
-
'lambda',
|
|
89
|
-
'add-layer-version-permission',
|
|
90
|
-
'--layer-name',
|
|
91
|
-
layerName,
|
|
92
|
-
'--region',
|
|
93
|
-
regionName,
|
|
94
|
-
'--version-number',
|
|
95
|
-
LayerVersionArn.split(':').pop(),
|
|
96
|
-
'--statement-id',
|
|
97
|
-
`${layerName}-public`,
|
|
98
|
-
'--action',
|
|
99
|
-
'lambda:GetLayerVersion',
|
|
100
|
-
'--principal',
|
|
101
|
-
'*',
|
|
102
|
-
])
|
|
103
|
-
// }
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
this.log('Done')
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
await PublishCommand.run(process.argv.slice(2))
|
package/src/runtime/server.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Server } from 'bun'
|
|
2
|
-
import { serverResponse } from '@stacksjs/router'
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
async fetch(request: Request, server: Server): Promise<Response | undefined> {
|
|
6
|
-
// eslint-disable-next-line no-console
|
|
7
|
-
console.log('Request', {
|
|
8
|
-
url: request.url,
|
|
9
|
-
method: request.method,
|
|
10
|
-
headers: request.headers.toJSON(),
|
|
11
|
-
body: request.body ? await request.text() : null,
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
if (server.upgrade(request)) {
|
|
15
|
-
// eslint-disable-next-line no-console
|
|
16
|
-
console.log('WebSocket upgraded')
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return serverResponse(request)
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
websocket: {
|
|
24
|
-
// async open(ws: ServerWebSocket): Promise<void> {
|
|
25
|
-
// // eslint-disable-next-line no-console
|
|
26
|
-
// console.log('WebSocket opened')
|
|
27
|
-
// },
|
|
28
|
-
|
|
29
|
-
// async message(ws: ServerWebSocket, message: string): Promise<void> {
|
|
30
|
-
// // eslint-disable-next-line no-console
|
|
31
|
-
// console.log('WebSocket message', message)
|
|
32
|
-
// },
|
|
33
|
-
|
|
34
|
-
// async close(ws: ServerWebSocket, code: number, reason?: string): Promise<void> {
|
|
35
|
-
// // eslint-disable-next-line no-console
|
|
36
|
-
// console.log('WebSocket closed', { code, reason })
|
|
37
|
-
// },
|
|
38
|
-
},
|
|
39
|
-
}
|