@powerlines/engine 0.44.9 → 0.44.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/_internal/worker.cjs +136 -61
  2. package/dist/_internal/worker.mjs +137 -62
  3. package/dist/_internal/worker.mjs.map +1 -1
  4. package/dist/api.cjs +5 -10
  5. package/dist/api.d.cts +3 -3
  6. package/dist/api.d.cts.map +1 -1
  7. package/dist/api.d.mts +3 -3
  8. package/dist/api.d.mts.map +1 -1
  9. package/dist/api.mjs +5 -10
  10. package/dist/api.mjs.map +1 -1
  11. package/dist/{base-context-fOM4ZWUo.mjs → base-context-C6yzgs6K.mjs} +50 -21
  12. package/dist/base-context-C6yzgs6K.mjs.map +1 -0
  13. package/dist/{base-context-CAA1druQ.cjs → base-context-trNQZNsX.cjs} +49 -20
  14. package/dist/context/index.cjs +3 -3
  15. package/dist/context/index.d.cts +50 -17
  16. package/dist/context/index.d.cts.map +1 -1
  17. package/dist/context/index.d.mts +50 -17
  18. package/dist/context/index.d.mts.map +1 -1
  19. package/dist/context/index.mjs +3 -3
  20. package/dist/{engine-context-BWGxMU_n.mjs → engine-context-C-11i43N.mjs} +2 -2
  21. package/dist/{engine-context-BWGxMU_n.mjs.map → engine-context-C-11i43N.mjs.map} +1 -1
  22. package/dist/{engine-context-CUPubmrM.cjs → engine-context-D1_U6xVC.cjs} +1 -1
  23. package/dist/{execution-context-BVn7D0Ax.cjs → execution-context-C-M-Mxse.cjs} +87 -42
  24. package/dist/{execution-context-UJPngOZR.mjs → execution-context-D9Enw3J5.mjs} +89 -44
  25. package/dist/execution-context-D9Enw3J5.mjs.map +1 -0
  26. package/dist/index.cjs +4 -4
  27. package/dist/index.mjs +4 -4
  28. package/dist/index.mjs.map +1 -1
  29. package/package.json +3 -3
  30. package/dist/base-context-fOM4ZWUo.mjs.map +0 -1
  31. package/dist/execution-context-UJPngOZR.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { t as PowerlinesBaseContext } from "./base-context-fOM4ZWUo.mjs";
1
+ import { t as PowerlinesBaseContext } from "./base-context-C6yzgs6K.mjs";
2
2
  import { a as FileSystem } from "./fs-D1nIP45P.mjs";
3
3
  import { n as FileSystemStorageAdapter, t as VirtualStorageAdapter } from "./virtual-CYGZHTDd.mjs";
4
4
  import { i as getTsconfigFilePath } from "./tsconfig-CI6bla4E.mjs";
@@ -11,8 +11,9 @@ import { isSetObject } from "@stryke/type-checks/is-set-object";
11
11
  import { isString } from "@stryke/type-checks/is-string";
12
12
  import { isSetString } from "@stryke/type-checks/is-set-string";
13
13
  import { uuid } from "@stryke/unique-id/uuid";
14
- import { addPluginHook, createLogger, dedupeHooklist, isDuplicate, isPlugin, isPluginConfig, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens, withCustomLogger, withLogger } from "@powerlines/core/plugin-utils";
14
+ import { addPluginHook, createLogger, dedupeHooklist, isDuplicate, isPlugin, isPluginConfig, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens, resolveLogLevel, withCustomLogger, withLogFn } from "@powerlines/core/plugin-utils";
15
15
  import { colorText } from "@powerlines/core/plugin-utils/logging";
16
+ import { getEnvPaths } from "@stryke/env/get-env-paths";
16
17
  import { appendPath } from "@stryke/path/append";
17
18
  import { isEqual } from "@stryke/path/is-equal";
18
19
  import { replaceExtension, replacePath } from "@stryke/path/replace";
@@ -31,6 +32,7 @@ import { isObject } from "@stryke/type-checks/is-object";
31
32
  import { readJsonFile } from "@stryke/fs/json";
32
33
  import { deepClone } from "@stryke/helpers/deep-clone";
