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: write the bootstrap version to a file #5828

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 13 additions & 3 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 @@ -7,6 +7,7 @@ import { basename, dirname, extname, join } from 'path'
import { getPath as getV2APIPath } from '@netlify/serverless-functions-api'
import { copyFile } from 'cp-file'
import pMap from 'p-map'
import { tmpName } from 'tmp-promise'

import {
addZipContent,
Expand All @@ -31,6 +32,7 @@ import {
} from './entry_file.js'
import { ModuleFormat } from './module_format.js'
import { normalizeFilePath } from './normalize_path.js'
import { getClosestPackageJson } from './package_json.js'

// Taken from https://www.npmjs.com/package/cpy.
const COPY_FILE_CONCURRENCY = os.cpus().length === 0 ? 2 : os.cpus().length * 2
Expand All @@ -57,12 +59,20 @@ interface ZipNodeParameters {
generator?: string
}

const addBootstrapFile = function (srcFiles: string[], aliases: Map<string, string>) {
const addBootstrapFile = async function (srcFiles: string[], aliases: Map<string, string>) {
// This is the path to the file that contains all the code for the v2
// functions API. We add it to the list of source files and create an
// alias so that it's written as `BOOTSTRAP_FILE_NAME` in the ZIP/Directory.
const v2APIPath = getV2APIPath()

const bootstrapPkg = await getClosestPackageJson(getV2APIPath())
const version = bootstrapPkg?.contents?.version
if (version) {
const tmpFilePath = await tmpName()
await writeFile(tmpFilePath, version)
srcFiles.push(tmpFilePath, '.bootstrap_version')
}

srcFiles.push(v2APIPath)
aliases.set(v2APIPath, BOOTSTRAP_FILE_NAME)
}
Expand Down Expand Up @@ -122,7 +132,7 @@ const createDirectory = async function ({
])

if (runtimeAPIVersion === 2) {
addBootstrapFile(srcFiles, aliases)
await addBootstrapFile(srcFiles, aliases)
}

const symlinks = new Map<string, string>()
Expand Down Expand Up @@ -242,7 +252,7 @@ const createZipArchive = async function ({
}

if (runtimeAPIVersion === 2) {
addBootstrapFile(srcFiles, aliases)
await addBootstrapFile(srcFiles, aliases)
}

const deduplicatedSrcFiles = [...new Set(srcFiles)]
Expand Down
Loading