diff --git a/src/feature_flags.ts b/src/feature_flags.ts index d0c07a446..e72193ef2 100644 --- a/src/feature_flags.ts +++ b/src/feature_flags.ts @@ -29,6 +29,9 @@ export const defaultFlags = { // drops the "runtimeVersion" override field zisi_go_drop_runtime_override: false, + + // fixes symlinks in included files + zisi_fix_symlinks: false, } as const export type FeatureFlags = Partial> diff --git a/src/runtimes/node/bundlers/esbuild/src_files.ts b/src/runtimes/node/bundlers/esbuild/src_files.ts index e5029ea57..1e64f0962 100644 --- a/src/runtimes/node/bundlers/esbuild/src_files.ts +++ b/src/runtimes/node/bundlers/esbuild/src_files.ts @@ -4,10 +4,17 @@ import { getNewCache, TraversalCache } from '../../utils/traversal_cache.js' import type { GetSrcFilesFunction } from '../types.js' import { getDependencyPathsForDependency } from '../zisi/traverse.js' -export const getSrcFiles: GetSrcFilesFunction = async ({ config, mainFile, pluginsModulesPath, srcDir }) => { +export const getSrcFiles: GetSrcFilesFunction = async ({ + config, + mainFile, + pluginsModulesPath, + srcDir, + featureFlags, +}) => { const { externalNodeModules = [], includedFiles = [], includedFilesBasePath, nodeVersion } = config const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles( includedFiles, + featureFlags, includedFilesBasePath, ) const dependencyPaths = await getSrcFilesForDependencies({ diff --git a/src/runtimes/node/bundlers/nft/index.ts b/src/runtimes/node/bundlers/nft/index.ts index f65ad3ed2..e4f6faf1e 100644 --- a/src/runtimes/node/bundlers/nft/index.ts +++ b/src/runtimes/node/bundlers/nft/index.ts @@ -53,6 +53,7 @@ const bundle: BundleFunction = async ({ const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles( includedFiles, + featureFlags, includedFilesBasePath || basePath, ) const { @@ -238,10 +239,11 @@ const traceFilesAndTranspile = async function ({ } } -const getSrcFiles: GetSrcFilesFunction = async function ({ basePath, config, mainFile }) { +const getSrcFiles: GetSrcFilesFunction = async function ({ basePath, config, mainFile, featureFlags }) { const { includedFiles = [], includedFilesBasePath } = config const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles( includedFiles, + featureFlags, includedFilesBasePath, ) const { fileList: dependencyPaths } = await nodeFileTrace([mainFile], { diff --git a/src/runtimes/node/bundlers/none/index.ts b/src/runtimes/node/bundlers/none/index.ts index 66153c672..12816da84 100644 --- a/src/runtimes/node/bundlers/none/index.ts +++ b/src/runtimes/node/bundlers/none/index.ts @@ -37,10 +37,11 @@ const getModuleFormat = async function (mainFile: string): Promise return MODULE_FORMAT.COMMONJS } -export const getSrcFiles: GetSrcFilesFunction = async function ({ config, mainFile }) { +export const getSrcFiles: GetSrcFilesFunction = async function ({ config, mainFile, featureFlags }) { const { includedFiles = [], includedFilesBasePath } = config const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles( includedFiles, + featureFlags, includedFilesBasePath, ) const includedPaths = filterExcludedPaths(includedFilePaths, excludePatterns) diff --git a/src/runtimes/node/bundlers/zisi/src_files.ts b/src/runtimes/node/bundlers/zisi/src_files.ts index fe3e3cd7b..46f30d537 100644 --- a/src/runtimes/node/bundlers/zisi/src_files.ts +++ b/src/runtimes/node/bundlers/zisi/src_files.ts @@ -31,6 +31,7 @@ export const getSrcFiles: GetSrcFilesFunction = async function ({ const { includedFiles = [], includedFilesBasePath, nodeVersion } = config const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles( includedFiles, + featureFlags, includedFilesBasePath, ) const [treeFiles, depFiles] = await Promise.all([ diff --git a/src/runtimes/node/utils/included_files.ts b/src/runtimes/node/utils/included_files.ts index 43d447fb2..dab51d1e4 100644 --- a/src/runtimes/node/utils/included_files.ts +++ b/src/runtimes/node/utils/included_files.ts @@ -2,6 +2,7 @@ import { normalize, resolve } from 'path' import fastGlob from 'fast-glob' +import { type FeatureFlags } from '../../../feature_flags.js' import { minimatch } from '../../../utils/matching.js' // 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[] = export const getPathsOfIncludedFiles = async ( includedFiles: string[], + featureFlags: FeatureFlags, basePath?: string, ): Promise<{ excludePatterns: string[]; paths: string[] }> => { if (basePath === undefined) { @@ -53,13 +55,24 @@ export const getPathsOfIncludedFiles = async ( cwd: basePath, dot: true, ignore: excludePatterns, - onlyFiles: false, - // get directories as well to get symlinked directories, - // to filter the regular non symlinked directories out mark them with a slash at the end to filter them out. - markDirectories: true, - followSymbolicLinks: false, + ...(featureFlags.zisi_fix_symlinks + ? { + onlyFiles: false, + // get directories as well to get symlinked directories, + // to filter the regular non symlinked directories out mark them with a slash at the end to filter them out. + markDirectories: true, + followSymbolicLinks: false, + } + : { + followSymbolicLinks: true, + throwErrorOnBrokenSymbolicLink: true, + }), }) + const paths = featureFlags.zisi_fix_symlinks + ? pathGroups.filter((path) => !path.endsWith('/')).map(normalize) + : pathGroups.map(normalize) + // now filter the non symlinked directories out that got marked with a trailing slash - return { excludePatterns, paths: pathGroups.filter((path) => !path.endsWith('/')).map(normalize) } + return { excludePatterns, paths } } diff --git a/tests/symlinked_included_files.test.ts b/tests/symlinked_included_files.test.ts index 5616a7b2a..8bb7d93b4 100644 --- a/tests/symlinked_included_files.test.ts +++ b/tests/symlinked_included_files.test.ts @@ -46,7 +46,9 @@ test.skipIf(platform() === 'win32')('Symlinked directories from `includedFiles` includedFiles: ['**'], }, }, - featureFlags: {}, + featureFlags: { + zisi_fix_symlinks: true, + }, repositoryRoot: basePath, systemLog: console.log, debug: true,