@powerlines/core 0.14.5 → 0.15.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/constants/api.cjs +6 -5
- package/dist/constants/api.d.cts +3 -3
- package/dist/constants/api.d.cts.map +1 -1
- package/dist/constants/api.d.mts +3 -3
- package/dist/constants/api.d.mts.map +1 -1
- package/dist/constants/api.mjs +4 -4
- package/dist/constants/api.mjs.map +1 -1
- package/dist/constants/commands.cjs +3 -2
- package/dist/constants/commands.d.cts +1 -1
- package/dist/constants/commands.d.mts +1 -1
- package/dist/constants/commands.mjs +2 -2
- package/dist/constants/commands.mjs.map +1 -1
- package/dist/constants/devtools.cjs +23 -0
- package/dist/constants/devtools.d.cts +13 -0
- package/dist/constants/devtools.d.cts.map +1 -0
- package/dist/constants/devtools.d.mts +13 -0
- package/dist/constants/devtools.d.mts.map +1 -0
- package/dist/constants/devtools.mjs +14 -0
- package/dist/constants/devtools.mjs.map +1 -0
- package/dist/constants/environments.cjs +1 -0
- package/dist/constants/extensions.cjs +21 -0
- package/dist/constants/extensions.d.cts +5 -0
- package/dist/constants/extensions.d.cts.map +1 -0
- package/dist/constants/extensions.d.mts +5 -0
- package/dist/constants/extensions.d.mts.map +1 -0
- package/dist/constants/extensions.mjs +20 -0
- package/dist/constants/extensions.mjs.map +1 -0
- package/dist/constants/fs.cjs +1 -0
- package/dist/constants/hooks.cjs +1 -0
- package/dist/constants/index.cjs +48 -30
- package/dist/constants/index.d.cts +5 -3
- package/dist/constants/index.d.mts +5 -3
- package/dist/constants/index.mjs +5 -3
- package/dist/constants/log-level.cjs +90 -0
- package/dist/constants/log-level.d.cts +63 -0
- package/dist/constants/log-level.d.cts.map +1 -0
- package/dist/constants/log-level.d.mts +63 -0
- package/dist/constants/log-level.d.mts.map +1 -0
- package/dist/constants/log-level.mjs +82 -0
- package/dist/constants/log-level.mjs.map +1 -0
- package/dist/constants/meta.cjs +1 -0
- package/dist/constants/plugin.cjs +3 -2
- package/dist/constants/plugin.d.cts +2 -2
- package/dist/constants/plugin.d.mts +2 -2
- package/dist/context/base-context.cjs +127 -0
- package/dist/context/base-context.d.cts +81 -0
- package/dist/context/base-context.d.cts.map +1 -0
- package/dist/context/base-context.d.mts +81 -0
- package/dist/context/base-context.d.mts.map +1 -0
- package/dist/context/base-context.mjs +125 -0
- package/dist/context/base-context.mjs.map +1 -0
- package/dist/context/context.cjs +934 -0
- package/dist/context/context.d.cts +369 -0
- package/dist/context/context.d.cts.map +1 -0
- package/dist/context/context.d.mts +369 -0
- package/dist/context/context.d.mts.map +1 -0
- package/dist/context/context.mjs +932 -0
- package/dist/context/context.mjs.map +1 -0
- package/dist/context/environment-context.cjs +219 -0
- package/dist/context/environment-context.d.cts +100 -0
- package/dist/context/environment-context.d.cts.map +1 -0
- package/dist/context/environment-context.d.mts +100 -0
- package/dist/context/environment-context.d.mts.map +1 -0
- package/dist/context/environment-context.mjs +218 -0
- package/dist/context/environment-context.mjs.map +1 -0
- package/dist/context/execution-context.cjs +230 -0
- package/dist/context/execution-context.d.cts +101 -0
- package/dist/context/execution-context.d.cts.map +1 -0
- package/dist/context/execution-context.d.mts +101 -0
- package/dist/context/execution-context.d.mts.map +1 -0
- package/dist/context/execution-context.mjs +228 -0
- package/dist/context/execution-context.mjs.map +1 -0
- package/dist/context/index.cjs +12 -0
- package/dist/context/index.d.cts +6 -0
- package/dist/context/index.d.mts +6 -0
- package/dist/context/index.mjs +7 -0
- package/dist/context/plugin-context.cjs +83 -0
- package/dist/context/plugin-context.d.cts +18 -0
- package/dist/context/plugin-context.d.cts.map +1 -0
- package/dist/context/plugin-context.d.mts +18 -0
- package/dist/context/plugin-context.d.mts.map +1 -0
- package/dist/context/plugin-context.mjs +82 -0
- package/dist/context/plugin-context.mjs.map +1 -0
- package/dist/index.cjs +62 -9
- package/dist/index.d.cts +20 -9
- package/dist/index.d.mts +20 -9
- package/dist/index.mjs +17 -5
- package/dist/lib/config.cjs +160 -15
- package/dist/lib/config.d.cts +92 -6
- package/dist/lib/config.d.cts.map +1 -1
- package/dist/lib/config.d.mts +92 -6
- package/dist/lib/config.d.mts.map +1 -1
- package/dist/lib/config.mjs +154 -16
- package/dist/lib/config.mjs.map +1 -1
- package/dist/lib/context-helpers.cjs +43 -0
- package/dist/lib/context-helpers.d.cts +19 -0
- package/dist/lib/context-helpers.d.cts.map +1 -0
- package/dist/lib/context-helpers.d.mts +19 -0
- package/dist/lib/context-helpers.d.mts.map +1 -0
- package/dist/lib/context-helpers.mjs +41 -0
- package/dist/lib/context-helpers.mjs.map +1 -0
- package/dist/lib/entry.cjs +5 -5
- package/dist/lib/entry.d.cts.map +1 -1
- package/dist/lib/entry.d.mts.map +1 -1
- package/dist/lib/entry.mjs +5 -5
- package/dist/lib/entry.mjs.map +1 -1
- package/dist/lib/environment.cjs +72 -0
- package/dist/lib/environment.d.cts +12 -0
- package/dist/lib/environment.d.cts.map +1 -0
- package/dist/lib/environment.d.mts +12 -0
- package/dist/lib/environment.d.mts.map +1 -0
- package/dist/lib/environment.mjs +67 -0
- package/dist/lib/environment.mjs.map +1 -0
- package/dist/lib/events.cjs +43 -0
- package/dist/lib/events.d.cts +10 -0
- package/dist/lib/events.d.cts.map +1 -0
- package/dist/lib/events.d.mts +10 -0
- package/dist/lib/events.d.mts.map +1 -0
- package/dist/lib/events.mjs +42 -0
- package/dist/lib/events.mjs.map +1 -0
- package/dist/lib/generate-types.cjs +371 -0
- package/dist/lib/generate-types.d.cts +67 -0
- package/dist/lib/generate-types.d.cts.map +1 -0
- package/dist/lib/generate-types.d.mts +67 -0
- package/dist/lib/generate-types.d.mts.map +1 -0
- package/dist/lib/generate-types.mjs +368 -0
- package/dist/lib/generate-types.mjs.map +1 -0
- package/dist/lib/hooks.cjs +152 -0
- package/dist/lib/hooks.d.cts +28 -0
- package/dist/lib/hooks.d.cts.map +1 -0
- package/dist/lib/hooks.d.mts +28 -0
- package/dist/lib/hooks.d.mts.map +1 -0
- package/dist/lib/hooks.mjs +147 -0
- package/dist/lib/hooks.mjs.map +1 -0
- package/dist/lib/index.cjs +64 -9
- package/dist/lib/index.d.cts +15 -3
- package/dist/lib/index.d.mts +15 -3
- package/dist/lib/index.mjs +19 -5
- package/dist/lib/install-dependencies.cjs +25 -0
- package/dist/lib/install-dependencies.d.cts +12 -0
- package/dist/lib/install-dependencies.d.cts.map +1 -0
- package/dist/lib/install-dependencies.d.mts +12 -0
- package/dist/lib/install-dependencies.d.mts.map +1 -0
- package/dist/lib/install-dependencies.mjs +24 -0
- package/dist/lib/install-dependencies.mjs.map +1 -0
- package/dist/lib/meta.cjs +57 -0
- package/dist/lib/meta.d.cts +34 -0
- package/dist/lib/meta.d.cts.map +1 -0
- package/dist/lib/meta.d.mts +34 -0
- package/dist/lib/meta.d.mts.map +1 -0
- package/dist/lib/meta.mjs +54 -0
- package/dist/lib/meta.mjs.map +1 -0
- package/dist/lib/plugins.cjs +150 -0
- package/dist/lib/plugins.d.cts +40 -0
- package/dist/lib/plugins.d.cts.map +1 -0
- package/dist/lib/plugins.d.mts +40 -0
- package/dist/lib/plugins.d.mts.map +1 -0
- package/dist/lib/plugins.mjs +146 -0
- package/dist/lib/plugins.mjs.map +1 -0
- package/dist/lib/resolver.cjs +35 -0
- package/dist/lib/resolver.d.cts +21 -0
- package/dist/lib/resolver.d.cts.map +1 -0
- package/dist/lib/resolver.d.mts +21 -0
- package/dist/lib/resolver.d.mts.map +1 -0
- package/dist/lib/resolver.mjs +33 -0
- package/dist/lib/resolver.mjs.map +1 -0
- package/dist/lib/schemas.cjs +9 -0
- package/dist/lib/schemas.d.cts +2 -0
- package/dist/lib/schemas.d.mts +2 -0
- package/dist/lib/schemas.mjs +3 -0
- package/dist/lib/streaming-channel.cjs +260 -0
- package/dist/lib/streaming-channel.d.cts +133 -0
- package/dist/lib/streaming-channel.d.cts.map +1 -0
- package/dist/lib/streaming-channel.d.mts +133 -0
- package/dist/lib/streaming-channel.d.mts.map +1 -0
- package/dist/lib/streaming-channel.mjs +258 -0
- package/dist/lib/streaming-channel.mjs.map +1 -0
- package/dist/lib/typescript/index.cjs +16 -0
- package/dist/lib/typescript/index.d.cts +3 -0
- package/dist/lib/typescript/index.d.mts +3 -0
- package/dist/lib/typescript/index.mjs +4 -0
- package/dist/lib/typescript/ts-morph.cjs +105 -0
- package/dist/lib/typescript/ts-morph.d.cts +38 -0
- package/dist/lib/typescript/ts-morph.d.cts.map +1 -0
- package/dist/lib/typescript/ts-morph.d.mts +38 -0
- package/dist/lib/typescript/ts-morph.d.mts.map +1 -0
- package/dist/lib/typescript/ts-morph.mjs +102 -0
- package/dist/lib/typescript/ts-morph.mjs.map +1 -0
- package/dist/lib/typescript/tsconfig.cjs +253 -0
- package/dist/lib/typescript/tsconfig.d.cts +77 -0
- package/dist/lib/typescript/tsconfig.d.cts.map +1 -0
- package/dist/lib/typescript/tsconfig.d.mts +77 -0
- package/dist/lib/typescript/tsconfig.d.mts.map +1 -0
- package/dist/lib/typescript/tsconfig.mjs +240 -0
- package/dist/lib/typescript/tsconfig.mjs.map +1 -0
- package/dist/lib/unplugin/helpers.cjs +2 -2
- package/dist/lib/unplugin/module-resolution.cjs +18 -18
- package/dist/lib/unplugin/module-resolution.mjs +18 -18
- package/dist/lib/unplugin/module-resolution.mjs.map +1 -1
- package/dist/lib/unplugin/plugin.cjs +55 -62
- package/dist/lib/unplugin/plugin.d.cts +10 -11
- package/dist/lib/unplugin/plugin.d.cts.map +1 -1
- package/dist/lib/unplugin/plugin.d.mts +10 -11
- package/dist/lib/unplugin/plugin.d.mts.map +1 -1
- package/dist/lib/unplugin/plugin.mjs +55 -62
- package/dist/lib/unplugin/plugin.mjs.map +1 -1
- package/dist/lib/utilities/file-header.cjs +2 -2
- package/dist/lib/utilities/file-header.mjs +2 -2
- package/dist/lib/utilities/file-header.mjs.map +1 -1
- package/dist/lib/utilities/format.cjs +1 -1
- package/dist/lib/utilities/format.mjs +1 -1
- package/dist/lib/utilities/index.cjs +2 -2
- package/dist/lib/utilities/index.mjs +2 -2
- package/dist/lib/utilities/write-file.cjs +1 -2
- package/dist/lib/utilities/write-file.d.cts +1 -1
- package/dist/lib/utilities/write-file.d.cts.map +1 -1
- package/dist/lib/utilities/write-file.d.mts +1 -1
- package/dist/lib/utilities/write-file.d.mts.map +1 -1
- package/dist/lib/utilities/write-file.mjs +1 -2
- package/dist/lib/utilities/write-file.mjs.map +1 -1
- package/dist/lib/vfs.cjs +1104 -0
- package/dist/lib/vfs.d.cts +321 -0
- package/dist/lib/vfs.d.cts.map +1 -0
- package/dist/lib/vfs.d.mts +321 -0
- package/dist/lib/vfs.d.mts.map +1 -0
- package/dist/lib/vfs.mjs +1102 -0
- package/dist/lib/vfs.mjs.map +1 -0
- package/dist/plugin-base.cjs +1 -1
- package/dist/plugin-base.mjs +1 -1
- package/dist/plugin-base.mjs.map +1 -1
- package/dist/plugin-utils/build-helpers.cjs +2 -2
- package/dist/plugin-utils/build-helpers.mjs +2 -2
- package/dist/plugin-utils/build-helpers.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +22 -12
- package/dist/plugin-utils/context-helpers.d.cts +9 -1
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +9 -1
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +22 -13
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/filter.cjs +13 -5
- package/dist/plugin-utils/filter.d.cts +2 -1
- package/dist/plugin-utils/filter.d.cts.map +1 -1
- package/dist/plugin-utils/filter.d.mts +2 -1
- package/dist/plugin-utils/filter.d.mts.map +1 -1
- package/dist/plugin-utils/filter.mjs +13 -6
- package/dist/plugin-utils/filter.mjs.map +1 -1
- package/dist/plugin-utils/format.cjs +44 -0
- package/dist/plugin-utils/format.d.cts +11 -0
- package/dist/plugin-utils/format.d.cts.map +1 -0
- package/dist/plugin-utils/format.d.mts +11 -0
- package/dist/plugin-utils/format.d.mts.map +1 -0
- package/dist/plugin-utils/format.mjs +43 -0
- package/dist/plugin-utils/format.mjs.map +1 -0
- package/dist/plugin-utils/helpers.cjs +6 -6
- package/dist/plugin-utils/helpers.d.cts +15 -15
- package/dist/plugin-utils/helpers.d.cts.map +1 -1
- package/dist/plugin-utils/helpers.d.mts +15 -15
- package/dist/plugin-utils/helpers.d.mts.map +1 -1
- package/dist/plugin-utils/helpers.mjs +1 -1
- package/dist/plugin-utils/helpers.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +34 -4
- package/dist/plugin-utils/index.d.cts +7 -4
- package/dist/plugin-utils/index.d.mts +7 -4
- package/dist/plugin-utils/index.mjs +9 -6
- package/dist/plugin-utils/install.cjs +47 -0
- package/dist/plugin-utils/install.d.cts +23 -0
- package/dist/plugin-utils/install.d.cts.map +1 -0
- package/dist/plugin-utils/install.d.mts +23 -0
- package/dist/plugin-utils/install.d.mts.map +1 -0
- package/dist/plugin-utils/install.mjs +45 -0
- package/dist/plugin-utils/install.mjs.map +1 -0
- package/dist/plugin-utils/logging.cjs +588 -1
- package/dist/plugin-utils/logging.d.cts +93 -1
- package/dist/plugin-utils/logging.d.cts.map +1 -1
- package/dist/plugin-utils/logging.d.mts +93 -1
- package/dist/plugin-utils/logging.d.mts.map +1 -1
- package/dist/plugin-utils/logging.mjs +572 -1
- package/dist/plugin-utils/logging.mjs.map +1 -1
- package/dist/plugin-utils/merge.cjs +1 -1
- package/dist/plugin-utils/merge.mjs +1 -1
- package/dist/plugin-utils/modules.cjs +1 -1
- package/dist/plugin-utils/modules.mjs +1 -1
- package/dist/plugin-utils/modules.mjs.map +1 -1
- package/dist/plugin-utils/paths.cjs +6 -2
- package/dist/plugin-utils/paths.mjs +6 -2
- package/dist/plugin-utils/paths.mjs.map +1 -1
- package/dist/plugin-utils/virtual.cjs +80 -0
- package/dist/plugin-utils/virtual.d.cts +69 -0
- package/dist/plugin-utils/virtual.d.cts.map +1 -0
- package/dist/plugin-utils/virtual.d.mts +69 -0
- package/dist/plugin-utils/virtual.d.mts.map +1 -0
- package/dist/plugin-utils/virtual.mjs +73 -0
- package/dist/plugin-utils/virtual.mjs.map +1 -0
- package/dist/schemas/fs.cjs +232 -0
- package/dist/schemas/fs.d.cts +127 -0
- package/dist/schemas/fs.d.cts.map +1 -0
- package/dist/schemas/fs.d.mts +127 -0
- package/dist/schemas/fs.d.mts.map +1 -0
- package/dist/schemas/fs.mjs +226 -0
- package/dist/schemas/fs.mjs.map +1 -0
- package/dist/storage/base.cjs +216 -0
- package/dist/storage/base.d.cts +201 -0
- package/dist/storage/base.d.cts.map +1 -0
- package/dist/storage/base.d.mts +201 -0
- package/dist/storage/base.d.mts.map +1 -0
- package/dist/storage/base.mjs +215 -0
- package/dist/storage/base.mjs.map +1 -0
- package/dist/storage/file-system.cjs +180 -0
- package/dist/storage/file-system.d.cts +129 -0
- package/dist/storage/file-system.d.cts.map +1 -0
- package/dist/storage/file-system.d.mts +129 -0
- package/dist/storage/file-system.d.mts.map +1 -0
- package/dist/storage/file-system.mjs +179 -0
- package/dist/storage/file-system.mjs.map +1 -0
- package/dist/storage/helpers.cjs +37 -0
- package/dist/storage/helpers.d.cts +25 -0
- package/dist/storage/helpers.d.cts.map +1 -0
- package/dist/storage/helpers.d.mts +25 -0
- package/dist/storage/helpers.d.mts.map +1 -0
- package/dist/storage/helpers.mjs +34 -0
- package/dist/storage/helpers.mjs.map +1 -0
- package/dist/storage/index.cjs +12 -0
- package/dist/storage/index.d.cts +5 -0
- package/dist/storage/index.d.mts +5 -0
- package/dist/storage/index.mjs +6 -0
- package/dist/storage/virtual.cjs +98 -0
- package/dist/storage/virtual.d.cts +80 -0
- package/dist/storage/virtual.d.cts.map +1 -0
- package/dist/storage/virtual.d.mts +80 -0
- package/dist/storage/virtual.d.mts.map +1 -0
- package/dist/storage/virtual.mjs +97 -0
- package/dist/storage/virtual.mjs.map +1 -0
- package/dist/types/api.d.cts +18 -152
- package/dist/types/api.d.cts.map +1 -1
- package/dist/types/api.d.mts +18 -152
- package/dist/types/api.d.mts.map +1 -1
- package/dist/types/config.d.cts +194 -135
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +195 -136
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/context.d.cts +152 -128
- package/dist/types/context.d.cts.map +1 -1
- package/dist/types/context.d.mts +155 -131
- package/dist/types/context.d.mts.map +1 -1
- package/dist/types/fs.d.mts +1 -1
- package/dist/types/index.d.cts +5 -6
- package/dist/types/index.d.mts +5 -6
- package/dist/types/logging.d.cts +161 -0
- package/dist/types/logging.d.cts.map +1 -0
- package/dist/types/logging.d.mts +161 -0
- package/dist/types/logging.d.mts.map +1 -0
- package/dist/types/plugin.d.cts +6 -9
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts +6 -9
- package/dist/types/plugin.d.mts.map +1 -1
- package/dist/types/tsconfig.d.mts +1 -1
- package/dist/types/unplugin.d.cts +5 -26
- package/dist/types/unplugin.d.cts.map +1 -1
- package/dist/types/unplugin.d.mts +5 -26
- package/dist/types/unplugin.d.mts.map +1 -1
- package/package.json +259 -457
- package/schemas/fs.capnp +42 -0
- package/dist/constants/virtual-modules.cjs +0 -8
- package/dist/constants/virtual-modules.d.cts +0 -6
- package/dist/constants/virtual-modules.d.cts.map +0 -1
- package/dist/constants/virtual-modules.d.mts +0 -6
- package/dist/constants/virtual-modules.d.mts.map +0 -1
- package/dist/constants/virtual-modules.mjs +0 -7
- package/dist/constants/virtual-modules.mjs.map +0 -1
- package/dist/lib/logger.cjs +0 -99
- package/dist/lib/logger.d.cts +0 -53
- package/dist/lib/logger.d.cts.map +0 -1
- package/dist/lib/logger.d.mts +0 -53
- package/dist/lib/logger.d.mts.map +0 -1
- package/dist/lib/logger.mjs +0 -93
- package/dist/lib/logger.mjs.map +0 -1
- package/dist/types/_internal.cjs +0 -0
- package/dist/types/_internal.d.cts +0 -106
- package/dist/types/_internal.d.cts.map +0 -1
- package/dist/types/_internal.d.mts +0 -106
- package/dist/types/_internal.d.mts.map +0 -1
- package/dist/types/_internal.mjs +0 -1
- package/dist/types/commands.d.cts +0 -16
- package/dist/types/commands.d.cts.map +0 -1
- package/dist/types/commands.d.mts +0 -16
- package/dist/types/commands.d.mts.map +0 -1
- package/dist/types/utils.d.cts +0 -9
- package/dist/types/utils.d.cts.map +0 -1
- package/dist/types/utils.d.mts +0 -9
- package/dist/types/utils.d.mts.map +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Plugin } from "../types/plugin.mjs";
|
|
2
|
+
import { Logger, LoggerOptions } from "../types/logging.mjs";
|
|
3
|
+
import { ExecutionContext, PluginContext } from "../types/context.mjs";
|
|
4
|
+
import { EnvironmentResolvedConfig, ExecutionOptions, PluginConfig, ResolvedConfig } from "../types/config.mjs";
|
|
5
|
+
import { PowerlinesContext } from "./context.mjs";
|
|
6
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/context/execution-context.d.ts
|
|
9
|
+
declare class PowerlinesExecutionContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig, TSystemContext = unknown> extends PowerlinesContext<TResolvedConfig, TSystemContext> implements ExecutionContext<TResolvedConfig, TSystemContext> {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new Storm context from the workspace root and user config.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The execution options to create the context with.
|
|
15
|
+
* @param inlineConfig - The inline configuration for the context.
|
|
16
|
+
* @returns A promise that resolves to the new context.
|
|
17
|
+
*/
|
|
18
|
+
static from<TResolvedConfig extends ResolvedConfig = ResolvedConfig, TSystemContext = unknown>(options: ExecutionOptions, inlineConfig?: TResolvedConfig["inlineConfig"], system?: TSystemContext): Promise<PowerlinesExecutionContext<TResolvedConfig, TSystemContext>>;
|
|
19
|
+
/**
|
|
20
|
+
* 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.
|
|
21
|
+
*/
|
|
22
|
+
get id(): string;
|
|
23
|
+
/**
|
|
24
|
+
* A record of all environments by name
|
|
25
|
+
*/
|
|
26
|
+
get environments(): Record<string, PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>>;
|
|
27
|
+
get plugins(): Array<Plugin<PluginContext<TResolvedConfig, TSystemContext>>>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new instance.
|
|
30
|
+
*
|
|
31
|
+
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
32
|
+
*/
|
|
33
|
+
protected constructor(options: ExecutionOptions);
|
|
34
|
+
/**
|
|
35
|
+
* 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.
|
|
36
|
+
*
|
|
37
|
+
* @param config - The inline configuration values to set.
|
|
38
|
+
* @returns A promise that resolves when the inline configuration values have been set.
|
|
39
|
+
*/
|
|
40
|
+
setInlineConfig(config: TResolvedConfig["inlineConfig"]): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new logger instance
|
|
43
|
+
*
|
|
44
|
+
* @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.
|
|
45
|
+
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
46
|
+
*/
|
|
47
|
+
createLogger(options: LoggerOptions): Logger;
|
|
48
|
+
/**
|
|
49
|
+
* Extend the base logger with additional configuration options
|
|
50
|
+
*
|
|
51
|
+
* @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.
|
|
52
|
+
* @returns A new logger client instance that extends the base logger with the provided configuration options.
|
|
53
|
+
*/
|
|
54
|
+
extendLogger(options: LoggerOptions): Logger;
|
|
55
|
+
/**
|
|
56
|
+
* A function to copy the context and update the fields for a specific environment
|
|
57
|
+
*
|
|
58
|
+
* @param environment - The environment configuration to use.
|
|
59
|
+
* @returns A new context instance with the updated environment.
|
|
60
|
+
*/
|
|
61
|
+
createEnvironment(environment: EnvironmentResolvedConfig<TResolvedConfig>["environment"]): Promise<PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>>;
|
|
62
|
+
/**
|
|
63
|
+
* Update the context using a new inline configuration options
|
|
64
|
+
*/
|
|
65
|
+
resolveConfig(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Get an environment by name, or the default environment if no name is provided
|
|
68
|
+
*
|
|
69
|
+
* @param name - The name of the environment to retrieve.
|
|
70
|
+
* @returns The requested environment context.
|
|
71
|
+
*/
|
|
72
|
+
getEnvironment(name?: string): Promise<PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>>;
|
|
73
|
+
/**
|
|
74
|
+
* A safe version of `getEnvironment` that returns `undefined` if the environment is not found
|
|
75
|
+
*
|
|
76
|
+
* @param name - The name of the environment to retrieve.
|
|
77
|
+
* @returns The requested environment context or `undefined` if not found.
|
|
78
|
+
*/
|
|
79
|
+
getEnvironmentSafe(name?: string): Promise<PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext> | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* A function to merge all configured environments into a single context.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* If only one environment is configured, that environment will be returned directly.
|
|
85
|
+
*
|
|
86
|
+
* @returns A promise that resolves to a merged/global environment context.
|
|
87
|
+
*/
|
|
88
|
+
toEnvironment(): Promise<PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>>;
|
|
89
|
+
/**
|
|
90
|
+
* A function used internally to add a plugin to the context and update the configuration options
|
|
91
|
+
*
|
|
92
|
+
* @danger
|
|
93
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
unstable_addPlugin(plugin: PluginConfig<PluginContext<TResolvedConfig, TSystemContext>>): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { PowerlinesExecutionContext };
|
|
101
|
+
//# sourceMappingURL=execution-context.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.d.mts","names":[],"sources":["../../src/context/execution-context.ts"],"mappings":";;;;;;;;cAkDa,0BAAA,yBACa,cAAA,GAAiB,cAAA,oCAGjC,iBAAA,CAAkB,eAAA,EAAiB,cAAA,aAChC,gBAAA,CAAiB,eAAA,EAAiB,cAAA;EAAA;;;;;AAL/C;;;SA2BsB,IAAA,yBACM,cAAA,GAAiB,cAAA,2BAAA,CAGzC,OAAA,EAAS,gBAAA,EACT,YAAA,GAAe,eAAA,kBACf,MAAA,GAAS,cAAA,GACR,OAAA,CAAQ,0BAAA,CAA2B,eAAA,EAAiB,cAAA;EAjCd;;;EAAA,IAsD9B,EAAA,CAAA;EAlDkC;;;EAAA,IAyDlC,YAAA,CAAA,GAAgB,MAAA,SAEzB,4BAAA,CAA6B,eAAA,EAAiB,cAAA;EAAA,IAKrC,OAAA,CAAA,GAAW,KAAA,CACpB,MAAA,CAAO,aAAA,CAAc,eAAA,EAAiB,cAAA;EArC7B;;;;;EAAA,UA+CF,WAAA,CAAa,OAAA,EAAS,gBAAA;EAhBiB;;;;;;EA0B1B,eAAA,CACpB,MAAA,EAAQ,eAAA,mBACP,OAAA;EAvBmB;;;;;;EA6CN,YAAA,CAAa,OAAA,EAAS,aAAA,GAAgB,MAAA;EAcA;;;;;;EAAtC,YAAA,CAAa,OAAA,EAAS,aAAA,GAAgB,MAAA;EAgGnB;;;;;;EAlFtB,iBAAA,CACX,WAAA,EAAa,yBAAA,CAA0B,eAAA,mBACtC,OAAA,CAAQ,4BAAA,CAA6B,eAAA,EAAiB,cAAA;EAuKvD;;;EAvFoB,aAAA,CAAA,GAAa,OAAA;EAyGjC;;;;;;EAlFW,cAAA,CAAe,IAAA,YAAa,OAAA,CAAA,4BAAA,CAAA,eAAA,EAAA,cAAA;EAnPjC;;;;;;EAgTK,kBAAA,CACX,IAAA,YACC,OAAA,CACD,4BAAA,CAA6B,eAAA,EAAiB,cAAA;EArThD;;;;;;;;EAsUa,aAAA,CAAA,GAAiB,OAAA,CAC5B,4BAAA,CAA6B,eAAA,EAAiB,cAAA;EA7S9C;;;;;;;;EA2UW,kBAAA,CACX,MAAA,EAAQ,YAAA,CAAa,aAAA,CAAc,eAAA,EAAiB,cAAA,KAAgB,OAAA;AAAA"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { DEFAULT_ENVIRONMENT, GLOBAL_ENVIRONMENT } from "../constants/environments.mjs";
|
|
2
|
+
import { resolvePlugins } from "../lib/plugins.mjs";
|
|
3
|
+
import { PowerlinesContext } from "./context.mjs";
|
|
4
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.mjs";
|
|
5
|
+
import { createDefaultEnvironment, createEnvironment } from "../lib/environment.mjs";
|
|
6
|
+
import { existsSync } from "@stryke/fs/exists";
|
|
7
|
+
import { readJsonFile } from "@stryke/fs/json";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
10
|
+
import { isObject } from "@stryke/type-checks/is-object";
|
|
11
|
+
import { joinPaths } from "@stryke/path/join";
|
|
12
|
+
import { deepClone } from "@stryke/helpers/deep-clone";
|
|
13
|
+
|
|
14
|
+
//#region src/context/execution-context.ts
|
|
15
|
+
var PowerlinesExecutionContext = class PowerlinesExecutionContext extends PowerlinesContext {
|
|
16
|
+
/**
|
|
17
|
+
* A record of all environments by name
|
|
18
|
+
*/
|
|
19
|
+
#environments = {};
|
|
20
|
+
/**
|
|
21
|
+
* 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.
|
|
22
|
+
*/
|
|
23
|
+
#plugins = [];
|
|
24
|
+
/**
|
|
25
|
+
* Create a new Storm context from the workspace root and user config.
|
|
26
|
+
*
|
|
27
|
+
* @param options - The execution options to create the context with.
|
|
28
|
+
* @param inlineConfig - The inline configuration for the context.
|
|
29
|
+
* @returns A promise that resolves to the new context.
|
|
30
|
+
*/
|
|
31
|
+
static async from(options, inlineConfig, system) {
|
|
32
|
+
const context = new PowerlinesExecutionContext(options);
|
|
33
|
+
if (system) context.system = system;
|
|
34
|
+
await context.init();
|
|
35
|
+
if (inlineConfig) await context.setInlineConfig(inlineConfig);
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 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.
|
|
40
|
+
*/
|
|
41
|
+
get id() {
|
|
42
|
+
return this.options.executionId;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A record of all environments by name
|
|
46
|
+
*/
|
|
47
|
+
get environments() {
|
|
48
|
+
return this.#environments;
|
|
49
|
+
}
|
|
50
|
+
get plugins() {
|
|
51
|
+
return this.#plugins;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new instance.
|
|
55
|
+
*
|
|
56
|
+
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
57
|
+
*/
|
|
58
|
+
constructor(options) {
|
|
59
|
+
super(options);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 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.
|
|
63
|
+
*
|
|
64
|
+
* @param config - The inline configuration values to set.
|
|
65
|
+
* @returns A promise that resolves when the inline configuration values have been set.
|
|
66
|
+
*/
|
|
67
|
+
async setInlineConfig(config) {
|
|
68
|
+
await super.setInlineConfig(config);
|
|
69
|
+
if (this.inlineConfig.command === "new") {
|
|
70
|
+
const workspacePackageJsonPath = joinPaths(this.cwd, "package.json");
|
|
71
|
+
if (!existsSync(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
72
|
+
this.packageJson = await readJsonFile(workspacePackageJsonPath);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a new logger instance
|
|
77
|
+
*
|
|
78
|
+
* @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.
|
|
79
|
+
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
80
|
+
*/
|
|
81
|
+
createLogger(options) {
|
|
82
|
+
return super.createLogger({
|
|
83
|
+
...options,
|
|
84
|
+
executionId: this.id,
|
|
85
|
+
configIndex: this.options.configIndex
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extend the base logger with additional configuration options
|
|
90
|
+
*
|
|
91
|
+
* @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.
|
|
92
|
+
* @returns A new logger client instance that extends the base logger with the provided configuration options.
|
|
93
|
+
*/
|
|
94
|
+
extendLogger(options) {
|
|
95
|
+
return super.extendLogger({
|
|
96
|
+
...options,
|
|
97
|
+
executionId: this.id,
|
|
98
|
+
configIndex: this.options.configIndex
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A function to copy the context and update the fields for a specific environment
|
|
103
|
+
*
|
|
104
|
+
* @param environment - The environment configuration to use.
|
|
105
|
+
* @returns A new context instance with the updated environment.
|
|
106
|
+
*/
|
|
107
|
+
async createEnvironment(environment) {
|
|
108
|
+
const context = await PowerlinesEnvironmentContext.from(this, deepClone(this.options), deepClone(this.config), deepClone(this.overriddenConfig));
|
|
109
|
+
context.tsconfig = this.tsconfig;
|
|
110
|
+
context.system = this.system;
|
|
111
|
+
context.dependencies = deepClone(this.dependencies);
|
|
112
|
+
context.devDependencies = deepClone(this.devDependencies);
|
|
113
|
+
context.persistedMeta = deepClone(this.persistedMeta);
|
|
114
|
+
context.resolvePatterns = deepClone(this.resolvePatterns);
|
|
115
|
+
context.powerlinesPath ??= this.powerlinesPath;
|
|
116
|
+
context.resolver ??= this.resolver;
|
|
117
|
+
await context.setEnvironmentConfig(deepClone(environment));
|
|
118
|
+
context.plugins = [];
|
|
119
|
+
for (const plugin of this.plugins) await context.unstable_addPlugin(plugin);
|
|
120
|
+
for (const [key, value] of Object.entries(this)) if (![
|
|
121
|
+
"fs",
|
|
122
|
+
"system",
|
|
123
|
+
"options",
|
|
124
|
+
"config",
|
|
125
|
+
"inlineConfig",
|
|
126
|
+
"userConfig",
|
|
127
|
+
"pluginConfig",
|
|
128
|
+
"overriddenConfig",
|
|
129
|
+
"environmentConfig",
|
|
130
|
+
"dependencies",
|
|
131
|
+
"devDependencies",
|
|
132
|
+
"persistedMeta",
|
|
133
|
+
"packageJson",
|
|
134
|
+
"projectJson",
|
|
135
|
+
"tsconfig",
|
|
136
|
+
"resolver",
|
|
137
|
+
"plugins",
|
|
138
|
+
"environments"
|
|
139
|
+
].includes(key)) if (isObject(value) || Array.isArray(value)) context[key] = deepClone(value);
|
|
140
|
+
else context[key] = value;
|
|
141
|
+
return context;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Update the context using a new inline configuration options
|
|
145
|
+
*/
|
|
146
|
+
async resolveConfig() {
|
|
147
|
+
await super.resolveConfig();
|
|
148
|
+
await Promise.all(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) => {
|
|
149
|
+
this.#environments[env.name] = await this.createEnvironment(env);
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get an environment by name, or the default environment if no name is provided
|
|
154
|
+
*
|
|
155
|
+
* @param name - The name of the environment to retrieve.
|
|
156
|
+
* @returns The requested environment context.
|
|
157
|
+
*/
|
|
158
|
+
async getEnvironment(name) {
|
|
159
|
+
let environment;
|
|
160
|
+
if (name) environment = this.environments[name];
|
|
161
|
+
if (Object.keys(this.environments).length === 1) {
|
|
162
|
+
environment = this.environments[Object.keys(this.environments)[0]];
|
|
163
|
+
this.trace({
|
|
164
|
+
meta: { category: "plugins" },
|
|
165
|
+
message: `Applying the only configured environment: ${chalk.bold.cyanBright(environment?.config.environment?.name)}`
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (!environment) {
|
|
169
|
+
if (name) throw new Error(`Environment "${name}" not found.`);
|
|
170
|
+
environment = await this.createEnvironment(createDefaultEnvironment(this.config));
|
|
171
|
+
this.warn({
|
|
172
|
+
meta: { category: "plugins" },
|
|
173
|
+
message: `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.bold.cyanBright(environment.config.environment?.name)}`
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return environment;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A safe version of `getEnvironment` that returns `undefined` if the environment is not found
|
|
180
|
+
*
|
|
181
|
+
* @param name - The name of the environment to retrieve.
|
|
182
|
+
* @returns The requested environment context or `undefined` if not found.
|
|
183
|
+
*/
|
|
184
|
+
async getEnvironmentSafe(name) {
|
|
185
|
+
try {
|
|
186
|
+
return await this.getEnvironment(name);
|
|
187
|
+
} catch {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* A function to merge all configured environments into a single context.
|
|
193
|
+
*
|
|
194
|
+
* @remarks
|
|
195
|
+
* If only one environment is configured, that environment will be returned directly.
|
|
196
|
+
*
|
|
197
|
+
* @returns A promise that resolves to a merged/global environment context.
|
|
198
|
+
*/
|
|
199
|
+
async toEnvironment() {
|
|
200
|
+
let environment;
|
|
201
|
+
if (Object.keys(this.environments).length > 1) {
|
|
202
|
+
environment = await this.createEnvironment(createEnvironment(GLOBAL_ENVIRONMENT, this.config));
|
|
203
|
+
this.debug({
|
|
204
|
+
meta: { category: "plugins" },
|
|
205
|
+
message: `Combined all ${Object.keys(this.environments).length} environments into a single global context.`
|
|
206
|
+
});
|
|
207
|
+
} else environment = await this.getEnvironment();
|
|
208
|
+
return environment;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A function used internally to add a plugin to the context and update the configuration options
|
|
212
|
+
*
|
|
213
|
+
* @danger
|
|
214
|
+
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
215
|
+
*
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
async unstable_addPlugin(plugin) {
|
|
219
|
+
this.plugins.push(...await resolvePlugins(this, plugin, { skipLogging: Object.keys(this.environments).filter((key) => key !== "default" && key !== "__global__").length > 0 }));
|
|
220
|
+
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
221
|
+
await this.environments[name].unstable_addPlugin(plugin);
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
//#endregion
|
|
227
|
+
export { PowerlinesExecutionContext };
|
|
228
|
+
//# sourceMappingURL=execution-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.mjs","names":["#environments","#plugins"],"sources":["../../src/context/execution-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 { toArray } from \"@stryke/convert/to-array\";\nimport { existsSync } from \"@stryke/fs/exists\";\nimport { readJsonFile } from \"@stryke/fs/json\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { PackageJson } from \"@stryke/types/package-json\";\nimport chalk from \"chalk\";\nimport {\n DEFAULT_ENVIRONMENT,\n GLOBAL_ENVIRONMENT\n} from \"../constants/environments\";\nimport {\n createDefaultEnvironment,\n createEnvironment\n} from \"../lib/environment\";\nimport { resolvePlugins } from \"../lib/plugins\";\nimport type {\n EnvironmentResolvedConfig,\n ExecutionContext,\n ExecutionOptions,\n InferOverridableConfig,\n Logger,\n LoggerOptions,\n Plugin,\n PluginConfig,\n PluginContext,\n ResolvedConfig\n} from \"../types\";\nimport { PowerlinesContext } from \"./context\";\nimport { PowerlinesEnvironmentContext } from \"./environment-context\";\n\nexport class PowerlinesExecutionContext<\n TResolvedConfig extends ResolvedConfig = ResolvedConfig,\n TSystemContext = unknown\n>\n extends PowerlinesContext<TResolvedConfig, TSystemContext>\n implements ExecutionContext<TResolvedConfig, TSystemContext>\n{\n /**\n * A record of all environments by name\n */\n #environments: Record<\n string,\n PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>\n > = {};\n\n /**\n * 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.\n */\n #plugins: Plugin<PluginContext<TResolvedConfig, TSystemContext>>[] = [];\n\n /**\n * Create a new Storm context from the workspace root and user config.\n *\n * @param options - The execution options to create the context with.\n * @param inlineConfig - The inline configuration for the context.\n * @returns A promise that resolves to the new context.\n */\n public static async from<\n TResolvedConfig extends ResolvedConfig = ResolvedConfig,\n TSystemContext = unknown\n >(\n options: ExecutionOptions,\n inlineConfig?: TResolvedConfig[\"inlineConfig\"],\n system?: TSystemContext\n ): Promise<PowerlinesExecutionContext<TResolvedConfig, TSystemContext>> {\n const context = new PowerlinesExecutionContext<\n TResolvedConfig,\n TSystemContext\n >(options);\n if (system) {\n context.system = system;\n }\n\n await context.init();\n\n if (inlineConfig) {\n await context.setInlineConfig(inlineConfig);\n }\n\n return context;\n }\n\n /**\n * 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.\n */\n public get id(): string {\n return this.options.executionId;\n }\n\n /**\n * A record of all environments by name\n */\n public get environments(): Record<\n string,\n PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>\n > {\n return this.#environments;\n }\n\n public get plugins(): Array<\n Plugin<PluginContext<TResolvedConfig, TSystemContext>>\n > {\n return this.#plugins;\n }\n\n /**\n * Creates a new instance.\n *\n * @param options - The options to use for creating the context, including the resolved configuration and workspace settings.\n */\n protected constructor(options: ExecutionOptions) {\n super(options);\n }\n\n /**\n * 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.\n *\n * @param config - The inline configuration values to set.\n * @returns A promise that resolves when the inline configuration values have been set.\n */\n public override async setInlineConfig(\n config: TResolvedConfig[\"inlineConfig\"]\n ): Promise<void> {\n await super.setInlineConfig(config);\n if (this.inlineConfig.command === \"new\") {\n const workspacePackageJsonPath = joinPaths(this.cwd, \"package.json\");\n if (!existsSync(workspacePackageJsonPath)) {\n throw new Error(\n `The workspace package.json file could not be found at ${workspacePackageJsonPath}`\n );\n }\n\n this.packageJson = await readJsonFile<PackageJson>(\n workspacePackageJsonPath\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 * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.\n */\n public override createLogger(options: LoggerOptions): Logger {\n return super.createLogger({\n ...options,\n executionId: this.id,\n configIndex: this.options.configIndex\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 override extendLogger(options: LoggerOptions): Logger {\n return super.extendLogger({\n ...options,\n executionId: this.id,\n configIndex: this.options.configIndex\n });\n }\n\n /**\n * A function to copy the context and update the fields for a specific environment\n *\n * @param environment - The environment configuration to use.\n * @returns A new context instance with the updated environment.\n */\n public async createEnvironment(\n environment: EnvironmentResolvedConfig<TResolvedConfig>[\"environment\"]\n ): Promise<PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>> {\n const context = await PowerlinesEnvironmentContext.from<\n TResolvedConfig,\n TSystemContext\n >(\n this,\n deepClone(this.options),\n deepClone(this.config) as TResolvedConfig,\n deepClone(this.overriddenConfig) as InferOverridableConfig<\n EnvironmentResolvedConfig<TResolvedConfig>\n >\n );\n\n context.tsconfig = this.tsconfig;\n context.system = this.system;\n\n context.dependencies = deepClone<typeof this.dependencies>(\n this.dependencies\n );\n context.devDependencies = deepClone<typeof this.devDependencies>(\n this.devDependencies\n );\n context.persistedMeta = deepClone<typeof this.persistedMeta>(\n this.persistedMeta\n );\n context.resolvePatterns = deepClone<typeof this.resolvePatterns>(\n this.resolvePatterns\n );\n\n context.powerlinesPath ??= this.powerlinesPath;\n context.resolver ??= this.resolver;\n\n await context.setEnvironmentConfig(\n deepClone(\n environment\n ) as EnvironmentResolvedConfig<TResolvedConfig>[\"environment\"]\n );\n\n context.plugins = [];\n for (const plugin of this.plugins) {\n await context.unstable_addPlugin(plugin);\n }\n\n for (const [key, value] of Object.entries(this)) {\n if (\n ![\n \"fs\",\n \"system\",\n \"options\",\n \"config\",\n \"inlineConfig\",\n \"userConfig\",\n \"pluginConfig\",\n \"overriddenConfig\",\n \"environmentConfig\",\n \"dependencies\",\n \"devDependencies\",\n \"persistedMeta\",\n \"packageJson\",\n \"projectJson\",\n \"tsconfig\",\n \"resolver\",\n \"plugins\",\n \"environments\"\n ].includes(key)\n ) {\n if (isObject(value) || Array.isArray(value)) {\n (context as any)[key] = deepClone(value);\n } else {\n (context as any)[key] = value;\n }\n }\n }\n\n return context;\n }\n\n /**\n * Update the context using a new inline configuration options\n */\n public override async resolveConfig() {\n await super.resolveConfig();\n\n await Promise.all(\n toArray(\n this.config.environments &&\n Object.keys(this.config.environments).length > 0\n ? Object.keys(this.config.environments).map(name =>\n createEnvironment(name, this.config)\n )\n : createDefaultEnvironment(this.config)\n ).map(async env => {\n this.#environments[env.name] = await this.createEnvironment(env);\n })\n );\n }\n\n /**\n * Get an environment by name, or the default environment if no name is provided\n *\n * @param name - The name of the environment to retrieve.\n * @returns The requested environment context.\n */\n public async getEnvironment(name?: string) {\n let environment:\n | PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>\n | undefined;\n if (name) {\n environment = this.environments[name];\n }\n\n if (Object.keys(this.environments).length === 1) {\n environment = this.environments[Object.keys(this.environments)[0]!];\n\n this.trace({\n meta: { category: \"plugins\" },\n message: `Applying the only configured environment: ${chalk.bold.cyanBright(\n environment?.config.environment?.name\n )}`\n });\n }\n\n if (!environment) {\n if (name) {\n throw new Error(`Environment \"${name}\" not found.`);\n }\n\n environment = await this.createEnvironment(\n createDefaultEnvironment(this.config)\n );\n\n // environment = await PowerlinesEnvironmentContext.from<TResolvedConfig>(\n // deepClone(this.options),\n // deepClone(this.config) as TResolvedConfig,\n // deepClone(this.overriddenConfig) as InferOverridableConfig<\n // EnvironmentResolvedConfig<TResolvedConfig>\n // >,\n // deepClone(\n // createDefaultEnvironment(this.config)\n // ) as EnvironmentResolvedConfig<TResolvedConfig>[\"environment\"]\n // );\n\n // environment.plugins = [];\n // for (const plugin of this.plugins) {\n // await environment.addPlugin(plugin);\n // }\n\n this.warn({\n meta: { category: \"plugins\" },\n message: `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.bold.cyanBright(\n environment.config.environment?.name\n )}`\n });\n }\n\n return environment;\n }\n\n /**\n * A safe version of `getEnvironment` that returns `undefined` if the environment is not found\n *\n * @param name - The name of the environment to retrieve.\n * @returns The requested environment context or `undefined` if not found.\n */\n public async getEnvironmentSafe(\n name?: string\n ): Promise<\n PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext> | undefined\n > {\n try {\n return await this.getEnvironment(name);\n } catch {\n return undefined;\n }\n }\n\n /**\n * A function to merge all configured environments into a single context.\n *\n * @remarks\n * If only one environment is configured, that environment will be returned directly.\n *\n * @returns A promise that resolves to a merged/global environment context.\n */\n public async toEnvironment(): Promise<\n PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>\n > {\n let environment: PowerlinesEnvironmentContext<\n TResolvedConfig,\n TSystemContext\n >;\n if (Object.keys(this.environments).length > 1) {\n environment = await this.createEnvironment(\n createEnvironment<TResolvedConfig>(GLOBAL_ENVIRONMENT, this.config)\n );\n\n this.debug({\n meta: { category: \"plugins\" },\n message: `Combined all ${Object.keys(this.environments).length} environments into a single global context.`\n });\n } else {\n environment = await this.getEnvironment();\n }\n\n return environment;\n }\n\n /**\n * A function used internally to add a plugin to the context and update the configuration options\n *\n * @danger\n * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.\n *\n * @internal\n */\n public async unstable_addPlugin(\n plugin: PluginConfig<PluginContext<TResolvedConfig, TSystemContext>>\n ) {\n this.plugins.push(\n ...(await resolvePlugins<TResolvedConfig, TSystemContext>(this, plugin, {\n skipLogging:\n Object.keys(this.environments).filter(\n key => key !== DEFAULT_ENVIRONMENT && key !== GLOBAL_ENVIRONMENT\n ).length > 0\n }))\n );\n\n await Promise.all(\n Object.keys(this.environments).map(async name => {\n await this.environments[name]!.unstable_addPlugin(plugin);\n })\n );\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_context_base_context = require('./base-context.cjs');
|
|
3
|
+
const require_context_context = require('./context.cjs');
|
|
4
|
+
const require_context_plugin_context = require('./plugin-context.cjs');
|
|
5
|
+
const require_context_environment_context = require('./environment-context.cjs');
|
|
6
|
+
const require_context_execution_context = require('./execution-context.cjs');
|
|
7
|
+
|
|
8
|
+
exports.PowerlinesBaseContext = require_context_base_context.PowerlinesBaseContext;
|
|
9
|
+
exports.PowerlinesContext = require_context_context.PowerlinesContext;
|
|
10
|
+
exports.PowerlinesEnvironmentContext = require_context_environment_context.PowerlinesEnvironmentContext;
|
|
11
|
+
exports.PowerlinesExecutionContext = require_context_execution_context.PowerlinesExecutionContext;
|
|
12
|
+
exports.createPluginContext = require_context_plugin_context.createPluginContext;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PowerlinesBaseContext } from "./base-context.cjs";
|
|
2
|
+
import { PowerlinesContext } from "./context.cjs";
|
|
3
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.cjs";
|
|
4
|
+
import { PowerlinesExecutionContext } from "./execution-context.cjs";
|
|
5
|
+
import { createPluginContext } from "./plugin-context.cjs";
|
|
6
|
+
export { PowerlinesBaseContext, PowerlinesContext, PowerlinesEnvironmentContext, PowerlinesExecutionContext, createPluginContext };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PowerlinesBaseContext } from "./base-context.mjs";
|
|
2
|
+
import { PowerlinesContext } from "./context.mjs";
|
|
3
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.mjs";
|
|
4
|
+
import { PowerlinesExecutionContext } from "./execution-context.mjs";
|
|
5
|
+
import { createPluginContext } from "./plugin-context.mjs";
|
|
6
|
+
export { PowerlinesBaseContext, PowerlinesContext, PowerlinesEnvironmentContext, PowerlinesExecutionContext, createPluginContext };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PowerlinesBaseContext } from "./base-context.mjs";
|
|
2
|
+
import { PowerlinesContext } from "./context.mjs";
|
|
3
|
+
import { createPluginContext } from "./plugin-context.mjs";
|
|
4
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.mjs";
|
|
5
|
+
import { PowerlinesExecutionContext } from "./execution-context.mjs";
|
|
6
|
+
|
|
7
|
+
export { PowerlinesBaseContext, PowerlinesContext, PowerlinesEnvironmentContext, PowerlinesExecutionContext, createPluginContext };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
4
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
5
|
+
|
|
6
|
+
//#region src/context/plugin-context.ts
|
|
7
|
+
/**
|
|
8
|
+
* Create a Proxy-based PluginContext
|
|
9
|
+
*
|
|
10
|
+
* @param pluginId - The unique identifier of the plugin
|
|
11
|
+
* @param plugin - The plugin instance
|
|
12
|
+
* @param environment - The environment context
|
|
13
|
+
* @returns The proxied plugin context
|
|
14
|
+
*/
|
|
15
|
+
function createPluginContext(pluginId, plugin, environment) {
|
|
16
|
+
const logger = environment.extendLogger({ plugin: plugin.name });
|
|
17
|
+
const normalizeMessage = (message) => {
|
|
18
|
+
return {
|
|
19
|
+
meta: {
|
|
20
|
+
...(0, _stryke_type_checks_is_set_object.isSetObject)(message) ? message.meta : {},
|
|
21
|
+
environment: environment.config.environment.name,
|
|
22
|
+
plugin: plugin.name
|
|
23
|
+
},
|
|
24
|
+
message: (0, _stryke_type_checks_is_string.isString)(message) ? message : message.message
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
return new Proxy({}, {
|
|
28
|
+
get(_, prop) {
|
|
29
|
+
if (prop === "environment") return environment;
|
|
30
|
+
if (prop === "id") return pluginId;
|
|
31
|
+
if (prop === "logger") return logger;
|
|
32
|
+
if (prop === "log") return (type, message) => {
|
|
33
|
+
logger.log(type, normalizeMessage(message));
|
|
34
|
+
};
|
|
35
|
+
if (prop === "fatal") return (message) => {
|
|
36
|
+
logger.error(normalizeMessage(message));
|
|
37
|
+
};
|
|
38
|
+
if (prop === "error") return (message) => {
|
|
39
|
+
logger.error(normalizeMessage(message));
|
|
40
|
+
};
|
|
41
|
+
if (prop === "warn") return (message) => {
|
|
42
|
+
logger.warn(normalizeMessage(message));
|
|
43
|
+
};
|
|
44
|
+
if (prop === "info") return (message) => {
|
|
45
|
+
logger.info(normalizeMessage(message));
|
|
46
|
+
};
|
|
47
|
+
if (prop === "debug") return (message) => {
|
|
48
|
+
logger.debug(normalizeMessage(message));
|
|
49
|
+
};
|
|
50
|
+
if (prop === "trace") return (message) => {
|
|
51
|
+
logger.trace(normalizeMessage(message));
|
|
52
|
+
};
|
|
53
|
+
return environment[prop];
|
|
54
|
+
},
|
|
55
|
+
set(_, prop, value) {
|
|
56
|
+
if (prop === "unstable_addPlugin") {
|
|
57
|
+
logger.warn("Plugins should not be calling the 'addPlugin' function directly. This function is meant to be used internally by Powerlines and may cause unexpected behavior if used incorrectly.");
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if ([
|
|
61
|
+
"id",
|
|
62
|
+
"environment",
|
|
63
|
+
"config",
|
|
64
|
+
"log",
|
|
65
|
+
"logger",
|
|
66
|
+
"error",
|
|
67
|
+
"warn",
|
|
68
|
+
"plugins",
|
|
69
|
+
"hooks",
|
|
70
|
+
"fs",
|
|
71
|
+
"selectHooks"
|
|
72
|
+
].includes(prop)) {
|
|
73
|
+
logger.warn(`Cannot set the read-only "${String(prop)}" property`);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
environment[prop] = value;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
exports.createPluginContext = createPluginContext;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Plugin } from "../types/plugin.cjs";
|
|
2
|
+
import { PluginContext } from "../types/context.cjs";
|
|
3
|
+
import { ResolvedConfig } from "../types/config.cjs";
|
|
4
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.cjs";
|
|
5
|
+
|
|
6
|
+
//#region src/context/plugin-context.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Create a Proxy-based PluginContext
|
|
9
|
+
*
|
|
10
|
+
* @param pluginId - The unique identifier of the plugin
|
|
11
|
+
* @param plugin - The plugin instance
|
|
12
|
+
* @param environment - The environment context
|
|
13
|
+
* @returns The proxied plugin context
|
|
14
|
+
*/
|
|
15
|
+
declare function createPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig, TSystemContext = unknown>(pluginId: string, plugin: Plugin<PluginContext<TResolvedConfig, TSystemContext>>, environment: PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>): PluginContext<TResolvedConfig, TSystemContext>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createPluginContext };
|
|
18
|
+
//# sourceMappingURL=plugin-context.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-context.d.cts","names":[],"sources":["../../src/context/plugin-context.ts"],"mappings":";;;;;;;;;;;AAuCA;;;iBAAgB,mBAAA,yBACU,cAAA,GAAiB,cAAA,2BAAA,CAGzC,QAAA,UACA,MAAA,EAAQ,MAAA,CAAO,aAAA,CAAc,eAAA,EAAiB,cAAA,IAC9C,WAAA,EAAa,4BAAA,CAA6B,eAAA,EAAiB,cAAA,IAC1D,aAAA,CAAc,eAAA,EAAiB,cAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Plugin } from "../types/plugin.mjs";
|
|
2
|
+
import { PluginContext } from "../types/context.mjs";
|
|
3
|
+
import { ResolvedConfig } from "../types/config.mjs";
|
|
4
|
+
import { PowerlinesEnvironmentContext } from "./environment-context.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/context/plugin-context.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Create a Proxy-based PluginContext
|
|
9
|
+
*
|
|
10
|
+
* @param pluginId - The unique identifier of the plugin
|
|
11
|
+
* @param plugin - The plugin instance
|
|
12
|
+
* @param environment - The environment context
|
|
13
|
+
* @returns The proxied plugin context
|
|
14
|
+
*/
|
|
15
|
+
declare function createPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig, TSystemContext = unknown>(pluginId: string, plugin: Plugin<PluginContext<TResolvedConfig, TSystemContext>>, environment: PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>): PluginContext<TResolvedConfig, TSystemContext>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createPluginContext };
|
|
18
|
+
//# sourceMappingURL=plugin-context.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-context.d.mts","names":[],"sources":["../../src/context/plugin-context.ts"],"mappings":";;;;;;;;;;;AAuCA;;;iBAAgB,mBAAA,yBACU,cAAA,GAAiB,cAAA,2BAAA,CAGzC,QAAA,UACA,MAAA,EAAQ,MAAA,CAAO,aAAA,CAAc,eAAA,EAAiB,cAAA,IAC9C,WAAA,EAAa,4BAAA,CAA6B,eAAA,EAAiB,cAAA,IAC1D,aAAA,CAAc,eAAA,EAAiB,cAAA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
2
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
3
|
+
|
|
4
|
+
//#region src/context/plugin-context.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a Proxy-based PluginContext
|
|
7
|
+
*
|
|
8
|
+
* @param pluginId - The unique identifier of the plugin
|
|
9
|
+
* @param plugin - The plugin instance
|
|
10
|
+
* @param environment - The environment context
|
|
11
|
+
* @returns The proxied plugin context
|
|
12
|
+
*/
|
|
13
|
+
function createPluginContext(pluginId, plugin, environment) {
|
|
14
|
+
const logger = environment.extendLogger({ plugin: plugin.name });
|
|
15
|
+
const normalizeMessage = (message) => {
|
|
16
|
+
return {
|
|
17
|
+
meta: {
|
|
18
|
+
...isSetObject(message) ? message.meta : {},
|
|
19
|
+
environment: environment.config.environment.name,
|
|
20
|
+
plugin: plugin.name
|
|
21
|
+
},
|
|
22
|
+
message: isString(message) ? message : message.message
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
return new Proxy({}, {
|
|
26
|
+
get(_, prop) {
|
|
27
|
+
if (prop === "environment") return environment;
|
|
28
|
+
if (prop === "id") return pluginId;
|
|
29
|
+
if (prop === "logger") return logger;
|
|
30
|
+
if (prop === "log") return (type, message) => {
|
|
31
|
+
logger.log(type, normalizeMessage(message));
|
|
32
|
+
};
|
|
33
|
+
if (prop === "fatal") return (message) => {
|
|
34
|
+
logger.error(normalizeMessage(message));
|
|
35
|
+
};
|
|
36
|
+
if (prop === "error") return (message) => {
|
|
37
|
+
logger.error(normalizeMessage(message));
|
|
38
|
+
};
|
|
39
|
+
if (prop === "warn") return (message) => {
|
|
40
|
+
logger.warn(normalizeMessage(message));
|
|
41
|
+
};
|
|
42
|
+
if (prop === "info") return (message) => {
|
|
43
|
+
logger.info(normalizeMessage(message));
|
|
44
|
+
};
|
|
45
|
+
if (prop === "debug") return (message) => {
|
|
46
|
+
logger.debug(normalizeMessage(message));
|
|
47
|
+
};
|
|
48
|
+
if (prop === "trace") return (message) => {
|
|
49
|
+
logger.trace(normalizeMessage(message));
|
|
50
|
+
};
|
|
51
|
+
return environment[prop];
|
|
52
|
+
},
|
|
53
|
+
set(_, prop, value) {
|
|
54
|
+
if (prop === "unstable_addPlugin") {
|
|
55
|
+
logger.warn("Plugins should not be calling the 'addPlugin' function directly. This function is meant to be used internally by Powerlines and may cause unexpected behavior if used incorrectly.");
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if ([
|
|
59
|
+
"id",
|
|
60
|
+
"environment",
|
|
61
|
+
"config",
|
|
62
|
+
"log",
|
|
63
|
+
"logger",
|
|
64
|
+
"error",
|
|
65
|
+
"warn",
|
|
66
|
+
"plugins",
|
|
67
|
+
"hooks",
|
|
68
|
+
"fs",
|
|
69
|
+
"selectHooks"
|
|
70
|
+
].includes(prop)) {
|
|
71
|
+
logger.warn(`Cannot set the read-only "${String(prop)}" property`);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
environment[prop] = value;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { createPluginContext };
|
|
82
|
+
//# sourceMappingURL=plugin-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-context.mjs","names":[],"sources":["../../src/context/plugin-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 { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { UnpluginMessage } from \"unplugin\";\nimport type {\n EnvironmentContext,\n LoggerMessage,\n LogLevel,\n Plugin,\n PluginContext,\n ResolvedConfig\n} from \"../types\";\nimport { PowerlinesEnvironmentContext } from \"./environment-context\";\n\n/**\n * Create a Proxy-based PluginContext\n *\n * @param pluginId - The unique identifier of the plugin\n * @param plugin - The plugin instance\n * @param environment - The environment context\n * @returns The proxied plugin context\n */\nexport function createPluginContext<\n TResolvedConfig extends ResolvedConfig = ResolvedConfig,\n TSystemContext = unknown\n>(\n pluginId: string,\n plugin: Plugin<PluginContext<TResolvedConfig, TSystemContext>>,\n environment: PowerlinesEnvironmentContext<TResolvedConfig, TSystemContext>\n): PluginContext<TResolvedConfig, TSystemContext> {\n const logger = environment.extendLogger({\n plugin: plugin.name\n });\n\n const normalizeMessage = (\n message: string | UnpluginMessage\n ): LoggerMessage => {\n return {\n meta: {\n ...(isSetObject(message) ? message.meta : {}),\n environment: environment.config.environment.name,\n plugin: plugin.name\n },\n message: isString(message) ? message : message.message\n };\n };\n\n return new Proxy({} as PluginContext<TResolvedConfig, TSystemContext>, {\n get(_, prop) {\n if (prop === \"environment\") {\n return environment;\n }\n\n if (prop === \"id\") {\n return pluginId;\n }\n\n if (prop === \"logger\") {\n return logger;\n }\n\n if (prop === \"log\") {\n return (type: LogLevel, message: string | UnpluginMessage) => {\n logger.log(type, normalizeMessage(message));\n };\n }\n\n if (prop === \"fatal\") {\n return (message: string | UnpluginMessage) => {\n logger.error(normalizeMessage(message));\n };\n }\n\n if (prop === \"error\") {\n return (message: string | UnpluginMessage) => {\n logger.error(normalizeMessage(message));\n };\n }\n\n if (prop === \"warn\") {\n return (message: string | UnpluginMessage) => {\n logger.warn(normalizeMessage(message));\n };\n }\n\n if (prop === \"info\") {\n return (message: string | UnpluginMessage) => {\n logger.info(normalizeMessage(message));\n };\n }\n\n if (prop === \"debug\") {\n return (message: string | UnpluginMessage) => {\n logger.debug(normalizeMessage(message));\n };\n }\n\n if (prop === \"trace\") {\n return (message: string | UnpluginMessage) => {\n logger.trace(normalizeMessage(message));\n };\n }\n\n return environment[\n prop as keyof EnvironmentContext<TResolvedConfig, TSystemContext>\n ];\n },\n set(_, prop, value) {\n if (prop === \"unstable_addPlugin\") {\n logger.warn(\n \"Plugins should not be calling the 'addPlugin' function directly. This function is meant to be used internally by Powerlines and may cause unexpected behavior if used incorrectly.\"\n );\n return false;\n }\n\n if (\n [\n \"id\",\n \"environment\",\n \"config\",\n \"log\",\n \"logger\",\n \"error\",\n \"warn\",\n \"plugins\",\n \"hooks\",\n \"fs\",\n \"selectHooks\"\n ].includes(prop as string)\n ) {\n logger.warn(`Cannot set the read-only \"${String(prop)}\" property`);\n\n return false;\n }\n\n (environment as Record<string, any>)[prop as string] = value;\n return true;\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,SAAgB,oBAId,UACA,QACA,aACgD;CAChD,MAAM,SAAS,YAAY,aAAa,EACtC,QAAQ,OAAO,MAChB,CAAC;CAEF,MAAM,oBACJ,YACkB;AAClB,SAAO;GACL,MAAM;IACJ,GAAI,YAAY,QAAQ,GAAG,QAAQ,OAAO,EAAE;IAC5C,aAAa,YAAY,OAAO,YAAY;IAC5C,QAAQ,OAAO;IAChB;GACD,SAAS,SAAS,QAAQ,GAAG,UAAU,QAAQ;GAChD;;AAGH,QAAO,IAAI,MAAM,EAAE,EAAoD;EACrE,IAAI,GAAG,MAAM;AACX,OAAI,SAAS,cACX,QAAO;AAGT,OAAI,SAAS,KACX,QAAO;AAGT,OAAI,SAAS,SACX,QAAO;AAGT,OAAI,SAAS,MACX,SAAQ,MAAgB,YAAsC;AAC5D,WAAO,IAAI,MAAM,iBAAiB,QAAQ,CAAC;;AAI/C,OAAI,SAAS,QACX,SAAQ,YAAsC;AAC5C,WAAO,MAAM,iBAAiB,QAAQ,CAAC;;AAI3C,OAAI,SAAS,QACX,SAAQ,YAAsC;AAC5C,WAAO,MAAM,iBAAiB,QAAQ,CAAC;;AAI3C,OAAI,SAAS,OACX,SAAQ,YAAsC;AAC5C,WAAO,KAAK,iBAAiB,QAAQ,CAAC;;AAI1C,OAAI,SAAS,OACX,SAAQ,YAAsC;AAC5C,WAAO,KAAK,iBAAiB,QAAQ,CAAC;;AAI1C,OAAI,SAAS,QACX,SAAQ,YAAsC;AAC5C,WAAO,MAAM,iBAAiB,QAAQ,CAAC;;AAI3C,OAAI,SAAS,QACX,SAAQ,YAAsC;AAC5C,WAAO,MAAM,iBAAiB,QAAQ,CAAC;;AAI3C,UAAO,YACL;;EAGJ,IAAI,GAAG,MAAM,OAAO;AAClB,OAAI,SAAS,sBAAsB;AACjC,WAAO,KACL,qLACD;AACD,WAAO;;AAGT,OACE;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD,CAAC,SAAS,KAAe,EAC1B;AACA,WAAO,KAAK,6BAA6B,OAAO,KAAK,CAAC,YAAY;AAElE,WAAO;;AAGT,GAAC,YAAoC,QAAkB;AACvD,UAAO;;EAEV,CAAC"}
|