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

Commit

Permalink
chore: put the symlink fix behind a feature flag (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasholzer committed Jan 29, 2024
1 parent 8ebae9d commit 655f1a8
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/feature_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<keyof typeof defaultFlags, boolean>>
Expand Down
9 changes: 8 additions & 1 deletion src/runtimes/node/bundlers/esbuild/src_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 3 additions & 1 deletion src/runtimes/node/bundlers/nft/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const bundle: BundleFunction = async ({

const { excludePatterns, paths: includedFilePaths } = await getPathsOfIncludedFiles(
includedFiles,
featureFlags,
includedFilesBasePath || basePath,
)
const {
Expand Down Expand Up @@ -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], {
Expand Down
3 changes: 2 additions & 1 deletion src/runtimes/node/bundlers/none/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ const getModuleFormat = async function (mainFile: string): Promise<ModuleFormat>
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)
Expand Down
1 change: 1 addition & 0 deletions src/runtimes/node/bundlers/zisi/src_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
25 changes: 19 additions & 6 deletions src/runtimes/node/utils/included_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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 }
}
4 changes: 3 additions & 1 deletion tests/symlinked_included_files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

1 comment on commit 655f1a8

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 1.5s
  • largeDepsNft: 5.5s
  • largeDepsZisi: 10.4s

Please sign in to comment.