Skip to content

"tsc -b" with minimal watch capabilities #24465

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

Merged
merged 53 commits into from
Jun 9, 2018
Merged
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
d98a9a0
WIP
RyanCavanaugh May 15, 2018
aeb5625
WIP
RyanCavanaugh May 17, 2018
a4eb156
WIP, need to lint
RyanCavanaugh May 17, 2018
b2720ad
Lint
RyanCavanaugh May 21, 2018
b1dedf2
WIP
RyanCavanaugh May 21, 2018
7e0825a
Clean, etc
RyanCavanaugh May 22, 2018
6d04378
Testing WIP
RyanCavanaugh May 22, 2018
76d2ba6
Testing WIP
SeaRyanC May 22, 2018
5a9a883
WIP
SeaRyanC May 22, 2018
18f2baa
Fix errors
RyanCavanaugh May 22, 2018
fa07830
Passing tests
RyanCavanaugh May 22, 2018
5a664be
Baseline accept
RyanCavanaugh May 22, 2018
d4a56b9
WIP more tests
RyanCavanaugh May 23, 2018
fc22b5b
WIP
RyanCavanaugh May 24, 2018
8a883ae
Comments
RyanCavanaugh May 24, 2018
0781279
Add resolution branding
RyanCavanaugh May 24, 2018
d9bfbfe
Fix tests run in parallel
RyanCavanaugh May 24, 2018
8936b03
Merge branch 'master' into tsbuild
RyanCavanaugh May 24, 2018
19ab8ab
Fix strictNullChecks breaks
RyanCavanaugh May 24, 2018
cb8aa9b
Don't use invalid cached SourceFiles
RyanCavanaugh May 24, 2018
8ac795b
Correctly skip upstream-blocked projects
RyanCavanaugh May 24, 2018
1863d3f
Graph ordering test WIP
RyanCavanaugh May 25, 2018
a7fcbcd
Use better toposorting algorithm
RyanCavanaugh May 25, 2018
70fa29b
Add graph ordering tests
RyanCavanaugh May 29, 2018
fe191fe
Merge branch 'master' into tsbuild
RyanCavanaugh May 29, 2018
129f747
VFS fixes
RyanCavanaugh May 29, 2018
f8c4301
Add more errors; commandline help for --build; invalid flag combo det…
RyanCavanaugh May 30, 2018
cd7a844
We definitely have a type system
RyanCavanaugh May 30, 2018
8adbf85
Candidate sectional sourcemap emit implementation
weswigham May 31, 2018
eb1973a
Fixup sourcemap positions and text writer calculations
weswigham May 31, 2018
d21c03a
Invalidation + separated downstream builds
RyanCavanaugh May 31, 2018
7a1de61
Scaffold watch mode
RyanCavanaugh Jun 1, 2018
7e9e29c
Store + use the resolved path of sourceFiles in proj. ref. scenarios
RyanCavanaugh Jun 1, 2018
9b0dc37
Merge branch 'fixMissingScriptInfo' into tsbuild
RyanCavanaugh Jun 4, 2018
45842a0
Merge remote-tracking branch 'weswigham/sourcemap-concatenation-stati…
RyanCavanaugh Jun 5, 2018
17dc380
Reorganize tsbuild unit test file
RyanCavanaugh Jun 5, 2018
514a0d8
Add outfile-concat project refs test
RyanCavanaugh Jun 5, 2018
394e29f
Accept baselines for sourcemap sections
RyanCavanaugh Jun 5, 2018
e407780
Complicate the paths of the project for better sourcemap testing
RyanCavanaugh Jun 5, 2018
449d60c
Don't crash on no args
RyanCavanaugh Jun 5, 2018
5065c54
Tidy
RyanCavanaugh Jun 5, 2018
fad8f67
Lint
RyanCavanaugh Jun 5, 2018
cf87bd4
Merge branch 'master' into tsbuild
RyanCavanaugh Jun 5, 2018
7ad9d57
Include filename when reporting not found
RyanCavanaugh Jun 5, 2018
5111f4d
Move proj ref logic to the right place
RyanCavanaugh Jun 5, 2018
11df004
Include all lib files in tsbuild harness
RyanCavanaugh Jun 5, 2018
856fc79
Lint
RyanCavanaugh Jun 5, 2018
291289f
Update messages
RyanCavanaugh Jun 6, 2018
b107849
Improve handling of container projects and issue relative filename me…
RyanCavanaugh Jun 6, 2018
21a65f5
Improved watch mode
RyanCavanaugh Jun 6, 2018
1de2f83
PR fixups
RyanCavanaugh Jun 9, 2018
b97bc8e
Use native map
SeaRyanC Jun 9, 2018
0f626fd
Last round PR comments
SeaRyanC Jun 9, 2018
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
127 changes: 127 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ namespace ts {
paramType: Diagnostics.FILE_OR_DIRECTORY,
description: Diagnostics.Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json,
},
{
name: "build",
type: "boolean",
shortName: "b",
showInSimplifiedHelpView: true,
category: Diagnostics.Command_line_Options,
description: Diagnostics.Build_one_or_more_projects_and_their_dependencies_if_out_of_date
},
{
name: "pretty",
type: "boolean",
Expand Down Expand Up @@ -968,6 +976,125 @@ namespace ts {
}


function getDiagnosticText(_message: DiagnosticMessage, ..._args: any[]): string {
const diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
return <string>diagnostic.messageText;
}

/* @internal */
export function printVersion() {
sys.write(getDiagnosticText(Diagnostics.Version_0, version) + sys.newLine);
}

/* @internal */
export function printHelp(optionsList: CommandLineOption[], syntaxPrefix = "") {
const output: string[] = [];

// We want to align our "syntax" and "examples" commands to a certain margin.
const syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
const examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length;
let marginLength = Math.max(syntaxLength, examplesLength);

// Build up the syntactic skeleton.
let syntax = makePadding(marginLength - syntaxLength);
syntax += `tsc ${syntaxPrefix}[${getDiagnosticText(Diagnostics.options)}] [${getDiagnosticText(Diagnostics.file)}...]`;

output.push(getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax));
output.push(sys.newLine + sys.newLine);

// Build up the list of examples.
const padding = makePadding(marginLength);
output.push(getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine);
output.push(padding + "tsc --outFile file.js file.ts" + sys.newLine);
output.push(padding + "tsc @args.txt" + sys.newLine);
output.push(padding + "tsc --build tsconfig.json" + sys.newLine);
output.push(sys.newLine);

output.push(getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine);

// We want our descriptions to align at the same column in our output,
// so we keep track of the longest option usage string.
marginLength = 0;
const usageColumn: string[] = []; // Things like "-d, --declaration" go in here.
const descriptionColumn: string[] = [];

const optionsDescriptionMap = createMap<string[]>(); // Map between option.description and list of option.type if it is a kind

for (const option of optionsList) {
// If an option lacks a description,
// it is not officially supported.
if (!option.description) {
continue;
}

let usageText = " ";
if (option.shortName) {
usageText += "-" + option.shortName;
usageText += getParamType(option);
usageText += ", ";
}

usageText += "--" + option.name;
usageText += getParamType(option);

usageColumn.push(usageText);
let description: string;

if (option.name === "lib") {
description = getDiagnosticText(option.description);
const element = (<CommandLineOptionOfListType>option).element;
const typeMap = <Map<number | string>>element.type;
optionsDescriptionMap.set(description, arrayFrom(typeMap.keys()).map(key => `'${key}'`));
}
else {
description = getDiagnosticText(option.description);
}

descriptionColumn.push(description);

// Set the new margin for the description column if necessary.
marginLength = Math.max(usageText.length, marginLength);
}

// Special case that can't fit in the loop.
const usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">";
usageColumn.push(usageText);
descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file));
marginLength = Math.max(usageText.length, marginLength);

