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

Commit 655f1a8

Browse files
author
Lukas Holzer
authored
chore: put the symlink fix behind a feature flag (#1704)
1 parent 8ebae9d commit 655f1a8

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

src/feature_flags.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const defaultFlags = {
2929

3030
// drops the "runtimeVersion" override field
3131
zisi_go_drop_runtime_override: false,
32+
33+
// fixes symlinks in included files
34+
zisi_fix_symlinks: false,
3235
} as const
3336

3437
export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>

src/runtimes/node/bundlers/esbuild/src_files.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import { getNewCache, TraversalCache } from '../../utils/traversal_cache.js'
44
import type { GetSrcFilesFunction } from '../types.js'
55
import { getDependencyPathsForDependency } from '../zisi/traverse.js'
66

7-
export const getSrcFiles: GetSrcFilesFunction = async ({ config, mainFile, pluginsModulesPath, srcDir }) => {
7+
export const getSrcFiles: GetSrcFilesFunction = async ({
8+
config,
9+
mainFile,
10+
pluginsModulesPath,
11+
srcDir,
12+
featureFlags,
13+
}) => {
814
const { externalNodeModules = [], includedFiles = [], includedFilesBasePath, nodeVersion } = config
915
const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles(
1016
includedFiles,
17+
featureFlags,
1118
includedFilesBasePath,
1219
)
1320
const dependencyPaths = await getSrcFilesForDependencies({

src/runtimes/node/bundlers/nft/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const bundle: BundleFunction = async ({
5353

5454
const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles(
5555
includedFiles,
56+
featureFlags,
5657
includedFilesBasePath || basePath,
5758
)
5859
const {
@@ -238,10 +239,11 @@ const traceFilesAndTranspile = async function ({
238239
}
239240
}
240241

241-
const getSrcFiles: GetSrcFilesFunction = async function ({ basePath, config, mainFile }) {
242+
const getSrcFiles: GetSrcFilesFunction = async function ({ basePath, config, mainFile, featureFlags }) {
242243
const { includedFiles = [], includedFilesBasePath } = config
243244
const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles(
244245
includedFiles,
246+
featureFlags,
245247
includedFilesBasePath,
246248
)
247249
const { fileList: dependencyPaths } = await nodeFileTrace([mainFile], {

src/runtimes/node/bundlers/none/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ const getModuleFormat = async function (mainFile: string): Promise<ModuleFormat>
3737
return MODULE_FORMAT.COMMONJS
3838
}
3939

40-
export const getSrcFiles: GetSrcFilesFunction = async function ({ config, mainFile }) {
40+
export const getSrcFiles: GetSrcFilesFunction = async function ({ config, mainFile, featureFlags }) {
4141
const { includedFiles = [], includedFilesBasePath } = config
4242
const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles(
4343
includedFiles,
44+
featureFlags,
4445
includedFilesBasePath,
4546
)
4647
const includedPaths = filterExcludedPaths(includedFilePaths, excludePatterns)

src/runtimes/node/bundlers/zisi/src_files.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const getSrcFiles: GetSrcFilesFunction = async function ({
3131
const { includedFiles = [], includedFilesBasePath, nodeVersion } = config
3232
const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles(
3333
includedFiles,
34+
featureFlags,
3435
includedFilesBasePath,
3536
)
3637
const [treeFiles, depFiles] = await Promise.all([

src/runtimes/node/utils/included_files.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { normalize, resolve } from 'path'
22

33
import fastGlob from 'fast-glob'
44

5+
import { type FeatureFlags } from '../../../feature_flags.js'
56
import { minimatch } from '../../../utils/matching.js'
67

78
// Returns the subset of `paths` that don't match any of the glob expressions
@@ -18,6 +19,7 @@ export const filterExcludedPaths = (paths: string[], excludePattern: string[] =
1819

1920
export const getPathsOfIncludedFiles = async (
2021
includedFiles: string[],
22+
featureFlags: FeatureFlags,
2123
basePath?: string,
2224
): Promise<{ excludePatterns: string[]; paths: string[] }> => {
2325
if (basePath === undefined) {
@@ -53,13 +55,24 @@ export const getPathsOfIncludedFiles = async (
5355
cwd: basePath,
5456
dot: true,
5557
ignore: excludePatterns,
56-
onlyFiles: false,
57-
// get directories as well to get symlinked directories,
58-
// to filter the regular non symlinked directories out mark them with a slash at the end to filter them out.
59-
markDirectories: true,
60-
followSymbolicLinks: false,
58+
...(featureFlags.zisi_fix_symlinks
59+
? {
60+
onlyFiles: false,
61+
// get directories as well to get symlinked directories,
62+
// to filter the regular non symlinked directories out mark them with a slash at the end to filter them out.
63+
markDirectories: true,
64+
followSymbolicLinks: false,
65+
}
66+
: {
67+
followSymbolicLinks: true,
68+
throwErrorOnBrokenSymbolicLink: true,
69+
}),
6170
})
6271

72+
const paths = featureFlags.zisi_fix_symlinks
73+
? pathGroups.filter((path) => !path.endsWith('/')).map(normalize)
74+
: pathGroups.map(normalize)
75+
6376
// now filter the non symlinked directories out that got marked with a trailing slash
64-
return { excludePatterns, paths: pathGroups.filter((path) => !path.endsWith('/')).map(normalize) }
77+
return { excludePatterns, paths }
6578
}

tests/symlinked_included_files.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ test.skipIf(platform() === 'win32')('Symlinked directories from `includedFiles`
4646
includedFiles: ['**'],
4747
},
4848
},
49-
featureFlags: {},
49+
featureFlags: {
50+
zisi_fix_symlinks: true,
51+
},
5052
repositoryRoot: basePath,
5153
systemLog: console.log,
5254
debug: true,

0 commit comments

Comments
 (0)