@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
|
@@ -11,8 +11,8 @@ let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
|
|
|
11
11
|
let _stryke_fs = require("@stryke/fs");
|
|
12
12
|
let _stryke_path = require("@stryke/path");
|
|
13
13
|
let _stryke_path_append = require("@stryke/path/append");
|
|
14
|
-
let _stryke_path_is_equal = require("@stryke/path/is-equal");
|
|
15
14
|
let _stryke_path_replace = require("@stryke/path/replace");
|
|
15
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
16
16
|
let chalk = require("chalk");
|
|
17
17
|
chalk = require_chunk.__toESM(chalk, 1);
|
|
18
18
|
let date_fns_formatDistanceToNowStrict = require("date-fns/formatDistanceToNowStrict");
|
|
@@ -50,7 +50,7 @@ function createResolver(options) {
|
|
|
50
50
|
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region src/context/base-context.ts
|
|
53
|
-
var PowerlinesBaseContext = class
|
|
53
|
+
var PowerlinesBaseContext = class {
|
|
54
54
|
#timestamp = Date.now();
|
|
55
55
|
/**
|
|
56
56
|
* The path to the Powerlines package
|
|
@@ -61,17 +61,17 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
61
61
|
*/
|
|
62
62
|
resolver;
|
|
63
63
|
/**
|
|
64
|
-
* The options provided to the Powerlines process
|
|
64
|
+
* 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.
|
|
65
65
|
*/
|
|
66
66
|
options;
|
|
67
67
|
/**
|
|
68
|
-
* The
|
|
68
|
+
* The parsed `package.json` file for the project
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
packageJson;
|
|
71
71
|
/**
|
|
72
|
-
* The
|
|
72
|
+
* The parsed `project.json` file for the project
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
projectJson = void 0;
|
|
75
75
|
/**
|
|
76
76
|
* The parsed configuration file for the project
|
|
77
77
|
*/
|
|
@@ -102,19 +102,6 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* 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.
|
|
106
|
-
*
|
|
107
|
-
* @remarks
|
|
108
|
-
* 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.
|
|
109
|
-
*
|
|
110
|
-
* @returns A promise that resolves to the cloned context.
|
|
111
|
-
*/
|
|
112
|
-
async clone() {
|
|
113
|
-
const clone = new PowerlinesBaseContext();
|
|
114
|
-
await clone.init(this.options, this.initialConfig);
|
|
115
|
-
return clone;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
105
|
* A logging function for fatal messages
|
|
119
106
|
*
|
|
120
107
|
* @param message - The message to log.
|
|
@@ -194,7 +181,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
194
181
|
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
195
182
|
*/
|
|
196
183
|
createLogger(options, logFn) {
|
|
197
|
-
return (0, _powerlines_core_plugin_utils_logging.createLogger)(this.options.name || this.options.root, {
|
|
184
|
+
return (0, _powerlines_core_plugin_utils_logging.createLogger)(this.options.name || this.options.root || "powerlines", {
|
|
198
185
|
...this.configFile.config,
|
|
199
186
|
...this.options,
|
|
200
187
|
...options
|
|
@@ -210,6 +197,24 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
210
197
|
return (0, _powerlines_core_plugin_utils_logging.extendLogger)(this.logger, options);
|
|
211
198
|
}
|
|
212
199
|
/**
|
|
200
|
+
* 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
|
|
201
|
+
*/
|
|
202
|
+
initialOptions = {};
|
|
203
|
+
/**
|
|
204
|
+
* The initial configuration provided when initializing the context, which may be used during the setup process to ensure that the configuration is properly merged and applied to the context. This is typically the user configuration provided in the Powerlines configuration file, but may also include additional configuration options provided by plugins or other sources.
|
|
205
|
+
*/
|
|
206
|
+
initialConfig = {};
|
|
207
|
+
/**
|
|
208
|
+
* Initialize the context with the provided configuration options and set up the resolver and user configuration file. This method is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup as the original context.
|
|
209
|
+
*
|
|
210
|
+
* @param options - The configuration options to initialize the context with, which can include properties such as the project root, mode, log level, and other settings that affect the behavior of the context and its plugins.
|
|
211
|
+
* @param initialConfig - The initial configuration to initialize the context with, which is typically the user configuration provided in the Powerlines configuration file. This can also include additional configuration options provided by plugins or other sources that should be merged with the user configuration during initialization
|
|
212
|
+
*/
|
|
213
|
+
constructor(options, initialConfig = {}) {
|
|
214
|
+
this.initialOptions = options;
|
|
215
|
+
this.initialConfig = initialConfig;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
213
218
|
* Retrieve the workspace configuration for the current project, if it exists. This function will look for a configuration file in the project root and return its contents as a JavaScript object. If no configuration file is found, it will return undefined.
|
|
214
219
|
*
|
|
215
220
|
* @returns A promise that resolves to the workspace configuration object, or undefined if no configuration file is found.
|
|
@@ -221,64 +226,41 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
221
226
|
} : void 0);
|
|
222
227
|
}
|
|
223
228
|
/**
|
|
224
|
-
* Determine the default mode for the current execution based on the environment and workspace configuration. This function will check the `NODE_ENV` environment variable to determine if the current environment is development, production, or test. If `NODE_ENV` is not set, it will look for a `mode` property in the workspace configuration file. If no mode is specified in the workspace configuration, it will default to "production".
|
|
225
|
-
*
|
|
226
|
-
* @returns A promise that resolves to the default mode for the current execution, which can be "development", "production", or "test".
|
|
227
|
-
*/
|
|
228
|
-
async getDefaultMode() {
|
|
229
|
-
const workspaceConfig = await this.getWorkspaceConfig();
|
|
230
|
-
return _stryke_env_environment_checks.isProduction ? "production" : _stryke_env_environment_checks.isDevelopment ? "development" : _stryke_env_environment_checks.isTest ? "test" : workspaceConfig?.mode || "production";
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Determine the default log level for the current execution based on the environment and workspace configuration. This function will check the `logLevel` property in the workspace configuration file and resolve it to a `LogLevelResolvedConfig` value. If no log level is specified in the workspace configuration, it will default to "info" for development mode and "warn" for production mode.
|
|
234
|
-
*
|
|
235
|
-
* @returns A promise that resolves to the default log level for the current execution, which can be "fatal", "error", "warn", "info", "debug", or "trace".
|
|
236
|
-
*/
|
|
237
|
-
async getDefaultLogLevel() {
|
|
238
|
-
const workspaceConfig = await this.getWorkspaceConfig();
|
|
239
|
-
return (0, _powerlines_core_plugin_utils.resolveLogLevel)(workspaceConfig?.logLevel ? workspaceConfig.logLevel === "success" || workspaceConfig.logLevel === "performance" ? "info" : workspaceConfig.logLevel === "all" ? "debug" : workspaceConfig.logLevel === "fatal" ? "error" : workspaceConfig.logLevel : void 0, this.options?.mode || this.initialOptions?.mode || workspaceConfig?.mode || await this.getDefaultMode());
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
229
|
* Initialize the context with the provided configuration options
|
|
243
230
|
*
|
|
244
231
|
* @remarks
|
|
245
232
|
* This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.
|
|
246
|
-
*
|
|
247
|
-
* @param options - The configuration options to initialize the context with
|
|
248
|
-
* @param initialConfig - The initial configuration to initialize the context with
|
|
249
233
|
*/
|
|
250
|
-
async init(
|
|
251
|
-
this.initialOptions = { ...options };
|
|
252
|
-
this.initialConfig = { ...initialConfig };
|
|
234
|
+
async init() {
|
|
253
235
|
if (!this.powerlinesPath) {
|
|
254
236
|
const powerlinesPath = await (0, _stryke_fs_resolve.resolvePackage)("powerlines");
|
|
255
237
|
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
256
238
|
this.powerlinesPath = powerlinesPath;
|
|
257
239
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
this.options = (0, defu.default)({
|
|
261
|
-
name: options.name || this.initialConfig.name,
|
|
262
|
-
root,
|
|
263
|
-
cwd,
|
|
264
|
-
mode: options.mode || this.initialConfig.mode,
|
|
265
|
-
logLevel: options.logLevel || this.initialConfig.logLevel,
|
|
266
|
-
framework: options.framework || this.initialConfig.framework,
|
|
267
|
-
organization: options.organization || this.initialConfig.organization,
|
|
268
|
-
configFile: options.configFile || this.initialConfig.configFile
|
|
269
|
-
}, this.options ?? {}, {
|
|
240
|
+
this.options = (0, defu.default)(this.initialOptions, this.initialConfig, {
|
|
241
|
+
cwd: process.cwd(),
|
|
270
242
|
mode: await this.getDefaultMode(),
|
|
271
|
-
logLevel: await this.getDefaultLogLevel()
|
|
243
|
+
logLevel: await this.getDefaultLogLevel(),
|
|
244
|
+
framework: "powerlines"
|
|
272
245
|
});
|
|
246
|
+
if (!this.options.root) if (this.options.configFile) {
|
|
247
|
+
const configFile = (0, _stryke_path_append.appendPath)(this.options.configFile, this.options.cwd);
|
|
248
|
+
if (!(0, node_fs.existsSync)(configFile)) throw new Error(`The user-provided configuration file at "${this.options.configFile}" does not exist. Please ensure this path is correct and try again.`);
|
|
249
|
+
if (!(0, _stryke_fs.isFile)(configFile)) throw new Error(`The user-provided configuration file at "${this.options.configFile}" is not a file. Please ensure this path is correct and try again.`);
|
|
250
|
+
this.options.root = (0, _stryke_path.relativePath)(this.options.cwd, (0, _stryke_path.findFilePath)(configFile));
|
|
251
|
+
} else this.options.root = ".";
|
|
252
|
+
else this.options.root = (0, _stryke_path_replace.replacePath)(this.options.root, this.options.cwd);
|
|
273
253
|
this.resolver = createResolver({
|
|
274
|
-
workspaceRoot: cwd,
|
|
275
|
-
root,
|
|
254
|
+
workspaceRoot: this.options.cwd,
|
|
255
|
+
root: this.options.root,
|
|
276
256
|
cacheDir: this.envPaths.cache,
|
|
277
257
|
mode: this.options.mode
|
|
278
258
|
});
|
|
259
|
+
await this.resolvePackageConfigs();
|
|
279
260
|
this.configFile = await (0, _powerlines_core_lib_config.loadUserConfigFile)(this.options, this.resolver);
|
|
280
|
-
if (
|
|
281
|
-
if (this.configFile.
|
|
261
|
+
if (this.configFile.config) {
|
|
262
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(this.configFile.configFile)) this.options.configFile ??= (0, _stryke_path_replace.replacePath)(this.configFile.configFile, this.options.cwd);
|
|
263
|
+
if (!this.options.name) {
|
|
282
264
|
if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.configFile.config) && (0, _stryke_type_checks_is_set_string.isSetString)(this.configFile.config.name)) this.options.name = this.configFile.config.name;
|
|
283
265
|
else if (Array.isArray(this.configFile.config)) {
|
|
284
266
|
for (const config of this.configFile.config) if ((0, _stryke_type_checks_is_set_object.isSetObject)(config) && (0, _stryke_type_checks_is_set_string.isSetString)(config.name)) {
|
|
@@ -287,22 +269,46 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
287
269
|
}
|
|
288
270
|
}
|
|
289
271
|
}
|
|
290
|
-
if (!this.options.name)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
272
|
+
if (!this.options.name) this.options.name = this.projectJson?.name || this.packageJson?.name;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* 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.
|
|
277
|
+
*
|
|
278
|
+
* @remarks
|
|
279
|
+
* 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.
|
|
280
|
+
*
|
|
281
|
+
* @param cwd - The current working directory to look for the package configurations. Defaults to the `cwd` specified in the context configuration.
|
|
282
|
+
* @param root - The root directory of the project to look for the package configurations. Defaults to the `root` specified in the context configuration.
|
|
283
|
+
* @returns A promise that resolves when the package configurations have been loaded and stored in the context.
|
|
284
|
+
*/
|
|
285
|
+
async resolvePackageConfigs(cwd = this.options.cwd, root = this.options.root) {
|
|
286
|
+
const projectJsonPath = (0, _stryke_path.joinPaths)((0, _stryke_path_append.appendPath)(root, cwd), "project.json");
|
|
287
|
+
if ((0, node_fs.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs.readJsonFile)(projectJsonPath);
|
|
288
|
+
const packageJsonPath = (0, _stryke_path.joinPaths)((0, _stryke_path_append.appendPath)(root, cwd), "package.json");
|
|
289
|
+
if ((0, node_fs.existsSync)(packageJsonPath)) {
|
|
290
|
+
this.packageJson = await (0, _stryke_fs.readJsonFile)(packageJsonPath);
|
|
291
|
+
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);
|
|
304
292
|
}
|
|
305
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Determine the default mode for the current execution based on the environment and workspace configuration. This function will check the `NODE_ENV` environment variable to determine if the current environment is development, production, or test. If `NODE_ENV` is not set, it will look for a `mode` property in the workspace configuration file. If no mode is specified in the workspace configuration, it will default to "production".
|
|
296
|
+
*
|
|
297
|
+
* @returns A promise that resolves to the default mode for the current execution, which can be "development", "production", or "test".
|
|
298
|
+
*/
|
|
299
|
+
async getDefaultMode() {
|
|
300
|
+
const workspaceConfig = await this.getWorkspaceConfig();
|
|
301
|
+
return _stryke_env_environment_checks.isProduction ? "production" : _stryke_env_environment_checks.isDevelopment ? "development" : _stryke_env_environment_checks.isTest ? "test" : workspaceConfig?.mode || "production";
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Determine the default log level for the current execution based on the environment and workspace configuration. This function will check the `logLevel` property in the workspace configuration file and resolve it to a `LogLevelResolvedConfig` value. If no log level is specified in the workspace configuration, it will default to "info" for development mode and "warn" for production mode.
|
|
305
|
+
*
|
|
306
|
+
* @returns A promise that resolves to the default log level for the current execution, which can be "fatal", "error", "warn", "info", "debug", or "trace".
|
|
307
|
+
*/
|
|
308
|
+
async getDefaultLogLevel() {
|
|
309
|
+
const workspaceConfig = await this.getWorkspaceConfig();
|
|
310
|
+
return (0, _powerlines_core_plugin_utils.resolveLogLevel)(workspaceConfig?.logLevel ? workspaceConfig.logLevel === "success" || workspaceConfig.logLevel === "performance" ? "info" : workspaceConfig.logLevel === "all" ? "debug" : workspaceConfig.logLevel === "fatal" ? "error" : workspaceConfig.logLevel : void 0, this.options?.mode || this.initialOptions?.mode || workspaceConfig?.mode || await this.getDefaultMode());
|
|
311
|
+
}
|
|
306
312
|
};
|
|
307
313
|
|
|
308
314
|
//#endregion
|
|
@@ -7,11 +7,11 @@ import { createLogger as createLogger$1, extendLogger } from "@powerlines/core/p
|
|
|
7
7
|
import { tryGetWorkspaceConfig } from "@storm-software/config-tools/get-config";
|
|
8
8
|
import { isDevelopment, isProduction, isTest } from "@stryke/env/environment-checks";
|
|
9
9
|
import { getEnvPaths } from "@stryke/env/get-env-paths";
|
|
10
|
-
import { readJsonFile } from "@stryke/fs";
|
|
11
|
-
import { joinPaths } from "@stryke/path";
|
|
10
|
+
import { isFile, readJsonFile } from "@stryke/fs";
|
|
11
|
+
import { findFilePath, joinPaths, relativePath } from "@stryke/path";
|
|
12
12
|
import { appendPath } from "@stryke/path/append";
|
|
13
|
-
import { isEqual } from "@stryke/path/is-equal";
|
|
14
13
|
import { replacePath } from "@stryke/path/replace";
|
|
14
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
15
15
|
import chalk from "chalk";
|
|
16
16
|
import { formatDistanceToNowStrict } from "date-fns/formatDistanceToNowStrict";
|
|
17
17
|
import defu from "defu";
|
|
@@ -47,7 +47,7 @@ function createResolver(options) {
|
|
|
47
47
|
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/context/base-context.ts
|
|
50
|
-
var PowerlinesBaseContext = class
|
|
50
|
+
var PowerlinesBaseContext = class {
|
|
51
51
|
#timestamp = Date.now();
|
|
52
52
|
/**
|
|
53
53
|
* The path to the Powerlines package
|
|
@@ -58,17 +58,17 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
58
58
|
*/
|
|
59
59
|
resolver;
|
|
60
60
|
/**
|
|
61
|
-
* The options provided to the Powerlines process
|
|
61
|
+
* 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.
|
|
62
62
|
*/
|
|
63
63
|
options;
|
|
64
64
|
/**
|
|
65
|
-
* The
|
|
65
|
+
* The parsed `package.json` file for the project
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
packageJson;
|
|
68
68
|
/**
|
|
69
|
-
* The
|
|
69
|
+
* The parsed `project.json` file for the project
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
projectJson = void 0;
|
|
72
72
|
/**
|
|
73
73
|
* The parsed configuration file for the project
|
|
74
74
|
*/
|
|
@@ -99,19 +99,6 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
* 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.
|
|
103
|
-
*
|
|
104
|
-
* @remarks
|
|
105
|
-
* 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.
|
|
106
|
-
*
|
|
107
|
-
* @returns A promise that resolves to the cloned context.
|
|
108
|
-
*/
|
|
109
|
-
async clone() {
|
|
110
|
-
const clone = new PowerlinesBaseContext();
|
|
111
|
-
await clone.init(this.options, this.initialConfig);
|
|
112
|
-
return clone;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
102
|
* A logging function for fatal messages
|
|
116
103
|
*
|
|
117
104
|
* @param message - The message to log.
|
|
@@ -191,7 +178,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
191
178
|
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
192
179
|
*/
|
|
193
180
|
createLogger(options, logFn) {
|
|
194
|
-
return createLogger$1(this.options.name || this.options.root, {
|
|
181
|
+
return createLogger$1(this.options.name || this.options.root || "powerlines", {
|
|
195
182
|
...this.configFile.config,
|
|
196
183
|
...this.options,
|
|
197
184
|
...options
|
|
@@ -207,6 +194,24 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
207
194
|
return extendLogger(this.logger, options);
|
|
208
195
|
}
|
|
209
196
|
/**
|
|
197
|
+
* 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
|
|
198
|
+
*/
|
|
199
|
+
initialOptions = {};
|
|
200
|
+
/**
|
|
201
|
+
* The initial configuration provided when initializing the context, which may be used during the setup process to ensure that the configuration is properly merged and applied to the context. This is typically the user configuration provided in the Powerlines configuration file, but may also include additional configuration options provided by plugins or other sources.
|
|
202
|
+
*/
|
|
203
|
+
initialConfig = {};
|
|
204
|
+
/**
|
|
205
|
+
* Initialize the context with the provided configuration options and set up the resolver and user configuration file. This method is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup as the original context.
|
|
206
|
+
*
|
|
207
|
+
* @param options - The configuration options to initialize the context with, which can include properties such as the project root, mode, log level, and other settings that affect the behavior of the context and its plugins.
|
|
208
|
+
* @param initialConfig - The initial configuration to initialize the context with, which is typically the user configuration provided in the Powerlines configuration file. This can also include additional configuration options provided by plugins or other sources that should be merged with the user configuration during initialization
|
|
209
|
+
*/
|
|
210
|
+
constructor(options, initialConfig = {}) {
|
|
211
|
+
this.initialOptions = options;
|
|
212
|
+
this.initialConfig = initialConfig;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
210
215
|
* Retrieve the workspace configuration for the current project, if it exists. This function will look for a configuration file in the project root and return its contents as a JavaScript object. If no configuration file is found, it will return undefined.
|
|
211
216
|
*
|
|
212
217
|
* @returns A promise that resolves to the workspace configuration object, or undefined if no configuration file is found.
|
|
@@ -218,64 +223,41 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
218
223
|
} : void 0);
|
|
219
224
|
}
|
|
220
225
|
/**
|
|
221
|
-
* Determine the default mode for the current execution based on the environment and workspace configuration. This function will check the `NODE_ENV` environment variable to determine if the current environment is development, production, or test. If `NODE_ENV` is not set, it will look for a `mode` property in the workspace configuration file. If no mode is specified in the workspace configuration, it will default to "production".
|
|
222
|
-
*
|
|
223
|
-
* @returns A promise that resolves to the default mode for the current execution, which can be "development", "production", or "test".
|
|
224
|
-
*/
|
|
225
|
-
async getDefaultMode() {
|
|
226
|
-
const workspaceConfig = await this.getWorkspaceConfig();
|
|
227
|
-
return isProduction ? "production" : isDevelopment ? "development" : isTest ? "test" : workspaceConfig?.mode || "production";
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Determine the default log level for the current execution based on the environment and workspace configuration. This function will check the `logLevel` property in the workspace configuration file and resolve it to a `LogLevelResolvedConfig` value. If no log level is specified in the workspace configuration, it will default to "info" for development mode and "warn" for production mode.
|
|
231
|
-
*
|
|
232
|
-
* @returns A promise that resolves to the default log level for the current execution, which can be "fatal", "error", "warn", "info", "debug", or "trace".
|
|
233
|
-
*/
|
|
234
|
-
async getDefaultLogLevel() {
|
|
235
|
-
const workspaceConfig = await this.getWorkspaceConfig();
|
|
236
|
-
return resolveLogLevel(workspaceConfig?.logLevel ? workspaceConfig.logLevel === "success" || workspaceConfig.logLevel === "performance" ? "info" : workspaceConfig.logLevel === "all" ? "debug" : workspaceConfig.logLevel === "fatal" ? "error" : workspaceConfig.logLevel : void 0, this.options?.mode || this.initialOptions?.mode || workspaceConfig?.mode || await this.getDefaultMode());
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
226
|
* Initialize the context with the provided configuration options
|
|
240
227
|
*
|
|
241
228
|
* @remarks
|
|
242
229
|
* This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.
|
|
243
|
-
*
|
|
244
|
-
* @param options - The configuration options to initialize the context with
|
|
245
|
-
* @param initialConfig - The initial configuration to initialize the context with
|
|
246
230
|
*/
|
|
247
|
-
async init(
|
|
248
|
-
this.initialOptions = { ...options };
|
|
249
|
-
this.initialConfig = { ...initialConfig };
|
|
231
|
+
async init() {
|
|
250
232
|
if (!this.powerlinesPath) {
|
|
251
233
|
const powerlinesPath = await resolvePackage("powerlines");
|
|
252
234
|
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
253
235
|
this.powerlinesPath = powerlinesPath;
|
|
254
236
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
this.options = defu({
|
|
258
|
-
name: options.name || this.initialConfig.name,
|
|
259
|
-
root,
|
|
260
|
-
cwd,
|
|
261
|
-
mode: options.mode || this.initialConfig.mode,
|
|
262
|
-
logLevel: options.logLevel || this.initialConfig.logLevel,
|
|
263
|
-
framework: options.framework || this.initialConfig.framework,
|
|
264
|
-
organization: options.organization || this.initialConfig.organization,
|
|
265
|
-
configFile: options.configFile || this.initialConfig.configFile
|
|
266
|
-
}, this.options ?? {}, {
|
|
237
|
+
this.options = defu(this.initialOptions, this.initialConfig, {
|
|
238
|
+
cwd: process.cwd(),
|
|
267
239
|
mode: await this.getDefaultMode(),
|
|
268
|
-
logLevel: await this.getDefaultLogLevel()
|
|
240
|
+
logLevel: await this.getDefaultLogLevel(),
|
|
241
|
+
framework: "powerlines"
|
|
269
242
|
});
|
|
243
|
+
if (!this.options.root) if (this.options.configFile) {
|
|
244
|
+
const configFile = appendPath(this.options.configFile, this.options.cwd);
|
|
245
|
+
if (!existsSync(configFile)) throw new Error(`The user-provided configuration file at "${this.options.configFile}" does not exist. Please ensure this path is correct and try again.`);
|
|
246
|
+
if (!isFile(configFile)) throw new Error(`The user-provided configuration file at "${this.options.configFile}" is not a file. Please ensure this path is correct and try again.`);
|
|
247
|
+
this.options.root = relativePath(this.options.cwd, findFilePath(configFile));
|
|
248
|
+
} else this.options.root = ".";
|
|
249
|
+
else this.options.root = replacePath(this.options.root, this.options.cwd);
|
|
270
250
|
this.resolver = createResolver({
|
|
271
|
-
workspaceRoot: cwd,
|
|
272
|
-
root,
|
|
251
|
+
workspaceRoot: this.options.cwd,
|
|
252
|
+
root: this.options.root,
|
|
273
253
|
cacheDir: this.envPaths.cache,
|
|
274
254
|
mode: this.options.mode
|
|
275
255
|
});
|
|
256
|
+
await this.resolvePackageConfigs();
|
|
276
257
|
this.configFile = await loadUserConfigFile(this.options, this.resolver);
|
|
277
|
-
if (
|
|
278
|
-
if (this.configFile.
|
|
258
|
+
if (this.configFile.config) {
|
|
259
|
+
if (isSetString(this.configFile.configFile)) this.options.configFile ??= replacePath(this.configFile.configFile, this.options.cwd);
|
|
260
|
+
if (!this.options.name) {
|
|
279
261
|
if (isSetObject(this.configFile.config) && isSetString(this.configFile.config.name)) this.options.name = this.configFile.config.name;
|
|
280
262
|
else if (Array.isArray(this.configFile.config)) {
|
|
281
263
|
for (const config of this.configFile.config) if (isSetObject(config) && isSetString(config.name)) {
|
|
@@ -284,24 +266,48 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
|
|
|
284
266
|
}
|
|
285
267
|
}
|
|
286
268
|
}
|
|
287
|
-
if (!this.options.name)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
269
|
+
if (!this.options.name) this.options.name = this.projectJson?.name || this.packageJson?.name;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 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.
|
|
274
|
+
*
|
|
275
|
+
* @remarks
|
|
276
|
+
* 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.
|
|
277
|
+
*
|
|
278
|
+
* @param cwd - The current working directory to look for the package configurations. Defaults to the `cwd` specified in the context configuration.
|
|
279
|
+
* @param root - The root directory of the project to look for the package configurations. Defaults to the `root` specified in the context configuration.
|
|
280
|
+
* @returns A promise that resolves when the package configurations have been loaded and stored in the context.
|
|
281
|
+
*/
|
|
282
|
+
async resolvePackageConfigs(cwd = this.options.cwd, root = this.options.root) {
|
|
283
|
+
const projectJsonPath = joinPaths(appendPath(root, cwd), "project.json");
|
|
284
|
+
if (existsSync(projectJsonPath)) this.projectJson = await readJsonFile(projectJsonPath);
|
|
285
|
+
const packageJsonPath = joinPaths(appendPath(root, cwd), "package.json");
|
|
286
|
+
if (existsSync(packageJsonPath)) {
|
|
287
|
+
this.packageJson = await readJsonFile(packageJsonPath);
|
|
288
|
+
this.options.organization ??= isSetObject(this.packageJson?.author) ? kebabCase(this.packageJson?.author?.name) : kebabCase(this.packageJson?.author);
|
|
301
289
|
}
|
|
302
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Determine the default mode for the current execution based on the environment and workspace configuration. This function will check the `NODE_ENV` environment variable to determine if the current environment is development, production, or test. If `NODE_ENV` is not set, it will look for a `mode` property in the workspace configuration file. If no mode is specified in the workspace configuration, it will default to "production".
|
|
293
|
+
*
|
|
294
|
+
* @returns A promise that resolves to the default mode for the current execution, which can be "development", "production", or "test".
|
|
295
|
+
*/
|
|
296
|
+
async getDefaultMode() {
|
|
297
|
+
const workspaceConfig = await this.getWorkspaceConfig();
|
|
298
|
+
return isProduction ? "production" : isDevelopment ? "development" : isTest ? "test" : workspaceConfig?.mode || "production";
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Determine the default log level for the current execution based on the environment and workspace configuration. This function will check the `logLevel` property in the workspace configuration file and resolve it to a `LogLevelResolvedConfig` value. If no log level is specified in the workspace configuration, it will default to "info" for development mode and "warn" for production mode.
|
|
302
|
+
*
|
|
303
|
+
* @returns A promise that resolves to the default log level for the current execution, which can be "fatal", "error", "warn", "info", "debug", or "trace".
|
|
304
|
+
*/
|
|
305
|
+
async getDefaultLogLevel() {
|
|
306
|
+
const workspaceConfig = await this.getWorkspaceConfig();
|
|
307
|
+
return resolveLogLevel(workspaceConfig?.logLevel ? workspaceConfig.logLevel === "success" || workspaceConfig.logLevel === "performance" ? "info" : workspaceConfig.logLevel === "all" ? "debug" : workspaceConfig.logLevel === "fatal" ? "error" : workspaceConfig.logLevel : void 0, this.options?.mode || this.initialOptions?.mode || workspaceConfig?.mode || await this.getDefaultMode());
|
|
308
|
+
}
|
|
303
309
|
};
|
|
304
310
|
|
|
305
311
|
//#endregion
|
|
306
312
|
export { PowerlinesBaseContext as t };
|
|
307
|
-
//# sourceMappingURL=base-context-
|
|
313
|
+
//# sourceMappingURL=base-context-DU0NRHDt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-context-DU0NRHDt.mjs","names":["joinPaths","#timestamp","createLogger"],"sources":["../src/_internal/helpers/resolver.ts","../src/context/base-context.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ResolvedConfig, Resolver } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport defu from \"defu\";\nimport { JitiOptions, createJiti } from \"jiti\";\n\nexport type CreateResolverOptions = Omit<\n JitiOptions,\n \"fsCache\" | \"moduleCache\" | \"interopDefault\"\n> &\n Partial<Pick<ResolvedConfig, \"mode\" | \"skipCache\">> & {\n workspaceRoot: string;\n root: string;\n cacheDir: string;\n };\n\n/**\n * Create a Jiti resolver for the given workspace and project root.\n *\n * @param options - The options for creating the resolver.\n * @returns A Jiti instance configured for the specified workspace and project root.\n */\nfunction resolveOptions(options: CreateResolverOptions): JitiOptions {\n return defu(options, {\n interopDefault: true,\n fsCache:\n options.mode !== \"development\"\n ? joinPaths(options.cacheDir, \"jiti\")\n : false,\n moduleCache: options.mode !== \"development\"\n });\n}\n\n/**\n * Create a Jiti resolver for the given workspace and project root.\n *\n * @param options - The options for creating the resolver.\n * @returns A Jiti instance configured for the specified workspace and project root.\n */\nexport function createResolver(options: CreateResolverOptions): Resolver {\n const baseResolver = createJiti(\n joinPaths(options.workspaceRoot, options.root),\n resolveOptions(options)\n ) as Resolver;\n baseResolver.plugin = createJiti(\n joinPaths(options.workspaceRoot, options.root),\n resolveOptions(options)\n );\n\n return baseResolver;\n}\n","/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n BaseContext,\n EngineOptions,\n LogFn,\n Logger,\n LoggerOptions,\n LogLevelResolvedConfig,\n LogMessage,\n Mode,\n ParsedUserConfig,\n Resolver,\n UserConfig,\n WorkspaceConfig\n} from \"@powerlines/core\";\nimport { loadUserConfigFile } from \"@powerlines/core/lib/config\";\nimport { resolveLogLevel } from \"@powerlines/core/plugin-utils\";\nimport {\n createLogger,\n extendLogger\n} from \"@powerlines/core/plugin-utils/logging\";\nimport { tryGetWorkspaceConfig } from \"@storm-software/config-tools/get-config\";\nimport {\n isDevelopment,\n isProduction,\n isTest\n} from \"@stryke/env/environment-checks\";\nimport { EnvPaths, getEnvPaths } from \"@stryke/env/get-env-paths\";\nimport { isFile, readJsonFile } from \"@stryke/fs\";\nimport { resolvePackage } from \"@stryke/fs/resolve\";\nimport { findFilePath, joinPaths, relativePath } from \"@stryke/path\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { DeepPartial, RequiredKeys } from \"@stryke/types/base\";\nimport { PackageJson } from \"@stryke/types/package-json\";\nimport chalk from \"chalk\";\nimport { formatDistanceToNowStrict } from \"date-fns/formatDistanceToNowStrict\";\nimport defu from \"defu\";\nimport { existsSync } from \"node:fs\";\nimport { createResolver } from \"../_internal/helpers/resolver\";\n\nexport class PowerlinesBaseContext implements BaseContext {\n #timestamp: number = Date.now();\n\n /**\n * The path to the Powerlines package\n */\n public powerlinesPath!: string;\n\n /**\n * The module resolver for the project\n */\n public resolver!: Resolver;\n\n /**\n * 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.\n */\n public options!: RequiredKeys<\n EngineOptions,\n \"mode\" | \"cwd\" | \"root\" | \"framework\"\n >;\n\n /**\n * The parsed `package.json` file for the project\n */\n public packageJson!: PackageJson;\n\n /**\n * The parsed `project.json` file for the project\n */\n public projectJson: Record<string, any> | undefined = undefined;\n\n /**\n * The parsed configuration file for the project\n */\n public configFile!: ParsedUserConfig;\n\n /**\n * The logger instance for the context, which can be used to create log messages with consistent formatting and metadata. This logger is extended by plugin contexts to include additional metadata such as the plugin name and category, which can be used to filter and format log messages in a more granular way.\n */\n public get logger(): Logger {\n return this.createLogger({});\n }\n\n /**\n * A timestamp representing when the context was initialized\n */\n public get timestamp(): number {\n return this.#timestamp;\n }\n\n public get logLevel(): LogLevelResolvedConfig {\n return resolveLogLevel(this.options.logLevel, this.options.mode);\n }\n\n /**\n * The environment paths for the project\n */\n public get envPaths(): EnvPaths {\n return getEnvPaths({\n orgId: this.options.organization,\n appId: this.options.framework || \"powerlines\",\n workspaceRoot: this.options.cwd\n });\n }\n\n /**\n * A logging function for fatal messages\n *\n * @param message - The message to log.\n */\n public fatal(message: string | LogMessage) {\n this.logger.error(message);\n }\n\n /**\n * A logging function for error messages\n *\n * @param message - The message to log.\n */\n public error(message: string | LogMessage) {\n this.logger.error(message);\n }\n\n /**\n * A logging function for warning messages\n *\n * @param message - The message to log.\n */\n public warn(message: string | LogMessage) {\n this.logger.warn(message);\n }\n\n /**\n * A logging function for informational messages\n *\n * @param message - The message to log.\n */\n public info(message: string | LogMessage) {\n this.logger.info(message);\n }\n\n /**\n * A logging function for debug messages\n *\n * @param message - The message to log.\n */\n public debug(message: string | LogMessage) {\n this.logger.debug(message);\n }\n\n /**\n * A logging function for trace messages\n *\n * @param message - The message to log.\n */\n public trace(message: string | LogMessage) {\n this.logger.trace(message);\n }\n\n /**\n * A function to create a timer for measuring the duration of asynchronous operations\n *\n * @example\n * ```ts\n * const stopTimer = context.timer(\"Your Async Operation\");\n * await performAsyncOperation();\n * stopTimer(); // \"Your Async Operation completed in 123.45 milliseconds\"\n * ```\n *\n * @param name - The name of the timer.\n * @returns A function that, when called, stops the timer and logs the duration.\n */\n public timer(name: string): () => void {\n const startDate = Date.now();\n const startDuration = performance.now();\n\n return () => {\n const duration = performance.now() - startDuration;\n this.logger.info({\n meta: {\n category: \"performance\"\n },\n message: `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(\n duration < 1000\n ? `${duration.toFixed(2)} milliseconds`\n : formatDistanceToNowStrict(startDate)\n )}`\n });\n };\n }\n\n /**\n * Create a new logger instance\n *\n * @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.\n * @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.\n * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.\n */\n public createLogger(options: LoggerOptions, logFn?: LogFn): Logger {\n return createLogger(\n this.options.name || this.options.root || \"powerlines\",\n { ...this.configFile.config, ...this.options, ...options },\n logFn\n );\n }\n\n /**\n * Extend the base logger with additional configuration options\n *\n * @param options - The configuration options to extend the base logger with, which can be used to add additional metadata or customize the appearance of log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance, as well as any additional metadata such as the plugin category or environment.\n * @returns A new logger client instance that extends the base logger with the provided configuration options.\n */\n public extendLogger(options: LoggerOptions): Logger {\n return extendLogger(this.logger, options);\n }\n\n /**\n * 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\n */\n protected initialOptions: EngineOptions = {};\n\n /**\n * The initial configuration provided when initializing the context, which may be used during the setup process to ensure that the configuration is properly merged and applied to the context. This is typically the user configuration provided in the Powerlines configuration file, but may also include additional configuration options provided by plugins or other sources.\n */\n protected initialConfig: DeepPartial<UserConfig> = {};\n\n /**\n * Initialize the context with the provided configuration options and set up the resolver and user configuration file. This method is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup as the original context.\n *\n * @param options - The configuration options to initialize the context with, which can include properties such as the project root, mode, log level, and other settings that affect the behavior of the context and its plugins.\n * @param initialConfig - The initial configuration to initialize the context with, which is typically the user configuration provided in the Powerlines configuration file. This can also include additional configuration options provided by plugins or other sources that should be merged with the user configuration during initialization\n */\n protected constructor(\n options: EngineOptions,\n initialConfig: DeepPartial<UserConfig> = {}\n ) {\n this.initialOptions = options;\n this.initialConfig = initialConfig;\n }\n\n /**\n * Retrieve the workspace configuration for the current project, if it exists. This function will look for a configuration file in the project root and return its contents as a JavaScript object. If no configuration file is found, it will return undefined.\n *\n * @returns A promise that resolves to the workspace configuration object, or undefined if no configuration file is found.\n */\n protected async getWorkspaceConfig(): Promise<WorkspaceConfig | undefined> {\n return tryGetWorkspaceConfig(\n false,\n this.options || this.initialOptions\n ? {\n cwd:\n this.options?.root || this.initialOptions?.root\n ? appendPath(\n this.options?.root || this.initialOptions?.root || \".\",\n this.options?.cwd || this.initialOptions?.cwd\n )\n : undefined,\n workspaceRoot: this.options?.cwd || this.initialOptions?.cwd\n }\n : undefined\n );\n }\n\n /**\n * Initialize the context with the provided configuration options\n *\n * @remarks\n * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.\n */\n protected async init() {\n if (!this.powerlinesPath) {\n const powerlinesPath = await resolvePackage(\"powerlines\");\n if (!powerlinesPath) {\n throw new Error(\"Could not resolve `powerlines` package location.\");\n }\n this.powerlinesPath = powerlinesPath;\n }\n\n this.options = defu(this.initialOptions, this.initialConfig, {\n cwd: process.cwd(),\n mode: await this.getDefaultMode(),\n logLevel: await this.getDefaultLogLevel(),\n framework: \"powerlines\"\n }) as RequiredKeys<EngineOptions, \"mode\" | \"cwd\" | \"root\" | \"framework\">;\n\n if (!this.options.root) {\n if (this.options.configFile) {\n const configFile = appendPath(\n this.options.configFile,\n this.options.cwd\n );\n if (!existsSync(configFile)) {\n throw new Error(\n `The user-provided configuration file at \"${\n this.options.configFile\n }\" does not exist. Please ensure this path is correct and try again.`\n );\n }\n if (!isFile(configFile)) {\n throw new Error(\n `The user-provided configuration file at \"${\n this.options.configFile\n }\" is not a file. Please ensure this path is correct and try again.`\n );\n }\n\n this.options.root = relativePath(\n this.options.cwd,\n findFilePath(configFile)\n );\n } else {\n this.options.root = \".\";\n }\n } else {\n this.options.root = replacePath(this.options.root, this.options.cwd);\n }\n\n this.resolver = createResolver({\n workspaceRoot: this.options.cwd,\n root: this.options.root,\n cacheDir: this.envPaths.cache,\n mode: this.options.mode\n });\n\n await this.resolvePackageConfigs();\n\n this.configFile = await loadUserConfigFile(this.options, this.resolver);\n if (this.configFile.config) {\n if (isSetString(this.configFile.configFile)) {\n this.options.configFile ??= replacePath(\n this.configFile.configFile,\n this.options.cwd\n );\n }\n\n if (!this.options.name) {\n if (\n isSetObject(this.configFile.config) &&\n isSetString((this.configFile.config as UserConfig).name)\n ) {\n this.options.name = (this.configFile.config as UserConfig).name;\n } else if (Array.isArray(this.configFile.config)) {\n for (const config of this.configFile.config) {\n if (\n isSetObject(config) &&\n isSetString((config as UserConfig).name)\n ) {\n this.options.name = (config as UserConfig).name;\n break;\n }\n }\n }\n }\n\n if (!this.options.name) {\n this.options.name = this.projectJson?.name || this.packageJson?.name;\n }\n }\n }\n\n /**\n * 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.\n *\n * @remarks\n * 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.\n *\n * @param cwd - The current working directory to look for the package configurations. Defaults to the `cwd` specified in the context configuration.\n * @param root - The root directory of the project to look for the package configurations. Defaults to the `root` specified in the context configuration.\n * @returns A promise that resolves when the package configurations have been loaded and stored in the context.\n */\n protected async resolvePackageConfigs(\n cwd: string = this.options.cwd,\n root: string = this.options.root\n ) {\n const projectJsonPath = joinPaths(appendPath(root, cwd), \"project.json\");\n if (existsSync(projectJsonPath)) {\n this.projectJson = await readJsonFile(projectJsonPath);\n }\n\n const packageJsonPath = joinPaths(appendPath(root, cwd), \"package.json\");\n if (existsSync(packageJsonPath)) {\n this.packageJson = await readJsonFile<PackageJson>(packageJsonPath);\n this.options.organization ??= isSetObject(this.packageJson?.author)\n ? kebabCase(this.packageJson?.author?.name)\n : kebabCase(this.packageJson?.author);\n }\n }\n\n /**\n * Determine the default mode for the current execution based on the environment and workspace configuration. This function will check the `NODE_ENV` environment variable to determine if the current environment is development, production, or test. If `NODE_ENV` is not set, it will look for a `mode` property in the workspace configuration file. If no mode is specified in the workspace configuration, it will default to \"production\".\n *\n * @returns A promise that resolves to the default mode for the current execution, which can be \"development\", \"production\", or \"test\".\n */\n protected async getDefaultMode(): Promise<Mode> {\n const workspaceConfig = await this.getWorkspaceConfig();\n\n return isProduction\n ? \"production\"\n : isDevelopment\n ? \"development\"\n : isTest\n ? \"test\"\n : workspaceConfig?.mode || \"production\";\n }\n\n /**\n * Determine the default log level for the current execution based on the environment and workspace configuration. This function will check the `logLevel` property in the workspace configuration file and resolve it to a `LogLevelResolvedConfig` value. If no log level is specified in the workspace configuration, it will default to \"info\" for development mode and \"warn\" for production mode.\n *\n * @returns A promise that resolves to the default log level for the current execution, which can be \"fatal\", \"error\", \"warn\", \"info\", \"debug\", or \"trace\".\n */\n protected async getDefaultLogLevel(): Promise<LogLevelResolvedConfig> {\n const workspaceConfig = await this.getWorkspaceConfig();\n\n return resolveLogLevel(\n workspaceConfig?.logLevel\n ? workspaceConfig.logLevel === \"success\" ||\n workspaceConfig.logLevel === \"performance\"\n ? \"info\"\n : workspaceConfig.logLevel === \"all\"\n ? \"debug\"\n : workspaceConfig.logLevel === \"fatal\"\n ? \"error\"\n : workspaceConfig.logLevel\n : undefined,\n this.options?.mode ||\n this.initialOptions?.mode ||\n workspaceConfig?.mode ||\n (await this.getDefaultMode())\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,eAAe,SAA6C;AACnE,QAAO,KAAK,SAAS;EACnB,gBAAgB;EAChB,SACE,QAAQ,SAAS,gBACbA,YAAU,QAAQ,UAAU,OAAO,GACnC;EACN,aAAa,QAAQ,SAAS;EAC/B,CAAC;;;;;;;;AASJ,SAAgB,eAAe,SAA0C;CACvE,MAAM,eAAe,WACnBA,YAAU,QAAQ,eAAe,QAAQ,KAAK,EAC9C,eAAe,QAAQ,CACxB;AACD,cAAa,SAAS,WACpBA,YAAU,QAAQ,eAAe,QAAQ,KAAK,EAC9C,eAAe,QAAQ,CACxB;AAED,QAAO;;;;;ACLT,IAAa,wBAAb,MAA0D;CACxD,aAAqB,KAAK,KAAK;;;;CAK/B,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAQP,AAAO;;;;CAKP,AAAO,cAA+C;;;;CAKtD,AAAO;;;;CAKP,IAAW,SAAiB;AAC1B,SAAO,KAAK,aAAa,EAAE,CAAC;;;;;CAM9B,IAAW,YAAoB;AAC7B,SAAO,MAAKC;;CAGd,IAAW,WAAmC;AAC5C,SAAO,gBAAgB,KAAK,QAAQ,UAAU,KAAK,QAAQ,KAAK;;;;;CAMlE,IAAW,WAAqB;AAC9B,SAAO,YAAY;GACjB,OAAO,KAAK,QAAQ;GACpB,OAAO,KAAK,QAAQ,aAAa;GACjC,eAAe,KAAK,QAAQ;GAC7B,CAAC;;;;;;;CAQJ,AAAO,MAAM,SAA8B;AACz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aAAa,gBAC3B,SACA,gBAAgB,aAAa,QAC3B,UACA,gBAAgB,aAAa,UAC3B,UACA,gBAAgB,WACtB,QACJ,KAAK,SAAS,QACZ,KAAK,gBAAgB,QACrB,iBAAiB,QAChB,MAAM,KAAK,gBAAgB,CAC/B"}
|
package/dist/context/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_base_context = require('../base-context-
|
|
3
|
-
const require_engine_context = require('../engine-context-
|
|
4
|
-
const require_execution_context = require('../execution-context-
|
|
2
|
+
const require_base_context = require('../base-context-D7G_24-i.cjs');
|
|
3
|
+
const require_engine_context = require('../engine-context-BuJQY312.cjs');
|
|
4
|
+
const require_execution_context = require('../execution-context-BrX9i_L8.cjs');
|
|
5
5
|
|
|
6
6
|
exports.PowerlinesBaseContext = require_base_context.PowerlinesBaseContext;
|
|
7
7
|
exports.PowerlinesContext = require_execution_context.PowerlinesContext;
|