33
34
  import { getUniqueInputs, isTypeDefinition, resolveInputsSync } from "@powerlines/core/lib/entry";
35
+ import { toBool } from "@stryke/convert/to-bool";
34
36
  import { relativeToWorkspaceRoot } from "@stryke/fs/get-workspace-root";
35
37
  import { murmurhash } from "@stryke/hash";
36
38
  import { hashDirectory } from "@stryke/hash/node";
@@ -141,34 +143,34 @@ async function writeMetaFile(context) {
141
143
 
142
144
  //#endregion
143
145
  //#region src/_internal/ipc/send.ts
144
- function sendWriteLogMessage(context, type, message) {
145
- const meta = {
146
- ...isSetObject(message) && isSetObject(message.meta) ? message.meta : {},
147
- ...context.logger.options
146
+ function sendWriteLogMessage(context, meta, message) {
147
+ const combinedMeta = {
148
+ ...context.logger.options,
149
+ ...isSetObject(meta) ? meta : { type: meta }
148
150
  };
149
151
  process.send?.({
150
152
  id: uuid(),
151
153
  type: "write-log",
152
- executionId: meta.executionId ?? context.config.executionId,
153
- executionIndex: meta.executionIndex ?? context.config.executionIndex,
154
- environment: meta.environment,
154
+ executionId: combinedMeta.executionId || context.config.executionId,
155
+ executionIndex: combinedMeta.executionIndex ?? context.config.executionIndex,
156
+ environment: combinedMeta.environment,
155
157
  timestamp: Date.now(),
156
158
  payload: {
157
159
  meta: {
158
- type,
159
- category: meta.category ?? LogCategories.GENERAL,
160
- logId: meta.logId ?? uuid(),
161
- timestamp: meta.timestamp ?? Date.now(),
162
- name: meta.name ?? context.config.name,
163
- executionId: meta.executionId ?? context.config.executionId,
164
- executionIndex: meta.executionIndex ?? context.config.executionIndex,
165
- command: meta.command ?? context.config.command,
166
- hook: meta.hook,
167
- environment: meta.environment,
168
- plugin: meta.plugin,
169
- source: meta.source
160
+ type: combinedMeta.type,
161
+ category: combinedMeta.category || LogCategories.GENERAL,
162
+ logId: combinedMeta.logId || uuid(),
163
+ timestamp: combinedMeta.timestamp ?? Date.now(),
164
+ name: combinedMeta.name || context.config.name,
165
+ executionId: combinedMeta.executionId || context.config.executionId,
166
+ executionIndex: combinedMeta.executionIndex ?? context.config.executionIndex,
167
+ command: combinedMeta.command || context.config.command,
168
+ hook: combinedMeta.hook,
169
+ environment: combinedMeta.environment,
170
+ plugin: combinedMeta.plugin,
171
+ source: combinedMeta.source
170
172
  },
171
- message: isSetString(message) ? message : message.message
173
+ message
172
174
  }
173
175
  });
174
176
  }
@@ -1504,18 +1506,45 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1504
1506
  }, {}) : this.config.resolve.alias : {});
1505
1507
  }
1506
1508
  /**
1507
- * 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.
1509
+ * Create a new logger instance
1510
+ *
1511
+ * @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.
1512
+ * @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.
1513
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
1508
1514
  */
