Skip to content

Commit

Permalink
fix(app-builder): skip incrementing files that do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 31, 2023
1 parent db7510d commit 25821f9
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions apps/app-builder/src/commands/increment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import path from 'path';
import fs from 'fs';
import glob from 'fast-glob';
import chalk from 'chalk';
import {isOfType} from '@myparcel/ts-utils';
import {executePromises, getFileContents, logSourcePath, reportDryRun, resolveStrings, usesPhpScoper} from '../utils';
import {
executePromises,
exists,
getFileContents,
logSourcePath,
reportDryRun,
resolvePath,
resolveStrings,
usesPhpScoper,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {
type RegexVersionSource,
Expand Down Expand Up @@ -31,17 +39,24 @@ const increment: PdkBuilderCommand = async (context) => {
sources.push(`${config.phpScoper.vendorOutDir}/${source.path}`);
}

const strings = resolveStrings(context, sources);

return {source, files: glob.sync(strings, {cwd: env.cwd})};
return {source, files: glob.sync(resolveStrings(context, sources), {cwd: env.cwd})};
});

await executePromises(
args,
matches.map(async ({files, source: match}) => {
return Promise.all(
files.sort().map(async (file) => {
const filePath = path.resolve(env.cwd, file);
const filePath = resolvePath(file, context);

if (!(await exists(filePath))) {
if (context.args.verbose >= VerbosityLevel.VeryVerbose) {
debug('Skipping %s', logSourcePath(filePath, context));
}

return;
}

const contents = await getFileContents(filePath);

let output: VersionReplacerOutput;
Expand All @@ -51,14 +66,11 @@ const increment: PdkBuilderCommand = async (context) => {
}

if (isOfType<RegexVersionSource>(match, 'regex')) {
output = replaceVersionByRegex({match, contents, newVersion}, {config, args, debug});
output = replaceVersionByRegex({match, contents, newVersion}, context);
} else if (filePath.endsWith('.json')) {
output = replaceVersionInJson({match, contents, newVersion}, {config, args, debug});
output = replaceVersionInJson({match, contents, newVersion}, context);
} else {
output = replaceVersionByRegex(
{match: {...match, regex: REGEX_VERSION}, contents, newVersion},
{config, args, debug},
);
output = replaceVersionByRegex({match: {...match, regex: REGEX_VERSION}, contents, newVersion}, context);
}

if (!args.dryRun) {
Expand Down

0 comments on commit 25821f9

Please sign in to comment.