Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ namespace ts {
shortName: "?",
type: "boolean"
},
{
name: "watch",
shortName: "w",
type: "boolean",
showInSimplifiedHelpView: true,
category: Diagnostics.Command_line_Options,
description: Diagnostics.Watch_input_files,
},
{
name: "preserveWatchOutput",
type: "boolean",
Expand All @@ -96,13 +104,12 @@ namespace ts {
category: Diagnostics.Advanced_Options,
description: Diagnostics.Print_names_of_generated_files_part_of_the_compilation
},

{
name: "watch",
shortName: "w",
name: "traceResolution",
type: "boolean",
showInSimplifiedHelpView: true,
category: Diagnostics.Command_line_Options,
description: Diagnostics.Watch_input_files,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Enable_tracing_of_the_name_resolution_process
},
];

Expand Down Expand Up @@ -581,12 +588,6 @@ namespace ts {
category: Diagnostics.Advanced_Options,
description: Diagnostics.Show_verbose_diagnostic_information
},
{
name: "traceResolution",
type: "boolean",
category: Diagnostics.Advanced_Options,
description: Diagnostics.Enable_tracing_of_the_name_resolution_process
},
{
name: "resolveJsonModule",
type: "boolean",
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ namespace ts {
if (symbol) {
(exportedModulesFromDeclarationEmit || (exportedModulesFromDeclarationEmit = [])).push(symbol);
}
if ((options.outDir || options.declarationDir) && pathIsRelative(input.text) && currentSourceFile.redirectedReferences) {
const normalizedTargetPath = getNormalizedAbsolutePath(input.text, getDirectoryPath(currentSourceFile.fileName));
for (const ext of [Extension.Ts, Extension.Tsx]) {
const probePath = normalizedTargetPath + ext;
if (currentSourceFile.redirectedReferences.indexOf(probePath) >= 0) {
const outputDir = getDirectoryPath(getOutputPathsFor(currentSourceFile, host, /*forceDtsPaths*/ true).declarationFilePath!);
const relativePath = getRelativePathFromDirectory(outputDir, normalizedTargetPath, host.getCanonicalFileName);
return createLiteral(relativePath);
}
}
}
}
}
return input;
Expand Down
91 changes: 77 additions & 14 deletions src/testRunner/unittests/tsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace ts {
export namespace Sample1 {
tick();
const projFs = loadProjectFromDisk("tests/projects/sample1");

const sample1ProjectOutput = loadOutputProjectFromDisk("sample1");
const allExpectedOutputs = ["/src/tests/index.js",
"/src/core/index.js", "/src/core/index.d.ts", "/src/core/index.d.ts.map",
"/src/logic/index.js", "/src/logic/index.js.map", "/src/logic/index.d.ts"];
Expand All @@ -17,11 +17,34 @@ namespace ts {
host.clearDiagnostics();
builder.buildAllProjects();
host.assertDiagnosticMessages(/*empty*/);
// Check for outputs
verifyOutputsFs(fs, sample1ProjectOutput, "/src");
});

// Check for outputs. Not an exhaustive list
for (const output of allExpectedOutputs) {
assert(fs.existsSync(output), `Expect file ${output} to exist`);
}
it("builds correctly when outDir is specified", () => {
const fs = projFs.shadow();
fs.writeFileSync("/src/logic/tsconfig.json", JSON.stringify({
compilerOptions: { composite: true, declaration: true, outDir: "outDir" },
references: [{ path: "../core" }]
}));
const host = new fakes.SolutionBuilderHost(fs);
const builder = createSolutionBuilder(host, ["/src/tests"], { });
builder.buildAllProjects();
host.assertDiagnosticMessages(/*empty*/);
verifyOutputs(fs, "sample1WithLogicOutDir");
});

it("builds correctly when declarationDir is specified", () => {
const fs = projFs.shadow();
fs.writeFileSync("/src/logic/tsconfig.json", JSON.stringify({
compilerOptions: { composite: true, declaration: true, declarationDir: "out/decls" },
references: [{ path: "../core" }]
}));
const host = new fakes.SolutionBuilderHost(fs);
const builder = createSolutionBuilder(host, ["/src/tests"], {});
builder.buildAllProjects();
host.assertDiagnosticMessages(/*empty*/);
verifyOutputs(fs, "sample1WithLogicDeclarationDir");
});
});

