@powerlines/plugin-webpack 0.5.126 → 0.5.127

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.
Files changed (87) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  2. package/dist/helpers/index.cjs +3 -1
  3. package/dist/helpers/index.mjs +3 -1
  4. package/dist/helpers/unplugin.cjs +12 -1
  5. package/dist/helpers/unplugin.mjs +11 -1
  6. package/dist/index.cjs +39 -1
  7. package/dist/index.mjs +33 -1
  8. package/dist/powerlines/schemas/fs.cjs +226 -1
  9. package/dist/powerlines/schemas/fs.mjs +224 -1
  10. package/dist/powerlines/src/api.cjs +576 -9
  11. package/dist/powerlines/src/api.mjs +578 -1
  12. package/dist/powerlines/src/internal/babel/module-resolver-plugin.cjs +86 -1
  13. package/dist/powerlines/src/internal/babel/module-resolver-plugin.mjs +84 -1
  14. package/dist/powerlines/src/internal/helpers/environment.cjs +52 -1
  15. package/dist/powerlines/src/internal/helpers/environment.mjs +48 -1
  16. package/dist/powerlines/src/internal/helpers/generate-types.cjs +50 -7
  17. package/dist/powerlines/src/internal/helpers/generate-types.mjs +48 -7
  18. package/dist/powerlines/src/internal/helpers/hooks.cjs +63 -1
  19. package/dist/powerlines/src/internal/helpers/hooks.mjs +61 -1
  20. package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +25 -3
  21. package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +24 -3
  22. package/dist/powerlines/src/internal/helpers/install.cjs +37 -1
  23. package/dist/powerlines/src/internal/helpers/install.mjs +36 -1
  24. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +97 -7
  25. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +93 -7
  26. package/dist/powerlines/src/internal/helpers/resolver.cjs +43 -1
  27. package/dist/powerlines/src/internal/helpers/resolver.mjs +41 -1
  28. package/dist/powerlines/src/lib/build/webpack.cjs +47 -1
  29. package/dist/powerlines/src/lib/build/webpack.mjs +45 -1
  30. package/dist/powerlines/src/lib/config-file.cjs +79 -1
  31. package/dist/powerlines/src/lib/config-file.mjs +76 -1
  32. package/dist/powerlines/src/lib/contexts/api-context.cjs +184 -1
  33. package/dist/powerlines/src/lib/contexts/api-context.mjs +182 -1
  34. package/dist/powerlines/src/lib/contexts/context.cjs +931 -1
  35. package/dist/powerlines/src/lib/contexts/context.mjs +929 -1
  36. package/dist/powerlines/src/lib/contexts/environment-context.cjs +160 -1
  37. package/dist/powerlines/src/lib/contexts/environment-context.mjs +159 -1
  38. package/dist/powerlines/src/lib/contexts/plugin-context.cjs +75 -1
  39. package/dist/powerlines/src/lib/contexts/plugin-context.mjs +74 -1
  40. package/dist/powerlines/src/lib/entry.cjs +69 -1
  41. package/dist/powerlines/src/lib/entry.mjs +67 -1
  42. package/dist/powerlines/src/lib/fs/helpers.cjs +85 -1
  43. package/dist/powerlines/src/lib/fs/helpers.mjs +81 -1
  44. package/dist/powerlines/src/lib/fs/storage/base.cjs +196 -1
  45. package/dist/powerlines/src/lib/fs/storage/base.mjs +195 -1
  46. package/dist/powerlines/src/lib/fs/storage/file-system.cjs +170 -1
  47. package/dist/powerlines/src/lib/fs/storage/file-system.mjs +169 -1
  48. package/dist/powerlines/src/lib/fs/storage/virtual.cjs +88 -1
  49. package/dist/powerlines/src/lib/fs/storage/virtual.mjs +87 -1
  50. package/dist/powerlines/src/lib/fs/vfs.cjs +830 -1
  51. package/dist/powerlines/src/lib/fs/vfs.mjs +828 -1
  52. package/dist/powerlines/src/lib/logger.cjs +58 -1
  53. package/dist/powerlines/src/lib/logger.mjs +55 -1
  54. package/dist/powerlines/src/lib/typescript/ts-morph.cjs +104 -1
  55. package/dist/powerlines/src/lib/typescript/ts-morph.mjs +102 -1
  56. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +149 -4
  57. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +144 -4
  58. package/dist/powerlines/src/lib/unplugin/factory.cjs +6 -1
  59. package/dist/powerlines/src/lib/unplugin/factory.mjs +8 -1
  60. package/dist/powerlines/src/lib/unplugin/helpers.cjs +17 -1
  61. package/dist/powerlines/src/lib/unplugin/helpers.mjs +16 -1
  62. package/dist/powerlines/src/lib/unplugin/index.cjs +3 -1
  63. package/dist/powerlines/src/lib/unplugin/index.mjs +5 -1
  64. package/dist/powerlines/src/lib/unplugin/plugin.cjs +127 -5
  65. package/dist/powerlines/src/lib/unplugin/plugin.mjs +126 -5
  66. package/dist/powerlines/src/lib/utilities/file-header.cjs +19 -7
  67. package/dist/powerlines/src/lib/utilities/file-header.mjs +18 -7
  68. package/dist/powerlines/src/lib/utilities/meta.cjs +45 -1
  69. package/dist/powerlines/src/lib/utilities/meta.mjs +41 -1
  70. package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -1
  71. package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -1
  72. package/dist/powerlines/src/plugin-utils/helpers.cjs +148 -1
  73. package/dist/powerlines/src/plugin-utils/helpers.mjs +138 -1
  74. package/dist/powerlines/src/plugin-utils/paths.cjs +36 -1
  75. package/dist/powerlines/src/plugin-utils/paths.mjs +35 -1
  76. package/dist/powerlines/src/types/build.cjs +15 -1
  77. package/dist/powerlines/src/types/build.mjs +14 -1
  78. package/dist/powerlines/src/types/commands.cjs +16 -1
  79. package/dist/powerlines/src/types/commands.mjs +15 -1
  80. package/dist/powerlines/src/types/config.d.mts +1 -0
  81. package/dist/powerlines/src/types/context.d.cts +27 -3
  82. package/dist/powerlines/src/types/context.d.mts +27 -3
  83. package/dist/powerlines/src/types/plugin.cjs +32 -1
  84. package/dist/powerlines/src/types/plugin.mjs +31 -1
  85. package/dist/types/index.mjs +1 -1
  86. package/dist/types/plugin.mjs +1 -1
  87. package/package.json +9 -9
