Skip to content

Commit 46de664

Browse files
authoredOct 21, 2024··
feat: add bootstrapVersion field to manifest (#5890)
1 parent a80f13c commit 46de664

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed
 

‎packages/zip-it-and-ship-it/src/manifest.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import type { ExtendedRoute, Route } from './utils/routes.js'
99

1010
interface ManifestFunction {
1111
buildData?: Record<string, unknown>
12+
bundler?: string
13+
displayName?: string
14+
excludedRoutes?: Route[]
15+
generator?: string
1216
invocationMode?: InvocationMode
1317
mainFile: string
1418
name: string
1519
path: string
20+
priority?: number
1621
routes?: ExtendedRoute[]
17-
excludedRoutes?: Route[]
1822
runtime: string
1923
runtimeVersion?: string
2024
schedule?: string
21-
displayName?: string
22-
bundler?: string
23-
generator?: string
2425
timeout?: number
25-
priority?: number
2626
trafficRules?: TrafficRules
2727
}
2828

@@ -51,6 +51,7 @@ export const createManifest = async ({ functions, path }: { functions: FunctionR
5151
}
5252

5353
const formatFunctionForManifest = ({
54+
bootstrapVersion,
5455
bundler,
5556
displayName,
5657
excludedRoutes,
@@ -74,7 +75,7 @@ const formatFunctionForManifest = ({
7475
generator,
7576
timeout,
7677
invocationMode,
77-
buildData: { runtimeAPIVersion },
78+
buildData: { bootstrapVersion, runtimeAPIVersion },
7879
mainFile,
7980
name,
8081
priority,

‎packages/zip-it-and-ship-it/src/runtimes/node/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const zipFunction: ZipFunction = async function ({
110110
createPluginsModulesPathAliases(srcFiles, pluginsModulesPath, aliases, finalBasePath)
111111

112112
const generator = mergedConfig?.generator || getInternalValue(isInternal)
113-
const zipPath = await zipNodeJs({
113+
const zipResult = await zipNodeJs({
114114
aliases,
115115
archiveFormat,
116116
basePath: finalBasePath,
@@ -152,11 +152,12 @@ const zipFunction: ZipFunction = async function ({
152152
const trafficRules = mergedConfig?.rateLimit ? getTrafficRulesConfig(mergedConfig.rateLimit) : undefined
153153

154154
return {
155+
bootstrapVersion: zipResult.bootstrapVersion,
155156
bundler: bundlerName,
156157
bundlerWarnings,
157158
config: mergedConfig,
158159
displayName: mergedConfig?.name,
159-
entryFilename: zipPath.entryFilename,
160+
entryFilename: zipResult.entryFilename,
160161
generator,
161162
timeout: mergedConfig?.timeout,
162163
inputs,
@@ -165,7 +166,7 @@ const zipFunction: ZipFunction = async function ({
165166
invocationMode,
166167
outputModuleFormat,
167168
nativeNodeModules,
168-
path: zipPath.path,
169+
path: zipResult.path,
169170
priority,
170171
trafficRules,
171172
runtimeVersion:

‎packages/zip-it-and-ship-it/src/runtimes/node/utils/zip.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ const createZipArchive = async function ({
229229
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : ''
230230

231231
let entryFilename = `${basename(filename, extname(filename))}.js`
232+
let bootstrapVersion: string | undefined
232233

233234
if (needsEntryFile) {
234235
const entryFile = getEntryFile({
@@ -255,8 +256,10 @@ const createZipArchive = async function ({
255256
const bootstrapPath = addBootstrapFile(srcFiles, aliases)
256257

257258
if (featureFlags.zisi_add_metadata_file === true) {
258-
const { version: bootstrapVersion } = await getPackageJsonIfAvailable(bootstrapPath)
259-
const payload = JSON.stringify(getMetadataFile(bootstrapVersion, branch))
259+
const { version } = await getPackageJsonIfAvailable(bootstrapPath)
260+
const payload = JSON.stringify(getMetadataFile(version, branch))
261+
262+
bootstrapVersion = version
260263

261264
addZipContent(archive, payload, METADATA_FILE_NAME)
262265
}
@@ -281,16 +284,19 @@ const createZipArchive = async function ({
281284

282285
await endZip(archive, output)
283286

284-
return { path: destPath, entryFilename }
287+
return { path: destPath, entryFilename, bootstrapVersion }
288+
}
289+
290+
interface ZipNodeJsResult {
291+
bootstrapVersion?: string
292+
entryFilename: string
293+
path: string
285294
}
286295

287296
export const zipNodeJs = function ({
288297
archiveFormat,
289298
...options
290-
}: ZipNodeParameters & { archiveFormat: ArchiveFormat }): Promise<{
291-
path: string
292-
entryFilename: string
293-
}> {
299+
}: ZipNodeParameters & { archiveFormat: ArchiveFormat }): Promise<ZipNodeJsResult> {
294300
if (archiveFormat === ARCHIVE_FORMAT.ZIP) {
295301
return createZipArchive(options)
296302
}

‎packages/zip-it-and-ship-it/src/utils/format_result.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { removeUndefined } from './remove_undefined.js'
55
import type { ExtendedRoute, Route } from './routes.js'
66

77
export type FunctionResult = Omit<FunctionArchive, 'runtime'> & {
8+
bootstrapVersion?: string
89
routes?: ExtendedRoute[]
910
excludedRoutes?: Route[]
1011
runtime: RuntimeName

‎packages/zip-it-and-ship-it/tests/v2api.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -753,4 +753,35 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
753753
})
754754
})
755755
})
756+
757+
test('Adds a `buildData` object to each function entry in the manifest file', async () => {
758+
const bootstrapPath = getBootstrapPath()
759+
const bootstrapPackageJson = await readFile(resolve(bootstrapPath, '..', '..', 'package.json'), 'utf8')
760+
const { version: bootstrapVersion } = JSON.parse(bootstrapPackageJson)
761+
762+
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
763+
const manifestPath = join(tmpDir, 'manifest.json')
764+
765+
const { files } = await zipFixture('v2-api', {
766+
fixtureDir: FIXTURES_ESM_DIR,
767+
opts: {
768+
featureFlags: {
769+
zisi_add_metadata_file: true,
770+
},
771+
manifest: manifestPath,
772+
},
773+
})
774+
775+
expect(files.length).toBe(1)
776+
expect(files[0].name).toBe('function')
777+
expect(files[0].bootstrapVersion).toBe(bootstrapVersion)
778+
expect(files[0].runtimeAPIVersion).toBe(2)
779+
780+
const manifestString = await readFile(manifestPath, { encoding: 'utf8' })
781+
const manifest = JSON.parse(manifestString)
782+
783+
expect(manifest.functions.length).toBe(1)
784+
expect(manifest.functions[0].name).toBe('function')
785+
expect(manifest.functions[0].buildData).toEqual({ bootstrapVersion, runtimeAPIVersion: 2 })
786+
})
756787
})

0 commit comments

Comments
 (0)
Please sign in to comment.