Skip to content

Commit 1908a47

Browse files
Project reference support enhancements (#1076)
* Add test for package json existance * Add input file of reference as dependency instead of .d.ts file * Show how output is different when module resolution resolves to .js/.d.ts * Store tsbuildinfos written on solution builder host and hand it off as asset * .d.ts as assets only if written * Make every project include just app and not other lib files * Fix watching for solution watched files Add test that doesnt pass yet. This is same as projectReferencesWatch so technically only change should be in bundled emit to have out to be lib\out\index.js instead * Dont depend on .d.ts output of the referenced project since we are depending on .ts file for that This fixes initial build to complete in single pass * Make sure to build all solution builder files before and track input and output * Add all the files from composite project as dependencies as any change in them can result in errors resulting in changes to the own output of the file * Get output from solutionBuilder for referenced files in transpileOnly mode as well * Read and write output files from referenced projects to disk * Test on already built * Handle written files by solution builder a bit better * Fix comparison tests where the multiple compilation callbacks were not handled so it didnt show correct output * Because comparison tests are run only on newer typescript build, build suite during tests instead of commandline to avoid breaking older runs * Remove node 8 build from travis * Fix test baselines * Revert multiple compilation stats per patch, has incorrect baseline that doesnt match actual behavior This reverts commit 9d62b44. * update package.json and CHANGELOG.md Co-authored-by: John Reilly <[email protected]>
1 parent d0c4b41 commit 1908a47

File tree

287 files changed

+6574
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+6574
-825
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ addons:
44
chrome: stable
55
language: node_js
66
node_js:
7-
- "8"
87
- "10"
98
- "12"
109
sudo: required

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v7.0.0
4+
* [Project reference support enhancements](https://github.com/TypeStrong/ts-loader/pull/1076) - thanks @sheetalkamat!
5+
* Following the end of life of Node 8, `ts-loader` no longer supports Node 8 **BREAKING CHANGE**
6+
37
## v6.2.2
48
* [Enable typescript 3.8.3 support when using `webpack.config.ts` files](https://github.com/TypeStrong/ts-loader/issues/1072) - thanks @vladimiry!
59

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "ts-loader",
3-
"version": "6.2.2",
3+
"version": "7.0.0",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",
77
"scripts": {
88
"build": "tsc --version && tsc --project \"./src\"",
99
"lint": "tslint --project \"./src\"",
10-
"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",
10+
"comparison-tests": "git clean -xfd test/comparison-tests && npm link ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js",
1111
"comparison-tests-generate": "git clean -xfd test/comparison-tests && node test/comparison-tests/stub-new-version.js",
1212
"execution-tests": "git clean -xfd test/execution-tests && node test/execution-tests/run-tests.js",
1313
"test": "git clean -xfd test/comparison-tests && git clean -xfd test/execution-tests && node test/run-tests.js",

src/after-compile.ts

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as webpack from 'webpack';
44

55
import * as constants from './constants';
66
import {
7-
forEachResolvedProjectReference,
87
getEmitFromWatchHost,
9-
getEmitOutput
8+
getEmitOutput,
9+
isReferencedFile
1010
} from './instances';
1111
import {
1212
TSFile,
@@ -39,6 +39,12 @@ export function makeAfterCompile(
3939
return;
4040
}
4141

42+
if (instance.loaderOptions.transpileOnly) {
43+
provideAssetsFromSolutionBuilderHost(instance, compilation);
44+
callback();
45+
return;
46+
}
47+
4248
removeTSLoaderErrors(compilation.errors);
4349

4450
provideCompilerOptionDiagnosticErrorsToWebpack(
@@ -65,15 +71,15 @@ export function makeAfterCompile(
6571
modules,
6672
instance
6773
);
68-
6974
provideDeclarationFilesToWebpack(
7075
filesToCheckForErrors,
7176
instance,
7277
compilation
7378
);
79+
provideTsBuildInfoFilesToWebpack(instance, compilation);
7480

7581
provideSolutionErrorsToWebpack(compilation, modules, instance);
76-
provideTsBuildInfoFilesToWebpack(instance, compilation);
82+
provideAssetsFromSolutionBuilderHost(instance, compilation);
7783

7884
instance.filesWithErrors = filesWithErrors;
7985
instance.modifiedFiles = undefined;
@@ -343,31 +349,51 @@ function provideDeclarationFilesToWebpack(
343349
continue;
344350
}
345351

346-
const outputFiles = getEmitOutput(instance, filePath);
347-
const declarationFiles = outputFiles.filter(outputFile =>
348-
outputFile.name.match(constants.dtsDtsxOrDtsDtsxMapRegex)
349-
);
350-
351-
declarationFiles.forEach(declarationFile => {
352-
const assetPath = path.relative(
353-
compilation.compiler.outputPath,
354-
declarationFile.name
352+
if (!isReferencedFile(instance, filePath)) {
353+
addDeclarationFilesAsAsset(
354+
getEmitOutput(instance, filePath),
355+
compilation
355356
);
356-
compilation.assets[assetPath] = {
357-
source: () => declarationFile.text,
358-
size: () => declarationFile.text.length
359-
};
360-
});
357+
}
361358
}
362359
}
363360

364-
function getOutputPathForBuildInfo(
365-
compiler: typeof ts,
366-
options: ts.CompilerOptions
361+
function addDeclarationFilesAsAsset<T extends ts.OutputFile>(
362+
outputFiles: T[] | IterableIterator<T>,
363+
compilation: webpack.compilation.Compilation,
364+
skipOutputFile?: (outputFile: T) => boolean
365+
) {
366+
outputFilesToAsset(outputFiles, compilation, outputFile =>
367+
skipOutputFile && skipOutputFile(outputFile)
368+
? true
369+
: !outputFile.name.match(constants.dtsDtsxOrDtsDtsxMapRegex)
370+
);
371+
}
372+
373+
function outputFileToAsset(
374+
outputFile: ts.OutputFile,
375+
compilation: webpack.compilation.Compilation
367376
) {
368-
return (compiler as any).getTsBuildInfoEmitOutputFilePath
369-
? (compiler as any).getTsBuildInfoEmitOutputFilePath(options)
370-
: (compiler as any).getOutputPathForBuildInfo(options);
377+
const assetPath = path.relative(
378+
compilation.compiler.outputPath,
379+
outputFile.name
380+
);
381+
compilation.assets[assetPath] = {
382+
source: () => outputFile.text,
383+
size: () => outputFile.text.length
384+
};
385+
}
386+
387+
function outputFilesToAsset<T extends ts.OutputFile>(
388+
outputFiles: T[] | IterableIterator<T>,
389+
compilation: webpack.compilation.Compilation,
390+
skipOutputFile?: (outputFile: T) => boolean
391+
) {
392+
for (const outputFile of outputFiles) {
393+
if (!skipOutputFile || !skipOutputFile(outputFile)) {
394+
outputFileToAsset(outputFile, compilation);
395+
}
396+
}
371397
}
372398

373399
/**
@@ -377,60 +403,32 @@ function provideTsBuildInfoFilesToWebpack(
377403
instance: TSInstance,
378404
compilation: webpack.compilation.Compilation
379405
) {
380-
if (instance.solutionBuilderHost && instance.modifiedFiles) {
381-
const program = ensureProgram(instance);
382-
if (program) {
383-
forEachResolvedProjectReference(
384-
program.getResolvedProjectReferences(),
385-
resolvedRef => {
386-
if (
387-
resolvedRef.commandLine.fileNames.some(f =>
388-
instance.modifiedFiles!.has(path.resolve(f))
389-
)
390-
) {
391-
const buildInfoPath = getOutputPathForBuildInfo(
392-
instance.compiler,
393-
resolvedRef.commandLine.options
394-
);
395-
if (buildInfoPath) {
396-
const text = instance.compiler.sys.readFile(buildInfoPath);
397-
if (text) {
398-
const assetPath = path.relative(
399-
compilation.compiler.outputPath,
400-
path.resolve(buildInfoPath)
401-
);
402-
compilation.assets[assetPath] = {
403-
source: () => text,
404-
size: () => text.length
405-
};
406-
}
407-
}
408-
}
409-
}
410-
);
411-
}
412-
}
413-
414406
if (instance.watchHost) {
415407
// Ensure emit is complete
416408
getEmitFromWatchHost(instance);
417409
if (instance.watchHost.tsbuildinfo) {
418-
const { tsbuildinfo } = instance.watchHost;
419-
const assetPath = path.relative(
420-
compilation.compiler.outputPath,
421-
path.resolve(tsbuildinfo.name)
422-
);
423-
compilation.assets[assetPath] = {
424-
source: () => tsbuildinfo.text,
425-
size: () => tsbuildinfo.text.length
426-
};
410+
outputFileToAsset(instance.watchHost.tsbuildinfo, compilation);
427411
}
428412

429413
instance.watchHost.outputFiles.clear();
430414
instance.watchHost.tsbuildinfo = undefined;
431415
}
432416
}
433417

418+
/**
419+
* gather all solution builder assets
420+
*/
421+
function provideAssetsFromSolutionBuilderHost(
422+
instance: TSInstance,
423+
compilation: webpack.compilation.Compilation
424+
) {
425+
if (instance.solutionBuilderHost) {
426+
// written files
427+
outputFilesToAsset(instance.solutionBuilderHost.writtenFiles, compilation);
428+
instance.solutionBuilderHost.writtenFiles.length = 0;
429+
}
430+
}
431+
434432
/**
435433
* handle all other errors. The basic approach here to get accurate error
436434
* reporting is to start with a "blank slate" each compilation and gather

0 commit comments

Comments
 (0)