Skip to content
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

[WIP] buildInfo to manipulate and update output of --out when .d.ts of reference doesnt change #29738

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
edfc91a
Write testcase to baseline with strict, prologues, shebangs
sheetalkamat Nov 7, 2018
607891b
Generate readable source map baselines for -b --out scenario
sheetalkamat Jan 16, 2019
6e57709
Handle shebang when using prepend nodes
sheetalkamat Jan 16, 2019
a90ff10
Tests for multiple prologues
sheetalkamat Jan 16, 2019
c739def
Handle prologues in prepend outputs
sheetalkamat Jan 17, 2019
36eae04
Handle emit helpers in --out scenario
sheetalkamat Jan 23, 2019
ff027d4
Handle triple slash refs
sheetalkamat Jan 25, 2019
0aaa880
Use bundle info to store info about prologues, emit Helpers, referenc…
sheetalkamat Jan 26, 2019
d5b5f8d
Handle --clean with .tsbuildinfo
sheetalkamat Jan 29, 2019
9dabe69
Dont assert but verify sourceMapGenerator
sheetalkamat Jan 29, 2019
36ae7be
Create tests when bundleInfo file is not present
sheetalkamat Jan 29, 2019
717dad9
Dont use tsbundleInfo to determine if bundle needs to be rebuilt
sheetalkamat Jan 29, 2019
c8ff9ac
Merge branch 'master' into prependWithBundleInfo
sheetalkamat Jan 30, 2019
00873f6
Make file generic to be .tsbuildinfo
sheetalkamat Jan 30, 2019
0d9cf96
Make the bundle info into buildInfo
sheetalkamat Jan 30, 2019
315a4dd
Merge branch 'master' into prependWithBundleInfo
sheetalkamat Jan 30, 2019
bb76259
More logs verification
sheetalkamat Jan 30, 2019
d1f3aca
Test case when final project isnt composite project
sheetalkamat Jan 31, 2019
aa74fa1
Fix UnparsedPrologue kind
sheetalkamat Jan 31, 2019
bd76940
If the project only needs prepend output to be changed, prepare to ju…
sheetalkamat Jan 30, 2019
39e37a2
Generate .tsbuildInfo if bundle uses references with prepend
sheetalkamat Jan 31, 2019
362c78e
Create prepend text sections in .buildInfo
sheetalkamat Jan 31, 2019
b15cb6b
Create nodes for unparsed text, prepend text
sheetalkamat Jan 31, 2019
38e0d4d
Add SourceMapUrl to section
sheetalkamat Jan 31, 2019
f7281e3
Use same property name for BundleFileSection and UnparsedNode for eas…
sheetalkamat Jan 31, 2019
db3a4fe
Separate out the tests for tsbuild into its own folder
sheetalkamat Jan 31, 2019
4205eaf
Baseline incremental build baselines
sheetalkamat Feb 1, 2019
3cf46f1
Dont diff with only sources in incremental compilation, diff with the…
sheetalkamat Feb 1, 2019
b7defb3
Some more reorg in test
sheetalkamat Feb 1, 2019
10f0131
Dont do base build again for each incremental scenario
sheetalkamat Feb 1, 2019
79b5992
Verify header updates
sheetalkamat Feb 1, 2019
03fa5bd
Merge branch 'master' into usePrependToSkipBuild
sheetalkamat Feb 1, 2019
66dab21
More refactoring
sheetalkamat Feb 1, 2019
a41d546
Store commonSourceDirectory
sheetalkamat Feb 1, 2019
4050378
Add source information to bundle info and use it to emit header infor…
sheetalkamat Feb 2, 2019
e3eb7bc
Add helpers from source files to the bundleInfo to be used later
sheetalkamat Feb 2, 2019
00917a4
Store pologue information in bundle info
sheetalkamat Feb 4, 2019
aa5d62a
Perform only emit on js file if no decl file change
sheetalkamat Feb 1, 2019
acec3c1
Use stored helpers to emit incrementally
sheetalkamat Feb 2, 2019
a64e5ad
Even though .d.ts doesnt change, the map file most likely changes, so…
sheetalkamat Feb 2, 2019
d9ead78
Map dts file to sections to write and fix from
sheetalkamat Feb 2, 2019
16914cc
Factor out unparsed source file for own creation
sheetalkamat Feb 4, 2019
a0a4e6b
Update test baselines
sheetalkamat Feb 4, 2019
3593685
Use prologue directive information in buildInfo to emit prologues whe…
sheetalkamat Feb 4, 2019
87bb6c9
Merge branch 'master' into usePrependToSkipBuild
sheetalkamat Feb 4, 2019
207ab9c
Since dts file doesnt change the dts bundle info doesnt change either…
sheetalkamat Feb 5, 2019
e6b74ef
Factor out baseline generation into tsbuild helper so that sample can…
sheetalkamat Feb 5, 2019
0571631
Generate baseline of .tsbuildinfo sections
sheetalkamat Feb 6, 2019
ee9d343
Generate baselines for sample
sheetalkamat Feb 5, 2019
3a28fb0
Add another test to generate baseline when sample's logic config file…
sheetalkamat Feb 7, 2019
ab7d65e
Merge branch 'master' into usePrependToSkipBuild
sheetalkamat Feb 7, 2019
ada1c3f
Fix missing comma
sheetalkamat Feb 7, 2019
9794080
Merge branch 'master' into usePrependToSkipBuild
sheetalkamat Feb 7, 2019
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
21 changes: 20 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3920,7 +3920,6 @@
"category": "Message",
"code": 6353
},

