@powerlines/engine 0.0.14 → 0.0.16

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.
@@ -65,12 +65,12 @@ let handlebars = require("handlebars");
65
65
  handlebars = __toESM(handlebars, 1);
66
66
  let _powerlines_core_constants = require("@powerlines/core/constants");
67
67
  let _stryke_fs_json = require("@stryke/fs/json");
68
+ let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
68
69
  let _stryke_path_join = require("@stryke/path/join");
69
70
  let _powerlines_core_lib_entry = require("@powerlines/core/lib/entry");
70
71
  let _stryke_fs_get_workspace_root = require("@stryke/fs/get-workspace-root");
71
72
  let _stryke_hash = require("@stryke/hash");
72
73
  let _stryke_hash_node = require("@stryke/hash/node");
73
- let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
74
74
  let _stryke_http_fetch = require("@stryke/http/fetch");
75
75
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
76
76
  let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
@@ -112,12 +112,12 @@ let _stryke_string_format_package = require("@stryke/string-format/package");
112
112
  let _donedeal0_superdiff = require("@donedeal0/superdiff");
113
113
 
114
114
  //#region src/_internal/helpers/environment.ts
115
- function createEnvironment(name, userConfig) {
116
- return (0, defu.default)(userConfig.environments?.[name] ?? {}, {
115
+ function createEnvironment(name, config = {}) {
116
+ return (0, defu.default)(config.environments?.[name] ?? {}, {
117
117
  name,
118
- title: userConfig.title || (0, _stryke_string_format_title_case.titleCase)(userConfig.name),
118
+ title: config.title ?? (0, _stryke_string_format_title_case.titleCase)(config.name),
119
119
  ssr: false,
120
- mainFields: userConfig?.platform === "browser" ? [
120
+ resolve: { mainFields: config.platform === "browser" ? [
121
121
  "browser",
122
122
  "module",
123
123
  "jsnext:main",
@@ -126,18 +126,9 @@ function createEnvironment(name, userConfig) {
126
126
  "module",
127
127
  "jsnext:main",
128
128
  "jsnext"
129
- ],
130
- extensions: [
131
- ".mjs",
132
- ".js",
133
- ".mts",
134
- ".ts",
135
- ".jsx",
136
- ".tsx",
137
- ".json"
138
- ],
139
- consumer: userConfig?.platform === "browser" ? "client" : "server",
140
- preview: userConfig?.platform === "browser" ? {
129
+ ] },
130
+ consumer: config.platform === "browser" ? "client" : "server",
131
+ preview: config.platform === "browser" ? {
141
132
  port: 5173,
142
133
  open: true,
143
134
  strictPort: false,
@@ -146,10 +137,37 @@ function createEnvironment(name, userConfig) {
146
137
  cors: true,
147
138
  headers: {}
148
139
  } : void 0
149
- }, userConfig);
140
+ });
150
141
  }
151
- function createDefaultEnvironment(userConfig) {
152
- return createEnvironment(_powerlines_core_constants.DEFAULT_ENVIRONMENT, userConfig);
142
+ function createDefaultEnvironment(config = {}) {
143
+ return createEnvironment(_powerlines_core_constants.DEFAULT_ENVIRONMENT, config);
144
+ }
145
+
146
+ //#endregion
147
+ //#region src/_internal/helpers/context.ts
148
+ function getConfigProps(config = {}, root, cwd) {
149
+ return {
150
+ name: config.name,
151
+ title: config.title,
152
+ description: config.description,
153
+ projectType: config.projectType,
154
+ customLogger: config.customLogger,
155
+ logLevel: config.logLevel,
156
+ tsconfig: config.tsconfig,
157
+ tsconfigRaw: config.tsconfigRaw,
158
+ skipCache: config.skipCache,
159
+ autoInstall: config.autoInstall,
160
+ input: (0, _stryke_type_checks_is_set_string.isSetString)(config.input) ? [config.input] : config.input,
161
+ plugins: config.plugins,
162
+ mode: config.mode,
163
+ resolve: config.resolve,
164
+ framework: config.framework,
165
+ ...config,
166
+ output: {
167
+ ...config.output ?? {},
168
+ path: config.output?.path ? (0, _stryke_path_append.appendPath)(config.output.path, (0, _stryke_path_append.appendPath)(root, cwd)) : void 0
169
+ }
170
+ };
153
171
  }
154
172
 
155
173
  //#endregion
@@ -2351,35 +2369,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2351
2369
  #tsconfig;
2352
2370
  #parserCache;
2353
2371
  #requestCache;
2354
- #getConfigProps(config = {}) {
2355
- return (0, _powerlines_core_plugin_utils.mergeConfig)({
2356
- name: config.name,
2357
- title: config.title,
2358
- compatibilityDate: (0, compatx.resolveCompatibilityDates)(config.compatibilityDate, "latest"),
2359
- description: config.description,
2360
- projectType: config.projectType,
2361
- customLogger: config.customLogger,
2362
- logLevel: config.logLevel,
2363
- tsconfig: config.tsconfig,
2364
- tsconfigRaw: config.tsconfigRaw,
2365
- skipCache: config.skipCache,
2366
- autoInstall: config.autoInstall,
2367
- input: (0, _stryke_type_checks_is_set_string.isSetString)(config.input) ? [config.input] : config.input,
2368
- plugins: config.plugins,
2369
- mode: config.mode,
2370
- resolve: config.resolve,
2371
- framework: config.framework,
2372
- ...config,
2373
- output: {
2374
- ...config.output ?? {},
2375
- path: config.output?.path ? (0, _stryke_path_append.appendPath)(config.output.path, (0, _stryke_path_append.appendPath)(this.config.root, this.config.cwd)) : void 0
2376
- }
2377
- }, { output: config.framework ? {
2378
- artifactsPath: `.${config.framework ?? "powerlines"}`,
2379
- dts: true,
2380
- types: (0, _stryke_path_join.joinPaths)(this.config.root, `${config.framework ?? "powerlines"}.d.ts`)
2381
- } : {} });
2382
- }
2383
2372
  /**
2384
2373
  * Create a new Storm context from the workspace root and user config.
2385
2374
  *
@@ -2994,36 +2983,16 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2994
2983
  }
2995
2984
  /**
2996
2985
  * Initialize the context with the provided configuration options
2997
- *
2998
- * @param config - The partial configuration options to initialize the context with
2999
2986
  */
3000
- async setup(config) {
2987
+ async setup() {
3001
2988
  this.resolvedConfig = (0, _powerlines_core_plugin_utils.mergeConfig)({
3002
2989
  inlineConfig: this.config.inlineConfig ?? {},
3003
2990
  userConfig: this.config.userConfig ?? {},
3004
- pluginConfig: this.config.pluginConfig ?? {},
3005
- tsconfig: getTsconfigFilePath(this.options.cwd, this.options.root, config.tsconfig || this.config.tsconfig)
3006
- }, this.options, this.#getConfigProps(config), this.#getConfigProps(this.config), {
2991
+ pluginConfig: this.config.pluginConfig ?? {}
2992
+ }, this.options, this.config.inlineConfig ? getConfigProps(this.config.inlineConfig, this.options.root, this.options.cwd) : {}, this.config.userConfig ? getConfigProps(this.config.userConfig, this.options.root, this.options.cwd) : {}, this.config.pluginConfig ? getConfigProps(this.config.pluginConfig, this.options.root, this.options.cwd) : {}, {
3007
2993
  name: this.projectJson?.name || this.packageJson?.name,
3008
2994
  version: this.packageJson?.version,
3009
- description: this.packageJson?.description,
3010
- output: (0, _powerlines_core_plugin_utils.mergeConfig)(this.config.output ?? {}, {
3011
- path: this.config.root ? (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.config.root, "dist"), this.config.cwd) : void 0,
3012
- copy: { assets: [
3013
- { glob: "LICENSE" },
3014
- {
3015
- input: this.config.root,
3016
- glob: "*.md"
3017
- },
3018
- {
3019
- input: this.config.root,
3020
- glob: "package.json"
3021
- }
3022
- ] },
3023
- artifactsPath: `.${this.config.framework ?? "powerlines"}`,
3024
- dts: true,
3025
- types: (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)
3026
- })
2995
+ description: this.packageJson?.description
3027
2996
  }, {
3028
2997
  projectType: "application",
3029
2998
  platform: "neutral",
@@ -3032,6 +3001,78 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3032
3001
  environments: {},
3033
3002
  resolve: {}
3034
3003
  });
3004
+ await this.innerSetup();
3005
+ }
3006
+ /**
3007
+ * The resolved configuration for this context
3008
+ */
3009
+ resolvedConfig = {};
3010
+ /**
3011
+ * Creates a clone of the current context with the same configuration and workspace settings. This can be useful for running multiple builds in parallel or for creating isolated contexts for different parts of the build process.
3012
+ *
3013
+ * @remarks
3014
+ * The cloned context will have the same configuration and workspace settings as the original context, but will have a different build ID, release ID, and timestamp. The virtual file system and caches will also be separate between the original and cloned contexts.
3015
+ *
3016
+ * @returns The cloned context.
3017
+ */
3018
+ copyTo(context) {
3019
+ context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
3020
+ context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
3021
+ context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
3022
+ context.packageJson = (0, _stryke_helpers_deep_clone.deepClone)(this.packageJson);
3023
+ context.projectJson = this.projectJson ? (0, _stryke_helpers_deep_clone.deepClone)(this.projectJson) : void 0;
3024
+ context.tsconfig = (0, _stryke_helpers_deep_clone.deepClone)(this.tsconfig);
3025
+ context.$$internal = this.$$internal;
3026
+ return context;
3027
+ }
3028
+ /**
3029
+ * Initialize the context with the provided configuration options
3030
+ *
3031
+ * @remarks
3032
+ * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.
3033
+ *
3034
+ * @param options - The configuration options to initialize the context with
3035
+ */
3036
+ async init(options = {}) {
3037
+ await super.init(options);
3038
+ this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
3039
+ const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "project.json");
3040
+ if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
3041
+ const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "package.json");
3042
+ if ((0, _stryke_fs_exists.existsSync)(packageJsonPath)) {
3043
+ this.packageJson = await (0, _stryke_fs_json.readJsonFile)(packageJsonPath);
3044
+ this.options.organization ??= (0, _stryke_type_checks_is_set_object.isSetObject)(this.packageJson?.author) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.packageJson?.author?.name) : (0, _stryke_string_format_kebab_case.kebabCase)(this.packageJson?.author);
3045
+ }
3046
+ this.#checksum = await this.generateChecksum(this.options.root);
3047
+ const userConfig = this.configFile.config ? Array.isArray(this.configFile.config) && this.configFile.config.length > this.options.configIndex ? this.configFile.config[this.options.configIndex] : this.configFile.config : {};
3048
+ this.resolvedConfig = {
3049
+ ...this.options,
3050
+ ...userConfig,
3051
+ userConfig
3052
+ };
3053
+ }
3054
+ /**
3055
+ * Initialize the context with the provided configuration options
3056
+ */
3057
+ async innerSetup() {
3058
+ this.resolvedConfig.compatibilityDate = (0, compatx.resolveCompatibilityDates)(this.config.inlineConfig.compatibilityDate ?? this.config.userConfig.compatibilityDate ?? this.config.pluginConfig.compatibilityDate, "latest");
3059
+ this.resolvedConfig.output = (0, defu.default)(this.resolvedConfig.output ?? {}, {
3060
+ path: this.config.root ? (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.config.root, "dist"), this.config.cwd) : void 0,
3061
+ copy: { assets: [
3062
+ { glob: "LICENSE" },
3063
+ {
3064
+ input: this.config.root,
3065
+ glob: "*.md"
3066
+ },
3067
+ {
3068
+ input: this.config.root,
3069
+ glob: "package.json"
3070
+ }
3071
+ ] },
3072
+ artifactsPath: `.${this.config.framework ?? "powerlines"}`,
3073
+ dts: true,
3074
+ types: (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)
3075
+ });
3035
3076
  this.logger = {
3036
3077
  log: this.createLog(this.config.name),
3037
3078
  level: (0, _stryke_type_checks_is_null.isNull)(this.logLevel) ? "silent" : this.logLevel
@@ -3069,7 +3110,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3069
3110
  ret.push(plugin);
3070
3111
  return ret;
3071
3112
  }, []);
