mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
On linux or editor with canUseEvents to prefer immediate directory if its not in root or node_modules (#58866)
This commit is contained in:
1 parent
fe0bdc8cde
commit
f7833b2a72
86 files changed
+135375
-230
No files matched your search
@@ -55,71 +55,77 @@ describe("unittests:: canWatch::", () => {
|
||||
scenario: string,
|
||||
forPath: "node_modules" | "node_modules/@types" | "",
|
||||
) {
|
||||
["file", "dir", "subDir"].forEach(type => {
|
||||
baselineCanWatch(
|
||||
`${scenario}In${type}`,
|
||||
() => `Determines whether to watch given failed lookup location (file that didnt exist) when resolving module.\r\nIt also determines the directory to watch and whether to watch it recursively or not.`,
|
||||
(paths, longestPathLength, baseline) => {
|
||||
const recursive = "Recursive";
|
||||
const maxLength = longestPathLength + ts.combinePaths(forPath, "dir/subdir/somefile.d.ts").length;
|
||||
const maxLengths = [maxLength, maxLength, recursive.length, maxLength] as const;
|
||||
baselineCanWatchForRoot(paths, baseline, (rootPathCompoments, root) => {
|
||||
pushHeader(baseline, ["Location", "getDirectoryToWatchFailedLookupLocation", recursive, "Location if not symlink"], maxLengths);
|
||||
paths.forEach(path => {
|
||||
let subPath;
|
||||
switch (type) {
|
||||
case "file":
|
||||
subPath = "somefile.d.ts";
|
||||
break;
|
||||
case "dir":
|
||||
subPath = "dir/somefile.d.ts";
|
||||
break;
|
||||
case "subDir":
|
||||
subPath = "dir/subdir/somefile.d.ts";
|
||||
break;
|
||||
}
|
||||
const testPath = combinePaths(path, forPath, subPath);
|
||||
const result = ts.getDirectoryToWatchFailedLookupLocation(
|
||||
testPath,
|
||||
testPath,
|
||||
root,
|
||||
root,
|
||||
rootPathCompoments,
|
||||
ts.returnUndefined,
|
||||
);
|
||||
pushRow(baseline, [testPath, result ? result.packageDir ?? result.dir : "", result ? `${!result.nonRecursive}` : "", result?.packageDir ? result.dir : ""], maxLengths);
|
||||
[undefined, true].forEach(preferNonRecursiveWatch => {
|
||||
["file", "dir", "subDir"].forEach(type => {
|
||||
baselineCanWatch(
|
||||
`${scenario}In${type}${preferNonRecursiveWatch ? "NonRecursive" : ""}`,
|
||||
() => `Determines whether to watch given failed lookup location (file that didnt exist) when resolving module.\r\nIt also determines the directory to watch and whether to watch it recursively or not.`,
|
||||
(paths, longestPathLength, baseline) => {
|
||||
const recursive = "Recursive";
|
||||
const maxLength = longestPathLength + ts.combinePaths(forPath, "dir/subdir/somefile.d.ts").length;
|
||||
const maxLengths = [maxLength, maxLength, recursive.length, maxLength] as const;
|
||||
baselineCanWatchForRoot(paths, baseline, (rootPathCompoments, root) => {
|
||||
pushHeader(baseline, ["Location", "getDirectoryToWatchFailedLookupLocation", recursive, "Location if not symlink"], maxLengths);
|
||||
paths.forEach(path => {
|
||||
let subPath;
|
||||
switch (type) {
|
||||
case "file":
|
||||
subPath = "somefile.d.ts";
|
||||
break;
|
||||
case "dir":
|
||||
subPath = "dir/somefile.d.ts";
|
||||
break;
|
||||
case "subDir":
|
||||
subPath = "dir/subdir/somefile.d.ts";
|
||||
break;
|
||||
}
|
||||
const testPath = combinePaths(path, forPath, subPath);
|
||||
const result = ts.getDirectoryToWatchFailedLookupLocation(
|
||||
testPath,
|
||||
testPath,
|
||||
root,
|
||||
root,
|
||||
rootPathCompoments,
|
||||
ts.returnUndefined,
|
||||
preferNonRecursiveWatch,
|
||||
);
|
||||
pushRow(baseline, [testPath, result ? result.packageDir ?? result.dir : "", result ? `${!result.nonRecursive}` : "", result?.packageDir ? result.dir : ""], maxLengths);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
baselineCanWatch(
|
||||
"getDirectoryToWatchFailedLookupLocationFromTypeRoot",
|
||||
() => `When watched typeRoot handler is invoked, this method determines the directory for which the failedLookupLocation would need to be invalidated.\r\nSince this is invoked only when watching default typeRoot and is used to handle flaky directory watchers, this is used as a fail safe where if failed lookup starts with returned directory we will invalidate that resolution.`,
|
||||
(paths, longestPathLength, baseline) => {
|
||||
const maxLength = longestPathLength + "/node_modules/@types".length;
|
||||
const maxLengths = [maxLength, maxLength] as const;
|
||||
baselineCanWatchForRoot(paths, baseline, (rootPathCompoments, root) => {
|
||||
pushHeader(baseline, ["Directory", "getDirectoryToWatchFailedLookupLocationFromTypeRoot"], maxLengths);
|
||||
paths.forEach(path => {
|
||||
path = combinePaths(path, "node_modules/@types");
|
||||
// This is invoked only on paths that are watched
|
||||
if (!ts.canWatchAtTypes(path)) return;
|
||||
const result = ts.getDirectoryToWatchFailedLookupLocationFromTypeRoot(
|
||||
path,
|
||||
path,
|
||||
root,
|
||||
rootPathCompoments,
|
||||
ts.returnUndefined,
|
||||
ts.returnTrue,
|
||||
);
|
||||
pushRow(baseline, [path, result !== undefined ? result : ""], maxLengths);
|
||||
[undefined, true].forEach(preferNonRecursiveWatch => {
|
||||
baselineCanWatch(
|
||||
`getDirectoryToWatchFailedLookupLocationFromTypeRoot${preferNonRecursiveWatch ? "NonRecursive" : ""}`,
|
||||
() => `When watched typeRoot handler is invoked, this method determines the directory for which the failedLookupLocation would need to be invalidated.\r\nSince this is invoked only when watching default typeRoot and is used to handle flaky directory watchers, this is used as a fail safe where if failed lookup starts with returned directory we will invalidate that resolution.`,
|
||||
(paths, longestPathLength, baseline) => {
|
||||
const maxLength = longestPathLength + "/node_modules/@types".length;
|
||||
const maxLengths = [maxLength, maxLength] as const;
|
||||
baselineCanWatchForRoot(paths, baseline, (rootPathCompoments, root) => {
|
||||
pushHeader(baseline, ["Directory", "getDirectoryToWatchFailedLookupLocationFromTypeRoot"], maxLengths);
|
||||
paths.forEach(path => {
|
||||
path = combinePaths(path, "node_modules/@types");
|
||||
// This is invoked only on paths that are watched
|
||||
if (!ts.canWatchAtTypes(path)) return;
|
||||
const result = ts.getDirectoryToWatchFailedLookupLocationFromTypeRoot(
|
||||
path,
|
||||
path,
|
||||
root,
|
||||
rootPathCompoments,
|
||||
ts.returnUndefined,
|
||||
preferNonRecursiveWatch,
|
||||
ts.returnTrue,
|
||||
);
|
||||
pushRow(baseline, [path, result !== undefined ? result : ""], maxLengths);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
function baselineCanWatchForRoot(paths: readonly ts.Path[], baseline: string[], baselineForRoot: (rootPathCompoments: Readonly<ts.PathPathComponents>, root: ts.Path) => void) {
|
||||
paths.forEach(rootDirForResolution => {
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
import {
|
||||
emptyArray,
|
||||
noop,
|
||||
} from "../../_namespaces/ts.js";
|
||||
import { dedent } from "../../_namespaces/Utils.js";
|
||||
import { jsonToReadableText } from "../helpers.js";
|
||||
import { libContent } from "./contents.js";
|
||||
import { solutionBuildWithBaseline } from "./solutionBuilder.js";
|
||||
import {
|
||||
TscWatchCompileChange,
|
||||
TscWatchSystem,
|
||||
} from "./tscWatch.js";
|
||||
import {
|
||||
createServerHost,
|
||||
createWatchedSystem,
|
||||
libFile,
|
||||
osFlavorToString,
|
||||
TestServerHost,
|
||||
TestServerHostOsFlavor,
|
||||
} from "./virtualFileSystemWithWatch.js";
|
||||
|
||||
export function getMonorepoSymlinkedSiblingPackagesSys(forTsserver: boolean, built: boolean, osFlavor?: TestServerHostOsFlavor): TestServerHost {
|
||||
function getMonorepoSymlinkedSiblingPackagesSys(forTsserver: boolean, built: boolean, osFlavor?: TestServerHostOsFlavor): TestServerHost {
|
||||
const configText = jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es2016",
|
||||
@@ -57,10 +67,224 @@ function getPackageJson(packageName: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function buildMonorepoSymlinkedSiblingPackage1(host: TestServerHost) {
|
||||
function buildMonorepoSymlinkedSiblingPackage1(host: TestServerHost) {
|
||||
solutionBuildWithBaseline(host, ["packages/package1"]);
|
||||
}
|
||||
|
||||
export function cleanMonorepoSymlinkedSiblingPackage1(host: TestServerHost) {
|
||||
function cleanMonorepoSymlinkedSiblingPackage1(host: TestServerHost) {
|
||||
host.deleteFolder("/home/src/projects/project/packages/package1/dist", /*recursive*/ true);
|
||||
}
|
||||
|
||||
function forEachMonorepoSymlinkedSiblingPackagesSys(
|
||||
forTsserver: boolean,
|
||||
action: (
|
||||
scenario: string,
|
||||
sys: () => TestServerHost,
|
||||
edits: () => readonly TscWatchCompileChange[],
|
||||
project: string,
|
||||
) => void,
|
||||
) {
|
||||
for (const built of [false, true]) {
|
||||
for (const osFlavor of [undefined, TestServerHostOsFlavor.Linux]) {
|
||||
action(
|
||||
`monorepo style sibling packages symlinked${built ? " package1 built" : ""}${osFlavor ? ` ${osFlavorToString(osFlavor)}` : ""}`,
|
||||
() => getMonorepoSymlinkedSiblingPackagesSys(forTsserver, built, osFlavor),
|
||||
() =>
|
||||
getEditsWithBuildAndClean(
|
||||
forTsserver,
|
||||
built,
|
||||
osFlavor,
|
||||
buildMonorepoSymlinkedSiblingPackage1,
|
||||
cleanMonorepoSymlinkedSiblingPackage1,
|
||||
),
|
||||
"packages/package2",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function threeTimeouts(sys: TscWatchSystem) {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
}
|
||||
|
||||
function getEditsWithBuildAndClean(
|
||||
forTsserver: boolean,
|
||||
built: boolean,
|
||||
osFlavor: TestServerHostOsFlavor | undefined,
|
||||
build: (host: TscWatchSystem) => void,
|
||||
clean: (host: TscWatchSystem) => void,
|
||||
beforeBuild?: readonly TscWatchCompileChange[],
|
||||
beforeClean?: readonly TscWatchCompileChange[],
|
||||
): readonly TscWatchCompileChange[] {
|
||||
return [
|
||||
...beforeBuild ?? emptyArray,
|
||||
...built ? emptyArray : [{
|
||||
caption: "Build dependencies",
|
||||
edit: build,
|
||||
timeouts: threeTimeouts,
|
||||
}],
|
||||
...beforeClean ?? emptyArray,
|
||||
{
|
||||
caption: "Clean dependencies build",
|
||||
edit: clean,
|
||||
timeouts: forTsserver ? threeTimeouts : sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
...!forTsserver && osFlavor === TestServerHostOsFlavor.Linux ? [{
|
||||
caption: "After updating childs",
|
||||
edit: noop,
|
||||
timeouts: threeTimeouts,
|
||||
}] : emptyArray,
|
||||
{
|
||||
caption: "Build dependencies",
|
||||
edit: build,
|
||||
timeouts: threeTimeouts,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(
|
||||
forTsserver: boolean,
|
||||
built: boolean,
|
||||
osFlavor: TestServerHostOsFlavor,
|
||||
): TestServerHost {
|
||||
const sys = (!forTsserver ? createWatchedSystem : createServerHost)({
|
||||
"/home/src/projects/c/3/c-impl/c/src/c.ts": `export const c: string = 'test';`,
|
||||
"/home/src/projects/c/3/c-impl/c/src/index.ts": `export * from './c';`,
|
||||
"/home/src/projects/c/3/c-impl/c/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "lib",
|
||||
declaration: true,
|
||||
},
|
||||
include: ["src/**/*.ts"],
|
||||
}),
|
||||
"/home/src/projects/c/3/c-impl/c/package.json": jsonToReadableText({
|
||||
name: "c",
|
||||
version: "1.0.0",
|
||||
types: "./lib/index.d.ts",
|
||||
}),
|
||||
"/home/src/projects/c/4/unrelated/somefile.ts": `export const a: string = 'test';`,
|
||||
"/home/src/projects/a/1/a-impl/a/src/a.ts": `export const a: string = 'test';`,
|
||||
"/home/src/projects/a/1/a-impl/a/src/index.ts": dedent`
|
||||
export * from './a';
|
||||
export * from 'c';
|
||||
`,
|
||||
"/home/src/projects/a/1/a-impl/a/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "lib",
|
||||
declaration: true,
|
||||
},
|
||||
include: ["src/**/*.ts"],
|
||||
}),
|
||||
"/home/src/projects/a/1/a-impl/a/package.json": jsonToReadableText({
|
||||
name: "a",
|
||||
version: "1.0.0",
|
||||
types: "./lib/index.d.ts",
|
||||
}),
|
||||
"/home/src/projects/a/1/a-impl/a/node_modules/c": { symLink: "/home/src/projects/c/3/c-impl/c" },
|
||||
"/home/src/projects/a/2/unrelated/somefile.ts": `export const a: string = 'test';`,
|
||||
"/home/src/projects/b/2/b-impl/b/src/index.ts": `import { a } from 'a';`,
|
||||
"/home/src/projects/b/2/b-impl/b/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "lib",
|
||||
},
|
||||
include: ["src/**/*.ts"],
|
||||
}),
|
||||
"/home/src/projects/b/2/b-impl/b/node_modules/a": { symLink: "/home/src/projects/a/1/a-impl/a" },
|
||||
[libFile.path]: libContent,
|
||||
}, { currentDirectory: "/home/src/projects/b/2/b-impl/b", osFlavor });
|
||||
if (built) buildDependenciesOfMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(sys);
|
||||
return sys;
|
||||
}
|
||||
|
||||
function buildDependenciesOfMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(host: TestServerHost) {
|
||||
solutionBuildWithBaseline(host, ["../../../../c/3/c-impl/c", "../../../../a/1/a-impl/a"]);
|
||||
}
|
||||
|
||||
function cleanDependenciesOfMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(host: TestServerHost) {
|
||||
host.deleteFolder("/home/src/projects/c/3/c-impl/c/lib", /*recursive*/ true);
|
||||
host.deleteFolder("/home/src/projects/a/1/a-impl/a/lib", /*recursive*/ true);
|
||||
}
|
||||
|
||||
function forEachMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(
|
||||
forTsserver: boolean,
|
||||
action: (
|
||||
scenario: string,
|
||||
sys: () => TestServerHost,
|
||||
edits: () => readonly TscWatchCompileChange[],
|
||||
indexFile: string,
|
||||
) => void,
|
||||
) {
|
||||
for (const built of [false, true]) {
|
||||
for (const osFlavor of [TestServerHostOsFlavor.Windows, TestServerHostOsFlavor.MacOs, TestServerHostOsFlavor.Linux]) {
|
||||
action(
|
||||
`packages outside project folder${built ? " built" : ""} ${osFlavorToString(osFlavor)}`,
|
||||
() => getMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(forTsserver, built, osFlavor),
|
||||
() =>
|
||||
getEditsWithBuildAndClean(
|
||||
forTsserver,
|
||||
built,
|
||||
osFlavor,
|
||||
buildDependenciesOfMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders,
|
||||
cleanDependenciesOfMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders,
|
||||
[
|
||||
{
|
||||
caption: "change in unrelated folder in a",
|
||||
edit: sys => sys.writeFile("/home/src/projects/a/2/unrelated/somethingUnrelated.ts", "export const a = 10;"),
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
{
|
||||
caption: "change in unrelated folder in c",
|
||||
edit: sys => sys.writeFile("/home/src/projects/c/4/unrelated/somethingUnrelated.ts", "export const a = 10;"),
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
caption: "change in unrelated folder in a",
|
||||
edit: sys => sys.writeFile("/home/src/projects/a/2/unrelated/anotherFile.ts", "export const a = 10;"),
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
{
|
||||
caption: "change in unrelated folder in c",
|
||||
edit: sys => sys.writeFile("/home/src/projects/c/4/unrelated/anotherFile.ts", "export const a = 10;"),
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
],
|
||||
),
|
||||
".",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function forEachMonorepoSymlinkScenario(
|
||||
forTsserver: boolean,
|
||||
action: (
|
||||
scenario: string,
|
||||
sys: () => TestServerHost,
|
||||
edits: () => readonly TscWatchCompileChange[],
|
||||
indexFile: string,
|
||||
) => void,
|
||||
) {
|
||||
describe("monorepoSymlinkedSiblingPackages:: monorepo style sibling packages symlinked", () => {
|
||||
forEachMonorepoSymlinkedSiblingPackagesSys(forTsserver, action);
|
||||
});
|
||||
|
||||
describe("monorepoSymlinkedSiblingPackagesWithUnrelatedFolders:: packages outside project folder", () => {
|
||||
forEachMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(forTsserver, action);
|
||||
});
|
||||
}
|
||||
@@ -310,6 +310,7 @@ function verifyProgramStructureAndResolutionCache(
|
||||
getCompilationSettings: () => options,
|
||||
fileIsOpen: ts.returnFalse,
|
||||
getCurrentProgram: () => program,
|
||||
preferNonRecursiveWatch: sys.preferNonRecursiveWatch,
|
||||
|
||||
watchDirectoryOfFailedLookupLocation: ts.returnNoopFileWatcher,
|
||||
watchAffectingFileLocation: ts.returnNoopFileWatcher,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { patchHostForBuildInfoReadWrite } from "../../_namespaces/fakes.js";
|
||||
import * as Harness from "../../_namespaces/Harness.js";
|
||||
import * as ts from "../../_namespaces/ts.js";
|
||||
import { ensureErrorFreeBuild } from "./solutionBuilder.js";
|
||||
import { TscWatchCompileChange } from "./tscWatch.js";
|
||||
import {
|
||||
customTypesMap,
|
||||
TestTypingsInstallerAdapter,
|
||||
@@ -630,3 +631,17 @@ export function createHostWithSolutionBuild(files: readonly FileOrFolderOrSymLin
|
||||
ensureErrorFreeBuild(host, rootNames);
|
||||
return host;
|
||||
}
|
||||
|
||||
export function forEachTscWatchEdit(
|
||||
session: TestSession,
|
||||
edits: readonly TscWatchCompileChange[],
|
||||
action: () => void,
|
||||
) {
|
||||
edits.forEach(edit => {
|
||||
session.logger.log(edit.caption);
|
||||
edit.edit(session.host);
|
||||
if (session.watchChanges.size) session.invokeWatchChanges();
|
||||
edit.timeouts(session.host, undefined!, undefined!);
|
||||
action();
|
||||
});
|
||||
}
|
||||
@@ -368,6 +368,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
|
||||
watchDirectory: HostWatchDirectory;
|
||||
service?: server.ProjectService;
|
||||
osFlavor: TestServerHostOsFlavor;
|
||||
preferNonRecursiveWatch: boolean;
|
||||
constructor(
|
||||
fileOrFolderorSymLinkList: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[],
|
||||
{
|
||||
@@ -395,6 +396,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
|
||||
this.runWithFallbackPolling = !!runWithFallbackPolling;
|
||||
const tscWatchFile = this.environmentVariables && this.environmentVariables.get("TSC_WATCHFILE");
|
||||
const tscWatchDirectory = this.environmentVariables && this.environmentVariables.get("TSC_WATCHDIRECTORY");
|
||||
this.preferNonRecursiveWatch = this.osFlavor === TestServerHostOsFlavor.Linux;
|
||||
this.inodeWatching = this.osFlavor !== TestServerHostOsFlavor.Windows;
|
||||
if (this.inodeWatching) this.inodes = new Map();
|
||||
|
||||
@@ -410,7 +412,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
|
||||
fileSystemEntryExists: this.fileSystemEntryExists.bind(this),
|
||||
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
|
||||
getCurrentDirectory: this.getCurrentDirectory.bind(this),
|
||||
fsSupportsRecursiveFsWatch: this.osFlavor !== TestServerHostOsFlavor.Linux,
|
||||
fsSupportsRecursiveFsWatch: !this.preferNonRecursiveWatch,
|
||||
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
|
||||
realpath: this.realpath.bind(this),
|
||||
tscWatchFile,
|
||||
|
||||
@@ -1,65 +1,14 @@
|
||||
import {
|
||||
buildMonorepoSymlinkedSiblingPackage1,
|
||||
cleanMonorepoSymlinkedSiblingPackage1,
|
||||
getMonorepoSymlinkedSiblingPackagesSys,
|
||||
} from "../helpers/monorepoSymlinkedSiblingPackages.js";
|
||||
import {
|
||||
noopChange,
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch.js";
|
||||
import {
|
||||
osFlavorToString,
|
||||
TestServerHostOsFlavor,
|
||||
} from "../helpers/virtualFileSystemWithWatch.js";
|
||||
import { forEachMonorepoSymlinkScenario } from "../helpers/monorepoSymlinkedSiblingPackages.js";
|
||||
import { verifyTscWatch } from "../helpers/tscWatch.js";
|
||||
|
||||
describe("unittests:: tsc-watch:: symlinks::", () => {
|
||||
describe("monorepoSymlinkedSiblingPackages:: monorepo style sibling packages symlinked", () => {
|
||||
verify(/*built*/ false);
|
||||
verify(/*built*/ true);
|
||||
verify(/*built*/ false, TestServerHostOsFlavor.Linux);
|
||||
verify(/*built*/ true, TestServerHostOsFlavor.Linux);
|
||||
function verify(built: boolean, osFlavor?: TestServerHostOsFlavor) {
|
||||
verifyTscWatch({
|
||||
scenario: "symlinks",
|
||||
subScenario: `monorepo style sibling packages symlinked${built ? " package1 built" : ""}${osFlavor ? ` ${osFlavorToString(osFlavor)}` : ""}`,
|
||||
commandLineArgs: ["--w", "-p", "packages/package2", "--extendedDiagnostics"],
|
||||
sys: () => getMonorepoSymlinkedSiblingPackagesSys(/*forTsserver*/ false, built, osFlavor),
|
||||
edits: [
|
||||
built ? noopChange : {
|
||||
caption: "Build package1",
|
||||
edit: buildMonorepoSymlinkedSiblingPackage1,
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
{
|
||||
caption: "Clean package1 build",
|
||||
edit: cleanMonorepoSymlinkedSiblingPackage1,
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
osFlavor === TestServerHostOsFlavor.Linux ? {
|
||||
caption: "After updating childs",
|
||||
edit: noopChange.edit,
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
} : noopChange,
|
||||
{
|
||||
caption: "Build package1",
|
||||
edit: buildMonorepoSymlinkedSiblingPackage1,
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
sys.runQueuedTimeoutCallbacks();
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
forEachMonorepoSymlinkScenario(/*forTsserver*/ false, (subScenario, sys, edits, project) => {
|
||||
verifyTscWatch({
|
||||
scenario: "symlinks",
|
||||
subScenario,
|
||||
commandLineArgs: ["--w", "-p", project, "--extendedDiagnostics", "--explainFiles", "--traceResolution"],
|
||||
sys,
|
||||
edits: edits(),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,11 @@
|
||||
import * as ts from "../../_namespaces/ts.js";
|
||||
import { dedent } from "../../_namespaces/Utils.js";
|
||||
import { jsonToReadableText } from "../helpers.js";
|
||||
import {
|
||||
buildMonorepoSymlinkedSiblingPackage1,
|
||||
cleanMonorepoSymlinkedSiblingPackage1,
|
||||
getMonorepoSymlinkedSiblingPackagesSys,
|
||||
} from "../helpers/monorepoSymlinkedSiblingPackages.js";
|
||||
import { forEachMonorepoSymlinkScenario } from "../helpers/monorepoSymlinkedSiblingPackages.js";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
closeFilesForSession,
|
||||
forEachTscWatchEdit,
|
||||
openFilesForSession,
|
||||
protocolLocationFromSubstring,
|
||||
TestSession,
|
||||
@@ -18,10 +15,8 @@ import {
|
||||
createServerHost,
|
||||
File,
|
||||
libFile,
|
||||
osFlavorToString,
|
||||
SymLink,
|
||||
TestServerHost,
|
||||
TestServerHostOsFlavor,
|
||||
} from "../helpers/virtualFileSystemWithWatch.js";
|
||||
|
||||
describe("unittests:: tsserver:: symLinks::", () => {
|
||||
@@ -272,41 +267,17 @@ new C();`,
|
||||
baselineTsserverLogs("symLinks", "when not symlink but differs in casing", session);
|
||||
});
|
||||
|
||||
describe("monorepoSymlinkedSiblingPackages:: monorepo style sibling packages symlinked", () => {
|
||||
verify(/*built*/ false);
|
||||
verify(/*built*/ true);
|
||||
verify(/*built*/ false, TestServerHostOsFlavor.Linux);
|
||||
verify(/*built*/ true, TestServerHostOsFlavor.Linux);
|
||||
function verify(built: boolean, osFlavor?: TestServerHostOsFlavor) {
|
||||
it(`monorepo style sibling packages symlinked${built ? " package1 built" : ""}${osFlavor ? ` ${osFlavorToString(osFlavor)}` : ""}`, () => {
|
||||
const indexFile = "/home/src/projects/project/packages/package2/src/index.ts";
|
||||
const host = getMonorepoSymlinkedSiblingPackagesSys(/*forTsserver*/ true, built, osFlavor);
|
||||
const session = new TestSession(host);
|
||||
forEachMonorepoSymlinkScenario(/*forTsserver*/ true, (scenario, getHost, edits, project) => {
|
||||
[undefined, true].forEach(canUseWatchEvents => {
|
||||
it(`${scenario}${canUseWatchEvents ? " canUseWatchEvents" : ""}`, () => {
|
||||
const host = getHost();
|
||||
const indexFile = ts.normalizePath(ts.combinePaths(host.getCurrentDirectory(), project, "src/index.ts"));
|
||||
const session = new TestSession({ host, canUseWatchEvents });
|
||||
openFilesForSession([indexFile], session);
|
||||
verifyGetErrRequest({ session, files: [indexFile] });
|
||||
|
||||
if (!built) {
|
||||
buildMonorepoSymlinkedSiblingPackage1(host);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
verifyGetErrRequest({ session, files: [indexFile] });
|
||||
}
|
||||
|
||||
cleanMonorepoSymlinkedSiblingPackage1(host);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
verifyGetErrRequest({ session, files: [indexFile] });
|
||||
|
||||
buildMonorepoSymlinkedSiblingPackage1(host);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
verifyGetErrRequest({ session, files: [indexFile] });
|
||||
|
||||
baselineTsserverLogs("symLinks", `monorepo style sibling packages symlinked${built ? " package1 built" : ""}${osFlavor ? ` ${osFlavorToString(osFlavor)}` : ""}`, session);
|
||||
forEachTscWatchEdit(session, edits(), () => verifyGetErrRequest({ session, files: [indexFile] }));
|
||||
baselineTsserverLogs("symLinks", `${scenario}${canUseWatchEvents ? " canUseWatchEvents" : ""}`, session);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user