Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

refactor: remove feature flag buildGoSource and zisi_detect_esm #1113

Merged
merged 1 commit into from
Jun 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/feature_flags.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { env } from 'process'

export const defaultFlags: Record<string, boolean> = {
buildGoSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
buildRustSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
parseWithEsbuild: false,
traceWithNft: false,
zisi_detect_esm: false,
zisi_pure_esm: false,
}

Expand Down
6 changes: 1 addition & 5 deletions src/runtimes/go/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ const findFunctionsInPaths: FindFunctionsInPathsFunction = async function ({ fea
return functions.filter(nonNullable)
}

const findFunctionInPath: FindFunctionInPathFunction = async function ({ featureFlags, fsCache, path }) {
const findFunctionInPath: FindFunctionInPathFunction = async function ({ fsCache, path }) {
const runtime = await detectBinaryRuntime({ fsCache, path })

if (runtime === 'go') {
return processBinary({ fsCache, path })
}

if (featureFlags.buildGoSource !== true) {
return
}

const goSourceFile = await detectGoFunction({ fsCache, path })

if (goSourceFile) {
Expand Down
10 changes: 2 additions & 8 deletions src/runtimes/node/bundlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ export const getDefaultBundler = async ({
return 'nft'
}

if (featureFlags.zisi_detect_esm) {
const functionIsESM = await detectEsModule({ mainFile })
const functionIsESM = await detectEsModule({ mainFile })

if (functionIsESM) {
return 'nft'
}
}

return 'zisi'
return functionIsESM ? 'nft' : 'zisi'
}
41 changes: 6 additions & 35 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ testMany(
nodeVersion: 'nodejs12.x',
},
},
featureFlags: { zisi_detect_esm: true, zisi_pure_esm: false },
featureFlags: { zisi_pure_esm: false },
})
const { files, tmpDir } = await zipFixture(t, fixtureName, {
length,
Expand Down Expand Up @@ -517,7 +517,7 @@ testMany(
nodeVersion: 'nodejs12.x',
},
},
featureFlags: { zisi_detect_esm: true, zisi_pure_esm: false },
featureFlags: { zisi_pure_esm: false },
})
const { tmpDir } = await zipFixture(t, fixtureName, {
length,
Expand Down Expand Up @@ -559,11 +559,8 @@ testMany(
testMany(
'Can bundle CJS functions that import ESM files with an `import()` expression',
['bundler_default', 'bundler_esbuild', 'bundler_nft'],
async (options, t) => {
async (opts, t) => {
const fixtureName = 'node-cjs-importing-mjs'
const opts = merge(options, {
featureFlags: { zisi_detect_esm: true },
})
const { files, tmpDir } = await zipFixture(t, fixtureName, {
opts,
})
Expand All @@ -590,7 +587,7 @@ testMany(
const fixtureName = 'node-esm'
const opts = merge(options, {
basePath: join(FIXTURES_DIR, fixtureName),
featureFlags: { zisi_detect_esm: true, zisi_pure_esm: true },
featureFlags: { zisi_pure_esm: true },
})
const { files, tmpDir } = await zipFixture(t, fixtureName, {
length,
Expand Down Expand Up @@ -622,7 +619,6 @@ testMany(
const fixtureName = 'node-esm'
const opts = merge(options, {
basePath: join(FIXTURES_DIR, fixtureName),
featureFlags: { zisi_detect_esm: true },
})
const { files, tmpDir } = await zipFixture(t, fixtureName, {
length,
Expand Down Expand Up @@ -2226,9 +2222,6 @@ test.serial('Zips Go functions built from source if the `zipGo` config property
zipGo: true,
},
},
featureFlags: {
buildGoSource: true,
},
},
})
const [func] = files
Expand All @@ -2244,27 +2237,12 @@ test.serial('Zips Go functions built from source if the `zipGo` config property
t.is(mockSource, unzippedBinaryContents)
})

test.serial('Does not build Go functions from source if the `buildGoSource` feature flag is not enabled', async (t) => {
shellUtilsStub.callsFake((...args) => writeFile(args[1][2], ''))

const fixtureName = 'go-source-multiple'
const { files } = await zipFixture(t, fixtureName, { length: 0 })

t.is(files.length, 0)
t.is(shellUtilsStub.callCount, 0)
})

test.serial('Builds Go functions from source if the `buildGoSource` feature flag is enabled', async (t) => {
test.serial('Builds Go functions from source', async (t) => {
shellUtilsStub.callsFake((...args) => writeFile(args[1][2], ''))

const fixtureName = 'go-source-multiple'
const { files } = await zipFixture(t, fixtureName, {
length: 2,
opts: {
featureFlags: {
buildGoSource: true,
},
},
})

t.is(shellUtilsStub.callCount, 2)
Expand Down Expand Up @@ -2301,13 +2279,7 @@ test.serial('Adds `type: "functionsBundling"` to errors resulting from compiling
})

try {
await zipFixture(t, 'go-source', {
opts: {
featureFlags: {
buildGoSource: true,
},
},
})
await zipFixture(t, 'go-source')

t.fail('Expected catch block')
} catch (error) {
Expand Down Expand Up @@ -2640,7 +2612,6 @@ test('Generates a sourcemap for any transpiled files when `nodeSourcemap: true`'
archiveFormat: 'none',
basePath,
config: { '*': { nodeBundler: 'nft', nodeSourcemap: true } },
featureFlags: { nftTranspile: true },
danez marked this conversation as resolved.
Show resolved Hide resolved
},
})
const func = await importFunctionFile(join(files[0].path, 'function.js'))
Expand Down