From 88ba1ef2de9674fd6baae67cfc6aaf04cf63891c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 7 Mar 2018 19:54:19 -0800 Subject: [PATCH] Platform independent wildcard file include ordering (#22393) * Resolve config wildcards result order in a platform independent manner * Accept affected user test baseline * Per reccomendation, just change matchFiles * Add test asserting the same order on differing case sensitive platforms --- src/compiler/core.ts | 5 ++- src/harness/unittests/matchFiles.ts | 32 +++++++++++++++++++ .../user/chrome-devtools-frontend.log | 4 +-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index d44cbf4a72de4..33cd19d207c98 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2539,7 +2539,6 @@ namespace ts { path = normalizePath(path); currentDirectory = normalizePath(currentDirectory); - const comparer = useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive; const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory); const regexFlag = useCaseSensitiveFileNames ? "" : "i"; @@ -2560,7 +2559,7 @@ namespace ts { function visitDirectory(path: string, absolutePath: string, depth: number | undefined) { const { files, directories } = getFileSystemEntries(path); - for (const current of sort(files, comparer)) { + for (const current of sort(files, compareStringsCaseSensitive)) { const name = combinePaths(path, current); const absoluteName = combinePaths(absolutePath, current); if (extensions && !fileExtensionIsOneOf(name, extensions)) continue; @@ -2583,7 +2582,7 @@ namespace ts { } } - for (const current of sort(directories, comparer)) { + for (const current of sort(directories, compareStringsCaseSensitive)) { const name = combinePaths(path, current); const absoluteName = combinePaths(absolutePath, current); if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) && diff --git a/src/harness/unittests/matchFiles.ts b/src/harness/unittests/matchFiles.ts index bbefd24bb57d6..b2f41ba4fa2fa 100644 --- a/src/harness/unittests/matchFiles.ts +++ b/src/harness/unittests/matchFiles.ts @@ -91,6 +91,18 @@ namespace ts { "c:/dev/g.min.js/.g/g.ts" ]); + const caseInsensitiveOrderingDiffersWithCaseHost = new Utils.MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [ + "c:/dev/xylophone.ts", + "c:/dev/Yosemite.ts", + "c:/dev/zebra.ts", + ]); + + const caseSensitiveOrderingDiffersWithCaseHost = new Utils.MockParseConfigHost(caseSensitiveBasePath, /*useCaseSensitiveFileNames*/ true, [ + "/dev/xylophone.ts", + "/dev/Yosemite.ts", + "/dev/zebra.ts", + ]); + function assertParsed(actual: ParsedCommandLine, expected: ParsedCommandLine): void { assert.deepEqual(actual.fileNames, expected.fileNames); assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); @@ -1482,5 +1494,25 @@ namespace ts { validateMatches(expected, json, caseSensitiveHost, caseSensitiveBasePath); }); }); + + it("can include files in the same order on multiple platforms", () => { + function getExpected(basePath: string): ParsedCommandLine { + return { + options: {}, + errors: [], + fileNames: [ + `${basePath}Yosemite.ts`, // capital always comes before lowercase letters + `${basePath}xylophone.ts`, + `${basePath}zebra.ts` + ], + wildcardDirectories: { + [basePath.slice(0, basePath.length - 1)]: WatchDirectoryFlags.Recursive + }, + }; + } + const json = {}; + validateMatches(getExpected(caseSensitiveBasePath), json, caseSensitiveOrderingDiffersWithCaseHost, caseSensitiveBasePath); + validateMatches(getExpected(caseInsensitiveBasePath), json, caseInsensitiveOrderingDiffersWithCaseHost, caseInsensitiveBasePath); + }); }); } diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index 9d5f478f0a990..75335f4256e4b 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -13074,9 +13074,9 @@ node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1057,39): node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1108,15): error TS2339: Property 'valuesArray' does not exist on type 'Set'. node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1116,15): error TS2339: Property 'firstValue' does not exist on type 'Set'. node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1126,15): error TS2339: Property 'addAll' does not exist on type 'Set'. -node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1127,17): error TS2495: Type 'T[] | Iterable' is not an array type or a string type. +node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1127,17): error TS2495: Type 'Iterable | T[]' is not an array type or a string type. node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1136,15): error TS2339: Property 'containsAll' does not exist on type 'Set'. -node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1137,17): error TS2495: Type 'T[] | Iterable' is not an array type or a string type. +node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1137,17): error TS2495: Type 'Iterable | T[]' is not an array type or a string type. node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1148,15): error TS2339: Property 'remove' does not exist on type 'Map'. node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1155,21): error TS2304: Cannot find name 'VALUE'. node_modules/chrome-devtools-frontend/front_end/platform/utilities.js(1157,15): error TS2339: Property 'valuesArray' does not exist on type 'Map'.