@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
834 lines (760 loc) • 33 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 _chunk4PG3MS76js = require('./chunk-4PG3MS76.js');
var _chunkVWERGJQ6js = require('./chunk-VWERGJQ6.js');
var _chunkK7STHRGHjs = require('./chunk-K7STHRGH.js');
var _chunk4WHSR4FKjs = require('./chunk-4WHSR4FK.js');
var _chunk53DNHF7Bjs = require('./chunk-53DNHF7B.js');
var _chunk3RG5ZIWIjs = require('./chunk-3RG5ZIWI.js');
// ../esbuild/src/build.ts
var _esbuild = require('esbuild'); var esbuild = _interopRequireWildcard(_esbuild);
var _globby = require('globby');
// ../build-tools/src/config.ts
var DEFAULT_COMPILED_BANNER = `/*****************************************
*
* \u26A1 Built by Storm Software
*
*****************************************/
`;
var DEFAULT_ENVIRONMENT = "production";
var DEFAULT_ORGANIZATION = "storm-software";
// ../build-tools/src/plugins/swc.ts
var _core = require('@swc/core');
// ../build-tools/src/plugins/ts-resolve.ts
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
var _module = require('module');
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
var _resolve2 = require('resolve'); var _resolve3 = _interopRequireDefault(_resolve2);
// ../build-tools/src/plugins/type-definitions.ts
var _devkit = require('@nx/devkit');
// ../build-tools/src/utilities/copy-assets.ts
var _copyassetshandler = require('@nx/js/src/utils/assets/copy-assets-handler');
var _glob = require('glob');
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
var copyAssets = async (config, assets, outputPath, projectRoot, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
const pendingAssets = Array.from(_nullishCoalesce(assets, () => ( [])));
pendingAssets.push({
input: projectRoot,
glob: "*.md",
output: "."
});
pendingAssets.push({
input: ".",
glob: "LICENSE",
output: "."
});
if (generatePackageJson2 === false) {
pendingAssets.push({
input: projectRoot,
glob: "package.json",
output: "."
});
}
if (includeSrc === true) {
pendingAssets.push({
input: sourceRoot,
glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
output: "src/"
});
}
_chunkK7STHRGHjs.writeTrace.call(void 0,
`\u{1F4DD} Copying the following assets to the output directory:
${pendingAssets.map((pendingAsset) => typeof pendingAsset === "string" ? ` - ${pendingAsset} -> ${outputPath}` : ` - ${pendingAsset.input}/${pendingAsset.glob} -> ${_chunk53DNHF7Bjs.joinPaths.call(void 0, outputPath, pendingAsset.output)}`).join("\n")}`,
config
);
const assetHandler = new (0, _copyassetshandler.CopyAssetsHandler)({
projectDir: projectRoot,
rootDir: config.workspaceRoot,
outputDir: outputPath,
assets: pendingAssets
});
await assetHandler.processAllAssetsOnce();
if (includeSrc === true) {
_chunkK7STHRGHjs.writeDebug.call(void 0,
`\u{1F4DD} Adding banner and writing source files: ${_chunk53DNHF7Bjs.joinPaths.call(void 0,
outputPath,
"src"
)}`,
config
);
const files = await _glob.glob.call(void 0, [
_chunk53DNHF7Bjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.ts"),
_chunk53DNHF7Bjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.tsx"),
_chunk53DNHF7Bjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.js"),
_chunk53DNHF7Bjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.jsx")
]);
await Promise.allSettled(
files.map(
async (file) => _promises.writeFile.call(void 0,
file,
`${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
${await _promises.readFile.call(void 0, file, "utf8")}
${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`
)
)
);
}
};
// ../build-tools/src/utilities/generate-package-json.ts
var _buildablelibsutils = require('@nx/js/src/utils/buildable-libs-utils');
var _projectgraph = require('nx/src/project-graph/project-graph');
var addPackageDependencies = async (workspaceRoot, projectRoot, projectName, packageJson) => {
let projectGraph;
try {
projectGraph = _projectgraph.readCachedProjectGraph.call(void 0, );
} catch (e) {
await _projectgraph.createProjectGraphAsync.call(void 0, );
projectGraph = _projectgraph.readCachedProjectGraph.call(void 0, );
}
if (!projectGraph) {
throw new Error(
"The Build process failed because the project graph is not available. Please run the build command again."
);
}
const projectDependencies = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0,
void 0,
projectGraph,
workspaceRoot,
projectName,
process.env.NX_TASK_TARGET_TARGET || "build",
process.env.NX_TASK_TARGET_CONFIGURATION || "production",
true
);
const localPackages = [];
for (const project of projectDependencies.dependencies.filter(
(dep) => dep.node.type === "lib" && _optionalChain([dep, 'access', _ => _.node, 'access', _2 => _2.data, 'optionalAccess', _3 => _3.root]) !== projectRoot && _optionalChain([dep, 'access', _4 => _4.node, 'access', _5 => _5.data, 'optionalAccess', _6 => _6.root]) !== workspaceRoot
)) {
const projectNode = project.node;
if (projectNode.data.root) {
const projectPackageJsonPath = _chunk53DNHF7Bjs.joinPaths.call(void 0,
workspaceRoot,
projectNode.data.root,
"package.json"
);
if (_fs.existsSync.call(void 0, projectPackageJsonPath)) {
const projectPackageJsonContent = await _promises.readFile.call(void 0,
projectPackageJsonPath,
"utf8"
);
const projectPackageJson = JSON.parse(projectPackageJsonContent);
if (projectPackageJson.private !== true) {
localPackages.push(projectPackageJson);
}
}
}
}
if (localPackages.length > 0) {
_chunkK7STHRGHjs.writeTrace.call(void 0,
`\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`
);
const projectJsonFile = await _promises.readFile.call(void 0,
_chunk53DNHF7Bjs.joinPaths.call(void 0, projectRoot, "project.json"),
"utf8"
);
const projectJson = JSON.parse(projectJsonFile);
const projectName2 = projectJson.name;
const projectConfigurations = _projectgraph.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
if (!_optionalChain([projectConfigurations, 'optionalAccess', _7 => _7.projects, 'optionalAccess', _8 => _8[projectName2]])) {
throw new Error(
"The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project."
);
}
const implicitDependencies = _optionalChain([projectConfigurations, 'access', _9 => _9.projects, 'optionalAccess', _10 => _10[projectName2], 'access', _11 => _11.implicitDependencies, 'optionalAccess', _12 => _12.reduce, 'call', _13 => _13((ret, dep) => {
if (_optionalChain([projectConfigurations, 'access', _14 => _14.projects, 'optionalAccess', _15 => _15[dep]])) {
const depPackageJsonPath = _chunk53DNHF7Bjs.joinPaths.call(void 0,
workspaceRoot,
projectConfigurations.projects[dep].root,
"package.json"
);
if (_fs.existsSync.call(void 0, depPackageJsonPath)) {
const depPackageJsonContent = _fs.readFileSync.call(void 0,
depPackageJsonPath,
"utf8"
);
const depPackageJson = JSON.parse(depPackageJsonContent);
if (depPackageJson.private !== true && !ret.includes(depPackageJson.name)) {
ret.push(depPackageJson.name);
}
}
}
return ret;
}, [])]);
packageJson.dependencies = localPackages.reduce((ret, localPackage) => {
if (!ret[localPackage.name] && !_optionalChain([implicitDependencies, 'optionalAccess', _16 => _16.includes, 'call', _17 => _17(localPackage.name)]) && _optionalChain([packageJson, 'access', _18 => _18.devDependencies, 'optionalAccess', _19 => _19[localPackage.name]]) === void 0) {
ret[localPackage.name] = `^${localPackage.version || "0.0.1"}`;
}
return ret;
}, _nullishCoalesce(packageJson.dependencies, () => ( {})));
packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
if (!ret[localPackage.name] && _optionalChain([implicitDependencies, 'optionalAccess', _20 => _20.includes, 'call', _21 => _21(localPackage.name)]) && _optionalChain([packageJson, 'access', _22 => _22.dependencies, 'optionalAccess', _23 => _23[localPackage.name]]) === void 0) {
ret[localPackage.name] = `^${localPackage.version || "0.0.1"}`;
}
return ret;
}, _nullishCoalesce(packageJson.devDependencies, () => ( {})));
} else {
_chunkK7STHRGHjs.writeTrace.call(void 0, "\u{1F4E6} No local packages dependencies to add to package.json");
}
return packageJson;
};
var addWorkspacePackageJsonFields = async (workspaceConfig, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
const workspaceRoot = workspaceConfig.workspaceRoot ? workspaceConfig.workspaceRoot : _chunk4WHSR4FKjs.findWorkspaceRoot.call(void 0, );
const workspacePackageJsonContent = await _promises.readFile.call(void 0,
_chunk53DNHF7Bjs.joinPaths.call(void 0, workspaceRoot, "package.json"),
"utf8"
);
const workspacePackageJson = JSON.parse(workspacePackageJsonContent);
packageJson.type ??= "module";
packageJson.sideEffects ??= false;
if (includeSrc === true) {
let distSrc = sourceRoot.replace(projectRoot, "");
if (distSrc.startsWith("/")) {
distSrc = distSrc.substring(1);
}
packageJson.source ??= `${_chunk53DNHF7Bjs.joinPaths.call(void 0, distSrc, "index.ts").replaceAll("\\", "/")}`;
}
packageJson.files ??= ["dist/**/*"];
if (includeSrc === true && !packageJson.files.includes("src")) {
packageJson.files.push("src/**/*");
}
packageJson.publishConfig ??= {
access: "public"
};
packageJson.description ??= workspacePackageJson.description;
packageJson.homepage ??= workspacePackageJson.homepage;
packageJson.bugs ??= workspacePackageJson.bugs;
packageJson.license ??= workspacePackageJson.license;
packageJson.keywords ??= workspacePackageJson.keywords;
packageJson.funding ??= workspacePackageJson.funding;
packageJson.author ??= workspacePackageJson.author;
packageJson.maintainers ??= workspacePackageJson.maintainers;
if (!packageJson.maintainers && packageJson.author) {
packageJson.maintainers = [packageJson.author];
}
packageJson.contributors ??= workspacePackageJson.contributors;
if (!packageJson.contributors && packageJson.author) {
packageJson.contributors = [packageJson.author];
}
packageJson.repository ??= workspacePackageJson.repository;
packageJson.repository.directory ??= projectRoot ? projectRoot : _chunk53DNHF7Bjs.joinPaths.call(void 0, "packages", projectName);
return packageJson;
};
// ../build-tools/src/utilities/get-entry-points.ts
// ../build-tools/src/utilities/get-env.ts
var getEnv = (builder, options) => {
return {
STORM_BUILD: builder,
STORM_ORG: options.orgName || DEFAULT_ORGANIZATION,
STORM_NAME: options.name,
STORM_MODE: options.mode || DEFAULT_ENVIRONMENT,
STORM_PLATFORM: options.platform,
STORM_FORMAT: JSON.stringify(options.format),
STORM_TARGET: JSON.stringify(options.target),
...options.env
};
};
// ../build-tools/src/utilities/read-nx-config.ts
// ../build-tools/src/utilities/task-graph.ts
var _createtaskgraph = require('nx/src/tasks-runner/create-task-graph');
// ../esbuild/src/assets.ts
async function copyBuildAssets(context) {
if (!_optionalChain([context, 'access', _24 => _24.result, 'optionalAccess', _25 => _25.errors, 'access', _26 => _26.length]) && _optionalChain([context, 'access', _27 => _27.options, 'access', _28 => _28.assets, 'optionalAccess', _29 => _29.length])) {
_chunkK7STHRGHjs.writeDebug.call(void 0,
` \u{1F4CB} Copying ${context.options.assets.length} asset files to output directory: ${context.outputPath}`,
context.workspaceConfig
);
const stopwatch = _chunkK7STHRGHjs.getStopwatch.call(void 0, `${context.options.name} asset copy`);
await copyAssets(
context.workspaceConfig,
_nullishCoalesce(context.options.assets, () => ( [])),
context.outputPath,
context.options.projectRoot,
context.sourceRoot,
true,
false
);
stopwatch();
}
return context;
}
// ../esbuild/src/clean.ts
async function cleanDirectories(directory) {
await _promises.rm.call(void 0, directory, { recursive: true, force: true });
}
// ../esbuild/src/context.ts
var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);
var _findworkspaceroot = require('nx/src/utils/find-workspace-root');
// ../esbuild/src/config.ts
var DEFAULT_BUILD_OPTIONS = {
platform: "node",
target: "node22",
format: "esm",
mode: "production",
generatePackageJson: true,
includeSrc: false,
keepNames: true,
metafile: false,
treeshake: true,
splitting: true,
shims: false,
watch: false,
bundle: true,
distDir: "dist",
loader: {
".aac": "file",
".css": "file",
".eot": "file",
".flac": "file",
".gif": "file",
".jpeg": "file",
".jpg": "file",
".mp3": "file",
".mp4": "file",
".ogg": "file",
".otf": "file",
".png": "file",
".svg": "file",
".ttf": "file",
".wav": "file",
".webm": "file",
".webp": "file",
".woff": "file",
".woff2": "file"
},
banner: {
js: DEFAULT_COMPILED_BANNER,
css: DEFAULT_COMPILED_BANNER
}
};
// ../esbuild/src/context.ts
async function resolveContext(userOptions) {
const projectRoot = userOptions.projectRoot;
const workspaceRoot = _findworkspaceroot.findWorkspaceRoot.call(void 0, projectRoot);
if (!workspaceRoot) {
throw new Error("Cannot find Nx workspace root");
}
const workspaceConfig = await _chunkVWERGJQ6js.getWorkspaceConfig.call(void 0, true, {
workspaceRoot: workspaceRoot.dir
});
_chunkK7STHRGHjs.writeDebug.call(void 0, " \u2699\uFE0F Resolving build options", workspaceConfig);
const stopwatch = _chunkK7STHRGHjs.getStopwatch.call(void 0, "Build options resolution");
const projectGraph = await _devkit.createProjectGraphAsync.call(void 0, {
exitOnError: true
});
const projectJsonPath = _chunk53DNHF7Bjs.joinPaths.call(void 0,
workspaceRoot.dir,
projectRoot,
"project.json"
);
if (!_fs.existsSync.call(void 0, projectJsonPath)) {
throw new Error("Cannot find project.json configuration");
}
const projectJsonFile = await _promises2.default.readFile(projectJsonPath, "utf8");
const projectJson = JSON.parse(projectJsonFile);
const projectName = projectJson.name || userOptions.name;
const projectConfigurations = _devkit.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
if (!_optionalChain([projectConfigurations, 'optionalAccess', _30 => _30.projects, 'optionalAccess', _31 => _31[projectName]])) {
throw new Error(
"The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project."
);
}
const options = _defu2.default.call(void 0, userOptions, DEFAULT_BUILD_OPTIONS);
options.name ??= projectName;
const packageJsonPath = _chunk53DNHF7Bjs.joinPaths.call(void 0,
workspaceRoot.dir,
options.projectRoot,
"package.json"
);
if (!_fs.existsSync.call(void 0, packageJsonPath)) {
throw new Error("Cannot find package.json configuration");
}
const env = getEnv("esbuild", options);
const define = _defu2.default.call(void 0, _nullishCoalesce(options.define, () => ( {})), _nullishCoalesce(env, () => ( {})));
const resolvedOptions = {
...options,
tsconfig: userOptions.tsconfig === null ? void 0 : userOptions.tsconfig ? userOptions.tsconfig : _chunk53DNHF7Bjs.joinPaths.call(void 0, workspaceRoot.dir, projectRoot, "tsconfig.json"),
metafile: userOptions.mode === "development",
clean: false,
env,
define: {
STORM_FORMAT: JSON.stringify(options.format),
...Object.keys(define).filter((key) => define[key] !== void 0).reduce((res, key) => {
const value = JSON.stringify(define[key]);
const safeKey = key.replaceAll("(", "").replaceAll(")", "");
return {
...res,
[`process.env.${safeKey}`]: value,
[`import.meta.env.${safeKey}`]: value
};
}, {})
}
};
stopwatch();
const context = {
options: resolvedOptions,
clean: userOptions.clean !== false,
workspaceConfig,
projectConfigurations,
projectName,
projectGraph,
sourceRoot: resolvedOptions.sourceRoot || projectJson.sourceRoot || _chunk53DNHF7Bjs.joinPaths.call(void 0, resolvedOptions.projectRoot, "src"),
outputPath: resolvedOptions.outputPath || _chunk53DNHF7Bjs.joinPaths.call(void 0,
workspaceConfig.workspaceRoot,
"dist",
resolvedOptions.projectRoot
),
minify: resolvedOptions.minify || resolvedOptions.mode === "production"
};
context.options.esbuildPlugins = [..._nullishCoalesce(context.options.esbuildPlugins, () => ( []))];
if (context.options.verbose) {
_chunkK7STHRGHjs.writeDebug.call(void 0,
` \u2699\uFE0F Build options resolved:
${_chunkK7STHRGHjs.formatLogMessage.call(void 0, context.options)}`,
workspaceConfig
);
}
return context;
}
// ../esbuild/src/package-json.ts
async function generatePackageJson(context) {
if (context.options.generatePackageJson !== false && _fs.existsSync.call(void 0, _chunk53DNHF7Bjs.joinPaths.call(void 0, context.options.projectRoot, "package.json"))) {
_chunkK7STHRGHjs.writeDebug.call(void 0, " \u270D\uFE0F Writing package.json file", context.workspaceConfig);
const stopwatch = _chunkK7STHRGHjs.getStopwatch.call(void 0, "Write package.json file");
const packageJsonPath = _chunk53DNHF7Bjs.joinPaths.call(void 0,
context.options.projectRoot,
"project.json"
);
if (!_fs.existsSync.call(void 0, packageJsonPath)) {
throw new Error("Cannot find package.json configuration");
}
const packageJsonFile = await _promises2.default.readFile(
_chunk53DNHF7Bjs.joinPaths.call(void 0,
context.workspaceConfig.workspaceRoot,
context.options.projectRoot,
"package.json"
),
"utf8"
);
let packageJson = JSON.parse(packageJsonFile);
if (!packageJson) {
throw new Error("Cannot find package.json configuration file");
}
packageJson = await addPackageDependencies(
context.workspaceConfig.workspaceRoot,
context.options.projectRoot,
context.projectName,
packageJson
);
packageJson = await addWorkspacePackageJsonFields(
context.workspaceConfig,
context.options.projectRoot,
context.sourceRoot,
context.projectName,
false,
packageJson
);
if (context.options.entry) {
packageJson.exports ??= {};
packageJson.exports["./package.json"] ??= "./package.json";
const entryPoints = Array.isArray(context.options.entry) ? context.options.entry : Object.keys(context.options.entry);
if (entryPoints.length > 0) {
const defaultEntry = entryPoints.includes("index") ? `.${context.options.distDir ? `/${context.options.distDir}` : ""}/index` : `.${context.options.distDir ? `/${context.options.distDir}` : ""}/${entryPoints[0]}`;
const isEsm = Array.isArray(context.options.format) ? context.options.format.includes("esm") : context.options.format === "esm";
const isCjs = Array.isArray(context.options.format) ? context.options.format.includes("cjs") : context.options.format === "cjs";
const isDts = context.options.dts || context.options.experimentalDts;
packageJson.exports["."] ??= `${defaultEntry}.${isEsm ? "mjs" : isCjs ? "cjs" : "js"}`;
for (const entryPoint of entryPoints) {
packageJson.exports[`./${entryPoint}`] ??= {};
if (isEsm) {
if (isDts) {
packageJson.exports[`./${entryPoint}`].import = {
types: `./dist/${entryPoint}.d.mts`,
default: `./dist/${entryPoint}.mjs`
};
} else {
packageJson.exports[`./${entryPoint}`].import = `./dist/${entryPoint}.mjs`;
}
if (isDts) {
packageJson.exports[`./${entryPoint}`].default = {
types: `./dist/${entryPoint}.d.mts`,
default: `./dist/${entryPoint}.mjs`
};
} else {
packageJson.exports[`./${entryPoint}`].default = `./dist/${entryPoint}.mjs`;
}
}
if (isCjs) {
if (isDts) {
packageJson.exports[`./${entryPoint}`].require = {
types: `./dist/${entryPoint}.d.cts`,
default: `./dist/${entryPoint}.cjs`
};
} else {
packageJson.exports[`./${entryPoint}`].require = `./dist/${entryPoint}.cjs`;
}
if (!isEsm) {
if (isDts) {
packageJson.exports[`./${entryPoint}`].default = {
types: `./dist/${entryPoint}.d.cts`,
default: `./dist/${entryPoint}.cjs`
};
} else {
packageJson.exports[`./${entryPoint}`].default = `./dist/${entryPoint}.cjs`;
}
}
}
if (!isEsm && !isCjs) {
if (isDts) {
packageJson.exports[`./${entryPoint}`].default = {
types: `./dist/${entryPoint}.d.ts`,
default: `./dist/${entryPoint}.js`
};
} else {
packageJson.exports[`./${entryPoint}`].default = `./dist/${entryPoint}.js`;
}
}
}
if (isEsm) {
packageJson.module = `${defaultEntry}.mjs`;
} else {
packageJson.main = `${defaultEntry}.cjs`;
}
if (isDts) {
packageJson.types = `${defaultEntry}.d.${isEsm ? "mts" : isCjs ? "cts" : "ts"}`;
}
packageJson.exports = Object.keys(packageJson.exports).reduce(
(ret, key) => {
if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
ret[key.replace("/index", "")] = packageJson.exports[key];
}
return ret;
},
packageJson.exports
);
}
}
await _devkit.writeJsonFile.call(void 0,
_chunk53DNHF7Bjs.joinPaths.call(void 0, context.outputPath, "package.json"),
packageJson
);
stopwatch();
}
return context;
}
// ../esbuild/src/plugins/deps-check.ts
var unusedIgnore = [
// these are our dev dependencies
/@types\/.*?/,
/@typescript-eslint.*?/,
/eslint.*?/,
"esbuild",
"husky",
"is-ci",
"lint-staged",
"prettier",
"typescript",
"ts-node",
"ts-jest",
"@swc/core",
"@swc/jest",
"jest",
// these are missing 3rd party deps
"spdx-exceptions",
"spdx-license-ids",
// type-only, so it is not detected
"ts-toolbelt",
// these are indirectly used by build
"buffer"
];
var missingIgnore = [".prisma", "@prisma/client", "ts-toolbelt"];
var depsCheckPlugin = (bundle) => ({
name: "storm:deps-check",
setup(build3) {
const pkgJsonPath = _path2.default.join(process.cwd(), "package.json");
const pkgContents = _chunk3RG5ZIWIjs.__require.call(void 0, pkgJsonPath);
const regDependencies = Object.keys(_nullishCoalesce(pkgContents["dependencies"], () => ( {})));
const devDependencies = Object.keys(_nullishCoalesce(pkgContents["devDependencies"], () => ( {})));
const peerDependencies = Object.keys(_nullishCoalesce(pkgContents["peerDependencies"], () => ( {})));
const dependencies = [
...regDependencies,
...bundle ? devDependencies : []
];
const collectedDependencies = /* @__PURE__ */ new Set();
const onlyPackages = /^[^./](?!:)|^\.[^./]|^\.\.[^/]/;
build3.onResolve({ filter: onlyPackages }, (args) => {
if (args.importer.includes(process.cwd())) {
if (args.path[0] === "@") {
const [org, pkg] = args.path.split("/");
collectedDependencies.add(`${org}/${pkg}`);
} else {
const [pkg] = args.path.split("/");
collectedDependencies.add(pkg);
}
}
return { external: true };
});
build3.onEnd(() => {
const unusedDependencies = [...dependencies].filter((dep) => {
return !collectedDependencies.has(dep) || _module.builtinModules.includes(dep);
});
const missingDependencies = [...collectedDependencies].filter((dep) => {
return !dependencies.includes(dep) && !_module.builtinModules.includes(dep);
});
const filteredUnusedDeps = unusedDependencies.filter((dep) => {
return !unusedIgnore.some((pattern) => dep.match(pattern));
});
const filteredMissingDeps = missingDependencies.filter((dep) => {
return !missingIgnore.some((pattern) => dep.match(pattern)) && !peerDependencies.includes(dep);
});
_chunkK7STHRGHjs.writeWarning.call(void 0,
`Unused Dependencies: ${JSON.stringify(filteredUnusedDeps)}`
);
_chunkK7STHRGHjs.writeError.call(void 0,
`Missing Dependencies: ${JSON.stringify(filteredMissingDeps)}`
);
if (filteredMissingDeps.length > 0) {
throw new Error(`Missing dependencies detected - please install them:
${JSON.stringify(filteredMissingDeps)}
`);
}
});
}
});
// ../esbuild/src/tsup.ts
var _tsup = require('tsup');
async function executeTsup(context) {
_chunkK7STHRGHjs.writeDebug.call(void 0,
` \u{1F680} Running ${context.options.name} build`,
context.workspaceConfig
);
const stopwatch = _chunkK7STHRGHjs.getStopwatch.call(void 0, `${context.options.name} build`);
await _tsup.build.call(void 0, {
...context.options,
outDir: context.options.distDir ? _chunk53DNHF7Bjs.joinPaths.call(void 0, context.outputPath, context.options.distDir) : context.outputPath,
workspaceConfig: context.workspaceConfig
});
stopwatch();
return context;
}
// ../esbuild/src/build.ts
async function reportResults(context) {
if (_optionalChain([context, 'access', _32 => _32.result, 'optionalAccess', _33 => _33.errors, 'access', _34 => _34.length]) === 0) {
if (context.result.warnings.length > 0) {
_chunkK7STHRGHjs.writeWarning.call(void 0,
` \u{1F6A7} The following warnings occurred during the build: ${context.result.warnings.map((warning) => warning.text).join("\n")}`,
context.workspaceConfig
);
}
_chunkK7STHRGHjs.writeSuccess.call(void 0,
` \u{1F4E6} The ${context.options.name} build completed successfully`,
context.workspaceConfig
);
} else if (_optionalChain([context, 'access', _35 => _35.result, 'optionalAccess', _36 => _36.errors]) && _optionalChain([context, 'access', _37 => _37.result, 'optionalAccess', _38 => _38.errors, 'access', _39 => _39.length]) > 0) {
_chunkK7STHRGHjs.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: [depsCheckPlugin(options.bundle)]
});
await buildPromise.catch(() => {
});
return void 0;
}
async function cleanOutputPath(context) {
if (context.clean !== false && context.outputPath) {
_chunkK7STHRGHjs.writeDebug.call(void 0,
` \u{1F9F9} Cleaning ${context.options.name} output path: ${context.outputPath}`,
context.workspaceConfig
);
const stopwatch = _chunkK7STHRGHjs.getStopwatch.call(void 0, `${context.options.name} output clean`);
await cleanDirectories(context.outputPath);
stopwatch();
}
return context;
}
async function build2(options) {
_chunkK7STHRGHjs.writeDebug.call(void 0, ` \u26A1 Executing Storm ESBuild pipeline`);
const stopwatch = _chunkK7STHRGHjs.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 resolveContext(options);
await cleanOutputPath(context);
await Promise.all([
dependencyCheck(context.options),
generatePackageJson(context),
copyBuildAssets(context),
executeTsup(context)
]);
await reportResults(context);
_chunkK7STHRGHjs.writeSuccess.call(void 0, " \u{1F3C1} ESBuild pipeline build completed successfully");
} catch (error) {
_chunkK7STHRGHjs.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();
}
}
// src/executors/esbuild/executor.ts
async function esbuildExecutorFn(options, context, config) {
_chunkK7STHRGHjs.writeInfo.call(void 0, "\u{1F4E6} Running Storm ESBuild executor on the workspace", config);
if (!_optionalChain([context, 'access', _40 => _40.projectsConfigurations, 'optionalAccess', _41 => _41.projects]) || !context.projectName || !context.projectsConfigurations.projects[context.projectName] || !_optionalChain([context, 'access', _42 => _42.projectsConfigurations, 'access', _43 => _43.projects, 'access', _44 => _44[context.projectName], 'optionalAccess', _45 => _45.root])) {
throw new Error(
"The Build process failed because the context is not valid. Please run this command from a workspace."
);
}
await build2({
...options,
projectRoot: _optionalChain([context, 'access', _46 => _46.projectsConfigurations, 'access', _47 => _47.projects, 'optionalAccess', _48 => _48[context.projectName], 'access', _49 => _49.root]),
name: context.projectName,
sourceRoot: _optionalChain([context, 'access', _50 => _50.projectsConfigurations, 'access', _51 => _51.projects, 'optionalAccess', _52 => _52[context.projectName], 'optionalAccess', _53 => _53.sourceRoot]),
format: options.format,
platform: options.format
});
return {
success: true
};
}
var executor_default = _chunk4PG3MS76js.withRunExecutor.call(void 0,
"Storm ESBuild build",
esbuildExecutorFn,
{
skipReadingConfig: false,
hooks: {
applyDefaultOptions: async (options, config) => {
options.entry ??= ["src/index.ts"];
options.outputPath ??= "dist/{projectRoot}";
options.tsconfig ??= "{projectRoot}/tsconfig.json";
return options;
}
}
}
);
exports.esbuildExecutorFn = esbuildExecutorFn; exports.executor_default = executor_default;