Skip to content

Commit eb34d7c

Browse files
committed
Convert symlink scenarios to virtual FS where its symlinks are correctly maintained
Adds test for #36866
1 parent 9120497 commit eb34d7c

11 files changed

+1458
-204
lines changed

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ interface Array<T> { length: number; [n: number]: T; }`
7070
}
7171

7272
export type FileOrFolderOrSymLink = File | Folder | SymLink;
73-
function isFile(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is File {
73+
export function isFile(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is File {
7474
return isString((<File>fileOrFolderOrSymLink).content);
7575
}
7676

77-
function isSymLink(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is SymLink {
77+
export function isSymLink(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is SymLink {
7878
return isString((<SymLink>fileOrFolderOrSymLink).symLink);
7979
}
8080

src/testRunner/unittests/tsc/declarationEmit.ts

Lines changed: 229 additions & 115 deletions
Large diffs are not rendered by default.

src/testRunner/unittests/tscWatch/helpers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ namespace ts.tscWatch {
300300
baselineSourceMap
301301
} = input;
302302

303+
if (!isWatch(commandLineArgs)) sys.exit = exitCode => sys.exitCode = exitCode;
303304
const { cb, getPrograms } = commandLineCallbacks(sys);
304305
const watchOrSolution = executeCommandLine(
305306
sys,
@@ -352,7 +353,17 @@ namespace ts.tscWatch {
352353
baselineSourceMap
353354
});
354355
}
355-
Harness.Baseline.runBaseline(`${isBuild(commandLineArgs) ? "tsbuild/watchMode" : "tscWatch"}/${scenario}/${subScenario.split(" ").join("-")}.js`, baseline.join("\r\n"));
356+
Harness.Baseline.runBaseline(`${isBuild(commandLineArgs) ?
357+
isWatch(commandLineArgs) ? "tsbuild/watchMode" : "tsbuild" :
358+
isWatch(commandLineArgs) ? "tscWatch" : "tsc"}/${scenario}/${subScenario.split(" ").join("-")}.js`, baseline.join("\r\n"));
359+
}
360+
361+
function isWatch(commandLineArgs: readonly string[]) {
362+
return forEach(commandLineArgs, arg => {
363+
if (arg.charCodeAt(0) !== CharacterCodes.minus) return false;
364+
const option = arg.slice(arg.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
365+
return option === "watch" || option === "w";
366+
});
356367
}
357368

358369
export interface WatchBaseline extends TscWatchCheckOptions {

tests/baselines/reference/tsc/declarationEmit/initial-build/when-pkg-references-sibling-package-through-indirect-symlink.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js

Lines changed: 0 additions & 38 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/a/lib/tsc.js -p pkg3 --listFiles
2+
//// [/user/username/projects/myProject/pkg1/dist/index.d.ts]
3+
export * from './types';
4+
5+
//// [/user/username/projects/myProject/pkg1/dist/types.d.ts]
6+
export declare type A = {
7+
id: string;
8+
};
9+
export declare type B = {
10+
id: number;
11+
};
12+
export declare type IdType = A | B;
13+
export declare class MetadataAccessor<T, D extends IdType = IdType> {
14+
readonly key: string;
15+
private constructor();
16+
toString(): string;
17+
static create<T, D extends IdType = IdType>(key: string): MetadataAccessor<T, D>;
18+
}
19+
20+
//// [/user/username/projects/myProject/pkg1/package.json]
21+
{"name":"@raymondfeng/pkg1","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"}
22+
23+
//// [/user/username/projects/myproject/pkg2/dist/index.d.ts]
24+
export * from './types';
25+
26+
//// [/user/username/projects/myproject/pkg2/dist/types.d.ts]
27+
export {MetadataAccessor} from '@raymondfeng/pkg1';
28+
29+
//// [/user/username/projects/myproject/pkg2/package.json]
30+
{"name":"@raymondfeng/pkg2","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"}
31+
32+
//// [/user/username/projects/myproject/pkg3/src/index.ts]
33+
export * from './keys';
34+
35+
//// [/user/username/projects/myproject/pkg3/src/keys.ts]
36+
import {MetadataAccessor} from "@raymondfeng/pkg2";
37+
export const ADMIN = MetadataAccessor.create<boolean>('1');
38+
39+
//// [/user/username/projects/myproject/pkg3/tsconfig.json]
40+
{"compilerOptions":{"outDir":"dist","rootDir":"src","target":"es5","module":"commonjs","strict":true,"esModuleInterop":true,"declaration":true}}
41+
42+
//// [/user/username/projects/myProject/pkg2/node_modules/@raymondfeng/pkg1] symlink(/user/username/projects/myProject/pkg1)
43+
//// [/user/username/projects/myproject/pkg3/node_modules/@raymondfeng/pkg2] symlink(/user/username/projects/myproject/pkg2)
44+
//// [/a/lib/lib.d.ts]
45+
/// <reference no-default-lib="true"/>
46+
interface Boolean {}
47+
interface Function {}
48+
interface CallableFunction {}
49+
interface NewableFunction {}
50+
interface IArguments {}
51+
interface Number { toExponential: any; }
52+
interface Object {}
53+
interface RegExp {}
54+
interface String { charAt: any; }
55+
interface Array<T> { length: number; [n: number]: T; }
56+
57+
//// [/user/username/projects/myproject/pkg3/dist/keys.js]
58+
"use strict";
59+
Object.defineProperty(exports, "__esModule", { value: true });
60+
exports.ADMIN = void 0;
61+
var pkg2_1 = require("@raymondfeng/pkg2");
62+
exports.ADMIN = pkg2_1.MetadataAccessor.create('1');
63+
64+
65+
//// [/user/username/projects/myproject/pkg3/dist/keys.d.ts]
66+
import { MetadataAccessor } from "@raymondfeng/pkg2";
67+
export declare const ADMIN: MetadataAccessor<boolean, import("../../pkg1/dist").IdType>;
68+
69+
70+
//// [/user/username/projects/myproject/pkg3/dist/index.js]
71+
"use strict";
72+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
73+
if (k2 === undefined) k2 = k;
74+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
75+
}) : (function(o, m, k, k2) {
76+
if (k2 === undefined) k2 = k;
77+
o[k2] = m[k];
78+
}));
79+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
80+
for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p);
81+
}
82+
Object.defineProperty(exports, "__esModule", { value: true });
83+
__exportStar(require("./keys"), exports);
84+
85+
86+
//// [/user/username/projects/myproject/pkg3/dist/index.d.ts]
87+
export * from './keys';
88+
89+
90+
91+
Output::
92+
/a/lib/lib.d.ts
93+
94+
/user/username/projects/myProject/pkg1/dist/types.d.ts
95+
96+
/user/username/projects/myProject/pkg1/dist/index.d.ts
97+
98+
/user/username/projects/myproject/pkg2/dist/types.d.ts
99+
100+
/user/username/projects/myproject/pkg2/dist/index.d.ts
101+
102+
/user/username/projects/myproject/pkg3/src/keys.ts
103+
104+
/user/username/projects/myproject/pkg3/src/index.ts
105+
106+
107+
108+
Program root files: ["/user/username/projects/myproject/pkg3/src/index.ts","/user/username/projects/myproject/pkg3/src/keys.ts"]
109+
Program options: {"outDir":"/user/username/projects/myproject/pkg3/dist","rootDir":"/user/username/projects/myproject/pkg3/src","target":1,"module":1,"strict":true,"esModuleInterop":true,"declaration":true,"project":"/user/username/projects/myproject/pkg3","listFiles":true,"configFilePath":"/user/username/projects/myproject/pkg3/tsconfig.json"}
110+
Program files::
111+
/a/lib/lib.d.ts
112+
/user/username/projects/myProject/pkg1/dist/types.d.ts
113+
/user/username/projects/myProject/pkg1/dist/index.d.ts
114+
/user/username/projects/myproject/pkg2/dist/types.d.ts
115+
/user/username/projects/myproject/pkg2/dist/index.d.ts
116+
/user/username/projects/myproject/pkg3/src/keys.ts
117+
/user/username/projects/myproject/pkg3/src/index.ts
118+
119+
WatchedFiles::
120+
121+
FsWatches::
122+
123+
FsWatchesRecursive::
124+
125+
exitCode:: ExitStatus.Success
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/a/lib/tsc.js -p pkg3 --listFiles
2+
//// [/user/username/projects/myproject/pkg1/dist/index.d.ts]
3+
export * from './types';
4+
5+
//// [/user/username/projects/myproject/pkg1/dist/types.d.ts]
6+
export declare type A = {
7+
id: string;
8+
};
9+
export declare type B = {
10+
id: number;
11+
};
12+
export declare type IdType = A | B;
13+
export declare class MetadataAccessor<T, D extends IdType = IdType> {
14+
readonly key: string;
15+
private constructor();
16+
toString(): string;
17+
static create<T, D extends IdType = IdType>(key: string): MetadataAccessor<T, D>;
18+
}
19+
20+
//// [/user/username/projects/myproject/pkg1/package.json]
21+
{"name":"@raymondfeng/pkg1","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"}
22+
23+
//// [/user/username/projects/myproject/pkg2/dist/index.d.ts]
24+
export * from './types';
25+
26+
//// [/user/username/projects/myproject/pkg2/dist/types.d.ts]
27+
export {MetadataAccessor} from '@raymondfeng/pkg1';
28+
29+
//// [/user/username/projects/myproject/pkg2/package.json]
30+
{"name":"@raymondfeng/pkg2","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"}
31+
32+
//// [/user/username/projects/myproject/pkg3/src/index.ts]
33+
export * from './keys';
34+
35+
//// [/user/username/projects/myproject/pkg3/src/keys.ts]
36+
import {MetadataAccessor} from "@raymondfeng/pkg2";
37+
export const ADMIN = MetadataAccessor.create<boolean>('1');
38+
39+
//// [/user/username/projects/myproject/pkg3/tsconfig.json]
40+
{"compilerOptions":{"outDir":"dist","rootDir":"src","target":"es5","module":"commonjs","strict":true,"esModuleInterop":true,"declaration":true}}
41+
42+
//// [/user/username/projects/myproject/pkg2/node_modules/@raymondfeng/pkg1] symlink(/user/username/projects/myproject/pkg1)
43+
//// [/user/username/projects/myproject/pkg3/node_modules/@raymondfeng/pkg2] symlink(/user/username/projects/myproject/pkg2)
44+
//// [/a/lib/lib.d.ts]
45+
/// <reference no-default-lib="true"/>
46+
interface Boolean {}
47+
interface Function {}
48+
interface CallableFunction {}
49+
interface NewableFunction {}
50+
interface IArguments {}
51+
interface Number { toExponential: any; }
52+
interface Object {}
53+
interface RegExp {}
54+
interface String { charAt: any; }
55+
interface Array<T> { length: number; [n: number]: T; }
56+
57+
//// [/user/username/projects/myproject/pkg3/dist/keys.js]
58+
"use strict";
59+
Object.defineProperty(exports, "__esModule", { value: true });
60+
exports.ADMIN = void 0;
61+
var pkg2_1 = require("@raymondfeng/pkg2");
62+
exports.ADMIN = pkg2_1.MetadataAccessor.create('1');
63+
64+
65+
//// [/user/username/projects/myproject/pkg3/dist/keys.d.ts]
66+
import { MetadataAccessor } from "@raymondfeng/pkg2";
67+
export declare const ADMIN: MetadataAccessor<boolean, import("../../pkg1/dist").IdType>;
68+
69+
70+
//// [/user/username/projects/myproject/pkg3/dist/index.js]
71+
"use strict";
72+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
73+
if (k2 === undefined) k2 = k;
74+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
75+
}) : (function(o, m, k, k2) {
76+
if (k2 === undefined) k2 = k;
77+
o[k2] = m[k];
78+
}));
79+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
80+
for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p);
81+
}
82+
Object.defineProperty(exports, "__esModule", { value: true });
83+
__exportStar(require("./keys"), exports);
84+
85+
86+
//// [/user/username/projects/myproject/pkg3/dist/index.d.ts]
87+
export * from './keys';
88+
89+
90+
91+
Output::
92+
/a/lib/lib.d.ts
93+
94+
/user/username/projects/myproject/pkg1/dist/types.d.ts
95+
96+
/user/username/projects/myproject/pkg1/dist/index.d.ts
97+
98+
/user/username/projects/myproject/pkg2/dist/types.d.ts
99+
100+
/user/username/projects/myproject/pkg2/dist/index.d.ts
101+
102+
/user/username/projects/myproject/pkg3/src/keys.ts
103+
104+
/user/username/projects/myproject/pkg3/src/index.ts
105+
106+
107+
108+
Program root files: ["/user/username/projects/myproject/pkg3/src/index.ts","/user/username/projects/myproject/pkg3/src/keys.ts"]
109+
Program options: {"outDir":"/user/username/projects/myproject/pkg3/dist","rootDir":"/user/username/projects/myproject/pkg3/src","target":1,"module":1,"strict":true,"esModuleInterop":true,"declaration":true,"project":"/user/username/projects/myproject/pkg3","listFiles":true,"configFilePath":"/user/username/projects/myproject/pkg3/tsconfig.json"}
110+
Program files::
111+
/a/lib/lib.d.ts
112+
/user/username/projects/myproject/pkg1/dist/types.d.ts
113+
/user/username/projects/myproject/pkg1/dist/index.d.ts
114+
/user/username/projects/myproject/pkg2/dist/types.d.ts
115+
/user/username/projects/myproject/pkg2/dist/index.d.ts
116+
/user/username/projects/myproject/pkg3/src/keys.ts
117+
/user/username/projects/myproject/pkg3/src/index.ts
118+
119+
WatchedFiles::
120+
121+
FsWatches::
122+
123+
FsWatchesRecursive::
124+
125+
exitCode:: ExitStatus.Success

0 commit comments

Comments
 (0)