"Project '{0}' is up to date with .d.ts files from its dependencies": {
"category": "Message",
"code": 6354
Expand Down Expand Up @@ -3993,6 +3992,26 @@
"category": "Message",
"code": 6371
},
"Project '{0}' is out of date because output javascript and source map (if specified) of its dependency '{1}' has changed": {
"category": "Message",
"code": 6372
},
"Updating output javascript and javascript source map (if specified) of project '{0}'...": {
"category": "Message",
"code": 6373
},
"A non-dry build would update timestamps for output of project '{0}'": {
"category": "Message",
"code": 6374
},
"A non-dry build would update output javascript and javascript source map (if specified) of project '{0}'": {
"category": "Message",
"code": 6375
},
"Cannot update output javascript and javascript source map (if specified) of project '{0}' because there was error reading file '{1}'": {
"category": "Message",
"code": 6376
},

"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
Expand Down
458 changes: 390 additions & 68 deletions src/compiler/emitter.ts

Large diffs are not rendered by default.

265 changes: 253 additions & 12 deletions src/compiler/factory.ts

Large diffs are not rendered by default.

54 changes: 30 additions & 24 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ namespace ts {
function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
return {
getPrependNodes,
getProjectReferences,
getCanonicalFileName,
getCommonSourceDirectory: program.getCommonSourceDirectory,
getCompilerOptions: program.getCompilerOptions,
Expand Down Expand Up @@ -1442,30 +1443,16 @@ namespace ts {
return projectReferences;
}

function getPrependNodes(): InputFiles[] {
if (!projectReferences) {
return emptyArray;
}

const nodes: InputFiles[] = [];
for (let i = 0; i < projectReferences.length; i++) {
const ref = projectReferences[i];
const resolvedRefOpts = resolvedProjectReferences![i]!.commandLine;
if (ref.prepend && resolvedRefOpts && resolvedRefOpts.options) {
const out = resolvedRefOpts.options.outFile || resolvedRefOpts.options.out;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out) continue;

const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true);
const node = createInputFiles(fileName => {
const path = toPath(fileName);
const sourceFile = getSourceFileByPath(path);
return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
}, jsFilePath! , sourceMapFilePath, declarationFilePath! , declarationMapPath);
nodes.push(node);
function getPrependNodes() {
return createPrependNodes(
projectReferences,
(_ref, index) => resolvedProjectReferences![index]!.commandLine,
fileName => {
const path = toPath(fileName);
const sourceFile = getSourceFileByPath(path);
return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
}
}
return nodes;
);
}

function isSourceFileFromExternalLibrary(file: SourceFile): boolean {
Expand Down Expand Up @@ -1562,7 +1549,7 @@ namespace ts {
const emitResult = emitFiles(
emitResolver,
getEmitHost(writeFileCallback),
sourceFile!, // TODO: GH#18217
sourceFile,
emitOnlyDtsFiles,
transformers,
customTransformers && customTransformers.afterDeclarations
Expand Down Expand Up @@ -3140,6 +3127,25 @@ namespace ts {
fileExists(fileName: string): boolean;
}

/* @internal */
export function createPrependNodes(projectReferences: ReadonlyArray<ProjectReference> | undefined, getCommandLine: (ref: ProjectReference, index: number) => ParsedCommandLine | undefined, readFile: (path: string) => string | undefined) {
if (!projectReferences) return emptyArray;
let nodes: InputFiles[] | undefined;
for (let i = 0; i < projectReferences.length; i++) {
const ref = projectReferences[i];
const resolvedRefOpts = getCommandLine(ref, i);
if (ref.prepend && resolvedRefOpts && resolvedRefOpts.options) {
const out = resolvedRefOpts.options.outFile || resolvedRefOpts.options.out;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out) continue;

const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true, resolvedRefOpts.projectReferences);
const node = createInputFiles(readFile, jsFilePath!, sourceMapFilePath, declarationFilePath!, declarationMapPath, buildInfoPath);
(nodes || (nodes = [])).push(node);
}
}
return nodes || emptyArray;
}
/**
* Returns the target config filename of a project reference.
* Note: The file might not exist.
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,15 @@ namespace ts {

const shebangTriviaRegex = /^#!.*/;

function isShebangTrivia(text: string, pos: number) {
/*@internal*/
export function isShebangTrivia(text: string, pos: number) {
// Shebangs check must only be done at the start of the file
Debug.assert(pos === 0);
return shebangTriviaRegex.test(text);
}

function scanShebangTrivia(text: string, pos: number) {
/*@internal*/
export function scanShebangTrivia(text: string, pos: number) {
const shebang = shebangTriviaRegex.exec(text)![0];
pos = pos + shebang.length;
return pos;
Expand Down
19 changes: 16 additions & 3 deletions src/compiler/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace ts {
exit();
}

function appendSourceMap(generatedLine: number, generatedCharacter: number, map: RawSourceMap, sourceMapPath: string) {
function appendSourceMap(generatedLine: number, generatedCharacter: number, map: RawSourceMap, sourceMapPath: string, start?: LineAndCharacter, end?: LineAndCharacter) {
Debug.assert(generatedLine >= pendingGeneratedLine, "generatedLine cannot backtrack");
Debug.assert(generatedCharacter >= 0, "generatedCharacter cannot be negative");
enter();
Expand All @@ -149,6 +149,17 @@ namespace ts {
let nameIndexToNewNameIndexMap: number[] | undefined;
const mappingIterator = decodeMappings(map.mappings);
for (let { value: raw, done } = mappingIterator.next(); !done; { value: raw, done } = mappingIterator.next()) {
if (end && (
raw.generatedLine > end.line ||
(raw.generatedLine === end.line && raw.generatedCharacter > end.character))) {
break;
}

if (start && (
raw.generatedLine < start.line ||
(start.line === raw.generatedLine && raw.generatedCharacter < start.character))) {
continue;
}
// Then reencode all the updated mappings into the overall map
let newSourceIndex: number | undefined;
let newSourceLine: number | undefined;
Expand Down Expand Up @@ -178,8 +189,10 @@ namespace ts {
}
}

const newGeneratedLine = raw.generatedLine + generatedLine;
const newGeneratedCharacter = raw.generatedLine === 0 ? raw.generatedCharacter + generatedCharacter : raw.generatedCharacter;
const rawGeneratedLine = raw.generatedLine - (start ? start.line : 0);
const newGeneratedLine = rawGeneratedLine + generatedLine;
const rawGeneratedCharacter = start && start.line === raw.generatedLine ? raw.generatedCharacter - start.character : raw.generatedCharacter;
const newGeneratedCharacter = rawGeneratedLine === 0 ? rawGeneratedCharacter + generatedCharacter : rawGeneratedCharacter;
addMapping(newGeneratedLine, newGeneratedCharacter, newSourceIndex, newSourceLine, newSourceCharacter, newNameIndex);
}
exit();
Expand Down
16 changes: 11 additions & 5 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace ts {
const { noResolve, stripInternal } = options;
return transformRoot;

function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: string[] | undefined): void {
function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: ReadonlyArray<string> | undefined): void {
if (!typeReferenceDirectives) {
return;
}
Expand Down Expand Up @@ -207,8 +207,14 @@ namespace ts {
}
), mapDefined(node.prepends, prepend => {
if (prepend.kind === SyntaxKind.InputFiles) {
return createUnparsedSourceFile(prepend, "dts");
const sourceFile = createUnparsedSourceFile(prepend, "dts");
hasNoDefaultLib = hasNoDefaultLib || !!sourceFile.hasNoDefaultLib;
collectReferences(sourceFile, refs);
recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
collectLibs(sourceFile, libs);
return sourceFile;
}
return prepend;
}));
bundle.syntheticFileReferences = [];
bundle.syntheticTypeReferences = getFileReferencesForUsedTypeReferences();
Expand Down Expand Up @@ -311,8 +317,8 @@ namespace ts {
}
}

function collectReferences(sourceFile: SourceFile, ret: Map<SourceFile>) {
if (noResolve || isSourceFileJS(sourceFile)) return ret;
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: Map<SourceFile>) {
if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret;
forEach(sourceFile.referencedFiles, f => {
const elem = tryResolveScriptReference(host, sourceFile, f);
if (elem) {
Expand All @@ -322,7 +328,7 @@ namespace ts {
return ret;
}

function collectLibs(sourceFile: SourceFile, ret: Map<boolean>) {
function collectLibs(sourceFile: SourceFile | UnparsedSource, ret: Map<boolean>) {
forEach(sourceFile.libReferenceDirectives, ref => {
const lib = host.getLibFileFromReference(ref);
if (lib) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/destructuring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ namespace ts {
return name;
}

const restHelper: EmitHelper = {
export const restHelper: UnscopedEmitHelper = {
name: "typescript:rest",
scoped: false,
text: `
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4383,7 +4383,7 @@ namespace ts {
);
}

const extendsHelper: EmitHelper = {
export const extendsHelper: UnscopedEmitHelper = {
name: "typescript:extends",
scoped: false,
priority: 0,
Expand All @@ -4404,7 +4404,7 @@ namespace ts {
})();`
};

const templateObjectHelper: EmitHelper = {
export const templateObjectHelper: UnscopedEmitHelper = {
name: "typescript:makeTemplateObject",
scoped: false,
priority: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2017.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ namespace ts {
NodeFlags.Const));
}

const awaiterHelper: EmitHelper = {
export const awaiterHelper: UnscopedEmitHelper = {
name: "typescript:awaiter",
scoped: false,
priority: 5,
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/transformers/es2018.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ namespace ts {
}
}

const assignHelper: EmitHelper = {
export const assignHelper: UnscopedEmitHelper = {
name: "typescript:assign",
scoped: false,
priority: 1,
Expand Down Expand Up @@ -948,7 +948,7 @@ namespace ts {
);
}

const awaitHelper: EmitHelper = {
export const awaitHelper: UnscopedEmitHelper = {
name: "typescript:await",
scoped: false,
text: `
Expand All @@ -960,7 +960,7 @@ namespace ts {
return createCall(getHelperName("__await"), /*typeArguments*/ undefined, [expression]);
}

const asyncGeneratorHelper: EmitHelper = {
export const asyncGeneratorHelper: UnscopedEmitHelper = {
name: "typescript:asyncGenerator",
scoped: false,
text: `
Expand Down Expand Up @@ -995,7 +995,7 @@ namespace ts {
);
}

const asyncDelegator: EmitHelper = {
export const asyncDelegator: UnscopedEmitHelper = {
name: "typescript:asyncDelegator",
scoped: false,
text: `
Expand All @@ -1019,7 +1019,7 @@ namespace ts {
);
}

const asyncValues: EmitHelper = {
export const asyncValues: UnscopedEmitHelper = {
name: "typescript:asyncValues",
scoped: false,
text: `
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,7 @@ namespace ts {
// entering a finally block.
//
// For examples of how these are used, see the comments in ./transformers/generators.ts
const generatorHelper: EmitHelper = {
export const generatorHelper: UnscopedEmitHelper = {
name: "typescript:generator",
scoped: false,
priority: 6,
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ namespace ts {
};

// emit helper for `import * as Name from "foo"`
const importStarHelper: EmitHelper = {
export const importStarHelper: UnscopedEmitHelper = {
name: "typescript:commonjsimportstar",
scoped: false,
text: `
Expand All @@ -1820,7 +1820,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};

// emit helper for `import Name from "foo"`
const importDefaultHelper: EmitHelper = {
export const importDefaultHelper: UnscopedEmitHelper = {
name: "typescript:commonjsimportdefault",
scoped: false,
text: `
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,7 @@ namespace ts {
);
}

const decorateHelper: EmitHelper = {
export const decorateHelper: UnscopedEmitHelper = {
name: "typescript:decorate",
scoped: false,
priority: 2,
Expand All @@ -3705,7 +3705,7 @@ namespace ts {
);
}

const metadataHelper: EmitHelper = {
export const metadataHelper: UnscopedEmitHelper = {
name: "typescript:metadata",
scoped: false,
priority: 3,
Expand All @@ -3730,7 +3730,7 @@ namespace ts {
);
}

const paramHelper: EmitHelper = {
export const paramHelper: UnscopedEmitHelper = {
name: "typescript:param",
scoped: false,
priority: 4,
Expand Down
Loading