mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
TypeReference directive reuse (#49750)
This commit is contained in:
1 parent
1d96eb489e
commit
48aebcdcdb
13 files changed
+627
-72
No files matched your search
@@ -483,11 +483,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File 'b1.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name './b1' was successfully resolved to 'b1.ts'. ========",
|
||||
"======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========",
|
||||
"Resolving with primary search path 'node_modules/@types'.",
|
||||
"File 'node_modules/@types/typerefs2/package.json' does not exist.",
|
||||
"File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========",
|
||||
"Reusing resolution of type reference directive 'typerefs2' from 'f2.ts' of old program, it was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts'.",
|
||||
"Reusing resolution of module './b2' from 'f2.ts' of old program, it was successfully resolved to 'b2.ts'.",
|
||||
"Reusing resolution of module './f1' from 'f2.ts' of old program, it was successfully resolved to 'f1.ts'."
|
||||
], "program2: reuse module resolutions in f2 since it is unchanged");
|
||||
@@ -507,11 +503,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File 'b1.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name './b1' was successfully resolved to 'b1.ts'. ========",
|
||||
"======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========",
|
||||
"Resolving with primary search path 'node_modules/@types'.",
|
||||
"File 'node_modules/@types/typerefs2/package.json' does not exist.",
|
||||
"File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========",
|
||||
"Reusing resolution of type reference directive 'typerefs2' from 'f2.ts' of old program, it was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts'.",
|
||||
"Reusing resolution of module './b2' from 'f2.ts' of old program, it was successfully resolved to 'b2.ts'.",
|
||||
"Reusing resolution of module './f1' from 'f2.ts' of old program, it was successfully resolved to 'f1.ts'."
|
||||
], "program3: reuse module resolutions in f2 since it is unchanged");
|
||||
@@ -532,11 +524,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File 'b1.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name './b1' was successfully resolved to 'b1.ts'. ========",
|
||||
"======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========",
|
||||
"Resolving with primary search path 'node_modules/@types'.",
|
||||
"File 'node_modules/@types/typerefs2/package.json' does not exist.",
|
||||
"File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========",
|
||||
"Reusing resolution of type reference directive 'typerefs2' from 'f2.ts' of old program, it was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts'.",
|
||||
"Reusing resolution of module './b2' from 'f2.ts' of old program, it was successfully resolved to 'b2.ts'.",
|
||||
"Reusing resolution of module './f1' from 'f2.ts' of old program, it was successfully resolved to 'f1.ts'.",
|
||||
], "program_4: reuse module resolutions in f2 since it is unchanged");
|
||||
@@ -573,11 +561,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File 'b1.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name './b1' was successfully resolved to 'b1.ts'. ========",
|
||||
"======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========",
|
||||
"Resolving with primary search path 'node_modules/@types'.",
|
||||
"File 'node_modules/@types/typerefs2/package.json' does not exist.",
|
||||
"File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========",
|
||||
"Reusing resolution of type reference directive 'typerefs2' from 'f2.ts' of old program, it was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts'.",
|
||||
"Reusing resolution of module './b2' from 'f2.ts' of old program, it was successfully resolved to 'b2.ts'.",
|
||||
"Reusing resolution of module './f1' from 'f2.ts' of old program, it was successfully resolved to 'f1.ts'.",
|
||||
], "program_6: reuse module resolutions in f2 since it is unchanged");
|
||||
@@ -593,11 +577,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
assert.lengthOf(program7Diagnostics, expectedErrors, `removing import is noop with respect to program, so no change in diagnostics.`);
|
||||
|
||||
assert.deepEqual(program7.host.getTrace(), [
|
||||
"======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========",
|
||||
"Resolving with primary search path 'node_modules/@types'.",
|
||||
"File 'node_modules/@types/typerefs2/package.json' does not exist.",
|
||||
"File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========",
|
||||
"Reusing resolution of type reference directive 'typerefs2' from 'f2.ts' of old program, it was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts'.",
|
||||
"Reusing resolution of module './b2' from 'f2.ts' of old program, it was successfully resolved to 'b2.ts'.",
|
||||
"Reusing resolution of module './f1' from 'f2.ts' of old program, it was successfully resolved to 'f1.ts'.",
|
||||
], "program_7 should reuse module resolutions in f2 since it is unchanged");
|
||||
|
||||
@@ -328,4 +328,93 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
ts.tscWatch.verifyTscWatch({
|
||||
scenario: "moduleResolution",
|
||||
subScenario: "type reference resolutions reuse",
|
||||
sys: () => ts.tscWatch.createWatchedSystem([
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { moduleResolution: "node16" },
|
||||
})
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/index.ts`,
|
||||
content: Utils.dedent`
|
||||
/// <reference types="pkg" resolution-mode="import"/>
|
||||
/// <reference types="pkg1" resolution-mode="require"/>
|
||||
export interface LocalInterface extends RequireInterface {}
|
||||
`
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/a.ts`,
|
||||
content: Utils.dedent`
|
||||
export const x = 10;
|
||||
`
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/node_modules/pkg/package.json`,
|
||||
content: JSON.stringify({
|
||||
name: "pkg",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
import: "./import.js",
|
||||
require: "./require.js"
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/node_modules/pkg/import.d.ts`,
|
||||
content: Utils.dedent`
|
||||
export {};
|
||||
declare global {
|
||||
interface ImportInterface {}
|
||||
}
|
||||
`
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/node_modules/pkg/require.d.ts`,
|
||||
content: Utils.dedent`
|
||||
export {};
|
||||
declare global {
|
||||
interface RequireInterface {}
|
||||
}
|
||||
`
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/node_modules/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
name: "pkg1",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
import: "./import.js",
|
||||
require: "./require.js"
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/node_modules/pkg1/import.d.ts`,
|
||||
content: Utils.dedent`
|
||||
export {};
|
||||
declare global {
|
||||
interface ImportInterface {}
|
||||
}
|
||||
`
|
||||
},
|
||||
{
|
||||
path: `${ts.tscWatch.projectRoot}/node_modules/@types/pkg2/index.d.ts`,
|
||||
content: `export const x = 10;`
|
||||
},
|
||||
ts.tscWatch.libFile
|
||||
], { currentDirectory: ts.tscWatch.projectRoot }),
|
||||
commandLineArgs: ["-w", "--traceResolution"],
|
||||
changes: [
|
||||
{
|
||||
caption: "modify aFile by adding import",
|
||||
change: sys => sys.prependFile(`${ts.tscWatch.projectRoot}/a.ts`, `/// <reference types="pkg" resolution-mode="import"/>\n`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user