@storm-software/esbuild
Version:
A package containing `esbuild` utilities for building Storm Software libraries and applications
126 lines (123 loc) • 3.65 kB
JavaScript
import {
depsCheckPlugin
} from "./chunk-J23YJYET.js";
import {
copyBuildAssets
} from "./chunk-OHC4AOQG.js";
import {
cleanDirectories
} from "./chunk-YYB2TDMT.js";
import {
resolveContext
} from "./chunk-WMU243HH.js";
import {
generatePackageJson
} from "./chunk-VREJONM4.js";
import {
executeTsup
} from "./chunk-OVF7EMMD.js";
import {
getStopwatch,
writeDebug,
writeError,
writeFatal,
writeSuccess,
writeWarning
} from "./chunk-S4OFPSFS.js";
import {
init_esm_shims
} from "./chunk-GL7N7ANS.js";
// src/build.ts
init_esm_shims();
import * as esbuild from "esbuild";
import { globbySync } from "globby";
async function reportResults(context) {
if (context.result?.errors.length === 0) {
if (context.result.warnings.length > 0) {
writeWarning(
` \u{1F6A7} The following warnings occurred during the build: ${context.result.warnings.map((warning) => warning.text).join("\n")}`,
context.workspaceConfig
);
}
writeSuccess(
` \u{1F4E6} The ${context.options.name} build completed successfully`,
context.workspaceConfig
);
} else if (context.result?.errors && context.result?.errors.length > 0) {
writeError(
` \u274C The ${context.options.name} build failed with the following errors: ${context.result.errors.map((error) => error.text).join("\n")}`,
context.workspaceConfig
);
throw new Error(
`The ${context.options.name} build failed with the following errors: ${context.result.errors.map((error) => error.text).join("\n")}`
);
}
}
async function dependencyCheck(options) {
if (process.env.DEV === "true") {
return void 0;
}
if (process.env.CI && !process.env.BUILDKITE) {
return void 0;
}
const buildPromise = esbuild.build({
entryPoints: globbySync("**/*.{j,t}s", {
// We don't check dependencies in ecosystem tests because tests are isolated from the build.
ignore: ["./src/__tests__/**/*", "./tests/e2e/**/*", "./dist/**/*"],
gitignore: true
}),
logLevel: "silent",
// there will be errors
bundle: true,
// we bundle to get everything
write: false,
// no need to write for analysis
outdir: "out",
plugins: [depsCheckPlugin(options.bundle)]
});
await buildPromise.catch(() => {
});
return void 0;
}
async function cleanOutputPath(context) {
if (context.clean !== false && context.outputPath) {
writeDebug(
` \u{1F9F9} Cleaning ${context.options.name} output path: ${context.outputPath}`,
context.workspaceConfig
);
const stopwatch = getStopwatch(`${context.options.name} output clean`);
await cleanDirectories(context.outputPath);
stopwatch();
}
return context;
}
async function build2(options) {
writeDebug(` \u26A1 Executing Storm ESBuild pipeline`);
const stopwatch = getStopwatch("ESBuild pipeline");
try {
const opts = Array.isArray(options) ? options : [options];
if (opts.length === 0) {
throw new Error("No build options were provided");
}
const context = await resolveContext(options);
await cleanOutputPath(context);
await Promise.all([
dependencyCheck(context.options),
generatePackageJson(context),
copyBuildAssets(context),
executeTsup(context)
]);
await reportResults(context);
writeSuccess(" \u{1F3C1} ESBuild pipeline build completed successfully");
} catch (error) {
writeFatal(
"Fatal errors that the build process could not recover from have occured. The build process has been terminated."
);
throw error;
} finally {
stopwatch();
}
}
export {
build2 as build
};