@@ -1 +1,184 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../internal/helpers/environment.cjs`),n=require(`../config-file.cjs`),r=require(`./context.cjs`),i=require(`./environment-context.cjs`);let a=require(`@storm-software/config-tools/types`),o=require(`@stryke/convert/to-array`),s=require(`@stryke/fs/resolve`),c=require(`@stryke/type-checks/is-set-object`),l=require(`chalk`);l=e.__toESM(l);var u=class e extends r.PowerlinesContext{#e={};#t=[];#n;static async from(t,r){let i=new e(await n.loadWorkspaceConfig(t,r.root));await i.withUserConfig(r);let a=await(0,s.resolvePackage)(`powerlines`);if(!a)throw Error("Could not resolve `powerlines` package location.");return i.powerlinesPath=a,i}get $$internal(){return super.$$internal}set $$internal(e){super.$$internal=e;for(let e of Object.values(this.environments))e.$$internal=super.$$internal}get environments(){return this.#e}get log(){return this.#n||=this.createLog(),this.#n}get plugins(){return this.#t}constructor(e){super(e)}async init(e={}){await super.init(e),await Promise.all((0,o.toArray)(this.config.userConfig.environments&&Object.keys(this.config.userConfig.environments).length>0?Object.keys(this.config.userConfig.environments).map(e=>t.createEnvironment(e,this.config.userConfig)):t.createDefaultEnvironment(this.config.userConfig)).map(async e=>{this.#e[e.name]=await this.in(e)}))}async in(e){let t;t=this.environments[e.name]?this.environments[e.name]:await i.PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig,this.config),(0,c.isSetObject)(this.config.inlineConfig)&&await t.withInlineConfig(this.config.inlineConfig),t.environment=e,t.plugins=[];for(let e of this.plugins)await t.addPlugin(e);return t}async withUserConfig(e,t={isHighPriority:!0}){await super.withUserConfig(e,t),await Promise.all(Object.keys(this.#e).map(async n=>{await this.#e[n].withUserConfig(e,t)}))}async withInlineConfig(e,t={isHighPriority:!0}){await super.withInlineConfig(e,t),await Promise.all(Object.keys(this.#e).map(async n=>{await this.#e[n].withInlineConfig(e,t)}))}async addPlugin(e){this.plugins.push(e),await Promise.all(Object.keys(this.environments).map(async t=>{await this.environments[t].addPlugin(e)}))}async getEnvironment(e){let n;if(e&&(n=this.environments[e]),Object.keys(this.environments).length===1&&(n=this.environments[Object.keys(this.environments)[0]],this.log(a.LogLevelLabel.DEBUG,`Applying the only configured environment: ${l.default.bold.cyanBright(n?.environment.name)}`)),!n){if(e)throw Error(`Environment "${e}" not found.`);n=await this.in(t.createDefaultEnvironment(this.config.userConfig)),this.log(a.LogLevelLabel.WARN,`No environment specified, and no default environment found. Using a temporary default environment: ${l.default.bold.cyanBright(n?.environment.name)}`)}return n}async getEnvironmentSafe(e){try{return await this.getEnvironment(e)}catch{return}}async toEnvironment(){let e;return Object.keys(this.environments).length>1?(e=await this.in(t.createEnvironment(t.GLOBAL_ENVIRONMENT,this.config.userConfig)),this.log(a.LogLevelLabel.DEBUG,`Combined all ${Object.keys(this.environments).length} environments into a single global context.`)):e=await this.getEnvironment(),e}};exports.PowerlinesAPIContext=u;
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ const require_environment = require('../../internal/helpers/environment.cjs');
3
+ const require_config_file = require('../config-file.cjs');
4
+ const require_context = require('./context.cjs');
5
+ const require_environment_context = require('./environment-context.cjs');
6
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
7
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
8
+ let __stryke_fs_resolve = require("@stryke/fs/resolve");
9
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
10
+ let chalk = require("chalk");
11
+ chalk = require_rolldown_runtime.__toESM(chalk);
12
+
13
+ //#region ../powerlines/src/lib/contexts/api-context.ts
14
+ var PowerlinesAPIContext = class PowerlinesAPIContext extends require_context.PowerlinesContext {
15
+ #environments = {};
16
+ #plugins = [];
17
+ #log;
18
+ /**
19
+ * Create a new Storm context from the workspace root and user config.
20
+ *
21
+ * @param workspaceRoot - The root directory of the workspace.
22
+ * @param config - The user configuration options.
23
+ * @returns A promise that resolves to the new context.
24
+ */
25
+ static async from(workspaceRoot, config) {
26
+ const context = new PowerlinesAPIContext(await require_config_file.loadWorkspaceConfig(workspaceRoot, config.root));
27
+ await context.withUserConfig(config);
28
+ const powerlinesPath = await (0, __stryke_fs_resolve.resolvePackage)("powerlines");
29
+ if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
30
+ context.powerlinesPath = powerlinesPath;
31
+ return context;
32
+ }
33
+ /**
34
+ * Internal context fields and methods
35
+ *
36
+ * @danger
37
+ * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
38
+ *
39
+ * @internal
40
+ */
41
+ get $$internal() {
42
+ return super.$$internal;
43
+ }
44
+ /**
45
+ * Internal context fields and methods
46
+ *
47
+ * @danger
48
+ * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
49
+ *
50
+ * @internal
51
+ */
52
+ set $$internal(value) {
53
+ super.$$internal = value;
54
+ for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
55
+ }
56
+ /**
57
+ * A record of all environments by name
58
+ */
59
+ get environments() {
60
+ return this.#environments;
61
+ }
62
+ get log() {
63
+ if (!this.#log) this.#log = this.createLog();
64
+ return this.#log;
65
+ }
66
+ get plugins() {
67
+ return this.#plugins;
68
+ }
69
+ constructor(workspaceConfig) {
70
+ super(workspaceConfig);
71
+ }
72
+ /**
73
+ * Initialize the context with the provided configuration options
74
+ *
75
+ * @param config - The partial user configuration to use for initialization.
76
+ */
77
+ async init(config = {}) {
78
+ await super.init(config);
79
+ await Promise.all((0, __stryke_convert_to_array.toArray)(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => require_environment.createEnvironment(name, this.config.userConfig)) : require_environment.createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
80
+ this.#environments[env.name] = await this.in(env);
81
+ }));
82
+ }
83
+ /**
84
+ * A function to copy the context and update the fields for a specific environment
85
+ *
86
+ * @param environment - The environment configuration to use.
87
+ * @returns A new context instance with the updated environment.
88
+ */
89
+ async in(environment) {
90
+ let context;
91
+ if (this.environments[environment.name]) context = this.environments[environment.name];
92
+ else context = await require_environment_context.PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
93
+ if ((0, __stryke_type_checks_is_set_object.isSetObject)(this.config.inlineConfig)) await context.withInlineConfig(this.config.inlineConfig);
94
+ context.environment = environment;
95
+ context.plugins = [];
96
+ for (const plugin of this.plugins) await context.addPlugin(plugin);
97
+ return context;
98
+ }
99
+ /**
100
+ * Update the context using a new user configuration options
101
+ *
102
+ * @param userConfig - The new user configuration options.
103
+ */
104
+ async withUserConfig(userConfig, options = { isHighPriority: true }) {
105
+ await super.withUserConfig(userConfig, options);
106
+ await Promise.all(Object.keys(this.#environments).map(async (name) => {
107
+ await this.#environments[name].withUserConfig(userConfig, options);
108
+ }));
109
+ }
110
+ /**
111
+ * Update the context using a new inline configuration options
112
+ *
113
+ * @param inlineConfig - The new inline configuration options.
114
+ */
115
+ async withInlineConfig(inlineConfig, options = { isHighPriority: true }) {
116
+ await super.withInlineConfig(inlineConfig, options);
117
+ await Promise.all(Object.keys(this.#environments).map(async (name) => {
118
+ await this.#environments[name].withInlineConfig(inlineConfig, options);
119
+ }));
120
+ }
121
+ /**
122
+ * Add a plugin to the API context and all environments
123
+ *
124
+ * @param plugin - The plugin to add.
125
+ */
126
+ async addPlugin(plugin) {
127
+ this.plugins.push(plugin);
128
+ await Promise.all(Object.keys(this.environments).map(async (name) => {
129
+ await this.environments[name].addPlugin(plugin);
130
+ }));
131
+ }
132
+ /**
133
+ * Get an environment by name, or the default environment if no name is provided
134
+ *
135
+ * @param name - The name of the environment to retrieve.
136
+ * @returns The requested environment context.
137
+ */
138
+ async getEnvironment(name) {
139
+ let environment;
140
+ if (name) environment = this.environments[name];
141
+ if (Object.keys(this.environments).length === 1) {
142
+ environment = this.environments[Object.keys(this.environments)[0]];
143
+ this.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk.default.bold.cyanBright(environment?.environment.name)}`);
144
+ }
145
+ if (!environment) {
146
+ if (name) throw new Error(`Environment "${name}" not found.`);
147
+ environment = await this.in(require_environment.createDefaultEnvironment(this.config.userConfig));
148
+ this.log(__storm_software_config_tools_types.LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment?.environment.name)}`);
149
+ }
150
+ return environment;
151
+ }
152
+ /**
153
+ * A safe version of `getEnvironment` that returns `undefined` if the environment is not found
154
+ *
155
+ * @param name - The name of the environment to retrieve.
156
+ * @returns The requested environment context or `undefined` if not found.
157
+ */
158
+ async getEnvironmentSafe(name) {
159
+ try {
160
+ return await this.getEnvironment(name);
161
+ } catch {
162
+ return;
163
+ }
164
+ }
165
+ /**
166
+ * A function to merge all configured environments into a single context.
167
+ *
168
+ * @remarks
169
+ * If only one environment is configured, that environment will be returned directly.
170
+ *
171
+ * @returns A promise that resolves to a merged/global environment context.
172
+ */
173
+ async toEnvironment() {
174
+ let environment;
175
+ if (Object.keys(this.environments).length > 1) {
176
+ environment = await this.in(require_environment.createEnvironment(require_environment.GLOBAL_ENVIRONMENT, this.config.userConfig));
177
+ this.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, `Combined all ${Object.keys(this.environments).length} environments into a single global context.`);
178
+ } else environment = await this.getEnvironment();
179
+ return environment;
180
+ }
181
+ };
182
+
183
+ //#endregion
184
+ exports.PowerlinesAPIContext = PowerlinesAPIContext;
@@ -1 +1,182 @@
1
- import{GLOBAL_ENVIRONMENT as e,createDefaultEnvironment as t,createEnvironment as n}from"../../internal/helpers/environment.mjs";import{loadWorkspaceConfig as r}from"../config-file.mjs";import{PowerlinesContext as i}from"./context.mjs";import{PowerlinesEnvironmentContext as a}from"./environment-context.mjs";import{LogLevelLabel as o}from"@storm-software/config-tools/types";import{toArray as s}from"@stryke/convert/to-array";import{resolvePackage as c}from"@stryke/fs/resolve";import{isSetObject as l}from"@stryke/type-checks/is-set-object";import u from"chalk";var d=class d extends i{#e={};#t=[];#n;static async from(e,t){let n=new d(await r(e,t.root));await n.withUserConfig(t);let i=await c(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=i,n}get $$internal(){return super.$$internal}set $$internal(e){super.$$internal=e;for(let e of Object.values(this.environments))e.$$internal=super.$$internal}get environments(){return this.#e}get log(){return this.#n||=this.createLog(),this.#n}get plugins(){return this.#t}constructor(e){super(e)}async init(e={}){await super.init(e),await Promise.all(s(this.config.userConfig.environments&&Object.keys(this.config.userConfig.environments).length>0?Object.keys(this.config.userConfig.environments).map(e=>n(e,this.config.userConfig)):t(this.config.userConfig)).map(async e=>{this.#e[e.name]=await this.in(e)}))}async in(e){let t;t=this.environments[e.name]?this.environments[e.name]:await a.fromConfig(this.workspaceConfig,this.config),l(this.config.inlineConfig)&&await t.withInlineConfig(this.config.inlineConfig),t.environment=e,t.plugins=[];for(let e of this.plugins)await t.addPlugin(e);return t}async withUserConfig(e,t={isHighPriority:!0}){await super.withUserConfig(e,t),await Promise.all(Object.keys(this.#e).map(async n=>{await this.#e[n].withUserConfig(e,t)}))}async withInlineConfig(e,t={isHighPriority:!0}){await super.withInlineConfig(e,t),await Promise.all(Object.keys(this.#e).map(async n=>{await this.#e[n].withInlineConfig(e,t)}))}async addPlugin(e){this.plugins.push(e),await Promise.all(Object.keys(this.environments).map(async t=>{await this.environments[t].addPlugin(e)}))}async getEnvironment(e){let n;if(e&&(n=this.environments[e]),Object.keys(this.environments).length===1&&(n=this.environments[Object.keys(this.environments)[0]],this.log(o.DEBUG,`Applying the only configured environment: ${u.bold.cyanBright(n?.environment.name)}`)),!n){if(e)throw Error(`Environment "${e}" not found.`);n=await this.in(t(this.config.userConfig)),this.log(o.WARN,`No environment specified, and no default environment found. Using a temporary default environment: ${u.bold.cyanBright(n?.environment.name)}`)}return n}async getEnvironmentSafe(e){try{return await this.getEnvironment(e)}catch{return}}async toEnvironment(){let t;return Object.keys(this.environments).length>1?(t=await this.in(n(e,this.config.userConfig)),this.log(o.DEBUG,`Combined all ${Object.keys(this.environments).length} environments into a single global context.`)):t=await this.getEnvironment(),t}};export{d as PowerlinesAPIContext};
1
+ import { GLOBAL_ENVIRONMENT, createDefaultEnvironment, createEnvironment } from "../../internal/helpers/environment.mjs";
2
+ import { loadWorkspaceConfig } from "../config-file.mjs";
3
+ import { PowerlinesContext } from "./context.mjs";
4
+ import { PowerlinesEnvironmentContext } from "./environment-context.mjs";
5
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
6
+ import { toArray } from "@stryke/convert/to-array";
7
+ import { resolvePackage } from "@stryke/fs/resolve";
8
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
9
+ import chalk from "chalk";
10
+
11
+ //#region ../powerlines/src/lib/contexts/api-context.ts
12
+ var PowerlinesAPIContext = class PowerlinesAPIContext extends PowerlinesContext {
13
+ #environments = {};
14
+ #plugins = [];
15
+ #log;
16
+ /**
17
+ * Create a new Storm context from the workspace root and user config.
18
+ *
19
+ * @param workspaceRoot - The root directory of the workspace.
20
+ * @param config - The user configuration options.
21
+ * @returns A promise that resolves to the new context.
22
+ */
23
+ static async from(workspaceRoot, config) {
24
+ const context = new PowerlinesAPIContext(await loadWorkspaceConfig(workspaceRoot, config.root));
25
+ await context.withUserConfig(config);
26
+ const powerlinesPath = await resolvePackage("powerlines");
27
+ if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
28
+ context.powerlinesPath = powerlinesPath;
29
+ return context;
30
+ }
31
+ /**
32
+ * Internal context fields and methods
33
+ *
34
+ * @danger
35
+ * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
36
+ *
37
+ * @internal
38
+ */
39
+ get $$internal() {
40
+ return super.$$internal;
41
+ }
42
+ /**
43
+ * Internal context fields and methods
44
+ *
45
+ * @danger
46
+ * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
47
+ *
48
+ * @internal
49
+ */
50
+ set $$internal(value) {
51
+ super.$$internal = value;
52
+ for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
53
+ }
54
+ /**
55
+ * A record of all environments by name
56
+ */
57
+ get environments() {
58
+ return this.#environments;
59
+ }
60
+ get log() {
61
+ if (!this.#log) this.#log = this.createLog();
62
+ return this.#log;
63
+ }
64
+ get plugins() {
65
+ return this.#plugins;
66
+ }
67
+ constructor(workspaceConfig) {
68
+ super(workspaceConfig);
69
+ }
70
+ /**
71
+ * Initialize the context with the provided configuration options
72
+ *
73
+ * @param config - The partial user configuration to use for initialization.
74
+ */
75
+ async init(config = {}) {
76
+ await super.init(config);
77
+ await Promise.all(toArray(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => createEnvironment(name, this.config.userConfig)) : createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
78
+ this.#environments[env.name] = await this.in(env);
79
+ }));
80
+ }
81
+ /**
82
+ * A function to copy the context and update the fields for a specific environment
83
+ *
84
+ * @param environment - The environment configuration to use.
85
+ * @returns A new context instance with the updated environment.
86
+ */
87
+ async in(environment) {
88
+ let context;
89
+ if (this.environments[environment.name]) context = this.environments[environment.name];
90
+ else context = await PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
91
+ if (isSetObject(this.config.inlineConfig)) await context.withInlineConfig(this.config.inlineConfig);
92
+ context.environment = environment;
93
+ context.plugins = [];
94
+ for (const plugin of this.plugins) await context.addPlugin(plugin);
95
+ return context;
96
+ }
97
+ /**
98
+ * Update the context using a new user configuration options
99
+ *
100
+ * @param userConfig - The new user configuration options.
101
+ */
102
+ async withUserConfig(userConfig, options = { isHighPriority: true }) {
103
+ await super.withUserConfig(userConfig, options);
104
+ await Promise.all(Object.keys(this.#environments).map(async (name) => {
105
+ await this.#environments[name].withUserConfig(userConfig, options);
106
+ }));
107
+ }
108
+ /**
109
+ * Update the context using a new inline configuration options
110
+ *
111
+ * @param inlineConfig - The new inline configuration options.
112
+ */
113
+ async withInlineConfig(inlineConfig, options = { isHighPriority: true }) {
114
+ await super.withInlineConfig(inlineConfig, options);
115
+ await Promise.all(Object.keys(this.#environments).map(async (name) => {
116
+ await this.#environments[name].withInlineConfig(inlineConfig, options);
117
+ }));
118
+ }
119
+ /**
120
+ * Add a plugin to the API context and all environments
121
+ *
122
+ * @param plugin - The plugin to add.
123
+ */
124
+ async addPlugin(plugin) {
125
+ this.plugins.push(plugin);
126
+ await Promise.all(Object.keys(this.environments).map(async (name) => {
127
+ await this.environments[name].addPlugin(plugin);
128
+ }));
129
+ }
130
+ /**
131
+ * Get an environment by name, or the default environment if no name is provided
132
+ *
133
+ * @param name - The name of the environment to retrieve.
134
+ * @returns The requested environment context.
135
+ */
136
+ async getEnvironment(name) {
137
+ let environment;
138
+ if (name) environment = this.environments[name];
139
+ if (Object.keys(this.environments).length === 1) {
140
+ environment = this.environments[Object.keys(this.environments)[0]];
141
+ this.log(LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk.bold.cyanBright(environment?.environment.name)}`);
142
+ }
143
+ if (!environment) {
144
+ if (name) throw new Error(`Environment "${name}" not found.`);
145
+ environment = await this.in(createDefaultEnvironment(this.config.userConfig));
146
+ this.log(LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.bold.cyanBright(environment?.environment.name)}`);
147
+ }
148
+ return environment;
149
+ }
150
+ /**
151
+ * A safe version of `getEnvironment` that returns `undefined` if the environment is not found
152
+ *
153
+ * @param name - The name of the environment to retrieve.
154
+ * @returns The requested environment context or `undefined` if not found.
155
+ */
156
+ async getEnvironmentSafe(name) {
157
+ try {
158
+ return await this.getEnvironment(name);
159
+ } catch {
160
+ return;
161
+ }
162
+ }
163
+ /**
164
+ * A function to merge all configured environments into a single context.
165
+ *
166
+ * @remarks
167
+ * If only one environment is configured, that environment will be returned directly.
168
+ *
169
+ * @returns A promise that resolves to a merged/global environment context.
170
+ */
171
+ async toEnvironment() {
172
+ let environment;
173
+ if (Object.keys(this.environments).length > 1) {
174
+ environment = await this.in(createEnvironment(GLOBAL_ENVIRONMENT, this.config.userConfig));
175
+ this.log(LogLevelLabel.DEBUG, `Combined all ${Object.keys(this.environments).length} environments into a single global context.`);
176
+ } else environment = await this.getEnvironment();
177
+ return environment;
178
+ }
179
+ };
180
+
181
+ //#endregion
182
+ export { PowerlinesAPIContext };