From 3e41ae6713fe839eebb4992808401ad9645057bf Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 16:59:40 +0200 Subject: [PATCH 01/33] Start transformation to TypeScript --- bin/{run.js => run.ts} | 28 +++++----- .eslintrc.yml => configs/.eslintrc.yml | 0 configs/tsconfig.json | 27 ++++++++++ package.json | 9 ++-- src/@types/kaba.d.ts | 4 ++ {lib => src}/CliConfig.js | 0 {lib => src}/Kaba.js | 18 ++++++- {lib => src}/Logger.js | 0 .../print-package-versions.ts | 29 +++------- {lib => src}/runner/SassRunner.js | 0 {lib => src}/runner/WebpackRunner.js | 54 ++++++++++++------- tests/fixtures/js/kaba.js | 2 +- tests/fixtures/scss/kaba.js | 2 +- tests/fixtures/scss_fail_on_error/kaba.js | 2 +- tests/fixtures/ts/kaba.js | 2 +- tsconfig.json | 40 +++++++------- 16 files changed, 134 insertions(+), 83 deletions(-) rename bin/{run.js => run.ts} (88%) rename .eslintrc.yml => configs/.eslintrc.yml (100%) create mode 100644 configs/tsconfig.json create mode 100644 src/@types/kaba.d.ts rename {lib => src}/CliConfig.js (100%) rename {lib => src}/Kaba.js (96%) rename {lib => src}/Logger.js (100%) rename lib/print-package-versions.js => src/print-package-versions.ts (56%) rename {lib => src}/runner/SassRunner.js (100%) rename {lib => src}/runner/WebpackRunner.js (74%) diff --git a/bin/run.js b/bin/run.ts similarity index 88% rename from bin/run.js rename to bin/run.ts index aa414a3..ed583f6 100755 --- a/bin/run.js +++ b/bin/run.ts @@ -1,12 +1,12 @@ #!/usr/bin/env node -const CliConfig = require("../lib/CliConfig"); -const {bgYellow, black, green, red, yellow} = require("kleur"); -const Logger = require("../lib/Logger"); -const printPackageVersions = require("../lib/print-package-versions"); +const CliConfig = require("../src/CliConfig"); +const Logger = require("../src/Logger"); +const printPackageVersions = require("../src/print-package-versions"); const sade = require("sade"); -const SassRunner = require("../lib/runner/SassRunner"); -const WebpackRunner = require("../lib/runner/WebpackRunner"); +const SassRunner = require("../src/runner/SassRunner"); +const WebpackRunner = require("../src/runner/WebpackRunner"); +import {bgYellow, black, blue, cyan, green, magenta, red, yellow} from "kleur"; console.log(``); @@ -94,14 +94,14 @@ program console.log(` ${bgYellow(black(" Versions "))}`); console.log(""); printPackageVersions(kabaVersion, { - "kaba-babel-preset": "yellow", - "kaba-scss": "yellow", - webpack: "cyan", - "babel-core": "blue", - typescript: "blue", - eslint: "blue", - "node-sass": "magenta", - stylelint: "magenta", + "kaba-babel-preset": yellow, + "kaba-scss": yellow, + webpack: cyan, + "babel-core": blue, + typescript: blue, + eslint: blue, + "node-sass": magenta, + stylelint: magenta, }); process.exit(0); diff --git a/.eslintrc.yml b/configs/.eslintrc.yml similarity index 100% rename from .eslintrc.yml rename to configs/.eslintrc.yml diff --git a/configs/tsconfig.json b/configs/tsconfig.json new file mode 100644 index 0000000..aa6fdef --- /dev/null +++ b/configs/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "alwaysStrict": false, + "esModuleInterop": true, + "experimentalDecorators": true, + "jsx": "react", + "jsxFactory": "h", + "lib": [ + "dom", + "es5", + "es2015" + ], + "module": "es2015", + "moduleResolution": "node", + "noImplicitThis": true, + "removeComments": true, + "sourceMap": true, + "strict": false, + "target": "es5" + + }, + "exclude": [ + "../node_modules", + "vendor" + ] +} diff --git a/package.json b/package.json index f510b29..46a65c5 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,15 @@ "url": "https://github.com/Becklyn/kaba.git" }, "version": "8.1.0", - "main": "lib/Kaba.js", + "main": "src/Kaba.js", "bin": { "kaba": "bin/run.js" }, "scripts": { - "test": "ava" + "build": "node_modules/.bin/tsc --noEmitOnError --noErrorTruncation --listEmittedFiles --pretty --noUnusedLocals", + "dev": "node_modules/.bin/tsc --noEmitOnError --noErrorTruncation --listEmittedFiles --pretty", + "prepublishOnly": "npm run-script build", + "test": "npm run-script build && ava" }, "dependencies": { "@babel/core": "^7.0.0", @@ -33,7 +36,7 @@ "sade": "^1.4.1", "terser-webpack-plugin": "^1.0.2", "ts-loader": "^6.0.0", - "typescript": "^3.0.0", + "typescript": "^3.5.2", "webpack": "^4.16.1" }, "peerDependencies": { diff --git a/src/@types/kaba.d.ts b/src/@types/kaba.d.ts new file mode 100644 index 0000000..359bd85 --- /dev/null +++ b/src/@types/kaba.d.ts @@ -0,0 +1,4 @@ +declare namespace kaba +{ + +} diff --git a/lib/CliConfig.js b/src/CliConfig.js similarity index 100% rename from lib/CliConfig.js rename to src/CliConfig.js diff --git a/lib/Kaba.js b/src/Kaba.js similarity index 96% rename from lib/Kaba.js rename to src/Kaba.js index a74b863..6ab9c19 100644 --- a/lib/Kaba.js +++ b/src/Kaba.js @@ -16,10 +16,15 @@ const typeScriptErrorFormatter = require("@becklyn/typescript-error-formatter"); * }} SassBuildConfig * * @typedef {{ + * config: webpack.Configuration, + * module: true, + * }} ModularizedWebpackConfig + * + * @typedef {{ * sass: SassBuildConfig, * js: { * javaScriptDependenciesFileName: string, - * webpack: webpack.Configuration, + * webpack: ModularizedWebpackConfig[], * customTypeScriptConfig: string|null, * }, * cwd: string, @@ -368,7 +373,16 @@ class Kaba sass: this.buildSassConfig(), js: { javaScriptDependenciesFileName: this.javaScriptDependenciesFileName, - webpack: this.buildWebpackConfig(cliConfig), + webpack: [ + { + config: this.buildWebpackConfig(cliConfig, false), + module: false, + }, + { + config: this.buildWebpackConfig(cliConfig, true), + module: true, + }, + ], customTypeScriptConfig: this.customTypeScriptConfig, }, cwd: this.cwd, diff --git a/lib/Logger.js b/src/Logger.js similarity index 100% rename from lib/Logger.js rename to src/Logger.js diff --git a/lib/print-package-versions.js b/src/print-package-versions.ts similarity index 56% rename from lib/print-package-versions.js rename to src/print-package-versions.ts index 0366e15..4913bf8 100644 --- a/lib/print-package-versions.js +++ b/src/print-package-versions.ts @@ -1,19 +1,5 @@ -const kleur = require("kleur"); - - -/** - * Returns the max package name length - * - * @private - * @param {Object.} packages - * @return {number} - */ -function getMaxPackageNameLength (packages) -{ - return Object - .keys(packages) - .reduce((max, name) => Math.max(max, name.length), 0); -} +import * as kleur from "kleur"; +import {yellow} from "kleur"; /** @@ -25,7 +11,7 @@ function getMaxPackageNameLength (packages) * @param {number} maxLength * @return {string} */ -function padding (packageName, maxLength) +function padding (packageName: string, maxLength: number) : string { const length = packageName.length; @@ -41,11 +27,10 @@ function padding (packageName, maxLength) * @param {string} kabaVersion * @param {Object.} packages */ -module.exports = function (kabaVersion, packages) +module.exports = function (kabaVersion: string, packages: {[name: string]: kleur.Color}) : void { - const maxLength = getMaxPackageNameLength(packages); - - console.log(kleur.yellow("kaba"), padding("kaba", maxLength), kabaVersion); + const maxLength = Object.keys(packages).reduce((max, name) => Math.max(max, name.length), 0); + console.log(yellow("kaba"), padding("kaba", maxLength), kabaVersion); for (const packageName in packages) { @@ -57,7 +42,7 @@ module.exports = function (kabaVersion, packages) const color = packages[packageName]; console.log( - kleur[color](packageName), + color(packageName), padding(packageName, maxLength), require(`${packageName}/package.json`).version ); diff --git a/lib/runner/SassRunner.js b/src/runner/SassRunner.js similarity index 100% rename from lib/runner/SassRunner.js rename to src/runner/SassRunner.js diff --git a/lib/runner/WebpackRunner.js b/src/runner/WebpackRunner.js similarity index 74% rename from lib/runner/WebpackRunner.js rename to src/runner/WebpackRunner.js index 8d12b3c..af4c9b3 100644 --- a/lib/runner/WebpackRunner.js +++ b/src/runner/WebpackRunner.js @@ -21,9 +21,9 @@ class WebpackRunner /** * @private - * @type {webpack.Configuration} + * @type {ModularizedWebpackConfig[]} */ - this.webpackConfig = buildConfig.js.webpack; + this.webpackConfigs = buildConfig.js.webpack; /** * @private @@ -33,9 +33,9 @@ class WebpackRunner /** * @private - * @type {?*} + * @type {Compiler.Watching[]} */ - this.watcher = null; + this.watchers = []; /** * @private @@ -52,7 +52,7 @@ class WebpackRunner */ async run () { - if (Object.keys(this.webpackConfig.entry).length === 0) + if (Object.keys(this.webpackConfigs).length === 0) { return true; } @@ -63,14 +63,27 @@ class WebpackRunner this.logger.log("Launching webpack..."); const start = process.hrtime(); - const compiler = webpack(this.webpackConfig); - if (null != this.buildConfig.js.customTypeScriptConfig) { this.logger.log(`Using custom TypeScript config: ${yellow(path.relative(this.buildConfig.cwd, this.buildConfig.js.customTypeScriptConfig))}`); } - if (this.webpackConfig.watch) + if (this.webpackConfigs.some(entry => entry.config.watch)) + { + this.resolveCallback = resolve; + } + + this.webpackConfigs.forEach(entry => { + const compiler = webpack(entry.config); + + if (entry.config.watch) + { + + } + }); + + + if (this.webpackConfigs.watch) { this.resolveCallback = resolve; @@ -98,9 +111,10 @@ class WebpackRunner * * @param {Error|null} error * @param {webpack.stats} stats + * @param {boolean} isModule * @return {boolean} whether the compilation had no errors */ - onCompilationFinished (error, stats) + onCompilationFinished (error, stats, isModule) { if (error) { @@ -116,7 +130,7 @@ class WebpackRunner console.log(""); // write dependencies file - this.writeDependenciesFile(stats); + this.writeDependenciesFile(stats, isModule); return !stats.hasErrors(); } @@ -129,11 +143,12 @@ class WebpackRunner { if (null !== this.resolveCallback) { - this.watcher.close( - () => { - this.resolveCallback(true); - } - ); + Promise.all( + this.watchers.map(watcher => + new Promise(resolve => watcher.close(resolve)) + ) + ) + .then(() => this.resolveCallback(true)); } } @@ -143,8 +158,9 @@ class WebpackRunner * * @private * @param {Stats} stats + * @param {boolean} isModule */ - writeDependenciesFile (stats) + writeDependenciesFile (stats, isModule) { const entrypoints = {}; @@ -160,11 +176,11 @@ class WebpackRunner } // ensure that output path exists - fs.ensureDirSync(this.webpackConfig.output.path); + fs.ensureDirSync(this.webpackConfigs.output.path); - const fileName = `${this.buildConfig.js.javaScriptDependenciesFileName}.json`; + const fileName = `${this.buildConfig.js.javaScriptDependenciesFileName}${isModule ? ".module" : ""}.json`; fs.writeFileSync( - path.join(this.webpackConfig.output.path, fileName), + path.join(this.webpackConfigs.output.path, fileName), JSON.stringify(entrypoints), "utf-8" ); diff --git a/tests/fixtures/js/kaba.js b/tests/fixtures/js/kaba.js index 8628a02..e45172c 100644 --- a/tests/fixtures/js/kaba.js +++ b/tests/fixtures/js/kaba.js @@ -1,4 +1,4 @@ -const Kaba = require("../../../lib/Kaba"); +const Kaba = require("../../../src/Kaba"); module.exports = (new Kaba()) diff --git a/tests/fixtures/scss/kaba.js b/tests/fixtures/scss/kaba.js index 6b1dfd1..1e96076 100644 --- a/tests/fixtures/scss/kaba.js +++ b/tests/fixtures/scss/kaba.js @@ -1,4 +1,4 @@ -const Kaba = require("../../../lib/Kaba"); +const Kaba = require("../../../src/Kaba"); module.exports = (new Kaba()) diff --git a/tests/fixtures/scss_fail_on_error/kaba.js b/tests/fixtures/scss_fail_on_error/kaba.js index 6b1dfd1..1e96076 100644 --- a/tests/fixtures/scss_fail_on_error/kaba.js +++ b/tests/fixtures/scss_fail_on_error/kaba.js @@ -1,4 +1,4 @@ -const Kaba = require("../../../lib/Kaba"); +const Kaba = require("../../../src/Kaba"); module.exports = (new Kaba()) diff --git a/tests/fixtures/ts/kaba.js b/tests/fixtures/ts/kaba.js index 2a97b67..7a159e3 100644 --- a/tests/fixtures/ts/kaba.js +++ b/tests/fixtures/ts/kaba.js @@ -1,4 +1,4 @@ -const Kaba = require("../../../lib/Kaba"); +const Kaba = require("../../../src/Kaba"); module.exports = (new Kaba()) diff --git a/tsconfig.json b/tsconfig.json index 1b64c3e..4b49826 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,29 @@ { "compilerOptions": { - "allowSyntheticDefaultImports": true, + "target": "es2017", + "module": "commonjs", + "declaration": true, + "sourceMap": false, + "strict": false, + "strictNullChecks": true, + "noImplicitThis": true, + "moduleResolution": "node", "alwaysStrict": false, - "esModuleInterop": true, - "experimentalDecorators": true, - "jsx": "react", - "jsxFactory": "h", + "allowSyntheticDefaultImports": true, "lib": [ - "dom", - "es5", - "es2015" - ], - "module": "es2015", - "moduleResolution": "node", - "noImplicitThis": true, - "removeComments": true, - "sourceMap": true, - "strict": false, - "target": "es5" - + "es2015", + "es2016", + "es2017" + ] }, + "files": [ + "./src/Kaba.ts" + ], + "include": [ + "**/*.tsx", + "**/*.ts" + ], "exclude": [ - "node_modules", - "vendor" + "node_modules" ] } From 41d5831f266d539a5bb5f2f68714363db5355eb3 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:03:27 +0200 Subject: [PATCH 02/33] Transform logger --- src/{Logger.js => Logger.ts} | 64 +++++++++++++++--------------------- src/runner/SassRunner.js | 2 +- src/runner/WebpackRunner.js | 2 +- 3 files changed, 28 insertions(+), 40 deletions(-) rename src/{Logger.js => Logger.ts} (60%) diff --git a/src/Logger.js b/src/Logger.ts similarity index 60% rename from src/Logger.js rename to src/Logger.ts index 4d9330b..0656ee1 100644 --- a/src/Logger.js +++ b/src/Logger.ts @@ -1,27 +1,35 @@ -const {gray, green, red, yellow} = require("kleur"); -const prettyHrtime = require("pretty-hrtime"); +import {gray, green, red, yellow} from "kleur"; +import prettyHrtime from "pretty-hrtime"; + +interface FileError +{ + file: string; + line: number; + message: string; + formatted: string; +} /** * Logger for all kinds of messages */ -class Logger +export class Logger { + private prefix: string; + + /** - * @param {string} prefix + * */ - constructor (prefix) + constructor (prefix: string) { - /** - * @private - * @type {string} - */ this.prefix = prefix; } + /** * Logs the start of a build */ - logBuildStart () + public logBuildStart (): void { this.log(green(`Build started`)); } @@ -29,11 +37,8 @@ class Logger /** * Logs a build success - * - * @param {string} fileName - * @param {array} duration the duration as provided by hrtime() */ - logBuildSuccess (fileName, duration) + public logBuildSuccess (fileName: string, duration: [number, number]): void { this.logWithDuration(`${green("Build finished")}: ${yellow(fileName)}`, duration); } @@ -41,21 +46,17 @@ class Logger /** * Logs a message with a duration - * - * @param {string} message - * @param {array} duration the duration as provided by hrtime() */ - logWithDuration (message, duration) + public logWithDuration (message: string, duration: [number, number]) { this.log(`${message} after ${prettyHrtime(duration)}`); } /** - * @param {string} message - * @param {Error|{message: string}} error + * */ - logError (message, error) + public logError (message: string, error: Error | { message: string }) { this.log(`${red(message)}: ${error.message}`); } @@ -63,10 +64,8 @@ class Logger /** * Logs a compilation error - * - * @param {{file: string, line: number, message: string, formatted: string}} error */ - logCompileError (error) + public logCompileError (error: FileError): void { this.log(`${red("Compilation Error")} in file ${yellow(error.file)} on line ${yellow(error.line)}:`); console.log(` ${error.message}`); @@ -88,10 +87,8 @@ class Logger /** * Writes a log message - * - * @param {string} message */ - log (message) + public log (message: string): void { console.log(`${gray(this.getCurrentTime())} ${this.prefix} ${message}`); } @@ -99,11 +96,8 @@ class Logger /** * Returns the current time - * - * @private - * @return {string} */ - getCurrentTime () + private getCurrentTime (): string { const now = new Date(); return `${this.padTime(now.getHours())}:${this.padTime(now.getMinutes())}:${this.padTime(now.getSeconds())}`; @@ -112,15 +106,9 @@ class Logger /** * Pads the time - * - * @private - * @param {number} time - * @return {string} */ - padTime (time) + private padTime (time: number): string { return ("" + time).padStart(2, "0"); } } - -module.exports = Logger; diff --git a/src/runner/SassRunner.js b/src/runner/SassRunner.js index 51159f2..e959288 100644 --- a/src/runner/SassRunner.js +++ b/src/runner/SassRunner.js @@ -1,5 +1,5 @@ const {bgMagenta, black} = require("kleur"); -const Logger = require("../Logger"); +import {Logger} from "../Logger"; const path = require("path"); diff --git a/src/runner/WebpackRunner.js b/src/runner/WebpackRunner.js index af4c9b3..3295ffd 100644 --- a/src/runner/WebpackRunner.js +++ b/src/runner/WebpackRunner.js @@ -1,6 +1,6 @@ const fs = require("fs-extra"); const {bgCyan, black, yellow} = require("kleur"); -const Logger = require("../Logger"); +import {Logger} from "../Logger"; const path = require("path"); const webpack = require("webpack"); From 860ce282c77306b87155e052bb90576b0933c2f8 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:21:40 +0200 Subject: [PATCH 03/33] Finalize run.ts --- bin/run.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/bin/run.ts b/bin/run.ts index ed583f6..d34f0a6 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -1,12 +1,11 @@ #!/usr/bin/env node -const CliConfig = require("../src/CliConfig"); -const Logger = require("../src/Logger"); -const printPackageVersions = require("../src/print-package-versions"); -const sade = require("sade"); -const SassRunner = require("../src/runner/SassRunner"); -const WebpackRunner = require("../src/runner/WebpackRunner"); +import {Logger} from "../src/Logger"; +import sade from "sade"; import {bgYellow, black, blue, cyan, green, magenta, red, yellow} from "kleur"; +import {printPackageVersions} from "../src/print-package-versions"; +import {SassRunner} from "../src/runner/SassRunner"; +import {WebpackRunner} from "../src/runner/WebpackRunner"; console.log(``); @@ -18,6 +17,16 @@ console.log(``); const program = sade("kaba"); const kabaVersion = require("../package").version; +interface CliConfig +{ + debug?: boolean; + watch?: boolean; + lint?: boolean; + openBundleAnalyzer?: boolean; + fix?: boolean; +} + + program .version(kabaVersion) .option('--verbose', 'show all errors in the runner / config file with stack trace'); @@ -66,7 +75,6 @@ program console.log(""); runKaba({ - analyze: true, lint: true, }, !!opts.verbose); }); @@ -115,18 +123,14 @@ program.parse(process.argv); /** * Main kaba function - * - * @param {CliConfigArguments} opts - * @param {boolean} isVerbose */ -function runKaba (opts, isVerbose) +function runKaba (cliConfig: CliConfig, isVerbose: boolean) : void { try { const logger = new Logger(bgYellow(black(" kaba "))); logger.log("kaba started"); const start = process.hrtime(); - const cliConfig = new CliConfig(opts); /** @type {Kaba} kaba */ const kaba = require(`${process.cwd()}/kaba.js`); @@ -153,7 +157,7 @@ function runKaba (opts, isVerbose) (...args) => console.log("something broke", args) ); - if (cliConfig.isWatch()) + if (cliConfig.watch) { const exitCallback = () => { scss.stop(); From dca06576551cf6b21cb2fe916d866ef8e3b6b9dd Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:21:54 +0200 Subject: [PATCH 04/33] Remove CliConfig --- src/CliConfig.js | 128 ----------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 src/CliConfig.js diff --git a/src/CliConfig.js b/src/CliConfig.js deleted file mode 100644 index b7d7a0b..0000000 --- a/src/CliConfig.js +++ /dev/null @@ -1,128 +0,0 @@ -/** - * @typedef {{ - * debug: ?boolean, - * watch: ?boolean, - * lint: ?boolean, - * openBundleAnalyzer: ?boolean, - * analyze: ?boolean, - * fix: ?boolean, - * }} CliConfigArguments - */ - - -/** - * Main CLI parser class - */ -class CliConfig -{ - /** - * @param {CliConfigArguments} argv - */ - constructor (argv) - { - // commander just returns undefined for missing flags, so transform them to boolean - /** - * @private - * @type {boolean} - */ - this.debug = !!argv.debug; - - /** - * @private - * @type {boolean} - */ - this.watch = !!argv.watch; - - /** - * @private - * @type {boolean} - */ - this.lint = !!argv.lint; - - /** - * @private - * @type {boolean} - */ - this.bundleAnalyzer = !!argv.openBundleAnalyzer; - - /** - * @private - * @type {boolean} - */ - this.analyze = !!argv.analyze; - - /** - * @private - * @type {boolean} - */ - this.fix = !!argv.fix; - } - - - /** - * Returns whether this is a debug build - * - * @return {boolean} - */ - isDebug () - { - return this.debug; - } - - - /** - * Returns whether the watcher should be activated - * - * @return {boolean} - */ - isWatch () - { - return this.watch; - } - - - /** - * Returns whether the code should be linted - * - * @return {boolean} - */ - isLint () - { - return this.lint; - } - - - /** - * Returns whether the bundle sizes should be analyzed - * - * @return {boolean} - */ - isBundleAnalyzerEnabled () - { - return this.bundleAnalyzer; - } - - - /** - * Returns whether the bundles should only be compiled and analyzed - * - * @return {boolean} - */ - isAnalyze () - { - return this.analyze; - } - - - /** - * Returns whether the code should automatically be fixed for code style - * - * @return {boolean} - */ - isFix () - { - return this.fix; - } -} - -module.exports = CliConfig; From fadb131414ca17e9708b1d095e0cfa9b78919b5c Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:22:04 +0200 Subject: [PATCH 05/33] Simplify print package versions --- src/print-package-versions.ts | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/print-package-versions.ts b/src/print-package-versions.ts index 4913bf8..69732d2 100644 --- a/src/print-package-versions.ts +++ b/src/print-package-versions.ts @@ -2,35 +2,16 @@ import * as kleur from "kleur"; import {yellow} from "kleur"; -/** - * Returns the padding for the given - * - * @private - * - * @param {string} packageName - * @param {number} maxLength - * @return {string} - */ -function padding (packageName: string, maxLength: number) : string -{ - const length = packageName.length; - - return (length < maxLength) - ? " ".repeat(maxLength - length) - : ""; -} - - /** * Exports a function to print the version overview * * @param {string} kabaVersion * @param {Object.} packages */ -module.exports = function (kabaVersion: string, packages: {[name: string]: kleur.Color}) : void +export function printPackageVersions (kabaVersion: string, packages: {[name: string]: kleur.Color}) : void { const maxLength = Object.keys(packages).reduce((max, name) => Math.max(max, name.length), 0); - console.log(yellow("kaba"), padding("kaba", maxLength), kabaVersion); + console.log(yellow("kaba"), "kaba".padStart(maxLength), kabaVersion); for (const packageName in packages) { @@ -43,8 +24,8 @@ module.exports = function (kabaVersion: string, packages: {[name: string]: kleur console.log( color(packageName), - padding(packageName, maxLength), + packageName.padStart(maxLength), require(`${packageName}/package.json`).version ); } -}; +} From 9e47d1fb7ad40dd982b5cb7edd391f027346686b Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:23:31 +0200 Subject: [PATCH 06/33] Move CliConfig type to @types --- bin/run.ts | 12 +----------- src/@types/kaba.d.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/bin/run.ts b/bin/run.ts index d34f0a6..d3555ae 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -17,16 +17,6 @@ console.log(``); const program = sade("kaba"); const kabaVersion = require("../package").version; -interface CliConfig -{ - debug?: boolean; - watch?: boolean; - lint?: boolean; - openBundleAnalyzer?: boolean; - fix?: boolean; -} - - program .version(kabaVersion) .option('--verbose', 'show all errors in the runner / config file with stack trace'); @@ -124,7 +114,7 @@ program.parse(process.argv); /** * Main kaba function */ -function runKaba (cliConfig: CliConfig, isVerbose: boolean) : void +function runKaba (cliConfig: kaba.CliConfig, isVerbose: boolean) : void { try { diff --git a/src/@types/kaba.d.ts b/src/@types/kaba.d.ts index 359bd85..8f1e227 100644 --- a/src/@types/kaba.d.ts +++ b/src/@types/kaba.d.ts @@ -1,4 +1,11 @@ declare namespace kaba { - + export interface CliConfig + { + debug?: boolean; + watch?: boolean; + lint?: boolean; + openBundleAnalyzer?: boolean; + fix?: boolean; + } } From 52d95cd1e296940cbdcefcbcbaa6ad51257d0ddf Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:29:45 +0200 Subject: [PATCH 07/33] Add more types --- src/@types/kaba.d.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/@types/kaba.d.ts b/src/@types/kaba.d.ts index 8f1e227..423f2ee 100644 --- a/src/@types/kaba.d.ts +++ b/src/@types/kaba.d.ts @@ -1,3 +1,6 @@ +import * as webpack from "webpack"; + + declare namespace kaba { export interface CliConfig @@ -8,4 +11,25 @@ declare namespace kaba openBundleAnalyzer?: boolean; fix?: boolean; } + + export interface SassBuildConfig + { + entries: {[name: string]: string}; + includePaths: string[]; + outputPath: string; + cwd: string; + } + + type WebpackBuildConfig = Partial; + + export interface BuildConfig + { + sass: SassBuildConfig; + js: { + _common: WebpackBuildConfig; + module: WebpackBuildConfig; + legacy: WebpackBuildConfig; + }; + cwd: string; + } } From 63b8839394d84a6fc41680897aa6367c2107b183 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:29:51 +0200 Subject: [PATCH 08/33] Transform SassRunner --- src/runner/{SassRunner.js => SassRunner.ts} | 53 ++++++--------------- 1 file changed, 15 insertions(+), 38 deletions(-) rename src/runner/{SassRunner.js => SassRunner.ts} (50%) diff --git a/src/runner/SassRunner.js b/src/runner/SassRunner.ts similarity index 50% rename from src/runner/SassRunner.js rename to src/runner/SassRunner.ts index e959288..97f444f 100644 --- a/src/runner/SassRunner.js +++ b/src/runner/SassRunner.ts @@ -1,40 +1,25 @@ -const {bgMagenta, black} = require("kleur"); +import {KabaScss} from "kaba-scss/src"; +import {bgMagenta, black} from "kleur"; +import {kaba} from "../@types/kaba"; import {Logger} from "../Logger"; -const path = require("path"); +import path from "path"; -class SassRunner +export class SassRunner { + private buildConfig: kaba.SassBuildConfig; + private cliConfig: kaba.CliConfig; + private logger: Logger; + private compiler?: KabaScss; + /** * Constructs a new runner - * @param {KabaBuildConfig} fullBuildConfig - * @param {CliConfig} cliConfig */ - constructor (fullBuildConfig, cliConfig) + constructor (fullBuildConfig: kaba.BuildConfig, cliConfig: kaba.CliConfig) { - /** - * @private - * @type {SassBuildConfig} - */ this.buildConfig = fullBuildConfig.sass; - - /** - * @private - * @type {CliConfig} - */ this.cliConfig = cliConfig; - - /** - * @private - * @type {Logger} - */ this.logger = new Logger(bgMagenta(black(" Sass "))); - - /** - * @private - * @type {?KabaScss} - */ - this.compiler = null; } @@ -57,13 +42,7 @@ class SassRunner const {KabaScss} = require("kaba-scss"); - this.compiler = new KabaScss({ - debug: this.cliConfig.isDebug(), - watch: this.cliConfig.isWatch(), - lint: this.cliConfig.isLint(), - fix: this.cliConfig.isFix(), - cwd: this.buildConfig.cwd, - }); + this.compiler = new KabaScss(Object.assign({}, this.cliConfig, {cwd: this.buildConfig.cwd})); entries.forEach( name => @@ -71,11 +50,11 @@ class SassRunner const src = this.buildConfig.entries[name]; const outputPath = `${this.buildConfig.outputPath}/${name}.css`; - this.compiler.addEntry(src, path.dirname(outputPath), path.basename(outputPath)); + (this.compiler as KabaScss).addEntry(src, path.dirname(outputPath), path.basename(outputPath)); } ); - return this.compiler.run(); + return (this.compiler as KabaScss).run(); } @@ -84,11 +63,9 @@ class SassRunner */ stop () { - if (this.compiler !== null) + if (this.compiler) { this.compiler.stop(); } } } - -module.exports = SassRunner; From 25be148c40283eec50776e6b840f03b5ec5581f6 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:42:50 +0200 Subject: [PATCH 09/33] Removed obsolete logger KabaScss has its own logger --- src/runner/SassRunner.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/runner/SassRunner.ts b/src/runner/SassRunner.ts index 97f444f..1bb9336 100644 --- a/src/runner/SassRunner.ts +++ b/src/runner/SassRunner.ts @@ -1,7 +1,5 @@ import {KabaScss} from "kaba-scss/src"; -import {bgMagenta, black} from "kleur"; import {kaba} from "../@types/kaba"; -import {Logger} from "../Logger"; import path from "path"; @@ -9,7 +7,6 @@ export class SassRunner { private buildConfig: kaba.SassBuildConfig; private cliConfig: kaba.CliConfig; - private logger: Logger; private compiler?: KabaScss; /** @@ -19,7 +16,6 @@ export class SassRunner { this.buildConfig = fullBuildConfig.sass; this.cliConfig = cliConfig; - this.logger = new Logger(bgMagenta(black(" Sass "))); } From fee9aab0d3bf0e9d9a85012bcfb17dc683dfbcba Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 17:43:05 +0200 Subject: [PATCH 10/33] Transform WebpackRunner --- src/@types/kaba.d.ts | 6 +- .../{WebpackRunner.js => WebpackRunner.ts} | 134 +++++++++--------- 2 files changed, 68 insertions(+), 72 deletions(-) rename src/runner/{WebpackRunner.js => WebpackRunner.ts} (53%) diff --git a/src/@types/kaba.d.ts b/src/@types/kaba.d.ts index 423f2ee..1217994 100644 --- a/src/@types/kaba.d.ts +++ b/src/@types/kaba.d.ts @@ -25,10 +25,12 @@ declare namespace kaba export interface BuildConfig { sass: SassBuildConfig; - js: { - _common: WebpackBuildConfig; + js?: { + common: WebpackBuildConfig; module: WebpackBuildConfig; legacy: WebpackBuildConfig; + javaScriptDependenciesFileName: string; + customTypeScriptConfig?: string; }; cwd: string; } diff --git a/src/runner/WebpackRunner.js b/src/runner/WebpackRunner.ts similarity index 53% rename from src/runner/WebpackRunner.js rename to src/runner/WebpackRunner.ts index 3295ffd..ae94c3c 100644 --- a/src/runner/WebpackRunner.js +++ b/src/runner/WebpackRunner.ts @@ -1,102 +1,96 @@ -const fs = require("fs-extra"); -const {bgCyan, black, yellow} = require("kleur"); +import fs from "fs-extra"; +import {bgCyan, black, yellow} from "kleur"; +import * as webpack from "webpack"; +import {kaba} from "../@types/kaba"; import {Logger} from "../Logger"; -const path = require("path"); -const webpack = require("webpack"); +import path from "path"; -class WebpackRunner +export class WebpackRunner { + private buildConfig: kaba.BuildConfig; + private logger: Logger; + private watchers: webpack.Compiler.Watching[] = []; + private resolveCallback?: (success: boolean) => void; + /** * Constructs a new runner - * @param {KabaBuildConfig} buildConfig */ - constructor (buildConfig) + public constructor (buildConfig: kaba.BuildConfig) { - /** - * @private - * @type {KabaBuildConfig} - */ this.buildConfig = buildConfig; - - /** - * @private - * @type {ModularizedWebpackConfig[]} - */ - this.webpackConfigs = buildConfig.js.webpack; - - /** - * @private - * @type {Logger} - */ this.logger = new Logger(bgCyan(black(" webpack "))); - - /** - * @private - * @type {Compiler.Watching[]} - */ - this.watchers = []; - - /** - * @private - * @type {?function} - */ - this.resolveCallback = null; } /** * Runs the actual runner - * - * @return {Promise} whether the build was successful and error-free */ - async run () + public async run (): Promise { - if (Object.keys(this.webpackConfigs).length === 0) - { - return true; - } - return new Promise( (resolve) => { + if (!this.buildConfig.js) + { + return true; + } + this.logger.log("Launching webpack..."); const start = process.hrtime(); - if (null != this.buildConfig.js.customTypeScriptConfig) + if (this.buildConfig.js.customTypeScriptConfig) { this.logger.log(`Using custom TypeScript config: ${yellow(path.relative(this.buildConfig.cwd, this.buildConfig.js.customTypeScriptConfig))}`); } - if (this.webpackConfigs.some(entry => entry.config.watch)) + if (this.buildConfig.js.common.watch) { this.resolveCallback = resolve; } - this.webpackConfigs.forEach(entry => { - const compiler = webpack(entry.config); - - if (entry.config.watch) - { + let compilerLegacy = webpack(Object.assign( + {}, + this.buildConfig.js.common, + this.buildConfig.js.legacy, + )); - } - }); + let compilerModule = webpack(Object.assign( + {}, + this.buildConfig.js.common, + this.buildConfig.js.module, + )); - if (this.webpackConfigs.watch) + if (this.buildConfig.js.common.watch) { this.resolveCallback = resolve; - this.watcher = compiler.watch( - {}, - (error, stats) => this.onCompilationFinished(error, stats) + this.watchers.push( + compilerLegacy.watch( + {}, + (error, stats) => this.onCompilationFinished(error, stats, false) + ) + ); + this.watchers.push( + compilerModule.watch( + {}, + (error, stats) => this.onCompilationFinished(error, stats, true) + ) ); } else { - compiler.run( + compilerLegacy.run( (error, stats) => { - resolve(this.onCompilationFinished(error, stats)); + resolve(this.onCompilationFinished(error, stats, false, start)); + this.logger.logBuildSuccess("(all files)", process.hrtime(start)); + } + ); + + compilerModule.run( + (error, stats) => { + resolve(this.onCompilationFinished(error, stats, true, start)); this.logger.logBuildSuccess("(all files)", process.hrtime(start)); } ); @@ -108,13 +102,8 @@ class WebpackRunner /** * Callback on after the compilation has finished - * - * @param {Error|null} error - * @param {webpack.stats} stats - * @param {boolean} isModule - * @return {boolean} whether the compilation had no errors */ - onCompilationFinished (error, stats, isModule) + private onCompilationFinished (error: Error|null, stats: webpack.Stats, isModule: boolean, start?: [number, number]) : boolean { if (error) { @@ -139,16 +128,16 @@ class WebpackRunner /** * Stops the runner */ - stop () + public stop () : void { - if (null !== this.resolveCallback) + if (this.resolveCallback) { Promise.all( this.watchers.map(watcher => new Promise(resolve => watcher.close(resolve)) ) ) - .then(() => this.resolveCallback(true)); + .then(() => (this.resolveCallback as (success: boolean) => void)(true)); } } @@ -162,6 +151,11 @@ class WebpackRunner */ writeDependenciesFile (stats, isModule) { + if (!this.buildConfig.js) + { + return; + } + const entrypoints = {}; for (const mapEntry of stats.compilation.entrypoints.entries()) @@ -175,17 +169,17 @@ class WebpackRunner ); } + let outputPath = (this.buildConfig.js.common.output as webpack.Output).path as string; + // ensure that output path exists - fs.ensureDirSync(this.webpackConfigs.output.path); + fs.ensureDirSync(outputPath); const fileName = `${this.buildConfig.js.javaScriptDependenciesFileName}${isModule ? ".module" : ""}.json`; fs.writeFileSync( - path.join(this.webpackConfigs.output.path, fileName), + path.join(outputPath, fileName), JSON.stringify(entrypoints), "utf-8" ); this.logger.log(`Entrypoint dependencies written to ${yellow(fileName)}`); } } - -module.exports = WebpackRunner; From 873baa1058acc305c5f4e18cf8a55b1ce1ac282c Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 18:16:26 +0200 Subject: [PATCH 11/33] Update ignore files --- .gitignore | 6 ++++++ .npmignore | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index c7dc7c5..267961a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ /package-lock.json /tests/fixtures/*/build /tests/fixtures/*/.stylelintcache + +# ignore build files +*.d.ts +*.js +!/src/@types/*.d.ts +!/tests/**/*.js diff --git a/.npmignore b/.npmignore index 2504663..41b6e8d 100644 --- a/.npmignore +++ b/.npmignore @@ -5,3 +5,9 @@ /node_modules /package-lock.json /tests +/tsconfig.json + +# ignore all .ts when publishing +*.ts +*.tsx +!*.d.ts From ea7b7736642e39976f1ce78e9ecb41ecafc7868a Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 18:16:32 +0200 Subject: [PATCH 12/33] Add missing import --- bin/run.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/run.ts b/bin/run.ts index d3555ae..1a7eb35 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -1,5 +1,6 @@ #!/usr/bin/env node +import {kaba} from "../src/@types/kaba"; import {Logger} from "../src/Logger"; import sade from "sade"; import {bgYellow, black, blue, cyan, green, magenta, red, yellow} from "kleur"; From ba7e6b94833fe91b162ceb081a1ffbd39e5aa952 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 18:16:48 +0200 Subject: [PATCH 13/33] Update dependencies --- package.json | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 46a65c5..82c3a21 100644 --- a/package.json +++ b/package.json @@ -21,31 +21,32 @@ "dependencies": { "@babel/core": "^7.0.0", "@becklyn/typescript-error-formatter": "^1.0.4", - "babel-eslint": "^10.0.0", + "babel-eslint": "^10.0.2", "babel-loader": "^8.0.2", "clean-webpack-plugin": "^3.0.0", "eslint": "^5.5.0", "eslint-loader": "^2.1.0", - "eslint-plugin-react": "^7.11.0", - "fork-ts-checker-webpack-plugin": "^1.3.4", + "eslint-plugin-react": "^7.14.2", + "fork-ts-checker-webpack-plugin": "^1.3.7", "fs-extra": "^8.0.0", "kaba-babel-preset": "^2.0.3", "kleur": "^3.0.3", "pretty-hrtime": "^1.0.3", "raw-loader": "^2.0.0", - "sade": "^1.4.1", + "sade": "^1.6.0", "terser-webpack-plugin": "^1.0.2", - "ts-loader": "^6.0.0", + "ts-loader": "^6.0.4", "typescript": "^3.5.2", - "webpack": "^4.16.1" + "webpack": "^4.35.0" }, "peerDependencies": { "kaba-scss": "^3.0.0", "webpack-bundle-analyzer": "^3.3.0" }, "devDependencies": { + "@types/terser-webpack-plugin": "^1.2.1", "ava": "^2.0.0", - "kaba-scss": "^3.0.0", + "kaba-scss": "^3.0.1", "webpack-bundle-analyzer": "^3.3.2" }, "engines": { From ed2b4dbfd0cf7454ba8817f67d3644204d6286dd Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 18:17:26 +0200 Subject: [PATCH 14/33] Transform kaba --- src/{Kaba.js => Kaba.ts} | 486 ++++++++++++++------------------------- 1 file changed, 170 insertions(+), 316 deletions(-) rename src/{Kaba.js => Kaba.ts} (54%) diff --git a/src/Kaba.js b/src/Kaba.ts similarity index 54% rename from src/Kaba.js rename to src/Kaba.ts index 6ab9c19..c825a58 100644 --- a/src/Kaba.js +++ b/src/Kaba.ts @@ -1,185 +1,78 @@ -const {CleanWebpackPlugin} = require('clean-webpack-plugin'); -const kabaBabelPreset = require("kaba-babel-preset"); -const {blue, red, yellow} = require("kleur"); -const fs = require("fs-extra"); -const path = require("path"); -const {ProvidePlugin} = require("webpack"); -const TerserPlugin = require('terser-webpack-plugin'); -const typeScriptErrorFormatter = require("@becklyn/typescript-error-formatter"); +import {CleanWebpackPlugin} from 'clean-webpack-plugin'; +import kabaBabelPreset from "kaba-babel-preset"; +import {blue, red, yellow} from "kleur"; +import fs from "fs-extra"; +import path from "path"; +import * as webpack from "webpack"; +import {ProvidePlugin} from "webpack"; +import TerserPlugin from 'terser-webpack-plugin'; +import typeScriptErrorFormatter from "@becklyn/typescript-error-formatter"; +import {kaba} from "./@types/kaba"; +import CliConfig = kaba.CliConfig; + + +interface Entries +{ + [name: string]: string; +} + +interface OutputPaths +{ + base: string; + css: string; + js: string; +} + +interface Externals +{ + [name: string]: string; +} -/** - * @typedef {{ - * entries: Object, - * includePaths: string[], - * outputPath: string, - * cwd: string, - * }} SassBuildConfig - * - * @typedef {{ - * config: webpack.Configuration, - * module: true, - * }} ModularizedWebpackConfig - * - * @typedef {{ - * sass: SassBuildConfig, - * js: { - * javaScriptDependenciesFileName: string, - * webpack: ModularizedWebpackConfig[], - * customTypeScriptConfig: string|null, - * }, - * cwd: string, - * }} KabaBuildConfig - */ /** * Main Kaba class */ -class Kaba +export default class Kaba { + private cwd: string; + private libRoot: string; + private jsEntries: Entries = {}; + private sassEntries: Entries = {}; + private sassIncludePaths: string[] = []; + private outputPaths: OutputPaths = { + base: "build", + css: "css", + js: "js", + }; + private publicPath: string = "/assets/"; + private externals: Externals = {}; + private moduleConcatenationEnabled: boolean = false; + private plugins: webpack.Plugin[] = []; + private javaScriptDependenciesFileName: string = "_dependencies"; + private splitChunks: boolean = true; + private hashFileNames: boolean = true; + private customTypeScriptConfig?: string; + /** * */ - constructor () + public constructor () { - /** - * @private - * @type {string} - */ this.cwd = process.cwd(); - - /** - * @private - * @†ype {string} - */ this.libRoot = path.dirname(__dirname); - - /** - * @private - * @type {Object} - */ - this.jsEntries = {}; - - /** - * @private - * @type {Object} - */ - this.sassEntries = {}; - - /** - * @private - * @type {string} - */ - this.sassIncludePaths = []; - - /** - * @private - * @type {{base : string, css : string, js : string}} - */ - this.outputPaths = {}; - - /** - * @private - * @type {string} - */ - this.publicPath = ""; - - /** - * @private - * @type {Object} - */ - this.externals = {}; - - /** - * @private - * @type {boolean} - */ - this.moduleConcatenationEnabled = false; - - /** - * The webpack plugins - * - * @private - * @type {Array} - */ this.plugins = [ new CleanWebpackPlugin(), new ProvidePlugin({ h: ["preact", "h"], }), ]; - - /** - * @private - * @type {string} - */ - this.javaScriptDependenciesFileName = "_dependencies"; - - /** - * @private - * @type {boolean} - */ - this.splitChunks = true; - - /** - * @private - * @type {boolean} - */ - this.hashFileNames = true; - - /** - * @private - * @type {?string} - */ - this.customTypeScriptConfig = null; - - - // set defaults - this - .setOutputPath("build") - .setPublicPath("/assets/") - ; - } - - - /** - * Adds an entry - * - * @deprecated - * @param {Object} mapping - * @return {Kaba} - */ - addEntries (mapping) - { - Object.keys(mapping).forEach( - name => - { - const source = mapping[name]; - const entry = { - [name]: source, - }; - - if (/\.scss$/.test(source)) - { - this.addSassEntries(entry); - } - else - { - this.addJsEntries(entry); - } - } - ); - - return this; } /** * Adds JS entries - * - * @param {Object} mapping - * @return {Kaba} */ - addJavaScriptEntries (mapping) + public addJavaScriptEntries (mapping: Entries): this { this.addEntriesToList(mapping, this.jsEntries, "js"); return this; @@ -188,11 +81,8 @@ class Kaba /** * Adds Sass entries - * - * @param {Object} mapping - * @return {Kaba} */ - addSassEntries (mapping) + public addSassEntries (mapping: Entries): this { try { @@ -200,7 +90,8 @@ class Kaba } catch (e) { - console.log(`${red("ERROR")} It seems that ${yellow("kaba-scss")} is not installed. Install it with ${blue("npm install -D kaba-scss")}`); + console.log(`${red("ERROR")} It seems that ${yellow("kaba-scss")} is not installed. Install it with ${blue( + "npm install -D kaba-scss")}`); process.exit(1); } @@ -211,13 +102,8 @@ class Kaba /** * Adds items from a mapping to list - * - * @private - * @param {Object} mapping - * @param {Object} list - * @param {string} type */ - addEntriesToList (mapping, list, type) + private addEntriesToList (mapping: Entries, list: Entries, type: string): void { Object.keys(mapping).forEach( name => @@ -235,20 +121,15 @@ class Kaba } list[name] = source; - } + }, ); } /** * Sets the output path - * - * @param {string} base - * @param {string} cssSubDir - * @param {string} jsSubDir - * @return {Kaba} */ - setOutputPath (base, cssSubDir = "css", jsSubDir = "js") + public setOutputPath (base: string, cssSubDir: string = "css", jsSubDir: string = "js"): this { this.outputPaths = { base: path.join(this.cwd, base), @@ -261,11 +142,8 @@ class Kaba /** * Sets the relative public path (for automatic imports) - * - * @param {string} publicPath relative to the cwd - * @return {Kaba} */ - setPublicPath (publicPath) + public setPublicPath (publicPath: string): this { this.publicPath = publicPath; return this; @@ -273,11 +151,9 @@ class Kaba /** - * - * @param {Object} externals - * @return {Kaba} + * Sets the externally available instances */ - setExternals (externals) + public setExternals (externals: Externals): this { this.externals = externals; return this; @@ -286,10 +162,8 @@ class Kaba /** * Disables module concatenation - * - * @return {Kaba} */ - disableModuleConcatenation () + public disableModuleConcatenation (): this { this.moduleConcatenationEnabled = false; return this; @@ -298,10 +172,8 @@ class Kaba /** * Enables module concatenation - * - * @return {Kaba} */ - enableModuleConcatenation () + public enableModuleConcatenation (): this { this.moduleConcatenationEnabled = true; return this; @@ -310,10 +182,8 @@ class Kaba /** * Adds `node_modules` to the include dir of sass. - * - * @return {Kaba} */ - enableSassNodeModulesIncludePaths () + public enableSassNodeModulesIncludePaths (): this { this.sassIncludePaths = [ path.join(this.cwd, "node_modules"), @@ -324,11 +194,8 @@ class Kaba /** * Sets the file name of the javascript dependencies file - * - * @param {string} name - * @return {Kaba} */ - setJavaScriptDependenciesName (name) + public setJavaScriptDependenciesName (name: string): this { this.javaScriptDependenciesFileName = name; return this; @@ -337,10 +204,8 @@ class Kaba /** * Disables chunk splitting - * - * @returns {Kaba} */ - disableChunkSplitting () + public disableChunkSplitting (): this { this.splitChunks = false; return this; @@ -349,10 +214,8 @@ class Kaba /** * Disables chunk hashes in file names - * - * @returns {Kaba} */ - disableFileNameHashing () + public disableFileNameHashing (): this { this.hashFileNames = false; return this; @@ -363,26 +226,27 @@ class Kaba * Returns the kaba config * * @internal - * @private - * @param {CliConfig} cliConfig - * @return {KabaBuildConfig} */ - getBuildConfig (cliConfig) + public getBuildConfig (cliConfig: CliConfig): kaba.BuildConfig { + let customTypeScriptConfig = path.join(this.cwd, "tsconfig.json"); + if (fs.pathExistsSync(customTypeScriptConfig)) + { + this.customTypeScriptConfig = customTypeScriptConfig; + } + return { - sass: this.buildSassConfig(), + sass: { + entries: this.sassEntries, + includePaths: this.sassIncludePaths, + outputPath: path.join(this.outputPaths.base, this.outputPaths.css), + cwd: this.cwd, + }, js: { + common: this.buildWebpackCommon(cliConfig), + module: this.buildWebpackConfig(cliConfig, true), + legacy: this.buildWebpackConfig(cliConfig, false), javaScriptDependenciesFileName: this.javaScriptDependenciesFileName, - webpack: [ - { - config: this.buildWebpackConfig(cliConfig, false), - module: false, - }, - { - config: this.buildWebpackConfig(cliConfig, true), - module: true, - }, - ], customTypeScriptConfig: this.customTypeScriptConfig, }, cwd: this.cwd, @@ -391,95 +255,16 @@ class Kaba /** - * Builds the SCSS config - * - * @private - * @return {SassBuildConfig} + * Builds the common webpack config, that is common between legacy & module */ - buildSassConfig () + private buildWebpackCommon (cliConfig: kaba.CliConfig): Partial { - return { - entries: this.sassEntries, - includePaths: this.sassIncludePaths, - outputPath: path.join(this.outputPaths.base, this.outputPaths.css), - cwd: this.cwd, - }; - } - - - /** - * Builds the webpack config - * - * @private - * @param {CliConfig} cliConfig - * @return {webpack.Configuration} - */ - buildWebpackConfig (cliConfig) - { - const babelLoader = { - loader: "babel-loader?cacheDirectory", - options: { - babelrc: false, - presets: [ - kabaBabelPreset, - ], - }, - }; - - let customTypeScriptConfig = path.join(this.cwd, "tsconfig.json"); - if (fs.pathExistsSync(customTypeScriptConfig)) - { - this.customTypeScriptConfig = customTypeScriptConfig; - } - - /** @type {webpack.Configuration} config */ - const config = { + const config: Partial = { // entry entry: this.jsEntries, // mode - mode: cliConfig.isDebug() ? "development" : "production", - - // output - output: { - path: path.join(this.outputPaths.base, this.outputPaths.js), - filename: this.hashFileNames ? '[name].[chunkhash].js' : '[name].js', - publicPath: this.publicPath, - pathinfo: !cliConfig.isDebug(), - }, - - // module - module: { - rules: [ - // TypeScript - { - test: /\.tsx?$/, - use: [ - babelLoader, - { - loader: "ts-loader", - options: { - context: this.cwd, - configFile: this.customTypeScriptConfig || path.join(this.libRoot, "tsconfig.json"), - errorFormatter: (message, colors) => typeScriptErrorFormatter(message, colors, this.cwd), - }, - }, - ], - }, - - // Babel - { - test: /\.m?jsx?$/, - use: [babelLoader], - }, - - // content files - { - test: /\.(svg|txt)$/, - loader: "raw-loader", - }, - ], - }, + mode: cliConfig.debug ? "development" : "production", // resolve resolve: { @@ -495,6 +280,11 @@ class Kaba ], }, + // module + module: { + rules: [], + }, + // optimization optimization: { concatenateModules: this.moduleConcatenationEnabled, @@ -504,7 +294,7 @@ class Kaba // performance // devtool (source maps) - devtool: cliConfig.isDebug() + devtool: cliConfig.debug ? "eval" : "hidden-source-map", @@ -529,7 +319,7 @@ class Kaba plugins: this.plugins, // watch - watch: cliConfig.isWatch(), + watch: cliConfig.watch, // node // don't automatically polyfill certain node libraries @@ -539,7 +329,7 @@ class Kaba if (this.splitChunks) { - config.optimization.splitChunks = { + (config.optimization as any).splitChunks = { chunks: "all", minChunks: 1, maxAsyncRequests: 5, @@ -558,12 +348,12 @@ class Kaba }, }; - config.optimization.runtimeChunk = "single"; + (config.optimization as any).runtimeChunk = "single"; } - if (!cliConfig.isDebug()) + if (!cliConfig.debug) { - config.optimization.minimizer.push(new TerserPlugin({ + (config.optimization as any).minimizer.push(new TerserPlugin({ cache: true, parallel: true, sourceMap: true, @@ -573,28 +363,27 @@ class Kaba })); } - if (cliConfig.isLint() || cliConfig.isFix()) + if (cliConfig.lint || cliConfig.fix) { - config.module.rules.push({ - enforce: "pre", + (config.module as any).rules.push({ test: /\.m?jsx?$/, exclude: /node_modules|tests|vendor/, loader: "eslint-loader", options: { cache: true, - configFile: path.join(this.libRoot, ".eslintrc.yml"), - fix: cliConfig.isFix(), + configFile: path.join(this.libRoot, "configs/.eslintrc.yml"), + fix: cliConfig.fix, parser: "babel-eslint", }, }); } - if (cliConfig.isBundleAnalyzerEnabled()) + if (cliConfig.openBundleAnalyzer) { try { const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; - config.plugins.push(new BundleAnalyzerPlugin()); + (config.plugins as any[]).push(new BundleAnalyzerPlugin()); } catch (e) { @@ -617,6 +406,71 @@ class Kaba return config; } -} -module.exports = Kaba; + + /** + * Builds the specialized webpack config for a legacy / module build + */ + private buildWebpackConfig (cliConfig: kaba.CliConfig, isModule: boolean): Partial + { + const babelLoader = { + loader: "babel-loader?cacheDirectory", + options: { + babelrc: false, + presets: [ + isModule ? kabaBabelPreset.module : kabaBabelPreset.legacy, + ], + }, + }; + + let fileNamePattern = this.hashFileNames ? '[name].[chunkhash].js' : '[name].js'; + + if (!isModule) + { + fileNamePattern = this.hashFileNames ? '[name].[chunkhash].legacy.js' : '[name].legacy.js'; + } + + return { + // output + output: { + path: path.join(this.outputPaths.base, this.outputPaths.js), + filename: fileNamePattern, + publicPath: this.publicPath, + pathinfo: !cliConfig.debug, + }, + + // module + module: { + rules: [ + // TypeScript + { + test: /\.tsx?$/, + use: [ + babelLoader, + { + loader: "ts-loader", + options: { + context: this.cwd, + configFile: this.customTypeScriptConfig || path.join(this.libRoot, "configs/tsconfig.json"), + errorFormatter: (message, colors) => typeScriptErrorFormatter(message, colors, this.cwd), + }, + }, + ], + }, + + // Babel + { + test: /\.m?jsx?$/, + use: [babelLoader], + }, + + // content files + { + test: /\.(svg|txt)$/, + loader: "raw-loader", + }, + ], + }, + }; + } +} From 1348a812ff5ffafec4a5a31e7823ef23b9063ac5 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 18:18:43 +0200 Subject: [PATCH 15/33] Exclude tests dir in build --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 4b49826..2a61927 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "**/*.ts" ], "exclude": [ - "node_modules" + "node_modules", + "tests" ] } From 4e6feee942337cdec359514feddb1c0b5840ba11 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 18:47:25 +0200 Subject: [PATCH 16/33] Various smaller fixes --- bin/run.ts | 8 ++-- package.json | 1 + src/@types/kaba.d.ts | 1 - src/Kaba.ts | 70 ++++++++++++++++++++--------------- src/Logger.ts | 2 +- src/print-package-versions.ts | 8 +++- src/runner/SassRunner.ts | 2 +- src/runner/WebpackRunner.ts | 9 +++-- 8 files changed, 59 insertions(+), 42 deletions(-) diff --git a/bin/run.ts b/bin/run.ts index 1a7eb35..715f3e6 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -1,8 +1,9 @@ #!/usr/bin/env node import {kaba} from "../src/@types/kaba"; +import Kaba from "../src/Kaba"; import {Logger} from "../src/Logger"; -import sade from "sade"; +const sade = require("sade"); import {bgYellow, black, blue, cyan, green, magenta, red, yellow} from "kleur"; import {printPackageVersions} from "../src/print-package-versions"; import {SassRunner} from "../src/runner/SassRunner"; @@ -96,7 +97,7 @@ program "kaba-babel-preset": yellow, "kaba-scss": yellow, webpack: cyan, - "babel-core": blue, + "@babel/core": blue, typescript: blue, eslint: blue, "node-sass": magenta, @@ -123,8 +124,7 @@ function runKaba (cliConfig: kaba.CliConfig, isVerbose: boolean) : void logger.log("kaba started"); const start = process.hrtime(); - /** @type {Kaba} kaba */ - const kaba = require(`${process.cwd()}/kaba.js`); + const kaba: Kaba = require(`${process.cwd()}/kaba.js`); const buildConfig = kaba.getBuildConfig(cliConfig); const scss = new SassRunner(buildConfig, cliConfig); diff --git a/package.json b/package.json index 82c3a21..9275ef3 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "babel-eslint": "^10.0.2", "babel-loader": "^8.0.2", "clean-webpack-plugin": "^3.0.0", + "deep-extend": "^0.6.0", "eslint": "^5.5.0", "eslint-loader": "^2.1.0", "eslint-plugin-react": "^7.14.2", diff --git a/src/@types/kaba.d.ts b/src/@types/kaba.d.ts index 1217994..0c2496e 100644 --- a/src/@types/kaba.d.ts +++ b/src/@types/kaba.d.ts @@ -1,6 +1,5 @@ import * as webpack from "webpack"; - declare namespace kaba { export interface CliConfig diff --git a/src/Kaba.ts b/src/Kaba.ts index c825a58..279ad7c 100644 --- a/src/Kaba.ts +++ b/src/Kaba.ts @@ -1,12 +1,12 @@ import {CleanWebpackPlugin} from 'clean-webpack-plugin'; -import kabaBabelPreset from "kaba-babel-preset"; +const kabaBabelPreset = require("kaba-babel-preset"); import {blue, red, yellow} from "kleur"; -import fs from "fs-extra"; -import path from "path"; +const fs = require("fs-extra"); +const path = require("path"); import * as webpack from "webpack"; import {ProvidePlugin} from "webpack"; -import TerserPlugin from 'terser-webpack-plugin'; -import typeScriptErrorFormatter from "@becklyn/typescript-error-formatter"; +const TerserPlugin = require('terser-webpack-plugin'); +const typeScriptErrorFormatter = require("@becklyn/typescript-error-formatter"); import {kaba} from "./@types/kaba"; import CliConfig = kaba.CliConfig; @@ -32,7 +32,7 @@ interface Externals /** * Main Kaba class */ -export default class Kaba +export class Kaba { private cwd: string; private libRoot: string; @@ -40,9 +40,9 @@ export default class Kaba private sassEntries: Entries = {}; private sassIncludePaths: string[] = []; private outputPaths: OutputPaths = { - base: "build", - css: "css", - js: "js", + base: "", + css: "", + js: "", }; private publicPath: string = "/assets/"; private externals: Externals = {}; @@ -66,6 +66,9 @@ export default class Kaba h: ["preact", "h"], }), ]; + + // set defaults + this.setOutputPath("build"); } @@ -266,6 +269,13 @@ export default class Kaba // mode mode: cliConfig.debug ? "development" : "production", + // output + output: { + path: path.join(this.outputPaths.base, this.outputPaths.js), + publicPath: this.publicPath, + pathinfo: !cliConfig.debug, + }, + // resolve resolve: { // TS is potentially added below @@ -363,21 +373,6 @@ export default class Kaba })); } - if (cliConfig.lint || cliConfig.fix) - { - (config.module as any).rules.push({ - test: /\.m?jsx?$/, - exclude: /node_modules|tests|vendor/, - loader: "eslint-loader", - options: { - cache: true, - configFile: path.join(this.libRoot, "configs/.eslintrc.yml"), - fix: cliConfig.fix, - parser: "babel-eslint", - }, - }); - } - if (cliConfig.openBundleAnalyzer) { try @@ -427,16 +422,13 @@ export default class Kaba if (!isModule) { - fileNamePattern = this.hashFileNames ? '[name].[chunkhash].legacy.js' : '[name].legacy.js'; + fileNamePattern = fileNamePattern.replace(".js", ".legacy.js"); } - return { + let config = { // output output: { - path: path.join(this.outputPaths.base, this.outputPaths.js), filename: fileNamePattern, - publicPath: this.publicPath, - pathinfo: !cliConfig.debug, }, // module @@ -472,5 +464,25 @@ export default class Kaba ], }, }; + + if (cliConfig.lint || cliConfig.fix) + { + (config.module as any).rules.push({ + test: /\.m?jsx?$/, + exclude: /node_modules|tests|vendor/, + loader: "eslint-loader", + options: { + cache: true, + configFile: path.join(this.libRoot, "configs/.eslintrc.yml"), + fix: cliConfig.fix, + parser: "babel-eslint", + }, + }); + } + + return config; } } + + +export default Kaba; diff --git a/src/Logger.ts b/src/Logger.ts index 0656ee1..126d044 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -1,5 +1,5 @@ import {gray, green, red, yellow} from "kleur"; -import prettyHrtime from "pretty-hrtime"; +const prettyHrtime = require("pretty-hrtime"); interface FileError { diff --git a/src/print-package-versions.ts b/src/print-package-versions.ts index 69732d2..3c1ea01 100644 --- a/src/print-package-versions.ts +++ b/src/print-package-versions.ts @@ -11,7 +11,11 @@ import {yellow} from "kleur"; export function printPackageVersions (kabaVersion: string, packages: {[name: string]: kleur.Color}) : void { const maxLength = Object.keys(packages).reduce((max, name) => Math.max(max, name.length), 0); - console.log(yellow("kaba"), "kaba".padStart(maxLength), kabaVersion); + console.log( + yellow("kaba"), + " ".repeat(maxLength - 4), + kabaVersion + ); for (const packageName in packages) { @@ -24,7 +28,7 @@ export function printPackageVersions (kabaVersion: string, packages: {[name: str console.log( color(packageName), - packageName.padStart(maxLength), + " ".repeat( maxLength - packageName.length), require(`${packageName}/package.json`).version ); } diff --git a/src/runner/SassRunner.ts b/src/runner/SassRunner.ts index 1bb9336..8afcd25 100644 --- a/src/runner/SassRunner.ts +++ b/src/runner/SassRunner.ts @@ -1,6 +1,6 @@ import {KabaScss} from "kaba-scss/src"; import {kaba} from "../@types/kaba"; -import path from "path"; +const path = require("path"); export class SassRunner diff --git a/src/runner/WebpackRunner.ts b/src/runner/WebpackRunner.ts index ae94c3c..2f15776 100644 --- a/src/runner/WebpackRunner.ts +++ b/src/runner/WebpackRunner.ts @@ -1,9 +1,10 @@ -import fs from "fs-extra"; +const fs = require("fs-extra"); import {bgCyan, black, yellow} from "kleur"; import * as webpack from "webpack"; import {kaba} from "../@types/kaba"; import {Logger} from "../Logger"; -import path from "path"; +const path = require("path"); +const deepExtend = require("deep-extend"); export class WebpackRunner @@ -49,13 +50,13 @@ export class WebpackRunner this.resolveCallback = resolve; } - let compilerLegacy = webpack(Object.assign( + let compilerLegacy = webpack(deepExtend( {}, this.buildConfig.js.common, this.buildConfig.js.legacy, )); - let compilerModule = webpack(Object.assign( + let compilerModule = webpack(deepExtend( {}, this.buildConfig.js.common, this.buildConfig.js.module, From 5e54871d13252536cdf2765bb0afb57802b5f3d6 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 20:44:37 +0200 Subject: [PATCH 17/33] Add docs + final polish --- CHANGELOG.md | 22 ++-- UPGRADE.md | 8 ++ .../{tsconfig.json => tsconfig.legacy.json} | 1 - configs/tsconfig.modern.json | 27 +++++ package.json | 5 +- src/@types/kaba.d.ts | 1 - src/Kaba.ts | 61 +++++----- src/runner/WebpackRunner.ts | 104 +++++++++--------- 8 files changed, 141 insertions(+), 88 deletions(-) rename configs/{tsconfig.json => tsconfig.legacy.json} (99%) create mode 100644 configs/tsconfig.modern.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 77b85af..0dff0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,26 @@ -8.1 -=== +9.0.0 +===== + +* Always build a legacy and a modern JS build. + + +8.1.0 +===== * Changed the webpack include order, to avoid false-positive TypeScript errors. * Activated the `no-prototype-builtins` ESLint rule. * Automatically add the import for the `h()` function from preact for all modules. -8.0 -=== +8.0.0 +===== * Removed `enableTypeScript()`. * Removed `setBrowserList()`. -7.3 -=== +7.3.0 +===== * Always build source maps. * Always enable TypeScript for `.ts` / `.tsx` files. @@ -23,8 +29,8 @@ * Deprecated `setBrowserList()`. -7.2 -=== +7.2.0 +===== * Updated bundled KabaScss to 2.x. * Update the rest of the bundled dependencies. diff --git a/UPGRADE.md b/UPGRADE.md index a82d0a8..64fa12c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,11 @@ +8.x to 9.0 +========== + +* Internal: The project was ported to TypeScript. +* Always build a legacy and a modern JS build. +* Removed the ability to use the project's `tsconfig.json`. + + 7.x to 8.0 ========== diff --git a/configs/tsconfig.json b/configs/tsconfig.legacy.json similarity index 99% rename from configs/tsconfig.json rename to configs/tsconfig.legacy.json index aa6fdef..fa9eca2 100644 --- a/configs/tsconfig.json +++ b/configs/tsconfig.legacy.json @@ -18,7 +18,6 @@ "sourceMap": true, "strict": false, "target": "es5" - }, "exclude": [ "../node_modules", diff --git a/configs/tsconfig.modern.json b/configs/tsconfig.modern.json new file mode 100644 index 0000000..242a82b --- /dev/null +++ b/configs/tsconfig.modern.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "alwaysStrict": false, + "esModuleInterop": true, + "experimentalDecorators": true, + "jsx": "react", + "jsxFactory": "h", + "lib": [ + "dom", + "es5", + "es2015", + "es2016" + ], + "module": "es2015", + "moduleResolution": "node", + "noImplicitThis": true, + "removeComments": true, + "sourceMap": true, + "strict": false, + "target": "es2016" + }, + "exclude": [ + "../node_modules", + "vendor" + ] +} diff --git a/package.json b/package.json index 9275ef3..be5386a 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,18 @@ }, "dependencies": { "@babel/core": "^7.0.0", + "@becklyn/browserslist-config": "^2.1.0", "@becklyn/typescript-error-formatter": "^1.0.4", "babel-eslint": "^10.0.2", "babel-loader": "^8.0.2", "clean-webpack-plugin": "^3.0.0", - "deep-extend": "^0.6.0", + "core-js": "^3.1.4", "eslint": "^5.5.0", "eslint-loader": "^2.1.0", "eslint-plugin-react": "^7.14.2", "fork-ts-checker-webpack-plugin": "^1.3.7", "fs-extra": "^8.0.0", - "kaba-babel-preset": "^2.0.3", + "kaba-babel-preset": "^3.0.1", "kleur": "^3.0.3", "pretty-hrtime": "^1.0.3", "raw-loader": "^2.0.0", diff --git a/src/@types/kaba.d.ts b/src/@types/kaba.d.ts index 0c2496e..d858c61 100644 --- a/src/@types/kaba.d.ts +++ b/src/@types/kaba.d.ts @@ -29,7 +29,6 @@ declare namespace kaba module: WebpackBuildConfig; legacy: WebpackBuildConfig; javaScriptDependenciesFileName: string; - customTypeScriptConfig?: string; }; cwd: string; } diff --git a/src/Kaba.ts b/src/Kaba.ts index 279ad7c..12e50f7 100644 --- a/src/Kaba.ts +++ b/src/Kaba.ts @@ -1,14 +1,13 @@ -import {CleanWebpackPlugin} from 'clean-webpack-plugin'; -const kabaBabelPreset = require("kaba-babel-preset"); import {blue, red, yellow} from "kleur"; const fs = require("fs-extra"); const path = require("path"); import * as webpack from "webpack"; -import {ProvidePlugin} from "webpack"; +import {DefinePlugin, ProvidePlugin} from "webpack"; const TerserPlugin = require('terser-webpack-plugin'); const typeScriptErrorFormatter = require("@becklyn/typescript-error-formatter"); import {kaba} from "./@types/kaba"; import CliConfig = kaba.CliConfig; +const browserslistConfig = require("@becklyn/browserslist-config/envs"); interface Entries @@ -51,7 +50,6 @@ export class Kaba private javaScriptDependenciesFileName: string = "_dependencies"; private splitChunks: boolean = true; private hashFileNames: boolean = true; - private customTypeScriptConfig?: string; /** * @@ -61,7 +59,6 @@ export class Kaba this.cwd = process.cwd(); this.libRoot = path.dirname(__dirname); this.plugins = [ - new CleanWebpackPlugin(), new ProvidePlugin({ h: ["preact", "h"], }), @@ -232,12 +229,6 @@ export class Kaba */ public getBuildConfig (cliConfig: CliConfig): kaba.BuildConfig { - let customTypeScriptConfig = path.join(this.cwd, "tsconfig.json"); - if (fs.pathExistsSync(customTypeScriptConfig)) - { - this.customTypeScriptConfig = customTypeScriptConfig; - } - return { sass: { entries: this.sassEntries, @@ -250,7 +241,6 @@ export class Kaba module: this.buildWebpackConfig(cliConfig, true), legacy: this.buildWebpackConfig(cliConfig, false), javaScriptDependenciesFileName: this.javaScriptDependenciesFileName, - customTypeScriptConfig: this.customTypeScriptConfig, }, cwd: this.cwd, }; @@ -263,17 +253,15 @@ export class Kaba private buildWebpackCommon (cliConfig: kaba.CliConfig): Partial { const config: Partial = { - // entry - entry: this.jsEntries, - // mode mode: cliConfig.debug ? "development" : "production", // output output: { path: path.join(this.outputPaths.base, this.outputPaths.js), + filename: this.hashFileNames ? '[name].[chunkhash].js' : '[name].js', publicPath: this.publicPath, - pathinfo: !cliConfig.debug, + pathinfo: cliConfig.debug, }, // resolve @@ -305,7 +293,7 @@ export class Kaba // devtool (source maps) devtool: cliConfig.debug - ? "eval" + ? "inline-cheap-source-map" : "hidden-source-map", // context @@ -413,23 +401,39 @@ export class Kaba options: { babelrc: false, presets: [ - isModule ? kabaBabelPreset.module : kabaBabelPreset.legacy, + ["@babel/preset-env", { + useBuiltIns: "entry", + corejs: 3, + targets: isModule ? browserslistConfig.modern : browserslistConfig.legacy, + }], ], }, }; - let fileNamePattern = this.hashFileNames ? '[name].[chunkhash].js' : '[name].js'; + let entries = this.jsEntries; if (!isModule) { - fileNamePattern = fileNamePattern.replace(".js", ".legacy.js"); + entries = {}; + Object.keys(this.jsEntries).forEach( + entry => + { + entries[`_legacy.${entry}`] = this.jsEntries[entry]; + } + ); } + let typeScriptConfig = path.join( + this.libRoot, + "configs", + isModule + ? "tsconfig.modern.json" + : "tsconfig.legacy.json" + ); + let config = { - // output - output: { - filename: fileNamePattern, - }, + // entry + entry: entries, // module module: { @@ -443,7 +447,7 @@ export class Kaba loader: "ts-loader", options: { context: this.cwd, - configFile: this.customTypeScriptConfig || path.join(this.libRoot, "configs/tsconfig.json"), + configFile: typeScriptConfig, errorFormatter: (message, colors) => typeScriptErrorFormatter(message, colors, this.cwd), }, }, @@ -463,6 +467,13 @@ export class Kaba }, ], }, + + // plugins + plugins: [ + new DefinePlugin({ + 'process.env.MODERN_BUILD': isModule, + }), + ], }; if (cliConfig.lint || cliConfig.fix) diff --git a/src/runner/WebpackRunner.ts b/src/runner/WebpackRunner.ts index 2f15776..32aabfd 100644 --- a/src/runner/WebpackRunner.ts +++ b/src/runner/WebpackRunner.ts @@ -1,10 +1,10 @@ +import MultiStats = webpack.compilation.MultiStats; const fs = require("fs-extra"); -import {bgCyan, black, yellow} from "kleur"; +import {bgCyan, black, yellow, cyan} from "kleur"; import * as webpack from "webpack"; import {kaba} from "../@types/kaba"; import {Logger} from "../Logger"; const path = require("path"); -const deepExtend = require("deep-extend"); export class WebpackRunner @@ -40,58 +40,50 @@ export class WebpackRunner this.logger.log("Launching webpack..."); const start = process.hrtime(); - if (this.buildConfig.js.customTypeScriptConfig) - { - this.logger.log(`Using custom TypeScript config: ${yellow(path.relative(this.buildConfig.cwd, this.buildConfig.js.customTypeScriptConfig))}`); - } - if (this.buildConfig.js.common.watch) { this.resolveCallback = resolve; } - let compilerLegacy = webpack(deepExtend( + + let configLegacy = Object.assign( {}, this.buildConfig.js.common, this.buildConfig.js.legacy, - )); + { + plugins: (this.buildConfig.js.common.plugins as any[]).concat(this.buildConfig.js.legacy.plugins), + name: "legacy", + } + ); - let compilerModule = webpack(deepExtend( + let configModule = Object.assign( {}, this.buildConfig.js.common, this.buildConfig.js.module, - )); + { + plugins: (this.buildConfig.js.common.plugins as any[]).concat(this.buildConfig.js.module.plugins), + name: "module", + } + ); + let compiler = webpack([configLegacy, configModule]) as webpack.MultiCompiler; if (this.buildConfig.js.common.watch) { this.resolveCallback = resolve; this.watchers.push( - compilerLegacy.watch( - {}, - (error, stats) => this.onCompilationFinished(error, stats, false) - ) - ); - this.watchers.push( - compilerModule.watch( + compiler.watch( {}, - (error, stats) => this.onCompilationFinished(error, stats, true) + (error, stats) => this.onCompilationFinished(error, (stats as unknown) as MultiStats) ) ); } else { - compilerLegacy.run( + compiler.run( (error, stats) => { - resolve(this.onCompilationFinished(error, stats, false, start)); - this.logger.logBuildSuccess("(all files)", process.hrtime(start)); - } - ); - - compilerModule.run( - (error, stats) => { - resolve(this.onCompilationFinished(error, stats, true, start)); + resolve(this.onCompilationFinished(error, (stats as unknown) as MultiStats, start)); this.logger.logBuildSuccess("(all files)", process.hrtime(start)); } ); @@ -104,7 +96,7 @@ export class WebpackRunner /** * Callback on after the compilation has finished */ - private onCompilationFinished (error: Error|null, stats: webpack.Stats, isModule: boolean, start?: [number, number]) : boolean + private onCompilationFinished (error: Error|null, stats: MultiStats, start?: [number, number]) : boolean { if (error) { @@ -114,15 +106,23 @@ export class WebpackRunner } // log webpack output - console.log(stats.toString({ - colors: true, - })); - console.log(""); + stats.stats.forEach( + singleStats => + { + console.log(""); + let type = singleStats.compilation.compiler.options.name as string; + console.log(`${bgCyan(black(" webpack "))} ${cyan(type)}`); + console.log(singleStats.toString({ + colors: true, + })); + } + ); + console.log(""); // write dependencies file - this.writeDependenciesFile(stats, isModule); + this.writeDependenciesFile(stats); - return !stats.hasErrors(); + return !stats.stats.some(single => single.hasErrors()); } @@ -145,12 +145,8 @@ export class WebpackRunner /** * Writes the entry dependencies file - * - * @private - * @param {Stats} stats - * @param {boolean} isModule */ - writeDependenciesFile (stats, isModule) + private writeDependenciesFile (stats: MultiStats) : void { if (!this.buildConfig.js) { @@ -159,23 +155,29 @@ export class WebpackRunner const entrypoints = {}; - for (const mapEntry of stats.compilation.entrypoints.entries()) - { - const entry = mapEntry[1]; - entrypoints[entry.name] = entry.chunks.reduce( - (files, chunk) => { - return files.concat(chunk.files); - }, - [] - ); - } + stats.stats.forEach( + singleStats => + { + for (const mapEntry of singleStats.compilation.entrypoints.entries()) + { + const entry = mapEntry[1]; + entrypoints[entry.name] = entry.chunks.reduce( + (files, chunk) => { + return files.concat(chunk.files); + }, + [] + ); + } + } + ); + let outputPath = (this.buildConfig.js.common.output as webpack.Output).path as string; // ensure that output path exists fs.ensureDirSync(outputPath); - const fileName = `${this.buildConfig.js.javaScriptDependenciesFileName}${isModule ? ".module" : ""}.json`; + const fileName = `${this.buildConfig.js.javaScriptDependenciesFileName}.json`; fs.writeFileSync( path.join(outputPath, fileName), JSON.stringify(entrypoints), From 9c791040055edc7a5fac3e7e832f84be54ebe66d Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 20:46:46 +0200 Subject: [PATCH 18/33] Update packages --- package.json | 6 ++---- src/Kaba.ts | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index be5386a..405eb71 100644 --- a/package.json +++ b/package.json @@ -24,17 +24,15 @@ "@becklyn/typescript-error-formatter": "^1.0.4", "babel-eslint": "^10.0.2", "babel-loader": "^8.0.2", - "clean-webpack-plugin": "^3.0.0", "core-js": "^3.1.4", - "eslint": "^5.5.0", + "eslint": "^6.0.1", "eslint-loader": "^2.1.0", "eslint-plugin-react": "^7.14.2", - "fork-ts-checker-webpack-plugin": "^1.3.7", "fs-extra": "^8.0.0", "kaba-babel-preset": "^3.0.1", "kleur": "^3.0.3", "pretty-hrtime": "^1.0.3", - "raw-loader": "^2.0.0", + "raw-loader": "^3.0.0", "sade": "^1.6.0", "terser-webpack-plugin": "^1.0.2", "ts-loader": "^6.0.4", diff --git a/src/Kaba.ts b/src/Kaba.ts index 12e50f7..6602e4b 100644 --- a/src/Kaba.ts +++ b/src/Kaba.ts @@ -401,11 +401,7 @@ export class Kaba options: { babelrc: false, presets: [ - ["@babel/preset-env", { - useBuiltIns: "entry", - corejs: 3, - targets: isModule ? browserslistConfig.modern : browserslistConfig.legacy, - }], + ["kaba-babel-preset"], ], }, }; From dbfc0cb48f93cd1873123a287a145b102388ab9f Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 27 Jun 2019 21:01:55 +0200 Subject: [PATCH 19/33] Use the right preset per build env --- package.json | 3 +-- src/Kaba.ts | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 405eb71..42e0732 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ }, "dependencies": { "@babel/core": "^7.0.0", - "@becklyn/browserslist-config": "^2.1.0", "@becklyn/typescript-error-formatter": "^1.0.4", "babel-eslint": "^10.0.2", "babel-loader": "^8.0.2", @@ -29,7 +28,7 @@ "eslint-loader": "^2.1.0", "eslint-plugin-react": "^7.14.2", "fs-extra": "^8.0.0", - "kaba-babel-preset": "^3.0.1", + "kaba-babel-preset": "^4.0.0", "kleur": "^3.0.3", "pretty-hrtime": "^1.0.3", "raw-loader": "^3.0.0", diff --git a/src/Kaba.ts b/src/Kaba.ts index 6602e4b..03cfaed 100644 --- a/src/Kaba.ts +++ b/src/Kaba.ts @@ -1,5 +1,4 @@ import {blue, red, yellow} from "kleur"; -const fs = require("fs-extra"); const path = require("path"); import * as webpack from "webpack"; import {DefinePlugin, ProvidePlugin} from "webpack"; @@ -7,7 +6,7 @@ const TerserPlugin = require('terser-webpack-plugin'); const typeScriptErrorFormatter = require("@becklyn/typescript-error-formatter"); import {kaba} from "./@types/kaba"; import CliConfig = kaba.CliConfig; -const browserslistConfig = require("@becklyn/browserslist-config/envs"); +const kabaBabelPreset = require("kaba-babel-preset"); interface Entries @@ -401,7 +400,7 @@ export class Kaba options: { babelrc: false, presets: [ - ["kaba-babel-preset"], + [isModule ? kabaBabelPreset.modern : kabaBabelPreset.legacy], ], }, }; From 9dbd9c71838bacb27ed504b519bb61b6b625a210 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 10:17:19 +0200 Subject: [PATCH 20/33] Use newer kaba-babel-preset --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 42e0732..9653a62 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "eslint-loader": "^2.1.0", "eslint-plugin-react": "^7.14.2", "fs-extra": "^8.0.0", - "kaba-babel-preset": "^4.0.0", + "kaba-babel-preset": "^4.0.1", "kleur": "^3.0.3", "pretty-hrtime": "^1.0.3", "raw-loader": "^3.0.0", From 0e39f94a10b0e116b509b580373e6179462b9ee2 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:15:23 +0200 Subject: [PATCH 21/33] Fix exports --- bin/run.ts | 2 +- src/Kaba.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/run.ts b/bin/run.ts index 715f3e6..4c61c04 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import {kaba} from "../src/@types/kaba"; -import Kaba from "../src/Kaba"; +import {Kaba} from "../src/Kaba"; import {Logger} from "../src/Logger"; const sade = require("sade"); import {bgYellow, black, blue, cyan, green, magenta, red, yellow} from "kleur"; diff --git a/src/Kaba.ts b/src/Kaba.ts index 03cfaed..23f2b11 100644 --- a/src/Kaba.ts +++ b/src/Kaba.ts @@ -490,5 +490,5 @@ export class Kaba } } - export default Kaba; +module.exports = Kaba; From 6ac10585d470bf6e97b04df24da1063b50e1b90a Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:15:35 +0200 Subject: [PATCH 22/33] Only add JS config if there actually entries --- src/Kaba.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Kaba.ts b/src/Kaba.ts index 23f2b11..af52017 100644 --- a/src/Kaba.ts +++ b/src/Kaba.ts @@ -228,6 +228,18 @@ export class Kaba */ public getBuildConfig (cliConfig: CliConfig): kaba.BuildConfig { + let jsConfig: any = null; + + if (Object.keys(this.jsEntries).length) + { + jsConfig = { + common: this.buildWebpackCommon(cliConfig), + module: this.buildWebpackConfig(cliConfig, true), + legacy: this.buildWebpackConfig(cliConfig, false), + javaScriptDependenciesFileName: this.javaScriptDependenciesFileName, + }; + } + return { sass: { entries: this.sassEntries, @@ -235,12 +247,7 @@ export class Kaba outputPath: path.join(this.outputPaths.base, this.outputPaths.css), cwd: this.cwd, }, - js: { - common: this.buildWebpackCommon(cliConfig), - module: this.buildWebpackConfig(cliConfig, true), - legacy: this.buildWebpackConfig(cliConfig, false), - javaScriptDependenciesFileName: this.javaScriptDependenciesFileName, - }, + js: jsConfig, cwd: this.cwd, }; } From e561b00cf79c765a4de15f39b320223d55b0e9e8 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:15:44 +0200 Subject: [PATCH 23/33] Use absolute paths in SassRunner --- src/runner/SassRunner.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runner/SassRunner.ts b/src/runner/SassRunner.ts index 8afcd25..7856d72 100644 --- a/src/runner/SassRunner.ts +++ b/src/runner/SassRunner.ts @@ -37,13 +37,18 @@ export class SassRunner // lazy load it as it is optional const {KabaScss} = require("kaba-scss"); - - this.compiler = new KabaScss(Object.assign({}, this.cliConfig, {cwd: this.buildConfig.cwd})); + this.compiler = new KabaScss({ + debug: this.cliConfig.debug, + watch: this.cliConfig.watch, + lint: this.cliConfig.lint, + fix: this.cliConfig.fix, + cwd: this.buildConfig.cwd, + }); entries.forEach( name => { - const src = this.buildConfig.entries[name]; + const src = path.join(this.buildConfig.cwd, this.buildConfig.entries[name]); const outputPath = `${this.buildConfig.outputPath}/${name}.css`; (this.compiler as KabaScss).addEntry(src, path.dirname(outputPath), path.basename(outputPath)); From ea4b387775ef71dc1713b09c9916bea0902035a3 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:25:10 +0200 Subject: [PATCH 24/33] Simplify conditional --- bin/run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run.ts b/bin/run.ts index 4c61c04..2603ca8 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -134,7 +134,7 @@ function runKaba (cliConfig: kaba.CliConfig, isVerbose: boolean) : void .then( ([scssOk, webpackOk]) => { - const failed = (false === scssOk || false === webpackOk); + const failed = !scssOk || !webpackOk; const status = failed ? red("failed") : green("succeeded"); From f28768626eabbe45fbd017847709e32f63caa476 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:25:25 +0200 Subject: [PATCH 25/33] Add return type --- src/runner/SassRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner/SassRunner.ts b/src/runner/SassRunner.ts index 7856d72..5101469 100644 --- a/src/runner/SassRunner.ts +++ b/src/runner/SassRunner.ts @@ -24,7 +24,7 @@ export class SassRunner * * @return {Promise} whether the build was successful and error-free */ - async run () + async run () : Promise { const entries = Object.keys(this.buildConfig.entries); From eb064897eba098c612c040b4329731e6b1b4eb31 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:25:34 +0200 Subject: [PATCH 26/33] Fix issue with never resolved promise --- src/runner/WebpackRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner/WebpackRunner.ts b/src/runner/WebpackRunner.ts index 32aabfd..f1d05f3 100644 --- a/src/runner/WebpackRunner.ts +++ b/src/runner/WebpackRunner.ts @@ -34,7 +34,7 @@ export class WebpackRunner { if (!this.buildConfig.js) { - return true; + return resolve(true); } this.logger.log("Launching webpack..."); From 9540a4a84552a1b816aa9ef37ea4d0404b5d3fbf Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:28:41 +0200 Subject: [PATCH 27/33] Try to debug CI failures --- tests/all_fixtures.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/all_fixtures.js b/tests/all_fixtures.js index c324a65..f23d613 100644 --- a/tests/all_fixtures.js +++ b/tests/all_fixtures.js @@ -47,6 +47,11 @@ Object.keys(fixtureTests).forEach(key => ? result.stdout.toString() : ""; + if (null === result.status && result.stdout) + { + console.log("Broke failed, details:", result.stdout.toString()); + } + t.is(result.status, expected.status); if (undefined !== expected.match) From 8fe9a2fe52142c5b6daaa9a709d07f5352b4b765 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:33:03 +0200 Subject: [PATCH 28/33] Try even more things to fix the build --- tests/all_fixtures.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/all_fixtures.js b/tests/all_fixtures.js index f23d613..c66d7ab 100644 --- a/tests/all_fixtures.js +++ b/tests/all_fixtures.js @@ -47,9 +47,13 @@ Object.keys(fixtureTests).forEach(key => ? result.stdout.toString() : ""; - if (null === result.status && result.stdout) + if (null === result.status) { - console.log("Broke failed, details:", result.stdout.toString()); + console.log("Broke failed, details:", + result.output.map( + out => out.toString ? out.toString() : out + ) + ); } t.is(result.status, expected.status); From d0dd4b59b8bbd13facf6d33854d7a364735e25bb Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 28 Jun 2019 11:38:35 +0200 Subject: [PATCH 29/33] Remove test debug --- tests/all_fixtures.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/all_fixtures.js b/tests/all_fixtures.js index c66d7ab..c324a65 100644 --- a/tests/all_fixtures.js +++ b/tests/all_fixtures.js @@ -47,15 +47,6 @@ Object.keys(fixtureTests).forEach(key => ? result.stdout.toString() : ""; - if (null === result.status) - { - console.log("Broke failed, details:", - result.output.map( - out => out.toString ? out.toString() : out - ) - ); - } - t.is(result.status, expected.status); if (undefined !== expected.match) From c8cd808d84d663db534acdba9e4e547ba3e25986 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Fri, 28 Jun 2019 11:58:12 +0200 Subject: [PATCH 30/33] Add visibility modifiers and return type --- src/runner/SassRunner.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runner/SassRunner.ts b/src/runner/SassRunner.ts index 5101469..d48a25c 100644 --- a/src/runner/SassRunner.ts +++ b/src/runner/SassRunner.ts @@ -12,7 +12,7 @@ export class SassRunner /** * Constructs a new runner */ - constructor (fullBuildConfig: kaba.BuildConfig, cliConfig: kaba.CliConfig) + public constructor (fullBuildConfig: kaba.BuildConfig, cliConfig: kaba.CliConfig) { this.buildConfig = fullBuildConfig.sass; this.cliConfig = cliConfig; @@ -24,7 +24,7 @@ export class SassRunner * * @return {Promise} whether the build was successful and error-free */ - async run () : Promise + async public run () : Promise { const entries = Object.keys(this.buildConfig.entries); @@ -62,7 +62,7 @@ export class SassRunner /** * Stops the runner */ - stop () + public stop () : void { if (this.compiler) { From ea2fde96eacf0aafb641a7459ad4ad1b91a1aafe Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Fri, 28 Jun 2019 11:58:56 +0200 Subject: [PATCH 31/33] CS --- src/runner/WebpackRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner/WebpackRunner.ts b/src/runner/WebpackRunner.ts index f1d05f3..478a76c 100644 --- a/src/runner/WebpackRunner.ts +++ b/src/runner/WebpackRunner.ts @@ -27,7 +27,7 @@ export class WebpackRunner /** * Runs the actual runner */ - public async run (): Promise + async public run (): Promise { return new Promise( (resolve) => From 2cb0124bf47a7867dd8c84b6e328e546c1959c7f Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Fri, 28 Jun 2019 12:01:11 +0200 Subject: [PATCH 32/33] CS --- src/runner/SassRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner/SassRunner.ts b/src/runner/SassRunner.ts index d48a25c..f261b10 100644 --- a/src/runner/SassRunner.ts +++ b/src/runner/SassRunner.ts @@ -24,7 +24,7 @@ export class SassRunner * * @return {Promise} whether the build was successful and error-free */ - async public run () : Promise + public async run () : Promise { const entries = Object.keys(this.buildConfig.entries); From 99d2fbe0799aada3f8e0baaca5e83abf8c63ff3d Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Fri, 28 Jun 2019 12:01:27 +0200 Subject: [PATCH 33/33] Update WebpackRunner.ts --- src/runner/WebpackRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner/WebpackRunner.ts b/src/runner/WebpackRunner.ts index 478a76c..f1d05f3 100644 --- a/src/runner/WebpackRunner.ts +++ b/src/runner/WebpackRunner.ts @@ -27,7 +27,7 @@ export class WebpackRunner /** * Runs the actual runner */ - async public run (): Promise + public async run (): Promise { return new Promise( (resolve) =>