diff --git a/src/convert/replacements.ts b/src/convert/replacements.ts index b134e1ddfc..2ad1fd3eda 100644 --- a/src/convert/replacements.ts +++ b/src/convert/replacements.ts @@ -6,6 +6,7 @@ */ import { readFile } from 'fs/promises'; import { Transform, Readable } from 'stream'; +import { sep, posix } from 'path'; import { Lifecycle, Messages, SfProject } from '@salesforce/core'; import * as minimatch from 'minimatch'; import { Env } from '@salesforce/kit'; @@ -194,7 +195,7 @@ export const getReplacements = async ( export const matchesFile = (f: string, r: ReplacementConfig): boolean => // filenames will be absolute. We don't have convenient access to the pkgDirs, // so we need to be more open than an exact match - Boolean((r.filename && f.endsWith(r.filename)) || (r.glob && minimatch(f, `**/${r.glob}`))); + Boolean((r.filename && posixifyPaths(f).endsWith(r.filename)) || (r.glob && minimatch(f, `**/${r.glob}`))); /** * Regardless of any components, return the ReplacementConfig that are valid with the current env. @@ -228,3 +229,5 @@ export const stringToRegex = (input: string): RegExp => // being overly conservative // eslint-disable-next-line no-useless-escape new RegExp(input.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'); + +const posixifyPaths = (f: string): string => f.split(sep).join(posix.sep); diff --git a/test/convert/replacements.test.ts b/test/convert/replacements.test.ts index c3bd82934c..9e02136352 100644 --- a/test/convert/replacements.test.ts +++ b/test/convert/replacements.test.ts @@ -18,6 +18,10 @@ describe('file matching', () => { expect(matchesFile('foo', { filename: 'foo', ...base })).to.be.true; expect(matchesFile('bar', { filename: 'foo', ...base })).to.not.be.true; }); + it('paths with separators to cover possibility of windows paths', () => { + expect(matchesFile(path.join('foo', 'bar'), { filename: 'foo/bar', ...base })).to.be.true; + expect(matchesFile(path.join('foo', 'bar'), { filename: 'foo/baz', ...base })).to.not.be.true; + }); it('file matches glob (posix paths)', () => { expect(matchesFile('foo/bar', { glob: 'foo/**', ...base })).to.be.true; expect(matchesFile('foo/bar', { glob: 'foo/*', ...base })).to.be.true;