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

Project reference support enhancements #1076

Merged
merged 20 commits into from Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d662385
Add test for package json existance
sheetalkamat Oct 3, 2019
00d40db
Show how output is different when module resolution resolves to .js/.…
sheetalkamat Apr 8, 2020
a3a39e3
Add input file of reference as dependency instead of .d.ts file
sheetalkamat Oct 3, 2019
d5474b2
Store tsbuildinfos written on solution builder host and hand it off a…
sheetalkamat Oct 7, 2019
f57b8fc
.d.ts as assets only if written
sheetalkamat Oct 7, 2019
453ce34
Make every project include just app and not other lib files
sheetalkamat Oct 7, 2019
35d283c
Fix watching for solution watched files
sheetalkamat Oct 7, 2019
cecfc8a
Dont depend on .d.ts output of the referenced project since we are de…
sheetalkamat Oct 9, 2019
cdfce32
Make sure to build all solution builder files before and track input …
sheetalkamat Apr 2, 2020
bf49856
Add all the files from composite project as dependencies as any chang…
sheetalkamat Apr 6, 2020
0561a9f
Get output from solutionBuilder for referenced files in transpileOnly…
sheetalkamat Apr 8, 2020
eb4b4fc
Read and write output files from referenced projects to disk
sheetalkamat Apr 9, 2020
61e7b3a
Test on already built
sheetalkamat Apr 9, 2020
e3bd56e
Handle written files by solution builder a bit better
sheetalkamat Apr 9, 2020
9d62b44
Fix comparison tests where the multiple compilation callbacks were no…
sheetalkamat Apr 10, 2020
6cd9347
Because comparison tests are run only on newer typescript build, buil…
sheetalkamat Apr 10, 2020
1977b89
Remove node 8 build from travis
sheetalkamat Apr 10, 2020
399b60a
Fix test baselines
sheetalkamat Apr 10, 2020
7b0ec7d
Revert multiple compilation stats per patch, has incorrect baseline t…
sheetalkamat Apr 13, 2020
43695e4
update package.json and CHANGELOG.md
johnnyreilly Apr 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ addons:
chrome: stable
language: node_js
node_js:
- "8"
- "10"
- "12"
sudo: required
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsc --version && tsc --project \"./src\"",
"lint": "tslint --project \"./src\"",
"comparison-tests": "git clean -xfd test/comparison-tests && tsc --project \"./test/comparison-tests\" && npm link ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js",
"comparison-tests": "git clean -xfd test/comparison-tests && npm link ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js",
"comparison-tests-generate": "git clean -xfd test/comparison-tests && node test/comparison-tests/stub-new-version.js",
"execution-tests": "git clean -xfd test/execution-tests && node test/execution-tests/run-tests.js",
"test": "git clean -xfd test/comparison-tests && git clean -xfd test/execution-tests && node test/run-tests.js",
Expand Down
132 changes: 65 additions & 67 deletions src/after-compile.ts
Expand Up @@ -4,9 +4,9 @@ import * as webpack from 'webpack';

