@powerlines/engine 0.0.15 → 0.0.17

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.
@@ -17,6 +17,7 @@ let defu = require("defu");
17
17
  defu = require_chunk.__toESM(defu, 1);
18
18
  let _stryke_path_join_paths = require("@stryke/path/join-paths");
19
19
  let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
20
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
20
21
  let _powerlines_core_lib_utilities_format = require("@powerlines/core/lib/utilities/format");
21
22
  let _powerlines_core_plugin_utils = require("@powerlines/core/plugin-utils");
22
23
  let _stryke_convert_to_array = require("@stryke/convert/to-array");
@@ -29,14 +30,13 @@ let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
29
30
  let _stryke_path_replace = require("@stryke/path/replace");
30
31
  let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
31
32
  let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
32
- let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
33
33
  let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
34
34
  let _stryke_fs_json = require("@stryke/fs/json");
35
+ let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
35
36
  let _powerlines_core_lib_entry = require("@powerlines/core/lib/entry");
36
37
  let _stryke_fs_get_workspace_root = require("@stryke/fs/get-workspace-root");
37
38
  let _stryke_hash = require("@stryke/hash");
38
39
  let _stryke_hash_node = require("@stryke/hash/node");
39
- let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
40
40
  let _stryke_http_fetch = require("@stryke/http/fetch");
41
41
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
42
42
  let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
@@ -60,12 +60,12 @@ let node_url = require("node:url");
60
60
  let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
61
61
 
62
62
  //#region src/_internal/helpers/environment.ts
