Skip to content

Commit

Permalink
chore: fix build script
Browse files Browse the repository at this point in the history
I was a bit too quick in 66a0027
  • Loading branch information
SimenB committed Oct 2, 2023
1 parent 66a0027 commit 46285d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
21 changes: 16 additions & 5 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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`,
Expand Down
13 changes: 5 additions & 8 deletions scripts/buildUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const copyrightSnippet = `
*/
`.trim();

function createWebpackConfigs() {
export function createBuildConfigs() {
const packages = getPackages();

return packages.map(({packageDir, pkg}) => {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions scripts/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 46285d8

Please sign in to comment.