Skip to content

Commit

Permalink
feat: Add option to select GAE nodejs version (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfdanJ authored Feb 4, 2023
1 parent 25ddfc2 commit 6db2125
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type AdapterOptions = {
external?: string[];
/** Dependencies to be added in package.json */
dependencies?: Record<string, string>;
/**
* 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;
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 6db2125

Please sign in to comment.