63
- function createEnvironment(name, userConfig) {
64
- return (0, defu.default)(userConfig.environments?.[name] ?? {}, {
63
+ function createEnvironment(name, config = {}) {
64
+ return (0, defu.default)(config.environments?.[name] ?? {}, {
65
65
  name,
66
- title: userConfig.title || (0, _stryke_string_format_title_case.titleCase)(userConfig.name),
66
+ title: config.title ?? (0, _stryke_string_format_title_case.titleCase)(config.name),
67
67
  ssr: false,
68
- mainFields: userConfig?.platform === "browser" ? [
68
+ resolve: { mainFields: config.platform === "browser" ? [
69
69
  "browser",
70
70
  "module",
71
71
  "jsnext:main",
@@ -74,18 +74,9 @@ function createEnvironment(name, userConfig) {
74
74
  "module",
75
75
  "jsnext:main",
76
76
  "jsnext"
77
- ],
78
- extensions: [
79
- ".mjs",
80
- ".js",
81
- ".mts",
82
- ".ts",
83
- ".jsx",
84
- ".tsx",
85
- ".json"
86
- ],
87
- consumer: userConfig?.platform === "browser" ? "client" : "server",
88
- preview: userConfig?.platform === "browser" ? {
77
+ ] },
78
+ consumer: config.platform === "browser" ? "client" : "server",
79
+ preview: config.platform === "browser" ? {
89
80
  port: 5173,
90
81
  open: true,
91
82
  strictPort: false,
@@ -94,10 +85,37 @@ function createEnvironment(name, userConfig) {
94
85
  cors: true,
95
86
  headers: {}
96
87
  } : void 0
97
- }, userConfig);
88
+ });
98
89
  }
99
- function createDefaultEnvironment(userConfig) {
100
- return createEnvironment(_powerlines_core_constants.DEFAULT_ENVIRONMENT, userConfig);
90
+ function createDefaultEnvironment(config = {}) {
91
+ return createEnvironment(_powerlines_core_constants.DEFAULT_ENVIRONMENT, config);
92
+ }
93
+
94
+ //#endregion
95
+ //#region src/_internal/helpers/context.ts
96
+ function getConfigProps(config = {}, root, cwd) {
97
+ return {
98
+ name: config.name,
99
+ title: config.title,
100
+ description: config.description,
101
+ projectType: config.projectType,
102
+ customLogger: config.customLogger,
103
+ logLevel: config.logLevel,
104
+ tsconfig: config.tsconfig,
105
+ tsconfigRaw: config.tsconfigRaw,
106
+ skipCache: config.skipCache,
107
+ autoInstall: config.autoInstall,
108
+ input: (0, _stryke_type_checks_is_set_string.isSetString)(config.input) ? [config.input] : config.input,
109
+ plugins: config.plugins,
110
+ mode: config.mode,
111
+ resolve: config.resolve,
112
+ framework: config.framework,
113
+ ...config,
114
+ output: {
115
+ ...config.output ?? {},
116
+ path: config.output?.path ? (0, _stryke_path_append.appendPath)(config.output.path, (0, _stryke_path_append.appendPath)(root, cwd)) : void 0
117
+ }
118
+ };
101
119
  }
102
120
 
103
121
  //#endregion
@@ -1232,35 +1250,6 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
1232
1250
  #tsconfig;
1233
1251
  #parserCache;
1234
1252
  #requestCache;
1235
- #getConfigProps(config = {}) {
1236
- return (0, _powerlines_core_plugin_utils.mergeConfig)({
1237
- name: config.name,
1238
- title: config.title,
1239
- compatibilityDate: (0, compatx.resolveCompatibilityDates)(config.compatibilityDate, "latest"),
1240
- description: config.description,
1241
- projectType: config.projectType,
1242
- customLogger: config.customLogger,
1243
- logLevel: config.logLevel,
1244
- tsconfig: config.tsconfig,
1245
- tsconfigRaw: config.tsconfigRaw,
1246
- skipCache: config.skipCache,
1247
- autoInstall: config.autoInstall,
1248
- input: (0, _stryke_type_checks_is_set_string.isSetString)(config.input) ? [config.input] : config.input,
1249
- plugins: config.plugins,
1250
- mode: config.mode,
1251
- resolve: config.resolve,
1252
- framework: config.framework,
1253
- ...config,
1254
- output: {
1255
- ...config.output ?? {},
1256
- 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
1257
- }
1258
- }, { output: config.framework ? {
1259
- artifactsPath: `.${config.framework ?? "powerlines"}`,
1260
- dts: true,
1261
- types: (0, _stryke_path_join.joinPaths)(this.config.root, `${config.framework ?? "powerlines"}.d.ts`)
1262
- } : {} });
1263
- }
1264
1253
  /**
1265
1254
  * Create a new Storm context from the workspace root and user config.
1266
1255
  *
@@ -1875,36 +1864,16 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
1875
1864
  }
1876
1865
  /**
1877
1866
  * Initialize the context with the provided configuration options
1878
- *
1879
- * @param config - The partial configuration options to initialize the context with
1880
1867
  */
1881
- async setup(config) {
1868
+ async setup() {
1882
1869
  this.resolvedConfig = (0, _powerlines_core_plugin_utils.mergeConfig)({
1883
1870
  inlineConfig: this.config.inlineConfig ?? {},
1884
1871
  userConfig: this.config.userConfig ?? {},
1885
- pluginConfig: this.config.pluginConfig ?? {},
1886
- tsconfig: require_tsconfig.getTsconfigFilePath(this.options.cwd, this.options.root, config.tsconfig || this.config.tsconfig)
1887
- }, this.options, this.#getConfigProps(config), this.#getConfigProps(this.config), {
1872
+ pluginConfig: this.config.pluginConfig ?? {}
1873
+ }, 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) : {}, {
1888
1874
  name: this.projectJson?.name || this.packageJson?.name,
1889
1875
  version: this.packageJson?.version,
1890
- description: this.packageJson?.description,
1891
- output: (0, _powerlines_core_plugin_utils.mergeConfig)(this.config.output ?? {}, {
1892
- path: this.config.root ? (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.config.root, "dist"), this.config.cwd) : void 0,
1893
- copy: { assets: [
1894
- { glob: "LICENSE" },
1895
- {
1896
- input: this.config.root,
1897
- glob: "*.md"
1898
- },
1899
- {
1900
- input: this.config.root,
1901
- glob: "package.json"
1902
- }
1903
- ] },
1904
- artifactsPath: `.${this.config.framework ?? "powerlines"}`,
1905
- dts: true,
1906
- types: (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)
1907
- })
1876
+ description: this.packageJson?.description
1908
1877
  }, {
1909
1878
  projectType: "application",
1910
1879
  platform: "neutral",
@@ -1913,6 +1882,78 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
1913
1882
  environments: {},
1914
1883
  resolve: {}
1915
1884
  });
1885
+ await this.innerSetup();
1886
+ }
1887
+ /**
1888
+ * The resolved configuration for this context
1889
+ */
1890
+ resolvedConfig = {};
1891
+ /**
1892
+ * 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.
1893
+ *
1894
+ * @remarks
1895
+ * 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.
1896
+ *
1897
+ * @returns The cloned context.
1898
+ */
1899
+ copyTo(context) {
1900
+ context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
1901
+ context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
1902
+ context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
1903
+ context.packageJson = (0, _stryke_helpers_deep_clone.deepClone)(this.packageJson);
1904
+ context.projectJson = this.projectJson ? (0, _stryke_helpers_deep_clone.deepClone)(this.projectJson) : void 0;
1905
+ context.tsconfig = (0, _stryke_helpers_deep_clone.deepClone)(this.tsconfig);
1906
+ context.$$internal = this.$$internal;
1907
+ return context;
1908
+ }
1909
+ /**
1910
+ * Initialize the context with the provided configuration options
1911
+ *
1912
+ * @remarks
1913
+ * 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.
1914
+ *
1915
+ * @param options - The configuration options to initialize the context with
1916
+ */
1917
+ async init(options = {}) {
1918
+ await super.init(options);
1919
+ this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
1920
+ const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "project.json");
1921
+ if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
1922
+ const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "package.json");
1923
+ if ((0, _stryke_fs_exists.existsSync)(packageJsonPath)) {
1924
+ this.packageJson = await (0, _stryke_fs_json.readJsonFile)(packageJsonPath);
1925
+ 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);
1926
+ }
1927
+ this.#checksum = await this.generateChecksum(this.options.root);
1928
+ 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 : {};
1929
+ this.resolvedConfig = {
1930
+ ...this.options,
1931
+ ...userConfig,
1932
+ userConfig
1933
+ };
1934
+ }
1935
+ /**
1936
+ * Initialize the context with the provided configuration options
1937
+ */
1938
+ async innerSetup() {
1939
+ this.resolvedConfig.compatibilityDate = (0, compatx.resolveCompatibilityDates)(this.config.inlineConfig.compatibilityDate ?? this.config.userConfig.compatibilityDate ?? this.config.pluginConfig.compatibilityDate, "latest");
1940
+ this.resolvedConfig.output = (0, defu.default)(this.resolvedConfig.output ?? {}, {
1941
+ path: this.config.root ? (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.config.root, "dist"), this.config.cwd) : void 0,
1942
+ copy: { assets: [
1943
+ { glob: "LICENSE" },
1944
+ {
1945
+ input: this.config.root,
1946
+ glob: "*.md"
1947
+ },
1948
+ {
1949
+ input: this.config.root,
1950
+ glob: "package.json"
1951
+ }
1952
+ ] },
1953
+ artifactsPath: `.${this.config.framework ?? "powerlines"}`,
1954
+ dts: true,
1955
+ types: (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)
1956
+ });
1916
1957
  this.logger = {
1917
1958
  log: this.createLog(this.config.name),
1918
1959
  level: (0, _stryke_type_checks_is_null.isNull)(this.logLevel) ? "silent" : this.logLevel
@@ -1950,7 +1991,6 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
1950
1991
  ret.push(plugin);
1951
1992
  return ret;
1952
1993
  }, []);