// Print out each row, aligning all the descriptions on the same column.
for (let i = 0; i < usageColumn.length; i++) {
const usage = usageColumn[i];
const description = descriptionColumn[i];
const kindsList = optionsDescriptionMap.get(description);
output.push(usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine);

if (kindsList) {
output.push(makePadding(marginLength + 4));
for (const kind of kindsList) {
output.push(kind + " ");
}
output.push(sys.newLine);
}
}

for (const line of output) {
sys.write(line);
}
return;

function getParamType(option: CommandLineOption) {
if (option.paramType !== undefined) {
return " " + getDiagnosticText(option.paramType);
}
return "";
}

function makePadding(paddingLength: number): string {
return Array(paddingLength + 1).join(" ");
}
}

export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
/**
* Reports config file diagnostics
Expand Down
89 changes: 89 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,95 @@
"category": "Error",
"code": 6309
},
"Project '{0}' is out of date because oldest output '{1}' is older than newest input '{2}'": {
"category": "Message",
"code": 6350
},
"Project '{0}' is up to date because newest input '{1}' is older than oldest output '{2}'": {
"category": "Message",
"code": 6351
},
"Project '{0}' is out of date because output file '{1}' does not exist": {
"category": "Message",
"code": 6352
},
"Project '{0}' is out of date because its dependency '{1}' is out of date": {
"category": "Message",
"code": 6353
},

"Project '{0}' is up to date with .d.ts files from its dependencies": {
"category": "Message",
"code": 6354
},
"Projects in this build: {0}": {
"category": "Message",
"code": 6355
},
"A non-dry build would delete the following files: {0}": {
"category": "Message",
"code": 6356
},
"A non-dry build would build project '{0}'": {
"category": "Message",
"code": 6357
},
"Building project '{0}'...": {
"category": "Message",
"code": 6358
},
"Updating output timestamps of project '{0}'...": {
"category": "Message",
"code": 6359
},
"delete this - Project '{0}' is up to date because it was previously built": {
"category": "Message",
"code": 6360
},
"Project '{0}' is up to date": {
"category": "Message",
"code": 6361
},
"Skipping build of project '{0}' because its dependency '{1}' has errors": {
"category": "Message",
"code": 6362
},
"Project '{0}' can't be built because its dependency '{1}' has errors": {
"category": "Message",
"code": 6363
},
"Build one or more projects and their dependencies, if out of date": {
"category": "Message",
"code": 6364
},
"Delete the outputs of all projects": {
"category": "Message",
"code": 6365
},
"Enable verbose logging": {
"category": "Message",
"code": 6366
},
"Show what would be built (or deleted, if specified with '--clean')": {
"category": "Message",
"code": 6367
},
"Build all projects, including those that appear to be up to date": {
"category": "Message",
"code": 6368
},
"Option '--build' must be the first command line argument.": {
"category": "Error",
"code": 6369
},
"Options '{0}' and '{1}' cannot be combined.": {
"category": "Error",
"code": 6370
},
"Skipping clean because not all projects could be located": {
"category": "Error",
"code": 6371
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ namespace ts {

// SyntaxKind.UnparsedSource
function emitUnparsedSource(unparsed: UnparsedSource) {
write(unparsed.text);
writer.rawWrite(unparsed.text);
}

//
Expand Down
7 changes: 5 additions & 2 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2587,16 +2587,19 @@ namespace ts {
return node;
}

export function createUnparsedSourceFile(text: string): UnparsedSource {
export function createUnparsedSourceFile(text: string, map?: string): UnparsedSource {
const node = <UnparsedSource>createNode(SyntaxKind.UnparsedSource);
node.text = text;
node.sourceMapText = map;
return node;
}

export function createInputFiles(javascript: string, declaration: string): InputFiles {
export function createInputFiles(javascript: string, declaration: string, javascriptMapText?: string, declarationMapText?: string): InputFiles {
const node = <InputFiles>createNode(SyntaxKind.InputFiles);
node.javascriptText = javascript;
node.javascriptMapText = javascriptMapText;
node.declarationText = declaration;
node.declarationMapText = declarationMapText;
return node;
}

Expand Down
42 changes: 25 additions & 17 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ namespace ts {
getEnvironmentVariable: name => sys.getEnvironmentVariable ? sys.getEnvironmentVariable(name) : "",
getDirectories: (path: string) => sys.getDirectories(path),
realpath,
readDirectory: (path, extensions, include, exclude, depth) => sys.readDirectory(path, extensions, include, exclude, depth)
readDirectory: (path, extensions, include, exclude, depth) => sys.readDirectory(path, extensions, include, exclude, depth),
getModifiedTime: sys.getModifiedTime && (path => sys.getModifiedTime!(path)),
setModifiedTime: sys.setModifiedTime && ((path, date) => sys.setModifiedTime!(path, date)),
deleteFile: sys.deleteFile && (path => sys.deleteFile!(path))
};
}

Expand Down Expand Up @@ -615,25 +618,27 @@ namespace ts {
// A parallel array to projectReferences storing the results of reading in the referenced tsconfig files
const resolvedProjectReferences: (ResolvedProjectReference | undefined)[] | undefined = projectReferences ? [] : undefined;
const projectReferenceRedirects: Map<string> = createMap();
if (projectReferences) {
for (const ref of projectReferences) {
const parsedRef = parseProjectReferenceConfigFile(ref);
resolvedProjectReferences!.push(parsedRef);
if (parsedRef) {
if (parsedRef.commandLine.options.outFile) {
const dtsOutfile = changeExtension(parsedRef.commandLine.options.outFile, ".d.ts");
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
}
addProjectReferenceRedirects(parsedRef.commandLine, projectReferenceRedirects);
}
}
}

const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
const structuralIsReused = tryReuseStructureFromOldProgram();
if (structuralIsReused !== StructureIsReused.Completely) {
processingDefaultLibFiles = [];
processingOtherFiles = [];

if (projectReferences) {
for (const ref of projectReferences) {
const parsedRef = parseProjectReferenceConfigFile(ref);
resolvedProjectReferences!.push(parsedRef);
if (parsedRef) {
if (parsedRef.commandLine.options.outFile) {
const dtsOutfile = changeExtension(parsedRef.commandLine.options.outFile, ".d.ts");
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
}
addProjectReferenceRedirects(parsedRef.commandLine, projectReferenceRedirects);
}
}
}

forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false));

// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
Expand Down Expand Up @@ -1021,7 +1026,7 @@ namespace ts {

for (const oldSourceFile of oldSourceFiles) {
let newSourceFile = host.getSourceFileByPath
? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.path, options.target!, /*onError*/ undefined, shouldCreateNewSourceFile)
? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath || oldSourceFile.path, options.target!, /*onError*/ undefined, shouldCreateNewSourceFile)
: host.getSourceFile(oldSourceFile.fileName, options.target!, /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217

if (!newSourceFile) {
Expand Down Expand Up @@ -1234,8 +1239,10 @@ namespace ts {

const dtsFilename = changeExtension(resolvedRefOpts.options.outFile, ".d.ts");
const js = host.readFile(resolvedRefOpts.options.outFile) || `/* Input file ${resolvedRefOpts.options.outFile} was missing */\r\n`;
const jsMap = host.readFile(resolvedRefOpts.options.outFile + ".map"); // TODO: try to read sourceMappingUrl comment from the js file
const dts = host.readFile(dtsFilename) || `/* Input file ${dtsFilename} was missing */\r\n`;
const node = createInputFiles(js, dts);
const dtsMap = host.readFile(dtsFilename + ".map");
const node = createInputFiles(js, dts, jsMap, dtsMap);
nodes.push(node);
}
}
Expand Down Expand Up @@ -2047,6 +2054,7 @@ namespace ts {
if (file) {
sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
file.path = path;
file.resolvedPath = toPath(fileName);

if (host.useCaseSensitiveFileNames()) {
const pathLowerCase = path.toLowerCase();
Expand Down Expand Up @@ -2781,7 +2789,7 @@ namespace ts {
/**
* Returns the target config filename of a project reference
*/
function resolveProjectReferencePath(host: CompilerHost, ref: ProjectReference): string | undefined {
export function resolveProjectReferencePath(host: CompilerHost, ref: ProjectReference): string | undefined {
if (!host.fileExists(ref.path)) {
return combinePaths(ref.path, "tsconfig.json");
}
Expand Down
Loading