@storm-software/workspace-tools 1.19.2 → 1.20.0

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.
@@ -1,8 +1,9 @@
1
- import { TsupExecutorSchema } from "../tsup/schema";
1
+ import { Platform, TsupExecutorSchema } from "../tsup/schema";
2
2
 
3
3
  export type TsupNeutralExecutorSchema = Omit<
4
4
  TsupExecutorSchema,
5
5
  "env" | "platform"
6
6
  > & {
7
7
  transports?: string[];
8
+ platform?: Platform;
8
9
  };
@@ -105336,20 +105336,19 @@ var getWorkspaceRoot2 = () => {
105336
105336
  };
105337
105337
 
105338
105338
  // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
105339
- var applyWorkspaceTokens = (option, config) => {
105339
+ var applyWorkspaceExecutorTokens = (option, config) => {
105340
105340
  let result = option;
105341
105341
  if (!result) {
105342
105342
  return result;
105343
105343
  }
105344
- const workspaceRoot = getWorkspaceRoot2();
105345
105344
  let projectName;
105346
105345
  let projectRoot;
105347
105346
  let sourceRoot;
105348
- if (config?.projectsConfigurations?.projects && config?.projectName) {
105347
+ if (config?.projectName) {
105349
105348
  const context = config;
105350
105349
  projectName = context.projectName;
105351
- projectRoot = context.projectsConfigurations.projects[projectName].root;
105352
- sourceRoot = context.projectsConfigurations.projects[projectName].sourceRoot;
105350
+ projectRoot = context.root;
105351
+ sourceRoot = context.sourceRoot;
105353
105352
  } else {
105354
105353
  const projectConfig = config;
105355
105354
  projectName = projectConfig.name;
@@ -105366,27 +105365,67 @@ var applyWorkspaceTokens = (option, config) => {
105366
105365
  result = result.replaceAll("{sourceRoot}", sourceRoot);
105367
105366
  }
105368
105367
  if (result.includes("{workspaceRoot}")) {
105369
- result = result.replaceAll("{workspaceRoot}", workspaceRoot);
105368
+ result = result.replaceAll(
105369
+ "{workspaceRoot}",
105370
+ config.workspaceRoot ?? getWorkspaceRoot2()
105371
+ );
105370
105372
  }
105371
105373
  return result;
105372
105374
  };
105375
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
105376
+ let result = options;
105377
+ if (!result) {
105378
+ return {};
105379
+ }
105380
+ return Object.keys(options).reduce(
105381
+ (ret, option) => {
105382
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
105383
+ ret[option] = tokenizerFn(option, config);
105384
+ } else if (Array.isArray(options[option])) {
105385
+ ret[option] = options[option].map(
105386
+ (item) => tokenizerFn(item, config)
105387
+ );
105388
+ } else if (typeof options[option] === "object") {
105389
+ ret[option] = tokenizerFn(options[option], config);
105390
+ }
105391
+ return ret;
105392
+ },
105393
+ {}
105394
+ );
105395
+ };
105373
105396
 
105374
105397
  // packages/workspace-tools/src/base/base-executor.ts
105375
- var withRunExecutor = (name, executorFn, executorOptions = { skipReadingConfig: false }) => async (options, context) => {
105398
+ var withRunExecutor = (name, executorFn, executorOptions = {
105399
+ skipReadingConfig: false
105400
+ }) => async (options, context) => {
105376
105401
  const startTime = Date.now();
105377
105402
  try {
105378
105403
  console.info(`\u26A1 Running the ${name} executor...`);
105379
- console.debug(`\u2699\uFE0F Executor schema options:
105404
+ if (executorOptions?.applyDefaultFn) {
105405
+ options = executorOptions.applyDefaultFn(options);
105406
+ }
105407
+ console.debug(`\u2699\uFE0F Executor schema options:
105380
105408
  `, options);
105381
- const tokenized = Object.keys(options).reduce(
105382
- (ret, key) => {
105383
- ret[key] = applyWorkspaceTokens(
105384
- options[key],
105385
- context
105386
- );
105387
- return ret;
105409
+ if (!context.projectsConfigurations?.projects || !context.projectName || !context.projectsConfigurations.projects[context.projectName]) {
105410
+ throw new Error(
105411
+ "The Build process failed because the context is not valid. Please run this command from a workspace."
105412
+ );
105413
+ }
105414
+ const workspaceRoot = getWorkspaceRoot2();
105415
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
105416
+ const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot;
105417
+ const projectName = context.projectsConfigurations.projects[context.projectName].name;
105418
+ const tokenized = applyWorkspaceTokens(
105419
+ options,
105420
+ {
105421
+ workspaceRoot,
105422
+ projectRoot,
105423
+ sourceRoot,
105424
+ projectName,
105425
+ ...context.projectsConfigurations.projects[context.projectName],
105426
+ ...executorOptions
105388
105427
  },
105389
- options
105428
+ applyWorkspaceExecutorTokens
105390
105429
  );
105391
105430
  let config;
105392
105431
  if (!executorOptions.skipReadingConfig) {
@@ -111964,28 +112003,9 @@ var outExtension = ({ format: format2 }) => {
111964
112003
  };
111965
112004
 
111966
112005
  // packages/workspace-tools/src/executors/tsup/executor.ts
111967
- async function tsupExecutor(options, context) {
112006
+ async function tsupExecutorFn(options, context) {
111968
112007
  try {
111969
112008
  console.log("\u{1F4E6} Running Storm build executor on the workspace");
111970
- options.entry ??= "{sourceRoot}/index.ts";
111971
- options.outputPath ??= "dist/{projectRoot}";
111972
- options.tsConfig ??= "tsconfig.json";
111973
- options.platform ??= "neutral";
111974
- options.verbose ??= false;
111975
- options.external ??= [];
111976
- options.additionalEntryPoints ??= [];
111977
- options.assets ??= [];
111978
- options.plugins ??= [];
111979
- options.includeSrc ??= true;
111980
- options.clean ??= true;
111981
- options.bundle ??= true;
111982
- options.debug ??= false;
111983
- options.watch ??= false;
111984
- options.apiReport ??= true;
111985
- options.docModel ??= true;
111986
- options.tsdocMetadata ??= true;
111987
- options.define ??= {};
111988
- options.env ??= {};
111989
112009
  options.verbose && console.log(
111990
112010
  `\u2699\uFE0F Executor options:
111991
112011
  ${Object.keys(options).map(
@@ -112001,17 +112021,9 @@ ${Object.keys(options).map(
112001
112021
  const workspaceRoot = getWorkspaceRoot2();
112002
112022
  const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
112003
112023
  const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot;
112004
- const outputPath = applyWorkspaceTokens(
112005
- options.outputPath ? options.outputPath : "dist/{projectRoot}",
112006
- context
112007
- );
112008
- options.entry = applyWorkspaceTokens(
112009
- options.entry ? options.entry : "{sourceRoot}/index.ts",
112010
- context
112011
- );
112012
112024
  if (options.clean !== false) {
112013
- console.log(`\u{1F9F9} Cleaning output path: ${outputPath}`);
112014
- (0, import_fs_extra.removeSync)(outputPath);
112025
+ console.log(`\u{1F9F9} Cleaning output path: ${options.outputPath}`);
112026
+ (0, import_fs_extra.removeSync)(options.outputPath);
112015
112027
  }
112016
112028
  const assets = Array.from(options.assets);
112017
112029
  assets.push({
@@ -112032,7 +112044,7 @@ ${Object.keys(options).map(
112032
112044
  });
112033
112045
  }
112034
112046
  const result = await (0, import_js.copyAssets)(
112035
- { assets, watch: options.watch, outputPath },
112047
+ { assets, watch: options.watch, outputPath: options.outputPath },
112036
112048
  context
112037
112049
  );
112038
112050
  if (!result.success) {
@@ -112161,7 +112173,11 @@ ${externalDependencies.map((dep) => {
112161
112173
  packageJson.keywords ??= workspacePackageJson.keywords;
112162
112174
  packageJson.repository ??= workspacePackageJson.repository;
112163
112175
  packageJson.repository.directory ??= projectRoot ? projectRoot : (0, import_path4.join)("packages", context.projectName);
112164
- const packageJsonPath = (0, import_path4.join)(context.root, outputPath, "package.json");
112176
+ const packageJsonPath = (0, import_path4.join)(
112177
+ context.root,
112178
+ options.outputPath,
112179
+ "package.json"
112180
+ );
112165
112181
  console.log(`\u26A1 Writing package.json file to: ${packageJsonPath}`);
112166
112182
  (0, import_fs3.writeFileSync)(
112167
112183
  packageJsonPath,
@@ -112183,10 +112199,10 @@ ${externalDependencies.map((dep) => {
112183
112199
  );
112184
112200
  if (options.includeSrc !== false) {
112185
112201
  const files = globSync([
112186
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.ts"),
112187
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.tsx"),
112188
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.js"),
112189
- (0, import_devkit.joinPathFragments)(context.root, outputPath, "src/**/*.jsx")
112202
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.ts"),
112203
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.tsx"),
112204
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.js"),
112205
+ (0, import_devkit.joinPathFragments)(context.root, options.outputPath, "src/**/*.jsx")
112190
112206
  ]);
112191
112207
  await Promise.allSettled(
112192
112208
  files.map(
@@ -112212,7 +112228,7 @@ ${(0, import_fs3.readFileSync)(file, "utf-8")}`,
112212
112228
  ...options,
112213
112229
  dtsTsConfig: getNormalizedTsConfig(
112214
112230
  context.root,
112215
- outputPath,
112231
+ options.outputPath,
112216
112232
  (0, import_tsc.createTypeScriptCompilationOptions)(
112217
112233
  (0, import_normalize_options.normalizeOptions)(
112218
112234
  {
@@ -112238,7 +112254,7 @@ ${options.banner}
112238
112254
 
112239
112255
  `
112240
112256
  } : void 0,
112241
- outputPath
112257
+ outputPath: options.outputPath
112242
112258
  });
112243
112259
  if (typeof config === "function") {
112244
112260
  await build(await Promise.resolve(config({})));
@@ -112301,16 +112317,43 @@ var isPrimitive = (value) => {
112301
112317
  return false;
112302
112318
  }
112303
112319
  };
112304
- var executor_default = tsupExecutor;
112320
+ var applyDefault = (options) => {
112321
+ options.entry ??= "{sourceRoot}/index.ts";
112322
+ options.outputPath ??= "dist/{projectRoot}";
112323
+ options.tsConfig ??= "tsconfig.json";
112324
+ options.platform ??= "neutral";
112325
+ options.verbose ??= false;
112326
+ options.external ??= [];
112327
+ options.additionalEntryPoints ??= [];
112328
+ options.assets ??= [];
112329
+ options.plugins ??= [];
112330
+ options.includeSrc ??= true;
112331
+ options.clean ??= true;
112332
+ options.bundle ??= true;
112333
+ options.debug ??= false;
112334
+ options.watch ??= false;
112335
+ options.apiReport ??= true;
112336
+ options.docModel ??= true;
112337
+ options.tsdocMetadata ??= true;
112338
+ options.define ??= {};
112339
+ options.env ??= {};
112340
+ return options;
112341
+ };
112342
+ var executor_default = withRunExecutor(
112343
+ "TypeScript Build using tsup",
112344
+ tsupExecutorFn,
112345
+ {
112346
+ skipReadingConfig: false,
112347
+ applyDefaultFn: applyDefault
112348
+ }
112349
+ );
112305
112350
 
112306
112351
  // packages/workspace-tools/src/executors/tsup-node/executor.ts
112307
112352
  var tsNodeBuildExecutorFn = (options, context, config) => {
112308
- options.plugins ??= [];
112309
- options.transports ??= ["pino-pretty", "pino-loki"];
112310
112353
  if (options.transports && Array.isArray(options.transports) && options.transports.length > 0) {
112311
112354
  options.plugins.push(esbuildPluginPino({ transports: options.transports }));
112312
112355
  }
112313
- return executor_default(
112356
+ return tsupExecutorFn(
112314
112357
  {
112315
112358
  ...options,
112316
112359
  platform: "node",
@@ -112331,9 +112374,19 @@ var tsNodeBuildExecutorFn = (options, context, config) => {
112331
112374
  context
112332
112375
  );
112333
112376
  };
112377
+ var applyDefault2 = (options) => {
112378
+ options = applyDefault({ ...options, platform: "node" });
112379
+ options.plugins ??= [];
112380
+ options.transports ??= ["pino-pretty", "pino-loki"];
112381
+ return options;
112382
+ };
112334
112383
  var executor_default2 = withRunExecutor(
112335
112384
  "TypeScript Build (NodeJs Platform)",
112336
- tsNodeBuildExecutorFn
112385
+ tsNodeBuildExecutorFn,
112386
+ {
112387
+ skipReadingConfig: false,
112388
+ applyDefaultFn: applyDefault2
112389
+ }
112337
112390
  );
112338
112391
  // Annotate the CommonJS export names for ESM import in node:
112339
112392
  0 && (module.exports = {
@@ -1,6 +1,9 @@
1
1
  import { TsupNeutralExecutorSchema } from "../tsup-neutral/schema";
2
+ import { Platform } from "../tsup/schema";
2
3
 
3
4
  export type TsupNodeExecutorSchema = Omit<
4
5
  TsupNeutralExecutorSchema,
5
6
  "platform"
6
- >;
7
+ > & {
8
+ platform?: Platform;
9
+ };
@@ -29593,12 +29593,67 @@ var setConfigEnv = (config) => {
29593
29593
  });
29594
29594
  };
29595
29595
 
29596
+ // packages/workspace-tools/src/utils/get-workspace-root.ts
29597
+ var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
29598
+ var getWorkspaceRoot2 = () => {
29599
+ const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
29600
+ process.env.STORM_REPO_ROOT ??= root?.dir;
29601
+ process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
29602
+ return root?.dir;
29603
+ };
29604
+
29605
+ // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
29606
+ var applyWorkspaceGeneratorTokens = (option, config) => {
29607
+ let result = option;
29608
+ if (!result) {
29609
+ return result;
29610
+ }
29611
+ if (result.includes("{workspaceRoot}")) {
29612
+ result = result.replaceAll(
29613
+ "{workspaceRoot}",
29614
+ config.workspaceRoot ?? getWorkspaceRoot2()
29615
+ );
29616
+ }
29617
+ return result;
29618
+ };
29619
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
29620
+ let result = options;
29621
+ if (!result) {
29622
+ return {};
29623
+ }
29624
+ return Object.keys(options).reduce(
29625
+ (ret, option) => {
29626
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
29627
+ ret[option] = tokenizerFn(option, config);
29628
+ } else if (Array.isArray(options[option])) {
29629
+ ret[option] = options[option].map(
29630
+ (item) => tokenizerFn(item, config)
29631
+ );
29632
+ } else if (typeof options[option] === "object") {
29633
+ ret[option] = tokenizerFn(options[option], config);
29634
+ }
29635
+ return ret;
29636
+ },
29637
+ {}
29638
+ );
29639
+ };
29640
+
29596
29641
  // packages/workspace-tools/src/base/base-generator.ts
29597
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
29642
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
29643
+ skipReadingConfig: false
29644
+ }) => async (tree, options) => {
29598
29645
  const startTime = Date.now();
29599
29646
  try {
29600
29647
  console.info(`\u26A1 Running the ${name} generator...`);
29601
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
29648
+ if (generatorOptions?.applyDefaultFn) {
29649
+ options = generatorOptions.applyDefaultFn(options);
29650
+ }
29651
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
29652
+ const tokenized = applyWorkspaceTokens(
29653
+ options,
29654
+ { workspaceRoot: tree.root },
29655
+ applyWorkspaceGeneratorTokens
29656
+ );
29602
29657
  let config;
29603
29658
  if (!generatorOptions.skipReadingConfig) {
29604
29659
  const configFile = await getConfigFile();
@@ -29611,7 +29666,9 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
29611
29666
  console.debug(`Loaded Storm config into env:
29612
29667
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
29613
29668
  }
29614
- const result = await Promise.resolve(generatorFn(tree, options, config));
29669
+ const result = await Promise.resolve(
29670
+ generatorFn(tree, tokenized, config)
29671
+ );
29615
29672
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
29616
29673
  throw new Error(`The ${name} generator failed to run`, {
29617
29674
  cause: result.error
@@ -29636,24 +29693,12 @@ ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\
29636
29693
 
29637
29694
  // packages/workspace-tools/src/utils/get-project-configurations.ts
29638
29695
  var import_retrieve_workspace_files = require("nx/src/project-graph/utils/retrieve-workspace-files");
29639
-
29640
- // packages/workspace-tools/src/utils/get-workspace-root.ts
29641
- var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
29642
- var getWorkspaceRoot2 = () => {
29643
- const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
29644
- process.env.STORM_REPO_ROOT ??= root?.dir;
29645
- process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
29646
- return root?.dir;
29647
- };
29648
-
29649
- // packages/workspace-tools/src/utils/get-project-configurations.ts
29650
29696
  var getProjectConfigurations = () => (0, import_retrieve_workspace_files.retrieveProjectConfigurationsWithoutPluginInference)(
29651
29697
  getWorkspaceRoot2()
29652
29698
  );
29653
29699
 
29654
29700
  // packages/workspace-tools/src/generators/config-schema/generator.ts
29655
29701
  async function configSchemaGeneratorFn(tree, options) {
29656
- const schema = {};
29657
29702
  const projectConfigurations = getProjectConfigurations();
29658
29703
  const workspaceRoot = getWorkspaceRoot2();
29659
29704
  const modules = await Promise.all(
@@ -43925,12 +43925,67 @@ var setConfigEnv = (config) => {
43925
43925
  });
43926
43926
  };
43927
43927
 
43928
+ // packages/workspace-tools/src/utils/get-workspace-root.ts
43929
+ var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
43930
+ var getWorkspaceRoot2 = () => {
43931
+ const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
43932
+ process.env.STORM_REPO_ROOT ??= root?.dir;
43933
+ process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
43934
+ return root?.dir;
43935
+ };
43936
+
43937
+ // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
43938
+ var applyWorkspaceGeneratorTokens = (option, config) => {
43939
+ let result = option;
43940
+ if (!result) {
43941
+ return result;
43942
+ }
43943
+ if (result.includes("{workspaceRoot}")) {
43944
+ result = result.replaceAll(
43945
+ "{workspaceRoot}",
43946
+ config.workspaceRoot ?? getWorkspaceRoot2()
43947
+ );
43948
+ }
43949
+ return result;
43950
+ };
43951
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
43952
+ let result = options;
43953
+ if (!result) {
43954
+ return {};
43955
+ }
43956
+ return Object.keys(options).reduce(
43957
+ (ret, option) => {
43958
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
43959
+ ret[option] = tokenizerFn(option, config);
43960
+ } else if (Array.isArray(options[option])) {
43961
+ ret[option] = options[option].map(
43962
+ (item) => tokenizerFn(item, config)
43963
+ );
43964
+ } else if (typeof options[option] === "object") {
43965
+ ret[option] = tokenizerFn(options[option], config);
43966
+ }
43967
+ return ret;
43968
+ },
43969
+ {}
43970
+ );
43971
+ };
43972
+
43928
43973
  // packages/workspace-tools/src/base/base-generator.ts
43929
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
43974
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
43975
+ skipReadingConfig: false
43976
+ }) => async (tree, options) => {
43930
43977
  const startTime = Date.now();
43931
43978
  try {
43932
43979
  console.info(`\u26A1 Running the ${name} generator...`);
43933
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
43980
+ if (generatorOptions?.applyDefaultFn) {
43981
+ options = generatorOptions.applyDefaultFn(options);
43982
+ }
43983
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
43984
+ const tokenized = applyWorkspaceTokens(
43985
+ options,
43986
+ { workspaceRoot: tree.root },
43987
+ applyWorkspaceGeneratorTokens
43988
+ );
43934
43989
  let config;
43935
43990
  if (!generatorOptions.skipReadingConfig) {
43936
43991
  const configFile = await getConfigFile();
@@ -43943,7 +43998,9 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
43943
43998
  console.debug(`Loaded Storm config into env:
43944
43999
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
43945
44000
  }
43946
- const result = await Promise.resolve(generatorFn(tree, options, config));
44001
+ const result = await Promise.resolve(
44002
+ generatorFn(tree, tokenized, config)
44003
+ );
43947
44004
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
43948
44005
  throw new Error(`The ${name} generator failed to run`, {
43949
44006
  cause: result.error
@@ -24950,12 +24950,67 @@ var setConfigEnv = (config) => {
24950
24950
  });
24951
24951
  };
24952
24952
 
24953
+ // packages/workspace-tools/src/utils/get-workspace-root.ts
24954
+ var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
24955
+ var getWorkspaceRoot2 = () => {
24956
+ const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
24957
+ process.env.STORM_REPO_ROOT ??= root?.dir;
24958
+ process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
24959
+ return root?.dir;
24960
+ };
24961
+
24962
+ // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
24963
+ var applyWorkspaceGeneratorTokens = (option, config) => {
24964
+ let result = option;
24965
+ if (!result) {
24966
+ return result;
24967
+ }
24968
+ if (result.includes("{workspaceRoot}")) {
24969
+ result = result.replaceAll(
24970
+ "{workspaceRoot}",
24971
+ config.workspaceRoot ?? getWorkspaceRoot2()
24972
+ );
24973
+ }
24974
+ return result;
24975
+ };
24976
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
24977
+ let result = options;
24978
+ if (!result) {
24979
+ return {};
24980
+ }
24981
+ return Object.keys(options).reduce(
24982
+ (ret, option) => {
24983
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
24984
+ ret[option] = tokenizerFn(option, config);
24985
+ } else if (Array.isArray(options[option])) {
24986
+ ret[option] = options[option].map(
24987
+ (item) => tokenizerFn(item, config)
24988
+ );
24989
+ } else if (typeof options[option] === "object") {
24990
+ ret[option] = tokenizerFn(options[option], config);
24991
+ }
24992
+ return ret;
24993
+ },
24994
+ {}
24995
+ );
24996
+ };
24997
+
24953
24998
  // packages/workspace-tools/src/base/base-generator.ts
24954
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
24999
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
25000
+ skipReadingConfig: false
25001
+ }) => async (tree, options) => {
24955
25002
  const startTime = Date.now();
24956
25003
  try {
24957
25004
  console.info(`\u26A1 Running the ${name} generator...`);
24958
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
25005
+ if (generatorOptions?.applyDefaultFn) {
25006
+ options = generatorOptions.applyDefaultFn(options);
25007
+ }
25008
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
25009
+ const tokenized = applyWorkspaceTokens(
25010
+ options,
25011
+ { workspaceRoot: tree.root },
25012
+ applyWorkspaceGeneratorTokens
25013
+ );
24959
25014
  let config;
24960
25015
  if (!generatorOptions.skipReadingConfig) {
24961
25016
  const configFile = await getConfigFile();
@@ -24968,7 +25023,9 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
24968
25023
  console.debug(`Loaded Storm config into env:
24969
25024
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
24970
25025
  }
24971
- const result = await Promise.resolve(generatorFn(tree, options, config));
25026
+ const result = await Promise.resolve(
25027
+ generatorFn(tree, tokenized, config)
25028
+ );
24972
25029
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
24973
25030
  throw new Error(`The ${name} generator failed to run`, {
24974
25031
  cause: result.error
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var utils_exports = {};
21
21
  __export(utils_exports, {
22
22
  WorkspaceStorage: () => WorkspaceStorage,
23
+ applyWorkspaceExecutorTokens: () => applyWorkspaceExecutorTokens,
24
+ applyWorkspaceGeneratorTokens: () => applyWorkspaceGeneratorTokens,
23
25
  applyWorkspaceTokens: () => applyWorkspaceTokens,
24
26
  eslintVersion: () => eslintVersion,
25
27
  findCacheDirectory: () => findCacheDirectory,
@@ -58,20 +60,19 @@ var getWorkspaceRoot = () => {
58
60
  };
59
61
 
60
62
  // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
61
- var applyWorkspaceTokens = (option, config) => {
63
+ var applyWorkspaceExecutorTokens = (option, config) => {
62
64
  let result = option;
63
65
  if (!result) {
64
66
  return result;
65
67
  }
66
- const workspaceRoot = getWorkspaceRoot();
67
68
  let projectName;
68
69
  let projectRoot;
69
70
  let sourceRoot;
70
- if (config?.projectsConfigurations?.projects && config?.projectName) {
71
+ if (config?.projectName) {
71
72
  const context = config;
72
73
  projectName = context.projectName;
73
- projectRoot = context.projectsConfigurations.projects[projectName].root;
74
- sourceRoot = context.projectsConfigurations.projects[projectName].sourceRoot;
74
+ projectRoot = context.root;
75
+ sourceRoot = context.sourceRoot;
75
76
  } else {
76
77
  const projectConfig = config;
77
78
  projectName = projectConfig.name;
@@ -88,10 +89,47 @@ var applyWorkspaceTokens = (option, config) => {
88
89
  result = result.replaceAll("{sourceRoot}", sourceRoot);
89
90
  }
90
91
  if (result.includes("{workspaceRoot}")) {
91
- result = result.replaceAll("{workspaceRoot}", workspaceRoot);
92
+ result = result.replaceAll(
93
+ "{workspaceRoot}",
94
+ config.workspaceRoot ?? getWorkspaceRoot()
95
+ );
92
96
  }
93
97
  return result;
94
98
  };
99
+ var applyWorkspaceGeneratorTokens = (option, config) => {
100
+ let result = option;
101
+ if (!result) {
102
+ return result;
103
+ }
104
+ if (result.includes("{workspaceRoot}")) {
105
+ result = result.replaceAll(
106
+ "{workspaceRoot}",
107
+ config.workspaceRoot ?? getWorkspaceRoot()
108
+ );
109
+ }
110
+ return result;
111
+ };
112
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
113
+ let result = options;
114
+ if (!result) {
115
+ return {};
116
+ }
117
+ return Object.keys(options).reduce(
118
+ (ret, option) => {
119
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
120
+ ret[option] = tokenizerFn(option, config);
121
+ } else if (Array.isArray(options[option])) {
122
+ ret[option] = options[option].map(
123
+ (item) => tokenizerFn(item, config)
124
+ );
125
+ } else if (typeof options[option] === "object") {
126
+ ret[option] = tokenizerFn(options[option], config);
127
+ }
128
+ return ret;
129
+ },
130
+ {}
131
+ );
132
+ };
95
133
 
96
134
  // packages/workspace-tools/src/utils/file-path-utils.ts
97
135
  var import_node_path = require("node:path");
@@ -283,6 +321,8 @@ var WorkspaceStorage = class {
283
321
  // Annotate the CommonJS export names for ESM import in node:
284
322
  0 && (module.exports = {
285
323
  WorkspaceStorage,
324
+ applyWorkspaceExecutorTokens,
325
+ applyWorkspaceGeneratorTokens,
286
326
  applyWorkspaceTokens,
287
327
  eslintVersion,
288
328
  findCacheDirectory,