Skip to content

Commit 47febfd

Browse files
committed
Add project reference test, update release
1 parent 77c8a91 commit 47febfd

File tree

28 files changed

+166
-38
lines changed

28 files changed

+166
-38
lines changed

gulpfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ async function runTest(name) {
9898
const newGulpTs = require('./release-2/main');
9999
const testTask = require(`./${path.posix.join(testDir, 'gulptask.js')}`);
100100

101+
const matchingLibs = testTask.match ? libs.filter(([, tsLib]) => testTask.match(tsLib)) : libs;
102+
if (matchingLibs.length === 0) return Promise.resolve();
103+
101104
fs.mkdirSync(outputDir);
102-
return Promise.all(libs.map(([tsVersion, tsLib]) => {
105+
return Promise.all(matchingLibs.map(([tsVersion, tsLib]) => {
103106
return new Promise((resolve, reject) => {
104107
const errors = [];
105108
let finishInfo;

release/compiler.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export declare class ProjectCompiler implements ICompiler {
1818
prepare(project: ProjectInfo): void;
1919
inputFile(file: File): void;
2020
inputDone(): void;
21-
private attachContentToFile(file, fileName, content);
22-
private emit(result, callback);
23-
private emitFile({file, jsFileName, dtsFileName, dtsMapFileName, jsContent, dtsContent, dtsMapContent, jsMapContent}, currentDirectory);
24-
private reportDiagnostics(diagnostics);
25-
private removeSourceMapComment(content);
21+
private attachContentToFile;
22+
private emit;
23+
private emitFile;
24+
private reportDiagnostics;
25+
private removeSourceMapComment;
2626
}
2727
export declare class FileCompiler implements ICompiler {
2828
host: Host;
@@ -31,7 +31,8 @@ export declare class FileCompiler implements ICompiler {
3131
private previousOutput;
3232
private compilationResult;
3333
prepare(project: ProjectInfo): void;
34-
private write(file, fileName, diagnostics, content, sourceMap);
34+
private write;
3535
inputFile(file: File): void;
3636
inputDone(): void;
3737
}
38+
//# sourceMappingURL=compiler.d.ts.map

release/compiler.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ class ProjectCompiler {
3232
this.project.options.sourceMap = this.hasSourceMap;
3333
const currentDirectory = utils.getCommonBasePathOfArray(rootFilenames.map(fileName => this.project.input.getFile(fileName).gulp.cwd));
3434
this.host = new host_1.Host(this.project.typescript, currentDirectory, this.project.input, this.project.options);
35-
this.program = this.project.typescript.createProgram(rootFilenames, this.project.options, this.host, this.program);
35+
// Calling `createProgram` with an object is only supported in 3.0. Only call this overload
36+
// if we have project references (also only supported in 3.0)
37+
this.program = this.project.projectReferences
38+
? this.project.typescript.createProgram({
39+
rootNames: rootFilenames,
40+
options: this.project.options,
41+
projectReferences: this.project.projectReferences,
42+
host: this.host,
43+
oldProgram: this.program
44+
})
45+
: this.project.typescript.createProgram(rootFilenames, this.project.options, this.host, this.program);
3646
const result = reporter_1.emptyCompilationResult(this.project.options.noEmit);
3747
result.optionsErrors = this.reportDiagnostics(this.program.getOptionsDiagnostics());
3848
result.syntaxErrors = this.reportDiagnostics(this.program.getSyntacticDiagnostics());

release/host.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export declare class Host implements ts.CompilerHost {
2020
getDirectories: (path: string) => string[];
2121
directoryExists: (path: string) => boolean;
2222
}
23+
//# sourceMappingURL=host.d.ts.map

release/input.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference types="vinyl" />
21
import * as ts from 'typescript';
32
import * as utils from './utils';
43
import * as VinylFile from 'vinyl';
@@ -7,11 +6,11 @@ export declare enum FileChangeState {
76
Equal = 1,
87
Modified = 2,
98
Deleted = 3,
10-
NotFound = 4,
9+
NotFound = 4
1110
}
1211
export declare enum FileKind {
1312
Source = 0,
14-
Config = 1,
13+
Config = 1
1514
}
1615
export interface FileChange {
1716
previous: File;
@@ -39,11 +38,11 @@ export declare class FileDictionary {
3938
constructor(typescript: typeof ts);
4039
addGulp(gFile: VinylFile): File;
4140
addContent(fileName: string, content: string): File;
42-
private addFile(file);
41+
private addFile;
4342
getFile(name: string): File;
4443
initTypeScriptSourceFile: (file: File) => void;
4544
getFileNames(onlyGulp?: boolean): string[];
46-
private getSourceFileNames(onlyGulp?);
45+
private getSourceFileNames;
4746
commonBasePath: string;
4847
commonSourceDirectory: string;
4948
}
@@ -58,8 +57,8 @@ export declare class FileCache {
5857
addGulp(gFile: VinylFile): File;
5958
addContent(fileName: string, content: string): File;
6059
reset(): void;
61-
private createDictionary();
62-
private initTypeScriptSourceFile(file);
60+
private createDictionary;
61+
private initTypeScriptSourceFile;
6362
getFile(name: string): File;
6463
getFileChange(name: string): FileChange;
6564
getFileNames(onlyGulp?: boolean): string[];
@@ -68,3 +67,4 @@ export declare class FileCache {
6867
commonSourceDirectory: string;
6968
isChanged(onlyGulp?: boolean): boolean;
7069
}
70+
//# sourceMappingURL=input.d.ts.map

release/main.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ declare module compile {
4747
function filter(...args: any[]): void;
4848
}
4949
export = compile;
50+
//# sourceMappingURL=main.d.ts.map

release/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function reportErrors(errors, typescript, ignore = []) {
8686
let projectDirectory = process.cwd();
8787
let typescript;
8888
let compilerOptions;
89+
let projectReferences;
8990
let fileName;
9091
let rawConfig;
9192
if (fileNameOrSettings !== undefined) {
@@ -118,10 +119,11 @@ function reportErrors(errors, typescript, ignore = []) {
118119
reportErrors(parsed.errors, typescript, [18003]);
119120
}
120121
compilerOptions = parsed.options;
122+
projectReferences = parsed.projectReferences;
121123
}
122124
}
123125
normalizeCompilerOptions(compilerOptions, typescript);
124-
const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, typescript);
126+
const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, projectReferences, typescript);
125127
return project;
126128
}
127129
compile.createProject = createProject;

release/output.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ export declare class Output {
1313
streamDts: stream.Readable;
1414
private pendingIO;
1515
writeJs(base: string, fileName: string, content: string, sourceMapContent: string, cwd: string, original: input.File): void;
16-
writeDts(base: string, fileName: string, content: string, declarationMapContent: string, cwd: string, original: input.File): Promise<void>;
17-
private applySourceMap(sourceMapContent, original, output);
16+
private writeJsAsync;
17+
writeDts(base: string, fileName: string, content: string, declarationMapContent: string, cwd: string, original: input.File): void;
18+
private writeDtsAsync;
19+
private applySourceMap;
20+
private pipeRejection;
1821
finish(result: reporter.CompilationResult): void;
19-
private mightFinish();
20-
private getError(info);
22+
private mightFinish;
23+
private getError;
2124
diagnostic(info: ts.Diagnostic): void;
2225
error(error: reporter.TypeScriptError): void;
2326
}
27+
//# sourceMappingURL=output.d.ts.map

release/output.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,31 @@ class Output {
2323
this.streamDts = streamDts;
2424
}
2525
writeJs(base, fileName, content, sourceMapContent, cwd, original) {
26-
const file = new VinylFile({
27-
path: fileName,
28-
contents: Buffer.from(content),
29-
cwd,
30-
base
31-
});
32-
this.pendingIO++;
33-
this.applySourceMap(sourceMapContent, original, file).then(appliedSourceMap => {
34-
if (appliedSourceMap)
35-
file.sourceMap = JSON.parse(appliedSourceMap);
36-
this.streamFull.push(file);
37-
this.streamJs.push(file);
38-
this.pendingIO--;
39-
this.mightFinish();
26+
this.pipeRejection(this.writeJsAsync(base, fileName, content, sourceMapContent, cwd, original), this.streamJs);
27+
}
28+
writeJsAsync(base, fileName, content, sourceMapContent, cwd, original) {
29+
return __awaiter(this, void 0, void 0, function* () {
30+
const file = new VinylFile({
31+
path: fileName,
32+
contents: Buffer.from(content),
33+
cwd,
34+
base
35+
});
36+
this.pendingIO++;
37+
yield this.applySourceMap(sourceMapContent, original, file).then(appliedSourceMap => {
38+
if (appliedSourceMap)
39+
file.sourceMap = JSON.parse(appliedSourceMap);
40+
this.streamFull.push(file);
41+
this.streamJs.push(file);
42+
this.pendingIO--;
43+
this.mightFinish();
44+
});
4045
});
4146
}
4247
writeDts(base, fileName, content, declarationMapContent, cwd, original) {
48+
this.pipeRejection(this.writeDtsAsync(base, fileName, content, declarationMapContent, cwd, original), this.streamDts);
49+
}
50+
writeDtsAsync(base, fileName, content, declarationMapContent, cwd, original) {
4351
return __awaiter(this, void 0, void 0, function* () {
4452
const file = new VinylFile({
4553
path: fileName,
@@ -48,7 +56,7 @@ class Output {
4856
base
4957
});
5058
this.pendingIO++;
51-
this.applySourceMap(declarationMapContent, original, file).then(appliedSourceMap => {
59+
yield this.applySourceMap(declarationMapContent, original, file).then(appliedSourceMap => {
5260
if (appliedSourceMap)
5361
file.sourceMap = JSON.parse(appliedSourceMap);
5462
this.streamFull.push(file);
@@ -102,6 +110,13 @@ class Output {
102110
}
103111
});
104112
}
113+
// Avoids UnhandledPromiseRejectionWarning in NodeJS
114+
pipeRejection(promise, alternateStream) {
115+
promise.catch(err => {
116+
this.streamFull.emit("error", err);
117+
alternateStream.emit("error", err);
118+
});
119+
}
105120
finish(result) {
106121
this.result = result;
107122
this.mightFinish();

release/project.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ export interface Project {
1515
readonly rawConfig: any;
1616
readonly config: TsConfig;
1717
readonly options: ts.CompilerOptions;
18+
readonly projectReferences: ReadonlyArray<ts.ProjectReference> | undefined;
1819
}
1920
export interface ProjectInfo {
2021
input: FileCache;
2122
output: Output;
2223
compiler: ICompiler;
2324
singleOutput: boolean;
2425
options: ts.CompilerOptions;
26+
projectReferences: ReadonlyArray<ts.ProjectReference>;
2527
typescript: typeof ts;
2628
directory: string;
2729
reporter: Reporter;
2830
}
29-
export declare function setupProject(projectDirectory: string, configFileName: string, rawConfig: any, config: TsConfig, options: ts.CompilerOptions, typescript: typeof ts): Project;
31+
export declare function setupProject(projectDirectory: string, configFileName: string, rawConfig: any, config: TsConfig, options: ts.CompilerOptions, projectReferences: ReadonlyArray<ts.ProjectReference>, typescript: typeof ts): Project;
3032
export interface ICompileStream extends NodeJS.ReadWriteStream {
3133
js: stream.Readable;
3234
dts: stream.Readable;
3335
}
36+
//# sourceMappingURL=project.d.ts.map

0 commit comments

Comments
 (0)