This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ESM support when bundling with NFT (#759)
* feat: add ESM support when bundling with NFT * chore: disable test for NFT * chore: update test fixture * refactor: remove types file Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4167cfc
commit b63ff7e
Showing
7 changed files
with
144 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { build } from '@netlify/esbuild' | ||
import { tmpName } from 'tmp-promise' | ||
|
||
import type { FunctionConfig } from '../../../../config' | ||
import { safeUnlink } from '../../../../utils/fs' | ||
import { getBundlerTarget } from '../esbuild/bundler_target' | ||
|
||
const transpile = async (path: string, config: FunctionConfig) => { | ||
const targetPath = await tmpName({ postfix: '.js' }) | ||
const cleanupFn = () => safeUnlink(targetPath) | ||
|
||
// The version of ECMAScript to use as the build target. This will determine | ||
// whether certain features are transpiled down or left untransformed. | ||
const nodeTarget = getBundlerTarget(config.nodeVersion) | ||
|
||
await build({ | ||
bundle: false, | ||
entryPoints: [path], | ||
format: 'cjs', | ||
logLevel: 'error', | ||
outfile: targetPath, | ||
platform: 'node', | ||
target: [nodeTarget], | ||
}) | ||
|
||
return { | ||
cleanupFn, | ||
path: targetPath, | ||
} | ||
} | ||
|
||
const transpileMany = async (paths: string[], config: FunctionConfig) => { | ||
const transpiledPaths: Map<string, string> = new Map() | ||
|
||
await Promise.all( | ||
paths.map(async (path) => { | ||
const transpiled = await transpile(path, config) | ||
|
||
transpiledPaths.set(transpiled.path, path) | ||
}), | ||
) | ||
|
||
return transpiledPaths | ||
} | ||
|
||
export { transpileMany } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
const scopeModule = require('@netlify/eslint-config-node') | ||
const { stack } = require('@netlify/mock-package') | ||
|
||
module.exports = typeof scopeModule === 'object' | ||
module.exports = stack === 'jam' |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/node-module-scope/node_modules/@netlify/mock-package/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
tests/fixtures/node-module-scope/node_modules/@netlify/mock-package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tests/fixtures/node-module-scope/node_modules/@netlify/mock-package/stack.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b63ff7e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⏱ Benchmark results
largeDepsEsbuild: 6.4s
largeDepsNft: 46s
largeDepsZisi: 54.9s