3072
- if (this.config.tsconfig) this.config.tsconfig = (0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.tsconfig);
3073
3113
  if (this.config.output.types) if ((0, _stryke_type_checks_is_set_string.isSetString)(this.config.output.types)) this.config.output.types = (0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.output.types);
3074
3114
  else this.config.output.types = (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`);
3075
3115
  if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = "debug";
@@ -3078,6 +3118,8 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3078
3118
  else this.config.output.sourceMap = false;
3079
3119
  if (!this.config.userConfig?.output?.minify && !this.config.inlineConfig?.output?.minify) if (this.config.mode === "production") this.config.output.minify = true;
3080
3120
  else this.config.output.minify = false;
3121
+ if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.options.cwd, this.options.root);
3122
+ else if (this.config.tsconfig) this.config.tsconfig = (0, _stryke_path_replace.replacePath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.tsconfig), this.config.cwd);
3081
3123
  if (this.config.output.copy && this.config.output.copy.assets) this.config.output.copy.assets = this.config.output.copy.assets.map((asset) => ({
3082
3124
  ...asset,
3083
3125
  glob: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.glob),
@@ -3088,54 +3130,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3088
3130
  if ((0, _stryke_type_checks_is_set_string.isSetString)(this.config.output?.storage) && this.config.output.storage === "virtual" || (0, _stryke_type_checks_is_set_object.isSetObject)(this.config.output?.storage) && Object.values(this.config.output.storage).every((adapter) => adapter.preset === "virtual")) this.config.output.overwrite = true;
3089
3131
  this.#fs ??= await VirtualFileSystem.create(this);
3090
3132
  }
3091
- /**
3092
- * The resolved configuration for this context
3093
- */
3094
- resolvedConfig = {};
3095
- /**
3096
- * Creates a clone of the current context with the same configuration and workspace settings. This can be useful for running multiple builds in parallel or for creating isolated contexts for different parts of the build process.
3097
- *
3098
- * @remarks
3099
- * The cloned context will have the same configuration and workspace settings as the original context, but will have a different build ID, release ID, and timestamp. The virtual file system and caches will also be separate between the original and cloned contexts.
3100
- *
3101
- * @returns The cloned context.
3102
- */
3103
- copyTo(context) {
3104
- context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
3105
- context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
3106
- context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
3107
- context.packageJson = (0, _stryke_helpers_deep_clone.deepClone)(this.packageJson);
3108
- context.projectJson = this.projectJson ? (0, _stryke_helpers_deep_clone.deepClone)(this.projectJson) : void 0;
3109
- context.tsconfig = (0, _stryke_helpers_deep_clone.deepClone)(this.tsconfig);
3110
- context.$$internal = this.$$internal;
3111
- return context;
3112
- }
3113
- /**
3114
- * Initialize the context with the provided configuration options
3115
- *
3116
- * @remarks
3117
- * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.
3118
- *
3119
- * @param options - The configuration options to initialize the context with
3120
- */
3121
- async init(options = {}) {
3122
- await super.init(options);
3123
- this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
3124
- const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "project.json");
3125
- if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
3126
- const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "package.json");
3127
- if ((0, _stryke_fs_exists.existsSync)(packageJsonPath)) {
3128
- this.packageJson = await (0, _stryke_fs_json.readJsonFile)(packageJsonPath);
3129
- this.options.organization ??= (0, _stryke_type_checks_is_set_object.isSetObject)(this.packageJson?.author) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.packageJson?.author?.name) : (0, _stryke_string_format_kebab_case.kebabCase)(this.packageJson?.author);
3130
- }
3131
- this.#checksum = await this.generateChecksum(this.options.root);
3132
- const userConfig = this.configFile.config ? Array.isArray(this.configFile.config) && this.configFile.config.length > this.options.configIndex ? this.configFile.config[this.options.configIndex] : this.configFile.config : {};
3133
- this.resolvedConfig = {
3134
- ...this.options,
3135
- ...userConfig,
3136
- userConfig
3137
- };
3138
- }
3139
3133
  };
3140
3134
 
3141
3135
  //#endregion
@@ -3359,10 +3353,9 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3359
3353
  * @param config - The user configuration options.
3360
3354
  * @returns A promise that resolves to the new context.
3361
3355
  */
3362
- static async fromConfig(options, config) {
3363
- const context = new PowerlinesEnvironmentContext(options, config);
3364
- await context.init(options);
3365
- await context.setup(config);
3356
+ static async fromConfig(options, config, environment) {
3357
+ const context = new PowerlinesEnvironmentContext(options, config, environment);
3358
+ await context.setup();
3366
3359
  const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
3367
3360
  if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
3368
3361
  context.powerlinesPath = powerlinesPath;
@@ -3404,9 +3397,19 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3404
3397
  * @returns A promise that resolves to the cloned context.
3405
3398
  */
3406
3399
  async clone() {
3407
- const context = await PowerlinesEnvironmentContext.fromConfig(this.options, this.config);
3400
+ const context = await PowerlinesEnvironmentContext.fromConfig((0, _stryke_helpers_deep_clone.deepClone)(this.options), (0, _stryke_helpers_deep_clone.deepClone)(this.config), (0, _stryke_helpers_deep_clone.deepClone)(this.environment));
3408
3401
  return this.copyTo(context);
3409
3402
  }
3403
+ /**
3404
+ * Initialize the context with the provided configuration options
3405
+ */
3406
+ async setup() {
3407
+ this.resolvedConfig = (0, _powerlines_core_plugin_utils.mergeConfig)({
3408
+ name: this.config.name,
3409
+ title: this.config.title
3410
+ }, getConfigProps(this.environment, this.options.root, this.options.cwd), this.config);
3411
+ await this.innerSetup();
3412
+ }
3410
3413
  async addPlugin(plugin) {
3411
3414
  let resolvedPlugin = plugin;
3412
3415
  if ((0, _stryke_type_checks_is_function.isFunction)(plugin.applyToEnvironment)) {
@@ -3459,9 +3462,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3459
3462
  }
3460
3463
  return result;
3461
3464
  }
3462
- constructor(options, config) {
3465
+ constructor(options, config, environment) {
3463
3466
  super(options);
3464
3467
  this.resolvedConfig = config;
3468
+ this.environment = environment;
3465
3469
  }
3466
3470
  /**
3467
3471
  * Creates a clone of the current context with the same configuration and workspace settings. This can be useful for running multiple builds in parallel or for creating isolated contexts for different parts of the build process.
@@ -3511,7 +3515,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3511
3515
  if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
3512
3516
  context.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
3513
3517
  }
3514
- await context.setup(config);
3518
+ await context.setup();
3515
3519
  const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
3516
3520
  if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
3517
3521
  context.powerlinesPath = powerlinesPath;
@@ -3567,48 +3571,33 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3567
3571
  */
3568
3572
  async clone() {
3569
3573
  const clone = await PowerlinesExecutionContext.fromOptions(this.options);
3570
- clone.config.userConfig = this.config.userConfig;
3571
- await clone.setup(this.config.inlineConfig);
3574
+ clone.config.userConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.userConfig);
3575
+ clone.config.inlineConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.inlineConfig);
3576
+ clone.config.pluginConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.pluginConfig);
3577
+ await clone.setup();
3578
+ clone.$$internal = this.$$internal;
3572
3579
  return this.copyTo(clone);
3573
3580
  }
3574
3581
  /**
3575
- * Initialize the context with the provided configuration options
3576
- *
3577
- * @param options - The resolved execution options to use for initialization.
3578
- */
3579
- async init(options) {
3580
- await super.init(options);
3581
- await Promise.all((0, _stryke_convert_to_array.toArray)(this.config.environments && Object.keys(this.config.environments).length > 0 ? Object.keys(this.config.environments).map((name) => createEnvironment(name, this.config)) : createDefaultEnvironment(this.config)).map(async (env) => {
3582
- this.#environments[env.name] = await this.in(env);
3583
- }));
3584
- }
3585
- /**
3586
3582
  * A function to copy the context and update the fields for a specific environment
3587
3583
  *
3588
3584
  * @param environment - The environment configuration to use.
3589
3585
  * @returns A new context instance with the updated environment.
3590
3586
  */
3591
3587
  async in(environment) {
3592
- let context;
3593
- if (this.environments[environment.name]) context = this.environments[environment.name];
3594
- else context = await PowerlinesEnvironmentContext.fromConfig(this.options, this.config);
3595
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.config.inlineConfig)) await context.setup(this.config.inlineConfig);
3596
- context.environment = environment;
3588
+ const context = await PowerlinesEnvironmentContext.fromConfig((0, _stryke_helpers_deep_clone.deepClone)(this.options), (0, _stryke_helpers_deep_clone.deepClone)(this.config), (0, _stryke_helpers_deep_clone.deepClone)(environment));
3589
+ context.$$internal = this.$$internal;
3597
3590
  context.plugins = [];
3598
3591
  for (const plugin of this.plugins) await context.addPlugin(plugin);
3599
3592
  return context;
3600
3593
  }
3601
3594
  /**
3602
3595
  * Update the context using a new inline configuration options
3603
- *
3604
- * @param config - The new inline configuration options.
3605
3596
  */
3606
- async setup(config) {
3607
- await super.setup(config);
3597
+ async setup() {
3598
+ await super.setup();
3608
3599
  await Promise.all((0, _stryke_convert_to_array.toArray)(this.config.environments && Object.keys(this.config.environments).length > 0 ? Object.keys(this.config.environments).map((name) => createEnvironment(name, this.config)) : createDefaultEnvironment(this.config)).map(async (env) => {
3609
- const context = await this.in(env);
3610
- await context.setup(config);
3611
- this.#environments[env.name] = context;
3600
+ this.#environments[env.name] = await this.in(env);
3612
3601
  }));
3613
3602
  }
3614
3603
  /**
@@ -3637,7 +3626,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3637
3626
  }
3638
3627
  if (!environment) {
3639
3628
  if (name) throw new Error(`Environment "${name}" not found.`);
3640
- environment = await this.in(createDefaultEnvironment(this.config.userConfig));
3629
+ environment = await this.in(createDefaultEnvironment(this.config));
3641
3630
  this.warn(`No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment?.environment.name)}`);
3642
3631
  }
3643
3632
  return environment;
@@ -3666,7 +3655,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3666
3655
  async toEnvironment() {
3667
3656
  let environment;
3668
3657
  if (Object.keys(this.environments).length > 1) {
3669
- environment = await this.in(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config.userConfig));
3658
+ environment = await this.in(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config));
3670
3659
  this.debug(`Combined all ${Object.keys(this.environments).length} environments into a single global context.`);
3671
3660
  } else environment = await this.getEnvironment();
3672
3661
  return environment;
@@ -4429,7 +4418,7 @@ ${formatTypes(code)}
4429
4418
  static async fromConfig(options, config) {
4430
4419
  const api = new PowerlinesExecution(await PowerlinesExecutionContext.fromOptions(options));
4431
4420
  api.#context.config.inlineConfig = config;
4432
- await api.#context.setup(config);
4421
+ await api.#context.setup();
4433
4422
  api.#context.$$internal = {
4434
4423
  api,
4435
4424
  addPlugin: api.addPlugin.bind(api)
@@ -4446,7 +4435,7 @@ ${formatTypes(code)}
4446
4435
  });
4447
4436
  if (pluginConfig) {
4448
4437
  api.#context.config.pluginConfig = pluginConfig;
4449
- await api.#context.setup(pluginConfig);
4438
+ await api.#context.setup();
4450
4439
  }
4451
4440
  timer();
4452
4441
  return api;
@@ -4462,7 +4451,8 @@ ${formatTypes(code)}
4462
4451
  async types(inlineConfig = { command: "types" }) {
4463
4452
  this.context.debug(" Aggregating configuration options for the Powerlines project");
4464
4453
  inlineConfig.command ??= "types";
4465
- await this.context.setup(inlineConfig);
4454
+ this.context.config.inlineConfig = inlineConfig;
4455
+ await this.context.setup();
4466
4456
  await this.#executeEnvironments(async (context) => {
4467
4457
  context.debug(`Initializing the processing options for the Powerlines project.`);
4468
4458
  await this.callHook("configResolved", {
@@ -4512,7 +4502,8 @@ ${formatTypes(code)}
4512
4502
  */
4513
4503
  async prepare(inlineConfig = { command: "prepare" }) {
4514
4504
  inlineConfig.command ??= "prepare";
4515
- await this.context.setup(inlineConfig);
4505
+ this.context.config.inlineConfig = inlineConfig;
4506
+ await this.context.setup();
4516
4507
  await this.#executeEnvironments(async (context) => {
4517
4508
  context.debug(`Initializing the processing options for the Powerlines project.`);
4518
4509
  await this.callHook("configResolved", {
@@ -4672,11 +4663,14 @@ ${formatTypes(code)}
4672
4663
  * @returns A promise that resolves when the build command has completed
4673
4664
  */
4674
4665
  async build(inlineConfig = { command: "build" }) {
4666
+ inlineConfig.command ??= "build";
4675
4667
  await this.context.generateChecksum();
4676
4668
  if (this.context.meta.checksum !== this.context.persistedMeta?.checksum || this.context.config.skipCache) {
4677
4669
  this.context.info(!this.context.persistedMeta?.checksum ? "No previous build cache found. Preparing the project for the initial build." : this.context.meta.checksum !== this.context.persistedMeta.checksum ? "The project has been modified since the last time `prepare` was ran. Re-preparing the project." : "The project is configured to skip cache. Re-preparing the project.");
4678
- inlineConfig.command ??= "build";
4679
4670
  await this.prepare(inlineConfig);
4671
+ } else {
4672
+ this.context.config.inlineConfig = inlineConfig;
4673
+ await this.context.setup();
4680
4674
  }
4681
4675
  if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
4682
4676
  else await this.#executeEnvironments(async (context) => {