diff options
author | Kai WU <kaiwu2004@gmail.com> | 2024-08-04 18:17:00 +0800 |
---|---|---|
committer | Kai WU <kaiwu2004@gmail.com> | 2024-08-04 18:17:00 +0800 |
commit | e65910c1489a43433c9bbb206c38bea6f781523e (patch) | |
tree | 286cd32a9f0f3d8a588b717597a35ca75e15e38f | |
parent | 0be38e2473f6b478b95d32075d947fba6268da6c (diff) | |
download | ngs-e65910c1489a43433c9bbb206c38bea6f781523e.tar.gz ngs-e65910c1489a43433c9bbb206c38bea6f781523e.zip |
swc to es5
-rw-r--r-- | gleam.toml | 2 | ||||
-rw-r--r-- | package-lock.json | 275 | ||||
-rw-r--r-- | package.json | 4 | ||||
-rw-r--r-- | src/ngs.gleam | 4 | ||||
-rw-r--r-- | src/ngs_ffi.mjs | 18 |
5 files changed, 295 insertions, 8 deletions
@@ -1,5 +1,5 @@ name = "ngs" -version = "0.1.0" +version = "1.0.0" target = "javascript" description = "Offload weight to nginx, implement HTTP server with gleam bindings to njs" diff --git a/package-lock.json b/package-lock.json index 9d5cf9e..f24a842 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,10 @@ "license": "MIT", "dependencies": { "esbuild": "^0.23.0" + }, + "devDependencies": { + "@swc/helpers": "^0.5.12", + "esbuild-plugin-es5": "^2.1.1" } }, "node_modules/@esbuild/aix-ppc64": { @@ -396,6 +400,252 @@ "node": ">=18" } }, + "node_modules/@swc/core": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.7.6.tgz", + "integrity": "sha512-FZxyao9eQks1MRmUshgsZTmlg/HB2oXK5fghkoWJm/1CU2q2kaJlVDll2as5j+rmWiwkp0Gidlq8wlXcEEAO+g==", + "dev": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@swc/counter": "^0.1.3", + "@swc/types": "^0.1.12" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/swc" + }, + "optionalDependencies": { + "@swc/core-darwin-arm64": "1.7.6", + "@swc/core-darwin-x64": "1.7.6", + "@swc/core-linux-arm-gnueabihf": "1.7.6", + "@swc/core-linux-arm64-gnu": "1.7.6", + "@swc/core-linux-arm64-musl": "1.7.6", + "@swc/core-linux-x64-gnu": "1.7.6", + "@swc/core-linux-x64-musl": "1.7.6", + "@swc/core-win32-arm64-msvc": "1.7.6", + "@swc/core-win32-ia32-msvc": "1.7.6", + "@swc/core-win32-x64-msvc": "1.7.6" + }, + "peerDependencies": { + "@swc/helpers": "*" + }, + "peerDependenciesMeta": { + "@swc/helpers": { + "optional": true + } + } + }, + "node_modules/@swc/core-darwin-arm64": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.7.6.tgz", + "integrity": "sha512-6lYHey84ZzsdtC7UuPheM4Rm0Inzxm6Sb8U6dmKc4eCx8JL0LfWG4LC5RsdsrTxnjTsbriWlnhZBffh8ijUHIQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-darwin-x64": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.7.6.tgz", + "integrity": "sha512-Fyl+8aH9O5rpx4O7r2KnsPpoi32iWoKOYKiipeTbGjQ/E95tNPxbmsz4yqE8Ovldcga60IPJ5OKQA3HWRiuzdw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm-gnueabihf": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.7.6.tgz", + "integrity": "sha512-2WxYTqFaOx48GKC2cbO1/IntA+w+kfCFy436Ij7qRqqtV/WAvTM9TC1OmiFbqq436rSot52qYmX8fkwdB5UcLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-gnu": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.7.6.tgz", + "integrity": "sha512-TBEGMSe0LhvPe4S7E68c7VzgT3OMu4VTmBLS7B2aHv4v8uZO92Khpp7L0WqgYU1y5eMjk+XLDLi4kokiNHv/Hg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-musl": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.7.6.tgz", + "integrity": "sha512-QI8QGL0HGT42tj7F1A+YAzhGkJjUcvvTfI1e2m704W0Enl2/UIK9v5D1zvQzYwusRyKuaQfbeBRYDh0NcLOGLg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-gnu": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.7.6.tgz", + "integrity": "sha512-61AYVzhjuNQAVIKKWOJu3H0/pFD28RYJGxnGg3YMhvRLRyuWNyY5Nyyj2WkKcz/ON+g38Arlz00NT1LDIViRLg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-musl": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.7.6.tgz", + "integrity": "sha512-hQFznpfLK8XajfAAN9Cjs0w/aVmO7iu9VZvInyrTCRcPqxV5O+rvrhRxKvC1LRMZXr5M6JRSRtepp5w+TK4kAw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-arm64-msvc": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.7.6.tgz", + "integrity": "sha512-Aqsd9afykVMuekzjm4X4TDqwxmG4CrzoOSFe0hZrn9SMio72l5eAPnMtYoe5LsIqtjV8MNprLfXaNbjHjTegmA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-ia32-msvc": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.7.6.tgz", + "integrity": "sha512-9h0hYnOeRVNeQgHQTvD1Im67faNSSzBZ7Adtxyu9urNLfBTJilMllFd2QuGHlKW5+uaT6ZH7ZWDb+c/enx7Lcg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-x64-msvc": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.7.6.tgz", + "integrity": "sha512-izeoB8glCSe6IIDQmrVm6bvR9muk9TeKgmtY7b6l1BwL4BFnTUk4dMmpbntT90bEVQn3JPCaPtUG4HfL8VuyuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0 AND MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/counter": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", + "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/@swc/helpers": { + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.12.tgz", + "integrity": "sha512-KMZNXiGibsW9kvZAO1Pam2JPTDBm+KSHMMHWdsyI/1DbIZjT2A6Gy3hblVXUMEDvUAKq+e0vL0X0o54owWji7g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@swc/types": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.12.tgz", + "integrity": "sha512-wBJA+SdtkbFhHjTMYH+dEH1y4VpfGdAc2Kw/LK09i9bXd/K6j6PkDcFCEzb6iVfZMkPRrl/q0e3toqTAJdkIVA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@swc/counter": "^0.1.3" + } + }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/esbuild": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.0.tgz", @@ -434,6 +684,31 @@ "@esbuild/win32-ia32": "0.23.0", "@esbuild/win32-x64": "0.23.0" } + }, + "node_modules/esbuild-plugin-es5": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/esbuild-plugin-es5/-/esbuild-plugin-es5-2.1.1.tgz", + "integrity": "sha512-GRcHLUwjmrjxz9bN24ooTedrBrAVx7+F8M1aD7FFB+7RTHkt7FY8tHAQ9znyzsV16+95ojbTyJLY+HPO0OI7zA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@swc/core": "^1.5.25", + "@swc/helpers": "^0.5.11", + "deepmerge": "^4.3.1" + }, + "engines": { + "node": ">=12.0" + }, + "peerDependencies": { + "esbuild": "*" + } + }, + "node_modules/tslib": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz", + "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", + "dev": true, + "license": "0BSD" } } } diff --git a/package.json b/package.json index 17cd469..b91c8ff 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,9 @@ "license": "MIT", "dependencies": { "esbuild": "^0.23.0" + }, + "devDependencies": { + "@swc/helpers": "^0.5.12", + "esbuild-plugin-es5": "^2.1.1" } } diff --git a/src/ngs.gleam b/src/ngs.gleam index 031d715..f7f71ad 100644 --- a/src/ngs.gleam +++ b/src/ngs.gleam @@ -66,13 +66,13 @@ fn conf_asset(apps: List(App), watch: Bool) -> List(Asset) { True -> Asset( src <> a.name <> "/nginx.conf", - dist <> a.name <> "/nginx/conf/nginx.conf", + dist <> a.name <> "/nginx/nginx.conf", copy_watch, ) False -> Asset( src <> a.name <> "/nginx.conf", - dist <> a.name <> "/nginx/conf/nginx.conf", + dist <> a.name <> "/nginx/nginx.conf", copy_build, ) } diff --git a/src/ngs_ffi.mjs b/src/ngs_ffi.mjs index 7b68e02..1bd7110 100644 --- a/src/ngs_ffi.mjs +++ b/src/ngs_ffi.mjs @@ -1,3 +1,5 @@ +import { es5Plugin } from 'esbuild-plugin-es5'; +import path from 'path'; import { build, context } from 'esbuild' import { Ok, Error } from "./gleam.mjs" @@ -6,13 +8,19 @@ export function bundle_build(entry, out) { build({ entryPoints: [entry], bundle: true, - minify: true, + minify: false, footer: {js : "export default app.exports()"}, - keepNames: true, + // keepNames: true, format: 'iife', globalName: 'app', outfile: out, - external: ['querystring'], + external: ['querystring', 'crypto'], + plugins: [es5Plugin()], // # 1. Use esbuild-plugin-es5 + target: ['es5'], // # 2. Set the target to es5 + alias: { + // # 3. Set the alias to @swc/helpers + '@swc/helpers': path.dirname('@swc/helpers/package.json'), + } }).then(function(r){ resolve(new Ok(undefined)) }).catch(function(e){ @@ -41,12 +49,12 @@ export function bundle_watch(entry, out) { entryPoints: [entry], bundle: true, minify: true, - footer: "export default app.exports()", + footer: {js : "export default app.exports()"}, keepNames: true, format: 'iife', globalName: 'app', outfile: out, - external: ['querystring'], + external: ['querystring', 'crypto'], }).then(function(ctx){ ctx.watch() console.log(`watching bundle ${entry}...`) |