Skip to content

Commit

Permalink
fix: windows path replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 5, 2023
1 parent 684952e commit 0f48ae5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/convert/replacements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
4 changes: 4 additions & 0 deletions test/convert/replacements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

2 comments on commit 0f48ae5

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 0f48ae5 Previous: 3c4dff8 Ratio
eda-componentSetCreate-linux 265 ms 334 ms 0.79
eda-sourceToMdapi-linux 5548 ms 7389 ms 0.75
eda-sourceToZip-linux 5225 ms 6251 ms 0.84
eda-mdapiToSource-linux 4927 ms 5902 ms 0.83
lotsOfClasses-componentSetCreate-linux 537 ms 693 ms 0.77
lotsOfClasses-sourceToMdapi-linux 8275 ms 11793 ms 0.70
lotsOfClasses-sourceToZip-linux 7903 ms 8651 ms 0.91
lotsOfClasses-mdapiToSource-linux 5773 ms 7179 ms 0.80
lotsOfClassesOneDir-componentSetCreate-linux 909 ms 1096 ms 0.83
lotsOfClassesOneDir-sourceToMdapi-linux 14194 ms 17378 ms 0.82
lotsOfClassesOneDir-sourceToZip-linux 11961 ms 13416 ms 0.89
lotsOfClassesOneDir-mdapiToSource-linux 10464 ms 13070 ms 0.80

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 0f48ae5 Previous: 3c4dff8 Ratio
eda-componentSetCreate-win32 398 ms 678 ms 0.59
eda-sourceToMdapi-win32 8448 ms 12153 ms 0.70
eda-sourceToZip-win32 7687 ms 7779 ms 0.99
eda-mdapiToSource-win32 8091 ms 11653 ms 0.69
lotsOfClasses-componentSetCreate-win32 838 ms 1534 ms 0.55
lotsOfClasses-sourceToMdapi-win32 12074 ms 15807 ms 0.76
lotsOfClasses-sourceToZip-win32 8500 ms 11174 ms 0.76
lotsOfClasses-mdapiToSource-win32 9474 ms 13776 ms 0.69
lotsOfClassesOneDir-componentSetCreate-win32 1533 ms 2775 ms 0.55
lotsOfClassesOneDir-sourceToMdapi-win32 19105 ms 27913 ms 0.68
lotsOfClassesOneDir-sourceToZip-win32 13898 ms 17957 ms 0.77
lotsOfClassesOneDir-mdapiToSource-win32 16920 ms 25267 ms 0.67

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.