diff --git a/apps/app-builder/src/__tests__/__snapshots__/exports.spec.ts.snap b/apps/app-builder/src/__tests__/__snapshots__/exports.spec.ts.snap index deba4d911..6c408f5eb 100644 --- a/apps/app-builder/src/__tests__/__snapshots__/exports.spec.ts.snap +++ b/apps/app-builder/src/__tests__/__snapshots__/exports.spec.ts.snap @@ -12,6 +12,7 @@ exports[`exports > exports from index.ts 1`] = ` "getFileContents", "getPlatformDistPath", "getRelativePath", + "globFiles", "isEmptyDir", "isVerbose", "isVeryVerbose", diff --git a/apps/app-builder/src/commands/copy.ts b/apps/app-builder/src/commands/copy.ts index 281840fa1..e58c23331 100644 --- a/apps/app-builder/src/commands/copy.ts +++ b/apps/app-builder/src/commands/copy.ts @@ -1,4 +1,3 @@ -import glob from 'fast-glob'; import chalk from 'chalk'; import { addPlatformToContext, @@ -6,6 +5,7 @@ import { copyScopedFiles, executePromises, getPlatformDistPath, + globFiles, logPlatforms, logTargetPath, resolvePath, @@ -14,15 +14,14 @@ import { import {type PdkBuilderCommand} from '../types'; const copy: PdkBuilderCommand = async (context) => { - const {env, config, args, debug} = context; + const {config, args, debug} = context; - const resolvedSources = resolveStrings(context, config.source); - const files = glob.sync(resolvedSources, {cwd: env.cwd}); + const files = globFiles(config.source, context); debug( 'Copying %s files from %s to %s for platforms %s', chalk.greenBright(files.length), - chalk.yellow(resolvedSources), + chalk.yellow(resolveStrings(context, config.source)), logTargetPath(config.outDir, context), logPlatforms(config.platforms), ); diff --git a/apps/app-builder/src/commands/increment.ts b/apps/app-builder/src/commands/increment.ts index 890a12b62..410ffb6d2 100644 --- a/apps/app-builder/src/commands/increment.ts +++ b/apps/app-builder/src/commands/increment.ts @@ -1,15 +1,14 @@ -import glob from 'fast-glob'; import chalk from 'chalk'; import {isOfType} from '@myparcel/ts-utils'; import { executePromises, exists, getFileContents, + globFiles, isVerbose, logSourcePath, reportFileDoesNotExist, resolvePath, - resolveStrings, usesPhpScoper, writeFile, } from '../utils'; @@ -38,7 +37,7 @@ const increment: PdkBuilderCommand = async (context) => { sources.push(`${config.phpScoper.vendorOutDir}/${source.path}`); } - return {source, files: glob.sync(resolveStrings(context, sources), {cwd: env.cwd})}; + return {source, files: globFiles(sources, context)}; }); await executePromises( diff --git a/apps/app-builder/src/commands/rename.ts b/apps/app-builder/src/commands/rename.ts index dc481698d..9144042f9 100644 --- a/apps/app-builder/src/commands/rename.ts +++ b/apps/app-builder/src/commands/rename.ts @@ -1,11 +1,11 @@ /* eslint-disable max-lines-per-function */ import path from 'path'; -import glob from 'fast-glob'; import chalk from 'chalk'; import { addPlatformToContext, executePromises, getPlatformDistPath, + globFiles, logRelativePath, renameFile, replaceCaseSensitive, @@ -17,7 +17,7 @@ import {type PdkBuilderCommand} from '../types'; const STRING_TO_REPLACE = 'myparcelnl'; const rename: PdkBuilderCommand = async (context) => { - const {env, config, args, debug} = context; + const {config, args, debug} = context; debug('Renaming files for platforms %s', chalk.cyanBright(config.platforms.join(', '))); @@ -33,9 +33,8 @@ const rename: PdkBuilderCommand = async (context) => { debug('Renaming files in %s', logRelativePath(platformDistPath, platformContext)); - const files = glob.sync(`${platformDistPath}/**/*`, { + const files = globFiles(`${platformDistPath}/**/*`, context, { ignore: [`${platformDistPath}/node_modules/**/*`, `${platformDistPath}/vendor/**/*`], - cwd: env.cwd, }); await Promise.all( diff --git a/apps/app-builder/src/commands/transform.ts b/apps/app-builder/src/commands/transform.ts index 7fc96eee4..2533a5e75 100644 --- a/apps/app-builder/src/commands/transform.ts +++ b/apps/app-builder/src/commands/transform.ts @@ -1,11 +1,11 @@ /* eslint-disable max-lines-per-function */ -import glob from 'fast-glob'; import chalk from 'chalk'; import { addPlatformToContext, executePromises, getFileContents, getOccurrences, + globFiles, isVeryVeryVerbose, logPlatforms, logSourcePath, @@ -44,7 +44,7 @@ const transform: PdkBuilderCommand = async (context) => { debug('Transforming files in %s', logSourcePath(platformFolderPath, platformContext)); - const files = glob.sync(`${platformFolderPath}/**/*`, { + const files = globFiles(`${platformFolderPath}/**/*`, context, { ignore: [ `${platformFolderPath}/node_modules/**/*`, `${platformFolderPath}/package.json`, @@ -53,7 +53,6 @@ const transform: PdkBuilderCommand = async (context) => { `${platformFolderPath}/**/*.map`, `${platformFolderPath}/**/*.d.ts`, ], - cwd: env.cwd, }); const promises = await Promise.all( diff --git a/apps/app-builder/src/index.ts b/apps/app-builder/src/index.ts index 67162b9a8..f0af24062 100644 --- a/apps/app-builder/src/index.ts +++ b/apps/app-builder/src/index.ts @@ -17,6 +17,7 @@ export { getFileContents, getPlatformDistPath, getRelativePath, + globFiles, isEmptyDir, isVerbose, isVeryVerbose, diff --git a/apps/app-builder/src/utils/copyScopedFiles.ts b/apps/app-builder/src/utils/copyScopedFiles.ts index dd6776ea1..d08160391 100644 --- a/apps/app-builder/src/utils/copyScopedFiles.ts +++ b/apps/app-builder/src/utils/copyScopedFiles.ts @@ -1,7 +1,7 @@ -import glob from 'fast-glob'; import {type PdkBuilderContext} from '../types'; import {usesPhpScoper} from './usesPhpScoper'; import {resolvePath} from './resolvePath'; +import {globFiles} from './globFiles'; import {getPlatformDistPath} from './getPlatformDistPath'; import {copyFile} from './fs'; import {executePromises} from './executePromises'; @@ -13,7 +13,7 @@ export const copyScopedFiles = async (context: PdkBuilderContext): Promise return; } - const {env, config, args, debug} = context; + const {config, args, debug} = context; await executePromises( args, @@ -26,7 +26,7 @@ export const copyScopedFiles = async (context: PdkBuilderContext): Promise const scopedVendorDir = resolvePath(config.phpScoper.vendorOutDir, context); await Promise.all([ - ...glob.sync(`${scopedVendorDir}/**/*`, {cwd: env.cwd}).map(async (file) => { + ...globFiles(`${scopedVendorDir}/**/*`, context).map(async (file) => { await copyFile( file, file.replace(scopedVendorDir, resolvePath([platformDistPath, 'vendor'], context)), @@ -34,7 +34,7 @@ export const copyScopedFiles = async (context: PdkBuilderContext): Promise ); }), - ...glob.sync(`${scopedSourceDir}/**/*`, {cwd: env.cwd}).map(async (file) => { + ...globFiles(`${scopedSourceDir}/**/*`, context).map(async (file) => { await copyFile(file, file.replace(scopedSourceDir, platformDistPath), context); }), ]); diff --git a/apps/app-builder/src/utils/globFiles.ts b/apps/app-builder/src/utils/globFiles.ts new file mode 100644 index 000000000..2abbd7ad9 --- /dev/null +++ b/apps/app-builder/src/utils/globFiles.ts @@ -0,0 +1,12 @@ +import glob, {type Options} from 'fast-glob'; +import {type OneOrMore} from '@myparcel/ts-utils'; +import {type PdkBuilderContext, type StringGenerator} from '../types'; +import {resolveStrings} from './resolveStrings'; + +export const globFiles = ( + patterns: OneOrMore, + context: PdkBuilderContext, + options: Options = {}, +): string[] => { + return glob.sync(resolveStrings(context, patterns), {cwd: context.env.cwd, ...options}); +}; diff --git a/apps/app-builder/src/utils/index.ts b/apps/app-builder/src/utils/index.ts index 5a6591277..f284dc630 100644 --- a/apps/app-builder/src/utils/index.ts +++ b/apps/app-builder/src/utils/index.ts @@ -9,6 +9,7 @@ export * from './executePromises'; export * from './fs'; export * from './getPlatformDistPath'; export * from './getRelativePath'; +export * from './globFiles'; export * from './mergeDefaultConfig'; export * from './parseJsonFile'; export * from './resolveConfig';