Skip to content

Commit

Permalink
Merge pull request #951 from andrewbranch/bug/950
Browse files Browse the repository at this point in the history
Don’t try to resolve project references if project references are disabled in loader options
  • Loading branch information
andrewbranch committed Jun 10, 2019
2 parents e94d499 + 7a1215f commit f667bb5
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ export function getConfigParseResult(
compiler: typeof typescript,
configFile: ConfigFile,
basePath: string,
configFilePath: string | undefined
configFilePath: string | undefined,
enableProjectReferences: boolean
) {
const configParseResult = compiler.parseJsonConfigFileContent(
configFile.config,
compiler.sys,
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, {
Expand Down
3 changes: 2 additions & 1 deletion src/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ function successfulTypeScriptInstance(
compiler,
configFile,
basePath,
configFilePath
configFilePath,
loaderOptions.projectReferences
);

if (configParseResult.errors.length > 0 && !loaderOptions.happyPackMode) {
Expand Down
17 changes: 17 additions & 0 deletions test/execution-tests/3.0.1_projectReferencesDisabled/karma.conf.js
Original file line number Diff line number Diff line change
@@ -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'
]
})
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*.js.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare const lib: {
one: number;
two: number;
three: number;
};
10 changes: 10 additions & 0 deletions test/execution-tests/3.0.1_projectReferencesDisabled/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const lib = {
one: 1,
two: 2,
three: 3
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": true,
"sourceMap": true
},
"files": [
"./index.ts"
]
}
2 changes: 2 additions & 0 deletions test/execution-tests/3.0.1_projectReferencesDisabled/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const testsContext = require.context('./', true, /\.tests\.ts(x?)$/);
testsContext.keys().forEach(testsContext);
10 changes: 10 additions & 0 deletions test/execution-tests/3.0.1_projectReferencesDisabled/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { lib } from '../lib';

export function whatNumbersDoYouHave() {
return [lib.one, lib.two, lib.three];
}
Original file line number Diff line number Diff line change
@@ -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]);
});
});
11 changes: 11 additions & 0 deletions test/execution-tests/3.0.1_projectReferencesDisabled/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [
"./src/app.ts"
],
"references": [
{ "path": "./lib" }
],
"compilerOptions": {
"noEmitOnError": true
}
}
Original file line number Diff line number Diff line change
@@ -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") } }
13 changes: 13 additions & 0 deletions test/execution-tests/3.0.1_projectReferencesDisabled/yarn.lock
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit f667bb5

Please sign in to comment.