1953
- if (this.config.tsconfig) this.config.tsconfig = (0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.tsconfig);
1954
1994
  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);
1955
1995
  else this.config.output.types = (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`);
1956
1996
  if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = "debug";
@@ -1959,6 +1999,8 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
1959
1999
  else this.config.output.sourceMap = false;
1960
2000
  if (!this.config.userConfig?.output?.minify && !this.config.inlineConfig?.output?.minify) if (this.config.mode === "production") this.config.output.minify = true;
1961
2001
  else this.config.output.minify = false;
2002
+ if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = require_tsconfig.getTsconfigFilePath(this.options.cwd, this.options.root);
2003
+ 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);
1962
2004
  if (this.config.output.copy && this.config.output.copy.assets) this.config.output.copy.assets = this.config.output.copy.assets.map((asset) => ({
1963
2005
  ...asset,
1964
2006
  glob: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.glob),
@@ -1969,54 +2011,6 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
1969
2011
  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;
1970
2012
  this.#fs ??= await VirtualFileSystem.create(this);
1971
2013
  }
1972
- /**
1973
- * The resolved configuration for this context
1974
- */
1975
- resolvedConfig = {};
1976
- /**
1977
- * 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.
1978
- *
1979
- * @remarks
1980
- * 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.
1981
- *
1982
- * @returns The cloned context.
1983
- */
1984
- copyTo(context) {
1985
- context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
1986
- context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
1987
- context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
1988
- context.packageJson = (0, _stryke_helpers_deep_clone.deepClone)(this.packageJson);
1989
- context.projectJson = this.projectJson ? (0, _stryke_helpers_deep_clone.deepClone)(this.projectJson) : void 0;
1990
- context.tsconfig = (0, _stryke_helpers_deep_clone.deepClone)(this.tsconfig);
1991
- context.$$internal = this.$$internal;
1992
- return context;
1993
- }
1994
- /**
1995
- * Initialize the context with the provided configuration options
1996
- *
1997
- * @remarks
1998
- * 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.
1999
- *
2000
- * @param options - The configuration options to initialize the context with
2001
- */
2002
- async init(options = {}) {
2003
- await super.init(options);
2004
- this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
2005
- const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "project.json");
2006
- if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
2007
- const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.root, "package.json");
2008
- if ((0, _stryke_fs_exists.existsSync)(packageJsonPath)) {
2009
- this.packageJson = await (0, _stryke_fs_json.readJsonFile)(packageJsonPath);
2010
- 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);
2011
- }
2012
- this.#checksum = await this.generateChecksum(this.options.root);
2013
- 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 : {};
2014
- this.resolvedConfig = {
2015
- ...this.options,
2016
- ...userConfig,
2017
- userConfig
2018
- };
2019
- }
2020
2014
  };
2021
2015
 
2022
2016
  //#endregion
@@ -2240,10 +2234,9 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2240
2234
  * @param config - The user configuration options.
2241
2235
  * @returns A promise that resolves to the new context.
2242
2236
  */
2243
- static async fromConfig(options, config) {
2244
- const context = new PowerlinesEnvironmentContext(options, config);
2245
- await context.init(options);
2246
- await context.setup(config);
2237
+ static async fromConfig(options, config, environment) {
2238
+ const context = new PowerlinesEnvironmentContext(options, config, environment);
2239
+ await context.setup();
2247
2240
  const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
2248
2241
  if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
2249
2242
  context.powerlinesPath = powerlinesPath;
@@ -2285,9 +2278,19 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2285
2278
  * @returns A promise that resolves to the cloned context.
2286
2279
  */
2287
2280
  async clone() {
2288
- const context = await PowerlinesEnvironmentContext.fromConfig(this.options, this.config);
2281
+ 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));
2289
2282
  return this.copyTo(context);
2290
2283
  }
2284
+ /**
2285
+ * Initialize the context with the provided configuration options
2286
+ */
2287
+ async setup() {
2288
+ this.resolvedConfig = (0, _powerlines_core_plugin_utils.mergeConfig)({
2289
+ name: this.config.name,
2290
+ title: this.config.title
2291
+ }, getConfigProps(this.environment, this.options.root, this.options.cwd), this.config);
2292
+ await this.innerSetup();
2293
+ }
2291
2294
  async addPlugin(plugin) {
2292
2295
  let resolvedPlugin = plugin;
2293
2296
  if ((0, _stryke_type_checks_is_function.isFunction)(plugin.applyToEnvironment)) {
@@ -2340,9 +2343,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2340
2343
  }
2341
2344
  return result;
2342
2345
  }
2343
- constructor(options, config) {
2346
+ constructor(options, config, environment) {
2344
2347
  super(options);
2345
2348
  this.resolvedConfig = config;
2349
+ this.environment = environment;
2346
2350
  }
2347
2351
  /**
2348
2352
  * 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.
@@ -2392,7 +2396,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2392
2396
  if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
2393
2397
  context.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
2394
2398
  }
2395
- await context.setup(config);
2399
+ await context.setup();
2396
2400
  const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
2397
2401
  if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
2398
2402
  context.powerlinesPath = powerlinesPath;
@@ -2448,48 +2452,32 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2448
2452
  */
2449
2453
  async clone() {
2450
2454
  const clone = await PowerlinesExecutionContext.fromOptions(this.options);
2451
- clone.config.userConfig = this.config.userConfig;
2452
- await clone.setup(this.config.inlineConfig);
2455
+ clone.config.userConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.userConfig);
2456
+ clone.config.inlineConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.inlineConfig);
2457
+ clone.config.pluginConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.pluginConfig);
2458
+ await clone.setup();
2459
+ clone.$$internal = this.$$internal;
2453
2460
  return this.copyTo(clone);
2454
2461
  }
2455
2462
  /**
2456
- * Initialize the context with the provided configuration options
2457
- *
2458
- * @param options - The resolved execution options to use for initialization.
2459
- */
2460
- async init(options) {
2461
- await super.init(options);
2462
- 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) => {
2463
- this.#environments[env.name] = await this.in(env);
2464
- }));
2465
- }
2466
- /**
2467
2463
  * A function to copy the context and update the fields for a specific environment
2468
2464
  *
2469
2465
  * @param environment - The environment configuration to use.
2470
2466
  * @returns A new context instance with the updated environment.
2471
2467
  */
2472
2468
  async in(environment) {
2473
- let context;
2474
- if (this.environments[environment.name]) context = this.environments[environment.name];
2475
- else context = await PowerlinesEnvironmentContext.fromConfig(this.options, this.config);
2476
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.config.inlineConfig)) await context.setup(this.config.inlineConfig);
2477
- context.environment = environment;
2469
+ const context = this.copyTo(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)));
2478
2470
  context.plugins = [];
2479
2471
  for (const plugin of this.plugins) await context.addPlugin(plugin);
2480
2472
  return context;
2481
2473
  }
2482
2474
  /**
2483
2475
  * Update the context using a new inline configuration options
2484
- *
2485
- * @param config - The new inline configuration options.
2486
2476
  */
2487
- async setup(config) {
2488
- await super.setup(config);
2477
+ async setup() {
2478
+ await super.setup();
2489
2479
  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) => {
2490
- const context = await this.in(env);
2491
- await context.setup(config);
2492
- this.#environments[env.name] = context;
2480
+ this.#environments[env.name] = await this.in(env);
2493
2481
  }));
2494
2482
  }
2495
2483
  /**
@@ -2518,7 +2506,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2518
2506
  }
2519
2507
  if (!environment) {
2520
2508
  if (name) throw new Error(`Environment "${name}" not found.`);
2521
- environment = await this.in(createDefaultEnvironment(this.config.userConfig));
2509
+ environment = await this.in(createDefaultEnvironment(this.config));
2522
2510
  this.warn(`No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment?.environment.name)}`);
2523
2511
  }
2524
2512
  return environment;
@@ -2547,7 +2535,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2547
2535
  async toEnvironment() {
2548
2536
  let environment;
2549
2537
  if (Object.keys(this.environments).length > 1) {
2550
- environment = await this.in(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config.userConfig));
2538
+ environment = await this.in(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config));
2551
2539
  this.debug(`Combined all ${Object.keys(this.environments).length} environments into a single global context.`);
2552
2540
  } else environment = await this.getEnvironment();
2553
2541
  return environment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/engine",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "private": false,
5
5
  "description": "An internal package containing the core engine modules for Powerlines.",
6
6
  "homepage": "https://stormsoftware.com",
@@ -137,7 +137,7 @@
137
137
  "@cacheable/memory": "^2.0.8",
138
138
  "@donedeal0/superdiff": "^3.2.0",
139
139
  "@jridgewell/sourcemap-codec": "^1.5.5",
140
- "@powerlines/core": "^0.13.23",
140
+ "@powerlines/core": "^0.13.24",
141
141
  "@storm-software/config": "^1.137.31",
142
142
  "@storm-software/config-tools": "^1.189.77",
143
143
  "@stryke/capnp": "^0.12.92",
@@ -179,5 +179,5 @@
179
179
  "typescript": "^6.0.3",
180
180
  "undici-types": "^7.25.0"
181
181
  },
182
- "gitHead": "026a6f082ae5efe2fe607e3ba27eebdf01db89e0"
182
+ "gitHead": "182725c5b044a748506a1b46fd9cf72627b600b4"
183
183
  }