Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: populate Netlify global before customer code (#1643)
Browse files Browse the repository at this point in the history
* fix: populate Netlify global before customer code

* Update tests/v2api.test.ts

Co-authored-by: Eduardo Bouças <[email protected]>

---------

Co-authored-by: Eduardo Bouças <[email protected]>
  • Loading branch information
Skn0tt and eduardoboucas authored Nov 3, 2023
1 parent a01ecdb commit 97992ee
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@babel/parser": "^7.22.5",
"@babel/types": "7.23.0",
"@netlify/binary-info": "^1.0.0",
"@netlify/serverless-functions-api": "^1.10.1",
"@netlify/serverless-functions-api": "^1.11.0",
"@vercel/nft": "^0.23.0",
"archiver": "^6.0.0",
"common-path-prefix": "^3.0.0",
Expand Down
3 changes: 1 addition & 2 deletions src/runtimes/node/utils/entry_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ const getEntryFileContents = (

if (runtimeAPIVersion === 2) {
return [
`import * as func from '${importPath}'`,
`import * as bootstrap from './${BOOTSTRAP_FILE_NAME}'`,
`import * as func from '${importPath}'`,

// See https://esbuild.github.io/content-types/#default-interop.
'const funcModule = typeof func.default === "function" ? func : func.default',

`global.Netlify = bootstrap.getNetlifyGlobal()`,
`export const handler = bootstrap.getLambdaHandler(funcModule)`,
].join(';')
}
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures-esm/v2-api-environment-variables/function.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const baz = Netlify.env.get('baz')

export default async () => {
Netlify.env.set('bar', 'bar!')

Expand All @@ -10,5 +12,6 @@ export default async () => {
foo: Netlify.env.has('foo'),
bar: Netlify.env.get('bar'),
env: Netlify.env.toObject(),
baz,
})
}
2 changes: 2 additions & 0 deletions tests/v2api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
})

vi.stubEnv('foo', 'foo!')
vi.stubEnv('baz', 'baz!')

const [{ name: archive, entryFilename }] = files
const func = await importFunctionFile(`${tmpDir}/${archive}/${entryFilename}`)
Expand All @@ -494,6 +495,7 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
env: expect.objectContaining({
foo: 'foo!',
}),
baz: 'baz!',
})
// bar got set and deleted again
expect(parsed).not.toHaveProperty('bar')
Expand Down

1 comment on commit 97992ee

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⏱ Benchmark results

  • largeDepsEsbuild: 3.4s
  • largeDepsNft: 10.8s
  • largeDepsZisi: 21.1s

Please sign in to comment.