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
feat: generate pure ESM functions for NFT #1004
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8186d80
feat: generate ESM entrypoints
eduardoboucas 7ff2df8
chore: fix linting errors
eduardoboucas d0acab6
chore: fix test
eduardoboucas 760cb28
feat: add `zisi_pure_esm` feature flag
eduardoboucas 7156614
chore: fix tests
eduardoboucas 861776e
Merge branch 'main' into feat/esm-entrypoint
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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,14 +1,17 @@ | ||
import type { Message } from '@netlify/esbuild' | ||
|
||
import type { NodeBundlerName } from '..' | ||
import { FunctionConfig } from '../../../config' | ||
import { FeatureFlag, FeatureFlags } from '../../../feature_flags' | ||
import { FunctionSource } from '../../../function' | ||
import { detectEsModule } from '../utils/detect_es_module' | ||
import { ModuleFormat } from '../utils/module_format' | ||
|
||
import esbuildBundler from './esbuild' | ||
import nftBundler from './nft' | ||
import zisiBundler from './zisi' | ||
|
||
export type NodeBundlerName = 'esbuild' | 'esbuild_zisi' | 'nft' | 'zisi' | ||
|
||
// TODO: Create a generic warning type | ||
type BundlerWarning = Message | ||
|
||
|
@@ -49,6 +52,7 @@ type BundleFunction = ( | |
cleanupFunction?: CleanupFunction | ||
inputs: string[] | ||
mainFile: string | ||
moduleFormat: ModuleFormat | ||
nativeNodeModules?: NativeNodeModules | ||
nodeModulesWithDynamicImports?: string[] | ||
srcFiles: string[] | ||
|
@@ -86,5 +90,37 @@ const getBundler = (name: NodeBundlerName): NodeBundler => { | |
} | ||
} | ||
|
||
export { getBundler } | ||
// We use ZISI as the default bundler, except for certain extensions, for which | ||
// esbuild is the only option. | ||
const getDefaultBundler = async ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was moved from |
||
extension, | ||
mainFile, | ||
featureFlags, | ||
}: { | ||
extension: string | ||
mainFile: string | ||
featureFlags: FeatureFlags | ||
}): Promise<NodeBundlerName> => { | ||
const { defaultEsModulesToEsbuild, traceWithNft } = featureFlags | ||
|
||
if (['.mjs', '.ts'].includes(extension)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for a future PR: maybe we should support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely! |
||
return 'esbuild' | ||
} | ||
|
||
if (traceWithNft) { | ||
return 'nft' | ||
} | ||
|
||
if (defaultEsModulesToEsbuild) { | ||
const isEsModule = await detectEsModule({ mainFile }) | ||
|
||
if (isEsModule) { | ||
return 'esbuild' | ||
} | ||
} | ||
|
||
return 'zisi' | ||
} | ||
|
||
export { getBundler, getDefaultBundler } | ||
export type { BundleFunction, GetSrcFilesFunction, NativeNodeModules } |
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
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 |
---|---|---|
|
@@ -42,6 +42,7 @@ const bundle: BundleFunction = async ({ | |
basePath: getBasePath(dirnames), | ||
inputs: srcFiles, | ||
mainFile, | ||
moduleFormat: 'cjs', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be addressed in a follow-up PR. |
||
srcFiles, | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To be addressed in a follow-up PR.