@storm-software/workspace-tools 1.19.3 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.20.0](https://github.com/storm-software/storm-ops/compare/workspace-tools-v1.19.3...workspace-tools-v1.20.0) (2023-12-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * **workspace-tools:** Added default options function parameter to workspace tools ([9a5c880](https://github.com/storm-software/storm-ops/commit/9a5c880c24898f5c593c32d1d13e978c5e0b3356))
7
+
8
+ ## [1.19.3](https://github.com/storm-software/storm-ops/compare/workspace-tools-v1.19.2...workspace-tools-v1.19.3) (2023-12-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **workspace-tools:** Resolved issue with `esbuildPluginPino` plugin for neutral build ([dba1022](https://github.com/storm-software/storm-ops/commit/dba102278281102a359c1c7cff087b9969b58c7c))
14
+
1
15
  ## [1.19.2](https://github.com/storm-software/storm-ops/compare/workspace-tools-v1.19.1...workspace-tools-v1.19.2) (2023-12-02)
2
16
 
3
17
 
package/index.js CHANGED
@@ -104957,6 +104957,9 @@ var require_dist6 = __commonJS({
104957
104957
  var workspace_tools_exports = {};
104958
104958
  __export(workspace_tools_exports, {
104959
104959
  WorkspaceStorage: () => WorkspaceStorage,
104960
+ applyDefault: () => applyDefault,
104961
+ applyWorkspaceExecutorTokens: () => applyWorkspaceExecutorTokens,
104962
+ applyWorkspaceGeneratorTokens: () => applyWorkspaceGeneratorTokens,
104960
104963
  applyWorkspaceTokens: () => applyWorkspaceTokens,
104961
104964
  configSchemaGeneratorFn: () => configSchemaGeneratorFn,
104962
104965
  eslintVersion: () => eslintVersion,
@@ -104984,7 +104987,7 @@ __export(workspace_tools_exports, {
104984
104987
  tsLibVersion: () => tsLibVersion,
104985
104988
  tsNeutralBuildExecutorFn: () => tsNeutralBuildExecutorFn,
104986
104989
  tsNodeBuildExecutorFn: () => tsNodeBuildExecutorFn,
104987
- tsupExecutor: () => tsupExecutor,
104990
+ tsupExecutorFn: () => tsupExecutorFn,
104988
104991
  tsupVersion: () => tsupVersion,
104989
104992
  typesNodeVersion: () => typesNodeVersion,
104990
104993
  typescriptVersion: () => typescriptVersion,
@@ -105239,26 +105242,39 @@ var getWorkspaceRoot2 = () => {
105239
105242
  };
105240
105243
 
105241
105244
  // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
105242
- var applyWorkspaceTokens = (option, config) => {
105245
+ var applyWorkspaceExecutorTokens = (option, tokenizerOptions) => {
105246
+ console.log("applyWorkspaceExecutorTokens", option);
105243
105247
  let result = option;
105244
105248
  if (!result) {
105245
105249
  return result;
105246
105250
  }
105247
- const workspaceRoot = getWorkspaceRoot2();
105248
105251
  let projectName;
105249
105252
  let projectRoot;
105250
105253
  let sourceRoot;
105251
- if (config?.projectsConfigurations?.projects && config?.projectName) {
105252
- const context = config;
105254
+ if (tokenizerOptions?.projectName) {
105255
+ const context = tokenizerOptions;
105253
105256
  projectName = context.projectName;
105254
- projectRoot = context.projectsConfigurations.projects[projectName].root;
105255
- sourceRoot = context.projectsConfigurations.projects[projectName].sourceRoot;
105257
+ projectRoot = context.root;
105258
+ sourceRoot = context.sourceRoot;
105256
105259
  } else {
105257
- const projectConfig = config;
105260
+ const projectConfig = tokenizerOptions;
105258
105261
  projectName = projectConfig.name;
105259
105262
  projectRoot = projectConfig.root;
105260
105263
  sourceRoot = projectConfig.sourceRoot;
105261
105264
  }
105265
+ if (tokenizerOptions.config) {
105266
+ const configKeys = Object.keys(tokenizerOptions.config);
105267
+ if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
105268
+ configKeys.forEach((configKey) => {
105269
+ if (result.includes(`{${configKey}}`)) {
105270
+ result = result.replaceAll(
105271
+ `{${configKey}}`,
105272
+ tokenizerOptions.config[configKey]
105273
+ );
105274
+ }
105275
+ });
105276
+ }
105277
+ }
105262
105278
  if (result.includes("{projectName}")) {
105263
105279
  result = result.replaceAll("{projectName}", projectName);
105264
105280
  }
@@ -105269,28 +105285,69 @@ var applyWorkspaceTokens = (option, config) => {
105269
105285
  result = result.replaceAll("{sourceRoot}", sourceRoot);
105270
105286
  }
105271
105287
  if (result.includes("{workspaceRoot}")) {
105272
- result = result.replaceAll("{workspaceRoot}", workspaceRoot);
105288
+ result = result.replaceAll(
105289
+ "{workspaceRoot}",
105290
+ tokenizerOptions.workspaceRoot ?? getWorkspaceRoot2()
105291
+ );
105273
105292
  }
105274
105293
  return result;
105275
105294
  };
105295
+ var applyWorkspaceGeneratorTokens = (option, tokenizerOptions) => {
105296
+ let result = option;
105297
+ if (!result) {
105298
+ return result;
105299
+ }
105300
+ if (result.includes("{workspaceRoot}")) {
105301
+ result = result.replaceAll(
105302
+ "{workspaceRoot}",
105303
+ tokenizerOptions.workspaceRoot ?? tokenizerOptions.config.workspaceRoot ?? getWorkspaceRoot2()
105304
+ );
105305
+ }
105306
+ return result;
105307
+ };
105308
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
105309
+ let result = options;
105310
+ if (!result) {
105311
+ return {};
105312
+ }
105313
+ return Object.keys(options).reduce(
105314
+ (ret, option) => {
105315
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
105316
+ ret[option] = tokenizerFn(option, config);
105317
+ } else if (Array.isArray(options[option])) {
105318
+ ret[option] = options[option].map(
105319
+ (item) => tokenizerFn(item, config)
105320
+ );
105321
+ } else if (typeof options[option] === "object") {
105322
+ ret[option] = tokenizerFn(options[option], config);
105323
+ }
105324
+ return ret;
105325
+ },
105326
+ {}
105327
+ );
105328
+ };
105276
105329
 
105277
105330
  // packages/workspace-tools/src/base/base-executor.ts
105278
- var withRunExecutor = (name, executorFn, executorOptions = { skipReadingConfig: false }) => async (options, context) => {
105331
+ var withRunExecutor = (name, executorFn, executorOptions = {
105332
+ skipReadingConfig: false
105333
+ }) => async (options, context) => {
105279
105334
  const startTime = Date.now();
105280
105335
  try {
105281
105336
  console.info(`\u26A1 Running the ${name} executor...`);
105282
- console.debug(`\u2699\uFE0F Executor schema options:
105337
+ if (executorOptions?.applyDefaultFn) {
105338
+ options = executorOptions.applyDefaultFn(options);
105339
+ }
105340
+ console.debug(`\u2699\uFE0F Executor schema options:
105283
105341
  `, options);
105284
- const tokenized = Object.keys(options).reduce(
105285
- (ret, key) => {
105286
- ret[key] = applyWorkspaceTokens(
105287
- options[key],
105288
- context
105289
- );
105290
- return ret;
105291
- },
105292
- options
105293
- );
105342
+ if (!context.projectsConfigurations?.projects || !context.projectName || !context.projectsConfigurations.projects[context.projectName]) {
105343
+ throw new Error(
105344
+ "The Build process failed because the context is not valid. Please run this command from a workspace."
105345
+ );
105346
+ }
105347
+ const workspaceRoot = getWorkspaceRoot2();
105348
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
105349
+ const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot;
105350
+ const projectName = context.projectsConfigurations.projects[context.projectName].name;
105294
105351
  let config;
105295
105352
  if (!executorOptions.skipReadingConfig) {
105296
105353
  const configFile = await getConfigFile();
@@ -105301,8 +105358,21 @@ var withRunExecutor = (name, executorFn, executorOptions = { skipReadingConfig:
105301
105358
  });
105302
105359
  setConfigEnv(config);
105303
105360
  console.debug(`Loaded Storm config into env:
105304
- ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
105361
+ ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
105305
105362
  }
105363
+ const tokenized = applyWorkspaceTokens(
105364
+ options,
105365
+ {
105366
+ config,
105367
+ workspaceRoot,
105368
+ projectRoot,
105369
+ sourceRoot,
105370
+ projectName,
105371
+ ...context.projectsConfigurations.projects[context.projectName],
105372
+ ...executorOptions
105373
+ },
105374
+ applyWorkspaceExecutorTokens
105375
+ );
105306
105376
  const result = await Promise.resolve(
105307
105377
  executorFn(tokenized, context, config)
105308
105378
  );
@@ -105327,11 +105397,16 @@ ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\
105327
105397
  };
105328
105398
 
105329
105399
  // packages/workspace-tools/src/base/base-generator.ts
105330
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
105400
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
105401
+ skipReadingConfig: false
105402
+ }) => async (tree, options) => {
105331
105403
  const startTime = Date.now();
105332
105404
  try {
105333
105405
  console.info(`\u26A1 Running the ${name} generator...`);
105334
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
105406
+ if (generatorOptions?.applyDefaultFn) {
105407
+ options = generatorOptions.applyDefaultFn(options);
105408
+ }
105409
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
105335
105410
  let config;
105336
105411
  if (!generatorOptions.skipReadingConfig) {
105337
105412
  const configFile = await getConfigFile();
@@ -105344,7 +105419,14 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
105344
105419
  console.debug(`Loaded Storm config into env:
105345
105420
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
105346
105421
  }
105347
- const result = await Promise.resolve(generatorFn(tree, options, config));
105422
+ const tokenized = applyWorkspaceTokens(
105423
+ options,
105424
+ { workspaceRoot: tree.root, config },
105425
+ applyWorkspaceGeneratorTokens
105426
+ );
105427
+ const result = await Promise.resolve(
105428
+ generatorFn(tree, tokenized, config)
105429
+ );
105348
105430
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
105349
105431
  throw new Error(`The ${name} generator failed to run`, {
105350
105432
  cause: result.error
@@ -111914,28 +111996,9 @@ var outExtension = ({ format: format2 }) => {
111914
111996
  };
111915
111997
 
111916
111998
  // packages/workspace-tools/src/executors/tsup/executor.ts
111917
- async function tsupExecutor(options, context) {
111999
+ async function tsupExecutorFn(options, context) {
111918
112000
  try {
111919
112001
  console.log("\u{1F4E6} Running Storm build executor on the workspace");
111920
- options.entry ??= "{sourceRoot}/index.ts";
111921
- options.outputPath ??= "dist/{projectRoot}";
111922
- options.tsConfig ??= "tsconfig.json";
111923
- options.platform ??= "neutral";
111924
- options.verbose ??= false;
111925
- options.external ??= [];
111926
- options.additionalEntryPoints ??= [];
111927
- options.assets ??= [];
111928
- options.plugins ??= [];
111929
- options.includeSrc ??= true;
111930
- options.clean ??= true;
111931
- options.bundle ??= true;
111932
- options.debug ??= false;
111933
- options.watch ??= false;
111934
- options.apiReport ??= true;
111935
- options.docModel ??= true;
111936
- options.tsdocMetadata ??= true;
111937
- options.define ??= {};
111938
- options.env ??= {};
111939
112002
  options.verbose && console.log(
111940
112003
  `\u2699\uFE0F Executor options:
111941
112004
  ${Object.keys(options).map(
@@ -111951,17 +112014,9 @@ ${Object.keys(options).map(
111951
112014
  const workspaceRoot = getWorkspaceRoot2();
111952
112015
  const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
111953
112016
  const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot;
111954
- const outputPath = applyWorkspaceTokens(
111955
- options.outputPath ? options.outputPath : "dist/{projectRoot}",
111956
- context
111957
- );
111958
- options.entry = applyWorkspaceTokens(
111959
- options.entry ? options.entry : "{sourceRoot}/index.ts",
111960
- context
111961
- );
111962
112017
  if (options.clean !== false) {
111963
- console.log(`\u{1F9F9} Cleaning output path: ${outputPath}`);
111964
- (0, import_fs_extra.removeSync)(outputPath);
112018
+ console.log(`\u{1F9F9} Cleaning output path: ${options.outputPath}`);
112019
+ (0, import_fs_extra.removeSync)(options.outputPath);
111965
112020
  }
111966
112021
  const assets = Array.from(options.assets);
111967
112022
  assets.push({
@@ -111982,7 +112037,7 @@ ${Object.keys(options).map(
111982
112037
  });
111983
112038
  }
111984
112039
  const result = await (0, import_js.copyAssets)(
111985
- { assets, watch: options.watch, outputPath },
112040
+ { assets, watch: options.watch, outputPath: options.outputPath },
111986
112041
  context
111987
112042
  );
111988
112043
  if (!result.success) {
@@ -112111,7 +112166,11 @@ ${externalDependencies.map((dep) => {
112111
112166
  packageJson.keywords ??= workspacePackageJson.keywords;
112112
112167
  packageJson.repository ??= workspacePackageJson.repository;
112113
112168
  packageJson.repository.directory ??= projectRoot ? projectRoot : (0, import_path4.join)("packages", context.projectName);
112114
- const packageJsonPath = (0, import_path4.join)(context.root, outputPath, "package.json");
112169
+ const packageJsonPath = (0, import_path4.join)(
112170
+ context.root,
112171
+ options.outputPath,
112172
+ "package.json"
112173
+ );
112115
112174
  console.log(`\u26A1 Writing package.json file to: ${packageJsonPath}`);
112116
112175
  (0, import_fs3.writeFileSync)(
112117
112176
  packageJsonPath,
@@ -112133,10 +112192,10 @@ ${externalDependencies.map((dep) => {
112133
112192
  );
112134
112193
  if (options.includeSrc !== false) {
112135
112194
  const files = globSync([
112136
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.ts"),
112137
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.tsx"),
112138
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.js"),
112139
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.jsx")
112195
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.ts"),
112196
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.tsx"),
112197
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.js"),
112198
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.jsx")
112140
112199
  ]);
112141
112200
  await Promise.allSettled(
112142
112201
  files.map(
@@ -112162,7 +112221,7 @@ ${(0, import_fs3.readFileSync)(file, "utf-8")}`,
112162
112221
  ...options,
112163
112222
  dtsTsConfig: getNormalizedTsConfig(
112164
112223
  context.root,
112165
- outputPath,
112224
+ options.outputPath,
112166
112225
  (0, import_tsc.createTypeScriptCompilationOptions)(
112167
112226
  (0, import_normalize_options.normalizeOptions)(
112168
112227
  {
@@ -112188,7 +112247,7 @@ ${options.banner}
112188
112247
 
112189
112248
  `
112190
112249
  } : void 0,
112191
- outputPath
112250
+ outputPath: options.outputPath
112192
112251
  });
112193
112252
  if (typeof config === "function") {
112194
112253
  await build(await Promise.resolve(config({})));
@@ -112251,12 +112310,41 @@ var isPrimitive = (value) => {
112251
112310
  return false;
112252
112311
  }
112253
112312
  };
112254
- var executor_default = tsupExecutor;
112313
+ var applyDefault = (options) => {
112314
+ options.entry ??= "{sourceRoot}/index.ts";
112315
+ options.outputPath ??= "dist/{projectRoot}";
112316
+ options.tsConfig ??= "tsconfig.json";
112317
+ options.platform ??= "neutral";
112318
+ options.verbose ??= false;
112319
+ options.external ??= [];
112320
+ options.additionalEntryPoints ??= [];
112321
+ options.assets ??= [];
112322
+ options.plugins ??= [];
112323
+ options.includeSrc ??= true;
112324
+ options.clean ??= true;
112325
+ options.bundle ??= true;
112326
+ options.debug ??= false;
112327
+ options.watch ??= false;
112328
+ options.apiReport ??= true;
112329
+ options.docModel ??= true;
112330
+ options.tsdocMetadata ??= true;
112331
+ options.define ??= {};
112332
+ options.env ??= {};
112333
+ return options;
112334
+ };
112335
+ var executor_default = withRunExecutor(
112336
+ "TypeScript Build using tsup",
112337
+ tsupExecutorFn,
112338
+ {
112339
+ skipReadingConfig: false,
112340
+ applyDefaultFn: applyDefault
112341
+ }
112342
+ );
112255
112343
 
112256
112344
  // packages/workspace-tools/src/executors/tsup-neutral/executor.ts
112257
112345
  var tsNeutralBuildExecutorFn = (options, context, config) => {
112258
112346
  options.plugins ??= [];
112259
- return executor_default(
112347
+ return tsupExecutorFn(
112260
112348
  {
112261
112349
  ...options,
112262
112350
  platform: "neutral",
@@ -112277,9 +112365,18 @@ var tsNeutralBuildExecutorFn = (options, context, config) => {
112277
112365
  context
112278
112366
  );
112279
112367
  };
112368
+ var applyDefault2 = (options) => {
112369
+ options = applyDefault({ ...options, platform: "neutral" });
112370
+ options.plugins ??= [];
112371
+ return options;
112372
+ };
112280
112373
  var executor_default2 = withRunExecutor(
112281
112374
  "TypeScript Build (Neutral Platform)",
112282
- tsNeutralBuildExecutorFn
112375
+ tsNeutralBuildExecutorFn,
112376
+ {
112377
+ skipReadingConfig: false,
112378
+ applyDefaultFn: applyDefault2
112379
+ }
112283
112380
  );
112284
112381
 
112285
112382
  // node_modules/.pnpm/esbuild-plugin-pino@2.1.0_esbuild@0.19.5/node_modules/esbuild-plugin-pino/dist/index.mjs
@@ -112414,12 +112511,10 @@ function esbuildPluginPino({
112414
112511
 
112415
112512
  // packages/workspace-tools/src/executors/tsup-node/executor.ts
112416
112513
  var tsNodeBuildExecutorFn = (options, context, config) => {
112417
- options.plugins ??= [];
112418
- options.transports ??= ["pino-pretty", "pino-loki"];
112419
112514
  if (options.transports && Array.isArray(options.transports) && options.transports.length > 0) {
112420
112515
  options.plugins.push(esbuildPluginPino({ transports: options.transports }));
112421
112516
  }
112422
- return executor_default(
112517
+ return tsupExecutorFn(
112423
112518
  {
112424
112519
  ...options,
112425
112520
  platform: "node",
@@ -112440,9 +112535,19 @@ var tsNodeBuildExecutorFn = (options, context, config) => {
112440
112535
  context
112441
112536
  );
112442
112537
  };
112538
+ var applyDefault3 = (options) => {
112539
+ options = applyDefault({ ...options, platform: "node" });
112540
+ options.plugins ??= [];
112541
+ options.transports ??= ["pino-pretty", "pino-loki"];
112542
+ return options;
112543
+ };
112443
112544
  var executor_default3 = withRunExecutor(
112444
112545
  "TypeScript Build (NodeJs Platform)",
112445
- tsNodeBuildExecutorFn
112546
+ tsNodeBuildExecutorFn,
112547
+ {
112548
+ skipReadingConfig: false,
112549
+ applyDefaultFn: applyDefault3
112550
+ }
112446
112551
  );
112447
112552
 
112448
112553
  // packages/workspace-tools/src/generators/config-schema/generator.ts
@@ -117100,7 +117205,6 @@ var getProjectConfigurations = () => (0, import_retrieve_workspace_files.retriev
117100
117205
 
117101
117206
  // packages/workspace-tools/src/generators/config-schema/generator.ts
117102
117207
  async function configSchemaGeneratorFn(tree, options) {
117103
- const schema = {};
117104
117208
  const projectConfigurations = getProjectConfigurations();
117105
117209
  const workspaceRoot = getWorkspaceRoot2();
117106
117210
  const modules = await Promise.all(
@@ -117896,6 +118000,9 @@ var WorkspaceStorage = class {
117896
118000
  // Annotate the CommonJS export names for ESM import in node:
117897
118001
  0 && (module.exports = {
117898
118002
  WorkspaceStorage,
118003
+ applyDefault,
118004
+ applyWorkspaceExecutorTokens,
118005
+ applyWorkspaceGeneratorTokens,
117899
118006
  applyWorkspaceTokens,
117900
118007
  configSchemaGeneratorFn,
117901
118008
  eslintVersion,
@@ -117923,7 +118030,7 @@ var WorkspaceStorage = class {
117923
118030
  tsLibVersion,
117924
118031
  tsNeutralBuildExecutorFn,
117925
118032
  tsNodeBuildExecutorFn,
117926
- tsupExecutor,
118033
+ tsupExecutorFn,
117927
118034
  tsupVersion,
117928
118035
  typesNodeVersion,
117929
118036
  typescriptVersion,