Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bootstrapVersion field to manifest #5890

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/zip-it-and-ship-it/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import type { ExtendedRoute, Route } from './utils/routes.js'

interface ManifestFunction {
buildData?: Record<string, unknown>
bundler?: string
Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing has been added or deleted, just sorted alphabetically. 🤓

displayName?: string
excludedRoutes?: Route[]
generator?: string
invocationMode?: InvocationMode
mainFile: string
name: string
path: string
priority?: number
routes?: ExtendedRoute[]
excludedRoutes?: Route[]
runtime: string
runtimeVersion?: string
schedule?: string
displayName?: string
bundler?: string
generator?: string
timeout?: number
priority?: number
trafficRules?: TrafficRules
}

Expand Down Expand Up @@ -51,6 +51,7 @@ export const createManifest = async ({ functions, path }: { functions: FunctionR
}

const formatFunctionForManifest = ({
bootstrapVersion,
bundler,
displayName,
excludedRoutes,
Expand All @@ -74,7 +75,7 @@ const formatFunctionForManifest = ({
generator,
timeout,
invocationMode,
buildData: { runtimeAPIVersion },
buildData: { bootstrapVersion, runtimeAPIVersion },
mainFile,
name,
priority,
Expand Down
7 changes: 4 additions & 3 deletions packages/zip-it-and-ship-it/src/runtimes/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const zipFunction: ZipFunction = async function ({
createPluginsModulesPathAliases(srcFiles, pluginsModulesPath, aliases, finalBasePath)

const generator = mergedConfig?.generator || getInternalValue(isInternal)
const zipPath = await zipNodeJs({
const zipResult = await zipNodeJs({
aliases,
archiveFormat,
basePath: finalBasePath,
Expand Down Expand Up @@ -152,11 +152,12 @@ const zipFunction: ZipFunction = async function ({
const trafficRules = mergedConfig?.rateLimit ? getTrafficRulesConfig(mergedConfig.rateLimit) : undefined

return {
bootstrapVersion: zipResult.bootstrapVersion,
bundler: bundlerName,
bundlerWarnings,
config: mergedConfig,
displayName: mergedConfig?.name,
entryFilename: zipPath.entryFilename,
entryFilename: zipResult.entryFilename,
generator,
timeout: mergedConfig?.timeout,
inputs,
Expand All @@ -165,7 +166,7 @@ const zipFunction: ZipFunction = async function ({
invocationMode,
outputModuleFormat,
nativeNodeModules,
path: zipPath.path,
path: zipResult.path,
priority,
trafficRules,
runtimeVersion:
Expand Down
20 changes: 13 additions & 7 deletions packages/zip-it-and-ship-it/src/runtimes/node/utils/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const createZipArchive = async function ({
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : ''

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

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

if (featureFlags.zisi_add_metadata_file === true) {
const { version: bootstrapVersion } = await getPackageJsonIfAvailable(bootstrapPath)
const payload = JSON.stringify(getMetadataFile(bootstrapVersion, branch))
const { version } = await getPackageJsonIfAvailable(bootstrapPath)
const payload = JSON.stringify(getMetadataFile(version, branch))

bootstrapVersion = version

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

await endZip(archive, output)

return { path: destPath, entryFilename }
return { path: destPath, entryFilename, bootstrapVersion }
}

interface ZipNodeJsResult {
bootstrapVersion?: string
entryFilename: string
path: string
}

export const zipNodeJs = function ({
archiveFormat,
...options
}: ZipNodeParameters & { archiveFormat: ArchiveFormat }): Promise<{
path: string
entryFilename: string
}> {
}: ZipNodeParameters & { archiveFormat: ArchiveFormat }): Promise<ZipNodeJsResult> {
if (archiveFormat === ARCHIVE_FORMAT.ZIP) {
return createZipArchive(options)
}
Expand Down
1 change: 1 addition & 0 deletions packages/zip-it-and-ship-it/src/utils/format_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { removeUndefined } from './remove_undefined.js'
import type { ExtendedRoute, Route } from './routes.js'

export type FunctionResult = Omit<FunctionArchive, 'runtime'> & {
bootstrapVersion?: string
routes?: ExtendedRoute[]
excludedRoutes?: Route[]
runtime: RuntimeName
Expand Down
31 changes: 31 additions & 0 deletions packages/zip-it-and-ship-it/tests/v2api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,35 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
})
})
})

test('Adds a `buildData` object to each function entry in the manifest file', async () => {
const bootstrapPath = getBootstrapPath()
const bootstrapPackageJson = await readFile(resolve(bootstrapPath, '..', '..', 'package.json'), 'utf8')
const { version: bootstrapVersion } = JSON.parse(bootstrapPackageJson)

const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
const manifestPath = join(tmpDir, 'manifest.json')

const { files } = await zipFixture('v2-api', {
fixtureDir: FIXTURES_ESM_DIR,
opts: {
featureFlags: {
zisi_add_metadata_file: true,
},
manifest: manifestPath,
},
})

expect(files.length).toBe(1)
expect(files[0].name).toBe('function')
expect(files[0].bootstrapVersion).toBe(bootstrapVersion)
expect(files[0].runtimeAPIVersion).toBe(2)

const manifestString = await readFile(manifestPath, { encoding: 'utf8' })
const manifest = JSON.parse(manifestString)

expect(manifest.functions.length).toBe(1)
expect(manifest.functions[0].name).toBe('function')
expect(manifest.functions[0].buildData).toEqual({ bootstrapVersion, runtimeAPIVersion: 2 })
})
})
Loading