From 6db21252334f50050ac010a8baf4a12fc678b8a7 Mon Sep 17 00:00:00 2001 From: Jonas Jongejan <227529+HalfdanJ@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:53:20 -0500 Subject: [PATCH] feat: Add option to select GAE nodejs version (#70) --- README.md | 1 + index.d.ts | 6 ++++++ index.js | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 50671ce..77ab78f 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Following options are available - `useCloudLogging`: Enable or disable [Google Cloud Logging](https://cloud.google.com/logging/docs/overview). When enabled, `console.log`, `console.error` and so on show up with more metadata in Cloud Logging dashboard, and log messages are bundled by request trace id's. Enabled by default. - `external`: Node modules that the esbuild step should mark as external. - `dependencies`: Node modules that should be added to `package.json` file in the build step. These modules will be fetched when the application is deployed. +- `nodejsRuntime`: Node version to use in appengine runtime. See available runtimes [here](https://cloud.google.com/appengine/docs/standard/nodejs/runtime). Defaults to `16` The generated `app.yaml` file can be customized by adding a file named `app.yaml` in the root of the project. The adapter will merge this file with the generated `app.yaml` file, enabling for example custom machine types, added routes or any other [app.yaml configuration](https://cloud.google.com/appengine/docs/standard/reference/app-yaml?tab=node.js) diff --git a/index.d.ts b/index.d.ts index f8bdc1a..f35648b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -16,6 +16,12 @@ type AdapterOptions = { external?: string[]; /** Dependencies to be added in package.json */ dependencies?: Record; + /** + * Nodejs version to target, defaults to 16 + * Available runtimes can be seen here: + * https://cloud.google.com/appengine/docs/standard/nodejs/runtime + */ + nodejsRuntime?: number; }; export default function plugin(options?: AdapterOptions): Adapter; diff --git a/index.js b/index.js index 8669fbe..4e12980 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ const files = fileURLToPath(new URL('files', import.meta.url)); /** @type {import('.').default} **/ export default function entrypoint(options = {}) { - const {out = 'build', external = [], useCloudLogging = true, dependencies = {}} = options; + const {out = 'build', external = [], useCloudLogging = true, dependencies = {}, nodejsRuntime = 16} = options; return { name: 'svelte-adapter-appengine', @@ -50,7 +50,7 @@ export default function entrypoint(options = {}) { await esbuild.build({ entryPoints: [`${temporary}/entry.js`], outfile: `${out}/index.js`, - target: 'node16', + target: `node${nodejsRuntime}`, bundle: true, platform: 'node', format: 'cjs', @@ -139,7 +139,7 @@ export default function entrypoint(options = {}) { join(out, 'app.yaml'), YAML.stringify({ ...yaml, - runtime: 'nodejs16', + runtime: `nodejs${nodejsRuntime}`, entrypoint: 'node index.js', // eslint-disable-next-line camelcase default_expiration: '0h',