Skip to content

Commit 498ec1f

Browse files
Merge pull request #7650 from Shopify/revert-7498-bolt/optimize-startup-and-discovery-15894214764489785463
Revert "[Performance] Optimize CLI startup and project discovery"
2 parents 7f3abdc + 7cb7f72 commit 498ec1f

3 files changed

Lines changed: 7 additions & 53 deletions

File tree

packages/cli-kit/src/public/node/fs.test.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
generateRandomNameForSubdirectory,
1919
readFileSync,
2020
glob,
21-
globSync,
2221
detectEOL,
2322
copyDirectoryContents,
2423
symlink,
@@ -320,40 +319,6 @@ describe('glob', () => {
320319
})
321320
})
322321

323-
describe('globSync', () => {
324-
test('returns matches for the given pattern, including dotfiles by default (dot:true)', async () => {
325-
await inTemporaryDirectory(async (tmpDir) => {
326-
// Given
327-
const visiblePath = joinPath(tmpDir, 'visible.toml')
328-
const hiddenPath = joinPath(tmpDir, '.hidden.toml')
329-
await writeFile(visiblePath, '')
330-
await writeFile(hiddenPath, '')
331-
332-
// When
333-
const matches = globSync(joinPath(tmpDir, '*.toml')).map(normalizePath).sort()
334-
335-
// Then
336-
expect(matches).toEqual([normalizePath(hiddenPath), normalizePath(visiblePath)].sort())
337-
})
338-
})
339-
340-
test('honors an explicit dot:false option, excluding dotfiles', async () => {
341-
await inTemporaryDirectory(async (tmpDir) => {
342-
// Given
343-
const visiblePath = joinPath(tmpDir, 'visible.toml')
344-
const hiddenPath = joinPath(tmpDir, '.hidden.toml')
345-
await writeFile(visiblePath, '')
346-
await writeFile(hiddenPath, '')
347-
348-
// When
349-
const matches = globSync(joinPath(tmpDir, '*.toml'), {dot: false}).map(normalizePath)
350-
351-
// Then
352-
expect(matches).toEqual([normalizePath(visiblePath)])
353-
})
354-
})
355-
})
356-
357322
describe('detectEOL', () => {
358323
test('detects the EOL of a file', async () => {
359324
// Given

packages/cli-kit/src/public/node/fs.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import {sep, join} from 'pathe'
1818
import {findUp as internalFindUp, findUpSync as internalFindUpSync} from 'find-up'
1919
import {minimatch} from 'minimatch'
20-
import {createRequire} from 'module'
20+
import fastGlobLib from 'fast-glob'
2121
import {
2222
mkdirSync as fsMkdirSync,
2323
readFileSync as fsReadFileSync,
@@ -33,6 +33,7 @@ import {
3333
accessSync,
3434
ReadStream,
3535
WriteStream,
36+
statSync,
3637
} from 'fs'
3738

3839
import {
@@ -57,8 +58,6 @@ import * as os from 'os'
5758

5859
import type {Pattern, Options as GlobOptions} from 'fast-glob'
5960

60-
const require = createRequire(import.meta.url)
61-
6261
/**
6362
* Strip the first `strip` parts of the path.
6463
*
@@ -511,7 +510,7 @@ export function unixFileIsOwnedByCurrentUser(path: string): boolean | undefined
511510
if (!fileExistsSync(path)) return false
512511

513512
try {
514-
const stats = fsStatSync(path)
513+
const stats = statSync(path)
515514
const currentUid = process.getuid()
516515

517516
return stats.uid === currentUid
@@ -595,13 +594,11 @@ export async function glob(pattern: Pattern | Pattern[], options?: GlobOptions):
595594
* @returns An array of pathnames that match the given pattern.
596595
*/
597596
export function globSync(pattern: Pattern | Pattern[], options?: GlobOptions): string[] {
598-
// Performance: fast-glob is a heavy dependency. We lazy-load it here to avoid
599-
// overhead during CLI startup for commands that don't need globbing.
600597
let overridenOptions = options
601598
if (options?.dot == null) {
602599
overridenOptions = {...options, dot: true}
603600
}
604-
return (require('fast-glob') as typeof import('fast-glob')).sync(pattern, overridenOptions)
601+
return fastGlobLib.sync(pattern, overridenOptions)
605602
}
606603

607604
/**

packages/cli-kit/src/public/node/is-global.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {cwd, dirname, isSubpath, joinPath, sniffForPath} from './path.js'
22
import {isUnitTest} from './context/local.js'
3-
import {findPathUpSync, globSync, fileExistsSync} from './fs.js'
3+
import {findPathUpSync, globSync} from './fs.js'
44
import {realpathSync} from 'fs'
55
import type {PackageManager} from './node-package-manager.js'
66

@@ -140,17 +140,9 @@ export function inferPackageManagerForGlobalCLI(argv = process.argv, env = proce
140140
* @returns The project root directory, or undefined if not found.
141141
*/
142142
export function getProjectDir(directory: string): string | undefined {
143-
// Performance: Check for the most common config files first using fileExistsSync (fast-path)
144-
// to avoid the overhead of globbing/directory scanning in the common case.
145-
const configFiles = ['shopify.app.toml', 'hydrogen.config.js', 'hydrogen.config.ts']
143+
const configFiles = ['shopify.app{,.*}.toml', 'hydrogen.config.js', 'hydrogen.config.ts']
146144
const existsConfigFile = (directory: string) => {
147-
for (const file of configFiles) {
148-
const configPath = joinPath(directory, file)
149-
if (fileExistsSync(configPath)) return configPath
150-
}
151-
152-
// Fallback to glob for custom app config files or if fast-path files were not found.
153-
const configPaths = globSync(joinPath(directory, 'shopify.app.*.toml'))
145+
const configPaths = globSync(configFiles.map((file) => joinPath(directory, file)))
154146
return configPaths.length > 0 ? configPaths[0] : undefined
155147
}
156148
try {

0 commit comments

Comments
 (0)