@powerlines/engine 0.45.2 → 0.46.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.
- package/dist/_internal/worker.cjs +844 -788
- package/dist/_internal/worker.mjs +847 -791
- package/dist/_internal/worker.mjs.map +1 -1
- package/dist/api.cjs +292 -323
- package/dist/api.d.cts +44 -11
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +44 -11
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +292 -323
- package/dist/api.mjs.map +1 -1
- package/dist/{base-context-Byizvf4F.cjs → base-context-BCG0xN2e.cjs} +70 -64
- package/dist/{base-context-BSAC5sO9.mjs → base-context-Cmo6TTh7.mjs} +73 -67
- package/dist/base-context-Cmo6TTh7.mjs.map +1 -0
- package/dist/context/index.cjs +3 -3
- package/dist/context/index.d.cts +44 -617
- package/dist/context/index.d.cts.map +1 -1
- package/dist/context/index.d.mts +44 -617
- package/dist/context/index.d.mts.map +1 -1
- package/dist/context/index.mjs +3 -3
- package/dist/engine-context-BjFMVQEE.mjs +86 -0
- package/dist/engine-context-BjFMVQEE.mjs.map +1 -0
- package/dist/engine-context-DOsGtgD9.cjs +91 -0
- package/dist/execution-context-BdZt7wWa.d.mts +631 -0
- package/dist/execution-context-BdZt7wWa.d.mts.map +1 -0
- package/dist/execution-context-CU6iNchD.d.cts +631 -0
- package/dist/execution-context-CU6iNchD.d.cts.map +1 -0
- package/dist/{execution-context-BRzNYU9u.mjs → execution-context-Cp32TarF.mjs} +421 -363
- package/dist/execution-context-Cp32TarF.mjs.map +1 -0
- package/dist/{execution-context-BlWK2rTX.cjs → execution-context-DgqxcDDx.cjs} +419 -361
- package/dist/index.cjs +15 -16
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +15 -16
- package/dist/index.mjs.map +1 -1
- package/dist/{tsconfig-QMSxSwBD.cjs → tsconfig-BUDqmOaT.cjs} +13 -13
- package/dist/{tsconfig-CI6bla4E.mjs → tsconfig-MeFEs21S.mjs} +14 -14
- package/dist/tsconfig-MeFEs21S.mjs.map +1 -0
- package/dist/typescript/index.cjs +1 -1
- package/dist/typescript/index.d.cts +6 -6
- package/dist/typescript/index.d.cts.map +1 -1
- package/dist/typescript/index.d.mts +6 -6
- package/dist/typescript/index.d.mts.map +1 -1
- package/dist/typescript/index.mjs +1 -1
- package/package.json +17 -17
- package/dist/base-context-BSAC5sO9.mjs.map +0 -1
- package/dist/engine-context-CI_0NWIk.cjs +0 -73
- package/dist/engine-context-_RMFwG4J.mjs +0 -68
- package/dist/engine-context-_RMFwG4J.mjs.map +0 -1
- package/dist/execution-context-BRzNYU9u.mjs.map +0 -1
- package/dist/tsconfig-CI6bla4E.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-C0xms8kb.cjs');
|
|
2
|
-
const require_base_context = require('./base-context-
|
|
2
|
+
const require_base_context = require('./base-context-BCG0xN2e.cjs');
|
|
3
3
|
const require_fs = require('./fs-XogSgMqT.cjs');
|
|
4
4
|
const require_virtual = require('./virtual-Ct3ZqPeN.cjs');
|
|
5
|
-
const require_tsconfig = require('./tsconfig-
|
|
5
|
+
const require_tsconfig = require('./tsconfig-BUDqmOaT.cjs');
|
|
6
6
|
let _powerlines_core_constants = require("@powerlines/core/constants");
|
|
7
7
|
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
8
8
|
let _stryke_fs_resolve = require("@stryke/fs/resolve");
|
|
@@ -10,20 +10,20 @@ let _stryke_path_join = require("@stryke/path/join");
|
|
|
10
10
|
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
11
11
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
12
12
|
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
13
|
+
let jest_worker = require("jest-worker");
|
|
13
14
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
14
15
|
let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
|
|
15
16
|
let _powerlines_core_plugin_utils = require("@powerlines/core/plugin-utils");
|
|
16
17
|
let _powerlines_core_plugin_utils_logging = require("@powerlines/core/plugin-utils/logging");
|
|
17
18
|
let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
|
|
18
19
|
let _stryke_path_append = require("@stryke/path/append");
|
|
19
|
-
let _stryke_path_is_equal = require("@stryke/path/is-equal");
|
|
20
20
|
let _stryke_path_replace = require("@stryke/path/replace");
|
|
21
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
21
22
|
let chalk = require("chalk");
|
|
22
23
|
chalk = require_chunk.__toESM(chalk, 1);
|
|
23
24
|
let defu = require("defu");
|
|
24
25
|
defu = require_chunk.__toESM(defu, 1);
|
|
25
26
|
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
26
|
-
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
27
27
|
let _powerlines_core_lib_utilities_format = require("@powerlines/core/lib/utilities/format");
|
|
28
28
|
let _storm_software_config_tools_logger_console = require("@storm-software/config-tools/logger/console");
|
|
29
29
|
let _stryke_fs_exists = require("@stryke/fs/exists");
|
|
@@ -31,17 +31,18 @@ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
|
31
31
|
let _stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
32
32
|
let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
33
33
|
let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
34
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
34
35
|
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
35
36
|
let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
37
|
+
let _stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
|
|
36
38
|
let _stryke_fs_json = require("@stryke/fs/json");
|
|
37
39
|
let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
|
|
38
40
|
let _powerlines_core_lib_entry = require("@powerlines/core/lib/entry");
|
|
39
|
-
let _stryke_convert_to_bool = require("@stryke/convert/to-bool");
|
|
40
41
|
let _stryke_fs_get_workspace_root = require("@stryke/fs/get-workspace-root");
|
|
41
42
|
let _stryke_hash = require("@stryke/hash");
|
|
42
43
|
let _stryke_hash_node = require("@stryke/hash/node");
|
|
43
44
|
let _stryke_http_fetch = require("@stryke/http/fetch");
|
|
44
|
-
let
|
|
45
|
+
let _stryke_path_is_equal = require("@stryke/path/is-equal");
|
|
45
46
|
let bundle_require = require("bundle-require");
|
|
46
47
|
let compatx = require("compatx");
|
|
47
48
|
let flat_cache = require("flat-cache");
|
|
@@ -63,9 +64,9 @@ let node_url = require("node:url");
|
|
|
63
64
|
let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
|
|
64
65
|
|
|
65
66
|
//#region src/_internal/helpers/environment.ts
|
|
66
|
-
function createEnvironment(name, config
|
|
67
|
+
function createEnvironment(name, config) {
|
|
67
68
|
return (0, defu.default)(config.environments?.[name] ?? {}, {
|
|
68
|
-
|
|
69
|
+
id: (0, _stryke_unique_id_uuid.uuid)(),
|
|
69
70
|
name,
|
|
70
71
|
title: config.title ?? (0, _stryke_string_format_title_case.titleCase)(config.name),
|
|
71
72
|
ssr: false,
|
|
@@ -91,7 +92,7 @@ function createEnvironment(name, config = {}) {
|
|
|
91
92
|
} : void 0
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
|
-
function createDefaultEnvironment(config
|
|
95
|
+
function createDefaultEnvironment(config) {
|
|
95
96
|
return createEnvironment(_powerlines_core_constants.DEFAULT_ENVIRONMENT, config);
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -148,16 +149,16 @@ async function writeMetaFile(context) {
|
|
|
148
149
|
|
|
149
150
|
//#endregion
|
|
150
151
|
//#region src/_internal/ipc/send.ts
|
|
151
|
-
function
|
|
152
|
+
function formatWriteLogMessage(context, meta, message) {
|
|
152
153
|
const combinedMeta = {
|
|
153
154
|
...context.logger.options,
|
|
154
155
|
...(0, _stryke_type_checks_is_set_object.isSetObject)(meta) ? meta : { type: meta }
|
|
155
156
|
};
|
|
156
|
-
|
|
157
|
+
return {
|
|
157
158
|
id: (0, _stryke_unique_id_uuid.uuid)(),
|
|
158
159
|
type: "write-log",
|
|
159
|
-
executionId: combinedMeta.executionId || context.
|
|
160
|
-
executionIndex: combinedMeta.executionIndex ?? context.
|
|
160
|
+
executionId: combinedMeta.executionId || context.options.executionId,
|
|
161
|
+
executionIndex: combinedMeta.executionIndex ?? context.options.executionIndex,
|
|
161
162
|
environment: combinedMeta.environment,
|
|
162
163
|
timestamp: Date.now(),
|
|
163
164
|
payload: {
|
|
@@ -167,8 +168,8 @@ function sendWriteLogMessage(context, meta, message) {
|
|
|
167
168
|
logId: combinedMeta.logId || (0, _stryke_unique_id_uuid.uuid)(),
|
|
168
169
|
timestamp: combinedMeta.timestamp ?? Date.now(),
|
|
169
170
|
name: combinedMeta.name || context.config.name,
|
|
170
|
-
executionId: combinedMeta.executionId || context.
|
|
171
|
-
executionIndex: combinedMeta.executionIndex ?? context.
|
|
171
|
+
executionId: combinedMeta.executionId || context.options.executionId,
|
|
172
|
+
executionIndex: combinedMeta.executionIndex ?? context.options.executionIndex,
|
|
172
173
|
command: combinedMeta.command || context.config.command,
|
|
173
174
|
hook: combinedMeta.hook,
|
|
174
175
|
environment: combinedMeta.environment,
|
|
@@ -177,7 +178,21 @@ function sendWriteLogMessage(context, meta, message) {
|
|
|
177
178
|
},
|
|
178
179
|
message
|
|
179
180
|
}
|
|
180
|
-
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function childProcessSend(message) {
|
|
184
|
+
process.send?.(message);
|
|
185
|
+
}
|
|
186
|
+
function workerThreadSend(message) {
|
|
187
|
+
(0, jest_worker.messageParent)(message);
|
|
188
|
+
}
|
|
189
|
+
function send(message) {
|
|
190
|
+
if (process.env.POWERLINES_EXECUTION_THREAD_TYPE === "child-process") childProcessSend(message);
|
|
191
|
+
else if (process.env.POWERLINES_EXECUTION_THREAD_TYPE === "worker-thread") workerThreadSend(message);
|
|
192
|
+
else console.warn("No IPC mechanism available to send message:", message);
|
|
193
|
+
}
|
|
194
|
+
function sendWriteLogMessage(context, meta, message) {
|
|
195
|
+
send(formatWriteLogMessage(context, meta, message));
|
|
181
196
|
}
|
|
182
197
|
|
|
183
198
|
//#endregion
|
|
@@ -1273,27 +1288,13 @@ var VirtualFileSystem = class VirtualFileSystem {
|
|
|
1273
1288
|
timeoutFactor: 2,
|
|
1274
1289
|
retryAfter: true
|
|
1275
1290
|
})));
|
|
1276
|
-
const
|
|
1277
|
-
"
|
|
1278
|
-
"
|
|
1279
|
-
"
|
|
1280
|
-
"
|
|
1281
|
-
"projectJson",
|
|
1282
|
-
"tsconfig",
|
|
1283
|
-
"resolver",
|
|
1284
|
-
"fs",
|
|
1285
|
-
"$$internal"
|
|
1291
|
+
const UNRESOLVED_CONFIG_NAMES = [
|
|
1292
|
+
"initialConfig",
|
|
1293
|
+
"userConfig",
|
|
1294
|
+
"inlineConfig",
|
|
1295
|
+
"pluginConfig"
|
|
1286
1296
|
];
|
|
1287
1297
|
var PowerlinesContext = class PowerlinesContext extends require_base_context.PowerlinesBaseContext {
|
|
1288
|
-
/**
|
|
1289
|
-
* Internal references storage
|
|
1290
|
-
*
|
|
1291
|
-
* @danger
|
|
1292
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
1293
|
-
*
|
|
1294
|
-
* @internal
|
|
1295
|
-
*/
|
|
1296
|
-
#internal = {};
|
|
1297
1298
|
#checksum = null;
|
|
1298
1299
|
#buildId = (0, _stryke_unique_id_uuid.uuid)();
|
|
1299
1300
|
#releaseId = (0, _stryke_unique_id_uuid.uuid)();
|
|
@@ -1301,24 +1302,22 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1301
1302
|
#tsconfig;
|
|
1302
1303
|
#parserCache;
|
|
1303
1304
|
#requestCache;
|
|
1305
|
+
#configProxy;
|
|
1304
1306
|
/**
|
|
1305
|
-
* Create a new
|
|
1307
|
+
* Create a new context from the workspace root and user config.
|
|
1306
1308
|
*
|
|
1307
1309
|
* @param options - The options for resolving the context.
|
|
1308
1310
|
* @returns A promise that resolves to the new context.
|
|
1309
1311
|
*/
|
|
1310
|
-
static async
|
|
1311
|
-
const context = new PowerlinesContext(options);
|
|
1312
|
-
await context.init(
|
|
1313
|
-
const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
|
|
1314
|
-
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
1315
|
-
context.powerlinesPath = powerlinesPath;
|
|
1312
|
+
static async fromInitialConfig(options, initialConfig) {
|
|
1313
|
+
const context = new PowerlinesContext(options, initialConfig);
|
|
1314
|
+
await context.init();
|
|
1316
1315
|
return context;
|
|
1317
1316
|
}
|
|
1318
1317
|
/**
|
|
1319
|
-
* The options provided to the Powerlines process
|
|
1318
|
+
* The options provided to the Powerlines process, resolved with default values and merged with any configuration provided by plugins or other sources. This is typically the final configuration used during the build process, but may also include additional options that are relevant to the context and its interactions with the Powerlines engine.
|
|
1320
1319
|
*/
|
|
1321
|
-
options;
|
|
1320
|
+
options = {};
|
|
1322
1321
|
/**
|
|
1323
1322
|
* An object containing the dependencies that should be installed for the project
|
|
1324
1323
|
*/
|
|
@@ -1332,39 +1331,33 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1332
1331
|
*/
|
|
1333
1332
|
persistedMeta = void 0;
|
|
1334
1333
|
/**
|
|
1335
|
-
* The
|
|
1334
|
+
* The resolved tsconfig file paths for the project
|
|
1336
1335
|
*/
|
|
1337
|
-
|
|
1336
|
+
resolvePatterns = [];
|
|
1338
1337
|
/**
|
|
1339
|
-
* The
|
|
1338
|
+
* The input options used to initialize the context, which may be used when cloning the context to ensure the same configuration is applied to the new context
|
|
1340
1339
|
*/
|
|
1341
|
-
|
|
1340
|
+
initialOptions = {};
|
|
1342
1341
|
/**
|
|
1343
|
-
* The resolved
|
|
1342
|
+
* The resolved configuration for this context
|
|
1344
1343
|
*/
|
|
1345
|
-
|
|
1344
|
+
resolvedConfig = {};
|
|
1346
1345
|
/**
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
1349
|
-
* @danger
|
|
1350
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
1351
|
-
*
|
|
1352
|
-
* @internal
|
|
1346
|
+
* The configuration options that were overridden by plugins during the build process, which may include additional properties or modifications made during the configuration loading process.
|
|
1353
1347
|
*/
|
|
1354
|
-
|
|
1355
|
-
return this.#internal;
|
|
1356
|
-
}
|
|
1348
|
+
overriddenConfig = {};
|
|
1357
1349
|
/**
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
* @danger
|
|
1361
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
1362
|
-
*
|
|
1363
|
-
* @internal
|
|
1350
|
+
* The configuration options provided inline during execution, such as CLI flags or other parameters that may be relevant to the command being executed. These options can be used to override or supplement the configuration options defined in a configuration file on disk, and are typically provided as part of the execution context when running a Powerlines command.
|
|
1364
1351
|
*/
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1352
|
+
inlineConfig = {};
|
|
1353
|
+
/**
|
|
1354
|
+
* The configuration options read from a configuration file on disk, which may be used to resolve the final configuration for the context. This typically includes the user configuration options defined in the `powerlines.config.ts` file, as well as any inline configuration options provided during execution.
|
|
1355
|
+
*/
|
|
1356
|
+
userConfig = {};
|
|
1357
|
+
/**
|
|
1358
|
+
* The configuration options provided by plugins added by the user (and other plugins)
|
|
1359
|
+
*/
|
|
1360
|
+
pluginConfig = {};
|
|
1368
1361
|
/**
|
|
1369
1362
|
* The resolved entry type definitions for the project
|
|
1370
1363
|
*/
|
|
@@ -1419,13 +1412,14 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1419
1412
|
* The resolved configuration options
|
|
1420
1413
|
*/
|
|
1421
1414
|
get config() {
|
|
1422
|
-
|
|
1415
|
+
if (!this.#configProxy) this.#configProxy = this.createConfigProxy();
|
|
1416
|
+
return this.#configProxy;
|
|
1423
1417
|
}
|
|
1424
1418
|
/**
|
|
1425
1419
|
* Get the path to the artifacts directory for the project
|
|
1426
1420
|
*/
|
|
1427
1421
|
get artifactsPath() {
|
|
1428
|
-
return (0, _stryke_path_join.joinPaths)(this.config.cwd, this.config.root, this.config.output.
|
|
1422
|
+
return (0, _stryke_path_join.joinPaths)(this.config.cwd, this.config.root, this.config.output?.artifactsPath || `.${this.config.framework || "powerlines"}`);
|
|
1429
1423
|
}
|
|
1430
1424
|
/**
|
|
1431
1425
|
* Get the path to the builtin modules used by the project
|
|
@@ -1482,7 +1476,7 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1482
1476
|
* Additional arguments provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed.
|
|
1483
1477
|
*/
|
|
1484
1478
|
get additionalArgs() {
|
|
1485
|
-
return Object.entries(this.config.inlineConfig
|
|
1479
|
+
return Object.entries(this.config.inlineConfig.additionalArgs ?? {}).reduce((ret, [key, value]) => {
|
|
1486
1480
|
const formattedKey = key.replace(/^--?/, "");
|
|
1487
1481
|
if (ret[formattedKey]) if (Array.isArray(ret[formattedKey])) if (Array.isArray(value)) ret[formattedKey] = [...(0, _stryke_convert_to_array.toArray)(ret[formattedKey]), ...value];
|
|
1488
1482
|
else ret[formattedKey] = [...(0, _stryke_convert_to_array.toArray)(ret[formattedKey]), value];
|
|
@@ -1511,29 +1505,6 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1511
1505
|
}, {}) : this.config.resolve.alias : {});
|
|
1512
1506
|
}
|
|
1513
1507
|
/**
|
|
1514
|
-
* Create a new logger instance
|
|
1515
|
-
*
|
|
1516
|
-
* @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
|
|
1517
|
-
* @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.
|
|
1518
|
-
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
1519
|
-
*/
|
|
1520
|
-
createLogger(options, logFn) {
|
|
1521
|
-
let logger;
|
|
1522
|
-
if ((0, _stryke_convert_to_bool.toBool)(process.env.POWERLINES_WORKER_THREAD_EXECUTION)) logger = (0, _powerlines_core_plugin_utils.createLogger)(this.config.name, {
|
|
1523
|
-
...this.options,
|
|
1524
|
-
...this.config,
|
|
1525
|
-
...options
|
|
1526
|
-
}, (meta, message) => sendWriteLogMessage(this, meta, message));
|
|
1527
|
-
else logger = (0, _powerlines_core_plugin_utils.createLogger)(this.config.name, {
|
|
1528
|
-
...this.options,
|
|
1529
|
-
...this.config,
|
|
1530
|
-
...options
|
|
1531
|
-
});
|
|
1532
|
-
if (this.config.customLogger) logger = (0, _powerlines_core_plugin_utils.withCustomLogger)(logger, this.config.customLogger);
|
|
1533
|
-
if (logFn) logger = (0, _powerlines_core_plugin_utils.withLogFn)(logger, logFn);
|
|
1534
|
-
return logger;
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
1508
|
* The log level for the context, which determines the minimum level of log messages that will be emitted by the logger. This is resolved based on the configuration options provided by the user, and can be set to different levels for development, production, and test environments. The log level can also be overridden by plugins or other parts of the build process to provide more granular control over logging output.
|
|
1538
1509
|
*/
|
|
1539
1510
|
get logLevel() {
|
|
@@ -1595,25 +1566,38 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1595
1566
|
}).filter(Boolean);
|
|
1596
1567
|
}
|
|
1597
1568
|
/**
|
|
1598
|
-
* Creates a new
|
|
1569
|
+
* Creates a new Context instance.
|
|
1599
1570
|
*
|
|
1600
1571
|
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
1572
|
+
* @param initialConfig - The initial configuration provided by the user, which can be used to resolve the final configuration for the context. This typically includes the user configuration options defined in the `powerlines.config.ts` file, as well as any inline configuration options provided during execution.
|
|
1601
1573
|
*/
|
|
1602
|
-
constructor(options) {
|
|
1603
|
-
super();
|
|
1604
|
-
this.
|
|
1574
|
+
constructor(options, initialConfig) {
|
|
1575
|
+
super(options, initialConfig);
|
|
1576
|
+
this.initialOptions = options;
|
|
1577
|
+
this.initialConfig = initialConfig;
|
|
1605
1578
|
}
|
|
1606
1579
|
/**
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
* @remarks
|
|
1610
|
-
* 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.
|
|
1580
|
+
* Create a new logger instance
|
|
1611
1581
|
*
|
|
1612
|
-
* @
|
|
1582
|
+
* @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
|
|
1583
|
+
* @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.
|
|
1584
|
+
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
1613
1585
|
*/
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1586
|
+
createLogger(options, logFn) {
|
|
1587
|
+
let logger;
|
|
1588
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(process.env.POWERLINES_EXECUTION_THREAD_TYPE)) logger = (0, _powerlines_core_plugin_utils.createLogger)(this.config.name, {
|
|
1589
|
+
...this.options,
|
|
1590
|
+
...this.config,
|
|
1591
|
+
...options
|
|
1592
|
+
}, (meta, message) => sendWriteLogMessage(this, meta, message));
|
|
1593
|
+
else logger = (0, _powerlines_core_plugin_utils.createLogger)(this.config.name, {
|
|
1594
|
+
...this.options,
|
|
1595
|
+
...this.config,
|
|
1596
|
+
...options
|
|
1597
|
+
});
|
|
1598
|
+
if (this.config.customLogger) logger = (0, _powerlines_core_plugin_utils.withCustomLogger)(logger, this.config.customLogger);
|
|
1599
|
+
if (logFn) logger = (0, _powerlines_core_plugin_utils.withLogFn)(logger, logFn);
|
|
1600
|
+
return logger;
|
|
1617
1601
|
}
|
|
1618
1602
|
/**
|
|
1619
1603
|
* A function to perform HTTP fetch requests
|
|
@@ -1943,206 +1927,233 @@ var PowerlinesContext = class PowerlinesContext extends require_base_context.Pow
|
|
|
1943
1927
|
/**
|
|
1944
1928
|
* Generates a checksum representing the current context state
|
|
1945
1929
|
*
|
|
1946
|
-
* @param
|
|
1930
|
+
* @param path - The root directory of the project to generate the checksum for
|
|
1947
1931
|
* @returns A promise that resolves to a string representing the checksum
|
|
1948
1932
|
*/
|
|
1949
|
-
async generateChecksum(
|
|
1950
|
-
|
|
1951
|
-
"node_modules",
|
|
1952
|
-
".git",
|
|
1953
|
-
".nx",
|
|
1954
|
-
".cache",
|
|
1955
|
-
"tmp",
|
|
1956
|
-
"dist"
|
|
1957
|
-
] });
|
|
1958
|
-
return this.#checksum;
|
|
1933
|
+
async generateChecksum(path) {
|
|
1934
|
+
return (0, _stryke_hash_node.hashDirectory)(path || (0, _stryke_path_append.appendPath)(this.options.root, this.options.cwd));
|
|
1959
1935
|
}
|
|
1960
1936
|
/**
|
|
1961
|
-
*
|
|
1937
|
+
* A setter function to populate the inline config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the inline configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any inline configuration provided during execution.
|
|
1938
|
+
*
|
|
1939
|
+
* @param config - The inline configuration values to set.
|
|
1940
|
+
* @returns A promise that resolves when the inline configuration values have been set.
|
|
1941
|
+
*/
|
|
1942
|
+
async setInlineConfig(config) {
|
|
1943
|
+
this.logger.debug({
|
|
1944
|
+
meta: { category: "config" },
|
|
1945
|
+
message: `Updating inline configuration object: \n${this.logConfig(config)}`
|
|
1946
|
+
});
|
|
1947
|
+
this.inlineConfig = config;
|
|
1948
|
+
await this.resolveConfig();
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* A setter function to populate the plugin config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the plugin configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any plugin configuration provided during execution.
|
|
1952
|
+
*
|
|
1953
|
+
* @param config - The plugin configuration values to set.
|
|
1954
|
+
* @returns A promise that resolves when the plugin configuration values have been set.
|
|
1955
|
+
*/
|
|
1956
|
+
async setPluginConfig(config) {
|
|
1957
|
+
this.logger.debug({
|
|
1958
|
+
meta: { category: "config" },
|
|
1959
|
+
message: `Updating plugin configuration object: \n${this.logConfig(config)}`
|
|
1960
|
+
});
|
|
1961
|
+
this.pluginConfig = config;
|
|
1962
|
+
await this.resolveConfig();
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* A function to merge the various configuration objects (initial, user, inline, and plugin) into a single resolved configuration object that can be used throughout the Powerlines process. This function takes into account the different sources of configuration and their respective priorities, ensuring that the final configuration reflects the intended settings for the project. The merged configuration is then returned as a new object that can be accessed through the `config` property of the context.
|
|
1966
|
+
*
|
|
1967
|
+
* @returns The merged configuration object that combines the initial, user, inline, and plugin configurations.
|
|
1962
1968
|
*/
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1969
|
+
mergeConfig() {
|
|
1970
|
+
return (0, _powerlines_core_plugin_utils.mergeConfig)({
|
|
1971
|
+
mode: this.initialOptions.mode,
|
|
1972
|
+
framework: this.initialOptions.framework,
|
|
1973
|
+
initialOptions: this.initialOptions,
|
|
1974
|
+
options: this.options,
|
|
1975
|
+
inlineConfig: this.inlineConfig,
|
|
1976
|
+
userConfig: this.userConfig,
|
|
1977
|
+
initialConfig: this.initialConfig,
|
|
1978
|
+
pluginConfig: this.pluginConfig
|
|
1979
|
+
}, getConfigProps(this.overriddenConfig), (0, _stryke_helpers_omit.omit)(this.options, ["mode", "framework"]), getConfigProps(this.inlineConfig), getConfigProps(this.userConfig), getConfigProps(this.initialConfig), getConfigProps(this.pluginConfig), {
|
|
1973
1980
|
version: this.packageJson?.version,
|
|
1974
1981
|
description: this.packageJson?.description
|
|
1975
1982
|
}, {
|
|
1976
1983
|
environments: {},
|
|
1977
1984
|
resolve: {}
|
|
1978
1985
|
});
|
|
1979
|
-
this.config.plugins = (this.config.initialConfig.plugins ?? []).concat(this.config.userConfig.plugins ?? [], this.config.inlineConfig.plugins ?? []);
|
|
1980
|
-
await this.innerSetup();
|
|
1981
1986
|
}
|
|
1982
1987
|
/**
|
|
1983
|
-
*
|
|
1984
|
-
*/
|
|
1985
|
-
resolvedConfig = {};
|
|
1986
|
-
/**
|
|
1987
|
-
* 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.
|
|
1988
|
-
*
|
|
1989
|
-
* @remarks
|
|
1990
|
-
* 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.
|
|
1988
|
+
* A setter function to populate the user config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the user configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any inline configuration provided during execution.
|
|
1991
1989
|
*
|
|
1992
|
-
* @
|
|
1990
|
+
* @param config - The user configuration values to set.
|
|
1991
|
+
* @returns A promise that resolves when the user configuration values have been set.
|
|
1993
1992
|
*/
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
|
|
2002
|
-
context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
|
|
2003
|
-
context.packageJson = (0, _stryke_helpers_deep_clone.deepClone)(this.packageJson);
|
|
2004
|
-
context.projectJson = this.projectJson ? (0, _stryke_helpers_deep_clone.deepClone)(this.projectJson) : void 0;
|
|
2005
|
-
context.tsconfig ??= (0, _stryke_helpers_deep_clone.deepClone)(this.tsconfig);
|
|
2006
|
-
context.resolver ??= this.resolver;
|
|
2007
|
-
context.fs ??= this.#fs;
|
|
2008
|
-
context.$$internal = this.$$internal;
|
|
2009
|
-
return context;
|
|
1993
|
+
async setUserConfig(config) {
|
|
1994
|
+
this.logger.debug({
|
|
1995
|
+
meta: { category: "config" },
|
|
1996
|
+
message: `Updating user configuration object: \n${this.logConfig(config)}`
|
|
1997
|
+
});
|
|
1998
|
+
this.userConfig = config;
|
|
1999
|
+
await this.resolveConfig();
|
|
2010
2000
|
}
|
|
2011
2001
|
/**
|
|
2012
2002
|
* Initialize the context with the provided configuration options
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
this.
|
|
2022
|
-
this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
|
|
2023
|
-
const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root, "project.json");
|
|
2024
|
-
if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
|
|
2025
|
-
const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root, "package.json");
|
|
2026
|
-
if ((0, _stryke_fs_exists.existsSync)(packageJsonPath)) {
|
|
2027
|
-
this.packageJson = await (0, _stryke_fs_json.readJsonFile)(packageJsonPath);
|
|
2028
|
-
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);
|
|
2029
|
-
}
|
|
2030
|
-
this.#checksum = await this.generateChecksum((0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root));
|
|
2031
|
-
const userConfig = this.configFile.config ? Array.isArray(this.configFile.config) && this.configFile.config.length > this.options.executionIndex ? this.configFile.config[this.options.executionIndex] : this.configFile.config : {};
|
|
2032
|
-
this.resolvedConfig = {
|
|
2033
|
-
cwd: this.options.cwd,
|
|
2034
|
-
root: this.options.root,
|
|
2035
|
-
...this.initialOptions,
|
|
2036
|
-
...initialConfig,
|
|
2037
|
-
...userConfig,
|
|
2038
|
-
inlineConfig: {},
|
|
2039
|
-
pluginConfig: {},
|
|
2040
|
-
initialConfig,
|
|
2041
|
-
userConfig
|
|
2042
|
-
};
|
|
2003
|
+
*/
|
|
2004
|
+
async init() {
|
|
2005
|
+
await super.init();
|
|
2006
|
+
this.options.executionId = this.initialOptions.executionId || (0, _stryke_unique_id_uuid.uuid)();
|
|
2007
|
+
this.options.executionIndex = this.initialOptions.executionIndex ?? 0;
|
|
2008
|
+
this.#checksum = await this.generateChecksum();
|
|
2009
|
+
const result = this.configFile.config && (0, _stryke_convert_to_array.toArray)(this.configFile.config).length > this.options.executionIndex ? (0, _stryke_convert_to_array.toArray)(this.configFile.config)[this.options.executionIndex] : this.configFile.config;
|
|
2010
|
+
if (!result) this.logger.warn(`No configuration found in ${this.options.configFile} for execution index ${this.options.executionIndex}.`);
|
|
2011
|
+
else await this.setUserConfig((0, _stryke_type_checks_is_function.isFunction)(result) ? await Promise.resolve(result(this.options)) : result);
|
|
2043
2012
|
}
|
|
2044
2013
|
/**
|
|
2045
2014
|
* Initialize the context with the provided configuration options
|
|
2046
2015
|
*/
|
|
2047
|
-
async
|
|
2048
|
-
const
|
|
2049
|
-
this.
|
|
2016
|
+
async resolveConfig() {
|
|
2017
|
+
const mergedConfig = this.mergeConfig();
|
|
2018
|
+
this.logger.trace({
|
|
2019
|
+
meta: { category: "config" },
|
|
2020
|
+
message: `Pre-setup Powerlines configuration object: \n --- Pre-Resolved Config --- \n${this.logConfig(mergedConfig)} \n --- Initial Config --- \n${this.logConfig(this.initialConfig)} \n --- User Config --- \n${this.logConfig(this.userConfig)} \n --- Inline Config --- \n${this.logConfig(this.inlineConfig)} \n --- Plugin Config --- \n${this.logConfig(this.pluginConfig)}`
|
|
2021
|
+
});
|
|
2022
|
+
mergedConfig.output = (0, defu.default)(mergedConfig.output ?? {}, {
|
|
2050
2023
|
copy: { assets: [
|
|
2051
2024
|
{ glob: "LICENSE" },
|
|
2052
2025
|
{
|
|
2053
|
-
input:
|
|
2026
|
+
input: mergedConfig.root,
|
|
2054
2027
|
glob: "*.md"
|
|
2055
2028
|
},
|
|
2056
2029
|
{
|
|
2057
|
-
input:
|
|
2030
|
+
input: mergedConfig.root,
|
|
2058
2031
|
glob: "package.json"
|
|
2059
2032
|
}
|
|
2060
2033
|
] },
|
|
2061
2034
|
dts: true
|
|
2062
2035
|
});
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
if (!this.initialOptions.mode && !this.config.userConfig?.mode && !this.config.inlineConfig?.mode && !this.config.initialConfig?.mode && !this.config.pluginConfig?.mode) {
|
|
2077
|
-
this.options.mode = "production";
|
|
2078
|
-
this.config.mode = "production";
|
|
2079
|
-
}
|
|
2080
|
-
if (!this.initialOptions.framework && !this.config.userConfig?.framework && !this.config.inlineConfig?.framework && !this.config.initialConfig?.framework && !this.config.pluginConfig?.framework) {
|
|
2081
|
-
this.options.framework = "powerlines";
|
|
2082
|
-
this.config.framework = "powerlines";
|
|
2083
|
-
}
|
|
2084
|
-
if (!this.config.userConfig?.projectType && !this.config.inlineConfig?.projectType && !this.config.initialConfig?.projectType && !this.config.pluginConfig?.projectType) this.config.projectType = "application";
|
|
2085
|
-
if (!this.config.userConfig?.platform && !this.config.inlineConfig?.platform && !this.config.initialConfig?.platform && !this.config.pluginConfig?.platform) this.config.platform = "neutral";
|
|
2086
|
-
this.config.compatibilityDate = (0, compatx.resolveCompatibilityDates)(this.config.inlineConfig.compatibilityDate ?? this.config.userConfig.compatibilityDate ?? this.config.initialConfig.compatibilityDate ?? this.config.pluginConfig.compatibilityDate, "latest");
|
|
2087
|
-
this.config.input = (0, _powerlines_core_lib_entry.getUniqueInputs)(this.config.input);
|
|
2088
|
-
if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) this.config.name = this.config.name.split("/").filter(Boolean)[1];
|
|
2089
|
-
this.config.title ??= (0, _stryke_string_format_title_case.titleCase)(this.config.name);
|
|
2090
|
-
if (this.config.resolve.external) this.config.resolve.external = (0, _stryke_helpers_get_unique.getUnique)(this.config.resolve.external);
|
|
2091
|
-
if (this.config.resolve.noExternal) this.config.resolve.noExternal = (0, _stryke_helpers_get_unique.getUnique)(this.config.resolve.noExternal);
|
|
2092
|
-
this.config.plugins = (this.config.plugins ?? []).flatMap((plugin) => (0, _stryke_convert_to_array.toArray)(plugin)).filter(Boolean).reduce((ret, plugin) => {
|
|
2036
|
+
if (!mergedConfig.mode) mergedConfig.mode = "production";
|
|
2037
|
+
if (!mergedConfig.framework) mergedConfig.framework = "powerlines";
|
|
2038
|
+
if (!mergedConfig.projectType) mergedConfig.projectType = "application";
|
|
2039
|
+
if (!mergedConfig.platform) mergedConfig.platform = "neutral";
|
|
2040
|
+
mergedConfig.compatibilityDate = (0, compatx.resolveCompatibilityDates)(mergedConfig.compatibilityDate, "latest");
|
|
2041
|
+
this.resolvedConfig = mergedConfig;
|
|
2042
|
+
this.#configProxy = this.createConfigProxy();
|
|
2043
|
+
mergedConfig.input = (0, _powerlines_core_lib_entry.getUniqueInputs)(mergedConfig.input);
|
|
2044
|
+
if (mergedConfig.name?.startsWith("@") && mergedConfig.name.split("/").filter(Boolean).length > 1) mergedConfig.name = mergedConfig.name.split("/").filter(Boolean)[1];
|
|
2045
|
+
mergedConfig.title ??= (0, _stryke_string_format_title_case.titleCase)(mergedConfig.name);
|
|
2046
|
+
if (mergedConfig.resolve.external) mergedConfig.resolve.external = (0, _stryke_helpers_get_unique.getUnique)(mergedConfig.resolve.external);
|
|
2047
|
+
if (mergedConfig.resolve.noExternal) mergedConfig.resolve.noExternal = (0, _stryke_helpers_get_unique.getUnique)(mergedConfig.resolve.noExternal);
|
|
2048
|
+
mergedConfig.plugins = (mergedConfig.plugins ?? []).flatMap((plugin) => (0, _stryke_convert_to_array.toArray)(plugin)).filter(Boolean).reduce((ret, plugin) => {
|
|
2093
2049
|
if ((0, _powerlines_core_plugin_utils.isPlugin)(plugin) && (0, _powerlines_core_plugin_utils.isDuplicate)(plugin, ret.filter((p) => (0, _powerlines_core_plugin_utils.isPlugin)(p)))) return ret;
|
|
2094
2050
|
ret.push(plugin);
|
|
2095
2051
|
return ret;
|
|
2096
2052
|
}, []);
|
|
2097
|
-
if (!
|
|
2098
|
-
else if (
|
|
2099
|
-
else
|
|
2100
|
-
if (
|
|
2101
|
-
else
|
|
2102
|
-
|
|
2103
|
-
if (
|
|
2104
|
-
else
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
if (this.config.output.types !== false) this.config.output.types = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.userConfig?.output?.types || this.config.inlineConfig?.output?.types || this.config.initialConfig?.output?.types || this.config.pluginConfig?.output?.types || (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
|
|
2111
|
-
if (this.config.output.copy && this.config.output.copy.path && this.config.output.copy.assets && Array.isArray(this.config.output.copy.assets)) this.config.output.copy.assets = (0, _stryke_helpers_get_unique.getUniqueBy)(this.config.output.copy.assets.map((asset) => {
|
|
2053
|
+
if (!mergedConfig.logLevel) if (mergedConfig.mode === "development") mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_DEVELOPMENT_LOG_LEVEL;
|
|
2054
|
+
else if (mergedConfig.mode === "test") mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_TEST_LOG_LEVEL;
|
|
2055
|
+
else mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_PRODUCTION_LOG_LEVEL;
|
|
2056
|
+
if (mergedConfig.tsconfig) mergedConfig.tsconfig = (0, _stryke_path_replace.replacePath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.tsconfig), mergedConfig.cwd);
|
|
2057
|
+
else mergedConfig.tsconfig = require_tsconfig.getTsconfigFilePath(mergedConfig.cwd, mergedConfig.root);
|
|
2058
|
+
mergedConfig.output.format = (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(mergedConfig.output?.format ?? (mergedConfig.projectType === "library" ? ["cjs", "esm"] : ["esm"])));
|
|
2059
|
+
if (mergedConfig.output.path) mergedConfig.output.path = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.path), mergedConfig.cwd);
|
|
2060
|
+
else mergedConfig.output.path = (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(mergedConfig.root, "dist"), mergedConfig.cwd);
|
|
2061
|
+
mergedConfig.output.copy ??= {};
|
|
2062
|
+
if (mergedConfig.output.copy !== false) if (!mergedConfig.root.replace(/^\.\/?/, "")) mergedConfig.output.copy.path = mergedConfig.output.copy.path ? (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.copy.path), mergedConfig.cwd) : mergedConfig.output.path;
|
|
2063
|
+
else mergedConfig.output.copy.path = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.copy.path || (0, _stryke_path_join.joinPaths)("dist", mergedConfig.root)), mergedConfig.cwd);
|
|
2064
|
+
if (mergedConfig.output.types !== false) mergedConfig.output.types = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.types || (0, _stryke_path_join.joinPaths)(mergedConfig.root, `${mergedConfig.framework ?? "powerlines"}.d.ts`)), mergedConfig.cwd);
|
|
2065
|
+
if (mergedConfig.output.copy && mergedConfig.output.copy.path && mergedConfig.output.copy.assets && Array.isArray(mergedConfig.output.copy.assets)) mergedConfig.output.copy.assets = (0, _stryke_helpers_get_unique.getUniqueBy)(mergedConfig.output.copy.assets.map((asset) => {
|
|
2112
2066
|
return {
|
|
2113
2067
|
glob: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) ? asset.glob : asset,
|
|
2114
|
-
input: (0, _stryke_type_checks_is_string.isString)(asset) || !asset.input || asset.input === "." || asset.input === "/" || asset.input === "./" ?
|
|
2115
|
-
output: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) && asset.output ? (0, _stryke_path_is_parent_path.isParentPath)(asset.output,
|
|
2068
|
+
input: (0, _stryke_type_checks_is_string.isString)(asset) || !asset.input || asset.input === "." || asset.input === "/" || asset.input === "./" ? mergedConfig.cwd : (0, _stryke_path_is_parent_path.isParentPath)(asset.input, mergedConfig.cwd) || (0, _stryke_path_is_equal.isEqual)(asset.input, mergedConfig.cwd) ? asset.input : (0, _stryke_path_append.appendPath)(asset.input, mergedConfig.cwd),
|
|
2069
|
+
output: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) && asset.output ? (0, _stryke_path_is_parent_path.isParentPath)(asset.output, mergedConfig.cwd) ? asset.output : (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(mergedConfig.output.copy.path, (0, _stryke_path_replace.replacePath)((0, _stryke_path_replace.replacePath)(asset.output, (0, _stryke_path_replace.replacePath)(mergedConfig.output.copy.path, mergedConfig.cwd)), mergedConfig.output.copy.path)), mergedConfig.cwd) : (0, _stryke_path_append.appendPath)(mergedConfig.output.copy.path, mergedConfig.cwd),
|
|
2116
2070
|
ignore: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) && asset.ignore ? (0, _stryke_convert_to_array.toArray)(asset.ignore) : void 0
|
|
2117
2071
|
};
|
|
2118
2072
|
}), (a) => `${a.input}-${a.glob}-${a.output}`);
|
|
2119
|
-
if (!
|
|
2120
|
-
else
|
|
2121
|
-
if (!
|
|
2122
|
-
else
|
|
2123
|
-
if (!
|
|
2124
|
-
if (
|
|
2073
|
+
if (!mergedConfig.output?.sourceMap) if (mergedConfig.mode === "development") mergedConfig.output.sourceMap = true;
|
|
2074
|
+
else mergedConfig.output.sourceMap = false;
|
|
2075
|
+
if (!mergedConfig.output.minify) if (mergedConfig.mode === "production") mergedConfig.output.minify = true;
|
|
2076
|
+
else mergedConfig.output.minify = false;
|
|
2077
|
+
if (!mergedConfig.output.artifactsPath) mergedConfig.output.artifactsPath = `.${mergedConfig.framework || "powerlines"}`;
|
|
2078
|
+
if (mergedConfig.output.copy && mergedConfig.output.copy.assets) mergedConfig.output.copy.assets = mergedConfig.output.copy.assets.map((asset) => ({
|
|
2125
2079
|
...asset,
|
|
2126
2080
|
glob: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.glob),
|
|
2127
2081
|
ignore: asset.ignore ? asset.ignore.map((ignore) => (0, _powerlines_core_plugin_utils.replacePathTokens)(this, ignore)) : void 0,
|
|
2128
2082
|
input: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.input),
|
|
2129
2083
|
output: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.output)
|
|
2130
2084
|
}));
|
|
2131
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(
|
|
2085
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(mergedConfig.output?.storage) && mergedConfig.output.storage === "virtual" || (0, _stryke_type_checks_is_set_object.isSetObject)(mergedConfig.output?.storage) && Object.values(mergedConfig.output.storage).every((adapter) => adapter.preset === "virtual")) mergedConfig.output.overwrite = true;
|
|
2086
|
+
this.resolvedConfig = mergedConfig;
|
|
2087
|
+
this.#configProxy = this.createConfigProxy();
|
|
2088
|
+
this.logger.debug({
|
|
2089
|
+
meta: { category: "config" },
|
|
2090
|
+
message: `Resolved Powerlines configuration object: \n --- Resolved Config --- \n${this.logConfig(this.resolvedConfig)} \n --- Initial Config --- \n${this.logConfig(this.initialConfig)} \n --- User Config --- \n${this.logConfig(this.userConfig)} \n --- Inline Config --- \n${this.logConfig(this.inlineConfig)} \n --- Plugin Config --- \n${this.logConfig(this.pluginConfig)}`
|
|
2091
|
+
});
|
|
2132
2092
|
this.#fs ??= await VirtualFileSystem.create(this);
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2093
|
+
}
|
|
2094
|
+
logConfig(config) {
|
|
2095
|
+
return (0, _storm_software_config_tools_logger_console.formatLogMessage)({
|
|
2096
|
+
...(0, _stryke_helpers_omit.omit)(config, ["plugins"]),
|
|
2097
|
+
plugins: config.plugins ? config.plugins.flatMap((plugin) => (0, _stryke_convert_to_array.toArray)(plugin)).map((plugin) => String((0, _stryke_type_checks_is_set_string.isSetString)(plugin) ? plugin : (0, _stryke_type_checks_is_promise.isPromise)(plugin) ? "<promise>" : (0, _stryke_type_checks_is_function.isFunction)(plugin) ? plugin.name || "<anonymous function>" : Array.isArray(plugin) ? plugin[0] || "<anonymous function plugin>" : "<unknown plugin>")) : void 0
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
createConfigProxy() {
|
|
2101
|
+
return new Proxy(this.resolvedConfig, {
|
|
2102
|
+
/**
|
|
2103
|
+
* A trap for the `delete` operator.
|
|
2104
|
+
* @param target - The original object which is being proxied.
|
|
2105
|
+
* @param key - The name or `Symbol` of the property to delete.
|
|
2106
|
+
* @returns A `boolean` indicating whether or not the property was deleted.
|
|
2107
|
+
*/
|
|
2108
|
+
deleteProperty: (target, key) => {
|
|
2109
|
+
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) throw new Error(`Cannot delete property ${key.toString()} from config - it is only intended to be used as a reference.`);
|
|
2110
|
+
Reflect.deleteProperty(this.overriddenConfig, key);
|
|
2111
|
+
return Reflect.deleteProperty(target, key);
|
|
2112
|
+
},
|
|
2113
|
+
/**
|
|
2114
|
+
* A trap for getting a property value.
|
|
2115
|
+
* @param target - The original object which is being proxied.
|
|
2116
|
+
* @param key - The name or `Symbol` of the property to get.
|
|
2117
|
+
* @param receiver - The proxy or an object that inherits from the proxy.
|
|
2118
|
+
*/
|
|
2119
|
+
get: (target, key, receiver) => {
|
|
2120
|
+
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) {
|
|
2121
|
+
if (key === "initialConfig") return this.initialConfig;
|
|
2122
|
+
if (key === "userConfig") return this.userConfig;
|
|
2123
|
+
if (key === "inlineConfig") return this.inlineConfig;
|
|
2124
|
+
if (key === "pluginConfig") return this.pluginConfig;
|
|
2125
|
+
}
|
|
2126
|
+
return Reflect.get(target, key, receiver);
|
|
2127
|
+
},
|
|
2128
|
+
/**
|
|
2129
|
+
* A trap for the `in` operator.
|
|
2130
|
+
* @param target - The original object which is being proxied.
|
|
2131
|
+
* @param key - The name or `Symbol` of the property to check for existence.
|
|
2132
|
+
*/
|
|
2133
|
+
has: (target, key) => {
|
|
2134
|
+
return Reflect.has(target, key) || UNRESOLVED_CONFIG_NAMES.includes(key.toString());
|
|
2135
|
+
},
|
|
2136
|
+
/**
|
|
2137
|
+
* A trap for `Reflect.ownKeys()`.
|
|
2138
|
+
* @param target - The original object which is being proxied.
|
|
2139
|
+
*/
|
|
2140
|
+
ownKeys: (target) => {
|
|
2141
|
+
return (0, _stryke_helpers_get_unique.getUnique)([...Reflect.ownKeys(target), ...UNRESOLVED_CONFIG_NAMES]);
|
|
2142
|
+
},
|
|
2143
|
+
/**
|
|
2144
|
+
* A trap for setting a property value.
|
|
2145
|
+
* @param target - The original object which is being proxied.
|
|
2146
|
+
* @param key - The name or `Symbol` of the property to set.
|
|
2147
|
+
* @param newValue - The new value to assign to the property.
|
|
2148
|
+
* @param receiver - The object to which the assignment was originally directed.
|
|
2149
|
+
* @returns A `boolean` indicating whether or not the property was set.
|
|
2150
|
+
*/
|
|
2151
|
+
set: (target, key, newValue, receiver) => {
|
|
2152
|
+
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) throw new Error(`Cannot change property ${key.toString()} from config - it is only intended to be used as a reference.`);
|
|
2153
|
+
Reflect.set(this.overriddenConfig, key, newValue, receiver);
|
|
2154
|
+
return Reflect.set(target, key, newValue, receiver);
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2146
2157
|
}
|
|
2147
2158
|
};
|
|
2148
2159
|
|
|
@@ -2287,7 +2298,7 @@ function createPluginContext(pluginId, plugin, environment) {
|
|
|
2287
2298
|
return {
|
|
2288
2299
|
meta: {
|
|
2289
2300
|
...(0, _stryke_type_checks_is_set_object.isSetObject)(message) ? message.meta : {},
|
|
2290
|
-
environment: environment.environment
|
|
2301
|
+
environment: environment.config.environment.name,
|
|
2291
2302
|
plugin: plugin.name
|
|
2292
2303
|
},
|
|
2293
2304
|
message: (0, _stryke_type_checks_is_string.isString)(message) ? message : message.message
|
|
@@ -2310,6 +2321,8 @@ function createPluginContext(pluginId, plugin, environment) {
|
|
|
2310
2321
|
callHook: callHookFn,
|
|
2311
2322
|
meta
|
|
2312
2323
|
};
|
|
2324
|
+
if (prop === "api") return environment.$$internal.api;
|
|
2325
|
+
if (prop === "environment") return environment;
|
|
2313
2326
|
if (prop === "id") return pluginId;
|
|
2314
2327
|
if (prop === "logger") return logger;
|
|
2315
2328
|
if (prop === "log") return (type, message) => {
|
|
@@ -2362,6 +2375,15 @@ function createPluginContext(pluginId, plugin, environment) {
|
|
|
2362
2375
|
//#endregion
|
|
2363
2376
|
//#region src/context/environment-context.ts
|
|
2364
2377
|
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
2378
|
+
/**
|
|
2379
|
+
* Internal references storage
|
|
2380
|
+
*
|
|
2381
|
+
* @danger
|
|
2382
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2383
|
+
*
|
|
2384
|
+
* @internal
|
|
2385
|
+
*/
|
|
2386
|
+
#internal = {};
|
|
2365
2387
|
/**
|
|
2366
2388
|
* The hooks registered by plugins in this environment
|
|
2367
2389
|
*/
|
|
@@ -2371,29 +2393,50 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2371
2393
|
*
|
|
2372
2394
|
* @param options - The resolved execution options.
|
|
2373
2395
|
* @param config - The user configuration options.
|
|
2374
|
-
* @
|
|
2396
|
+
* @param overriddenConfig - The configuration options that should override all other configuration sources, such as CLI flags or environment variables. This is used to ensure that certain configuration values take precedence over any other settings defined in the user configuration or environment configuration, allowing for dynamic overrides based on the execution context.
|
|
2397
|
+
* @param environment - The resolved environment configuration, which may include additional properties or modifications made during the configuration loading process. This is used to provide context about the environment in which the command is being executed, allowing for environment-specific behavior and configuration resolution.
|
|
2398
|
+
* @returns A promise that resolves to an instance of the PowerlinesEnvironmentContext class, initialized with the provided configuration and environment data.
|
|
2375
2399
|
*/
|
|
2376
|
-
static async
|
|
2377
|
-
const context = new PowerlinesEnvironmentContext(options, config,
|
|
2378
|
-
await context.
|
|
2379
|
-
const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
|
|
2380
|
-
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
2381
|
-
context.powerlinesPath = powerlinesPath;
|
|
2400
|
+
static async createEnvironment(options, config, overriddenConfig, environment) {
|
|
2401
|
+
const context = new PowerlinesEnvironmentContext(options, config, overriddenConfig);
|
|
2402
|
+
await context.setEnvironmentConfig(environment);
|
|
2382
2403
|
return context;
|
|
2383
2404
|
}
|
|
2384
2405
|
/**
|
|
2385
|
-
* The
|
|
2406
|
+
* The configuration options provided by plugins added by the user (and other plugins)
|
|
2386
2407
|
*/
|
|
2387
|
-
|
|
2408
|
+
environmentConfig = {};
|
|
2388
2409
|
/**
|
|
2389
2410
|
* The list of plugins applied to this environment
|
|
2390
2411
|
*/
|
|
2391
2412
|
plugins = [];
|
|
2392
2413
|
/**
|
|
2414
|
+
* Internal context fields and methods
|
|
2415
|
+
*
|
|
2416
|
+
* @danger
|
|
2417
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2418
|
+
*
|
|
2419
|
+
* @internal
|
|
2420
|
+
*/
|
|
2421
|
+
get $$internal() {
|
|
2422
|
+
return this.#internal;
|
|
2423
|
+
}
|
|
2424
|
+
/**
|
|
2425
|
+
* Internal context fields and methods
|
|
2426
|
+
*
|
|
2427
|
+
* @danger
|
|
2428
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2429
|
+
*
|
|
2430
|
+
* @internal
|
|
2431
|
+
*/
|
|
2432
|
+
set $$internal(value) {
|
|
2433
|
+
this.#internal = value;
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2393
2436
|
* The unique identifier of the environment associated with this context, which can be used for logging and other purposes to distinguish between different environments in the same process.
|
|
2394
2437
|
*/
|
|
2395
2438
|
get id() {
|
|
2396
|
-
return this.environment.
|
|
2439
|
+
return this.config.environment.id;
|
|
2397
2440
|
}
|
|
2398
2441
|
/**
|
|
2399
2442
|
* The hooks registered by plugins in this environment
|
|
@@ -2402,6 +2445,20 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2402
2445
|
return this.#hooks;
|
|
2403
2446
|
}
|
|
2404
2447
|
/**
|
|
2448
|
+
* A setter function to populate the environment config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the environment configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any environment configuration provided during execution.
|
|
2449
|
+
*
|
|
2450
|
+
* @param config - The environment configuration values to set.
|
|
2451
|
+
* @returns A promise that resolves when the environment configuration values have been set.
|
|
2452
|
+
*/
|
|
2453
|
+
async setEnvironmentConfig(config) {
|
|
2454
|
+
this.logger.debug({
|
|
2455
|
+
meta: { category: "config" },
|
|
2456
|
+
message: `Updating environment configuration object: \n${this.logConfig(config)}`
|
|
2457
|
+
});
|
|
2458
|
+
this.environmentConfig = config;
|
|
2459
|
+
await this.resolveConfig();
|
|
2460
|
+
}
|
|
2461
|
+
/**
|
|
2405
2462
|
* Create a new logger instance
|
|
2406
2463
|
*
|
|
2407
2464
|
* @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
|
|
@@ -2411,7 +2468,7 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2411
2468
|
createLogger(options, logFn) {
|
|
2412
2469
|
return super.createLogger({
|
|
2413
2470
|
...options,
|
|
2414
|
-
environment: this.environment?.name
|
|
2471
|
+
environment: this.config.environment?.name
|
|
2415
2472
|
}, logFn);
|
|
2416
2473
|
}
|
|
2417
2474
|
/**
|
|
@@ -2423,39 +2480,13 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2423
2480
|
extendLogger(options) {
|
|
2424
2481
|
return super.extendLogger({
|
|
2425
2482
|
...options,
|
|
2426
|
-
environment: this.environment?.name
|
|
2483
|
+
environment: this.config.environment?.name
|
|
2427
2484
|
});
|
|
2428
2485
|
}
|
|
2429
|
-
/**
|
|
2430
|
-
* 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.
|
|
2431
|
-
*
|
|
2432
|
-
* @remarks
|
|
2433
|
-
* 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.
|
|
2434
|
-
*
|
|
2435
|
-
* @returns A promise that resolves to the cloned context.
|
|
2436
|
-
*/
|
|
2437
|
-
async clone() {
|
|
2438
|
-
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));
|
|
2439
|
-
return this.copyTo(context);
|
|
2440
|
-
}
|
|
2441
|
-
/**
|
|
2442
|
-
* Initialize the context with the provided configuration options
|
|
2443
|
-
*/
|
|
2444
|
-
async setup() {
|
|
2445
|
-
this.resolvedConfig = (0, _powerlines_core_plugin_utils.mergeConfig)({
|
|
2446
|
-
name: this.config.name,
|
|
2447
|
-
title: this.config.title
|
|
2448
|
-
}, getConfigProps({
|
|
2449
|
-
...this.environment,
|
|
2450
|
-
root: this.options.root,
|
|
2451
|
-
cwd: this.options.cwd
|
|
2452
|
-
}), this.config);
|
|
2453
|
-
await this.innerSetup();
|
|
2454
|
-
}
|
|
2455
2486
|
async addPlugin(plugin) {
|
|
2456
2487
|
let resolvedPlugin = plugin;
|
|
2457
2488
|
if ((0, _stryke_type_checks_is_function.isFunction)(plugin.applyToEnvironment)) {
|
|
2458
|
-
const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
|
|
2489
|
+
const result = await Promise.resolve(plugin.applyToEnvironment(this.config.environment));
|
|
2459
2490
|
if (!result || (0, _stryke_type_checks_is_object.isObject)(result) && Object.keys(result).length === 0) return;
|
|
2460
2491
|
if ((0, _powerlines_core_plugin_utils.isPluginConfig)(result)) return this.$$internal.addPlugin(result);
|
|
2461
2492
|
resolvedPlugin = (0, _powerlines_core_plugin_utils.isPlugin)(result) ? result : plugin;
|
|
@@ -2506,29 +2537,51 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2506
2537
|
}
|
|
2507
2538
|
return result;
|
|
2508
2539
|
}
|
|
2509
|
-
constructor(options, config,
|
|
2510
|
-
super(options);
|
|
2511
|
-
this.
|
|
2512
|
-
this.
|
|
2540
|
+
constructor(options, config, overriddenConfig) {
|
|
2541
|
+
super(options, config.initialConfig);
|
|
2542
|
+
this.userConfig = config.userConfig ?? {};
|
|
2543
|
+
this.inlineConfig = config.inlineConfig ?? {};
|
|
2544
|
+
this.pluginConfig = config.pluginConfig ?? {};
|
|
2545
|
+
this.overriddenConfig = overriddenConfig;
|
|
2513
2546
|
}
|
|
2514
2547
|
/**
|
|
2515
|
-
*
|
|
2516
|
-
*
|
|
2517
|
-
* @remarks
|
|
2518
|
-
* 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.
|
|
2548
|
+
* A function to merge the various configuration objects (initial, user, inline, and plugin) into a single resolved configuration object that can be used throughout the Powerlines process. This function takes into account the different sources of configuration and their respective priorities, ensuring that the final configuration reflects the intended settings for the project. The merged configuration is then returned as a new object that can be accessed through the `config` property of the context.
|
|
2519
2549
|
*
|
|
2520
|
-
* @returns The
|
|
2550
|
+
* @returns The merged configuration object that combines the initial, user, inline, and plugin configurations.
|
|
2521
2551
|
*/
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2552
|
+
mergeConfig() {
|
|
2553
|
+
return (0, _powerlines_core_plugin_utils.mergeConfig)({
|
|
2554
|
+
...(0, _stryke_helpers_omit.omit)(this.environmentConfig ?? {}, [
|
|
2555
|
+
"ssr",
|
|
2556
|
+
"preview",
|
|
2557
|
+
"consumer",
|
|
2558
|
+
"runtime"
|
|
2559
|
+
]),
|
|
2560
|
+
environment: { name: this.environmentConfig?.name || _powerlines_core_constants.DEFAULT_ENVIRONMENT },
|
|
2561
|
+
environmentConfig: this.environmentConfig ?? {}
|
|
2562
|
+
}, super.mergeConfig());
|
|
2525
2563
|
}
|
|
2526
2564
|
};
|
|
2527
2565
|
|
|
2528
2566
|
//#endregion
|
|
2529
2567
|
//#region src/context/execution-context.ts
|
|
2530
2568
|
var PowerlinesExecutionContext = class PowerlinesExecutionContext extends PowerlinesContext {
|
|
2569
|
+
/**
|
|
2570
|
+
* Internal references storage
|
|
2571
|
+
*
|
|
2572
|
+
* @danger
|
|
2573
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2574
|
+
*
|
|
2575
|
+
* @internal
|
|
2576
|
+
*/
|
|
2577
|
+
#internal = {};
|
|
2578
|
+
/**
|
|
2579
|
+
* A record of all environments by name
|
|
2580
|
+
*/
|
|
2531
2581
|
#environments = {};
|
|
2582
|
+
/**
|
|
2583
|
+
* The plugins added to this execution context, which may be used to track the plugins that have been added to the context and ensure that they are properly registered and executed during the build process. This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2584
|
+
*/
|
|
2532
2585
|
#plugins = [];
|
|
2533
2586
|
/**
|
|
2534
2587
|
* Create a new Storm context from the workspace root and user config.
|
|
@@ -2536,12 +2589,9 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2536
2589
|
* @param options - The options for resolving the context.
|
|
2537
2590
|
* @returns A promise that resolves to the new context.
|
|
2538
2591
|
*/
|
|
2539
|
-
static async
|
|
2540
|
-
const context = new PowerlinesExecutionContext(options);
|
|
2541
|
-
await context.init(
|
|
2542
|
-
const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
|
|
2543
|
-
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
2544
|
-
context.powerlinesPath = powerlinesPath;
|
|
2592
|
+
static async fromInitialConfig(options, initialConfig) {
|
|
2593
|
+
const context = new PowerlinesExecutionContext(options, initialConfig);
|
|
2594
|
+
await context.init();
|
|
2545
2595
|
return context;
|
|
2546
2596
|
}
|
|
2547
2597
|
/**
|
|
@@ -2550,19 +2600,10 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2550
2600
|
* @param options - The options for resolving the context.
|
|
2551
2601
|
* @returns A promise that resolves to the new context.
|
|
2552
2602
|
*/
|
|
2553
|
-
static async
|
|
2554
|
-
const context = new PowerlinesExecutionContext(options);
|
|
2555
|
-
await context.init(
|
|
2556
|
-
context.
|
|
2557
|
-
if (context.config.inlineConfig.command === "new") {
|
|
2558
|
-
const workspacePackageJsonPath = (0, _stryke_path_join.joinPaths)(context.config.cwd, "package.json");
|
|
2559
|
-
if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
2560
|
-
context.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
|
|
2561
|
-
}
|
|
2562
|
-
await context.setup();
|
|
2563
|
-
const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
|
|
2564
|
-
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
2565
|
-
context.powerlinesPath = powerlinesPath;
|
|
2603
|
+
static async fromInlineConfig(options, initialConfig, inlineConfig) {
|
|
2604
|
+
const context = new PowerlinesExecutionContext(options, initialConfig);
|
|
2605
|
+
await context.init();
|
|
2606
|
+
await context.setInlineConfig(inlineConfig);
|
|
2566
2607
|
return context;
|
|
2567
2608
|
}
|
|
2568
2609
|
/**
|
|
@@ -2574,7 +2615,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2574
2615
|
* @internal
|
|
2575
2616
|
*/
|
|
2576
2617
|
get $$internal() {
|
|
2577
|
-
return
|
|
2618
|
+
return this.#internal;
|
|
2578
2619
|
}
|
|
2579
2620
|
/**
|
|
2580
2621
|
* Internal context fields and methods
|
|
@@ -2585,8 +2626,8 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2585
2626
|
* @internal
|
|
2586
2627
|
*/
|
|
2587
2628
|
set $$internal(value) {
|
|
2588
|
-
|
|
2589
|
-
for (const environment of Object.values(this.environments)) environment.$$internal =
|
|
2629
|
+
this.#internal = value;
|
|
2630
|
+
for (const environment of Object.values(this.environments)) environment.$$internal = value;
|
|
2590
2631
|
}
|
|
2591
2632
|
/**
|
|
2592
2633
|
* The unique identifier of the execution context, which can be used for logging and other purposes to distinguish between different executions in the same process.
|
|
@@ -2607,9 +2648,26 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2607
2648
|
* Creates a new instance.
|
|
2608
2649
|
*
|
|
2609
2650
|
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
2651
|
+
* @param initialConfig - The initial configuration options to use for the context, which can be used to provide default values for configuration options that may be overridden by user configuration or inline configuration. This is typically the configuration options provided by the user in a configuration file on disk, and can include any relevant settings such as environment definitions, plugin configurations, and other parameters that may be relevant to the execution of a Powerlines command.
|
|
2610
2652
|
*/
|
|
2611
|
-
constructor(options) {
|
|
2612
|
-
super(options);
|
|
2653
|
+
constructor(options, initialConfig = {}) {
|
|
2654
|
+
super(options, initialConfig);
|
|
2655
|
+
this.initialOptions = options;
|
|
2656
|
+
this.initialConfig = initialConfig;
|
|
2657
|
+
}
|
|
2658
|
+
/**
|
|
2659
|
+
* A setter function to populate the inline config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the inline configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any inline configuration provided during execution.
|
|
2660
|
+
*
|
|
2661
|
+
* @param config - The inline configuration values to set.
|
|
2662
|
+
* @returns A promise that resolves when the inline configuration values have been set.
|
|
2663
|
+
*/
|
|
2664
|
+
async setInlineConfig(config) {
|
|
2665
|
+
await super.setInlineConfig(config);
|
|
2666
|
+
if (this.inlineConfig.command === "new") {
|
|
2667
|
+
const workspacePackageJsonPath = (0, _stryke_path_join.joinPaths)(this.config.cwd, "package.json");
|
|
2668
|
+
if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
2669
|
+
this.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
|
|
2670
|
+
}
|
|
2613
2671
|
}
|
|
2614
2672
|
/**
|
|
2615
2673
|
* Create a new logger instance
|
|
@@ -2639,31 +2697,20 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2639
2697
|
});
|
|
2640
2698
|
}
|
|
2641
2699
|
/**
|
|
2642
|
-
* 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.
|
|
2643
|
-
*
|
|
2644
|
-
* @remarks
|
|
2645
|
-
* 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.
|
|
2646
|
-
*
|
|
2647
|
-
* @returns A promise that resolves to the cloned context.
|
|
2648
|
-
*/
|
|
2649
|
-
async clone() {
|
|
2650
|
-
const clone = await PowerlinesExecutionContext.init(this.options, this.initialConfig);
|
|
2651
|
-
clone.config.userConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.userConfig);
|
|
2652
|
-
clone.config.initialConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.initialConfig);
|
|
2653
|
-
clone.config.inlineConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.inlineConfig);
|
|
2654
|
-
clone.config.pluginConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.pluginConfig);
|
|
2655
|
-
await clone.setup();
|
|
2656
|
-
clone.$$internal = this.$$internal;
|
|
2657
|
-
return this.copyTo(clone);
|
|
2658
|
-
}
|
|
2659
|
-
/**
|
|
2660
2700
|
* A function to copy the context and update the fields for a specific environment
|
|
2661
2701
|
*
|
|
2662
2702
|
* @param environment - The environment configuration to use.
|
|
2663
2703
|
* @returns A new context instance with the updated environment.
|
|
2664
2704
|
*/
|
|
2665
|
-
async
|
|
2666
|
-
const context =
|
|
2705
|
+
async createEnvironment(environment) {
|
|
2706
|
+
const context = await PowerlinesEnvironmentContext.createEnvironment((0, _stryke_helpers_deep_clone.deepClone)(this.options), (0, _stryke_helpers_deep_clone.deepClone)(this.config), (0, _stryke_helpers_deep_clone.deepClone)(this.overriddenConfig), (0, _stryke_helpers_deep_clone.deepClone)(environment));
|
|
2707
|
+
context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
|
|
2708
|
+
context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
|
|
2709
|
+
context.persistedMeta = (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta);
|
|
2710
|
+
context.resolvePatterns = (0, _stryke_helpers_deep_clone.deepClone)(this.resolvePatterns);
|
|
2711
|
+
context.powerlinesPath ??= this.powerlinesPath;
|
|
2712
|
+
context.resolver ??= this.resolver;
|
|
2713
|
+
context.$$internal = this.$$internal;
|
|
2667
2714
|
context.plugins = [];
|
|
2668
2715
|
for (const plugin of this.plugins) await context.addPlugin(plugin);
|
|
2669
2716
|
return context;
|
|
@@ -2671,10 +2718,10 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2671
2718
|
/**
|
|
2672
2719
|
* Update the context using a new inline configuration options
|
|
2673
2720
|
*/
|
|
2674
|
-
async
|
|
2675
|
-
await super.
|
|
2721
|
+
async resolveConfig() {
|
|
2722
|
+
await super.resolveConfig();
|
|
2676
2723
|
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) => {
|
|
2677
|
-
this.#environments[env.name] = await this.
|
|
2724
|
+
this.#environments[env.name] = await this.createEnvironment(env);
|
|
2678
2725
|
}));
|
|
2679
2726
|
}
|
|
2680
2727
|
/**
|
|
@@ -2699,12 +2746,20 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2699
2746
|
if (name) environment = this.environments[name];
|
|
2700
2747
|
if (Object.keys(this.environments).length === 1) {
|
|
2701
2748
|
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2702
|
-
this.
|
|
2749
|
+
this.trace({
|
|
2750
|
+
meta: { category: "plugins" },
|
|
2751
|
+
message: `Applying the only configured environment: ${chalk.default.bold.cyanBright(environment?.config.environment?.name)}`
|
|
2752
|
+
});
|
|
2703
2753
|
}
|
|
2704
2754
|
if (!environment) {
|
|
2705
2755
|
if (name) throw new Error(`Environment "${name}" not found.`);
|
|
2706
|
-
environment = await this.
|
|
2707
|
-
|
|
2756
|
+
environment = await PowerlinesEnvironmentContext.createEnvironment((0, _stryke_helpers_deep_clone.deepClone)(this.options), (0, _stryke_helpers_deep_clone.deepClone)(this.config), (0, _stryke_helpers_deep_clone.deepClone)(this.overriddenConfig), (0, _stryke_helpers_deep_clone.deepClone)(createDefaultEnvironment(this.config)));
|
|
2757
|
+
environment.plugins = [];
|
|
2758
|
+
for (const plugin of this.plugins) await environment.addPlugin(plugin);
|
|
2759
|
+
this.warn({
|
|
2760
|
+
meta: { category: "plugins" },
|
|
2761
|
+
message: `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment.config.environment?.name)}`
|
|
2762
|
+
});
|
|
2708
2763
|
}
|
|
2709
2764
|
return environment;
|
|
2710
2765
|
}
|
|
@@ -2732,8 +2787,11 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2732
2787
|
async toEnvironment() {
|
|
2733
2788
|
let environment;
|
|
2734
2789
|
if (Object.keys(this.environments).length > 1) {
|
|
2735
|
-
environment = await this.
|
|
2736
|
-
this.debug(
|
|
2790
|
+
environment = await this.createEnvironment(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config));
|
|
2791
|
+
this.debug({
|
|
2792
|
+
meta: { category: "plugins" },
|
|
2793
|
+
message: `Combined all ${Object.keys(this.environments).length} environments into a single global context.`
|
|
2794
|
+
});
|
|
2737
2795
|
} else environment = await this.getEnvironment();
|
|
2738
2796
|
return environment;
|
|
2739
2797
|
}
|