chore: fix build script

I was a bit too quick in ee21efd1d4
This commit is contained in:
Simen Bekkhus
2023-10-02 14:16:29 +02:00
parent ee21efd1d4
commit 9fb0ec03cc
3 changed files with 25 additions and 16 deletions
+16 -5
View File
@@ -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`,
+5 -8
View File
@@ -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
+4 -3
View File
@@ -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) {