From 46285d8bd27e1fd798903dc1b46e4b095af1a959 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 2 Oct 2023 14:16:29 +0200 Subject: [PATCH] chore: fix build script I was a bit too quick in 66a002771cb69ca8f800301e75c6b133e91d803a --- scripts/build.mjs | 21 ++++++++++++++++----- scripts/buildUtils.mjs | 13 +++++-------- scripts/watch.mjs | 7 ++++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index d38e8eab2f94..ddcf5a21b72a 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -10,12 +10,20 @@ import * as path from 'path'; import util from 'util'; import chalk from 'chalk'; import fs from 'graceful-fs'; -import {ERROR, OK, createWebpackCompiler} from './buildUtils.mjs'; +import webpack from 'webpack'; +import { + ERROR, + OK, + createBuildConfigs, + createWebpackConfigs, +} from './buildUtils.mjs'; async function buildNodePackages() { process.stdout.write(chalk.inverse(' Bundling packages \n')); - const compiler = createWebpackCompiler(); + const buildConfigs = createBuildConfigs(); + + const compiler = webpack(createWebpackConfigs(buildConfigs)); let stats; try { @@ -29,15 +37,18 @@ async function buildNodePackages() { if (stats) { const info = stats.toJson(); - if (stats.hasErrors()) { - console.error('errors', info.errors); + for (const error of info.errors) { + console.error('error', error.message); + } + for (const warning of info.warnings) { + console.warn('warning', warning.message); } } throw error; } - for (const {packageDir, pkg} of webpackConfigs) { + for (const {packageDir, pkg} of buildConfigs) { assert.ok( fs.existsSync(path.resolve(packageDir, pkg.main)), `Main file "${pkg.main}" in "${pkg.name}" should exist`, diff --git a/scripts/buildUtils.mjs b/scripts/buildUtils.mjs index 9140a8b1247a..038dcfa83fda 100644 --- a/scripts/buildUtils.mjs +++ b/scripts/buildUtils.mjs @@ -146,7 +146,7 @@ export const copyrightSnippet = ` */ `.trim(); -function createWebpackConfigs() { +export function createBuildConfigs() { const packages = getPackages(); return packages.map(({packageDir, pkg}) => { @@ -292,13 +292,10 @@ function createWebpackConfigs() { }); } -export function createWebpackCompiler() { - const webpackConfigs = createWebpackConfigs(); - return webpack( - webpackConfigs - .map(({webpackConfig}) => webpackConfig) - .filter(config => config != null), - ); +export function createWebpackConfigs(webpackConfigs = createBuildConfigs()) { + return webpackConfigs + .map(({webpackConfig}) => webpackConfig) + .filter(config => config != null); } // inspired by https://framagit.org/Glandos/webpack-ignore-dynamic-require diff --git a/scripts/watch.mjs b/scripts/watch.mjs index a3e40bfd4229..15900562c028 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -10,13 +10,14 @@ */ import chalk from 'chalk'; -import {createWebpackCompiler} from './buildUtils.mjs'; +import webpack from 'webpack'; +import {createWebpackConfigs} from './buildUtils.mjs'; -const compiler = createWebpackCompiler(); +const compiler = webpack(createWebpackConfigs()); let hasBuilt = false; -console.log(chalk.cyan('Building packages…')); +console.log(chalk.inverse(' Bundling packages ')); compiler.watch({}, (error, stats) => { if (!hasBuilt) {