@powerlines/core 0.15.0 → 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,57 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_constants_meta = require('../constants/meta.cjs');
|
|
4
|
+
require('../constants/index.cjs');
|
|
5
|
+
let _stryke_fs_exists = require("@stryke/fs/exists");
|
|
6
|
+
let _stryke_fs_json = require("@stryke/fs/json");
|
|
7
|
+
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
8
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
9
|
+
let _stryke_fs_remove_file = require("@stryke/fs/remove-file");
|
|
10
|
+
|
|
11
|
+
//#region src/lib/meta.ts
|
|
12
|
+
/**
|
|
13
|
+
* Generates a prefixed project root hash object.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This function returns a string where the project root hash is prefixed with the project name plus a hyphen. If the total length of this string combination exceeds 45 characters, it will truncate the hash.
|
|
17
|
+
*
|
|
18
|
+
* @param name - The name of the project.
|
|
19
|
+
* @param rootHash - The hash of the project root.
|
|
20
|
+
* @returns An object containing the name and project root hash.
|
|
21
|
+
*/
|
|
22
|
+
function getPrefixedRootHash(name, rootHash) {
|
|
23
|
+
const combined = `${(0, _stryke_string_format_kebab_case.kebabCase)(name)}_${rootHash}`;
|
|
24
|
+
return combined.length > 45 ? combined.slice(0, 45) : combined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the persisted meta information from the context's data path.
|
|
28
|
+
*
|
|
29
|
+
* @param context - The build context.
|
|
30
|
+
* @returns A promise that resolves to the persisted meta information, or undefined if not found.
|
|
31
|
+
*/
|
|
32
|
+
async function getPersistedMeta(context) {
|
|
33
|
+
const metaFilePath = (0, _stryke_path_join_paths.joinPaths)(context.dataPath, "meta.json");
|
|
34
|
+
if ((0, _stryke_fs_exists.existsSync)(metaFilePath)) try {
|
|
35
|
+
return await (0, _stryke_fs_json.readJsonFile)(metaFilePath);
|
|
36
|
+
} catch {
|
|
37
|
+
context.warn(`Failed to read meta file at ${metaFilePath}. It may be corrupted.`);
|
|
38
|
+
await (0, _stryke_fs_remove_file.removeFile)(metaFilePath);
|
|
39
|
+
context.persistedMeta = void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Writes the meta file for the context.
|
|
44
|
+
*
|
|
45
|
+
* @param context - The context to write the meta file for.
|
|
46
|
+
* @returns A promise that resolves when the meta file has been written.
|
|
47
|
+
*/
|
|
48
|
+
async function writeMetaFile(context) {
|
|
49
|
+
const metaFilePath = (0, _stryke_path_join_paths.joinPaths)(context.dataPath, "meta.json");
|
|
50
|
+
context.debug(`Writing runtime metadata to ${metaFilePath}`);
|
|
51
|
+
await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
exports.getPersistedMeta = getPersistedMeta;
|
|
56
|
+
exports.getPrefixedRootHash = getPrefixedRootHash;
|
|
57
|
+
exports.writeMetaFile = writeMetaFile;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context, MetaInfo } from "../types/context.cjs";
|
|
2
|
+
//#region src/lib/meta.d.ts
|
|
3
|
+
interface CreateContextOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generates a prefixed project root hash object.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function returns a string where the project root hash is prefixed with the project name plus a hyphen. If the total length of this string combination exceeds 45 characters, it will truncate the hash.
|
|
11
|
+
*
|
|
12
|
+
* @param name - The name of the project.
|
|
13
|
+
* @param rootHash - The hash of the project root.
|
|
14
|
+
* @returns An object containing the name and project root hash.
|
|
15
|
+
*/
|
|
16
|
+
declare function getPrefixedRootHash(name: string, rootHash: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the persisted meta information from the context's data path.
|
|
19
|
+
*
|
|
20
|
+
* @param context - The build context.
|
|
21
|
+
* @returns A promise that resolves to the persisted meta information, or undefined if not found.
|
|
22
|
+
*/
|
|
23
|
+
declare function getPersistedMeta(context: Context): Promise<MetaInfo | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Writes the meta file for the context.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The context to write the meta file for.
|
|
28
|
+
* @returns A promise that resolves when the meta file has been written.
|
|
29
|
+
*/
|
|
30
|
+
declare function writeMetaFile(context: Context): Promise<void>;
|
|
31
|
+
declare type __ΩCreateContextOptions = any[];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { CreateContextOptions, __ΩCreateContextOptions, getPersistedMeta, getPrefixedRootHash, writeMetaFile };
|
|
34
|
+
//# sourceMappingURL=meta.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.cts","names":[],"sources":["../../src/lib/meta.ts"],"mappings":";;UA0BiB,oBAAA;EACf,IAAA;AAAA;AADF;;;;;AAcA;;;;;AAdA,iBAcgB,mBAAA,CAAoB,IAAA,UAAc,QAAA;;;;;;;iBAc5B,gBAAA,CACpB,OAAA,EAAS,OAAA,GACR,OAAA,CAAQ,QAAA;;;;;;;iBAwBW,aAAA,CAAc,OAAA,EAAS,OAAA,GAAU,OAAA;AAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context, MetaInfo } from "../types/context.mjs";
|
|
2
|
+
//#region src/lib/meta.d.ts
|
|
3
|
+
interface CreateContextOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generates a prefixed project root hash object.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function returns a string where the project root hash is prefixed with the project name plus a hyphen. If the total length of this string combination exceeds 45 characters, it will truncate the hash.
|
|
11
|
+
*
|
|
12
|
+
* @param name - The name of the project.
|
|
13
|
+
* @param rootHash - The hash of the project root.
|
|
14
|
+
* @returns An object containing the name and project root hash.
|
|
15
|
+
*/
|
|
16
|
+
declare function getPrefixedRootHash(name: string, rootHash: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the persisted meta information from the context's data path.
|
|
19
|
+
*
|
|
20
|
+
* @param context - The build context.
|
|
21
|
+
* @returns A promise that resolves to the persisted meta information, or undefined if not found.
|
|
22
|
+
*/
|
|
23
|
+
declare function getPersistedMeta(context: Context): Promise<MetaInfo | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Writes the meta file for the context.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The context to write the meta file for.
|
|
28
|
+
* @returns A promise that resolves when the meta file has been written.
|
|
29
|
+
*/
|
|
30
|
+
declare function writeMetaFile(context: Context): Promise<void>;
|
|
31
|
+
declare type __ΩCreateContextOptions = any[];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { CreateContextOptions, __ΩCreateContextOptions, getPersistedMeta, getPrefixedRootHash, writeMetaFile };
|
|
34
|
+
//# sourceMappingURL=meta.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.mts","names":[],"sources":["../../src/lib/meta.ts"],"mappings":";;UA0BiB,oBAAA;EACf,IAAA;AAAA;AADF;;;;;AAcA;;;;;AAdA,iBAcgB,mBAAA,CAAoB,IAAA,UAAc,QAAA;;;;;;;iBAc5B,gBAAA,CACpB,OAAA,EAAS,OAAA,GACR,OAAA,CAAQ,QAAA;;;;;;;iBAwBW,aAAA,CAAc,OAAA,EAAS,OAAA,GAAU,OAAA;AAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ROOT_HASH_LENGTH } from "../constants/meta.mjs";
|
|
2
|
+
import "../constants/index.mjs";
|
|
3
|
+
import { existsSync } from "@stryke/fs/exists";
|
|
4
|
+
import { readJsonFile } from "@stryke/fs/json";
|
|
5
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
6
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
7
|
+
import { removeFile } from "@stryke/fs/remove-file";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/meta.ts
|
|
10
|
+
/**
|
|
11
|
+
* Generates a prefixed project root hash object.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This function returns a string where the project root hash is prefixed with the project name plus a hyphen. If the total length of this string combination exceeds 45 characters, it will truncate the hash.
|
|
15
|
+
*
|
|
16
|
+
* @param name - The name of the project.
|
|
17
|
+
* @param rootHash - The hash of the project root.
|
|
18
|
+
* @returns An object containing the name and project root hash.
|
|
19
|
+
*/
|
|
20
|
+
function getPrefixedRootHash(name, rootHash) {
|
|
21
|
+
const combined = `${kebabCase(name)}_${rootHash}`;
|
|
22
|
+
return combined.length > 45 ? combined.slice(0, 45) : combined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the persisted meta information from the context's data path.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The build context.
|
|
28
|
+
* @returns A promise that resolves to the persisted meta information, or undefined if not found.
|
|
29
|
+
*/
|
|
30
|
+
async function getPersistedMeta(context) {
|
|
31
|
+
const metaFilePath = joinPaths(context.dataPath, "meta.json");
|
|
32
|
+
if (existsSync(metaFilePath)) try {
|
|
33
|
+
return await readJsonFile(metaFilePath);
|
|
34
|
+
} catch {
|
|
35
|
+
context.warn(`Failed to read meta file at ${metaFilePath}. It may be corrupted.`);
|
|
36
|
+
await removeFile(metaFilePath);
|
|
37
|
+
context.persistedMeta = void 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Writes the meta file for the context.
|
|
42
|
+
*
|
|
43
|
+
* @param context - The context to write the meta file for.
|
|
44
|
+
* @returns A promise that resolves when the meta file has been written.
|
|
45
|
+
*/
|
|
46
|
+
async function writeMetaFile(context) {
|
|
47
|
+
const metaFilePath = joinPaths(context.dataPath, "meta.json");
|
|
48
|
+
context.debug(`Writing runtime metadata to ${metaFilePath}`);
|
|
49
|
+
await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { getPersistedMeta, getPrefixedRootHash, writeMetaFile };
|
|
54
|
+
//# sourceMappingURL=meta.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.mjs","names":[],"sources":["../../src/lib/meta.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 { existsSync } from \"@stryke/fs/exists\";\nimport { readJsonFile } from \"@stryke/fs/json\";\nimport { removeFile } from \"@stryke/fs/remove-file\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { ROOT_HASH_LENGTH } from \"../constants\";\nimport type { Context, MetaInfo } from \"../types\";\n\nexport interface CreateContextOptions {\n name?: string;\n}\n\n/**\n * Generates a prefixed project root hash object.\n *\n * @remarks\n * This function returns a string where the project root hash is prefixed with the project name plus a hyphen. If the total length of this string combination exceeds 45 characters, it will truncate the hash.\n *\n * @param name - The name of the project.\n * @param rootHash - The hash of the project root.\n * @returns An object containing the name and project root hash.\n */\nexport function getPrefixedRootHash(name: string, rootHash: string): string {\n const combined = `${kebabCase(name)}_${rootHash}`;\n\n return combined.length > ROOT_HASH_LENGTH\n ? combined.slice(0, ROOT_HASH_LENGTH)\n : combined;\n}\n\n/**\n * Retrieves the persisted meta information from the context's data path.\n *\n * @param context - The build context.\n * @returns A promise that resolves to the persisted meta information, or undefined if not found.\n */\nexport async function getPersistedMeta(\n context: Context\n): Promise<MetaInfo | undefined> {\n const metaFilePath = joinPaths(context.dataPath, \"meta.json\");\n if (existsSync(metaFilePath)) {\n try {\n return await readJsonFile<MetaInfo>(metaFilePath);\n } catch {\n context.warn(\n `Failed to read meta file at ${metaFilePath}. It may be corrupted.`\n );\n await removeFile(metaFilePath);\n\n context.persistedMeta = undefined;\n }\n }\n\n return undefined;\n}\n\n/**\n * Writes the meta file for the context.\n *\n * @param context - The context to write the meta file for.\n * @returns A promise that resolves when the meta file has been written.\n */\nexport async function writeMetaFile(context: Context): Promise<void> {\n const metaFilePath = joinPaths(context.dataPath, \"meta.json\");\n\n context.debug(`Writing runtime metadata to ${metaFilePath}`);\n\n await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,oBAAoB,MAAc,UAA0B;CAC1E,MAAM,WAAW,GAAG,UAAU,KAAK,CAAC,GAAG;AAEvC,QAAO,SAAS,cACZ,SAAS,MAAM,MAAoB,GACnC;;;;;;;;AASN,eAAsB,iBACpB,SAC+B;CAC/B,MAAM,eAAe,UAAU,QAAQ,UAAU,YAAY;AAC7D,KAAI,WAAW,aAAa,CAC1B,KAAI;AACF,SAAO,MAAM,aAAuB,aAAa;SAC3C;AACN,UAAQ,KACN,+BAA+B,aAAa,wBAC7C;AACD,QAAM,WAAW,aAAa;AAE9B,UAAQ,gBAAgB;;;;;;;;;AAa9B,eAAsB,cAAc,SAAiC;CACnE,MAAM,eAAe,UAAU,QAAQ,UAAU,YAAY;AAE7D,SAAQ,MAAM,+BAA+B,eAAe;AAE5D,OAAM,QAAQ,GAAG,MAAM,cAAc,KAAK,UAAU,QAAQ,MAAM,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_plugin_utils_helpers = require('../plugin-utils/helpers.cjs');
|
|
4
|
+
require('../plugin-utils/index.cjs');
|
|
5
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
6
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
7
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
8
|
+
let chalk = require("chalk");
|
|
9
|
+
chalk = require_runtime.__toESM(chalk, 1);
|
|
10
|
+
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
11
|
+
let _stryke_path_join = require("@stryke/path/join");
|
|
12
|
+
let _stryke_fs_install = require("@stryke/fs/install");
|
|
13
|
+
let _stryke_fs_package_fns = require("@stryke/fs/package-fns");
|
|
14
|
+
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
15
|
+
let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
|
|
16
|
+
let _stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
|
|
17
|
+
|
|
18
|
+
//#region src/lib/plugins.ts
|
|
19
|
+
/**
|
|
20
|
+
* Resolve a plugin module based on the provided plugin path. This function checks if the plugin package is installed, attempts to import the plugin module, and handles various error cases such as missing packages or invalid module exports. It supports both direct plugin exports and plugins exported from a "plugin" subdirectory within the package.
|
|
21
|
+
*
|
|
22
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
23
|
+
* @param pluginPath - The path to the plugin module. This can be a package name, a scoped package name, or a path to a local module.
|
|
24
|
+
* @returns A promise that resolves to the plugin module, which can be a plugin instance, a factory function that returns a plugin, or an array of plugins.
|
|
25
|
+
*/
|
|
26
|
+
async function resolvePlugin(context, pluginPath) {
|
|
27
|
+
if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
|
|
28
|
+
const splits = pluginPath.split("/").filter(Boolean);
|
|
29
|
+
pluginPath = `${splits[0]}/${splits[1]}`;
|
|
30
|
+
}
|
|
31
|
+
const isInstalled = (0, _stryke_fs_package_fns.isPackageExists)(pluginPath, { paths: [context.config.cwd, context.config.root] });
|
|
32
|
+
if (!isInstalled && context.config.autoInstall) {
|
|
33
|
+
context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
|
|
34
|
+
const result = await (0, _stryke_fs_install.install)(pluginPath, { cwd: context.config.root });
|
|
35
|
+
if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
|
|
36
|
+
context.error(result.stderr);
|
|
37
|
+
throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const module = await context.resolver.plugin.import(context.resolver.plugin.esmResolve((0, _stryke_path_join.joinPaths)(pluginPath, "plugin")));
|
|
42
|
+
const result = module.plugin ?? module.default;
|
|
43
|
+
if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
44
|
+
return result;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
try {
|
|
47
|
+
const module = await context.resolver.plugin.import(context.resolver.plugin.esmResolve(pluginPath));
|
|
48
|
+
const result = module.plugin ?? module.default;
|
|
49
|
+
if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
50
|
+
return result;
|
|
51
|
+
} catch {
|
|
52
|
+
if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
|
|
53
|
+
else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
|
|
54
|
+
${(0, _stryke_type_checks_is_error.isError)(error) ? error.message : String(error)}
|
|
55
|
+
|
|
56
|
+
Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, factory functions, string paths to plugins, and arrays of plugins or plugin configurations. It validates the plugin configuration, resolves any plugin paths, and returns an array of initialized plugins.
|
|
62
|
+
*
|
|
63
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
64
|
+
* @param config - The plugin configuration, which can be in various forms such as a direct plugin instance, a string path to a plugin, a factory function that returns a plugin, or an array of plugins or plugin configurations. This configuration will be processed and validated to initialize the appropriate plugins.
|
|
65
|
+
* @returns A promise that resolves to an array of initialized plugins based on the provided configuration. If the configuration is invalid, an error will be thrown with details about the issue.
|
|
66
|
+
*/
|
|
67
|
+
async function initPlugin(context, config, options = {}) {
|
|
68
|
+
const { skipLogging = false } = options;
|
|
69
|
+
let awaited = config;
|
|
70
|
+
if ((0, _stryke_type_checks_is_promise.isPromiseLike)(config)) awaited = await Promise.resolve(config);
|
|
71
|
+
if (!require_plugin_utils_helpers.isPluginConfig(awaited)) {
|
|
72
|
+
const invalid = require_plugin_utils_helpers.findInvalidPluginConfig(awaited);
|
|
73
|
+
throw new Error(`Invalid ${invalid && invalid.length > 1 ? "plugins" : "plugin"} specified in the configuration - ${invalid && invalid.length > 0 ? JSON.stringify(awaited) : invalid?.join("\n\n")} \n\nPlease ensure the value is one of the following: \n - an instance of \`Plugin\` \n - a plugin name \n - an object with the \`plugin\` and \`options\` properties \n - a tuple array with the plugin and options \n - a factory function that returns a plugin or array of plugins \n - an array of plugins or plugin configurations`);
|
|
74
|
+
}
|
|
75
|
+
let plugins;
|
|
76
|
+
if (require_plugin_utils_helpers.isPlugin(awaited)) plugins = [awaited];
|
|
77
|
+
else if ((0, _stryke_type_checks_is_function.isFunction)(awaited)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(awaited()));
|
|
78
|
+
else if ((0, _stryke_type_checks_is_string.isString)(awaited)) {
|
|
79
|
+
const resolved = await resolvePlugin(context, awaited);
|
|
80
|
+
if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(resolved()));
|
|
81
|
+
else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
|
|
82
|
+
} else if (Array.isArray(awaited) && awaited.every(require_plugin_utils_helpers.isPlugin)) plugins = awaited;
|
|
83
|
+
else if (Array.isArray(awaited) && awaited.every(require_plugin_utils_helpers.isPluginConfig)) {
|
|
84
|
+
plugins = [];
|
|
85
|
+
for (const pluginConfig of awaited) {
|
|
86
|
+
const initialized = await initPlugin(context, pluginConfig);
|
|
87
|
+
if (initialized) plugins.push(...initialized);
|
|
88
|
+
}
|
|
89
|
+
} else if (require_plugin_utils_helpers.isPluginConfigTuple(awaited) || require_plugin_utils_helpers.isPluginConfigObject(awaited)) {
|
|
90
|
+
let pluginConfig;
|
|
91
|
+
let pluginOptions;
|
|
92
|
+
if (require_plugin_utils_helpers.isPluginConfigTuple(awaited)) {
|
|
93
|
+
pluginConfig = awaited[0];
|
|
94
|
+
pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
|
|
95
|
+
} else {
|
|
96
|
+
pluginConfig = awaited.plugin;
|
|
97
|
+
pluginOptions = awaited.options;
|
|
98
|
+
}
|
|
99
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(pluginConfig)) {
|
|
100
|
+
const resolved = await resolvePlugin(context, pluginConfig);
|
|
101
|
+
if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
|
|
102
|
+
else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
|
|
103
|
+
} else if ((0, _stryke_type_checks_is_function.isFunction)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginConfig(pluginOptions)));
|
|
104
|
+
else if (Array.isArray(pluginConfig) && pluginConfig.every(require_plugin_utils_helpers.isPlugin)) plugins = pluginConfig;
|
|
105
|
+
else if (require_plugin_utils_helpers.isPlugin(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(pluginConfig);
|
|
106
|
+
}
|
|
107
|
+
if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
|
|
108
|
+
if (plugins.length > 0 && !plugins.every(require_plugin_utils_helpers.isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
|
|
109
|
+
const result = [];
|
|
110
|
+
for (const plugin of plugins) if (require_plugin_utils_helpers.isDuplicate(plugin, context.plugins)) {
|
|
111
|
+
if (!skipLogging) context.trace({
|
|
112
|
+
meta: { category: "plugins" },
|
|
113
|
+
message: `Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
result.push(plugin);
|
|
117
|
+
if (!skipLogging) context.trace({
|
|
118
|
+
meta: { category: "plugins" },
|
|
119
|
+
message: `Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, plugin names, factory functions, and arrays of plugins. It validates the configuration, resolves plugin modules if necessary, and returns an array of initialized plugins ready to be added to the execution context.
|
|
126
|
+
*
|
|
127
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
128
|
+
* @param config - The plugin configuration, which can be in various forms such as a plugin instance, a plugin name string, a factory function that returns a plugin or an array of plugins, or an array of plugin configurations. The function will handle the resolution and initialization of the plugin(s) based on the provided configuration.
|
|
129
|
+
* @returns A promise that resolves to an array of initialized plugins that can be added to the execution context, or null if the configuration is invalid or results in no plugins being initialized.
|
|
130
|
+
*/
|
|
131
|
+
async function resolvePlugins(context, config, options = {}) {
|
|
132
|
+
const { skipLogging = false } = options;
|
|
133
|
+
const plugins = [];
|
|
134
|
+
if (config) {
|
|
135
|
+
const result = await initPlugin(context, config);
|
|
136
|
+
if (result) for (const plugin of result) {
|
|
137
|
+
if (!skipLogging) context.debug({
|
|
138
|
+
meta: { category: "plugins" },
|
|
139
|
+
message: `Successfully initialized the ${chalk.default.bold.cyanBright(plugin.name)} plugin`
|
|
140
|
+
});
|
|
141
|
+
plugins.push(plugin);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return plugins;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
exports.initPlugin = initPlugin;
|
|
149
|
+
exports.resolvePlugin = resolvePlugin;
|
|
150
|
+
exports.resolvePlugins = resolvePlugins;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Plugin } from "../types/plugin.cjs";
|
|
2
|
+
import { EnvironmentContext, ExecutionContext, PluginContext } from "../types/context.cjs";
|
|
3
|
+
import { PluginConfig, ResolvedConfig } from "../types/config.cjs";
|
|
4
|
+
import { MaybePromise } from "@stryke/types/base";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/plugins.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a plugin module based on the provided plugin path. This function checks if the plugin package is installed, attempts to import the plugin module, and handles various error cases such as missing packages or invalid module exports. It supports both direct plugin exports and plugins exported from a "plugin" subdirectory within the package.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
11
|
+
* @param pluginPath - The path to the plugin module. This can be a package name, a scoped package name, or a path to a local module.
|
|
12
|
+
* @returns A promise that resolves to the plugin module, which can be a plugin instance, a factory function that returns a plugin, or an array of plugins.
|
|
13
|
+
*/
|
|
14
|
+
declare function resolvePlugin<TResolvedConfig extends ResolvedConfig, TSystemContext, TContext extends EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext> = EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext>, TPluginContext extends PluginContext<TResolvedConfig, TSystemContext> = PluginContext<TResolvedConfig, TSystemContext>>(context: TContext, pluginPath: string): Promise<Plugin<TPluginContext> | Plugin<TPluginContext>[] | ((options?: any) => MaybePromise<Plugin<TPluginContext> | Plugin<TPluginContext>[]>)>;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, factory functions, string paths to plugins, and arrays of plugins or plugin configurations. It validates the plugin configuration, resolves any plugin paths, and returns an array of initialized plugins.
|
|
17
|
+
*
|
|
18
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
19
|
+
* @param config - The plugin configuration, which can be in various forms such as a direct plugin instance, a string path to a plugin, a factory function that returns a plugin, or an array of plugins or plugin configurations. This configuration will be processed and validated to initialize the appropriate plugins.
|
|
20
|
+
* @returns A promise that resolves to an array of initialized plugins based on the provided configuration. If the configuration is invalid, an error will be thrown with details about the issue.
|
|
21
|
+
*/
|
|
22
|
+
declare function initPlugin<TResolvedConfig extends ResolvedConfig, TSystemContext, TContext extends EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext> = EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext>, TPluginContext extends PluginContext<TResolvedConfig, TSystemContext> = PluginContext<TResolvedConfig, TSystemContext>>(context: TContext, config: PluginConfig<TPluginContext>, options?: ResolvePluginsOptions): Promise<Plugin<TPluginContext>[] | null>;
|
|
23
|
+
interface ResolvePluginsOptions {
|
|
24
|
+
/**
|
|
25
|
+
* If true, the plugin resolution process will skip logging messages about the plugin initialization. This can be useful in scenarios where you want to suppress plugin-related logs, such as when running in a non-interactive environment or when you want to reduce log verbosity. By default, this option is false, and plugin initialization messages will be logged using the context's logger.
|
|
26
|
+
*/
|
|
27
|
+
skipLogging?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, plugin names, factory functions, and arrays of plugins. It validates the configuration, resolves plugin modules if necessary, and returns an array of initialized plugins ready to be added to the execution context.
|
|
31
|
+
*
|
|
32
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
33
|
+
* @param config - The plugin configuration, which can be in various forms such as a plugin instance, a plugin name string, a factory function that returns a plugin or an array of plugins, or an array of plugin configurations. The function will handle the resolution and initialization of the plugin(s) based on the provided configuration.
|
|
34
|
+
* @returns A promise that resolves to an array of initialized plugins that can be added to the execution context, or null if the configuration is invalid or results in no plugins being initialized.
|
|
35
|
+
*/
|
|
36
|
+
declare function resolvePlugins<TResolvedConfig extends ResolvedConfig, TSystemContext, TContext extends EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext> = EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext>, TPluginContext extends PluginContext<TResolvedConfig, TSystemContext> = PluginContext<TResolvedConfig, TSystemContext>>(context: TContext, config: PluginConfig<TPluginContext>, options?: ResolvePluginsOptions): Promise<Plugin<TPluginContext>[]>;
|
|
37
|
+
declare type __ΩResolvePluginsOptions = any[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ResolvePluginsOptions, __ΩResolvePluginsOptions, initPlugin, resolvePlugin, resolvePlugins };
|
|
40
|
+
//# sourceMappingURL=plugins.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.cts","names":[],"sources":["../../src/lib/plugins.ts"],"mappings":";;;;;;;;;;;AAwDA;;iBAAsB,aAAA,yBACI,cAAA,mCAGpB,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,IAClC,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,0BACf,aAAA,CAAc,eAAA,EAAiB,cAAA,IACpD,aAAA,CAAc,eAAA,EAAiB,cAAA,EAAA,CAEjC,OAAA,EAAS,QAAA,EACT,UAAA,WACC,OAAA,CACC,MAAA,CAAO,cAAA,IACP,MAAA,CAAO,cAAA,QAEL,OAAA,WACG,YAAA,CAAa,MAAA,CAAO,cAAA,IAAkB,MAAA,CAAO,cAAA;;;;;;;;iBAsGhC,UAAA,yBACI,cAAA,mCAGpB,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,IAClC,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,0BACf,aAAA,CAAc,eAAA,EAAiB,cAAA,IACpD,aAAA,CAAc,eAAA,EAAiB,cAAA,EAAA,CAEjC,OAAA,EAAS,QAAA,EACT,MAAA,EAAQ,YAAA,CAAa,cAAA,GACrB,OAAA,GAAS,qBAAA,GACR,OAAA,CAAQ,MAAA,CAAO,cAAA;AAAA,UAwJD,qBAAA;EAxRX;;;EA4RJ,WAAA;AAAA;;;;;;;;iBAUoB,cAAA,yBACI,cAAA,mCAGpB,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,IAClC,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,0BACf,aAAA,CAAc,eAAA,EAAiB,cAAA,IACpD,aAAA,CAAc,eAAA,EAAiB,cAAA,EAAA,CAEjC,OAAA,EAAS,QAAA,EACT,MAAA,EAAQ,YAAA,CAAa,cAAA,GACrB,OAAA,GAAS,qBAAA,GAA0B,OAAA,CAAA,MAAA,CAAA,cAAA;AAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Plugin } from "../types/plugin.mjs";
|
|
2
|
+
import { EnvironmentContext, ExecutionContext, PluginContext } from "../types/context.mjs";
|
|
3
|
+
import { PluginConfig, ResolvedConfig } from "../types/config.mjs";
|
|
4
|
+
import { MaybePromise } from "@stryke/types/base";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/plugins.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a plugin module based on the provided plugin path. This function checks if the plugin package is installed, attempts to import the plugin module, and handles various error cases such as missing packages or invalid module exports. It supports both direct plugin exports and plugins exported from a "plugin" subdirectory within the package.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
11
|
+
* @param pluginPath - The path to the plugin module. This can be a package name, a scoped package name, or a path to a local module.
|
|
12
|
+
* @returns A promise that resolves to the plugin module, which can be a plugin instance, a factory function that returns a plugin, or an array of plugins.
|
|
13
|
+
*/
|
|
14
|
+
declare function resolvePlugin<TResolvedConfig extends ResolvedConfig, TSystemContext, TContext extends EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext> = EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext>, TPluginContext extends PluginContext<TResolvedConfig, TSystemContext> = PluginContext<TResolvedConfig, TSystemContext>>(context: TContext, pluginPath: string): Promise<Plugin<TPluginContext> | Plugin<TPluginContext>[] | ((options?: any) => MaybePromise<Plugin<TPluginContext> | Plugin<TPluginContext>[]>)>;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, factory functions, string paths to plugins, and arrays of plugins or plugin configurations. It validates the plugin configuration, resolves any plugin paths, and returns an array of initialized plugins.
|
|
17
|
+
*
|
|
18
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
19
|
+
* @param config - The plugin configuration, which can be in various forms such as a direct plugin instance, a string path to a plugin, a factory function that returns a plugin, or an array of plugins or plugin configurations. This configuration will be processed and validated to initialize the appropriate plugins.
|
|
20
|
+
* @returns A promise that resolves to an array of initialized plugins based on the provided configuration. If the configuration is invalid, an error will be thrown with details about the issue.
|
|
21
|
+
*/
|
|
22
|
+
declare function initPlugin<TResolvedConfig extends ResolvedConfig, TSystemContext, TContext extends EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext> = EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext>, TPluginContext extends PluginContext<TResolvedConfig, TSystemContext> = PluginContext<TResolvedConfig, TSystemContext>>(context: TContext, config: PluginConfig<TPluginContext>, options?: ResolvePluginsOptions): Promise<Plugin<TPluginContext>[] | null>;
|
|
23
|
+
interface ResolvePluginsOptions {
|
|
24
|
+
/**
|
|
25
|
+
* If true, the plugin resolution process will skip logging messages about the plugin initialization. This can be useful in scenarios where you want to suppress plugin-related logs, such as when running in a non-interactive environment or when you want to reduce log verbosity. By default, this option is false, and plugin initialization messages will be logged using the context's logger.
|
|
26
|
+
*/
|
|
27
|
+
skipLogging?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, plugin names, factory functions, and arrays of plugins. It validates the configuration, resolves plugin modules if necessary, and returns an array of initialized plugins ready to be added to the execution context.
|
|
31
|
+
*
|
|
32
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
33
|
+
* @param config - The plugin configuration, which can be in various forms such as a plugin instance, a plugin name string, a factory function that returns a plugin or an array of plugins, or an array of plugin configurations. The function will handle the resolution and initialization of the plugin(s) based on the provided configuration.
|
|
34
|
+
* @returns A promise that resolves to an array of initialized plugins that can be added to the execution context, or null if the configuration is invalid or results in no plugins being initialized.
|
|
35
|
+
*/
|
|
36
|
+
declare function resolvePlugins<TResolvedConfig extends ResolvedConfig, TSystemContext, TContext extends EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext> = EnvironmentContext<TResolvedConfig, TSystemContext> | ExecutionContext<TResolvedConfig, TSystemContext>, TPluginContext extends PluginContext<TResolvedConfig, TSystemContext> = PluginContext<TResolvedConfig, TSystemContext>>(context: TContext, config: PluginConfig<TPluginContext>, options?: ResolvePluginsOptions): Promise<Plugin<TPluginContext>[]>;
|
|
37
|
+
declare type __ΩResolvePluginsOptions = any[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ResolvePluginsOptions, __ΩResolvePluginsOptions, initPlugin, resolvePlugin, resolvePlugins };
|
|
40
|
+
//# sourceMappingURL=plugins.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.mts","names":[],"sources":["../../src/lib/plugins.ts"],"mappings":";;;;;;;;;;;AAwDA;;iBAAsB,aAAA,yBACI,cAAA,mCAGpB,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,IAClC,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,0BACf,aAAA,CAAc,eAAA,EAAiB,cAAA,IACpD,aAAA,CAAc,eAAA,EAAiB,cAAA,EAAA,CAEjC,OAAA,EAAS,QAAA,EACT,UAAA,WACC,OAAA,CACC,MAAA,CAAO,cAAA,IACP,MAAA,CAAO,cAAA,QAEL,OAAA,WACG,YAAA,CAAa,MAAA,CAAO,cAAA,IAAkB,MAAA,CAAO,cAAA;;;;;;;;iBAsGhC,UAAA,yBACI,cAAA,mCAGpB,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,IAClC,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,0BACf,aAAA,CAAc,eAAA,EAAiB,cAAA,IACpD,aAAA,CAAc,eAAA,EAAiB,cAAA,EAAA,CAEjC,OAAA,EAAS,QAAA,EACT,MAAA,EAAQ,YAAA,CAAa,cAAA,GACrB,OAAA,GAAS,qBAAA,GACR,OAAA,CAAQ,MAAA,CAAO,cAAA;AAAA,UAwJD,qBAAA;EAxRX;;;EA4RJ,WAAA;AAAA;;;;;;;;iBAUoB,cAAA,yBACI,cAAA,mCAGpB,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,IAClC,kBAAA,CAAmB,eAAA,EAAiB,cAAA,IACpC,gBAAA,CAAiB,eAAA,EAAiB,cAAA,0BACf,aAAA,CAAc,eAAA,EAAiB,cAAA,IACpD,aAAA,CAAc,eAAA,EAAiB,cAAA,EAAA,CAEjC,OAAA,EAAS,QAAA,EACT,MAAA,EAAQ,YAAA,CAAa,cAAA,GACrB,OAAA,GAAS,qBAAA,GAA0B,OAAA,CAAA,MAAA,CAAA,cAAA;AAAA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { findInvalidPluginConfig, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple } from "../plugin-utils/helpers.mjs";
|
|
2
|
+
import "../plugin-utils/index.mjs";
|
|
3
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
4
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
5
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
8
|
+
import { joinPaths } from "@stryke/path/join";
|
|
9
|
+
import { install } from "@stryke/fs/install";
|
|
10
|
+
import { isPackageExists } from "@stryke/fs/package-fns";
|
|
11
|
+
import { isNumber } from "@stryke/type-checks/is-number";
|
|
12
|
+
import { isError } from "@stryke/type-checks/is-error";
|
|
13
|
+
import { isPromiseLike } from "@stryke/type-checks/is-promise";
|
|
14
|
+
|
|
15
|
+
//#region src/lib/plugins.ts
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a plugin module based on the provided plugin path. This function checks if the plugin package is installed, attempts to import the plugin module, and handles various error cases such as missing packages or invalid module exports. It supports both direct plugin exports and plugins exported from a "plugin" subdirectory within the package.
|
|
18
|
+
*
|
|
19
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
20
|
+
* @param pluginPath - The path to the plugin module. This can be a package name, a scoped package name, or a path to a local module.
|
|
21
|
+
* @returns A promise that resolves to the plugin module, which can be a plugin instance, a factory function that returns a plugin, or an array of plugins.
|
|
22
|
+
*/
|
|
23
|
+
async function resolvePlugin(context, pluginPath) {
|
|
24
|
+
if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
|
|
25
|
+
const splits = pluginPath.split("/").filter(Boolean);
|
|
26
|
+
pluginPath = `${splits[0]}/${splits[1]}`;
|
|
27
|
+
}
|
|
28
|
+
const isInstalled = isPackageExists(pluginPath, { paths: [context.config.cwd, context.config.root] });
|
|
29
|
+
if (!isInstalled && context.config.autoInstall) {
|
|
30
|
+
context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
|
|
31
|
+
const result = await install(pluginPath, { cwd: context.config.root });
|
|
32
|
+
if (isNumber(result.exitCode) && result.exitCode > 0) {
|
|
33
|
+
context.error(result.stderr);
|
|
34
|
+
throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const module = await context.resolver.plugin.import(context.resolver.plugin.esmResolve(joinPaths(pluginPath, "plugin")));
|
|
39
|
+
const result = module.plugin ?? module.default;
|
|
40
|
+
if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
41
|
+
return result;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
try {
|
|
44
|
+
const module = await context.resolver.plugin.import(context.resolver.plugin.esmResolve(pluginPath));
|
|
45
|
+
const result = module.plugin ?? module.default;
|
|
46
|
+
if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
47
|
+
return result;
|
|
48
|
+
} catch {
|
|
49
|
+
if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
|
|
50
|
+
else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
|
|
51
|
+
${isError(error) ? error.message : String(error)}
|
|
52
|
+
|
|
53
|
+
Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, factory functions, string paths to plugins, and arrays of plugins or plugin configurations. It validates the plugin configuration, resolves any plugin paths, and returns an array of initialized plugins.
|
|
59
|
+
*
|
|
60
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
61
|
+
* @param config - The plugin configuration, which can be in various forms such as a direct plugin instance, a string path to a plugin, a factory function that returns a plugin, or an array of plugins or plugin configurations. This configuration will be processed and validated to initialize the appropriate plugins.
|
|
62
|
+
* @returns A promise that resolves to an array of initialized plugins based on the provided configuration. If the configuration is invalid, an error will be thrown with details about the issue.
|
|
63
|
+
*/
|
|
64
|
+
async function initPlugin(context, config, options = {}) {
|
|
65
|
+
const { skipLogging = false } = options;
|
|
66
|
+
let awaited = config;
|
|
67
|
+
if (isPromiseLike(config)) awaited = await Promise.resolve(config);
|
|
68
|
+
if (!isPluginConfig(awaited)) {
|
|
69
|
+
const invalid = findInvalidPluginConfig(awaited);
|
|
70
|
+
throw new Error(`Invalid ${invalid && invalid.length > 1 ? "plugins" : "plugin"} specified in the configuration - ${invalid && invalid.length > 0 ? JSON.stringify(awaited) : invalid?.join("\n\n")} \n\nPlease ensure the value is one of the following: \n - an instance of \`Plugin\` \n - a plugin name \n - an object with the \`plugin\` and \`options\` properties \n - a tuple array with the plugin and options \n - a factory function that returns a plugin or array of plugins \n - an array of plugins or plugin configurations`);
|
|
71
|
+
}
|
|
72
|
+
let plugins;
|
|
73
|
+
if (isPlugin(awaited)) plugins = [awaited];
|
|
74
|
+
else if (isFunction(awaited)) plugins = toArray(await Promise.resolve(awaited()));
|
|
75
|
+
else if (isString(awaited)) {
|
|
76
|
+
const resolved = await resolvePlugin(context, awaited);
|
|
77
|
+
if (isFunction(resolved)) plugins = toArray(await Promise.resolve(resolved()));
|
|
78
|
+
else plugins = toArray(resolved);
|
|
79
|
+
} else if (Array.isArray(awaited) && awaited.every(isPlugin)) plugins = awaited;
|
|
80
|
+
else if (Array.isArray(awaited) && awaited.every(isPluginConfig)) {
|
|
81
|
+
plugins = [];
|
|
82
|
+
for (const pluginConfig of awaited) {
|
|
83
|
+
const initialized = await initPlugin(context, pluginConfig);
|
|
84
|
+
if (initialized) plugins.push(...initialized);
|
|
85
|
+
}
|
|
86
|
+
} else if (isPluginConfigTuple(awaited) || isPluginConfigObject(awaited)) {
|
|
87
|
+
let pluginConfig;
|
|
88
|
+
let pluginOptions;
|
|
89
|
+
if (isPluginConfigTuple(awaited)) {
|
|
90
|
+
pluginConfig = awaited[0];
|
|
91
|
+
pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
|
|
92
|
+
} else {
|
|
93
|
+
pluginConfig = awaited.plugin;
|
|
94
|
+
pluginOptions = awaited.options;
|
|
95
|
+
}
|
|
96
|
+
if (isSetString(pluginConfig)) {
|
|
97
|
+
const resolved = await resolvePlugin(context, pluginConfig);
|
|
98
|
+
if (isFunction(resolved)) plugins = toArray(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
|
|
99
|
+
else plugins = toArray(resolved);
|
|
100
|
+
} else if (isFunction(pluginConfig)) plugins = toArray(await Promise.resolve(pluginConfig(pluginOptions)));
|
|
101
|
+
else if (Array.isArray(pluginConfig) && pluginConfig.every(isPlugin)) plugins = pluginConfig;
|
|
102
|
+
else if (isPlugin(pluginConfig)) plugins = toArray(pluginConfig);
|
|
103
|
+
}
|
|
104
|
+
if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
|
|
105
|
+
if (plugins.length > 0 && !plugins.every(isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
|
|
106
|
+
const result = [];
|
|
107
|
+
for (const plugin of plugins) if (isDuplicate(plugin, context.plugins)) {
|
|
108
|
+
if (!skipLogging) context.trace({
|
|
109
|
+
meta: { category: "plugins" },
|
|
110
|
+
message: `Duplicate ${chalk.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
result.push(plugin);
|
|
114
|
+
if (!skipLogging) context.trace({
|
|
115
|
+
meta: { category: "plugins" },
|
|
116
|
+
message: `Initializing the ${chalk.bold.cyanBright(plugin.name)} plugin...`
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Initialize a plugin based on the provided plugin configuration. This function handles various forms of plugin configurations, including direct plugin instances, plugin names, factory functions, and arrays of plugins. It validates the configuration, resolves plugin modules if necessary, and returns an array of initialized plugins ready to be added to the execution context.
|
|
123
|
+
*
|
|
124
|
+
* @param context - The execution context in which the plugin will be initialized. This context provides access to configuration, logging, and other utilities that may be needed during plugin initialization.
|
|
125
|
+
* @param config - The plugin configuration, which can be in various forms such as a plugin instance, a plugin name string, a factory function that returns a plugin or an array of plugins, or an array of plugin configurations. The function will handle the resolution and initialization of the plugin(s) based on the provided configuration.
|
|
126
|
+
* @returns A promise that resolves to an array of initialized plugins that can be added to the execution context, or null if the configuration is invalid or results in no plugins being initialized.
|
|
127
|
+
*/
|
|
128
|
+
async function resolvePlugins(context, config, options = {}) {
|
|
129
|
+
const { skipLogging = false } = options;
|
|
130
|
+
const plugins = [];
|
|
131
|
+
if (config) {
|
|
132
|
+
const result = await initPlugin(context, config);
|
|
133
|
+
if (result) for (const plugin of result) {
|
|
134
|
+
if (!skipLogging) context.debug({
|
|
135
|
+
meta: { category: "plugins" },
|
|
136
|
+
message: `Successfully initialized the ${chalk.bold.cyanBright(plugin.name)} plugin`
|
|
137
|
+
});
|
|
138
|
+
plugins.push(plugin);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return plugins;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
export { initPlugin, resolvePlugin, resolvePlugins };
|
|
146
|
+
//# sourceMappingURL=plugins.mjs.map
|