-
Notifications
You must be signed in to change notification settings - Fork 35
feat: detect V2 API using static analysis #1429
Changes from 7 commits
2670c39
4cc7ef8
dccccb0
60665a3
3d0d042
a87e5fa
0b91c89
03f4ae2
fcf5868
dd76396
54d0c7b
15d6633
c930a7f
a22d2e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,14 @@ import { zipNodeJs } from './utils/zip.js' | |
|
||
// A proxy for the `getSrcFiles` that calls `getSrcFiles` on the bundler | ||
const getSrcFilesWithBundler: GetSrcFilesFunction = async (parameters) => { | ||
const { config, extension, featureFlags, mainFile, srcDir } = parameters | ||
const { config, extension, featureFlags, mainFile, runtimeAPIVersion, srcDir } = parameters | ||
const pluginsModulesPath = await getPluginsModulesPath(srcDir) | ||
const bundlerName = await getBundlerName({ | ||
config, | ||
extension, | ||
featureFlags, | ||
mainFile, | ||
runtimeAPIVersion, | ||
}) | ||
const bundler = getBundler(bundlerName) | ||
const result = await bundler.getSrcFiles({ ...parameters, pluginsModulesPath }) | ||
|
@@ -48,15 +49,6 @@ const zipFunction: ZipFunction = async function ({ | |
stat, | ||
isInternal, | ||
}) { | ||
const pluginsModulesPath = await getPluginsModulesPath(srcDir) | ||
const bundlerName = await getBundlerName({ | ||
config, | ||
extension, | ||
featureFlags, | ||
mainFile, | ||
}) | ||
const bundler = getBundler(bundlerName) | ||
|
||
// If the file is a zip, we assume the function is bundled and ready to go. | ||
// We simply copy it to the destination path with no further processing. | ||
if (extension === '.zip') { | ||
|
@@ -67,6 +59,17 @@ const zipFunction: ZipFunction = async function ({ | |
return { config, path: destPath } | ||
} | ||
|
||
const inSourceConfig = await findISCDeclarationsInPath(mainFile, name, featureFlags) | ||
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. I'd like to call out this change, since we're now parsing ISC before bundling. This means we'll start parsing ESM, CJS and TS rather than the bundled/transpiled CJS. I don't anticipate any problems with this, but it's not something I can easily wrap with a feature flag, so something to keep an eye on. 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. We need to update the babel-parser in the future though, as we otherwise do not support the latest ES standard. It is currently locked at an old version because of previous performance problems. Last time I checked beginning of this year or end of last, the performance problems were still there I think. But I think the problems are because of the zisi bundler and not necessarily the isc parsing. |
||
const runtimeAPIVersion = inSourceConfig.apiVersion === 2 ? 2 : 1 | ||
const pluginsModulesPath = await getPluginsModulesPath(srcDir) | ||
const bundlerName = await getBundlerName({ | ||
config, | ||
extension, | ||
featureFlags, | ||
mainFile, | ||
runtimeAPIVersion, | ||
}) | ||
const bundler = getBundler(bundlerName) | ||
const { | ||
aliases = new Map(), | ||
cleanupFunction, | ||
|
@@ -92,13 +95,12 @@ const zipFunction: ZipFunction = async function ({ | |
pluginsModulesPath, | ||
repositoryRoot, | ||
runtime, | ||
runtimeAPIVersion, | ||
srcDir, | ||
srcPath, | ||
stat, | ||
}) | ||
|
||
const inSourceConfig = await findISCDeclarationsInPath(mainFile, name) | ||
|
||
createPluginsModulesPathAliases(srcFiles, pluginsModulesPath, aliases, finalBasePath) | ||
|
||
const zipPath = await zipNodeJs({ | ||
|
@@ -113,6 +115,7 @@ const zipFunction: ZipFunction = async function ({ | |
mainFile: finalMainFile, | ||
moduleFormat, | ||
rewrites, | ||
runtimeAPIVersion, | ||
srcFiles, | ||
}) | ||
|
||
|
@@ -123,7 +126,7 @@ const zipFunction: ZipFunction = async function ({ | |
let { invocationMode } = inSourceConfig | ||
|
||
// If we're using the V2 API, force the invocation to "stream". | ||
if (featureFlags.zisi_functions_api_v2) { | ||
if (runtimeAPIVersion === 2) { | ||
invocationMode = INVOCATION_MODE.Stream | ||
} | ||
|
||
|
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.
There is no need to install this. This plugin is for babel itself, but we are only using the parser, which has no concept of plugin packages. For the parser plugins are simply strings that enable features.