Expand All @@ -34,9 +57,7 @@ namespace ts {
host.assertDiagnosticMessages(Diagnostics.A_non_dry_build_would_build_project_0, Diagnostics.A_non_dry_build_would_build_project_0, Diagnostics.A_non_dry_build_would_build_project_0);

// Check for outputs to not be written. Not an exhaustive list
for (const output of allExpectedOutputs) {
assert(!fs.existsSync(output), `Expect file ${output} to not exist`);
}
verifyOutputsNotExistOnFs(fs, sample1ProjectOutput, "/src");
});

it("indicates that it would skip builds during a dry build", () => {
Expand All @@ -62,14 +83,10 @@ namespace ts {
const builder = createSolutionBuilder(host, ["/src/tests"], { dry: false, force: false, verbose: false });
builder.buildAllProjects();
// Verify they exist
for (const output of allExpectedOutputs) {
assert(fs.existsSync(output), `Expect file ${output} to exist`);
}
verifyOutputsFs(fs, sample1ProjectOutput, "/src");
builder.cleanAllProjects();
// Verify they are gone
for (const output of allExpectedOutputs) {
assert(!fs.existsSync(output), `Expect file ${output} to not exist`);
}
verifyOutputsNotExistOnFs(fs, sample1ProjectOutput, "/src");
// Subsequent clean shouldn't throw / etc
builder.cleanAllProjects();
});
Expand Down Expand Up @@ -529,4 +546,50 @@ export class cNew {}`);
fs.makeReadonly();
return fs;
}

function loadOutputProjectFromDisk(project: string): vfs.FileSystem {
const resolver = vfs.createResolver(Harness.IO);
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
files: {
["/src"]: new vfs.Mount(vpath.resolve(Harness.IO.getWorkspaceRoot(), `tests/baselines/reference/projects/${project}`), resolver)
},
cwd: "/",
time,
});
fs.makeReadonly();
return fs;
}

function verifyOutputs(buildFs: vfs.FileSystem, expectedOutputProject: string) {
const fs = loadOutputProjectFromDisk(expectedOutputProject);
verifyOutputsFs(buildFs, fs, "/src");
}

function verifyOutputsFs(buildFs: vfs.FileSystem, expectedOutputFs: vfs.FileSystem, directory: string) {
withOutputFs(expectedOutputFs, directory, outputFile => {
const actual = buildFs.readFileSync(outputFile, "utf8");
const expected = expectedOutputFs.readFileSync(outputFile, "utf8");
assert.equal(actual, expected, `File contents of ${outputFile} expected to be:
actual: ${actual}
expected: ${expected}`);
});
}

function verifyOutputsNotExistOnFs(buildFs: vfs.FileSystem, expectedOutputFs: vfs.FileSystem, directory: string) {
withOutputFs(expectedOutputFs, directory, outputFile =>
assert(!buildFs.existsSync(outputFile), `Expect file ${outputFile} to not exist`));
}

function withOutputFs(expectedOutputFs: vfs.FileSystem, directory: string, actionOnFile: (outputFile: string) => void) {
const children = expectedOutputFs.readdirSync(directory);
for (const child of children) {
const fullName = `${directory}/${child}`;
if (expectedOutputFs.statSync(fullName).isFile()) {
actionOnFile(fullName);
}
else {
withOutputFs(expectedOutputFs, fullName, actionOnFile);
}
}
}
}
6 changes: 1 addition & 5 deletions src/testRunner/unittests/tsbuildWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,7 @@ export function gfoo() {
solutionBuilder.buildInvalidatedProject();

host.checkTimeoutQueueLengthAndRun(1);
checkOutputErrorsIncremental(host, [
// TODO: #26036
// The error is reported in d.ts file because it isnt resolved from ts file path, but is resolved from .d.ts file
"sample1/logic/decls/index.d.ts(2,22): error TS2307: Cannot find module '../core/anotherModule'.\n"
]);
checkOutputErrorsIncremental(host, emptyArray);
checkProgramActualFiles(watch().getProgram(), [tests[1].path, libFile.path, coreIndexDts, coreAnotherModuleDts, projectFilePath(SubProject.logic, "decls/index.d.ts")]);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const World = "hello";
//# sourceMappingURL=anotherModule.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
exports.__esModule = true;
exports.World = "hello";
4 changes: 4 additions & 0 deletions tests/baselines/reference/projects/sample1/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare const someString: string;
export declare function leftPad(s: string, n: number): string;
export declare function multiply(a: number, b: number): number;
//# sourceMappingURL=index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/baselines/reference/projects/sample1/core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";
exports.__esModule = true;
exports.someString = "HELLO WORLD";
function leftPad(s, n) { return s + n; }
exports.leftPad = leftPad;
function multiply(a, b) { return a * b; }
exports.multiply = multiply;
3 changes: 3 additions & 0 deletions tests/baselines/reference/projects/sample1/logic/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function getSecondsInDay(): number;
import * as mod from '../core/anotherModule';
export declare const m: typeof mod;
10 changes: 10 additions & 0 deletions tests/baselines/reference/projects/sample1/logic/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/baselines/reference/projects/sample1/tests/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as mod from '../core/anotherModule';
export declare const m: typeof mod;
8 changes: 8 additions & 0 deletions tests/baselines/reference/projects/sample1/tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
exports.__esModule = true;
var c = require("../core/index");
var logic = require("../logic/index");
c.leftPad("", 10);
logic.getSecondsInDay();
var mod = require("../core/anotherModule");
exports.m = mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const World = "hello";
//# sourceMappingURL=anotherModule.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
exports.__esModule = true;
exports.World = "hello";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare const someString: string;
export declare function leftPad(s: string, n: number): string;
export declare function multiply(a: number, b: number): number;
//# sourceMappingURL=index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";
exports.__esModule = true;
exports.someString = "HELLO WORLD";
function leftPad(s, n) { return s + n; }
exports.leftPad = leftPad;
function multiply(a, b) { return a * b; }
exports.multiply = multiply;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
exports.__esModule = true;
var c = require("../core/index");
function getSecondsInDay() {
return c.multiply(10, 15);
}
exports.getSecondsInDay = getSecondsInDay;
var mod = require("../core/anotherModule");
exports.m = mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function getSecondsInDay(): number;
import * as mod from "../../../core/anotherModule";
export declare const m: typeof mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as mod from '../core/anotherModule';
export declare const m: typeof mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
exports.__esModule = true;
var c = require("../core/index");
var logic = require("../logic/index");
c.leftPad("", 10);
logic.getSecondsInDay();
var mod = require("../core/anotherModule");
exports.m = mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const World = "hello";
//# sourceMappingURL=anotherModule.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
exports.__esModule = true;
exports.World = "hello";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare const someString: string;
export declare function leftPad(s: string, n: number): string;
export declare function multiply(a: number, b: number): number;
//# sourceMappingURL=index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";
exports.__esModule = true;
exports.someString = "HELLO WORLD";
function leftPad(s, n) { return s + n; }
exports.leftPad = leftPad;
function multiply(a, b) { return a * b; }
exports.multiply = multiply;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function getSecondsInDay(): number;
import * as mod from "../../core/anotherModule";
export declare const m: typeof mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
exports.__esModule = true;
var c = require("../core/index");
function getSecondsInDay() {
return c.multiply(10, 15);
}
exports.getSecondsInDay = getSecondsInDay;
var mod = require("../core/anotherModule");
exports.m = mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as mod from '../core/anotherModule';
export declare const m: typeof mod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
exports.__esModule = true;
var c = require("../core/index");
var logic = require("../logic/index");
c.leftPad("", 10);
logic.getSecondsInDay();
var mod = require("../core/anotherModule");
exports.m = mod;