From ed8d596eba49217d54e40622be9bdd879f5bf53f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 20 Sep 2019 23:29:55 -0700 Subject: [PATCH] Consume typescript apis from typescript nightly (#1016) * Add support to run tests matching regexp * Consume typescript apis * Run tests matching criteria across the all tests * Remove TODO * Update CHANGELOG.md * Update package.json --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/after-compile.ts | 13 +++++++++++-- src/instances.ts | 11 ++++++++--- test/comparison-tests/run-tests.js | 9 +++++++++ test/execution-tests/run-tests.js | 9 +++++++++ test/run-tests.js | 8 +++++--- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1783912bb..bb84e63d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v6.1.2 +* [don't emit declaration files for a declaration file](https://github.com/TypeStrong/ts-loader/pull/1015) (#1014) - thanks @gvinaccia! +* [Consume typescript apis from typescript nightly](https://github.com/TypeStrong/ts-loader/pull/1016) - thanks @sheetalkamat! + ## v6.1.1 * [Fix SolutionBuilder watches](https://github.com/TypeStrong/ts-loader/pull/1003) and [related fixes](https://github.com/TypeStrong/ts-loader/pull/1011) (#998) - thanks @sheetalkamat! * [fix: no errors reported if flagged with @ts-check](https://github.com/TypeStrong/ts-loader/pull/1008) (#1004) - thanks @reinholdk! diff --git a/package.json b/package.json index 50726803a..9cf84eacc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-loader", - "version": "6.1.1", + "version": "6.1.2", "description": "TypeScript loader for webpack", "main": "index.js", "types": "dist/types/index.d.ts", diff --git a/src/after-compile.ts b/src/after-compile.ts index c536fb49a..0120355f7 100644 --- a/src/after-compile.ts +++ b/src/after-compile.ts @@ -357,6 +357,15 @@ function provideDeclarationFilesToWebpack( } } +function getOutputPathForBuildInfo( + compiler: typeof ts, + options: ts.CompilerOptions +) { + return (compiler as any).getTsBuildInfoEmitOutputFilePath + ? (compiler as any).getTsBuildInfoEmitOutputFilePath(options) + : (compiler as any).getOutputPathForBuildInfo(options); +} + /** * gather all .tsbuildinfo for the project */ @@ -375,8 +384,8 @@ function provideTsBuildInfoFilesToWebpack( instance.modifiedFiles!.has(path.resolve(f)) ) ) { - // TODO:: update compiler to expose this - const buildInfoPath = (instance.compiler as any).getOutputPathForBuildInfo( + const buildInfoPath = getOutputPathForBuildInfo( + instance.compiler, resolvedRef.commandLine.options ); if (buildInfoPath) { diff --git a/src/instances.ts b/src/instances.ts index d7456727b..575076d64 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -490,8 +490,15 @@ function getOutputFileNames( configFile: typescript.ParsedCommandLine, inputFileName: string ): string[] { - const outputs: string[] = []; const ignoreCase = !instance.compiler.sys.useCaseSensitiveFileNames; + if ((instance.compiler as any).getOutputFileNames) { + return (instance.compiler as any).getOutputFileNames( + configFile, + inputFileName, + ignoreCase + ); + } + const outputs: string[] = []; const addOutput = (fileName: string | undefined) => fileName && outputs.push(fileName); const js = getOutputJSFileName( @@ -539,8 +546,6 @@ function getOutputFilesFromReference( !options.out && fileNames.some(file => path.normalize(file) === filePath) ) { - // TODO api in typescript - // For now copying from typescript const outputFiles: typescript.OutputFile[] = []; getOutputFileNames( instance, diff --git a/test/comparison-tests/run-tests.js b/test/comparison-tests/run-tests.js index 70fa29947..57c3df980 100644 --- a/test/comparison-tests/run-tests.js +++ b/test/comparison-tests/run-tests.js @@ -17,6 +17,9 @@ const saveOutputMode = process.argv.indexOf('--save-output') !== -1; const indexOfSingleTest = process.argv.indexOf('--single-test'); const singleTestToRun = indexOfSingleTest !== -1 && process.argv[indexOfSingleTest + 1]; +const indexOfTestCriteria = process.argv.indexOf('--match-test'); +const testCriteria = + indexOfTestCriteria !== -1 && new RegExp(process.argv[indexOfTestCriteria + 1]); /** @type {string[]} */ let passingTests = []; @@ -58,6 +61,12 @@ function runTests() { const testPath = path.join(testDir, testName); return fs.statSync(testPath).isDirectory(); } + ) + .filter( + /** + * @param {string} testName + */ testName => + testCriteria ? !!testName.match(testCriteria) : true ); // Allow multiple attempts to pass tests as they're flaky diff --git a/test/execution-tests/run-tests.js b/test/execution-tests/run-tests.js index 40daab4dd..c16b44ae9 100644 --- a/test/execution-tests/run-tests.js +++ b/test/execution-tests/run-tests.js @@ -14,6 +14,9 @@ process.env.NODE_ENV = 'test'; var indexOfSingleTest = process.argv.indexOf('--single-test'); var singleTestToRun = indexOfSingleTest !== -1 && process.argv[indexOfSingleTest + 1]; var watch = process.argv.indexOf('--watch') !== -1 && !!singleTestToRun; +const indexOfTestCriteria = process.argv.indexOf('--match-test'); +const testCriteria = + indexOfTestCriteria !== -1 && new RegExp(process.argv[indexOfTestCriteria + 1]); var passingTests = []; var failingTests = []; @@ -32,6 +35,12 @@ else { .filter(isTestDirectory) .filter(isHighEnoughTypeScriptVersion) .filter(isNotHappyPackTest) + .filter( + /** + * @param {string} testName + */ testName => + testCriteria ? !!testName.match(testCriteria) : true + ) // .filter(isNotBabelTest) .forEach(runTests); } diff --git a/test/run-tests.js b/test/run-tests.js index 95aa79ff9..9c7b583d1 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -4,8 +4,10 @@ var webpackVersion = require('webpack/package.json').version; var typescript = require('typescript'); var execSync = require('child_process').execSync; -console.log('Using webpack version ' + webpackVersion); +const testArgs = process.argv.length > 2 ? ` -- ${process.argv.slice(2).join(" ")}` : ""; + +console.log('Using webpack version --' + webpackVersion); console.log('Using typescript version ' + typescript.version); -execSync('yarn run comparison-tests', { stdio: 'inherit' }); -execSync('yarn run execution-tests', { stdio: 'inherit' }); +execSync(`yarn run comparison-tests${testArgs}`, { stdio: 'inherit' }); +execSync(`yarn run execution-tests${testArgs}`, { stdio: 'inherit' });