Skip to content

Commit

Permalink
Merge branch 'main' into support-node-22-in-lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstork authored Dec 10, 2024
2 parents 698025a + 689a8dd commit 677e6e4
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 120 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/build-info/src/runtime/bun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ test('detects node when bunfig.toml is present', async ({ fs }) => {
expect(detected[0].name).toBe('Bun')
})

test('detects node when bun.lock is present', async ({ fs }) => {
const cwd = mockFileSystem({
'bun.lock': '',
})

const detected = await new Project(fs, cwd).detectRuntime()
expect(detected[0].name).toBe('Bun')
})

test('detects node when bun.lockb is present', async ({ fs }) => {
const cwd = mockFileSystem({
'bun.lockb': '',
Expand Down
2 changes: 1 addition & 1 deletion packages/build-info/src/runtime/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { LangRuntime } from './runtime.js'
export class Bun extends LangRuntime {
id = 'bun'
name = 'Bun'
configFiles = ['bun.lockb', 'bunfig.toml']
configFiles = ['bun.lock', 'bun.lockb', 'bunfig.toml']
}
17 changes: 15 additions & 2 deletions packages/build/src/plugins/spawn.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createRequire } from 'module'
import { platform } from 'os'
import { fileURLToPath, pathToFileURL } from 'url'
import { promisify } from 'util'

import { trace } from '@opentelemetry/api'
import { ExecaChildProcess, execaNode } from 'execa'
import { gte } from 'semver'
import { gte, satisfies } from 'semver'

import { FeatureFlags } from '../core/feature_flags.js'
import { addErrorInfo } from '../error/info.js'
Expand Down Expand Up @@ -217,5 +218,17 @@ const stopPlugin = async function ({
})
childProcess.disconnect()
}
childProcess.kill()

// On Windows with Node 21+, there's a bug where attempting to kill a child process
// results in an EPERM error. Ignore the error in that case.
// See: https://github.com/nodejs/node/issues/51766
// We also disable execa's `forceKillAfterTimeout` in this case
// which can cause unhandled rejection.
try {
childProcess.kill('SIGTERM', {
forceKillAfterTimeout: platform() === 'win32' && satisfies(process.version, '>=21') ? false : undefined,
})
} catch {
// no-op
}
}
3 changes: 2 additions & 1 deletion packages/build/src/plugins_core/blobs_upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const coreStep: CoreStepFunction = async function ({
systemLog(`Uploading blob ${key}`)

const { data, metadata } = await getFileWithMetadata(key, contentPath, metadataPath)
await blobStore.set(key, data, { metadata })
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.length)
await blobStore.set(key, arrayBuffer, { metadata })
},
{ concurrency: 10 },
)
Expand Down
3 changes: 2 additions & 1 deletion packages/build/src/plugins_core/dev_blobs_upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const coreStep: CoreStepFunction = async function ({
log(logs, `- Uploading blob ${key}`, { indent: true })
}
const { data, metadata } = await getFileWithMetadata(key, contentPath, metadataPath)
await blobStore.set(key, data, { metadata })
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.length)
await blobStore.set(key, arrayBuffer, { metadata })
},
{ concurrency: 10 },
)
Expand Down
47 changes: 5 additions & 42 deletions packages/config/src/api/site_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,18 @@ export const getSiteInfo = async function ({
context,
offline = false,
testOpts = {},
featureFlags = {},
siteFeatureFlagPrefix,
}: GetSiteInfoOpts) {
const { env: testEnv = false } = testOpts

const useV2Endpoint = !!accountId && featureFlags.cli_integration_installations_meta

if (useV2Endpoint) {
if (api === undefined || mode === 'buildbot' || testEnv) {
const siteInfo: { id?: string; account_id?: string } = {}

if (siteId !== undefined) siteInfo.id = siteId
if (accountId !== undefined) siteInfo.account_id = accountId

const integrations =
mode === 'buildbot' && !offline
? await getIntegrations({ siteId, testOpts, offline, useV2Endpoint, accountId })
: []

return { siteInfo, accounts: [], addons: [], integrations }
}

const promises = [
getSite(api, siteId, siteFeatureFlagPrefix),
getAccounts(api),
getAddons(api, siteId),
getIntegrations({ siteId, testOpts, offline, useV2Endpoint, accountId }),
]

const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)

if (siteInfo.use_envelope) {
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context })

siteInfo.build_settings.env = envelope
}

return { siteInfo, accounts, addons, integrations }
}

if (api === undefined || mode === 'buildbot' || testEnv) {
const siteInfo: { id?: string; account_id?: string } = {}

if (siteId !== undefined) siteInfo.id = siteId
if (accountId !== undefined) siteInfo.account_id = accountId

const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : []
const integrations =
mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline, accountId }) : []

return { siteInfo, accounts: [], addons: [], integrations }
}
Expand All @@ -90,7 +55,7 @@ export const getSiteInfo = async function ({
getSite(api, siteId, siteFeatureFlagPrefix),
getAccounts(api),
getAddons(api, siteId),
getIntegrations({ siteId, testOpts, offline }),
getIntegrations({ siteId, testOpts, offline, accountId }),
]

const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)
Expand Down Expand Up @@ -144,15 +109,13 @@ type GetIntegrationsOpts = {
accountId?: string
testOpts: TestOptions
offline: boolean
useV2Endpoint?: boolean
}

const getIntegrations = async function ({
siteId,
accountId,
testOpts,
offline,
useV2Endpoint,
}: GetIntegrationsOpts): Promise<IntegrationResponse[]> {
if (!siteId || offline) {
return []
Expand All @@ -162,8 +125,8 @@ const getIntegrations = async function ({

const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`)

// use future state feature flag
const url = useV2Endpoint
// if accountId isn't present, use safe v1 endpoint
const url = accountId
? `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}`
: `${baseUrl}site/${siteId}/integrations/safe`

Expand Down
14 changes: 11 additions & 3 deletions packages/config/src/case.js → packages/config/src/case.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// Some properties can be optionally capitalized. We normalize them to lowercase
export const normalizeConfigCase = function ({ Build, build = Build, ...config }) {
export const normalizeConfigCase = function ({
Build,
build = Build,
...config
}: {
Build: Record<string, unknown>
build: Record<string, unknown>
[key: string]: unknown
}): Record<string, unknown> {
const buildA = normalizeBuildCase(build)
return { ...config, build: buildA }
}

const normalizeBuildCase = function ({
const normalizeBuildCase = ({
Base,
base = Base,
Command,
Expand All @@ -22,7 +30,7 @@ const normalizeBuildCase = function ({
Publish,
publish = Publish,
...build
} = {}) {
}: Record<string, unknown> = {}): Record<string, unknown> => {
return {
...build,
base,
Expand Down
Loading

0 comments on commit 677e6e4

Please sign in to comment.