From f8682911bc1b79e3ba19245f47a2e49f7ff22ebf Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:08:39 -0500 Subject: [PATCH 1/8] feat: hello-world js example to mjs --- .eslintrc.cjs | 2 +- .../javascript/hello-world/{{name}}.js | 17 ----------------- .../javascript/hello-world/{{name}}.mjs | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 functions-templates/javascript/hello-world/{{name}}.js create mode 100644 functions-templates/javascript/hello-world/{{name}}.mjs diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0a0378304b8..992674e0726 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -70,7 +70,7 @@ module.exports = { }, // Example functions { - files: ['functions-templates/**/*.js'], + files: ['functions-templates/**/*.mjs'], rules: { 'require-await': 0, 'import/no-unresolved': 0, diff --git a/functions-templates/javascript/hello-world/{{name}}.js b/functions-templates/javascript/hello-world/{{name}}.js deleted file mode 100644 index fdf1fa5b1ae..00000000000 --- a/functions-templates/javascript/hello-world/{{name}}.js +++ /dev/null @@ -1,17 +0,0 @@ -// Docs on event and context https://docs.netlify.com/functions/build/#code-your-function-2 -const handler = async (event) => { - try { - const subject = event.queryStringParameters.name || 'World' - return { - statusCode: 200, - body: JSON.stringify({ message: `Hello ${subject}` }), - // // more keys you can return: - // headers: { "headerName": "headerValue", ... }, - // isBase64Encoded: true, - } - } catch (error) { - return { statusCode: 500, body: error.toString() } - } -} - -module.exports = { handler } diff --git a/functions-templates/javascript/hello-world/{{name}}.mjs b/functions-templates/javascript/hello-world/{{name}}.mjs new file mode 100644 index 00000000000..d86b20b4b28 --- /dev/null +++ b/functions-templates/javascript/hello-world/{{name}}.mjs @@ -0,0 +1,15 @@ +// Docs on request and context https://docs.netlify.com/functions/build/#code-your-function-2 +export default (request, context) => { + try { + const url = new URL(request.url) + const subject = url.searchParams.get('name') || 'World' + + return new Response(`Hello ${subject}`, { + status: 200, + }) + } catch (error) { + return new Response(error.toString, { + status: 500, + }) + } +} From 201cbb0cf4782e73621798e6f809f9230877f672 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:09:51 -0500 Subject: [PATCH 2/8] feat: remove identity example --- .../.netlify-function-template.mjs | 5 ---- .../javascript/identity-signup/{{name}}.js | 29 ------------------- 2 files changed, 34 deletions(-) delete mode 100644 functions-templates/javascript/identity-signup/.netlify-function-template.mjs delete mode 100644 functions-templates/javascript/identity-signup/{{name}}.js diff --git a/functions-templates/javascript/identity-signup/.netlify-function-template.mjs b/functions-templates/javascript/identity-signup/.netlify-function-template.mjs deleted file mode 100644 index 4da0d668b80..00000000000 --- a/functions-templates/javascript/identity-signup/.netlify-function-template.mjs +++ /dev/null @@ -1,5 +0,0 @@ -export default { - name: 'identity-signup', - description: 'Identity Signup: Triggered when a new Netlify Identity user confirms. Assigns roles and extra metadata', - functionType: 'serverless', -} diff --git a/functions-templates/javascript/identity-signup/{{name}}.js b/functions-templates/javascript/identity-signup/{{name}}.js deleted file mode 100644 index d807873caed..00000000000 --- a/functions-templates/javascript/identity-signup/{{name}}.js +++ /dev/null @@ -1,29 +0,0 @@ -// note - this function MUST be named `identity-signup` to work -// we do not yet offer local emulation of this functionality in Netlify Dev -// -// more: -// https://www.netlify.com/blog/2019/02/21/the-role-of-roles-and-how-to-set-them-in-netlify-identity/ -// https://docs.netlify.com/functions/functions-and-identity/ - -const handler = async function (event) { - const data = JSON.parse(event.body) - const { user } = data - - const responseBody = { - app_metadata: { - roles: user.email.split('@')[1] === 'trust-this-company.com' ? ['editor'] : ['visitor'], - my_user_info: 'this is some user info', - }, - user_metadata: { - // append current user metadata - ...user.user_metadata, - custom_data_from_function: 'hurray this is some extra metadata', - }, - } - return { - statusCode: 200, - body: JSON.stringify(responseBody), - } -} - -module.exports = { handler } From f7171d4afa5aa1300731cdf9f2424469ce3161a0 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:14:08 -0500 Subject: [PATCH 3/8] feat: remove sanity templates --- .../.netlify-function-template.mjs | 5 -- .../javascript/sanity-create/package.json | 20 ------ .../javascript/sanity-create/{{name}}.js | 72 ------------------- .../.netlify-function-template.mjs | 5 -- .../javascript/sanity-groq/package.json | 21 ------ .../javascript/sanity-groq/{{name}}.js | 56 --------------- 6 files changed, 179 deletions(-) delete mode 100644 functions-templates/javascript/sanity-create/.netlify-function-template.mjs delete mode 100644 functions-templates/javascript/sanity-create/package.json delete mode 100644 functions-templates/javascript/sanity-create/{{name}}.js delete mode 100644 functions-templates/javascript/sanity-groq/.netlify-function-template.mjs delete mode 100644 functions-templates/javascript/sanity-groq/package.json delete mode 100644 functions-templates/javascript/sanity-groq/{{name}}.js diff --git a/functions-templates/javascript/sanity-create/.netlify-function-template.mjs b/functions-templates/javascript/sanity-create/.netlify-function-template.mjs deleted file mode 100644 index ada348cb028..00000000000 --- a/functions-templates/javascript/sanity-create/.netlify-function-template.mjs +++ /dev/null @@ -1,5 +0,0 @@ -export default { - name: 'sanity-create', - description: 'Create documents in Sanity.io', - functionType: 'serverless', -} diff --git a/functions-templates/javascript/sanity-create/package.json b/functions-templates/javascript/sanity-create/package.json deleted file mode 100644 index e961223558f..00000000000 --- a/functions-templates/javascript/sanity-create/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "sanity-create", - "version": "1.0.0", - "description": "netlify functions:create - Create documents in Sanity.io", - "main": "sanity-create.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "netlify", - "serverless", - "js", - "sanity" - ], - "author": "Sanity.io", - "license": "MIT", - "dependencies": { - "@sanity/client": "^6.0.0" - } -} diff --git a/functions-templates/javascript/sanity-create/{{name}}.js b/functions-templates/javascript/sanity-create/{{name}}.js deleted file mode 100644 index 10671d427d6..00000000000 --- a/functions-templates/javascript/sanity-create/{{name}}.js +++ /dev/null @@ -1,72 +0,0 @@ -const process = require('process') - -const sanityClient = require('@sanity/client') - -// You will need to configure environment variables for Sanity.io project id, -// dataset name, and a token with write access. The variables are named -// -// SANITY_PROJECTID -// SANITY_DATASET -// SANITY_TOKEN -// -// Create a Sanity.io token at https://manage.sanity.io by selecting your -// project, going to Settings -> API and adding a new token with write access. -// -// Read more about configuring Netlify environment variables at -// https://docs.netlify.com/configure-builds/environment-variables/#declare-variables -const client = sanityClient({ - projectId: process.env.SANITY_PROJECTID, - dataset: process.env.SANITY_DATASET, - token: process.env.SANITY_TOKEN, - useCdn: false, -}) - -// A function for writing to a Sanity.io dataset with a write access token. -// -// In this example we accept POST requests with the following JSON body -// -// { -// "author": "A name", -// "message": "What I want to say" -// } -// -// Then we construct an object to save in Sanity.io and return the full saved -// object back to our caller -const handler = async (event) => { - if (!event.httpMethod === 'POST') { - return { - statusCode: 400, - body: 'unrecognized HTTP Method, only POST allowed', - } - } - - const payload = JSON.parse(event.body) - if (!payload.message) { - return { status: 400, body: "Missing 'message'" } - } - - const document = { - _type: 'comment', - // Some workflow state - status: 'waitingApproval', - author: payload.author || 'Anonymous', - message: payload.message, - } - - try { - const result = await client.create(document) - return { - statusCode: 200, - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(result), - } - } catch (error) { - return { - headers: { 'Content-Type': 'application/json' }, - statusCode: 500, - body: error.responseBody || JSON.stringify({ error: 'An error occurred' }), - } - } -} - -module.exports = { handler } diff --git a/functions-templates/javascript/sanity-groq/.netlify-function-template.mjs b/functions-templates/javascript/sanity-groq/.netlify-function-template.mjs deleted file mode 100644 index d0bba0316fa..00000000000 --- a/functions-templates/javascript/sanity-groq/.netlify-function-template.mjs +++ /dev/null @@ -1,5 +0,0 @@ -export default { - name: 'sanity-groq', - description: 'Query a Sanity.io dataset with GROQ', - functionType: 'serverless', -} diff --git a/functions-templates/javascript/sanity-groq/package.json b/functions-templates/javascript/sanity-groq/package.json deleted file mode 100644 index d59656ca24f..00000000000 --- a/functions-templates/javascript/sanity-groq/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "sanity-groq", - "version": "1.0.0", - "description": "netlify functions:create - Query a Sanity.io dataset with GROQ", - "main": "sanity-groq.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "netlify", - "serverless", - "js", - "sanity", - "GROQ" - ], - "author": "Sanity.io", - "license": "MIT", - "dependencies": { - "@sanity/client": "^6.0.0" - } -} diff --git a/functions-templates/javascript/sanity-groq/{{name}}.js b/functions-templates/javascript/sanity-groq/{{name}}.js deleted file mode 100644 index 221c6212800..00000000000 --- a/functions-templates/javascript/sanity-groq/{{name}}.js +++ /dev/null @@ -1,56 +0,0 @@ -const process = require('process') - -const sanityClient = require('@sanity/client') - -// You will need to configure environment variables for Sanity.io project id -// and dataset name. Optionally you may also configure a token, useful for -// reading private datasets or mutating data. The variables are named -// -// SANITY_PROJECTID -// SANITY_DATASET -// SANITY_TOKEN -// -// Read more about configuring environment variables at -// https://docs.netlify.com/configure-builds/environment-variables/#declare-variables -const client = sanityClient({ - projectId: process.env.SANITY_PROJECTID, - dataset: process.env.SANITY_DATASET, - token: process.env.SANITY_TOKEN, - // CDN will not be used if token is set - useCdn: true, -}) - -// A proxy for Sanity.io GROQ queries. -// -// Useful for querying private datasets with a token. Usually you will restrict -// access to this function with for example Netlify Identity. -// -// To explore what queries you can do with GROQ, check out the cheat sheet at -// https://www.sanity.io/docs/query-cheat-sheet -// -// Create Sanity.io tokens at https://manage.sanity.io -// -// Read more about restricting access to your Netlify functions at -// https://www.netlify.com/blog/2018/03/29/jamstack-architecture-on-netlify-how-identity-and-functions-work-together/#restricting-access -const handler = async (event) => { - const { query = '' } = event.queryStringParameters - // The rest of the query params are handled as parameters to the query - const params = { ...event.queryStringParameters, query: null } - - try { - const result = await client.fetch(query, params) - return { - statusCode: 200, - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(result), - } - } catch (error) { - return { - headers: { 'Content-Type': 'application/json' }, - statusCode: error.statusCode || 500, - body: error.responseBody || JSON.stringify({ error: 'Unknown error occurred' }), - } - } -} - -module.exports = { handler } From c386dccdf901cf97a10448ffea6adbbf9ae5e80c Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:19:50 -0500 Subject: [PATCH 4/8] feat: scheduled function to esm --- .eslintrc.cjs | 1 + .../javascript/scheduled-function/{{name}}.js | 12 ------------ .../javascript/scheduled-function/{{name}}.mjs | 11 +++++++++++ 3 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 functions-templates/javascript/scheduled-function/{{name}}.js create mode 100644 functions-templates/javascript/scheduled-function/{{name}}.mjs diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 992674e0726..83a108853cb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -80,6 +80,7 @@ module.exports = { 'no-undef': 0, 'no-unused-vars': 0, 'arrow-body-style': 0, + camelcase: 0, }, parserOptions: { sourceType: 'module', diff --git a/functions-templates/javascript/scheduled-function/{{name}}.js b/functions-templates/javascript/scheduled-function/{{name}}.js deleted file mode 100644 index f7767bde845..00000000000 --- a/functions-templates/javascript/scheduled-function/{{name}}.js +++ /dev/null @@ -1,12 +0,0 @@ -const { schedule } = require('@netlify/functions') - -// To learn about scheduled functions and supported cron extensions, -// see: https://ntl.fyi/sched-func -module.exports.handler = schedule('* * * * *', async (event) => { - const eventBody = JSON.parse(event.body) - console.log(`Next function run at ${eventBody.next_run}.`) - - return { - statusCode: 200, - } -}) diff --git a/functions-templates/javascript/scheduled-function/{{name}}.mjs b/functions-templates/javascript/scheduled-function/{{name}}.mjs new file mode 100644 index 00000000000..d158373143b --- /dev/null +++ b/functions-templates/javascript/scheduled-function/{{name}}.mjs @@ -0,0 +1,11 @@ +// To learn about scheduled functions and supported cron extensions, +// see: https://ntl.fyi/sched-func +export default async (req) => { + const { next_run } = await req.json() + + console.log('Received event! Next invocation at:', next_run) +} + +export const config = { + schedule: '@hourly', +} From ceecd9cb4cf3e1c4ac3ae3494d666770614298f1 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:38:58 -0500 Subject: [PATCH 5/8] feat: remove submission-create example because 3rd party docs out of date --- .../javascript/hello-world/{{name}}.mjs | 2 +- .../.netlify-function-template.mjs | 5 ---- .../submission-created/package.json | 19 ------------ .../javascript/submission-created/{{name}}.js | 29 ------------------- 4 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 functions-templates/javascript/submission-created/.netlify-function-template.mjs delete mode 100644 functions-templates/javascript/submission-created/package.json delete mode 100644 functions-templates/javascript/submission-created/{{name}}.js diff --git a/functions-templates/javascript/hello-world/{{name}}.mjs b/functions-templates/javascript/hello-world/{{name}}.mjs index d86b20b4b28..ee9c52d4d7f 100644 --- a/functions-templates/javascript/hello-world/{{name}}.mjs +++ b/functions-templates/javascript/hello-world/{{name}}.mjs @@ -8,7 +8,7 @@ export default (request, context) => { status: 200, }) } catch (error) { - return new Response(error.toString, { + return new Response(error.toString(), { status: 500, }) } diff --git a/functions-templates/javascript/submission-created/.netlify-function-template.mjs b/functions-templates/javascript/submission-created/.netlify-function-template.mjs deleted file mode 100644 index b48274513ff..00000000000 --- a/functions-templates/javascript/submission-created/.netlify-function-template.mjs +++ /dev/null @@ -1,5 +0,0 @@ -export default { - name: 'submission-created', - description: 'submission-created: template for event triggered function when a new Netlify Form is submitted', - functionType: 'serverless', -} diff --git a/functions-templates/javascript/submission-created/package.json b/functions-templates/javascript/submission-created/package.json deleted file mode 100644 index a18b57c772e..00000000000 --- a/functions-templates/javascript/submission-created/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "submission-created", - "version": "1.0.0", - "description": "netlify functions:create - template for submission-created event triggered function", - "main": "submission-created.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "netlify", - "serverless", - "js" - ], - "author": "Netlify", - "license": "MIT", - "dependencies": { - "node-fetch": "^3.0.0" - } -} diff --git a/functions-templates/javascript/submission-created/{{name}}.js b/functions-templates/javascript/submission-created/{{name}}.js deleted file mode 100644 index 59dffe04063..00000000000 --- a/functions-templates/javascript/submission-created/{{name}}.js +++ /dev/null @@ -1,29 +0,0 @@ -// // optionally configure local env vars -// require('dotenv').config() - -// // details in https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget -const process = require('process') - -const fetch = require('node-fetch') - -const { EMAIL_TOKEN } = process.env -const handler = async (event) => { - const { email } = JSON.parse(event.body).payload - console.log(`Received a submission: ${email}`) - try { - const response = await fetch('https://api.buttondown.email/v1/subscribers', { - method: 'POST', - headers: { - Authorization: `Token ${EMAIL_TOKEN}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ email }), - }) - const data = await response.json() - console.log(`Submitted to Buttondown:\n ${data}`) - } catch (error) { - return { statusCode: 422, body: String(error) } - } -} - -module.exports = { handler } From 25a76e7e7800d228193767da43de7c7a026b1ddc Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:43:48 -0500 Subject: [PATCH 6/8] feat: typescript hello world and make js same --- .eslintrc.cjs | 3 ++- .../javascript/hello-world/{{name}}.mjs | 4 +--- .../typescript/hello-world/{{name}}.mts | 14 ++++++++++++++ .../typescript/hello-world/{{name}}.ts | 12 ------------ 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 functions-templates/typescript/hello-world/{{name}}.mts delete mode 100644 functions-templates/typescript/hello-world/{{name}}.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 83a108853cb..fd0a2453401 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -70,7 +70,7 @@ module.exports = { }, // Example functions { - files: ['functions-templates/**/*.mjs'], + files: ['functions-templates/**/*.mjs', 'functions-templates/**/*.mts'], rules: { 'require-await': 0, 'import/no-unresolved': 0, @@ -80,6 +80,7 @@ module.exports = { 'no-undef': 0, 'no-unused-vars': 0, 'arrow-body-style': 0, + 'n/no-unsupported-features/node-builtins': 0, camelcase: 0, }, parserOptions: { diff --git a/functions-templates/javascript/hello-world/{{name}}.mjs b/functions-templates/javascript/hello-world/{{name}}.mjs index ee9c52d4d7f..a5d3dac88a4 100644 --- a/functions-templates/javascript/hello-world/{{name}}.mjs +++ b/functions-templates/javascript/hello-world/{{name}}.mjs @@ -4,9 +4,7 @@ export default (request, context) => { const url = new URL(request.url) const subject = url.searchParams.get('name') || 'World' - return new Response(`Hello ${subject}`, { - status: 200, - }) + return new Response(`Hello ${subject}`) } catch (error) { return new Response(error.toString(), { status: 500, diff --git a/functions-templates/typescript/hello-world/{{name}}.mts b/functions-templates/typescript/hello-world/{{name}}.mts new file mode 100644 index 00000000000..19c05d861ed --- /dev/null +++ b/functions-templates/typescript/hello-world/{{name}}.mts @@ -0,0 +1,14 @@ +import { Context } from '@netlify/functions' + +export default (request: Request, context: Context) => { + try { + const url = new URL(request.url) + const subject = url.searchParams.get('name') || 'World' + + return new Response(`Hello ${subject}`) + } catch (error) { + return new Response(error.toString(), { + status: 500, + }) + } +} diff --git a/functions-templates/typescript/hello-world/{{name}}.ts b/functions-templates/typescript/hello-world/{{name}}.ts deleted file mode 100644 index 79a2b3ab702..00000000000 --- a/functions-templates/typescript/hello-world/{{name}}.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Handler } from '@netlify/functions' - -export const handler: Handler = async (event, context) => { - const { name = 'stranger' } = event.queryStringParameters - - return { - statusCode: 200, - body: JSON.stringify({ - message: `Hello, ${name}!`, - }), - } -} From 6ce141bb356ae87e4183618c00c884be9020b7fd Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 11:45:16 -0500 Subject: [PATCH 7/8] feat: typescript scheduled function --- .../typescript/scheduled-function/{{name}}.mts | 11 +++++++++++ .../typescript/scheduled-function/{{name}}.ts | 12 ------------ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 functions-templates/typescript/scheduled-function/{{name}}.mts delete mode 100644 functions-templates/typescript/scheduled-function/{{name}}.ts diff --git a/functions-templates/typescript/scheduled-function/{{name}}.mts b/functions-templates/typescript/scheduled-function/{{name}}.mts new file mode 100644 index 00000000000..8613ce21de7 --- /dev/null +++ b/functions-templates/typescript/scheduled-function/{{name}}.mts @@ -0,0 +1,11 @@ +import type { Config } from "@netlify/functions" + +export default async (req: Request) => { + const { next_run } = await req.json() + + console.log("Received event! Next invocation at:", next_run) +} + +export const config: Config = { + schedule: "@hourly" +} diff --git a/functions-templates/typescript/scheduled-function/{{name}}.ts b/functions-templates/typescript/scheduled-function/{{name}}.ts deleted file mode 100644 index 266482ee25c..00000000000 --- a/functions-templates/typescript/scheduled-function/{{name}}.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { schedule } from '@netlify/functions' - -// To learn about scheduled functions and supported cron extensions, -// see: https://ntl.fyi/sched-func -export const handler = schedule('@hourly', async (event) => { - const eventBody = JSON.parse(event.body) - console.log(`Next function run at ${eventBody.next_run}.`) - - return { - statusCode: 200, - } -}) From 2397fee7f0ba05d7ddc82a46227a16827f98eb66 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 29 Nov 2024 12:12:17 -0500 Subject: [PATCH 8/8] test: update tests --- .../functions-create/functions-create.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/commands/functions-create/functions-create.test.ts b/tests/integration/commands/functions-create/functions-create.test.ts index a032551ff1c..86cc109a032 100644 --- a/tests/integration/commands/functions-create/functions-create.test.ts +++ b/tests/integration/commands/functions-create/functions-create.test.ts @@ -66,7 +66,7 @@ describe.concurrent('functions:create command', () => { await childProcess - expect(existsSync(`${builder.directory}/test/functions/hello-world/hello-world.js`)).toBe(true) + expect(existsSync(`${builder.directory}/test/functions/hello-world/hello-world.mjs`)).toBe(true) }) }) }) @@ -175,7 +175,7 @@ describe.concurrent('functions:create command', () => { await childProcess - expect(await fileExistsAsync(`${builder.directory}/functions/hello-world/hello-world.js`)).toBe(true) + expect(await fileExistsAsync(`${builder.directory}/functions/hello-world/hello-world.mjs`)).toBe(true) }) }) }) @@ -219,8 +219,8 @@ describe.concurrent('functions:create command', () => { }) }) - await createWithLanguageTemplate('javascript', 'hello-world/hello-world.js') - await createWithLanguageTemplate('typescript', 'hello-world/hello-world.ts') + await createWithLanguageTemplate('javascript', 'hello-world/hello-world.mjs') + await createWithLanguageTemplate('typescript', 'hello-world/hello-world.mts') }) test('throws an error when the --language flag contains an unsupported value', async (t) => { @@ -257,7 +257,7 @@ describe.concurrent('functions:create command', () => { await expect(childProcess).rejects.toThrowError('Invalid language: coffeescript') - expect(await fileExistsAsync(`${builder.directory}/test/functions/hello-world/hello-world.js`)).toBe(false) + expect(await fileExistsAsync(`${builder.directory}/test/functions/hello-world/hello-world.mjs`)).toBe(false) }) }) }) @@ -355,7 +355,7 @@ describe.concurrent('functions:create command', () => { const pkgBase = join(fixture.directory, 'packages/website') await childProcess - expect(existsSync(join(pkgBase, 'my-dir/functions/hello-world/hello-world.js'))).toBe(true) + expect(existsSync(join(pkgBase, 'my-dir/functions/hello-world/hello-world.mjs'))).toBe(true) }) }) })