mirror of
https://github.com/hanzoai/jest.git
synced 2026-09-24 16:59:57 +00:00
+16
-5
@@ -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`,
|
||||
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user