Skip to content

Commit

Permalink
fix: use correct file extensions for transpilation (#6256)
Browse files Browse the repository at this point in the history
* fix: use correct file extensions for transpilation

* chore: remove test function file rename

* chore: fix function args test

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
estephinson and kodiakhq[bot] authored Dec 8, 2023
1 parent 7e3349c commit 8308097
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/functions/netlify-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class NetlifyFunction {
}

if (extension === '.js') {
return '.js'
return '.mjs'
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/functions/runtimes/js/builders/zisi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default async function handler({ config, directory, errorExit, func, meta
featureFlags.zisi_pure_esm_mjs = true
} else {
// We must use esbuild for certain file extensions.
const mustTranspile = ['.js', '.ts', '.mts', '.cts'].includes(path.extname(func.mainFile))
const mustTranspile = ['.mjs', '.ts', '.mts', '.cts'].includes(path.extname(func.mainFile))
const mustUseEsbuild = hasTypeModule || mustTranspile

if (mustUseEsbuild && !functionsConfig['*'].nodeBundler) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/commands/deploy/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
export default async () => new Response("Internal V2 API")
export const config = { path: "/internal-v2-func" }
`,
path: '.netlify/functions-internal/func-4.js',
path: '.netlify/functions-internal/func-4.mjs',
})
.buildAsync()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ exports.handler = async () => ({
})
})

test('Serves functions with a `.js` extension', async (t) => {
test('Serves functions with a `.mjs` extension', async (t) => {
await withSiteBuilder('function-mjs', async (builder) => {
const bundlerConfig = args.includes('esbuild') ? { node_bundler: 'esbuild' } : {}

Expand All @@ -623,7 +623,7 @@ exports.handler = async () => ({
},
})
.withContentFile({
path: 'functions/hello.js',
path: 'functions/hello.mjs',
content: `
const handler = async () => {
return {
Expand Down

2 comments on commit 8308097

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,399
  • Package size: 405 MB
  • Number of ts-expect-error directives: 1,331

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,399
  • Package size: 405 MB
  • Number of ts-expect-error directives: 1,331

Please sign in to comment.