@powerlines/engine 0.45.3 → 0.46.1
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 +886 -803
- package/dist/_internal/worker.mjs +889 -806
- 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-D7G_24-i.cjs} +82 -76
- package/dist/{base-context-BSAC5sO9.mjs → base-context-DU0NRHDt.mjs} +85 -79
- package/dist/base-context-DU0NRHDt.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-BuJQY312.cjs +91 -0
- package/dist/engine-context-BvDfqfY7.mjs +86 -0
- package/dist/engine-context-BvDfqfY7.mjs.map +1 -0
- package/dist/execution-context-BpRfsnkE.d.mts +644 -0
- package/dist/execution-context-BpRfsnkE.d.mts.map +1 -0
- package/dist/{execution-context-BYGFYty0.cjs → execution-context-BrX9i_L8.cjs} +449 -364
- package/dist/{execution-context-Bkxp1fML.mjs → execution-context-CgDuoi8o.mjs} +451 -366
- package/dist/execution-context-CgDuoi8o.mjs.map +1 -0
- package/dist/execution-context-CodQucFX.d.cts +644 -0
- package/dist/execution-context-CodQucFX.d.cts.map +1 -0
- 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-Bkxp1fML.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-D7G_24-i.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,247 @@ 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.
|
|
1962
1955
|
*/
|
|
1963
|
-
async
|
|
1964
|
-
this.
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
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.
|
|
1968
|
+
*/
|
|
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
|
-
await this.innerSetup();
|
|
1980
1986
|
}
|
|
1981
1987
|
/**
|
|
1982
|
-
*
|
|
1983
|
-
*/
|
|
1984
|
-
resolvedConfig = {};
|
|
1985
|
-
/**
|
|
1986
|
-
* 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.
|
|
1987
|
-
*
|
|
1988
|
-
* @remarks
|
|
1989
|
-
* 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.
|
|
1990
1989
|
*
|
|
1991
|
-
* @
|
|
1990
|
+
* @param config - The user configuration values to set.
|
|
1991
|
+
* @returns A promise that resolves when the user configuration values have been set.
|
|
1992
1992
|
*/
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
|
|
2001
|
-
context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
|
|
2002
|
-
context.packageJson = (0, _stryke_helpers_deep_clone.deepClone)(this.packageJson);
|
|
2003
|
-
context.projectJson = this.projectJson ? (0, _stryke_helpers_deep_clone.deepClone)(this.projectJson) : void 0;
|
|
2004
|
-
context.tsconfig ??= (0, _stryke_helpers_deep_clone.deepClone)(this.tsconfig);
|
|
2005
|
-
context.resolver ??= this.resolver;
|
|
2006
|
-
context.fs ??= this.#fs;
|
|
2007
|
-
context.$$internal = this.$$internal;
|
|
2008
|
-
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();
|
|
2009
2000
|
}
|
|
2010
2001
|
/**
|
|
2011
2002
|
* Initialize the context with the provided configuration options
|
|
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);
|
|
2012
|
+
}
|
|
2013
|
+
/**
|
|
2014
|
+
* Resolve the package configurations for the project by loading the `package.json` and `project.json` files, if they exist. This function will look for these files in the project root and parse their contents as JavaScript objects. The parsed contents will be stored in the context for later use by plugins and other parts of the build process.
|
|
2012
2015
|
*
|
|
2013
|
-
*
|
|
2014
|
-
*
|
|
2015
|
-
*
|
|
2016
|
-
* @param
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root, "project.json");
|
|
2023
|
-
if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
|
|
2024
|
-
const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root, "package.json");
|
|
2025
|
-
if ((0, _stryke_fs_exists.existsSync)(packageJsonPath)) {
|
|
2026
|
-
this.packageJson = await (0, _stryke_fs_json.readJsonFile)(packageJsonPath);
|
|
2027
|
-
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);
|
|
2028
|
-
}
|
|
2029
|
-
this.#checksum = await this.generateChecksum((0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root));
|
|
2030
|
-
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 : {};
|
|
2031
|
-
this.resolvedConfig = {
|
|
2032
|
-
cwd: this.options.cwd,
|
|
2033
|
-
root: this.options.root,
|
|
2034
|
-
...this.initialOptions,
|
|
2035
|
-
...initialConfig,
|
|
2036
|
-
...userConfig,
|
|
2037
|
-
inlineConfig: {},
|
|
2038
|
-
pluginConfig: {},
|
|
2039
|
-
initialConfig,
|
|
2040
|
-
userConfig
|
|
2041
|
-
};
|
|
2016
|
+
* @remarks
|
|
2017
|
+
* The `package.json` file is typically used to store metadata about the project, such as its name, version, dependencies, and other information. The `project.json` file is an optional file that can be used to store additional configuration or metadata specific to the project, and is not required for all projects.
|
|
2018
|
+
*
|
|
2019
|
+
* @param cwd - The current working directory to look for the package configurations. Defaults to the `cwd` specified in the context configuration.
|
|
2020
|
+
* @param root - The root directory of the project to look for the package configurations. Defaults to the `root` specified in the context configuration.
|
|
2021
|
+
* @returns A promise that resolves when the package configurations have been loaded and stored in the context.
|
|
2022
|
+
*/
|
|
2023
|
+
async resolvePackageConfigs(cwd = this.config.cwd, root = this.config.root) {
|
|
2024
|
+
return super.resolvePackageConfigs(cwd, root);
|
|
2042
2025
|
}
|
|
2043
2026
|
/**
|
|
2044
2027
|
* Initialize the context with the provided configuration options
|
|
2045
2028
|
*/
|
|
2046
|
-
async
|
|
2047
|
-
const
|
|
2048
|
-
this.
|
|
2049
|
-
|
|
2029
|
+
async resolveConfig() {
|
|
2030
|
+
const mergedConfig = this.mergeConfig();
|
|
2031
|
+
this.logger.trace({
|
|
2032
|
+
meta: { category: "config" },
|
|
2033
|
+
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)}`
|
|
2034
|
+
});
|
|
2035
|
+
mergedConfig.output = (0, defu.default)(mergedConfig.output ?? {}, {
|
|
2050
2036
|
copy: { assets: [
|
|
2051
2037
|
{ glob: "LICENSE" },
|
|
2052
2038
|
{
|
|
2053
|
-
input:
|
|
2039
|
+
input: mergedConfig.root,
|
|
2054
2040
|
glob: "*.md"
|
|
2055
2041
|
},
|
|
2056
2042
|
{
|
|
2057
|
-
input:
|
|
2043
|
+
input: mergedConfig.root,
|
|
2058
2044
|
glob: "package.json"
|
|
2059
2045
|
}
|
|
2060
2046
|
] },
|
|
2061
2047
|
dts: true
|
|
2062
2048
|
});
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
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) => {
|
|
2049
|
+
if (!mergedConfig.mode) mergedConfig.mode = "production";
|
|
2050
|
+
if (!mergedConfig.framework) mergedConfig.framework = "powerlines";
|
|
2051
|
+
if (!mergedConfig.projectType) mergedConfig.projectType = "application";
|
|
2052
|
+
if (!mergedConfig.platform) mergedConfig.platform = "neutral";
|
|
2053
|
+
mergedConfig.compatibilityDate = (0, compatx.resolveCompatibilityDates)(mergedConfig.compatibilityDate, "latest");
|
|
2054
|
+
this.resolvedConfig = mergedConfig;
|
|
2055
|
+
this.#configProxy = this.createConfigProxy();
|
|
2056
|
+
if (!this.packageJson) await this.resolvePackageConfigs();
|
|
2057
|
+
mergedConfig.input = (0, _powerlines_core_lib_entry.getUniqueInputs)(mergedConfig.input);
|
|
2058
|
+
if (mergedConfig.name?.startsWith("@") && mergedConfig.name.split("/").filter(Boolean).length > 1) mergedConfig.name = mergedConfig.name.split("/").filter(Boolean)[1];
|
|
2059
|
+
mergedConfig.title ??= (0, _stryke_string_format_title_case.titleCase)(mergedConfig.name);
|
|
2060
|
+
if (mergedConfig.resolve.external) mergedConfig.resolve.external = (0, _stryke_helpers_get_unique.getUnique)(mergedConfig.resolve.external);
|
|
2061
|
+
if (mergedConfig.resolve.noExternal) mergedConfig.resolve.noExternal = (0, _stryke_helpers_get_unique.getUnique)(mergedConfig.resolve.noExternal);
|
|
2062
|
+
mergedConfig.plugins = (mergedConfig.plugins ?? []).flatMap((plugin) => (0, _stryke_convert_to_array.toArray)(plugin)).filter(Boolean).reduce((ret, plugin) => {
|
|
2093
2063
|
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
2064
|
ret.push(plugin);
|
|
2095
2065
|
return ret;
|
|
2096
2066
|
}, []);
|
|
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) => {
|
|
2067
|
+
if (!mergedConfig.logLevel) if (mergedConfig.mode === "development") mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_DEVELOPMENT_LOG_LEVEL;
|
|
2068
|
+
else if (mergedConfig.mode === "test") mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_TEST_LOG_LEVEL;
|
|
2069
|
+
else mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_PRODUCTION_LOG_LEVEL;
|
|
2070
|
+
if (mergedConfig.tsconfig) mergedConfig.tsconfig = (0, _stryke_path_replace.replacePath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.tsconfig), mergedConfig.cwd);
|
|
2071
|
+
else mergedConfig.tsconfig = require_tsconfig.getTsconfigFilePath(mergedConfig.cwd, mergedConfig.root);
|
|
2072
|
+
mergedConfig.output.format = (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(mergedConfig.output?.format ?? (mergedConfig.projectType === "library" ? ["cjs", "esm"] : ["esm"])));
|
|
2073
|
+
if (mergedConfig.output.path) mergedConfig.output.path = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.path), mergedConfig.cwd);
|
|
2074
|
+
else mergedConfig.output.path = (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(mergedConfig.root, "dist"), mergedConfig.cwd);
|
|
2075
|
+
mergedConfig.output.copy ??= {};
|
|
2076
|
+
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;
|
|
2077
|
+
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);
|
|
2078
|
+
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);
|
|
2079
|
+
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
2080
|
return {
|
|
2113
2081
|
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,
|
|
2082
|
+
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),
|
|
2083
|
+
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
2084
|
ignore: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) && asset.ignore ? (0, _stryke_convert_to_array.toArray)(asset.ignore) : void 0
|
|
2117
2085
|
};
|
|
2118
2086
|
}), (a) => `${a.input}-${a.glob}-${a.output}`);
|
|
2119
|
-
if (!
|
|
2120
|
-
else
|
|
2121
|
-
if (!
|
|
2122
|
-
else
|
|
2123
|
-
if (!
|
|
2124
|
-
if (
|
|
2087
|
+
if (!mergedConfig.output?.sourceMap) if (mergedConfig.mode === "development") mergedConfig.output.sourceMap = true;
|
|
2088
|
+
else mergedConfig.output.sourceMap = false;
|
|
2089
|
+
if (!mergedConfig.output.minify) if (mergedConfig.mode === "production") mergedConfig.output.minify = true;
|
|
2090
|
+
else mergedConfig.output.minify = false;
|
|
2091
|
+
if (!mergedConfig.output.artifactsPath) mergedConfig.output.artifactsPath = `.${mergedConfig.framework || "powerlines"}`;
|
|
2092
|
+
if (mergedConfig.output.copy && mergedConfig.output.copy.assets) mergedConfig.output.copy.assets = mergedConfig.output.copy.assets.map((asset) => ({
|
|
2125
2093
|
...asset,
|
|
2126
2094
|
glob: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.glob),
|
|
2127
2095
|
ignore: asset.ignore ? asset.ignore.map((ignore) => (0, _powerlines_core_plugin_utils.replacePathTokens)(this, ignore)) : void 0,
|
|
2128
2096
|
input: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.input),
|
|
2129
2097
|
output: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.output)
|
|
2130
2098
|
}));
|
|
2131
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(
|
|
2099
|
+
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;
|
|
2100
|
+
this.resolvedConfig = mergedConfig;
|
|
2101
|
+
this.#configProxy = this.createConfigProxy();
|
|
2102
|
+
this.logger.debug({
|
|
2103
|
+
meta: { category: "config" },
|
|
2104
|
+
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)}`
|
|
2105
|
+
});
|
|
2132
2106
|
this.#fs ??= await VirtualFileSystem.create(this);
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2107
|
+
}
|
|
2108
|
+
logConfig(config) {
|
|
2109
|
+
return (0, _storm_software_config_tools_logger_console.formatLogMessage)({
|
|
2110
|
+
...(0, _stryke_helpers_omit.omit)(config, ["plugins"]),
|
|
2111
|
+
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
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
createConfigProxy() {
|
|
2115
|
+
return new Proxy(this.resolvedConfig, {
|
|
2116
|
+
/**
|
|
2117
|
+
* A trap for the `delete` operator.
|
|
2118
|
+
* @param target - The original object which is being proxied.
|
|
2119
|
+
* @param key - The name or `Symbol` of the property to delete.
|
|
2120
|
+
* @returns A `boolean` indicating whether or not the property was deleted.
|
|
2121
|
+
*/
|
|
2122
|
+
deleteProperty: (target, key) => {
|
|
2123
|
+
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.`);
|
|
2124
|
+
Reflect.deleteProperty(this.overriddenConfig, key);
|
|
2125
|
+
return Reflect.deleteProperty(target, key);
|
|
2126
|
+
},
|
|
2127
|
+
/**
|
|
2128
|
+
* A trap for getting a property value.
|
|
2129
|
+
* @param target - The original object which is being proxied.
|
|
2130
|
+
* @param key - The name or `Symbol` of the property to get.
|
|
2131
|
+
* @param receiver - The proxy or an object that inherits from the proxy.
|
|
2132
|
+
*/
|
|
2133
|
+
get: (target, key, receiver) => {
|
|
2134
|
+
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) {
|
|
2135
|
+
if (key === "initialConfig") return this.initialConfig;
|
|
2136
|
+
if (key === "userConfig") return this.userConfig;
|
|
2137
|
+
if (key === "inlineConfig") return this.inlineConfig;
|
|
2138
|
+
if (key === "pluginConfig") return this.pluginConfig;
|
|
2139
|
+
}
|
|
2140
|
+
return Reflect.get(target, key, receiver);
|
|
2141
|
+
},
|
|
2142
|
+
/**
|
|
2143
|
+
* A trap for the `in` operator.
|
|
2144
|
+
* @param target - The original object which is being proxied.
|
|
2145
|
+
* @param key - The name or `Symbol` of the property to check for existence.
|
|
2146
|
+
*/
|
|
2147
|
+
has: (target, key) => {
|
|
2148
|
+
return Reflect.has(target, key) || UNRESOLVED_CONFIG_NAMES.includes(key.toString());
|
|
2149
|
+
},
|
|
2150
|
+
/**
|
|
2151
|
+
* A trap for `Reflect.ownKeys()`.
|
|
2152
|
+
* @param target - The original object which is being proxied.
|
|
2153
|
+
*/
|
|
2154
|
+
ownKeys: (target) => {
|
|
2155
|
+
return (0, _stryke_helpers_get_unique.getUnique)([...Reflect.ownKeys(target), ...UNRESOLVED_CONFIG_NAMES]);
|
|
2156
|
+
},
|
|
2157
|
+
/**
|
|
2158
|
+
* A trap for setting a property value.
|
|
2159
|
+
* @param target - The original object which is being proxied.
|
|
2160
|
+
* @param key - The name or `Symbol` of the property to set.
|
|
2161
|
+
* @param newValue - The new value to assign to the property.
|
|
2162
|
+
* @param receiver - The object to which the assignment was originally directed.
|
|
2163
|
+
* @returns A `boolean` indicating whether or not the property was set.
|
|
2164
|
+
*/
|
|
2165
|
+
set: (target, key, newValue, receiver) => {
|
|
2166
|
+
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.`);
|
|
2167
|
+
Reflect.set(this.overriddenConfig, key, newValue, receiver);
|
|
2168
|
+
return Reflect.set(target, key, newValue, receiver);
|
|
2169
|
+
}
|
|
2170
|
+
});
|
|
2146
2171
|
}
|
|
2147
2172
|
};
|
|
2148
2173
|
|
|
@@ -2287,7 +2312,7 @@ function createPluginContext(pluginId, plugin, environment) {
|
|
|
2287
2312
|
return {
|
|
2288
2313
|
meta: {
|
|
2289
2314
|
...(0, _stryke_type_checks_is_set_object.isSetObject)(message) ? message.meta : {},
|
|
2290
|
-
environment: environment.environment
|
|
2315
|
+
environment: environment.config.environment.name,
|
|
2291
2316
|
plugin: plugin.name
|
|
2292
2317
|
},
|
|
2293
2318
|
message: (0, _stryke_type_checks_is_string.isString)(message) ? message : message.message
|
|
@@ -2310,6 +2335,8 @@ function createPluginContext(pluginId, plugin, environment) {
|
|
|
2310
2335
|
callHook: callHookFn,
|
|
2311
2336
|
meta
|
|
2312
2337
|
};
|
|
2338
|
+
if (prop === "api") return environment.$$internal.api;
|
|
2339
|
+
if (prop === "environment") return environment;
|
|
2313
2340
|
if (prop === "id") return pluginId;
|
|
2314
2341
|
if (prop === "logger") return logger;
|
|
2315
2342
|
if (prop === "log") return (type, message) => {
|
|
@@ -2362,6 +2389,15 @@ function createPluginContext(pluginId, plugin, environment) {
|
|
|
2362
2389
|
//#endregion
|
|
2363
2390
|
//#region src/context/environment-context.ts
|
|
2364
2391
|
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
2392
|
+
/**
|
|
2393
|
+
* Internal references storage
|
|
2394
|
+
*
|
|
2395
|
+
* @danger
|
|
2396
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2397
|
+
*
|
|
2398
|
+
* @internal
|
|
2399
|
+
*/
|
|
2400
|
+
#internal = {};
|
|
2365
2401
|
/**
|
|
2366
2402
|
* The hooks registered by plugins in this environment
|
|
2367
2403
|
*/
|
|
@@ -2371,29 +2407,50 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2371
2407
|
*
|
|
2372
2408
|
* @param options - The resolved execution options.
|
|
2373
2409
|
* @param config - The user configuration options.
|
|
2374
|
-
* @
|
|
2410
|
+
* @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.
|
|
2411
|
+
* @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.
|
|
2412
|
+
* @returns A promise that resolves to an instance of the PowerlinesEnvironmentContext class, initialized with the provided configuration and environment data.
|
|
2375
2413
|
*/
|
|
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;
|
|
2414
|
+
static async createEnvironment(options, config, overriddenConfig, environment) {
|
|
2415
|
+
const context = new PowerlinesEnvironmentContext(options, config, overriddenConfig);
|
|
2416
|
+
await context.setEnvironmentConfig(environment);
|
|
2382
2417
|
return context;
|
|
2383
2418
|
}
|
|
2384
2419
|
/**
|
|
2385
|
-
* The
|
|
2420
|
+
* The configuration options provided by plugins added by the user (and other plugins)
|
|
2386
2421
|
*/
|
|
2387
|
-
|
|
2422
|
+
environmentConfig = {};
|
|
2388
2423
|
/**
|
|
2389
2424
|
* The list of plugins applied to this environment
|
|
2390
2425
|
*/
|
|
2391
2426
|
plugins = [];
|
|
2392
2427
|
/**
|
|
2428
|
+
* Internal context fields and methods
|
|
2429
|
+
*
|
|
2430
|
+
* @danger
|
|
2431
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2432
|
+
*
|
|
2433
|
+
* @internal
|
|
2434
|
+
*/
|
|
2435
|
+
get $$internal() {
|
|
2436
|
+
return this.#internal;
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Internal context fields and methods
|
|
2440
|
+
*
|
|
2441
|
+
* @danger
|
|
2442
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2443
|
+
*
|
|
2444
|
+
* @internal
|
|
2445
|
+
*/
|
|
2446
|
+
set $$internal(value) {
|
|
2447
|
+
this.#internal = value;
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2393
2450
|
* 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
2451
|
*/
|
|
2395
2452
|
get id() {
|
|
2396
|
-
return this.environment.
|
|
2453
|
+
return this.config.environment.id;
|
|
2397
2454
|
}
|
|
2398
2455
|
/**
|
|
2399
2456
|
* The hooks registered by plugins in this environment
|
|
@@ -2402,6 +2459,20 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2402
2459
|
return this.#hooks;
|
|
2403
2460
|
}
|
|
2404
2461
|
/**
|
|
2462
|
+
* 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.
|
|
2463
|
+
*
|
|
2464
|
+
* @param config - The environment configuration values to set.
|
|
2465
|
+
* @returns A promise that resolves when the environment configuration values have been set.
|
|
2466
|
+
*/
|
|
2467
|
+
async setEnvironmentConfig(config) {
|
|
2468
|
+
this.logger.debug({
|
|
2469
|
+
meta: { category: "config" },
|
|
2470
|
+
message: `Updating environment configuration object: \n${this.logConfig(config)}`
|
|
2471
|
+
});
|
|
2472
|
+
this.environmentConfig = config;
|
|
2473
|
+
await this.resolveConfig();
|
|
2474
|
+
}
|
|
2475
|
+
/**
|
|
2405
2476
|
* Create a new logger instance
|
|
2406
2477
|
*
|
|
2407
2478
|
* @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 +2482,7 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2411
2482
|
createLogger(options, logFn) {
|
|
2412
2483
|
return super.createLogger({
|
|
2413
2484
|
...options,
|
|
2414
|
-
environment: this.environment?.name
|
|
2485
|
+
environment: this.config.environment?.name
|
|
2415
2486
|
}, logFn);
|
|
2416
2487
|
}
|
|
2417
2488
|
/**
|
|
@@ -2423,47 +2494,21 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2423
2494
|
extendLogger(options) {
|
|
2424
2495
|
return super.extendLogger({
|
|
2425
2496
|
...options,
|
|
2426
|
-
environment: this.environment?.name
|
|
2497
|
+
environment: this.config.environment?.name
|
|
2427
2498
|
});
|
|
2428
2499
|
}
|
|
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
2500
|
async addPlugin(plugin) {
|
|
2456
2501
|
let resolvedPlugin = plugin;
|
|
2457
2502
|
if ((0, _stryke_type_checks_is_function.isFunction)(plugin.applyToEnvironment)) {
|
|
2458
|
-
const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
|
|
2503
|
+
const result = await Promise.resolve(plugin.applyToEnvironment(this.config.environment));
|
|
2459
2504
|
if (!result || (0, _stryke_type_checks_is_object.isObject)(result) && Object.keys(result).length === 0) return;
|
|
2460
2505
|
if ((0, _powerlines_core_plugin_utils.isPluginConfig)(result)) return this.$$internal.addPlugin(result);
|
|
2461
2506
|
resolvedPlugin = (0, _powerlines_core_plugin_utils.isPlugin)(result) ? result : plugin;
|
|
2462
2507
|
}
|
|
2463
|
-
const
|
|
2464
|
-
const context = createPluginContext(
|
|
2508
|
+
const id = (0, _stryke_unique_id_uuid.uuid)();
|
|
2509
|
+
const context = createPluginContext(id, resolvedPlugin, this);
|
|
2465
2510
|
this.plugins.push({
|
|
2466
|
-
|
|
2511
|
+
id,
|
|
2467
2512
|
plugin: resolvedPlugin,
|
|
2468
2513
|
context
|
|
2469
2514
|
});
|
|
@@ -2506,29 +2551,51 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
2506
2551
|
}
|
|
2507
2552
|
return result;
|
|
2508
2553
|
}
|
|
2509
|
-
constructor(options, config,
|
|
2510
|
-
super(options);
|
|
2511
|
-
this.
|
|
2512
|
-
this.
|
|
2554
|
+
constructor(options, config, overriddenConfig) {
|
|
2555
|
+
super(options, config.initialConfig);
|
|
2556
|
+
this.userConfig = config.userConfig ?? {};
|
|
2557
|
+
this.inlineConfig = config.inlineConfig ?? {};
|
|
2558
|
+
this.pluginConfig = config.pluginConfig ?? {};
|
|
2559
|
+
this.overriddenConfig = overriddenConfig;
|
|
2513
2560
|
}
|
|
2514
2561
|
/**
|
|
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.
|
|
2562
|
+
* 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
2563
|
*
|
|
2520
|
-
* @returns The
|
|
2564
|
+
* @returns The merged configuration object that combines the initial, user, inline, and plugin configurations.
|
|
2521
2565
|
*/
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2566
|
+
mergeConfig() {
|
|
2567
|
+
return (0, _powerlines_core_plugin_utils.mergeConfig)({
|
|
2568
|
+
...(0, _stryke_helpers_omit.omit)(this.environmentConfig ?? {}, [
|
|
2569
|
+
"ssr",
|
|
2570
|
+
"preview",
|
|
2571
|
+
"consumer",
|
|
2572
|
+
"runtime"
|
|
2573
|
+
]),
|
|
2574
|
+
environment: { name: this.environmentConfig?.name || _powerlines_core_constants.DEFAULT_ENVIRONMENT },
|
|
2575
|
+
environmentConfig: this.environmentConfig ?? {}
|
|
2576
|
+
}, super.mergeConfig());
|
|
2525
2577
|
}
|
|
2526
2578
|
};
|
|
2527
2579
|
|
|
2528
2580
|
//#endregion
|
|
2529
2581
|
//#region src/context/execution-context.ts
|
|
2530
2582
|
var PowerlinesExecutionContext = class PowerlinesExecutionContext extends PowerlinesContext {
|
|
2583
|
+
/**
|
|
2584
|
+
* Internal references storage
|
|
2585
|
+
*
|
|
2586
|
+
* @danger
|
|
2587
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2588
|
+
*
|
|
2589
|
+
* @internal
|
|
2590
|
+
*/
|
|
2591
|
+
#internal = {};
|
|
2592
|
+
/**
|
|
2593
|
+
* A record of all environments by name
|
|
2594
|
+
*/
|
|
2531
2595
|
#environments = {};
|
|
2596
|
+
/**
|
|
2597
|
+
* 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.
|
|
2598
|
+
*/
|
|
2532
2599
|
#plugins = [];
|
|
2533
2600
|
/**
|
|
2534
2601
|
* Create a new Storm context from the workspace root and user config.
|
|
@@ -2536,13 +2603,9 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2536
2603
|
* @param options - The options for resolving the context.
|
|
2537
2604
|
* @returns A promise that resolves to the new context.
|
|
2538
2605
|
*/
|
|
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;
|
|
2545
|
-
await context.setup();
|
|
2606
|
+
static async fromInitialConfig(options, initialConfig) {
|
|
2607
|
+
const context = new PowerlinesExecutionContext(options, initialConfig);
|
|
2608
|
+
await context.init();
|
|
2546
2609
|
return context;
|
|
2547
2610
|
}
|
|
2548
2611
|
/**
|
|
@@ -2551,19 +2614,10 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2551
2614
|
* @param options - The options for resolving the context.
|
|
2552
2615
|
* @returns A promise that resolves to the new context.
|
|
2553
2616
|
*/
|
|
2554
|
-
static async
|
|
2555
|
-
const context = new PowerlinesExecutionContext(options);
|
|
2556
|
-
await context.init(
|
|
2557
|
-
context.
|
|
2558
|
-
if (context.config.inlineConfig.command === "new") {
|
|
2559
|
-
const workspacePackageJsonPath = (0, _stryke_path_join.joinPaths)(context.config.cwd, "package.json");
|
|
2560
|
-
if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
2561
|
-
context.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
|
|
2562
|
-
}
|
|
2563
|
-
await context.setup();
|
|
2564
|
-
const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
|
|
2565
|
-
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
2566
|
-
context.powerlinesPath = powerlinesPath;
|
|
2617
|
+
static async fromInlineConfig(options, initialConfig, inlineConfig) {
|
|
2618
|
+
const context = new PowerlinesExecutionContext(options, initialConfig);
|
|
2619
|
+
await context.init();
|
|
2620
|
+
await context.setInlineConfig(inlineConfig);
|
|
2567
2621
|
return context;
|
|
2568
2622
|
}
|
|
2569
2623
|
/**
|
|
@@ -2575,7 +2629,7 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2575
2629
|
* @internal
|
|
2576
2630
|
*/
|
|
2577
2631
|
get $$internal() {
|
|
2578
|
-
return
|
|
2632
|
+
return this.#internal;
|
|
2579
2633
|
}
|
|
2580
2634
|
/**
|
|
2581
2635
|
* Internal context fields and methods
|
|
@@ -2586,8 +2640,8 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2586
2640
|
* @internal
|
|
2587
2641
|
*/
|
|
2588
2642
|
set $$internal(value) {
|
|
2589
|
-
|
|
2590
|
-
for (const environment of Object.values(this.environments)) environment.$$internal =
|
|
2643
|
+
this.#internal = value;
|
|
2644
|
+
for (const environment of Object.values(this.environments)) environment.$$internal = value;
|
|
2591
2645
|
}
|
|
2592
2646
|
/**
|
|
2593
2647
|
* 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.
|
|
@@ -2608,9 +2662,26 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2608
2662
|
* Creates a new instance.
|
|
2609
2663
|
*
|
|
2610
2664
|
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
2665
|
+
* @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.
|
|
2611
2666
|
*/
|
|
2612
|
-
constructor(options) {
|
|
2613
|
-
super(options);
|
|
2667
|
+
constructor(options, initialConfig = {}) {
|
|
2668
|
+
super(options, initialConfig);
|
|
2669
|
+
this.initialOptions = options;
|
|
2670
|
+
this.initialConfig = initialConfig;
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2673
|
+
* 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.
|
|
2674
|
+
*
|
|
2675
|
+
* @param config - The inline configuration values to set.
|
|
2676
|
+
* @returns A promise that resolves when the inline configuration values have been set.
|
|
2677
|
+
*/
|
|
2678
|
+
async setInlineConfig(config) {
|
|
2679
|
+
await super.setInlineConfig(config);
|
|
2680
|
+
if (this.inlineConfig.command === "new") {
|
|
2681
|
+
const workspacePackageJsonPath = (0, _stryke_path_join.joinPaths)(this.config.cwd, "package.json");
|
|
2682
|
+
if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
2683
|
+
this.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
|
|
2684
|
+
}
|
|
2614
2685
|
}
|
|
2615
2686
|
/**
|
|
2616
2687
|
* Create a new logger instance
|
|
@@ -2640,42 +2711,45 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2640
2711
|
});
|
|
2641
2712
|
}
|
|
2642
2713
|
/**
|
|
2643
|
-
* 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.
|
|
2644
|
-
*
|
|
2645
|
-
* @remarks
|
|
2646
|
-
* 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.
|
|
2647
|
-
*
|
|
2648
|
-
* @returns A promise that resolves to the cloned context.
|
|
2649
|
-
*/
|
|
2650
|
-
async clone() {
|
|
2651
|
-
const clone = await PowerlinesExecutionContext.init(this.options, this.initialConfig);
|
|
2652
|
-
clone.config.userConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.userConfig);
|
|
2653
|
-
clone.config.initialConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.initialConfig);
|
|
2654
|
-
clone.config.inlineConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.inlineConfig);
|
|
2655
|
-
clone.config.pluginConfig = (0, _stryke_helpers_deep_clone.deepClone)(this.config.pluginConfig);
|
|
2656
|
-
await clone.setup();
|
|
2657
|
-
clone.$$internal = this.$$internal;
|
|
2658
|
-
return this.copyTo(clone);
|
|
2659
|
-
}
|
|
2660
|
-
/**
|
|
2661
2714
|
* A function to copy the context and update the fields for a specific environment
|
|
2662
2715
|
*
|
|
2663
2716
|
* @param environment - The environment configuration to use.
|
|
2664
2717
|
* @returns A new context instance with the updated environment.
|
|
2665
2718
|
*/
|
|
2666
|
-
async
|
|
2667
|
-
const context =
|
|
2719
|
+
async createEnvironment(environment) {
|
|
2720
|
+
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));
|
|
2721
|
+
context.$$internal = this.$$internal;
|
|
2722
|
+
context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
|
|
2723
|
+
context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
|
|
2724
|
+
context.persistedMeta = (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta);
|
|
2725
|
+
context.resolvePatterns = (0, _stryke_helpers_deep_clone.deepClone)(this.resolvePatterns);
|
|
2726
|
+
context.powerlinesPath ??= this.powerlinesPath;
|
|
2727
|
+
context.resolver ??= this.resolver;
|
|
2668
2728
|
context.plugins = [];
|
|
2669
2729
|
for (const plugin of this.plugins) await context.addPlugin(plugin);
|
|
2730
|
+
for (const [key, value] of Object.entries(this)) if (![
|
|
2731
|
+
"fs",
|
|
2732
|
+
"$$internal",
|
|
2733
|
+
"dependencies",
|
|
2734
|
+
"devDependencies",
|
|
2735
|
+
"persistedMeta",
|
|
2736
|
+
"packageJson",
|
|
2737
|
+
"projectJson",
|
|
2738
|
+
"tsconfig",
|
|
2739
|
+
"resolver",
|
|
2740
|
+
"plugins",
|
|
2741
|
+
"environments"
|
|
2742
|
+
].includes(key)) if ((0, _stryke_type_checks_is_object.isObject)(value) || Array.isArray(value)) context[key] = (0, _stryke_helpers_deep_clone.deepClone)(value);
|
|
2743
|
+
else context[key] = value;
|
|
2670
2744
|
return context;
|
|
2671
2745
|
}
|
|
2672
2746
|
/**
|
|
2673
2747
|
* Update the context using a new inline configuration options
|
|
2674
2748
|
*/
|
|
2675
|
-
async
|
|
2676
|
-
await super.
|
|
2749
|
+
async resolveConfig() {
|
|
2750
|
+
await super.resolveConfig();
|
|
2677
2751
|
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) => {
|
|
2678
|
-
this.#environments[env.name] = await this.
|
|
2752
|
+
this.#environments[env.name] = await this.createEnvironment(env);
|
|
2679
2753
|
}));
|
|
2680
2754
|
}
|
|
2681
2755
|
/**
|
|
@@ -2700,12 +2774,20 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2700
2774
|
if (name) environment = this.environments[name];
|
|
2701
2775
|
if (Object.keys(this.environments).length === 1) {
|
|
2702
2776
|
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2703
|
-
this.
|
|
2777
|
+
this.trace({
|
|
2778
|
+
meta: { category: "plugins" },
|
|
2779
|
+
message: `Applying the only configured environment: ${chalk.default.bold.cyanBright(environment?.config.environment?.name)}`
|
|
2780
|
+
});
|
|
2704
2781
|
}
|
|
2705
2782
|
if (!environment) {
|
|
2706
2783
|
if (name) throw new Error(`Environment "${name}" not found.`);
|
|
2707
|
-
environment = await this.
|
|
2708
|
-
|
|
2784
|
+
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)));
|
|
2785
|
+
environment.plugins = [];
|
|
2786
|
+
for (const plugin of this.plugins) await environment.addPlugin(plugin);
|
|
2787
|
+
this.warn({
|
|
2788
|
+
meta: { category: "plugins" },
|
|
2789
|
+
message: `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment.config.environment?.name)}`
|
|
2790
|
+
});
|
|
2709
2791
|
}
|
|
2710
2792
|
return environment;
|
|
2711
2793
|
}
|
|
@@ -2733,8 +2815,11 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
|
|
|
2733
2815
|
async toEnvironment() {
|
|
2734
2816
|
let environment;
|
|
2735
2817
|
if (Object.keys(this.environments).length > 1) {
|
|
2736
|
-
environment = await this.
|
|
2737
|
-
this.debug(
|
|
2818
|
+
environment = await this.createEnvironment(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config));
|
|
2819
|
+
this.debug({
|
|
2820
|
+
meta: { category: "plugins" },
|
|
2821
|
+
message: `Combined all ${Object.keys(this.environments).length} environments into a single global context.`
|
|
2822
|
+
});
|
|
2738
2823
|
} else environment = await this.getEnvironment();
|
|
2739
2824
|
return environment;
|
|
2740
2825
|
}
|