Skip to content
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
4 changes: 3 additions & 1 deletion packages/edge-bundler/node/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class DenoBridge {
this.useGlobal = options.useGlobal ?? true

const useNextDeno =
options.featureFlags?.edge_bundler_generate_tarball || options.featureFlags?.edge_bundler_deno_v2
options.featureFlags?.edge_bundler_dry_run_generate_tarball ||
options.featureFlags?.edge_bundler_generate_tarball ||
options.featureFlags?.edge_bundler_deno_v2

this.versionRange = options.versionRange ?? (useNextDeno ? NEXT_DENO_VERSION_RANGE : DENO_VERSION_RANGE)
}
Expand Down
76 changes: 76 additions & 0 deletions packages/edge-bundler/node/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,82 @@ describe.skipIf(lt(denoVersion, '2.4.3'))(
await cleanup()
await rm(vendorDirectory.path, { force: true, recursive: true })
})

describe('Dry-run tarball generation flag enabled', () => {
test('Logs success message when tarball generation succeeded', async () => {
const systemLogger = vi.fn()
const { basePath, cleanup, distPath } = await useFixture('imports_node_builtin', { copyDirectory: true })
const declarations: Declaration[] = [
{
function: 'func1',
path: '/func1',
},
]

await bundle([join(basePath, 'netlify/edge-functions')], distPath, declarations, {
basePath,
configPath: join(basePath, '.netlify/edge-functions/config.json'),
featureFlags: {
edge_bundler_dry_run_generate_tarball: true,
edge_bundler_generate_tarball: false,
},
systemLogger,
})

expect(systemLogger).toHaveBeenCalledWith('Dry run: Tarball bundle generated successfully.')

const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8')
const manifest = JSON.parse(manifestFile)

expect(manifest.bundles.length).toBe(1)
expect(manifest.bundles[0].format).toBe('eszip2')

await cleanup()
})

test('Logs error message when tarball generation failed and does not fail the overall build', async () => {
const systemLogger = vi.fn()
vi.resetModules()
vi.doMock('./formats/tarball.js', () => ({
bundle: vi.fn().mockRejectedValue(new Error('Simulated tarball bundling failure')),
}))

const { bundle: bundleUnderTest } = await import('./bundler.js')

const { basePath, cleanup, distPath } = await useFixture('imports_node_builtin', { copyDirectory: true })
const sourceDirectory = join(basePath, 'functions')
const declarations: Declaration[] = [
{
function: 'func1',
path: '/func1',
},
]

await expect(
bundleUnderTest([sourceDirectory], distPath, declarations, {
basePath,
configPath: join(sourceDirectory, 'config.json'),
featureFlags: {
edge_bundler_dry_run_generate_tarball: true,
edge_bundler_generate_tarball: false,
},
systemLogger,
}),
).resolves.toBeDefined()

expect(systemLogger).toHaveBeenCalledWith(
`Dry run: Tarball bundle generation failed: Simulated tarball bundling failure`,
)

const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8')
const manifest = JSON.parse(manifestFile)
expect(manifest.bundles.length).toBe(1)
expect(manifest.bundles[0].format).toBe('eszip2')

await cleanup()
vi.resetModules()
})
})
},
10_000,
)
43 changes: 29 additions & 14 deletions packages/edge-bundler/node/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,35 @@ export const bundle = async (

const bundles: Bundle[] = []

if (featureFlags.edge_bundler_generate_tarball) {
bundles.push(
await bundleTarball({
basePath,
buildID,
debug,
deno,
distDirectory,
functions,
featureFlags,
importMap: importMap.clone(),
vendorDirectory: vendor?.directory,
}),
)
if (featureFlags.edge_bundler_generate_tarball || featureFlags.edge_bundler_dry_run_generate_tarball) {
const tarballPromise = bundleTarball({
basePath,
buildID,
debug,
deno,
distDirectory,
functions,
featureFlags,
importMap: importMap.clone(),
vendorDirectory: vendor?.directory,
})

if (featureFlags.edge_bundler_dry_run_generate_tarball) {
try {
await tarballPromise
logger.system('Dry run: Tarball bundle generated successfully.')
} catch (error: unknown) {
if (error instanceof Error) {
logger.system(`Dry run: Tarball bundle generation failed: ${error.message}`)
} else {
logger.system(`Dry run: Tarball bundle generation failed: ${String(error)}`)
}
}
}

if (featureFlags.edge_bundler_generate_tarball) {
bundles.push(await tarballPromise)
}
}

if (vendor) {
Expand Down
1 change: 1 addition & 0 deletions packages/edge-bundler/node/feature_flags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const defaultFlags = {
edge_bundler_generate_tarball: false,
edge_bundler_dry_run_generate_tarball: false,
edge_bundler_deno_v2: false,
}

Expand Down
Loading