From bb2722bfa96e514e98670528c03fb57fd5a4c5f7 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 7 Jun 2019 16:33:12 -0700 Subject: [PATCH 1/2] Fix projectReferences resolution with outDir --- src/config.ts | 7 ++++++- src/instances.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index d0cef0206..49cdf0274 100644 --- a/src/config.ts +++ b/src/config.ts @@ -127,7 +127,8 @@ export function getConfigParseResult( compiler: typeof typescript, configFile: ConfigFile, basePath: string, - configFilePath: string | undefined + configFilePath: string | undefined, + enableProjectReferences: boolean ) { const configParseResult = compiler.parseJsonConfigFileContent( configFile.config, @@ -135,6 +136,10 @@ export function getConfigParseResult( basePath ); + if (!enableProjectReferences) { + configParseResult.projectReferences = undefined; + } + if (semver.gte(compiler.version, '3.5.0')) { // set internal options.configFilePath flag on options to denote that we read this from a file configParseResult.options = Object.assign({}, configParseResult.options, { diff --git a/src/instances.ts b/src/instances.ts index c745687b3..a0118172e 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -100,7 +100,8 @@ function successfulTypeScriptInstance( compiler, configFile, basePath, - configFilePath + configFilePath, + loaderOptions.projectReferences ); if (configParseResult.errors.length > 0 && !loaderOptions.happyPackMode) { From 7a1215fdcf00cef5bd90a7186524706f6b26b20d Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 7 Jun 2019 17:10:10 -0700 Subject: [PATCH 2/2] Add test --- .../karma.conf.js | 17 +++++++++++++++++ .../lib/.gitignore | 1 + .../lib/index.d.ts | 5 +++++ .../lib/index.js | 10 ++++++++++ .../lib/index.js.map | 1 + .../lib/index.ts | 5 +++++ .../lib/tsconfig.json | 9 +++++++++ .../3.0.1_projectReferencesDisabled/main.js | 2 ++ .../package.json | 10 ++++++++++ .../3.0.1_projectReferencesDisabled/src/app.ts | 5 +++++ .../test/app.tests.ts | 7 +++++++ .../tsconfig.json | 11 +++++++++++ .../webpack.config.js | 18 ++++++++++++++++++ .../3.0.1_projectReferencesDisabled/yarn.lock | 13 +++++++++++++ 14 files changed, 114 insertions(+) create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/karma.conf.js create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/lib/.gitignore create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.d.ts create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js.map create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.ts create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/lib/tsconfig.json create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/main.js create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/package.json create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/src/app.ts create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/test/app.tests.ts create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/tsconfig.json create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/webpack.config.js create mode 100644 test/execution-tests/3.0.1_projectReferencesDisabled/yarn.lock diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/karma.conf.js b/test/execution-tests/3.0.1_projectReferencesDisabled/karma.conf.js new file mode 100644 index 000000000..a38a197f0 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/karma.conf.js @@ -0,0 +1,17 @@ +/* eslint-disable no-var, strict */ +'use strict'; +var webpackConfig = require('./webpack.config.js'); +var makeKarmaConfig = require('../../karmaConfig'); + +module.exports = function(config) { + config.set( + makeKarmaConfig({ + config, + webpackConfig, + files: [ + // This ensures we have the es6 shims in place from babel and then loads all the tests + 'main.js' + ] + }) + ); +}; diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/lib/.gitignore b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/.gitignore new file mode 100644 index 000000000..7b7f62099 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/.gitignore @@ -0,0 +1 @@ +!*.js.map \ No newline at end of file diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.d.ts b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.d.ts new file mode 100644 index 000000000..73d752279 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.d.ts @@ -0,0 +1,5 @@ +export declare const lib: { + one: number; + two: number; + three: number; +}; diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js new file mode 100644 index 000000000..94f953e3e --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js @@ -0,0 +1,10 @@ +"use strict"; +exports.__esModule = true; +exports.lib = { + one: 1, + two: 2, + three: 3 + // I am adding this comment here by hand to ensure + // Webpack is using the JS output for project references +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js.map b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js.map new file mode 100644 index 000000000..af3aabd86 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAAa,QAAA,GAAG,GAAG;IACjB,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;CACT,CAAC"} \ No newline at end of file diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.ts b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.ts new file mode 100644 index 000000000..669ca7b3d --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.ts @@ -0,0 +1,5 @@ +export const lib = { + one: 1, + two: 2, + three: 3 +}; diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/lib/tsconfig.json b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/tsconfig.json new file mode 100644 index 000000000..506c325eb --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/lib/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "sourceMap": true + }, + "files": [ + "./index.ts" + ] +} \ No newline at end of file diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/main.js b/test/execution-tests/3.0.1_projectReferencesDisabled/main.js new file mode 100644 index 000000000..118f90112 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/main.js @@ -0,0 +1,2 @@ +const testsContext = require.context('./', true, /\.tests\.ts(x?)$/); +testsContext.keys().forEach(testsContext); diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/package.json b/test/execution-tests/3.0.1_projectReferencesDisabled/package.json new file mode 100644 index 000000000..12bc6974a --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/package.json @@ -0,0 +1,10 @@ +{ + "name": "basic", + "license": "MIT", + "version": "1.0.0", + "main": "index.js", + "devDependencies": { + "@types/jasmine": "^2.5.35", + "jasmine-core": "^2.3.4" + } +} diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/src/app.ts b/test/execution-tests/3.0.1_projectReferencesDisabled/src/app.ts new file mode 100644 index 000000000..102964b70 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/src/app.ts @@ -0,0 +1,5 @@ +import { lib } from '../lib'; + +export function whatNumbersDoYouHave() { + return [lib.one, lib.two, lib.three]; +} diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/test/app.tests.ts b/test/execution-tests/3.0.1_projectReferencesDisabled/test/app.tests.ts new file mode 100644 index 000000000..25c9b229e --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/test/app.tests.ts @@ -0,0 +1,7 @@ +import { whatNumbersDoYouHave } from "../src/app"; + +describe("app", () => { + it("code compiled using projectReferences can be consumed", () => { + expect(whatNumbersDoYouHave()).toEqual([1, 2, 3]); + }); +}); diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/tsconfig.json b/test/execution-tests/3.0.1_projectReferencesDisabled/tsconfig.json new file mode 100644 index 000000000..57ce99826 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/tsconfig.json @@ -0,0 +1,11 @@ +{ + "files": [ + "./src/app.ts" + ], + "references": [ + { "path": "./lib" } + ], + "compilerOptions": { + "noEmitOnError": true + } +} diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/webpack.config.js b/test/execution-tests/3.0.1_projectReferencesDisabled/webpack.config.js new file mode 100644 index 000000000..5542b0df7 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/webpack.config.js @@ -0,0 +1,18 @@ +module.exports = { + mode: 'development', + entry: './src/app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { test: /\.ts$/, loader: 'ts-loader', options: { projectReferences: false } } + ] + } +} + +// for test harness purposes only, you would not need this in a normal project +module.exports.resolveLoader = { alias: { 'ts-loader': require('path').join(__dirname, "../../../index.js") } } \ No newline at end of file diff --git a/test/execution-tests/3.0.1_projectReferencesDisabled/yarn.lock b/test/execution-tests/3.0.1_projectReferencesDisabled/yarn.lock new file mode 100644 index 000000000..c83148e75 --- /dev/null +++ b/test/execution-tests/3.0.1_projectReferencesDisabled/yarn.lock @@ -0,0 +1,13 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/jasmine@^2.5.35": + version "2.8.5" + resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.5.tgz#96e58872583fa80c7ea0dd29024b180d5e133678" + integrity sha512-mkrHFZTgOXkZhau36K628iKFkjbp11t/bHCkY4Mefu4R6McMg2FD9P3naBv/0Ygyn4sz8baColJp2gdmSekgiw== + +jasmine-core@^2.3.4: + version "2.9.1" + resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.9.1.tgz#b6bbc1d8e65250d56f5888461705ebeeeb88f22f" + integrity sha1-trvB2OZSUNVvWIhGFwXr7uuI8i8=