import * as constants from './constants';
import {
forEachResolvedProjectReference,
getEmitFromWatchHost,
getEmitOutput
getEmitOutput,
isReferencedFile
} from './instances';
import {
TSFile,
Expand Down Expand Up @@ -39,6 +39,12 @@ export function makeAfterCompile(
return;
}

if (instance.loaderOptions.transpileOnly) {
provideAssetsFromSolutionBuilderHost(instance, compilation);
callback();
return;
}

removeTSLoaderErrors(compilation.errors);

provideCompilerOptionDiagnosticErrorsToWebpack(
Expand All @@ -65,15 +71,15 @@ export function makeAfterCompile(
modules,
instance
);

provideDeclarationFilesToWebpack(
filesToCheckForErrors,
instance,
compilation
);
provideTsBuildInfoFilesToWebpack(instance, compilation);

provideSolutionErrorsToWebpack(compilation, modules, instance);
provideTsBuildInfoFilesToWebpack(instance, compilation);
provideAssetsFromSolutionBuilderHost(instance, compilation);

instance.filesWithErrors = filesWithErrors;
instance.modifiedFiles = undefined;
Expand Down Expand Up @@ -343,31 +349,51 @@ function provideDeclarationFilesToWebpack(
continue;
}

const outputFiles = getEmitOutput(instance, filePath);
const declarationFiles = outputFiles.filter(outputFile =>
outputFile.name.match(constants.dtsDtsxOrDtsDtsxMapRegex)
);

declarationFiles.forEach(declarationFile => {
const assetPath = path.relative(
compilation.compiler.outputPath,
declarationFile.name
if (!isReferencedFile(instance, filePath)) {
addDeclarationFilesAsAsset(
getEmitOutput(instance, filePath),
compilation
);
compilation.assets[assetPath] = {
source: () => declarationFile.text,
size: () => declarationFile.text.length
};
});
}
}
}

function getOutputPathForBuildInfo(
compiler: typeof ts,
options: ts.CompilerOptions
function addDeclarationFilesAsAsset<T extends ts.OutputFile>(
outputFiles: T[] | IterableIterator<T>,
compilation: webpack.compilation.Compilation,
skipOutputFile?: (outputFile: T) => boolean
) {
outputFilesToAsset(outputFiles, compilation, outputFile =>
skipOutputFile && skipOutputFile(outputFile)
? true
: !outputFile.name.match(constants.dtsDtsxOrDtsDtsxMapRegex)
);
}

function outputFileToAsset(
outputFile: ts.OutputFile,
compilation: webpack.compilation.Compilation
) {
return (compiler as any).getTsBuildInfoEmitOutputFilePath
? (compiler as any).getTsBuildInfoEmitOutputFilePath(options)
: (compiler as any).getOutputPathForBuildInfo(options);
const assetPath = path.relative(
compilation.compiler.outputPath,
outputFile.name
);
compilation.assets[assetPath] = {
source: () => outputFile.text,
size: () => outputFile.text.length
};
}

function outputFilesToAsset<T extends ts.OutputFile>(
outputFiles: T[] | IterableIterator<T>,
compilation: webpack.compilation.Compilation,
skipOutputFile?: (outputFile: T) => boolean
) {
for (const outputFile of outputFiles) {
if (!skipOutputFile || !skipOutputFile(outputFile)) {
outputFileToAsset(outputFile, compilation);
}
}
}

/**
Expand All @@ -377,60 +403,32 @@ function provideTsBuildInfoFilesToWebpack(
instance: TSInstance,
compilation: webpack.compilation.Compilation
) {
if (instance.solutionBuilderHost && instance.modifiedFiles) {
const program = ensureProgram(instance);
if (program) {
forEachResolvedProjectReference(
program.getResolvedProjectReferences(),
resolvedRef => {
if (
resolvedRef.commandLine.fileNames.some(f =>
instance.modifiedFiles!.has(path.resolve(f))
)
) {
const buildInfoPath = getOutputPathForBuildInfo(
instance.compiler,
resolvedRef.commandLine.options
);
if (buildInfoPath) {
const text = instance.compiler.sys.readFile(buildInfoPath);
if (text) {
const assetPath = path.relative(
compilation.compiler.outputPath,
path.resolve(buildInfoPath)
);
compilation.assets[assetPath] = {
source: () => text,
size: () => text.length
};
}
}
}
}
);
}
}

if (instance.watchHost) {
// Ensure emit is complete
getEmitFromWatchHost(instance);
if (instance.watchHost.tsbuildinfo) {
const { tsbuildinfo } = instance.watchHost;
const assetPath = path.relative(
compilation.compiler.outputPath,
path.resolve(tsbuildinfo.name)
);
compilation.assets[assetPath] = {
source: () => tsbuildinfo.text,
size: () => tsbuildinfo.text.length
};
outputFileToAsset(instance.watchHost.tsbuildinfo, compilation);
}

instance.watchHost.outputFiles.clear();
instance.watchHost.tsbuildinfo = undefined;
}
}

/**
* gather all solution builder assets
*/
function provideAssetsFromSolutionBuilderHost(
instance: TSInstance,
compilation: webpack.compilation.Compilation
) {
if (instance.solutionBuilderHost) {
// written files
outputFilesToAsset(instance.solutionBuilderHost.writtenFiles, compilation);
instance.solutionBuilderHost.writtenFiles.length = 0;
}
}

/**
* handle all other errors. The basic approach here to get accurate error
* reporting is to start with a "blank slate" each compilation and gather
Expand Down