1509
- get logger() {
1510
- const options = {
1515
+ createLogger(options, logFn) {
1516
+ let logger;
1517
+ if (toBool(process.env.POWERLINES_WORKER_THREAD_EXECUTION)) logger = createLogger(this.config.name, {
1518
+ ...this.options,
1511
1519
  ...this.config,
1512
- ...this.options
1513
- };
1514
- const logger = withLogger(createLogger(this.config.name, options), createLogger(this.config.name, options, (type, message) => sendWriteLogMessage(this, type, message)));
1515
- if (this.config.customLogger) return withCustomLogger(logger, this.config.customLogger);
1520
+ ...options
1521
+ }, (meta, message) => sendWriteLogMessage(this, meta, message));
1522
+ else logger = createLogger(this.config.name, {
1523
+ ...this.options,
1524
+ ...this.config,
1525
+ ...options
1526
+ });
1527
+ if (this.config.customLogger) logger = withCustomLogger(logger, this.config.customLogger);
1528
+ if (logFn) logger = withLogFn(logger, logFn);
1516
1529
  return logger;
1517
1530
  }
1518
1531
  /**
1532
+ * 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.
1533
+ */
1534
+ get logLevel() {
1535
+ return resolveLogLevel(this.config.logLevel, this.config.mode);
1536
+ }
1537
+ /**
1538
+ * The environment paths for the project, which provide the locations of various directories and files used by the Powerlines framework. These paths are resolved based on the organization ID, application ID, and workspace root directory, and can be used to access configuration files, cache directories, and other resources in a consistent manner.
1539
+ */
1540
+ get envPaths() {
1541
+ return getEnvPaths({
1542
+ orgId: this.config.organization,
1543
+ appId: this.config.framework || "powerlines",
1544
+ workspaceRoot: this.config.cwd
1545
+ });
1546
+ }
1547
+ /**
1519
1548
  * Gets the parser cache.
1520
1549
  */
1521
1550
  get parserCache() {
@@ -1928,18 +1957,16 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1928
1957
  */
1929
1958
  async setup() {
1930
1959
  this.resolvedConfig = mergeConfig({
1960
+ root: this.options.root,
1961
+ cwd: this.options.cwd,
1931
1962
  inlineConfig: this.config.inlineConfig ?? {},
1932
1963
  userConfig: this.config.userConfig ?? {},
1933
1964
  pluginConfig: this.config.pluginConfig ?? {}
1934
- }, this.options, getConfigProps(this.config.inlineConfig), getConfigProps(this.config.userConfig), getConfigProps(this.config.pluginConfig), {
1965
+ }, getConfigProps(this.config.inlineConfig), getConfigProps(this.config.userConfig), getConfigProps(this.config.pluginConfig), this.options, {
1935
1966
  name: this.projectJson?.name || this.packageJson?.name,
1936
1967
  version: this.packageJson?.version,
1937
1968
  description: this.packageJson?.description
1938
1969
  }, {
1939
- projectType: "application",
1940
- platform: "neutral",
1941
- logLevel: "info",
1942
- preview: false,
1943
1970
  environments: {},
1944
1971
  resolve: {}
1945
1972
  });
@@ -1981,7 +2008,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1981
2008
  *
1982
2009
  * @param options - The configuration options to initialize the context with
1983
2010
  */
1984
- async init(options = {}) {
2011
+ async init(options) {
1985
2012
  await super.init(options);
1986
2013
  this.options.executionId = options.executionId ?? this.options.executionId;
1987
2014
  this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
@@ -2033,6 +2060,8 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2033
2060
  this.options.framework = "powerlines";
2034
2061
  this.config.framework = "powerlines";
2035
2062
  }
2063
+ if (!this.config.userConfig?.projectType && !this.config.inlineConfig?.projectType && !this.config.pluginConfig?.projectType) this.config.projectType = "application";
2064
+ if (!this.config.userConfig?.platform && !this.config.inlineConfig?.platform && !this.config.pluginConfig?.platform) this.config.platform = "neutral";
2036
2065
  this.resolvedConfig.compatibilityDate = resolveCompatibilityDates(this.config.inlineConfig.compatibilityDate ?? this.config.userConfig.compatibilityDate ?? this.config.pluginConfig.compatibilityDate, "latest");
2037
2066
  this.config.input = getUniqueInputs(this.config.input);
2038
2067
  if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) this.config.name = this.config.name.split("/").filter(Boolean)[1];
@@ -2059,7 +2088,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2059
2088
  if (!this.config.root.replace(/^\.\/?/, "")) this.config.output.copy.path = this.config.output.copy.path ? appendPath(replacePathTokens(this, this.config.output.copy.path), this.config.cwd) : this.config.output.path;
2060
2089
  else this.config.output.copy.path = appendPath(replacePathTokens(this, this.config.output.copy.path || joinPaths("dist", this.config.root)), this.config.cwd);
2061
2090
  }
2062
- if (this.config.output.dts !== false && this.config.output.types !== false) this.config.output.types = appendPath(replacePathTokens(this, this.config.userConfig?.output?.types || this.config.inlineConfig?.output?.types || this.config.pluginConfig?.output?.types || joinPaths(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
2091
+ if (this.config.output.types !== false) this.config.output.types = appendPath(replacePathTokens(this, this.config.userConfig?.output?.types || this.config.inlineConfig?.output?.types || this.config.pluginConfig?.output?.types || joinPaths(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
2063
2092
  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 = getUniqueBy(this.config.output.copy.assets.map((asset) => {
2064
2093
  return {
2065
2094
  glob: isSetObject(asset) ? asset.glob : asset,
@@ -2234,10 +2263,17 @@ function extractHooks(context, hooks, plugin, key, parentKey) {
2234
2263
  * @returns The proxied plugin context
2235
2264
  */
2236
2265
  function createPluginContext(pluginId, plugin, environment) {
2266
+ const logger = environment.extendLogger({ plugin: plugin.name });
2237
2267
  const normalizeMessage = (message) => {
2238
- return isString(message) ? message : message.message;
2268
+ return {
2269
+ meta: {
2270
+ ...isSetObject(message) ? message.meta : {},
2271
+ environment: environment.environment?.name,
2272
+ plugin: plugin.name
2273
+ },
2274
+ message: isString(message) ? message : message.message
2275
+ };
2239
2276
  };
2240
- const logger = environment.extendLogger({ plugin: plugin.name.replaceAll(":", " - ") });
2241
2277
  const callHookFn = async (hook, options, ...args) => {
2242
2278
  return environment.$$internal.api.callHook(hook, {
2243
2279
  sequential: true,
@@ -2257,6 +2293,9 @@ function createPluginContext(pluginId, plugin, environment) {
2257
2293
  };
2258
2294
  if (prop === "id") return pluginId;
2259
2295
  if (prop === "logger") return logger;
2296
+ if (prop === "log") return (type, message) => {
2297
+ logger.log(type, normalizeMessage(message));
2298
+ };
2260
2299
  if (prop === "fatal") return (message) => {
2261
2300
  logger.error(normalizeMessage(message));
2262
2301
  };
@@ -2347,13 +2386,14 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2347
2386
  * Create a new logger instance
2348
2387
  *
2349
2388
  * @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.
2389
+ * @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.
2350
2390
  * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
2351
2391
  */
2352
- createLogger(options, callback) {
2392
+ createLogger(options, logFn) {
2353
2393
  return super.createLogger({
2354
2394
  ...options,
2355
2395
  environment: this.environment?.name
2356
- }, callback);
2396
+ }, logFn);
2357
2397
  }
2358
2398
  /**
2359
2399
  * Extend the base logger with additional configuration options
@@ -2386,7 +2426,11 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2386
2426
  this.resolvedConfig = mergeConfig({
2387
2427
  name: this.config.name,
2388
2428
  title: this.config.title
2389
- }, getConfigProps(this.environment, this.options.root, this.options.cwd), this.config);
2429
+ }, getConfigProps({
2430
+ ...this.environment,
2431
+ root: this.options.root,
2432
+ cwd: this.options.cwd
2433
+ }), this.config);
2390
2434
  await this.innerSetup();
2391
2435
  }
2392
2436
  async addPlugin(plugin) {
@@ -2552,14 +2596,15 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2552
2596
  * Create a new logger instance
2553
2597
  *
2554
2598
  * @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.
2599
+ * @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.
2555
2600
  * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
2556
2601
  */
2557
- createLogger(options, callback) {
2602
+ createLogger(options, logFn) {
2558
2603
  return super.createLogger({
2559
2604
  ...options,
2560
2605
  executionId: this.id,
2561
2606
  executionIndex: this.options.executionIndex
2562
- }, callback);
2607
+ }, logFn);
2563
2608
  }
2564
2609
  /**
2565
2610
  * Extend the base logger with additional configuration options
@@ -2676,4 +2721,4 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2676
2721
 
2677
2722
  //#endregion
2678
2723
  export { mergeConfigs as a, callHook as i, PowerlinesEnvironmentContext as n, PowerlinesContext as o, createPluginContext as r, writeMetaFile as s, PowerlinesExecutionContext as t };
2679
- //# sourceMappingURL=execution-context-UJPngOZR.mjs.map
2724
+ //# sourceMappingURL=execution-context-D9Enw3J5.mjs.map