@storm-software/esbuild
Version:
A package containing `esbuild` utilities for building Storm Software libraries and applications
126 lines (101 loc) • 5.25 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkCBRUGQFQcjs = require('./chunk-CBRUGQFQ.cjs');
var _chunkPHUOQP5Fcjs = require('./chunk-PHUOQP5F.cjs');
var _chunkVYYRT4J4cjs = require('./chunk-VYYRT4J4.cjs');
var _chunkNXN35NZ7cjs = require('./chunk-NXN35NZ7.cjs');
var _chunkP3LL3C3Vcjs = require('./chunk-P3LL3C3V.cjs');
var _chunkY2WVY5RScjs = require('./chunk-Y2WVY5RS.cjs');
var _chunkDMCSA7GDcjs = require('./chunk-DMCSA7GD.cjs');
var _chunk4ICWACJMcjs = require('./chunk-4ICWACJM.cjs');
// src/build.ts
_chunk4ICWACJMcjs.init_cjs_shims.call(void 0, );
var _esbuild = require('esbuild'); var esbuild = _interopRequireWildcard(_esbuild);
var _globby = require('globby');
async function reportResults(context) {
if (_optionalChain([context, 'access', _ => _.result, 'optionalAccess', _2 => _2.errors, 'access', _3 => _3.length]) === 0) {
if (context.result.warnings.length > 0) {
_chunkDMCSA7GDcjs.writeWarning.call(void 0,
` \u{1F6A7} The following warnings occurred during the build: ${context.result.warnings.map((warning) => warning.text).join("\n")}`,
context.workspaceConfig
);
}
_chunkDMCSA7GDcjs.writeSuccess.call(void 0,
` \u{1F4E6} The ${context.options.name} build completed successfully`,
context.workspaceConfig
);
} else if (_optionalChain([context, 'access', _4 => _4.result, 'optionalAccess', _5 => _5.errors]) && _optionalChain([context, 'access', _6 => _6.result, 'optionalAccess', _7 => _7.errors, 'access', _8 => _8.length]) > 0) {
_chunkDMCSA7GDcjs.writeError.call(void 0,
` \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: _globby.globbySync.call(void 0, "**/*.{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: [_chunkCBRUGQFQcjs.depsCheckPlugin.call(void 0, options.bundle)]
});
await buildPromise.catch(() => {
});
return void 0;
}
async function cleanOutputPath(context) {
if (context.clean !== false && context.outputPath) {
_chunkDMCSA7GDcjs.writeDebug.call(void 0,
` \u{1F9F9} Cleaning ${context.options.name} output path: ${context.outputPath}`,
context.workspaceConfig
);
const stopwatch = _chunkDMCSA7GDcjs.getStopwatch.call(void 0, `${context.options.name} output clean`);
await _chunkVYYRT4J4cjs.cleanDirectories.call(void 0, context.outputPath);
stopwatch();
}
return context;
}
async function build2(options) {
_chunkDMCSA7GDcjs.writeDebug.call(void 0, ` \u26A1 Executing Storm ESBuild pipeline`);
const stopwatch = _chunkDMCSA7GDcjs.getStopwatch.call(void 0, "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 _chunkNXN35NZ7cjs.resolveContext.call(void 0, options);
await cleanOutputPath(context);
await Promise.all([
dependencyCheck(context.options),
_chunkP3LL3C3Vcjs.generatePackageJson.call(void 0, context),
_chunkPHUOQP5Fcjs.copyBuildAssets.call(void 0, context),
_chunkY2WVY5RScjs.executeTsup.call(void 0, context)
]);
await reportResults(context);
_chunkDMCSA7GDcjs.writeSuccess.call(void 0, " \u{1F3C1} ESBuild pipeline build completed successfully");
} catch (error) {
_chunkDMCSA7GDcjs.writeFatal.call(void 0,
"Fatal errors that the build process could not recover from have occured. The build process has been terminated."
);
throw error;
} finally {
stopwatch();
}
}
exports.build = build2;