Skip to content

Emit .buildinfo file #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
path = typescript/2.7
url = https://github.com/Microsoft/TypeScript.git
branch = release-2.7
[submodule "typescript/3.4"]
path = typescript/3.4
url = https://github.com/Microsoft/TypeScript
branch = release-3.4
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const tsVersions = {
dev: './typescript/dev',
release23: './typescript/2.3',
release27: './typescript/2.7',
release29: './typescript/2.9'
release29: './typescript/2.9',
release34: './typescript/3.4'
};

function findTSDefinition(location) {
Expand Down Expand Up @@ -96,6 +97,7 @@ const libs = [
['2.7', require(tsVersions.release27)],
['2.3', require(tsVersions.release23)],
['2.9', require(tsVersions.release29)],
['3.4', require(tsVersions.release34)],
['dev', require(tsVersions.dev)]
];

Expand Down Expand Up @@ -156,7 +158,7 @@ async function runExecTest(testName) {
const testDir = path.posix.join('test', testName);

return new Promise((resolve, reject) => {
childProcess.execFile("gulp", {
childProcess.exec("gulp", {
cwd: testDir,
}, (err) => {
if (err) {
Expand Down
12 changes: 11 additions & 1 deletion lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface OutputFile {
jsMapContent?: string;
dtsContent?: string;
dtsMapContent?: string;
buildinfoFileName?: string;
buildinfoContent?: string;
}

/**
Expand Down Expand Up @@ -169,6 +171,10 @@ export class ProjectCompiler implements ICompiler {
case 'map':
file.jsMapContent = content;
break;
case 'tsbuildinfo':
file.buildinfoFileName = fileName;
file.buildinfoContent = content;
break;
}
}
private emit(result: CompilationResult, preEmitDiagnostics: ReadonlyArray<ts.DiagnosticWithLocation>, callback: ts.WriteFileCallback) {
Expand All @@ -193,7 +199,7 @@ export class ProjectCompiler implements ICompiler {
this.project.output.diagnostic(error);
}
}
private emitFile({ file, jsFileName, dtsFileName, dtsMapFileName, jsContent, dtsContent, dtsMapContent, jsMapContent }: OutputFile, currentDirectory: string) {
private emitFile({ file, jsFileName, dtsFileName, dtsMapFileName, jsContent, dtsContent, dtsMapContent, jsMapContent, buildinfoFileName, buildinfoContent }: OutputFile, currentDirectory: string) {
if (!jsFileName) return;

let base: string;
Expand Down Expand Up @@ -233,6 +239,10 @@ export class ProjectCompiler implements ICompiler {
}
this.project.output.writeDts(baseDeclarations, dtsFileName, dtsContent, dtsMapContent, file ? file.gulp.cwd : currentDirectory, file);
}
if (buildinfoContent !== undefined) {
this.project.output.writeBuildInfo(base, buildinfoFileName, buildinfoContent, file ? file.gulp.cwd : currentDirectory);
}

}

private removeSourceMapComment(content: string): string {
Expand Down
19 changes: 17 additions & 2 deletions lib/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ import * as reporter from './reporter';
import * as project from './project';

export class Output {
constructor(_project: project.ProjectInfo, streamFull: stream.Readable, streamJs: stream.Readable, streamDts: stream.Readable) {
constructor(_project: project.ProjectInfo, streamFull: stream.Readable, streamJs: stream.Readable, streamDts: stream.Readable, streamBuildInfo: stream.Readable) {
this.project = _project;
this.streamFull = streamFull;
this.streamJs = streamJs;
this.streamDts = streamDts;
this.streamBuildInfo = streamBuildInfo;
}

project: project.ProjectInfo;
result: reporter.CompilationResult;
// .js and .d.ts files
// .js and .d.ts and .tsbuildinfo files
streamFull: stream.Readable;
// .js files
streamJs: stream.Readable;
// .d.ts files
streamDts: stream.Readable;
// .tsbuildinfo files
streamBuildInfo: stream.Readable;

// Number of pending IO operatrions
private pendingIO = 0;
Expand Down Expand Up @@ -76,6 +79,18 @@ export class Output {
});
}

writeBuildInfo(base: string, fileName: string, content: string, cwd: string) {
const file = new VinylFile({
path: fileName,
contents: Buffer.from(content),
cwd,
base
});

this.streamFull.push(file);
this.streamBuildInfo.push(file);
}

private async applySourceMap(sourceMapContent: string, original: input.File, output: VinylFile) {
if (sourceMapContent === undefined) return undefined;

Expand Down
4 changes: 3 additions & 1 deletion lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function setupProject(projectDirectory: string, configFileName: string, r
compiler.prepare(projectInfo, finalTransformers);

const stream = new CompileStream(projectInfo);
projectInfo.output = new Output(projectInfo, stream, stream.js, stream.dts);
projectInfo.output = new Output(projectInfo, stream, stream.js, stream.dts, stream.buildInfo);
projectInfo.reporter = reporter || defaultReporter();

stream.on('finish', () => {
Expand Down Expand Up @@ -143,6 +143,7 @@ function src(this: Project) {
export interface ICompileStream extends NodeJS.ReadWriteStream {
js: stream.Readable;
dts: stream.Readable;
buildInfo: stream.Readable;
}
class CompileStream extends stream.Duplex implements ICompileStream {
constructor(project: ProjectInfo) {
Expand Down Expand Up @@ -188,6 +189,7 @@ class CompileStream extends stream.Duplex implements ICompileStream {

js: stream.Readable = new CompileOutputStream();
dts: stream.Readable = new CompileOutputStream();
buildInfo: stream.Readable = new CompileOutputStream();
}
class CompileOutputStream extends stream.Readable {
constructor() {
Expand Down
49 changes: 37 additions & 12 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@types/through2": "2.0.33",
"@types/vinyl": "2.0.2",
"@types/vinyl-fs": "2.4.9",
"compare-versions": "^3.5.1",
"gulp": "^4.0.0",
"gulp-concat": "^2.6.1",
"gulp-diff": "^1.0.0",
Expand Down
18 changes: 18 additions & 0 deletions test/baselines/base/3.4/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
TypeScript error: error TS2318: Cannot find global type 'Array'.
TypeScript error: error TS2318: Cannot find global type 'Boolean'.
TypeScript error: error TS2318: Cannot find global type 'Function'.
TypeScript error: error TS2318: Cannot find global type 'IArguments'.
TypeScript error: error TS2318: Cannot find global type 'Number'.
TypeScript error: error TS2318: Cannot find global type 'Object'.
TypeScript error: error TS2318: Cannot find global type 'RegExp'.
TypeScript error: error TS2318: Cannot find global type 'String'.
{
"transpileErrors": 0,
"optionsErrors": 0,
"syntaxErrors": 0,
"globalErrors": 8,
"semanticErrors": 0,
"declarationErrors": 0,
"emitErrors": 0,
"emitSkipped": false
}
1 change: 1 addition & 0 deletions test/baselines/base/3.4/js/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x = {};
3 changes: 3 additions & 0 deletions test/baselines/basic/3.4/dts/other-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class Hello {
value: string;
}
1 change: 1 addition & 0 deletions test/baselines/basic/3.4/dts/test-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
10 changes: 10 additions & 0 deletions test/baselines/basic/3.4/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"transpileErrors": 0,
"optionsErrors": 0,
"syntaxErrors": 0,
"globalErrors": 0,
"semanticErrors": 0,
"declarationErrors": 0,
"emitErrors": 0,
"emitSkipped": false
}
12 changes: 12 additions & 0 deletions test/baselines/basic/3.4/js/other-3.js

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

1 change: 1 addition & 0 deletions test/baselines/basic/3.4/js/other-3.js.map

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

Loading