@powerlines/engine 0.47.4 → 0.49.2
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/api/build.cjs +66 -0
- package/dist/api/build.d.cts +14 -0
- package/dist/api/build.d.cts.map +1 -0
- package/dist/api/build.d.mts +14 -0
- package/dist/api/build.d.mts.map +1 -0
- package/dist/api/build.mjs +64 -0
- package/dist/api/build.mjs.map +1 -0
- package/dist/api/clean.cjs +28 -0
- package/dist/api/clean.d.cts +14 -0
- package/dist/api/clean.d.cts.map +1 -0
- package/dist/api/clean.d.mts +14 -0
- package/dist/api/clean.d.mts.map +1 -0
- package/dist/api/clean.mjs +28 -0
- package/dist/api/clean.mjs.map +1 -0
- package/dist/api/create.cjs +59 -0
- package/dist/api/create.d.cts +14 -0
- package/dist/api/create.d.cts.map +1 -0
- package/dist/api/create.d.mts +14 -0
- package/dist/api/create.d.mts.map +1 -0
- package/dist/api/create.mjs +57 -0
- package/dist/api/create.mjs.map +1 -0
- package/dist/api/deploy.cjs +24 -0
- package/dist/api/deploy.d.cts +17 -0
- package/dist/api/deploy.d.cts.map +1 -0
- package/dist/api/deploy.d.mts +17 -0
- package/dist/api/deploy.d.mts.map +1 -0
- package/dist/api/deploy.mjs +24 -0
- package/dist/api/deploy.mjs.map +1 -0
- package/dist/api/docs.cjs +24 -0
- package/dist/api/docs.d.cts +17 -0
- package/dist/api/docs.d.cts.map +1 -0
- package/dist/api/docs.d.mts +17 -0
- package/dist/api/docs.d.mts.map +1 -0
- package/dist/api/docs.mjs +24 -0
- package/dist/api/docs.mjs.map +1 -0
- package/dist/api/lint.cjs +27 -0
- package/dist/api/lint.d.cts +17 -0
- package/dist/api/lint.d.cts.map +1 -0
- package/dist/api/lint.d.mts +17 -0
- package/dist/api/lint.d.mts.map +1 -0
- package/dist/api/lint.mjs +27 -0
- package/dist/api/lint.mjs.map +1 -0
- package/dist/api/prepare.cjs +68 -0
- package/dist/api/prepare.d.cts +14 -0
- package/dist/api/prepare.d.cts.map +1 -0
- package/dist/api/prepare.d.mts +14 -0
- package/dist/api/prepare.d.mts.map +1 -0
- package/dist/api/prepare.mjs +68 -0
- package/dist/api/prepare.mjs.map +1 -0
- package/dist/api/test.cjs +27 -0
- package/dist/api/test.d.cts +17 -0
- package/dist/api/test.d.cts.map +1 -0
- package/dist/api/test.d.mts +17 -0
- package/dist/api/test.d.mts.map +1 -0
- package/dist/api/test.mjs +27 -0
- package/dist/api/test.mjs.map +1 -0
- package/dist/api/types.cjs +70 -0
- package/dist/api/types.d.cts +17 -0
- package/dist/api/types.d.cts.map +1 -0
- package/dist/api/types.d.mts +17 -0
- package/dist/api/types.d.mts.map +1 -0
- package/dist/api/types.mjs +70 -0
- package/dist/api/types.mjs.map +1 -0
- package/dist/api-BgyEi2hF.d.mts +138 -0
- package/dist/api-BgyEi2hF.d.mts.map +1 -0
- package/dist/api-DcHfCjQK.d.cts +138 -0
- package/dist/api-DcHfCjQK.d.cts.map +1 -0
- package/dist/api.cjs +39 -1268
- package/dist/api.d.cts +11 -300
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +11 -300
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +31 -1264
- package/dist/api.mjs.map +1 -1
- package/dist/config-ByLyzMI0.d.mts +204 -0
- package/dist/config-ByLyzMI0.d.mts.map +1 -0
- package/dist/config-DKEmqMrh.d.cts +204 -0
- package/dist/config-DKEmqMrh.d.cts.map +1 -0
- package/dist/context/engine-context.cjs +177 -0
- package/dist/context/engine-context.d.cts +2 -0
- package/dist/context/engine-context.d.mts +2 -0
- package/dist/context/engine-context.mjs +175 -0
- package/dist/context/engine-context.mjs.map +1 -0
- package/dist/context/index.cjs +2 -9
- package/dist/context/index.d.cts +2 -150
- package/dist/context/index.d.mts +2 -150
- package/dist/context/index.mjs +2 -4
- package/dist/context-D0_a0kRO.d.cts +149 -0
- package/dist/context-D0_a0kRO.d.cts.map +1 -0
- package/dist/context-DcXV6_GL.d.mts +149 -0
- package/dist/context-DcXV6_GL.d.mts.map +1 -0
- package/dist/engine-Dz6BvkFY.cjs +590 -0
- package/dist/engine-context-B8K6Jtkk.d.cts +53 -0
- package/dist/engine-context-B8K6Jtkk.d.cts.map +1 -0
- package/dist/engine-context-DKlA5Pgu.d.mts +53 -0
- package/dist/engine-context-DKlA5Pgu.d.mts.map +1 -0
- package/dist/engine-q6YKXXcB.mjs +571 -0
- package/dist/engine-q6YKXXcB.mjs.map +1 -0
- package/dist/engine.cjs +6 -0
- package/dist/engine.d.cts +143 -0
- package/dist/engine.d.cts.map +1 -0
- package/dist/engine.d.mts +143 -0
- package/dist/engine.d.mts.map +1 -0
- package/dist/engine.mjs +3 -0
- package/dist/helpers/create-execution-host.cjs +57 -0
- package/dist/helpers/create-execution-host.d.cts +20 -0
- package/dist/helpers/create-execution-host.d.cts.map +1 -0
- package/dist/helpers/create-execution-host.d.mts +20 -0
- package/dist/helpers/create-execution-host.d.mts.map +1 -0
- package/dist/helpers/create-execution-host.mjs +57 -0
- package/dist/helpers/create-execution-host.mjs.map +1 -0
- package/dist/helpers/finalize.cjs +26 -0
- package/dist/helpers/finalize.d.cts +12 -0
- package/dist/helpers/finalize.d.cts.map +1 -0
- package/dist/helpers/finalize.d.mts +12 -0
- package/dist/helpers/finalize.d.mts.map +1 -0
- package/dist/helpers/finalize.mjs +26 -0
- package/dist/helpers/finalize.mjs.map +1 -0
- package/dist/helpers/index.cjs +12 -0
- package/dist/helpers/index.d.cts +5 -0
- package/dist/helpers/index.d.mts +5 -0
- package/dist/helpers/index.mjs +6 -0
- package/dist/helpers/rpc.cjs +139 -0
- package/dist/helpers/rpc.d.cts +7 -0
- package/dist/helpers/rpc.d.cts.map +1 -0
- package/dist/helpers/rpc.d.mts +7 -0
- package/dist/helpers/rpc.d.mts.map +1 -0
- package/dist/helpers/rpc.mjs +139 -0
- package/dist/helpers/rpc.mjs.map +1 -0
- package/dist/helpers/stream.cjs +119 -0
- package/dist/helpers/stream.d.cts +45 -0
- package/dist/helpers/stream.d.cts.map +1 -0
- package/dist/helpers/stream.d.mts +45 -0
- package/dist/helpers/stream.d.mts.map +1 -0
- package/dist/helpers/stream.mjs +117 -0
- package/dist/helpers/stream.mjs.map +1 -0
- package/dist/index-BVVgDSdq.d.cts +1 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.cjs +8 -748
- package/dist/index.d.cts +6 -140
- package/dist/index.d.mts +6 -140
- package/dist/index.mjs +4 -747
- package/package.json +102 -132
- package/dist/_internal/worker.cjs +0 -5192
- package/dist/_internal/worker.d.cts +0 -46
- package/dist/_internal/worker.d.cts.map +0 -1
- package/dist/_internal/worker.d.mts +0 -46
- package/dist/_internal/worker.d.mts.map +0 -1
- package/dist/_internal/worker.mjs +0 -5153
- package/dist/_internal/worker.mjs.map +0 -1
- package/dist/base-context-DLemGRbd.cjs +0 -322
- package/dist/base-context-DUha4Lz-.mjs +0 -315
- package/dist/base-context-DUha4Lz-.mjs.map +0 -1
- package/dist/context/index.d.cts.map +0 -1
- package/dist/context/index.d.mts.map +0 -1
- package/dist/engine-context-BfFiKN53.mjs +0 -86
- package/dist/engine-context-BfFiKN53.mjs.map +0 -1
- package/dist/engine-context-D0y88i_J.cjs +0 -91
- package/dist/execution-context-CE5H90Um.mjs +0 -2845
- package/dist/execution-context-CE5H90Um.mjs.map +0 -1
- package/dist/execution-context-CnyaM3Ul.cjs +0 -2889
- package/dist/execution-context-NyDjVZ6T.d.cts +0 -647
- package/dist/execution-context-NyDjVZ6T.d.cts.map +0 -1
- package/dist/execution-context-YrjFeD9k.d.mts +0 -647
- package/dist/execution-context-YrjFeD9k.d.mts.map +0 -1
- package/dist/fs-CeEdzPKE.cjs +0 -262
- package/dist/fs-Dcle8lUp.mjs +0 -226
- package/dist/fs-Dcle8lUp.mjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/rpc/client.cjs +0 -74
- package/dist/rpc/client.d.cts +0 -31
- package/dist/rpc/client.d.cts.map +0 -1
- package/dist/rpc/client.d.mts +0 -31
- package/dist/rpc/client.d.mts.map +0 -1
- package/dist/rpc/client.mjs +0 -71
- package/dist/rpc/client.mjs.map +0 -1
- package/dist/rpc/serialization.cjs +0 -82
- package/dist/rpc/serialization.d.cts +0 -46
- package/dist/rpc/serialization.d.cts.map +0 -1
- package/dist/rpc/serialization.d.mts +0 -46
- package/dist/rpc/serialization.d.mts.map +0 -1
- package/dist/rpc/serialization.mjs +0 -76
- package/dist/rpc/serialization.mjs.map +0 -1
- package/dist/rpc/server.cjs +0 -69
- package/dist/rpc/server.d.cts +0 -29
- package/dist/rpc/server.d.cts.map +0 -1
- package/dist/rpc/server.d.mts +0 -29
- package/dist/rpc/server.d.mts.map +0 -1
- package/dist/rpc/server.mjs +0 -66
- package/dist/rpc/server.mjs.map +0 -1
- package/dist/rpc/types.cjs +0 -0
- package/dist/rpc/types.d.cts +0 -70
- package/dist/rpc/types.d.cts.map +0 -1
- package/dist/rpc/types.d.mts +0 -70
- package/dist/rpc/types.d.mts.map +0 -1
- package/dist/rpc/types.mjs +0 -1
- package/dist/schemas.cjs +0 -9
- package/dist/schemas.d.cts +0 -127
- package/dist/schemas.d.cts.map +0 -1
- package/dist/schemas.d.mts +0 -127
- package/dist/schemas.d.mts.map +0 -1
- package/dist/schemas.mjs +0 -3
- package/dist/storage/base.cjs +0 -216
- package/dist/storage/base.d.cts +0 -199
- package/dist/storage/base.d.cts.map +0 -1
- package/dist/storage/base.d.mts +0 -199
- package/dist/storage/base.d.mts.map +0 -1
- package/dist/storage/base.mjs +0 -215
- package/dist/storage/base.mjs.map +0 -1
- package/dist/storage/file-system.cjs +0 -180
- package/dist/storage/file-system.d.cts +0 -127
- package/dist/storage/file-system.d.cts.map +0 -1
- package/dist/storage/file-system.d.mts +0 -127
- package/dist/storage/file-system.d.mts.map +0 -1
- package/dist/storage/file-system.mjs +0 -179
- package/dist/storage/file-system.mjs.map +0 -1
- package/dist/storage/helpers.cjs +0 -37
- package/dist/storage/helpers.d.cts +0 -25
- package/dist/storage/helpers.d.cts.map +0 -1
- package/dist/storage/helpers.d.mts +0 -25
- package/dist/storage/helpers.d.mts.map +0 -1
- package/dist/storage/helpers.mjs +0 -34
- package/dist/storage/helpers.mjs.map +0 -1
- package/dist/storage/index.cjs +0 -12
- package/dist/storage/index.d.cts +0 -5
- package/dist/storage/index.d.mts +0 -5
- package/dist/storage/index.mjs +0 -6
- package/dist/storage/virtual.cjs +0 -98
- package/dist/storage/virtual.d.cts +0 -80
- package/dist/storage/virtual.d.cts.map +0 -1
- package/dist/storage/virtual.d.mts +0 -80
- package/dist/storage/virtual.d.mts.map +0 -1
- package/dist/storage/virtual.mjs +0 -97
- package/dist/storage/virtual.mjs.map +0 -1
- package/dist/ts-morph-BbM83PT9.cjs +0 -114
- package/dist/ts-morph-C6YBNc46.mjs +0 -102
- package/dist/ts-morph-C6YBNc46.mjs.map +0 -1
- package/dist/tsconfig-DeKMGasE.cjs +0 -198
- package/dist/tsconfig-HzJsMUrr.mjs +0 -155
- package/dist/tsconfig-HzJsMUrr.mjs.map +0 -1
- package/dist/typescript/index.cjs +0 -13
- package/dist/typescript/index.d.cts +0 -106
- package/dist/typescript/index.d.cts.map +0 -1
- package/dist/typescript/index.d.mts +0 -106
- package/dist/typescript/index.d.mts.map +0 -1
- package/dist/typescript/index.mjs +0 -4
- /package/dist/{chunk-C0xms8kb.cjs → chunk-C_NdSu1c.cjs} +0 -0
|
@@ -1,2889 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-C0xms8kb.cjs');
|
|
2
|
-
const require_fs = require('./fs-CeEdzPKE.cjs');
|
|
3
|
-
const require_storage_file_system = require('./storage/file-system.cjs');
|
|
4
|
-
const require_storage_virtual = require('./storage/virtual.cjs');
|
|
5
|
-
const require_tsconfig = require('./tsconfig-DeKMGasE.cjs');
|
|
6
|
-
const require_base_context = require('./base-context-DLemGRbd.cjs');
|
|
7
|
-
let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
|
|
8
|
-
let _powerlines_core_lib_utilities_format = require("@powerlines/core/lib/utilities/format");
|
|
9
|
-
let _powerlines_core_plugin_utils = require("@powerlines/core/plugin-utils");
|
|
10
|
-
let _powerlines_core_plugin_utils_logging = require("@powerlines/core/plugin-utils/logging");
|
|
11
|
-
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
12
|
-
let _stryke_fs_exists = require("@stryke/fs/exists");
|
|
13
|
-
let _stryke_fs_resolve = require("@stryke/fs/resolve");
|
|
14
|
-
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
15
|
-
let _stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
16
|
-
let _stryke_path_append = require("@stryke/path/append");
|
|
17
|
-
let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
18
|
-
let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
19
|
-
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
20
|
-
let _stryke_path_replace = require("@stryke/path/replace");
|
|
21
|
-
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
22
|
-
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
23
|
-
let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
24
|
-
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
25
|
-
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
26
|
-
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
27
|
-
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
28
|
-
let chalk = require("chalk");
|
|
29
|
-
chalk = require_chunk.__toESM(chalk, 1);
|
|
30
|
-
let defu = require("defu");
|
|
31
|
-
defu = require_chunk.__toESM(defu, 1);
|
|
32
|
-
let _powerlines_core_constants = require("@powerlines/core/constants");
|
|
33
|
-
let _stryke_fs_json = require("@stryke/fs/json");
|
|
34
|
-
let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
|
|
35
|
-
let _stryke_path_join = require("@stryke/path/join");
|
|
36
|
-
let _powerlines_core_lib_entry = require("@powerlines/core/lib/entry");
|
|
37
|
-
let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
|
|
38
|
-
let _stryke_fs_get_workspace_root = require("@stryke/fs/get-workspace-root");
|
|
39
|
-
let _stryke_hash = require("@stryke/hash");
|
|
40
|
-
let _stryke_hash_node = require("@stryke/hash/node");
|
|
41
|
-
let _stryke_http_fetch = require("@stryke/http/fetch");
|
|
42
|
-
let _stryke_path_is_equal = require("@stryke/path/is-equal");
|
|
43
|
-
let _stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
|
|
44
|
-
let bundle_require = require("bundle-require");
|
|
45
|
-
let compatx = require("compatx");
|
|
46
|
-
let flat_cache = require("flat-cache");
|
|
47
|
-
let node_fs = require("node:fs");
|
|
48
|
-
let oxc_parser = require("oxc-parser");
|
|
49
|
-
let undici = require("undici");
|
|
50
|
-
require("@stryke/fs/remove-file");
|
|
51
|
-
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
52
|
-
let jest_worker = require("jest-worker");
|
|
53
|
-
let _stryke_capnp = require("@stryke/capnp");
|
|
54
|
-
_stryke_capnp = require_chunk.__toESM(_stryke_capnp, 1);
|
|
55
|
-
let _stryke_fs_buffer = require("@stryke/fs/buffer");
|
|
56
|
-
let _stryke_path_correct_path = require("@stryke/path/correct-path");
|
|
57
|
-
let _stryke_path_glob_to_regex = require("@stryke/path/glob-to-regex");
|
|
58
|
-
let _stryke_path_is_type = require("@stryke/path/is-type");
|
|
59
|
-
let _stryke_path_slash = require("@stryke/path/slash");
|
|
60
|
-
let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
|
|
61
|
-
let _stryke_type_checks_is_regexp = require("@stryke/type-checks/is-regexp");
|
|
62
|
-
let node_buffer = require("node:buffer");
|
|
63
|
-
let node_url = require("node:url");
|
|
64
|
-
let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
|
|
65
|
-
|
|
66
|
-
//#region src/_internal/helpers/environment.ts
|
|
67
|
-
function createEnvironment(name, config) {
|
|
68
|
-
return (0, defu.default)(config.environments?.[name] ?? {}, {
|
|
69
|
-
id: (0, _stryke_unique_id_uuid.uuid)(),
|
|
70
|
-
name,
|
|
71
|
-
title: config.title ?? (0, _stryke_string_format_title_case.titleCase)(config.name),
|
|
72
|
-
ssr: false,
|
|
73
|
-
resolve: { mainFields: config.platform === "browser" ? [
|
|
74
|
-
"browser",
|
|
75
|
-
"module",
|
|
76
|
-
"jsnext:main",
|
|
77
|
-
"jsnext"
|
|
78
|
-
] : [
|
|
79
|
-
"module",
|
|
80
|
-
"jsnext:main",
|
|
81
|
-
"jsnext"
|
|
82
|
-
] },
|
|
83
|
-
consumer: config.platform === "browser" ? "client" : "server",
|
|
84
|
-
preview: config.platform === "browser" ? {
|
|
85
|
-
port: 5173,
|
|
86
|
-
open: true,
|
|
87
|
-
strictPort: false,
|
|
88
|
-
host: "localhost",
|
|
89
|
-
allowedHosts: ["."],
|
|
90
|
-
cors: true,
|
|
91
|
-
headers: {}
|
|
92
|
-
} : void 0
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function createDefaultEnvironment(config) {
|
|
96
|
-
return createEnvironment(_powerlines_core_constants.DEFAULT_ENVIRONMENT, config);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/_internal/helpers/context.ts
|
|
101
|
-
function getConfigProps(config = {}) {
|
|
102
|
-
return {
|
|
103
|
-
name: config.name,
|
|
104
|
-
title: config.title,
|
|
105
|
-
description: config.description,
|
|
106
|
-
projectType: config.projectType,
|
|
107
|
-
customLogger: config.customLogger,
|
|
108
|
-
logLevel: config.logLevel,
|
|
109
|
-
tsconfig: config.tsconfig,
|
|
110
|
-
tsconfigRaw: config.tsconfigRaw,
|
|
111
|
-
skipCache: config.skipCache,
|
|
112
|
-
autoInstall: config.autoInstall,
|
|
113
|
-
input: (0, _stryke_type_checks_is_set_string.isSetString)(config.input) ? [config.input] : config.input,
|
|
114
|
-
plugins: config.plugins,
|
|
115
|
-
mode: config.mode,
|
|
116
|
-
resolve: config.resolve,
|
|
117
|
-
framework: config.framework,
|
|
118
|
-
...config
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/_internal/helpers/meta.ts
|
|
124
|
-
/**
|
|
125
|
-
* Generates a prefixed project root hash object.
|
|
126
|
-
*
|
|
127
|
-
* @remarks
|
|
128
|
-
* 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.
|
|
129
|
-
*
|
|
130
|
-
* @param name - The name of the project.
|
|
131
|
-
* @param rootHash - The hash of the project root.
|
|
132
|
-
* @returns An object containing the name and project root hash.
|
|
133
|
-
*/
|
|
134
|
-
function getPrefixedRootHash(name, rootHash) {
|
|
135
|
-
const combined = `${(0, _stryke_string_format_kebab_case.kebabCase)(name)}_${rootHash}`;
|
|
136
|
-
return combined.length > _powerlines_core_constants.ROOT_HASH_LENGTH ? combined.slice(0, _powerlines_core_constants.ROOT_HASH_LENGTH) : combined;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Writes the meta file for the context.
|
|
140
|
-
*
|
|
141
|
-
* @param context - The context to write the meta file for.
|
|
142
|
-
* @returns A promise that resolves when the meta file has been written.
|
|
143
|
-
*/
|
|
144
|
-
async function writeMetaFile(context) {
|
|
145
|
-
const metaFilePath = (0, _stryke_path_join_paths.joinPaths)(context.dataPath, "meta.json");
|
|
146
|
-
context.debug(`Writing runtime metadata to ${metaFilePath}`);
|
|
147
|
-
await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//#endregion
|
|
151
|
-
//#region src/_internal/ipc/send.ts
|
|
152
|
-
function formatWriteLogMessage(context, meta, message) {
|
|
153
|
-
const combinedMeta = {
|
|
154
|
-
...context.logger.options,
|
|
155
|
-
...(0, _stryke_type_checks_is_set_object.isSetObject)(meta) ? meta : { type: meta }
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
id: (0, _stryke_unique_id_uuid.uuid)(),
|
|
159
|
-
type: "write-log",
|
|
160
|
-
executionId: combinedMeta.executionId || context.options.executionId,
|
|
161
|
-
executionIndex: combinedMeta.executionIndex ?? context.options.executionIndex,
|
|
162
|
-
environment: combinedMeta.environment,
|
|
163
|
-
timestamp: Date.now(),
|
|
164
|
-
payload: {
|
|
165
|
-
meta: {
|
|
166
|
-
type: combinedMeta.type,
|
|
167
|
-
category: combinedMeta.category || _powerlines_core_constants.LogCategories.GENERAL,
|
|
168
|
-
logId: combinedMeta.logId || (0, _stryke_unique_id_uuid.uuid)(),
|
|
169
|
-
timestamp: combinedMeta.timestamp ?? Date.now(),
|
|
170
|
-
name: combinedMeta.name || context.config.name,
|
|
171
|
-
executionId: combinedMeta.executionId || context.options.executionId,
|
|
172
|
-
executionIndex: combinedMeta.executionIndex ?? context.options.executionIndex,
|
|
173
|
-
command: combinedMeta.command || context.config.command,
|
|
174
|
-
hook: combinedMeta.hook,
|
|
175
|
-
environment: combinedMeta.environment,
|
|
176
|
-
plugin: combinedMeta.plugin,
|
|
177
|
-
source: combinedMeta.source
|
|
178
|
-
},
|
|
179
|
-
message
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function childProcessSend(message) {
|
|
184
|
-
process.send?.(message);
|
|
185
|
-
}
|
|
186
|
-
function workerThreadSend(message) {
|
|
187
|
-
(0, jest_worker.messageParent)(message);
|
|
188
|
-
}
|
|
189
|
-
function send(message) {
|
|
190
|
-
if (process.env.POWERLINES_EXECUTION_THREAD_TYPE === "child-process") childProcessSend(message);
|
|
191
|
-
else if (process.env.POWERLINES_EXECUTION_THREAD_TYPE === "worker-thread") workerThreadSend(message);
|
|
192
|
-
else console.warn("No IPC mechanism available to send message:", message);
|
|
193
|
-
}
|
|
194
|
-
function sendWriteLogMessage(context, meta, message) {
|
|
195
|
-
send(formatWriteLogMessage(context, meta, message));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/_internal/helpers/constants.ts
|
|
200
|
-
const DEFAULT_EXTENSIONS = [
|
|
201
|
-
"js",
|
|
202
|
-
"ts",
|
|
203
|
-
"cjs",
|
|
204
|
-
"cts",
|
|
205
|
-
"mjs",
|
|
206
|
-
"mts",
|
|
207
|
-
"tsx",
|
|
208
|
-
"jsx",
|
|
209
|
-
"json",
|
|
210
|
-
"json5",
|
|
211
|
-
"jsonc",
|
|
212
|
-
"md",
|
|
213
|
-
"mdx"
|
|
214
|
-
];
|
|
215
|
-
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/_internal/vfs.ts
|
|
218
|
-
function toFilePath(path) {
|
|
219
|
-
return (0, _stryke_path_correct_path.correctPath)((0, _stryke_path_slash.slash)(path?.toString() || ".").replace(/^file:\/\//, ""));
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Checks if a given file id is valid based on the specified prefix.
|
|
223
|
-
*
|
|
224
|
-
* @param id - The file ID to check.
|
|
225
|
-
* @param prefix - The prefix to use for built-in files. Default is "powerlines".
|
|
226
|
-
* @returns `true` if the file ID is valid, otherwise `false`.
|
|
227
|
-
*/
|
|
228
|
-
function isValidId(id, prefix = "powerlines") {
|
|
229
|
-
return id.replace(/^\\0/, "").startsWith(`${prefix.replace(/:$/, "")}`);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Formats a file id by removing the file extension and prepended runtime prefix.
|
|
233
|
-
*
|
|
234
|
-
* @param id - The file ID to format.
|
|
235
|
-
* @param prefix - The prefix to use for built-in files. Default is "powerlines".
|
|
236
|
-
* @returns The formatted file ID.
|
|
237
|
-
*/
|
|
238
|
-
function normalizeId(id, prefix = "powerlines") {
|
|
239
|
-
return (0, _stryke_path_replace.replaceExtension)(toFilePath(id)).replace(/^\\0/, "").replace(/^powerlines:/, "").replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), "");
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
|
|
243
|
-
*
|
|
244
|
-
* @param path - The path to normalize.
|
|
245
|
-
* @param builtinsPath - The path to built-in files.
|
|
246
|
-
* @param prefix - The prefix to use for built-in files. Default is "powerlines".
|
|
247
|
-
* @returns The normalized path.
|
|
248
|
-
*/
|
|
249
|
-
function normalizePath(path, builtinsPath, prefix = "powerlines") {
|
|
250
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(path)) {
|
|
251
|
-
if (!(0, _stryke_type_checks_is_string.isString)(path)) throw new Error("Path type must be a string or a file descriptor");
|
|
252
|
-
throw new Error("Path cannot be empty");
|
|
253
|
-
}
|
|
254
|
-
return (0, _stryke_path_is_type.isAbsolutePath)(path) ? path : isValidId(toFilePath(path), prefix) ? normalizeId(toFilePath(path), prefix).replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), builtinsPath) : toFilePath(path);
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Normalizes glob patterns by resolving them against the workspace root.
|
|
258
|
-
*
|
|
259
|
-
* @param workspaceRoot - The root directory of the workspace.
|
|
260
|
-
* @param patterns - The glob patterns to normalize.
|
|
261
|
-
* @returns An array of normalized glob patterns.
|
|
262
|
-
*/
|
|
263
|
-
function normalizeGlobPatterns(workspaceRoot, patterns) {
|
|
264
|
-
return (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(patterns).map((pattern) => {
|
|
265
|
-
if ((0, _stryke_type_checks_is_set_object.isSetObject)(pattern) && ((0, _stryke_type_checks_is_set_string.isSetString)(pattern.input) || (0, _stryke_type_checks_is_set_string.isSetString)(pattern.glob))) return (0, _stryke_path_join.joinPaths)(pattern.input || workspaceRoot, pattern.glob || "**/*");
|
|
266
|
-
else if (!(0, _stryke_type_checks_is_set_string.isSetString)(pattern)) return;
|
|
267
|
-
return pattern;
|
|
268
|
-
}).filter(_stryke_type_checks_is_set_string.isSetString));
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Represents a virtual file system (VFS) that stores files and their associated metadata in virtual memory.
|
|
272
|
-
*
|
|
273
|
-
* @remarks
|
|
274
|
-
* This class provides methods to manage virtual files, check their existence, retrieve their content, and manipulate the virtual file system. It allows for efficient file management and retrieval without relying on the actual file system.
|
|
275
|
-
*/
|
|
276
|
-
var VirtualFileSystem = class VirtualFileSystem {
|
|
277
|
-
/**
|
|
278
|
-
* A map of virtual file IDs to their associated metadata.
|
|
279
|
-
*/
|
|
280
|
-
#metadata;
|
|
281
|
-
/**
|
|
282
|
-
* A map of underlying file paths to their virtual file IDs.
|
|
283
|
-
*/
|
|
284
|
-
#ids;
|
|
285
|
-
/**
|
|
286
|
-
* A map of virtual file IDs to their underlying file paths.
|
|
287
|
-
*/
|
|
288
|
-
#paths;
|
|
289
|
-
/**
|
|
290
|
-
* The unified volume that combines the virtual file system with the real file system.
|
|
291
|
-
*
|
|
292
|
-
* @remarks
|
|
293
|
-
* This volume allows for seamless access to both virtual and real files.
|
|
294
|
-
*/
|
|
295
|
-
#storage;
|
|
296
|
-
/**
|
|
297
|
-
* A cache for module resolution results.
|
|
298
|
-
*/
|
|
299
|
-
#resolverCache;
|
|
300
|
-
/**
|
|
301
|
-
* Indicator specifying if the virtual file system (VFS) is disposed
|
|
302
|
-
*/
|
|
303
|
-
#isDisposed = false;
|
|
304
|
-
/**
|
|
305
|
-
* The context of the virtual file system.
|
|
306
|
-
*/
|
|
307
|
-
#context;
|
|
308
|
-
/**
|
|
309
|
-
* The file system's logger client utility.
|
|
310
|
-
*/
|
|
311
|
-
#logger;
|
|
312
|
-
/**
|
|
313
|
-
* Normalizes a given module id by resolving it against the built-ins path.
|
|
314
|
-
*
|
|
315
|
-
* @param id - The module id to normalize.
|
|
316
|
-
* @returns The normalized module id.
|
|
317
|
-
*/
|
|
318
|
-
#normalizeId(id) {
|
|
319
|
-
let normalized = id;
|
|
320
|
-
if ((0, _stryke_path_is_parent_path.isParentPath)(normalized, this.#context.builtinsPath)) normalized = (0, _stryke_path_replace.replacePath)(normalized, this.#context.builtinsPath);
|
|
321
|
-
return normalizeId(normalized, this.#context.config.framework);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
|
|
325
|
-
*
|
|
326
|
-
* @param path - The path to normalize.
|
|
327
|
-
* @returns The normalized path.
|
|
328
|
-
*/
|
|
329
|
-
#normalizePath(path) {
|
|
330
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(path)) {
|
|
331
|
-
if (!(0, _stryke_type_checks_is_string.isString)(path)) throw new Error("Path type must be a string or a file descriptor");
|
|
332
|
-
throw new Error("Path cannot be empty");
|
|
333
|
-
}
|
|
334
|
-
return normalizePath(path.includes("{") || path.includes("}") ? (0, _powerlines_core_plugin_utils.replacePathTokens)(this.#context, path) : path, this.#context.builtinsPath, this.#context.config.framework);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Gets the storage adapter and relative key for a given key.
|
|
338
|
-
*
|
|
339
|
-
* @remarks
|
|
340
|
-
* The `key` can be either a path or a storage adapter name.
|
|
341
|
-
*
|
|
342
|
-
* @param key - The key to get the storage adapter for.
|
|
343
|
-
* @returns The storage adapter and relative key for the given key.
|
|
344
|
-
*/
|
|
345
|
-
#getStorage(key, preset) {
|
|
346
|
-
const path = this.resolveSync(this.#normalizePath(key)) || key;
|
|
347
|
-
for (const base of Object.keys(this.#storage).filter(Boolean).sort().reverse()) if ((path === base || (0, _stryke_path_is_parent_path.isParentPath)(path, base)) && (!preset || this.#storage[base]?.preset?.toLowerCase() === preset.toLowerCase())) return {
|
|
348
|
-
base,
|
|
349
|
-
relativeKey: (0, _stryke_path_replace.replacePath)(path, base),
|
|
350
|
-
adapter: this.#storage[base]
|
|
351
|
-
};
|
|
352
|
-
if (!preset || this.#storage[""]?.preset?.toLowerCase() === preset.toLowerCase()) return {
|
|
353
|
-
base: "",
|
|
354
|
-
relativeKey: path,
|
|
355
|
-
adapter: this.#storage[""]
|
|
356
|
-
};
|
|
357
|
-
this.#storage[path] = preset === "virtual" ? new require_storage_virtual.VirtualStorageAdapter(this.#context, { base: path }) : new require_storage_file_system.FileSystemStorageAdapter(this.#context, { base: path });
|
|
358
|
-
return {
|
|
359
|
-
base: path,
|
|
360
|
-
relativeKey: "",
|
|
361
|
-
adapter: this.#storage[path]
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Gets all storage adapters that match a given base key.
|
|
366
|
-
*
|
|
367
|
-
* @param base - The base key to match storage adapters against.
|
|
368
|
-
* @param includeParent - Whether to include parent storage adapters.
|
|
369
|
-
* @returns An array of storage adapters that match the given base key.
|
|
370
|
-
*/
|
|
371
|
-
#getStorages(base = "", includeParent = false) {
|
|
372
|
-
const baseKey = this.resolveSync(base) || base;
|
|
373
|
-
return Object.keys(this.#storage).sort().reverse().filter((key) => (0, _stryke_path_is_parent_path.isParentPath)(key, baseKey) || includeParent && (0, _stryke_path_is_parent_path.isParentPath)(baseKey, key) || baseKey.includes("*") && ((0, _stryke_path_is_parent_path.isParentPath)((0, _stryke_path_correct_path.stripStars)(baseKey), key) || (0, _stryke_path_glob_to_regex.globToRegex)((0, _stryke_path_replace.replaceExtension)(baseKey)).test(key))).map((key) => ({
|
|
374
|
-
relativeBase: baseKey.length > key.length ? baseKey.slice(key.length) : void 0,
|
|
375
|
-
base: key,
|
|
376
|
-
adapter: this.#storage[key]
|
|
377
|
-
}));
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* A helper function to resolve modules in the virtual file system (VFS).
|
|
381
|
-
*
|
|
382
|
-
* @remarks
|
|
383
|
-
* This function can be used to resolve modules relative to the project root directory.
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```ts
|
|
387
|
-
* const resolved = await context.resolvePath("some-module", "/path/to/importer");
|
|
388
|
-
* ```
|
|
389
|
-
*
|
|
390
|
-
* @param id - The module to resolve.
|
|
391
|
-
* @param importer - An optional path to the importer module.
|
|
392
|
-
* @param options - Additional resolution options.
|
|
393
|
-
* @returns A promise that resolves to the resolved module path.
|
|
394
|
-
*/
|
|
395
|
-
#innerResolve = async (id, importer, options = {}) => {
|
|
396
|
-
let path = id;
|
|
397
|
-
if (path.includes("{") || path.includes("}")) path = (0, _powerlines_core_plugin_utils.replacePathTokens)(this.#context, path);
|
|
398
|
-
if (options.skipAlias !== true) path = this.resolveAlias(path);
|
|
399
|
-
if ((0, _stryke_path_is_type.isAbsolutePath)(path) && (!options.isFile || !await this.isDirectory(path))) return path;
|
|
400
|
-
const resolverCacheKey = (0, _stryke_hash.murmurhash)({
|
|
401
|
-
path: this.#normalizeId(path),
|
|
402
|
-
importer,
|
|
403
|
-
options
|
|
404
|
-
});
|
|
405
|
-
let result;
|
|
406
|
-
if (!this.#context.config.skipCache) {
|
|
407
|
-
result = this.resolverCache.get(resolverCacheKey);
|
|
408
|
-
if (result) return result;
|
|
409
|
-
}
|
|
410
|
-
result = this.paths[this.#normalizeId(path)];
|
|
411
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) {
|
|
412
|
-
const paths = options.paths ?? [];
|
|
413
|
-
if (importer && !paths.includes(importer)) paths.push(importer);
|
|
414
|
-
if (!importer) {
|
|
415
|
-
paths.push(this.#context.config.cwd);
|
|
416
|
-
paths.push((0, _stryke_path_append.appendPath)(this.#context.config.root, this.#context.config.cwd));
|
|
417
|
-
paths.push((0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.#context.config.root, "src"), this.#context.config.cwd));
|
|
418
|
-
}
|
|
419
|
-
paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => (0, _stryke_path_append.appendPath)(tsconfigPath, this.#context.config.cwd)));
|
|
420
|
-
for (const combination of (0, _stryke_fs_resolve.getResolutionCombinations)(path, { paths: (0, _stryke_helpers_get_unique.getUnique)(paths) })) {
|
|
421
|
-
const { relativeKey, adapter } = this.#getStorage(combination);
|
|
422
|
-
if (await adapter.exists(relativeKey)) {
|
|
423
|
-
result = combination;
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) try {
|
|
428
|
-
result = await (0, _stryke_fs_resolve.resolve)(path, {
|
|
429
|
-
...options,
|
|
430
|
-
paths
|
|
431
|
-
});
|
|
432
|
-
} catch {}
|
|
433
|
-
}
|
|
434
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) {
|
|
435
|
-
if (!this.#context.config.skipCache) this.resolverCache.set(this.#normalizeId(path), result);
|
|
436
|
-
return result;
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
/**
|
|
440
|
-
* A synchronous helper function to resolve modules using the Jiti resolver
|
|
441
|
-
*
|
|
442
|
-
* @remarks
|
|
443
|
-
* This function can be used to resolve modules relative to the project root directory.
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* ```ts
|
|
447
|
-
* const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
|
|
448
|
-
* ```
|
|
449
|
-
*
|
|
450
|
-
* @param id - The module to resolve.
|
|
451
|
-
* @param importer - An optional path to the importer module.
|
|
452
|
-
* @param options - Additional resolution options.
|
|
453
|
-
* @returns The resolved module path.
|
|
454
|
-
*/
|
|
455
|
-
#innerResolveSync = (id, importer, options = {}) => {
|
|
456
|
-
let path = id;
|
|
457
|
-
if (path.includes("{") || path.includes("}")) path = (0, _powerlines_core_plugin_utils.replacePathTokens)(this.#context, path);
|
|
458
|
-
if (options.skipAlias !== true) path = this.resolveAlias(path);
|
|
459
|
-
if ((0, _stryke_path_is_type.isAbsolutePath)(path) && (!options.isFile || !this.isDirectorySync(path))) return path;
|
|
460
|
-
let result;
|
|
461
|
-
if (!this.#context.config.skipCache) {
|
|
462
|
-
result = this.resolverCache.get(this.#normalizeId(path));
|
|
463
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) return result;
|
|
464
|
-
}
|
|
465
|
-
result = this.paths[this.#normalizeId(path)];
|
|
466
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) {
|
|
467
|
-
const paths = options.paths ?? [];
|
|
468
|
-
if (importer && !paths.includes(importer)) paths.push(importer);
|
|
469
|
-
if (!importer) {
|
|
470
|
-
paths.push(this.#context.config.cwd);
|
|
471
|
-
paths.push((0, _stryke_path_append.appendPath)(this.#context.config.root, this.#context.config.cwd));
|
|
472
|
-
paths.push((0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.#context.config.root, "src"), this.#context.config.cwd));
|
|
473
|
-
}
|
|
474
|
-
paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => (0, _stryke_path_append.appendPath)(tsconfigPath, this.#context.config.cwd)));
|
|
475
|
-
for (const combination of (0, _stryke_fs_resolve.getResolutionCombinations)(path, { paths })) {
|
|
476
|
-
const { relativeKey, adapter } = this.#getStorage(combination);
|
|
477
|
-
if (adapter.existsSync(relativeKey)) {
|
|
478
|
-
result = combination;
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) try {
|
|
483
|
-
result = (0, _stryke_fs_resolve.resolveSync)(path, {
|
|
484
|
-
...options,
|
|
485
|
-
paths
|
|
486
|
-
});
|
|
487
|
-
} catch {}
|
|
488
|
-
}
|
|
489
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) {
|
|
490
|
-
if (!this.#context.config.skipCache) this.resolverCache.set(this.#normalizeId(path), result);
|
|
491
|
-
return result;
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
/**
|
|
495
|
-
* Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
|
|
496
|
-
*
|
|
497
|
-
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
498
|
-
* @returns A promise that resolves to a new virtual file system instance.
|
|
499
|
-
*/
|
|
500
|
-
static async create(context) {
|
|
501
|
-
context.debug("Starting virtual file system (VFS) initialization processes...");
|
|
502
|
-
let result;
|
|
503
|
-
if (!context.config.skipCache && (0, _stryke_fs_exists.existsSync)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"))) {
|
|
504
|
-
const buffer = await (0, _stryke_fs_buffer.readFileBuffer)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"));
|
|
505
|
-
const fs = new _stryke_capnp.Message(buffer, false).getRoot(require_fs.FileSystem);
|
|
506
|
-
result = new VirtualFileSystem(context, fs);
|
|
507
|
-
if (fs._hasStorage() && fs.storage.length > 0) await Promise.all(fs.storage.values().map(async (file) => {
|
|
508
|
-
if (file.path && file.code) {
|
|
509
|
-
let id;
|
|
510
|
-
if (fs._hasIds()) id = fs.ids.find((fileId) => fileId.path === file.path);
|
|
511
|
-
let metadata;
|
|
512
|
-
if (fs._hasMetadata()) metadata = fs.metadata.find((meta) => meta.id === result.#normalizeId(id?.id ?? file.path));
|
|
513
|
-
await result.write(file.path, file.code, { meta: {
|
|
514
|
-
id: result.#normalizeId(id?.id ?? metadata?.id ?? file.path),
|
|
515
|
-
type: metadata?.type || "normal",
|
|
516
|
-
properties: metadata?._hasProperties() ? metadata?.properties.values().reduce((ret, kvp) => {
|
|
517
|
-
ret[kvp.key] = kvp.value;
|
|
518
|
-
return ret;
|
|
519
|
-
}, {}) : void 0,
|
|
520
|
-
timestamp: metadata?.timestamp
|
|
521
|
-
} });
|
|
522
|
-
}
|
|
523
|
-
}));
|
|
524
|
-
} else result = new VirtualFileSystem(context, new _stryke_capnp.Message().initRoot(require_fs.FileSystem));
|
|
525
|
-
result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
|
|
526
|
-
return result;
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Synchronously creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
|
|
530
|
-
*
|
|
531
|
-
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
532
|
-
* @returns A new virtual file system instance.
|
|
533
|
-
*/
|
|
534
|
-
static createSync(context) {
|
|
535
|
-
context.debug("Starting virtual file system (VFS) initialization processes...");
|
|
536
|
-
let result;
|
|
537
|
-
if (!context.config.skipCache && (0, _stryke_fs_exists.existsSync)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"))) {
|
|
538
|
-
const buffer = (0, _stryke_fs_buffer.readFileBufferSync)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"));
|
|
539
|
-
const fs = new _stryke_capnp.Message(buffer, false).getRoot(require_fs.FileSystem);
|
|
540
|
-
result = new VirtualFileSystem(context, fs);
|
|
541
|
-
if (fs._hasStorage() && fs.storage.length > 0) fs.storage.values().forEach((file) => {
|
|
542
|
-
if (file.path && file.code) {
|
|
543
|
-
let id;
|
|
544
|
-
if (fs._hasIds()) id = fs.ids.find((fileId) => fileId.path === file.path);
|
|
545
|
-
let metadata;
|
|
546
|
-
if (fs._hasMetadata()) metadata = fs.metadata.find((meta) => meta.id === result.#normalizeId(id?.id ?? file.path));
|
|
547
|
-
result.writeSync(file.path, file.code, { meta: {
|
|
548
|
-
id: result.#normalizeId(id?.id ?? metadata?.id ?? file.path),
|
|
549
|
-
type: metadata?.type,
|
|
550
|
-
properties: metadata?._hasProperties() ? metadata?.properties.values().reduce((ret, kvp) => {
|
|
551
|
-
ret[kvp.key] = kvp.value;
|
|
552
|
-
return ret;
|
|
553
|
-
}, {}) : void 0,
|
|
554
|
-
timestamp: metadata?.timestamp
|
|
555
|
-
} });
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
} else result = new VirtualFileSystem(context, new _stryke_capnp.Message().initRoot(require_fs.FileSystem));
|
|
559
|
-
result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* A map of file ids to their metadata.
|
|
564
|
-
*/
|
|
565
|
-
get metadata() {
|
|
566
|
-
return new Proxy(this.#metadata, {
|
|
567
|
-
get: (target, prop) => {
|
|
568
|
-
return target[this.#normalizeId(prop)];
|
|
569
|
-
},
|
|
570
|
-
set: (target, prop, value) => {
|
|
571
|
-
target[this.#normalizeId(prop)] = value;
|
|
572
|
-
return true;
|
|
573
|
-
},
|
|
574
|
-
deleteProperty: (target, prop) => {
|
|
575
|
-
delete target[this.#normalizeId(prop)];
|
|
576
|
-
return true;
|
|
577
|
-
},
|
|
578
|
-
has: (target, prop) => {
|
|
579
|
-
return this.#normalizeId(prop) in target;
|
|
580
|
-
},
|
|
581
|
-
ownKeys: (target) => {
|
|
582
|
-
return (0, _stryke_helpers_get_unique.getUnique)(Reflect.ownKeys(target).map((key) => this.#normalizeId(key)));
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* A map of file paths to their module ids.
|
|
588
|
-
*/
|
|
589
|
-
get ids() {
|
|
590
|
-
return new Proxy(this.#ids, {
|
|
591
|
-
get: (target, prop) => {
|
|
592
|
-
return target[this.#normalizePath(prop)];
|
|
593
|
-
},
|
|
594
|
-
set: (target, prop, value) => {
|
|
595
|
-
target[this.#normalizePath(prop)] = value;
|
|
596
|
-
return true;
|
|
597
|
-
},
|
|
598
|
-
deleteProperty: (target, prop) => {
|
|
599
|
-
delete target[this.#normalizePath(prop)];
|
|
600
|
-
return true;
|
|
601
|
-
},
|
|
602
|
-
has: (target, prop) => {
|
|
603
|
-
return this.#normalizePath(prop) in target;
|
|
604
|
-
},
|
|
605
|
-
ownKeys: (target) => {
|
|
606
|
-
return (0, _stryke_helpers_get_unique.getUnique)(Reflect.ownKeys(target).map((key) => this.#normalizePath(key)));
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* A map of module ids to their file paths.
|
|
612
|
-
*/
|
|
613
|
-
get paths() {
|
|
614
|
-
return new Proxy(this.#paths, {
|
|
615
|
-
get: (target, prop) => {
|
|
616
|
-
return this.#normalizeId(prop) in target ? target[this.#normalizeId(prop)] : void 0;
|
|
617
|
-
},
|
|
618
|
-
set: (target, prop, value) => {
|
|
619
|
-
target[this.#normalizeId(prop)] = value;
|
|
620
|
-
return true;
|
|
621
|
-
},
|
|
622
|
-
deleteProperty: (target, prop) => {
|
|
623
|
-
delete target[this.#normalizeId(prop)];
|
|
624
|
-
return true;
|
|
625
|
-
},
|
|
626
|
-
has: (target, prop) => {
|
|
627
|
-
return this.#normalizeId(prop) in target;
|
|
628
|
-
},
|
|
629
|
-
ownKeys: (target) => {
|
|
630
|
-
return (0, _stryke_helpers_get_unique.getUnique)(Reflect.ownKeys(target).map((key) => this.#normalizeId(key)));
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Gets the resolver cache.
|
|
636
|
-
*/
|
|
637
|
-
get resolverCache() {
|
|
638
|
-
if (!this.#resolverCache) this.#resolverCache = (0, flat_cache.create)({
|
|
639
|
-
cacheId: "module-resolution",
|
|
640
|
-
cacheDir: this.#context.cachePath,
|
|
641
|
-
ttl: 2.5 * 60 * 1e3,
|
|
642
|
-
lruSize: 8e3,
|
|
643
|
-
persistInterval: 100
|
|
644
|
-
});
|
|
645
|
-
return this.#resolverCache;
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Creates a new instance of the {@link VirtualFileSystem}.
|
|
649
|
-
*
|
|
650
|
-
* @param context - The context of the virtual file system, typically containing options and logging functions.
|
|
651
|
-
* @param fs - A buffer containing the serialized virtual file system data.
|
|
652
|
-
*/
|
|
653
|
-
constructor(context, fs) {
|
|
654
|
-
this.#context = context;
|
|
655
|
-
this.#storage = { "": new require_storage_file_system.FileSystemStorageAdapter(context) };
|
|
656
|
-
if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.#context.config.output.storage)) this.#storage = {
|
|
657
|
-
...this.#storage,
|
|
658
|
-
...this.#context.config.output.storage
|
|
659
|
-
};
|
|
660
|
-
this.#storage.virtual ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: "/_virtual" });
|
|
661
|
-
this.#storage[this.#context.config.output.path] ??= new require_storage_file_system.FileSystemStorageAdapter(context, { base: this.#context.config.output.path });
|
|
662
|
-
if (this.#context.config.output.copy && this.#context.config.output.copy.path) this.#storage[this.#context.config.output.copy.path] ??= new require_storage_file_system.FileSystemStorageAdapter(context, { base: this.#context.config.output.copy.path });
|
|
663
|
-
if (this.#context.config.output.storage !== "fs") {
|
|
664
|
-
this.#storage[this.#context.artifactsPath] ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: this.#context.artifactsPath });
|
|
665
|
-
this.#storage[this.#context.builtinsPath] ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: this.#context.builtinsPath });
|
|
666
|
-
this.#storage[this.#context.entryPath] ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: this.#context.entryPath });
|
|
667
|
-
}
|
|
668
|
-
this.#metadata = {};
|
|
669
|
-
if (fs._hasMetadata()) this.#metadata = fs.metadata.values().reduce((ret, metadata) => {
|
|
670
|
-
ret[metadata.id] = {
|
|
671
|
-
id: metadata.id,
|
|
672
|
-
type: metadata.type,
|
|
673
|
-
timestamp: metadata.timestamp ?? Date.now(),
|
|
674
|
-
properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret, item) => {
|
|
675
|
-
ret[item.key] = item.value;
|
|
676
|
-
return ret;
|
|
677
|
-
}, {}) : {}
|
|
678
|
-
};
|
|
679
|
-
return ret;
|
|
680
|
-
}, {});
|
|
681
|
-
this.#ids = {};
|
|
682
|
-
this.#paths = {};
|
|
683
|
-
if (fs._hasIds()) {
|
|
684
|
-
this.#ids = fs.ids.values().reduce((ret, identifier) => {
|
|
685
|
-
ret[identifier.path] ??= identifier.id;
|
|
686
|
-
return ret;
|
|
687
|
-
}, {});
|
|
688
|
-
this.#paths = fs.ids.values().reduce((ret, identifier) => {
|
|
689
|
-
ret[identifier.id] ??= identifier.path;
|
|
690
|
-
return ret;
|
|
691
|
-
}, {});
|
|
692
|
-
}
|
|
693
|
-
this.#logger = context.extendLogger({ category: "fs" });
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Asynchronously checks if a file exists in the virtual file system (VFS).
|
|
697
|
-
*
|
|
698
|
-
* @param path - The path to the file.
|
|
699
|
-
* @returns A promise that resolves to `true` if the file exists, otherwise `false`.
|
|
700
|
-
*/
|
|
701
|
-
async exists(path) {
|
|
702
|
-
const { relativeKey, adapter } = this.#getStorage(path);
|
|
703
|
-
return adapter.exists(relativeKey);
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* Synchronously checks if a file exists in the virtual file system (VFS).
|
|
707
|
-
*
|
|
708
|
-
* @param path - The path to the file.
|
|
709
|
-
* @returns `true` if the file exists, otherwise `false`.
|
|
710
|
-
*/
|
|
711
|
-
existsSync(path) {
|
|
712
|
-
const { relativeKey, adapter } = this.#getStorage(path);
|
|
713
|
-
return adapter.existsSync(relativeKey);
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Checks if a file is virtual in the virtual file system (VFS).
|
|
717
|
-
*
|
|
718
|
-
* @param path - The path to the file.
|
|
719
|
-
* @param importer - An optional path to the importer module.
|
|
720
|
-
* @param options - Additional resolution options.
|
|
721
|
-
* @returns `true` if the file is virtual, otherwise `false`.
|
|
722
|
-
*/
|
|
723
|
-
isVirtual(path, importer, options) {
|
|
724
|
-
const resolved = this.resolveSync(path, importer, options);
|
|
725
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
|
|
726
|
-
if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
|
|
727
|
-
return false;
|
|
728
|
-
}
|
|
729
|
-
return this.#getStorage(resolved)?.adapter?.preset === "virtual" || resolved.startsWith(`${this.#context.config.framework}:`) || path.startsWith(`${this.#context.config.framework}:`);
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* Checks if a path is a directory in the virtual file system (VFS).
|
|
733
|
-
*
|
|
734
|
-
* @param path - The path to check.
|
|
735
|
-
* @param importer - An optional path to the importer module.
|
|
736
|
-
* @param options - Additional resolution options.
|
|
737
|
-
* @returns `true` if the path is a directory, otherwise `false`.
|
|
738
|
-
*/
|
|
739
|
-
isDirectorySync(path, importer, options) {
|
|
740
|
-
const resolved = this.resolveSync(path, importer, options);
|
|
741
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
|
|
742
|
-
if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
|
|
743
|
-
return false;
|
|
744
|
-
}
|
|
745
|
-
return !!(this.existsSync(resolved) && this.#getStorage(resolved)?.adapter?.isDirectorySync(resolved));
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Checks if a path is a directory in the virtual file system (VFS).
|
|
749
|
-
*
|
|
750
|
-
* @param path - The path to check.
|
|
751
|
-
* @param importer - An optional path to the importer module.
|
|
752
|
-
* @param options - Additional resolution options.
|
|
753
|
-
* @returns `true` if the path is a directory, otherwise `false`.
|
|
754
|
-
*/
|
|
755
|
-
async isDirectory(path, importer, options) {
|
|
756
|
-
const resolved = await this.resolve(path, importer, options);
|
|
757
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
|
|
758
|
-
if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
|
|
759
|
-
return false;
|
|
760
|
-
}
|
|
761
|
-
return !!(await this.exists(resolved) && await this.#getStorage(resolved)?.adapter?.isDirectory(resolved));
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Checks if a path is a file in the virtual file system (VFS).
|
|
765
|
-
*
|
|
766
|
-
* @param path - The path to check.
|
|
767
|
-
* @param importer - An optional path to the importer module.
|
|
768
|
-
* @param options - Additional resolution options.
|
|
769
|
-
* @returns `true` if the path is a file, otherwise `false`.
|
|
770
|
-
*/
|
|
771
|
-
isFileSync(path, importer, options) {
|
|
772
|
-
const resolved = this.resolveSync(path, importer, options);
|
|
773
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
|
|
774
|
-
if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
|
|
775
|
-
return false;
|
|
776
|
-
}
|
|
777
|
-
return this.#getStorage(resolved)?.adapter?.isFileSync(resolved) ?? false;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Checks if a path is a file in the virtual file system (VFS).
|
|
781
|
-
*
|
|
782
|
-
* @param path - The path to check.
|
|
783
|
-
* @param importer - An optional path to the importer module.
|
|
784
|
-
* @param options - Additional resolution options.
|
|
785
|
-
* @returns `true` if the path is a file, otherwise `false`.
|
|
786
|
-
*/
|
|
787
|
-
async isFile(path, importer, options) {
|
|
788
|
-
const resolved = await this.resolve(path, importer, options);
|
|
789
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
|
|
790
|
-
if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
|
|
791
|
-
return false;
|
|
792
|
-
}
|
|
793
|
-
return await this.#getStorage(resolved)?.adapter?.isFile(resolved) ?? false;
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Checks if a file Id must be resolved by the virtual file system (VFS).
|
|
797
|
-
*
|
|
798
|
-
* @remarks
|
|
799
|
-
* Examples of file Ids that would be considered virtual include:
|
|
800
|
-
* - Ids that start with the framework specific prefix (e.g. `powerlines:`)
|
|
801
|
-
* - Ids that match a configured alias for virtual modules (returned true from {@link VirtualFileSystemInterface.isVirtual})
|
|
802
|
-
*
|
|
803
|
-
* @param path - The path or id of the file.
|
|
804
|
-
* @param importer - An optional path to the importer module, used for resolving the file path.
|
|
805
|
-
* @param options - Additional options for resolving the file path.
|
|
806
|
-
* @returns `true` if the file is virtual, otherwise `false`.
|
|
807
|
-
*/
|
|
808
|
-
isResolvableId(path, importer, options) {
|
|
809
|
-
return path.startsWith(`${this.#context.config.framework}:`) || this.isVirtual(path, importer, options) || this.isAlias(path) || this.isTsconfigPath(path);
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Lists files in a given path.
|
|
813
|
-
*
|
|
814
|
-
* @param path - The path to list files from.
|
|
815
|
-
* @returns An array of file names in the specified path.
|
|
816
|
-
*/
|
|
817
|
-
listSync(path) {
|
|
818
|
-
let resolvedPath = path;
|
|
819
|
-
if (resolvedPath.includes("*")) {
|
|
820
|
-
this.#logger.warn(`Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
|
|
821
|
-
resolvedPath = (0, _stryke_path_correct_path.stripStars)(resolvedPath);
|
|
822
|
-
}
|
|
823
|
-
return (0, _stryke_helpers_get_unique.getUnique)(this.#getStorages(resolvedPath, true).map((storage) => storage.adapter.listSync(storage.relativeBase ? storage.base ? (0, _stryke_path_append.appendPath)(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)).flat().filter(Boolean));
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Lists files in a given path.
|
|
827
|
-
*
|
|
828
|
-
* @param path - The path to list files from.
|
|
829
|
-
* @returns An array of file names in the specified path.
|
|
830
|
-
*/
|
|
831
|
-
async list(path) {
|
|
832
|
-
let resolvedPath = path;
|
|
833
|
-
if (resolvedPath.includes("*")) {
|
|
834
|
-
this.#logger.warn(`Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
|
|
835
|
-
resolvedPath = (0, _stryke_path_correct_path.stripStars)(resolvedPath);
|
|
836
|
-
}
|
|
837
|
-
return (0, _stryke_helpers_get_unique.getUnique)((await Promise.all(this.#getStorages(resolvedPath, true).map(async (storage) => storage.adapter.list(storage.relativeBase ? storage.base ? (0, _stryke_path_append.appendPath)(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)))).flat().filter(Boolean));
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* Removes a file in the virtual file system (VFS).
|
|
841
|
-
*
|
|
842
|
-
* @param path - The path to create the directory at.
|
|
843
|
-
*/
|
|
844
|
-
async remove(path) {
|
|
845
|
-
const normalizedPath = this.#normalizePath(path);
|
|
846
|
-
this.#logger.trace(`Removing file: ${normalizedPath}`);
|
|
847
|
-
const { relativeKey, adapter } = this.#getStorage(normalizedPath);
|
|
848
|
-
if ((0, _stryke_path_file_path_fns.hasFileExtension)(normalizedPath)) await adapter.remove(relativeKey);
|
|
849
|
-
else await adapter.clear(relativeKey);
|
|
850
|
-
const id = this.#ids[normalizedPath];
|
|
851
|
-
if (id && this.#metadata[id]) {
|
|
852
|
-
delete this.#metadata[id];
|
|
853
|
-
delete this.#ids[normalizedPath];
|
|
854
|
-
delete this.#paths[id];
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Removes a file in the virtual file system (VFS).
|
|
859
|
-
*
|
|
860
|
-
* @param path - The path to create the directory at.
|
|
861
|
-
*/
|
|
862
|
-
removeSync(path) {
|
|
863
|
-
const normalizedPath = this.#normalizePath(path);
|
|
864
|
-
this.#logger.trace(`Removing file: ${normalizedPath}`);
|
|
865
|
-
const { relativeKey, adapter } = this.#getStorage(normalizedPath);
|
|
866
|
-
if ((0, _stryke_path_file_path_fns.hasFileExtension)(normalizedPath)) adapter.removeSync(relativeKey);
|
|
867
|
-
else adapter.clearSync(relativeKey);
|
|
868
|
-
const id = this.#ids[normalizedPath];
|
|
869
|
-
if (id && this.#metadata[id]) {
|
|
870
|
-
delete this.#metadata[id];
|
|
871
|
-
delete this.#ids[normalizedPath];
|
|
872
|
-
delete this.#paths[id];
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Glob files in the virtual file system (VFS) based on the provided pattern(s).
|
|
877
|
-
*
|
|
878
|
-
* @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
|
|
879
|
-
* @returns An array of file paths matching the provided pattern(s)
|
|
880
|
-
*/
|
|
881
|
-
async glob(patterns) {
|
|
882
|
-
const results = [];
|
|
883
|
-
for (const pattern of normalizeGlobPatterns(this.#context.config.cwd, patterns)) {
|
|
884
|
-
const normalized = this.#normalizePath(pattern);
|
|
885
|
-
if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("*")) if (this.isDirectorySync(normalized)) results.push(...await this.list(normalized));
|
|
886
|
-
else {
|
|
887
|
-
const resolved = await this.resolve(normalized);
|
|
888
|
-
if (resolved && !results.includes(resolved)) results.push(resolved);
|
|
889
|
-
}
|
|
890
|
-
else {
|
|
891
|
-
const absPattern = (0, _stryke_path_is_type.isAbsolutePath)(normalized) ? normalized : this.#normalizePath((0, _stryke_path_append.appendPath)(normalized, this.#context.config.cwd));
|
|
892
|
-
await Promise.all((await this.list((0, _stryke_path_correct_path.stripStars)(absPattern))).map(async (file) => {
|
|
893
|
-
if ((0, _stryke_path_glob_to_regex.globToRegex)(absPattern).test(file)) {
|
|
894
|
-
const resolved = await this.resolve(file);
|
|
895
|
-
if (resolved && !results.includes(resolved)) results.push(resolved);
|
|
896
|
-
}
|
|
897
|
-
}));
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return results;
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
|
|
904
|
-
*
|
|
905
|
-
* @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
|
|
906
|
-
* @returns An array of file paths matching the provided pattern(s)
|
|
907
|
-
*/
|
|
908
|
-
globSync(patterns) {
|
|
909
|
-
const results = [];
|
|
910
|
-
for (const pattern of normalizeGlobPatterns(this.#context.config.cwd, patterns)) {
|
|
911
|
-
const normalized = this.#normalizePath(pattern);
|
|
912
|
-
if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("*")) if (this.isDirectorySync(normalized)) results.push(...this.listSync(normalized));
|
|
913
|
-
else {
|
|
914
|
-
const resolved = this.resolveSync(normalized);
|
|
915
|
-
if (resolved && !results.includes(resolved)) results.push(resolved);
|
|
916
|
-
}
|
|
917
|
-
else {
|
|
918
|
-
const absPattern = (0, _stryke_path_is_type.isAbsolutePath)(normalized) ? normalized : this.#normalizePath((0, _stryke_path_append.appendPath)(normalized, this.#context.config.cwd));
|
|
919
|
-
const files = this.listSync((0, _stryke_path_correct_path.stripStars)(absPattern));
|
|
920
|
-
for (const file of files) if ((0, _stryke_path_glob_to_regex.globToRegex)(absPattern).test(file)) {
|
|
921
|
-
const resolved = this.resolveSync(file);
|
|
922
|
-
if (resolved && !results.includes(resolved)) results.push(resolved);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return results;
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
|
-
* Copies a file from one path to another in the virtual file system (VFS).
|
|
930
|
-
*
|
|
931
|
-
* @param srcPath - The source path to copy
|
|
932
|
-
* @param destPath - The destination path to copy to
|
|
933
|
-
*/
|
|
934
|
-
async copy(srcPath, destPath) {
|
|
935
|
-
const src = srcPath instanceof URL ? (0, node_url.fileURLToPath)(srcPath) : srcPath;
|
|
936
|
-
const dest = destPath instanceof URL ? (0, node_url.fileURLToPath)(destPath) : destPath;
|
|
937
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(src) && (!(0, _stryke_type_checks_is_set_object.isSetObject)(src) || !(0, _stryke_type_checks_is_set_string.isSetString)(src.input)) || !(0, _stryke_type_checks_is_set_string.isSetString)(dest)) return;
|
|
938
|
-
const sourceStr = (0, _stryke_type_checks_is_string.isString)(src) ? src : src.input ? src.input : this.#context.config.cwd;
|
|
939
|
-
const source = await this.resolve(sourceStr);
|
|
940
|
-
if (!source) return;
|
|
941
|
-
if (this.isDirectorySync(source) || (0, _stryke_type_checks_is_set_string.isSetString)(src) && src.includes("*") || (0, _stryke_type_checks_is_set_object.isSetObject)(src) && (0, _stryke_type_checks_is_set_string.isSetString)(src.glob)) await Promise.all((await this.glob(src)).map(async (file) => {
|
|
942
|
-
return this.copy(file, (0, _stryke_path_append.appendPath)((0, _stryke_path_replace.replacePath)(file, sourceStr), dest));
|
|
943
|
-
}));
|
|
944
|
-
else {
|
|
945
|
-
const content = await this.read(source);
|
|
946
|
-
if (content !== void 0) await this.write(this.#normalizePath(dest), content, { skipFormat: true });
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Synchronously copies a file from one path to another in the virtual file system (VFS).
|
|
951
|
-
*
|
|
952
|
-
* @param srcPath - The source path to copy
|
|
953
|
-
* @param destPath - The destination path to copy to
|
|
954
|
-
*/
|
|
955
|
-
copySync(srcPath, destPath) {
|
|
956
|
-
const src = srcPath instanceof URL ? (0, node_url.fileURLToPath)(srcPath) : srcPath;
|
|
957
|
-
const dest = destPath instanceof URL ? (0, node_url.fileURLToPath)(destPath) : destPath;
|
|
958
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(src) && (!(0, _stryke_type_checks_is_set_object.isSetObject)(src) || !(0, _stryke_type_checks_is_set_string.isSetString)(src.input)) || !(0, _stryke_type_checks_is_set_string.isSetString)(dest)) return;
|
|
959
|
-
const sourceStr = (0, _stryke_type_checks_is_string.isString)(src) ? src : src.input ? src.input : this.#context.config.cwd;
|
|
960
|
-
const source = this.resolveSync(sourceStr);
|
|
961
|
-
if (!source) return;
|
|
962
|
-
if (this.isDirectorySync(source) || (0, _stryke_type_checks_is_set_string.isSetString)(src) && src.includes("*") || (0, _stryke_type_checks_is_set_object.isSetObject)(src) && (0, _stryke_type_checks_is_set_string.isSetString)(src.glob)) this.globSync(src).map((file) => {
|
|
963
|
-
return this.copySync(file, (0, _stryke_path_append.appendPath)((0, _stryke_path_file_path_fns.findFilePath)((0, _stryke_path_replace.replacePath)(file, sourceStr)), dest));
|
|
964
|
-
});
|
|
965
|
-
else {
|
|
966
|
-
const content = this.readSync(source);
|
|
967
|
-
if (content !== void 0) this.writeSync(this.#normalizePath((0, _stryke_path_file_path_fns.hasFileExtension)(dest) ? dest : (0, _stryke_path_append.appendPath)((0, _stryke_path_file_path_fns.findFileName)(source), dest)), content, { skipFormat: true });
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Moves a file (or files) from one path to another in the virtual file system (VFS).
|
|
972
|
-
*
|
|
973
|
-
* @param srcPath - The source path to move
|
|
974
|
-
* @param destPath - The destination path to move to
|
|
975
|
-
*/
|
|
976
|
-
async move(srcPath, destPath) {
|
|
977
|
-
if ((0, _stryke_path_file_path_fns.hasFileExtension)(srcPath)) {
|
|
978
|
-
await this.copy(srcPath, destPath);
|
|
979
|
-
await this.remove(srcPath);
|
|
980
|
-
} else await Promise.all((await this.list(srcPath)).map(async (file) => {
|
|
981
|
-
await this.copy(file, destPath);
|
|
982
|
-
await this.remove(file);
|
|
983
|
-
}));
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Synchronously moves a file (or files) from one path to another in the virtual file system (VFS).
|
|
987
|
-
*
|
|
988
|
-
* @param srcPath - The source path to move
|
|
989
|
-
* @param destPath - The destination path to move to
|
|
990
|
-
*/
|
|
991
|
-
moveSync(srcPath, destPath) {
|
|
992
|
-
if ((0, _stryke_path_file_path_fns.hasFileExtension)(srcPath)) {
|
|
993
|
-
this.copySync(srcPath, destPath);
|
|
994
|
-
this.removeSync(srcPath);
|
|
995
|
-
} else this.listSync(srcPath).forEach((file) => {
|
|
996
|
-
this.copySync(file, destPath);
|
|
997
|
-
this.removeSync(file);
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Asynchronously reads a file from the virtual file system (VFS).
|
|
1002
|
-
*
|
|
1003
|
-
* @param path - The path or ID of the file to read.
|
|
1004
|
-
* @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
|
|
1005
|
-
*/
|
|
1006
|
-
async read(path) {
|
|
1007
|
-
const filePath = await this.resolve(path, void 0, { isFile: true });
|
|
1008
|
-
if (!filePath || !this.existsSync(filePath)) return;
|
|
1009
|
-
const { adapter } = this.#getStorage(filePath);
|
|
1010
|
-
this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
|
|
1011
|
-
return await adapter.get(filePath) ?? void 0;
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* Synchronously reads a file from the virtual file system (VFS).
|
|
1015
|
-
*
|
|
1016
|
-
* @param path - The path or ID of the file to read.
|
|
1017
|
-
* @returns The contents of the file as a string, or undefined if the file does not exist.
|
|
1018
|
-
*/
|
|
1019
|
-
readSync(path) {
|
|
1020
|
-
const filePath = this.resolveSync(path, void 0, { isFile: true });
|
|
1021
|
-
if (!filePath || !this.existsSync(filePath)) return;
|
|
1022
|
-
const { adapter } = this.#getStorage(filePath);
|
|
1023
|
-
this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
|
|
1024
|
-
return adapter.getSync(filePath) ?? void 0;
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Writes a file to the virtual file system (VFS).
|
|
1028
|
-
*
|
|
1029
|
-
* @param path - The path to the file.
|
|
1030
|
-
* @param data - The contents of the file.
|
|
1031
|
-
* @param options - Optional parameters for writing the file.
|
|
1032
|
-
* @returns A promise that resolves when the file is written.
|
|
1033
|
-
*/
|
|
1034
|
-
async write(path, data = "", options = {}) {
|
|
1035
|
-
const meta = options.meta ?? {};
|
|
1036
|
-
const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
|
|
1037
|
-
const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
|
|
1038
|
-
this.#logger.trace(`Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, _stryke_convert_to_array.toArray)(data)).size)})`);
|
|
1039
|
-
let code = data;
|
|
1040
|
-
try {
|
|
1041
|
-
if (!options.skipFormat) code = await (0, _powerlines_core_lib_utilities_format.format)(this.#context, resolvedPath, data);
|
|
1042
|
-
} catch (err) {
|
|
1043
|
-
if (DEFAULT_EXTENSIONS.includes((0, _stryke_path_file_path_fns.findFileExtensionSafe)(resolvedPath, { fullExtension: true }))) this.#logger.warn(`Failed to format file ${resolvedPath} before writing: ${err.message}`);
|
|
1044
|
-
code = data;
|
|
1045
|
-
}
|
|
1046
|
-
this.#logger.trace(`Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, _stryke_convert_to_array.toArray)(code)).size)})`);
|
|
1047
|
-
const id = this.#normalizeId(meta.id || resolvedPath);
|
|
1048
|
-
this.metadata[id] = {
|
|
1049
|
-
type: "normal",
|
|
1050
|
-
timestamp: Date.now(),
|
|
1051
|
-
...this.metadata[id] ?? {},
|
|
1052
|
-
...meta
|
|
1053
|
-
};
|
|
1054
|
-
this.paths[id] = resolvedPath;
|
|
1055
|
-
this.ids[resolvedPath] = id;
|
|
1056
|
-
return adapter.set(relativeKey, code);
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* Synchronously writes a file to the virtual file system (VFS).
|
|
1060
|
-
*
|
|
1061
|
-
* @param path - The file to write.
|
|
1062
|
-
* @param data - The contents of the file.
|
|
1063
|
-
* @param options - Optional parameters for writing the file.
|
|
1064
|
-
*/
|
|
1065
|
-
writeSync(path, data = "", options = {}) {
|
|
1066
|
-
const meta = options.meta ?? {};
|
|
1067
|
-
const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
|
|
1068
|
-
const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
|
|
1069
|
-
this.#logger.trace(`Writing ${resolvedPath} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, _stryke_convert_to_array.toArray)(data)).size)})`);
|
|
1070
|
-
const id = this.#normalizeId(meta.id || resolvedPath);
|
|
1071
|
-
this.metadata[id] = {
|
|
1072
|
-
type: "normal",
|
|
1073
|
-
timestamp: Date.now(),
|
|
1074
|
-
...this.metadata[id] ?? {},
|
|
1075
|
-
...meta
|
|
1076
|
-
};
|
|
1077
|
-
this.paths[id] = resolvedPath;
|
|
1078
|
-
this.ids[resolvedPath] = id;
|
|
1079
|
-
return adapter.setSync(relativeKey, data);
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* Synchronously creates a directory at the specified path.
|
|
1083
|
-
*
|
|
1084
|
-
* @param dirPath - The path of the directory to create.
|
|
1085
|
-
*/
|
|
1086
|
-
mkdirSync(dirPath) {
|
|
1087
|
-
return this.#getStorage(dirPath)?.adapter?.mkdirSync(dirPath);
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Creates a directory at the specified path.
|
|
1091
|
-
*
|
|
1092
|
-
* @param path - The path of the directory to create.
|
|
1093
|
-
*/
|
|
1094
|
-
async mkdir(path) {
|
|
1095
|
-
return this.#getStorage(path)?.adapter?.mkdir(path);
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Retrieves the metadata of a file in the virtual file system (VFS).
|
|
1099
|
-
*
|
|
1100
|
-
* @param pathOrId - The path or ID of the file to retrieve metadata for.
|
|
1101
|
-
* @returns The metadata of the file, or undefined if the file does not exist.
|
|
1102
|
-
*/
|
|
1103
|
-
getMetadata(pathOrId) {
|
|
1104
|
-
const resolved = this.resolveSync(pathOrId);
|
|
1105
|
-
if (resolved && this.metadata[resolved]) return this.metadata[resolved];
|
|
1106
|
-
}
|
|
1107
|
-
/**
|
|
1108
|
-
* Resolves a given module ID using the configured aliases.
|
|
1109
|
-
*
|
|
1110
|
-
* @remarks
|
|
1111
|
-
* This function can be used to map module IDs to different paths based on the alias configuration.
|
|
1112
|
-
*
|
|
1113
|
-
* @param id - The module ID to resolve.
|
|
1114
|
-
* @returns The resolved module ID - after applying any configured aliases (this will be the same as the input ID if no aliases match).
|
|
1115
|
-
*/
|
|
1116
|
-
resolveAlias(id) {
|
|
1117
|
-
let path = id;
|
|
1118
|
-
if (this.#context.config.resolve.alias) {
|
|
1119
|
-
if (Array.isArray(this.#context.config.resolve.alias) && this.#context.config.resolve.alias.length > 0) {
|
|
1120
|
-
const found = this.#context.config.resolve.alias.filter((alias) => (0, _stryke_type_checks_is_set_string.isSetString)(alias.find) && (alias.find === path || path.startsWith(`${alias.find}/`)) || (0, _stryke_type_checks_is_regexp.isRegExp)(alias.find) && alias.find.test(path));
|
|
1121
|
-
if (found.length > 0) {
|
|
1122
|
-
const alias = found.reduce((ret, current) => {
|
|
1123
|
-
return ((0, _stryke_type_checks_is_set_string.isSetString)(ret.find) ? ret.find.length : (0, _stryke_type_checks_is_regexp.isRegExp)(ret.find) ? ret.find.source.length : 0) > ((0, _stryke_type_checks_is_set_string.isSetString)(current.find) ? current.find.length : (0, _stryke_type_checks_is_regexp.isRegExp)(current.find) ? current.find.source.length : 0) ? ret : current;
|
|
1124
|
-
});
|
|
1125
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(alias.find)) path = path.replace(new RegExp(`^${alias.find}`), alias.replacement);
|
|
1126
|
-
else if ((0, _stryke_type_checks_is_regexp.isRegExp)(alias.find)) path = path.replace(alias.find, alias.replacement);
|
|
1127
|
-
}
|
|
1128
|
-
} else if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.#context.config.resolve.alias)) {
|
|
1129
|
-
const found = Object.keys(this.#context.config.resolve.alias).filter((key) => key === path || path.startsWith(`${key}/`));
|
|
1130
|
-
if (found.length > 0) {
|
|
1131
|
-
const alias = found.reduce((ret, current) => {
|
|
1132
|
-
return ret.length > current.length ? ret : current;
|
|
1133
|
-
});
|
|
1134
|
-
path = path.replace(new RegExp(`^${alias}`), this.#context.config.resolve.alias[alias]);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
return path;
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Checks if a given module ID is an alias.
|
|
1142
|
-
*
|
|
1143
|
-
* @remarks
|
|
1144
|
-
* This function can be used to determine if a module ID matches any configured aliases.
|
|
1145
|
-
*
|
|
1146
|
-
* @param id - The module ID to check.
|
|
1147
|
-
* @returns A boolean indicating whether the module ID is an alias.
|
|
1148
|
-
*/
|
|
1149
|
-
isAlias(id) {
|
|
1150
|
-
const path = id;
|
|
1151
|
-
if (this.#context.config.resolve.alias) {
|
|
1152
|
-
if (Array.isArray(this.#context.config.resolve.alias) && this.#context.config.resolve.alias.length > 0) return this.#context.config.resolve.alias.filter((alias) => (0, _stryke_type_checks_is_set_string.isSetString)(alias.find) && (alias.find === path || path.startsWith(`${alias.find}/`)) || (0, _stryke_type_checks_is_regexp.isRegExp)(alias.find) && alias.find.test(path)).length > 0;
|
|
1153
|
-
else if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.#context.config.resolve.alias)) return Object.keys(this.#context.config.resolve.alias).filter((key) => key === path || path.startsWith(`${key}/`)).length > 0;
|
|
1154
|
-
}
|
|
1155
|
-
return false;
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Checks if a given module ID is a tsconfig path.
|
|
1159
|
-
*
|
|
1160
|
-
* @remarks
|
|
1161
|
-
* This function can be used to determine if a module ID matches any configured tsconfig paths.
|
|
1162
|
-
*
|
|
1163
|
-
* @param id - The module ID to check.
|
|
1164
|
-
* @returns A boolean indicating whether the module ID is a tsconfig path.
|
|
1165
|
-
*/
|
|
1166
|
-
isTsconfigPath(id) {
|
|
1167
|
-
return !!(this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).length > 0 && (0, bundle_require.match)(id, this.#context.resolvePatterns));
|
|
1168
|
-
}
|
|
1169
|
-
/**
|
|
1170
|
-
* A helper function to resolve modules in the virtual file system (VFS).
|
|
1171
|
-
*
|
|
1172
|
-
* @remarks
|
|
1173
|
-
* This function can be used to resolve modules relative to the project root directory.
|
|
1174
|
-
*
|
|
1175
|
-
* @example
|
|
1176
|
-
* ```ts
|
|
1177
|
-
* const resolved = await context.resolvePath("some-module", "/path/to/importer");
|
|
1178
|
-
* ```
|
|
1179
|
-
*
|
|
1180
|
-
* @param id - The module to resolve.
|
|
1181
|
-
* @param importer - An optional path to the importer module.
|
|
1182
|
-
* @param options - Additional resolution options.
|
|
1183
|
-
* @returns A promise that resolves to the resolved module path.
|
|
1184
|
-
*/
|
|
1185
|
-
async resolve(id, importer, options = {}) {
|
|
1186
|
-
const origResult = await this.#innerResolve(id, importer, options);
|
|
1187
|
-
if (origResult && options.isFile && await this.isDirectory(origResult)) {
|
|
1188
|
-
const indexResult = await this.resolve((0, _stryke_path_join.joinPaths)(origResult, "index"), importer, options);
|
|
1189
|
-
if (indexResult) return indexResult;
|
|
1190
|
-
if (!(0, _stryke_path_file_path_fns.hasFileExtension)(origResult)) for (const ext of DEFAULT_EXTENSIONS) {
|
|
1191
|
-
const extResult = await this.resolve(`${origResult}.${ext}`, importer, options);
|
|
1192
|
-
if (extResult) return extResult;
|
|
1193
|
-
}
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
return origResult;
|
|
1197
|
-
}
|
|
1198
|
-
/**
|
|
1199
|
-
* A synchronous helper function to resolve modules using the Jiti resolver
|
|
1200
|
-
*
|
|
1201
|
-
* @remarks
|
|
1202
|
-
* This function can be used to resolve modules relative to the project root directory.
|
|
1203
|
-
*
|
|
1204
|
-
* @example
|
|
1205
|
-
* ```ts
|
|
1206
|
-
* const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
|
|
1207
|
-
* ```
|
|
1208
|
-
*
|
|
1209
|
-
* @param id - The module to resolve.
|
|
1210
|
-
* @param importer - An optional path to the importer module.
|
|
1211
|
-
* @param options - Additional resolution options.
|
|
1212
|
-
* @returns The resolved module path.
|
|
1213
|
-
*/
|
|
1214
|
-
resolveSync(id, importer, options = {}) {
|
|
1215
|
-
const origResult = this.#innerResolveSync(id, importer, options);
|
|
1216
|
-
if (origResult && options.isFile && this.isDirectorySync(origResult)) {
|
|
1217
|
-
const indexResult = this.resolveSync((0, _stryke_path_join.joinPaths)(origResult, "index"), importer, options);
|
|
1218
|
-
if (indexResult) return indexResult;
|
|
1219
|
-
if (!(0, _stryke_path_file_path_fns.hasFileExtension)(origResult)) for (const ext of DEFAULT_EXTENSIONS) {
|
|
1220
|
-
const extResult = this.resolveSync(`${origResult}.${ext}`, importer, options);
|
|
1221
|
-
if (extResult) return extResult;
|
|
1222
|
-
}
|
|
1223
|
-
return;
|
|
1224
|
-
}
|
|
1225
|
-
return origResult;
|
|
1226
|
-
}
|
|
1227
|
-
/**
|
|
1228
|
-
* Disposes of the virtual file system (VFS) by saving its state to disk.
|
|
1229
|
-
*/
|
|
1230
|
-
async dispose() {
|
|
1231
|
-
if (!this.#isDisposed) {
|
|
1232
|
-
this.#isDisposed = true;
|
|
1233
|
-
this.#logger.debug("Disposing virtual file system...");
|
|
1234
|
-
await this.remove((0, _stryke_path_join.joinPaths)(this.#context.dataPath, "fs.bin"));
|
|
1235
|
-
const message = new _stryke_capnp.Message();
|
|
1236
|
-
const fs = message.initRoot(require_fs.FileSystem);
|
|
1237
|
-
const storage = fs._initStorage(Object.keys(this.#paths).length);
|
|
1238
|
-
await Promise.all(Object.values(this.#paths).map(async (path, index) => {
|
|
1239
|
-
const code = await this.read(path);
|
|
1240
|
-
const fd = storage.get(index);
|
|
1241
|
-
fd.path = path;
|
|
1242
|
-
fd.code = code || "";
|
|
1243
|
-
}));
|
|
1244
|
-
const ids = fs._initIds(Object.keys(this.#ids).length);
|
|
1245
|
-
Object.entries(this.#ids).filter(([, id]) => id).forEach(([path, id], index) => {
|
|
1246
|
-
const fileId = ids.get(index);
|
|
1247
|
-
fileId.id = id;
|
|
1248
|
-
fileId.path = path;
|
|
1249
|
-
});
|
|
1250
|
-
const metadata = fs._initMetadata(Object.keys(this.#metadata).length);
|
|
1251
|
-
Object.entries(this.#metadata).filter(([, value]) => value).forEach(([id, value], index) => {
|
|
1252
|
-
const fileMetadata = metadata.get(index);
|
|
1253
|
-
fileMetadata.id = id;
|
|
1254
|
-
fileMetadata.type = value.type;
|
|
1255
|
-
fileMetadata.timestamp = value.timestamp ?? Date.now();
|
|
1256
|
-
if (value.properties) {
|
|
1257
|
-
const props = fileMetadata._initProperties(Object.keys(value.properties).length);
|
|
1258
|
-
Object.entries(value.properties).filter(([, val]) => (0, _stryke_type_checks_is_set_string.isSetString)(val)).forEach(([key, val], index) => {
|
|
1259
|
-
const prop = props.get(index);
|
|
1260
|
-
prop.key = key;
|
|
1261
|
-
prop.value = val;
|
|
1262
|
-
});
|
|
1263
|
-
}
|
|
1264
|
-
});
|
|
1265
|
-
await (0, _stryke_fs_buffer.writeFileBuffer)((0, _stryke_path_join.joinPaths)(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
|
|
1266
|
-
if (!this.#context.config.skipCache) this.resolverCache.save(true);
|
|
1267
|
-
await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
|
|
1268
|
-
this.#logger.trace("Virtual file system has been disposed.");
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
/**
|
|
1272
|
-
* Asynchronously disposes of the virtual file system (VFS) by saving its state to disk.
|
|
1273
|
-
*
|
|
1274
|
-
* @remarks
|
|
1275
|
-
* This method is automatically called when the VFS instance is used within a `using` block, or can be manually invoked to ensure that the VFS state is saved and resources are cleaned up properly.
|
|
1276
|
-
*/
|
|
1277
|
-
async [Symbol.asyncDispose]() {
|
|
1278
|
-
return this.dispose();
|
|
1279
|
-
}
|
|
1280
|
-
};
|
|
1281
|
-
|
|
1282
|
-
//#endregion
|
|
1283
|
-
//#region src/context/context.ts
|
|
1284
|
-
(0, undici.setGlobalDispatcher)(new undici.Agent({ keepAliveTimeout: 1e4 }).compose(undici.interceptors.retry({
|
|
1285
|
-
maxRetries: 3,
|
|
1286
|
-
minTimeout: 1e3,
|
|
1287
|
-
maxTimeout: 1e4,
|
|
1288
|
-
timeoutFactor: 2,
|
|
1289
|
-
retryAfter: true
|
|
1290
|
-
})));
|
|
1291
|
-
const UNRESOLVED_CONFIG_NAMES = [
|
|
1292
|
-
"initialConfig",
|
|
1293
|
-
"userConfig",
|
|
1294
|
-
"inlineConfig",
|
|
1295
|
-
"pluginConfig",
|
|
1296
|
-
"environmentConfig"
|
|
1297
|
-
];
|
|
1298
|
-
var PowerlinesContext = class PowerlinesContext extends require_base_context.PowerlinesBaseContext {
|
|
1299
|
-
#checksum = null;
|
|
1300
|
-
#buildId = (0, _stryke_unique_id_uuid.uuid)();
|
|
1301
|
-
#releaseId = (0, _stryke_unique_id_uuid.uuid)();
|
|
1302
|
-
#fs;
|
|
1303
|
-
#tsconfig;
|
|
1304
|
-
#parserCache;
|
|
1305
|
-
#requestCache;
|
|
1306
|
-
#configProxy;
|
|
1307
|
-
/**
|
|
1308
|
-
* Create a new context from the workspace root and user config.
|
|
1309
|
-
*
|
|
1310
|
-
* @param options - The options for resolving the context.
|
|
1311
|
-
* @returns A promise that resolves to the new context.
|
|
1312
|
-
*/
|
|
1313
|
-
static async fromInitialConfig(options, initialConfig) {
|
|
1314
|
-
const context = new PowerlinesContext(options, initialConfig);
|
|
1315
|
-
await context.init();
|
|
1316
|
-
return context;
|
|
1317
|
-
}
|
|
1318
|
-
/**
|
|
1319
|
-
* The options provided to the Powerlines process, resolved with default values and merged with any configuration provided by plugins or other sources. This is typically the final configuration used during the build process, but may also include additional options that are relevant to the context and its interactions with the Powerlines engine.
|
|
1320
|
-
*/
|
|
1321
|
-
options = {};
|
|
1322
|
-
/**
|
|
1323
|
-
* An object containing the dependencies that should be installed for the project
|
|
1324
|
-
*/
|
|
1325
|
-
dependencies = {};
|
|
1326
|
-
/**
|
|
1327
|
-
* An object containing the development dependencies that should be installed for the project
|
|
1328
|
-
*/
|
|
1329
|
-
devDependencies = {};
|
|
1330
|
-
/**
|
|
1331
|
-
* The persisted meta information about the current build
|
|
1332
|
-
*/
|
|
1333
|
-
persistedMeta = void 0;
|
|
1334
|
-
/**
|
|
1335
|
-
* The resolved tsconfig file paths for the project
|
|
1336
|
-
*/
|
|
1337
|
-
resolvePatterns = [];
|
|
1338
|
-
/**
|
|
1339
|
-
* The input options used to initialize the context, which may be used when cloning the context to ensure the same configuration is applied to the new context
|
|
1340
|
-
*/
|
|
1341
|
-
initialOptions = {};
|
|
1342
|
-
/**
|
|
1343
|
-
* The resolved configuration for this context
|
|
1344
|
-
*/
|
|
1345
|
-
resolvedConfig = {};
|
|
1346
|
-
/**
|
|
1347
|
-
* The configuration options that were overridden by plugins during the build process, which may include additional properties or modifications made during the configuration loading process.
|
|
1348
|
-
*/
|
|
1349
|
-
overriddenConfig = {};
|
|
1350
|
-
/**
|
|
1351
|
-
* The configuration options provided inline during execution, such as CLI flags or other parameters that may be relevant to the command being executed. These options can be used to override or supplement the configuration options defined in a configuration file on disk, and are typically provided as part of the execution context when running a Powerlines command.
|
|
1352
|
-
*/
|
|
1353
|
-
inlineConfig = {};
|
|
1354
|
-
/**
|
|
1355
|
-
* The configuration options read from a configuration file on disk, which may be used to resolve the final configuration for the context. This typically includes the user configuration options defined in the `powerlines.config.ts` file, as well as any inline configuration options provided during execution.
|
|
1356
|
-
*/
|
|
1357
|
-
userConfig = {};
|
|
1358
|
-
/**
|
|
1359
|
-
* The configuration options provided by plugins added by the user (and other plugins)
|
|
1360
|
-
*/
|
|
1361
|
-
pluginConfig = {};
|
|
1362
|
-
/**
|
|
1363
|
-
* The configuration options provided by the environment
|
|
1364
|
-
*/
|
|
1365
|
-
environmentConfig = {};
|
|
1366
|
-
/**
|
|
1367
|
-
* The resolved entry type definitions for the project
|
|
1368
|
-
*/
|
|
1369
|
-
get entry() {
|
|
1370
|
-
const entry = this.resolvedEntry;
|
|
1371
|
-
return (0, _powerlines_core_lib_entry.resolveInputsSync)(this, entry && entry.length > 0 ? entry : Array.isArray(this.config.input) || (0, _stryke_type_checks_is_set_object.isSetObject)(this.config.input) && !(0, _powerlines_core_lib_entry.isTypeDefinition)(this.config.input) ? this.config.input : (0, _stryke_convert_to_array.toArray)(this.config.input).flat());
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* The TypeScript configuration parsed from the tsconfig file
|
|
1375
|
-
*/
|
|
1376
|
-
get tsconfig() {
|
|
1377
|
-
if (!this.#tsconfig) this.tsconfig = { tsconfigFilePath: this.config.tsconfig };
|
|
1378
|
-
return this.#tsconfig;
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Sets the TypeScript configuration parsed from the tsconfig file
|
|
1382
|
-
*/
|
|
1383
|
-
set tsconfig(value) {
|
|
1384
|
-
this.#tsconfig = value;
|
|
1385
|
-
this.resolvePatterns = (0, bundle_require.tsconfigPathsToRegExp)(value?.options?.paths ?? {});
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* The virtual file system interface for the project
|
|
1389
|
-
*/
|
|
1390
|
-
get fs() {
|
|
1391
|
-
if (!this.#fs) this.#fs = VirtualFileSystem.createSync(this);
|
|
1392
|
-
return this.#fs;
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Get the checksum of the project's current state
|
|
1396
|
-
*/
|
|
1397
|
-
get checksum() {
|
|
1398
|
-
return this.#checksum;
|
|
1399
|
-
}
|
|
1400
|
-
/**
|
|
1401
|
-
* The meta information about the current build
|
|
1402
|
-
*/
|
|
1403
|
-
get meta() {
|
|
1404
|
-
return {
|
|
1405
|
-
buildId: this.#buildId,
|
|
1406
|
-
releaseId: this.#releaseId,
|
|
1407
|
-
checksum: this.#checksum,
|
|
1408
|
-
timestamp: this.timestamp,
|
|
1409
|
-
rootHash: (0, _stryke_hash.murmurhash)({
|
|
1410
|
-
workspaceRoot: this.options?.cwd,
|
|
1411
|
-
root: this.config?.root
|
|
1412
|
-
}, { maxLength: _powerlines_core_constants.ROOT_HASH_LENGTH }),
|
|
1413
|
-
configHash: (0, _stryke_hash.murmurhash)(this.config, { maxLength: _powerlines_core_constants.CACHE_HASH_LENGTH })
|
|
1414
|
-
};
|
|
1415
|
-
}
|
|
1416
|
-
/**
|
|
1417
|
-
* The resolved configuration options
|
|
1418
|
-
*/
|
|
1419
|
-
get config() {
|
|
1420
|
-
if (!this.#configProxy) this.#configProxy = this.createConfigProxy();
|
|
1421
|
-
return this.#configProxy;
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Get the path to the artifacts directory for the project
|
|
1425
|
-
*/
|
|
1426
|
-
get artifactsPath() {
|
|
1427
|
-
return (0, _stryke_path_join.joinPaths)(this.config.cwd, this.config.root, this.config.output?.artifactsPath || `.${this.config.framework || "powerlines"}`);
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* Get the path to the builtin modules used by the project
|
|
1431
|
-
*/
|
|
1432
|
-
get builtinsPath() {
|
|
1433
|
-
return (0, _stryke_path_join.joinPaths)(this.artifactsPath, "builtins");
|
|
1434
|
-
}
|
|
1435
|
-
/**
|
|
1436
|
-
* Get the path to the entry directory for the project
|
|
1437
|
-
*/
|
|
1438
|
-
get entryPath() {
|
|
1439
|
-
return (0, _stryke_path_join.joinPaths)(this.artifactsPath, "entry");
|
|
1440
|
-
}
|
|
1441
|
-
/**
|
|
1442
|
-
* Get the path to the infrastructure modules used by the project
|
|
1443
|
-
*/
|
|
1444
|
-
get infrastructurePath() {
|
|
1445
|
-
return (0, _stryke_path_join.joinPaths)(this.artifactsPath, "infrastructure");
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* Get the path to the data directory for the project
|
|
1449
|
-
*/
|
|
1450
|
-
get dataPath() {
|
|
1451
|
-
return (0, _stryke_path_join.joinPaths)(this.envPaths.data, "projects", getPrefixedRootHash(this.config.name, this.meta.rootHash));
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Get the path to the cache directory for the project
|
|
1455
|
-
*/
|
|
1456
|
-
get cachePath() {
|
|
1457
|
-
return (0, _stryke_path_join.joinPaths)(this.envPaths.cache, "projects", (0, _stryke_hash.murmurhash)({
|
|
1458
|
-
checksum: this.#checksum,
|
|
1459
|
-
config: this.meta.configHash
|
|
1460
|
-
}, { maxLength: _powerlines_core_constants.CACHE_HASH_LENGTH }));
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Get the path to the generated declaration file for the project
|
|
1464
|
-
*/
|
|
1465
|
-
get typesPath() {
|
|
1466
|
-
return this.config.output.types ? (0, _stryke_path_append.appendPath)(this.config.output.types, this.config.cwd) : (0, _stryke_path_join.joinPaths)(this.config.cwd, this.config.root, "powerlines.d.ts");
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Get the project root relative to the workspace root
|
|
1470
|
-
*/
|
|
1471
|
-
get relativeToWorkspaceRoot() {
|
|
1472
|
-
return (0, _stryke_fs_get_workspace_root.relativeToWorkspaceRoot)(this.config.root);
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* The builtin module id that exist in the Powerlines virtual file system
|
|
1476
|
-
*/
|
|
1477
|
-
get builtins() {
|
|
1478
|
-
return Object.values(this.fs.metadata).filter((meta) => meta && meta.type === "builtin").map((meta) => meta?.id).filter(Boolean);
|
|
1479
|
-
}
|
|
1480
|
-
/**
|
|
1481
|
-
* Additional arguments provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed.
|
|
1482
|
-
*/
|
|
1483
|
-
get additionalArgs() {
|
|
1484
|
-
return Object.entries(this.config.inlineConfig.additionalArgs ?? {}).reduce((ret, [key, value]) => {
|
|
1485
|
-
const formattedKey = key.replace(/^--?/, "");
|
|
1486
|
-
if (ret[formattedKey]) if (Array.isArray(ret[formattedKey])) if (Array.isArray(value)) ret[formattedKey] = [...(0, _stryke_convert_to_array.toArray)(ret[formattedKey]), ...value];
|
|
1487
|
-
else ret[formattedKey] = [...(0, _stryke_convert_to_array.toArray)(ret[formattedKey]), value];
|
|
1488
|
-
else ret[formattedKey] = [ret[formattedKey], ...Array.isArray(value) ? value : [value]];
|
|
1489
|
-
else ret[formattedKey] = value;
|
|
1490
|
-
return ret;
|
|
1491
|
-
}, {});
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* The alias mappings for the project used during module resolution
|
|
1495
|
-
*
|
|
1496
|
-
* @remarks
|
|
1497
|
-
* This includes both the built-in module aliases as well as any custom aliases defined in the build configuration.
|
|
1498
|
-
*/
|
|
1499
|
-
get alias() {
|
|
1500
|
-
return this.builtins.reduce((ret, id) => {
|
|
1501
|
-
const moduleId = `${this.config?.framework || "powerlines"}:${id.replace(/^.*:/, "")}`;
|
|
1502
|
-
if (!ret[moduleId]) {
|
|
1503
|
-
const path = this.fs.paths[id];
|
|
1504
|
-
if (path) ret[moduleId] = path;
|
|
1505
|
-
}
|
|
1506
|
-
return ret;
|
|
1507
|
-
}, this.config.resolve.alias ? Array.isArray(this.config.resolve.alias) ? this.config.resolve.alias.reduce((ret, alias) => {
|
|
1508
|
-
if (!ret[alias.find.toString()]) ret[alias.find.toString()] = alias.replacement;
|
|
1509
|
-
return ret;
|
|
1510
|
-
}, {}) : this.config.resolve.alias : {});
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* The log level for the context, which determines the minimum level of log messages that will be emitted by the logger. This is resolved based on the configuration options provided by the user, and can be set to different levels for development, production, and test environments. The log level can also be overridden by plugins or other parts of the build process to provide more granular control over logging output.
|
|
1514
|
-
*/
|
|
1515
|
-
get logLevel() {
|
|
1516
|
-
return (0, _powerlines_core_plugin_utils.resolveLogLevel)(this.config.logLevel, this.config.mode);
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* The environment paths for the project, which provide the locations of various directories and files used by the Powerlines framework. These paths are resolved based on the organization ID, application ID, and workspace root directory, and can be used to access configuration files, cache directories, and other resources in a consistent manner.
|
|
1520
|
-
*/
|
|
1521
|
-
get envPaths() {
|
|
1522
|
-
return (0, _stryke_env_get_env_paths.getEnvPaths)({
|
|
1523
|
-
orgId: this.config.organization,
|
|
1524
|
-
appId: this.config.framework || "powerlines",
|
|
1525
|
-
workspaceRoot: this.config.cwd
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Gets the parser cache.
|
|
1530
|
-
*/
|
|
1531
|
-
get parserCache() {
|
|
1532
|
-
if (!this.#parserCache) this.#parserCache = (0, flat_cache.create)({
|
|
1533
|
-
cacheId: "parser",
|
|
1534
|
-
cacheDir: this.cachePath,
|
|
1535
|
-
ttl: 7200 * 1e3,
|
|
1536
|
-
lruSize: 5e3,
|
|
1537
|
-
persistInterval: 250
|
|
1538
|
-
});
|
|
1539
|
-
return this.#parserCache;
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Gets the request cache.
|
|
1543
|
-
*/
|
|
1544
|
-
get requestCache() {
|
|
1545
|
-
if (!this.#requestCache) this.#requestCache = (0, flat_cache.create)({
|
|
1546
|
-
cacheId: "http",
|
|
1547
|
-
cacheDir: this.cachePath,
|
|
1548
|
-
ttl: 360 * 60 * 1e3,
|
|
1549
|
-
lruSize: 5e3,
|
|
1550
|
-
persistInterval: 250
|
|
1551
|
-
});
|
|
1552
|
-
return this.#requestCache;
|
|
1553
|
-
}
|
|
1554
|
-
/**
|
|
1555
|
-
* The entry points that exist in the Powerlines virtual file system
|
|
1556
|
-
*/
|
|
1557
|
-
get resolvedEntry() {
|
|
1558
|
-
return Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "entry").map(([path, meta]) => {
|
|
1559
|
-
const typeDefinition = { file: path };
|
|
1560
|
-
if (meta.properties) {
|
|
1561
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(meta.properties.file)) typeDefinition.file = meta.properties.file;
|
|
1562
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(meta.properties.name)) typeDefinition.name = meta.properties.name;
|
|
1563
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(meta.properties["input.file"]) || (0, _stryke_type_checks_is_set_string.isSetString)(meta.properties["input.name"])) {
|
|
1564
|
-
typeDefinition.input ??= {};
|
|
1565
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(meta.properties["input.file"])) typeDefinition.input.file = meta.properties["input.file"];
|
|
1566
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(meta.properties["input.name"])) typeDefinition.input.name = meta.properties["input.name"];
|
|
1567
|
-
}
|
|
1568
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(meta.properties.output)) typeDefinition.output = meta.properties.output;
|
|
1569
|
-
}
|
|
1570
|
-
return typeDefinition;
|
|
1571
|
-
}).filter(Boolean);
|
|
1572
|
-
}
|
|
1573
|
-
/**
|
|
1574
|
-
* Creates a new Context instance.
|
|
1575
|
-
*
|
|
1576
|
-
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
1577
|
-
* @param initialConfig - The initial configuration provided by the user, which can be used to resolve the final configuration for the context. This typically includes the user configuration options defined in the `powerlines.config.ts` file, as well as any inline configuration options provided during execution.
|
|
1578
|
-
*/
|
|
1579
|
-
constructor(options, initialConfig) {
|
|
1580
|
-
super(options, initialConfig);
|
|
1581
|
-
this.initialOptions = options;
|
|
1582
|
-
this.initialConfig = initialConfig;
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* Create a new logger instance
|
|
1586
|
-
*
|
|
1587
|
-
* @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.
|
|
1588
|
-
* @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.
|
|
1589
|
-
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
1590
|
-
*/
|
|
1591
|
-
createLogger(options, logFn) {
|
|
1592
|
-
let logger;
|
|
1593
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(process.env.POWERLINES_EXECUTION_THREAD_TYPE)) logger = (0, _powerlines_core_plugin_utils.createLogger)(this.config.name, {
|
|
1594
|
-
...this.options,
|
|
1595
|
-
...this.config,
|
|
1596
|
-
...options
|
|
1597
|
-
}, (meta, message) => sendWriteLogMessage(this, meta, message));
|
|
1598
|
-
else logger = (0, _powerlines_core_plugin_utils.createLogger)(this.config.name, {
|
|
1599
|
-
...this.options,
|
|
1600
|
-
...this.config,
|
|
1601
|
-
...options
|
|
1602
|
-
});
|
|
1603
|
-
if (this.config.customLogger) logger = (0, _powerlines_core_plugin_utils.withCustomLogger)(logger, this.config.customLogger);
|
|
1604
|
-
if (logFn) logger = (0, _powerlines_core_plugin_utils.withLogFn)(logger, logFn);
|
|
1605
|
-
return logger;
|
|
1606
|
-
}
|
|
1607
|
-
/**
|
|
1608
|
-
* A function to perform HTTP fetch requests
|
|
1609
|
-
*
|
|
1610
|
-
* @remarks
|
|
1611
|
-
* This function uses a caching layer to avoid duplicate requests during the Powerlines process.
|
|
1612
|
-
*
|
|
1613
|
-
* @example
|
|
1614
|
-
* ```ts
|
|
1615
|
-
* const response = await context.fetch("https://api.example.com/data");
|
|
1616
|
-
* const data = await response.json();
|
|
1617
|
-
* ```
|
|
1618
|
-
*
|
|
1619
|
-
* @see https://github.com/nodejs/undici
|
|
1620
|
-
*
|
|
1621
|
-
* @param input - The URL to fetch.
|
|
1622
|
-
* @param options - The fetch request options.
|
|
1623
|
-
* @returns A promise that resolves to a response returned by the fetch.
|
|
1624
|
-
*/
|
|
1625
|
-
async fetch(input, options = {}) {
|
|
1626
|
-
const cacheKey = (0, _stryke_hash.murmurhash)({
|
|
1627
|
-
input: input.toString(),
|
|
1628
|
-
options: JSON.stringify(options)
|
|
1629
|
-
});
|
|
1630
|
-
if (!this.config.skipCache && !options.skipCache) {
|
|
1631
|
-
const cached = this.requestCache.get(cacheKey);
|
|
1632
|
-
if (cached) return new undici.Response(cached.body, {
|
|
1633
|
-
status: cached.status,
|
|
1634
|
-
statusText: cached.statusText,
|
|
1635
|
-
headers: cached.headers
|
|
1636
|
-
});
|
|
1637
|
-
}
|
|
1638
|
-
const logger = this.extendLogger({ category: "network" });
|
|
1639
|
-
const startTime = Date.now();
|
|
1640
|
-
logger.trace(`Sending fetch request (${options.method?.toUpperCase() || "GET"}): ${input.toString()}`);
|
|
1641
|
-
const response = await (0, _stryke_http_fetch.fetchRequest)(input, {
|
|
1642
|
-
timeout: 12e3,
|
|
1643
|
-
...options
|
|
1644
|
-
});
|
|
1645
|
-
const result = {
|
|
1646
|
-
body: await response.text(),
|
|
1647
|
-
status: response.status,
|
|
1648
|
-
statusText: response.statusText,
|
|
1649
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1650
|
-
};
|
|
1651
|
-
if (!this.config.skipCache && !options.skipCache) try {
|
|
1652
|
-
this.requestCache.set(cacheKey, result);
|
|
1653
|
-
} catch {}
|
|
1654
|
-
logger.trace(`Fetch request (${options.method?.toUpperCase() || "GET"}) completed in ${Date.now() - startTime}ms: ${input.toString()} - ${response.status} / ${response.statusText} \n - Response Headers: ${JSON.stringify(result.headers)}\n - Response Body: ${typeof result.body === "string" ? result.body.length > 1e3 ? `${result.body.slice(0, 1e3)}... (truncated, total length: ${result.body.length})` : result.body : "[Non-string body]"}`);
|
|
1655
|
-
return new undici.Response(result.body, {
|
|
1656
|
-
status: result.status,
|
|
1657
|
-
statusText: result.statusText,
|
|
1658
|
-
headers: result.headers
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Parse code using [Oxc-Parser](https://github.com/oxc/oxc) into an (ESTree-compatible)[https://github.com/estree/estree] AST object.
|
|
1663
|
-
*
|
|
1664
|
-
* @remarks
|
|
1665
|
-
* This function can be used to parse TypeScript code into an AST for further analysis or transformation.
|
|
1666
|
-
*
|
|
1667
|
-
* @example
|
|
1668
|
-
* ```ts
|
|
1669
|
-
* const ast = context.parse("const x: number = 42;");
|
|
1670
|
-
* ```
|
|
1671
|
-
*
|
|
1672
|
-
* @see https://rollupjs.org/plugin-development/#this-parse
|
|
1673
|
-
* @see https://github.com/oxc/oxc
|
|
1674
|
-
*
|
|
1675
|
-
* @param code - The source code to parse.
|
|
1676
|
-
* @param options - The options to pass to the parser.
|
|
1677
|
-
* @returns An (ESTree-compatible)[https://github.com/estree/estree] AST object.
|
|
1678
|
-
*/
|
|
1679
|
-
async parse(code, options = {}) {
|
|
1680
|
-
const cacheKey = (0, _stryke_hash.murmurhash)({
|
|
1681
|
-
code,
|
|
1682
|
-
options
|
|
1683
|
-
});
|
|
1684
|
-
let result;
|
|
1685
|
-
if (!this.config.skipCache) {
|
|
1686
|
-
result = this.parserCache.get(cacheKey);
|
|
1687
|
-
if (result) return result;
|
|
1688
|
-
}
|
|
1689
|
-
result = await (0, oxc_parser.parse)(`source.${options.lang || "ts"}`, code, {
|
|
1690
|
-
...options,
|
|
1691
|
-
sourceType: "module",
|
|
1692
|
-
showSemanticErrors: this.config.mode === "development"
|
|
1693
|
-
});
|
|
1694
|
-
if (!this.config.skipCache) this.parserCache.set(cacheKey, result);
|
|
1695
|
-
return result;
|
|
1696
|
-
}
|
|
1697
|
-
/**
|
|
1698
|
-
* A helper function to resolve modules in the Virtual File System
|
|
1699
|
-
*
|
|
1700
|
-
* @remarks
|
|
1701
|
-
* This function can be used to resolve modules relative to the project root directory.
|
|
1702
|
-
*
|
|
1703
|
-
* @example
|
|
1704
|
-
* ```ts
|
|
1705
|
-
* const resolved = await context.resolve("some-module", "/path/to/importer");
|
|
1706
|
-
* ```
|
|
1707
|
-
*
|
|
1708
|
-
* @param id - The module to resolve.
|
|
1709
|
-
* @param importer - An optional path to the importer module.
|
|
1710
|
-
* @param options - Additional resolution options.
|
|
1711
|
-
* @returns A promise that resolves to the resolved module path.
|
|
1712
|
-
*/
|
|
1713
|
-
async resolve(id, importer, options = {}) {
|
|
1714
|
-
let moduleId = id;
|
|
1715
|
-
if (this.config.resolve.alias) {
|
|
1716
|
-
if (Array.isArray(this.config.resolve.alias)) {
|
|
1717
|
-
const alias = this.config.resolve.alias.find((a) => (0, bundle_require.match)(moduleId, [a.find]));
|
|
1718
|
-
if (alias) moduleId = alias.replacement;
|
|
1719
|
-
} else if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.config.resolve.alias) && this.config.resolve.alias[id]) moduleId = this.config.resolve.alias[id];
|
|
1720
|
-
}
|
|
1721
|
-
if (this.fs.isResolvableId(moduleId) || importer && this.fs.isResolvableId(importer)) {
|
|
1722
|
-
let resolvedImporter = importer;
|
|
1723
|
-
if (importer && this.fs.isResolvableId(importer)) resolvedImporter = await this.fs.resolve(importer, void 0, (0, defu.default)({
|
|
1724
|
-
conditions: this.config.resolve.conditions,
|
|
1725
|
-
extensions: this.config.resolve.extensions
|
|
1726
|
-
}, options));
|
|
1727
|
-
const result = await this.fs.resolve(moduleId, resolvedImporter, (0, defu.default)({
|
|
1728
|
-
conditions: this.config.resolve.conditions,
|
|
1729
|
-
extensions: this.config.resolve.extensions
|
|
1730
|
-
}, options));
|
|
1731
|
-
if (!result) return;
|
|
1732
|
-
const external = Boolean(!(0, bundle_require.match)(moduleId, this.config.resolve.noExternal) && ((0, bundle_require.match)(moduleId, this.config.resolve.external) || moduleId.startsWith("node:") || (!this.fs.isVirtual(moduleId, importer, options) || this.fs.isVirtual(moduleId, importer, options) && this.config.projectType !== "application") && this.config.resolve.skipNodeModulesBundle && !/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(moduleId)));
|
|
1733
|
-
return {
|
|
1734
|
-
id: result,
|
|
1735
|
-
external,
|
|
1736
|
-
virtual: !external
|
|
1737
|
-
};
|
|
1738
|
-
}
|
|
1739
|
-
if (this.config.resolve.skipNodeModulesBundle) {
|
|
1740
|
-
if ((0, bundle_require.match)(moduleId, this.resolvePatterns) || (0, bundle_require.match)(moduleId, this.config.resolve.noExternal)) return;
|
|
1741
|
-
if ((0, bundle_require.match)(moduleId, this.config.resolve.external) || moduleId.startsWith("node:")) return {
|
|
1742
|
-
id: moduleId,
|
|
1743
|
-
external: true,
|
|
1744
|
-
virtual: false
|
|
1745
|
-
};
|
|
1746
|
-
if (!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(moduleId)) return {
|
|
1747
|
-
id: moduleId,
|
|
1748
|
-
external: true,
|
|
1749
|
-
virtual: false
|
|
1750
|
-
};
|
|
1751
|
-
} else {
|
|
1752
|
-
if ((0, bundle_require.match)(moduleId, this.config.resolve.noExternal)) return;
|
|
1753
|
-
if ((0, bundle_require.match)(moduleId, this.config.resolve.external) || moduleId.startsWith("node:")) return {
|
|
1754
|
-
id: moduleId,
|
|
1755
|
-
external: true,
|
|
1756
|
-
virtual: false
|
|
1757
|
-
};
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* A helper function to load modules from the Virtual File System
|
|
1762
|
-
*
|
|
1763
|
-
* @remarks
|
|
1764
|
-
* This function can be used to load modules relative to the project root directory.
|
|
1765
|
-
*
|
|
1766
|
-
* @example
|
|
1767
|
-
* ```ts
|
|
1768
|
-
* const module = await context.load("some-module", "/path/to/importer");
|
|
1769
|
-
* ```
|
|
1770
|
-
*
|
|
1771
|
-
* @param id - The module to load.
|
|
1772
|
-
* @returns A promise that resolves to the loaded module.
|
|
1773
|
-
*/
|
|
1774
|
-
async load(id) {
|
|
1775
|
-
const resolvedId = await this.fs.resolve(id);
|
|
1776
|
-
if (!resolvedId) return;
|
|
1777
|
-
const code = await this.fs.read(resolvedId);
|
|
1778
|
-
if (!code) return;
|
|
1779
|
-
return {
|
|
1780
|
-
code,
|
|
1781
|
-
map: null
|
|
1782
|
-
};
|
|
1783
|
-
}
|
|
1784
|
-
/**
|
|
1785
|
-
* Get the builtin virtual files that exist in the Powerlines virtual file system
|
|
1786
|
-
*/
|
|
1787
|
-
async getBuiltins() {
|
|
1788
|
-
return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "builtin").map(async ([id, meta]) => {
|
|
1789
|
-
const code = await this.fs.read(id);
|
|
1790
|
-
const path = this.fs.paths[id];
|
|
1791
|
-
return {
|
|
1792
|
-
...meta,
|
|
1793
|
-
path,
|
|
1794
|
-
code
|
|
1795
|
-
};
|
|
1796
|
-
}));
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Resolves a file and writes it to the VFS if it does not already exist
|
|
1800
|
-
*
|
|
1801
|
-
* @param code - The source code of the file
|
|
1802
|
-
* @param path - The path to write the file to
|
|
1803
|
-
* @param options - Additional options for writing the file
|
|
1804
|
-
*/
|
|
1805
|
-
async emit(code, path, options = {}) {
|
|
1806
|
-
const filePath = options.extension ? (0, _stryke_path_file_path_fns.findFileExtensionSafe)(path) ? options.extension.startsWith(".") ? path.replace((0, _stryke_path_file_path_fns.findFileDotExtensionSafe)(path), options.extension) : path.replace((0, _stryke_path_file_path_fns.findFileExtensionSafe)(path), options.extension) : options.extension.startsWith(".") ? `${path}${options.extension}` : `${path}.${options.extension}` : (0, _stryke_path_file_path_fns.findFileExtensionSafe)(path) ? path : `${path}.ts`;
|
|
1807
|
-
if ((0, _stryke_type_checks_is_function.isFunction)(this.emitFile) && options.emitWithBundler) return this.emitFile({
|
|
1808
|
-
needsCodeReference: options.needsCodeReference,
|
|
1809
|
-
originalFileName: options.originalFileName,
|
|
1810
|
-
fileName: filePath,
|
|
1811
|
-
source: code,
|
|
1812
|
-
type: "asset"
|
|
1813
|
-
});
|
|
1814
|
-
return this.fs.write(filePath, code, options);
|
|
1815
|
-
}
|
|
1816
|
-
/**
|
|
1817
|
-
* Synchronously resolves a file and writes it to the VFS if it does not already exist
|
|
1818
|
-
*
|
|
1819
|
-
* @param code - The source code of the file
|
|
1820
|
-
* @param path - The path to write the file to
|
|
1821
|
-
* @param options - Additional options for writing the file
|
|
1822
|
-
*/
|
|
1823
|
-
emitSync(code, path, options = {}) {
|
|
1824
|
-
const filePath = options.extension ? (0, _stryke_path_file_path_fns.findFileExtensionSafe)(path) ? options.extension.startsWith(".") ? path.replace((0, _stryke_path_file_path_fns.findFileDotExtensionSafe)(path), options.extension) : path.replace((0, _stryke_path_file_path_fns.findFileExtensionSafe)(path), options.extension) : options.extension.startsWith(".") ? `${path}${options.extension}` : `${path}.${options.extension}` : (0, _stryke_path_file_path_fns.findFileExtensionSafe)(path) ? path : `${path}.ts`;
|
|
1825
|
-
if ((0, _stryke_type_checks_is_function.isFunction)(this.emitFile) && options.emitWithBundler) return this.emitFile({
|
|
1826
|
-
needsCodeReference: options.needsCodeReference,
|
|
1827
|
-
originalFileName: options.originalFileName,
|
|
1828
|
-
fileName: filePath,
|
|
1829
|
-
source: code,
|
|
1830
|
-
type: "asset"
|
|
1831
|
-
});
|
|
1832
|
-
return this.fs.writeSync(filePath, code, options);
|
|
1833
|
-
}
|
|
1834
|
-
/**
|
|
1835
|
-
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
1836
|
-
*
|
|
1837
|
-
* @param code - The source code of the entry file
|
|
1838
|
-
* @param path - A path to write the entry file to
|
|
1839
|
-
* @param options - Optional write file options
|
|
1840
|
-
*/
|
|
1841
|
-
async emitEntry(code, path, options = {}) {
|
|
1842
|
-
return this.emit(code, (0, _stryke_path_append.appendPath)(path, this.entryPath), (0, defu.default)({ meta: {
|
|
1843
|
-
type: "entry",
|
|
1844
|
-
properties: {
|
|
1845
|
-
file: (0, _stryke_path_append.appendPath)(path, this.entryPath),
|
|
1846
|
-
name: options?.name,
|
|
1847
|
-
output: options?.output,
|
|
1848
|
-
"input.file": options?.input?.file,
|
|
1849
|
-
"input.name": options?.input?.name
|
|
1850
|
-
}
|
|
1851
|
-
} }, (0, _stryke_helpers_omit.omit)(options, ["name"])));
|
|
1852
|
-
}
|
|
1853
|
-
/**
|
|
1854
|
-
* Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
1855
|
-
*
|
|
1856
|
-
* @param code - The source code of the entry file
|
|
1857
|
-
* @param path - A path to write the entry file to
|
|
1858
|
-
* @param options - Optional write file options
|
|
1859
|
-
*/
|
|
1860
|
-
emitEntrySync(code, path, options = {}) {
|
|
1861
|
-
return this.emitSync(code, (0, _stryke_path_append.appendPath)(path, this.entryPath), (0, defu.default)({ meta: {
|
|
1862
|
-
type: "entry",
|
|
1863
|
-
properties: {
|
|
1864
|
-
file: (0, _stryke_path_append.appendPath)(path, this.entryPath),
|
|
1865
|
-
name: options?.name,
|
|
1866
|
-
output: options?.output,
|
|
1867
|
-
"input.file": options?.input?.file,
|
|
1868
|
-
"input.name": options?.input?.name
|
|
1869
|
-
}
|
|
1870
|
-
} }, (0, _stryke_helpers_omit.omit)(options, ["name"])));
|
|
1871
|
-
}
|
|
1872
|
-
/**
|
|
1873
|
-
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
1874
|
-
*
|
|
1875
|
-
* @param code - The source code of the builtin file
|
|
1876
|
-
* @param id - The unique identifier of the builtin file
|
|
1877
|
-
* @param options - Optional write file options
|
|
1878
|
-
*/
|
|
1879
|
-
async emitBuiltin(code, id, options = {}) {
|
|
1880
|
-
if (!this.builtinsPath) throw new Error(`The builtins path is not set. Cannot emit builtin file with id "${id}".`);
|
|
1881
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(id)) throw new Error(`The builtin id must be a non-empty string. Received: ${String(id)}`);
|
|
1882
|
-
return this.emit(code, (0, _stryke_path_append.appendPath)(id, this.builtinsPath), (0, defu.default)(options, { meta: {
|
|
1883
|
-
type: "builtin",
|
|
1884
|
-
id
|
|
1885
|
-
} }));
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
1889
|
-
*
|
|
1890
|
-
* @param code - The source code of the builtin file
|
|
1891
|
-
* @param id - The unique identifier of the builtin file
|
|
1892
|
-
* @param options - Optional write file options
|
|
1893
|
-
*/
|
|
1894
|
-
emitBuiltinSync(code, id, options = {}) {
|
|
1895
|
-
if (!this.builtinsPath) throw new Error(`The builtins path is not set. Cannot emit builtin file with id "${id}".`);
|
|
1896
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(id)) throw new Error(`The builtin id must be a non-empty string. Received: ${String(id)}`);
|
|
1897
|
-
return this.emitSync(code, (0, _stryke_path_append.appendPath)(id, this.builtinsPath), (0, defu.default)(options, { meta: {
|
|
1898
|
-
type: "builtin",
|
|
1899
|
-
id
|
|
1900
|
-
} }));
|
|
1901
|
-
}
|
|
1902
|
-
/**
|
|
1903
|
-
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
1904
|
-
*
|
|
1905
|
-
* @param code - The source code of the builtin file
|
|
1906
|
-
* @param id - The unique identifier of the builtin file
|
|
1907
|
-
* @param options - Optional write file options
|
|
1908
|
-
*/
|
|
1909
|
-
async emitInfrastructure(code, id, options = {}) {
|
|
1910
|
-
if (!this.infrastructurePath) throw new Error(`The infrastructure path is not set. Cannot emit infrastructure file with id "${id}".`);
|
|
1911
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(id)) throw new Error(`The infrastructure id must be a non-empty string. Received: ${String(id)}`);
|
|
1912
|
-
return this.emit(code, (0, _stryke_path_append.appendPath)(id, this.infrastructurePath), (0, defu.default)(options, { meta: {
|
|
1913
|
-
type: "infrastructure",
|
|
1914
|
-
id
|
|
1915
|
-
} }));
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Synchronously resolves an infrastructure virtual file and writes it to the VFS if it does not already exist
|
|
1919
|
-
*
|
|
1920
|
-
* @param code - The source code of the infrastructure file
|
|
1921
|
-
* @param id - The unique identifier of the infrastructure file
|
|
1922
|
-
* @param options - Optional write file options
|
|
1923
|
-
*/
|
|
1924
|
-
emitInfrastructureSync(code, id, options = {}) {
|
|
1925
|
-
if (!this.infrastructurePath) throw new Error(`The infrastructure path is not set. Cannot emit infrastructure file with id "${id}".`);
|
|
1926
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(id)) throw new Error(`The infrastructure id must be a non-empty string. Received: ${String(id)}`);
|
|
1927
|
-
return this.emitSync(code, (0, _stryke_path_append.appendPath)(id, this.infrastructurePath), (0, defu.default)(options, { meta: {
|
|
1928
|
-
type: "infrastructure",
|
|
1929
|
-
id
|
|
1930
|
-
} }));
|
|
1931
|
-
}
|
|
1932
|
-
/**
|
|
1933
|
-
* Generates a checksum representing the current context state
|
|
1934
|
-
*
|
|
1935
|
-
* @param path - The root directory of the project to generate the checksum for
|
|
1936
|
-
* @returns A promise that resolves to a string representing the checksum
|
|
1937
|
-
*/
|
|
1938
|
-
async generateChecksum(path) {
|
|
1939
|
-
return (0, _stryke_hash_node.hashDirectory)(path || (0, _stryke_path_append.appendPath)(this.options.root, this.options.cwd));
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* 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.
|
|
1943
|
-
*
|
|
1944
|
-
* @param config - The inline configuration values to set.
|
|
1945
|
-
* @returns A promise that resolves when the inline configuration values have been set.
|
|
1946
|
-
*/
|
|
1947
|
-
async setInlineConfig(config) {
|
|
1948
|
-
this.logger.debug({
|
|
1949
|
-
meta: { category: "config" },
|
|
1950
|
-
message: `Updating inline configuration object: \n${(0, _powerlines_core_plugin_utils.formatConfig)(config)}`
|
|
1951
|
-
});
|
|
1952
|
-
this.inlineConfig = config;
|
|
1953
|
-
await this.resolveConfig();
|
|
1954
|
-
}
|
|
1955
|
-
/**
|
|
1956
|
-
* A setter function to populate the plugin config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the plugin configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any plugin configuration provided during execution.
|
|
1957
|
-
*
|
|
1958
|
-
* @param config - The plugin configuration values to set.
|
|
1959
|
-
* @returns A promise that resolves when the plugin configuration values have been set.
|
|
1960
|
-
*/
|
|
1961
|
-
async setPluginConfig(config) {
|
|
1962
|
-
this.logger.debug({
|
|
1963
|
-
meta: { category: "config" },
|
|
1964
|
-
message: `Updating plugin configuration object: \n${(0, _powerlines_core_plugin_utils.formatConfig)(config)}`
|
|
1965
|
-
});
|
|
1966
|
-
this.pluginConfig = config;
|
|
1967
|
-
await this.resolveConfig();
|
|
1968
|
-
}
|
|
1969
|
-
/**
|
|
1970
|
-
* A function to merge the various configuration objects (initial, user, inline, and plugin) into a single resolved configuration object that can be used throughout the Powerlines process. This function takes into account the different sources of configuration and their respective priorities, ensuring that the final configuration reflects the intended settings for the project. The merged configuration is then returned as a new object that can be accessed through the `config` property of the context.
|
|
1971
|
-
*
|
|
1972
|
-
* @returns The merged configuration object that combines the initial, user, inline, and plugin configurations.
|
|
1973
|
-
*/
|
|
1974
|
-
mergeConfig() {
|
|
1975
|
-
return (0, _powerlines_core_plugin_utils.mergeConfig)({
|
|
1976
|
-
mode: this.initialOptions.mode,
|
|
1977
|
-
framework: this.initialOptions.framework,
|
|
1978
|
-
logLevel: this.initialOptions.logLevel,
|
|
1979
|
-
inlineConfig: this.inlineConfig,
|
|
1980
|
-
userConfig: this.userConfig,
|
|
1981
|
-
initialConfig: this.initialConfig,
|
|
1982
|
-
pluginConfig: this.pluginConfig,
|
|
1983
|
-
environmentConfig: this.environmentConfig
|
|
1984
|
-
}, getConfigProps(this.overriddenConfig), (0, _stryke_helpers_omit.omit)(this.options, [
|
|
1985
|
-
"name",
|
|
1986
|
-
"mode",
|
|
1987
|
-
"framework",
|
|
1988
|
-
"logLevel"
|
|
1989
|
-
]), getConfigProps(this.inlineConfig), getConfigProps(this.userConfig), getConfigProps(this.initialConfig), getConfigProps(this.pluginConfig), {
|
|
1990
|
-
name: this.initialOptions.name,
|
|
1991
|
-
version: this.packageJson?.version,
|
|
1992
|
-
description: this.packageJson?.description,
|
|
1993
|
-
environments: {},
|
|
1994
|
-
resolve: {}
|
|
1995
|
-
});
|
|
1996
|
-
}
|
|
1997
|
-
/**
|
|
1998
|
-
* A setter function to populate the user config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the user configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any inline configuration provided during execution.
|
|
1999
|
-
*
|
|
2000
|
-
* @param config - The user configuration values to set.
|
|
2001
|
-
* @returns A promise that resolves when the user configuration values have been set.
|
|
2002
|
-
*/
|
|
2003
|
-
async setUserConfig(config) {
|
|
2004
|
-
this.logger.debug({
|
|
2005
|
-
meta: { category: "config" },
|
|
2006
|
-
message: `Updating user configuration object: \n${(0, _powerlines_core_plugin_utils.formatConfig)(config)}`
|
|
2007
|
-
});
|
|
2008
|
-
this.userConfig = config;
|
|
2009
|
-
await this.resolveConfig();
|
|
2010
|
-
}
|
|
2011
|
-
/**
|
|
2012
|
-
* Initialize the context with the provided configuration options
|
|
2013
|
-
*/
|
|
2014
|
-
async init() {
|
|
2015
|
-
await super.init();
|
|
2016
|
-
this.options.executionId = this.initialOptions.executionId || (0, _stryke_unique_id_uuid.uuid)();
|
|
2017
|
-
this.options.executionIndex = this.initialOptions.executionIndex ?? 0;
|
|
2018
|
-
this.#checksum = await this.generateChecksum();
|
|
2019
|
-
const result = this.configFile.config && (0, _stryke_convert_to_array.toArray)(this.configFile.config).length > this.options.executionIndex ? (0, _stryke_convert_to_array.toArray)(this.configFile.config)[this.options.executionIndex] : this.configFile.config;
|
|
2020
|
-
if (!result) this.logger.warn(`No configuration found in ${this.options.configFile} for execution index ${this.options.executionIndex}.`);
|
|
2021
|
-
else await this.setUserConfig((0, _stryke_type_checks_is_function.isFunction)(result) ? await Promise.resolve(result(this.options)) : result);
|
|
2022
|
-
}
|
|
2023
|
-
/**
|
|
2024
|
-
* Resolve the package configurations for the project by loading the `package.json` and `project.json` files, if they exist. This function will look for these files in the project root and parse their contents as JavaScript objects. The parsed contents will be stored in the context for later use by plugins and other parts of the build process.
|
|
2025
|
-
*
|
|
2026
|
-
* @remarks
|
|
2027
|
-
* The `package.json` file is typically used to store metadata about the project, such as its name, version, dependencies, and other information. The `project.json` file is an optional file that can be used to store additional configuration or metadata specific to the project, and is not required for all projects.
|
|
2028
|
-
*
|
|
2029
|
-
* @param cwd - The current working directory to look for the package configurations. Defaults to the `cwd` specified in the context configuration.
|
|
2030
|
-
* @param root - The root directory of the project to look for the package configurations. Defaults to the `root` specified in the context configuration.
|
|
2031
|
-
* @returns A promise that resolves when the package configurations have been loaded and stored in the context.
|
|
2032
|
-
*/
|
|
2033
|
-
async resolvePackageConfigs(cwd = this.config.cwd, root = this.config.root) {
|
|
2034
|
-
return super.resolvePackageConfigs(cwd, root);
|
|
2035
|
-
}
|
|
2036
|
-
/**
|
|
2037
|
-
* Initialize the context with the provided configuration options
|
|
2038
|
-
*/
|
|
2039
|
-
async resolveConfig() {
|
|
2040
|
-
const mergedConfig = this.mergeConfig();
|
|
2041
|
-
this.logger.trace({
|
|
2042
|
-
meta: { category: "config" },
|
|
2043
|
-
message: `Pre-setup Powerlines configuration object: \n --- Merged Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(mergedConfig)} \n\n --- Initial Options --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.initialOptions)} \n\n --- Initial Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.initialConfig)} \n\n --- User Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.userConfig)} \n\n --- Inline Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.inlineConfig)} \n\n --- Plugin Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.pluginConfig)} \n\n --- Environment Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.environmentConfig)} \n\n --- Overridden Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.overriddenConfig)}`
|
|
2044
|
-
});
|
|
2045
|
-
mergedConfig.output = (0, defu.default)(mergedConfig.output ?? {}, {
|
|
2046
|
-
copy: { assets: [
|
|
2047
|
-
{ glob: "LICENSE" },
|
|
2048
|
-
{
|
|
2049
|
-
input: mergedConfig.root,
|
|
2050
|
-
glob: "*.md"
|
|
2051
|
-
},
|
|
2052
|
-
{
|
|
2053
|
-
input: mergedConfig.root,
|
|
2054
|
-
glob: "package.json"
|
|
2055
|
-
}
|
|
2056
|
-
] },
|
|
2057
|
-
dts: true
|
|
2058
|
-
});
|
|
2059
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.mode)) mergedConfig.mode = await this.getDefaultMode();
|
|
2060
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.framework)) mergedConfig.framework = "powerlines";
|
|
2061
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.platform)) mergedConfig.platform = "neutral";
|
|
2062
|
-
mergedConfig.compatibilityDate = (0, compatx.resolveCompatibilityDates)(mergedConfig.compatibilityDate, "latest");
|
|
2063
|
-
if (!this.packageJson && (0, node_fs.existsSync)((0, _stryke_path_join.joinPaths)((0, _stryke_path_append.appendPath)(mergedConfig.root, mergedConfig.cwd), "package.json")) || !this.projectJson && (0, node_fs.existsSync)((0, _stryke_path_join.joinPaths)((0, _stryke_path_append.appendPath)(mergedConfig.root, mergedConfig.cwd), "project.json"))) {
|
|
2064
|
-
await this.resolvePackageConfigs(mergedConfig.cwd, mergedConfig.root);
|
|
2065
|
-
if (this.packageJson) mergedConfig.organization ??= (0, _powerlines_core_plugin_utils.getPackageJsonOrganization)(this.packageJson) || "powerlines";
|
|
2066
|
-
}
|
|
2067
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.projectType)) mergedConfig.projectType = this.projectJson?.projectType || "application";
|
|
2068
|
-
this.resolvedConfig = mergedConfig;
|
|
2069
|
-
this.#configProxy = this.createConfigProxy();
|
|
2070
|
-
mergedConfig.input = (0, _powerlines_core_lib_entry.getUniqueInputs)(mergedConfig.input);
|
|
2071
|
-
if (mergedConfig.name?.startsWith("@") && mergedConfig.name.split("/").filter(Boolean).length > 1) mergedConfig.name = mergedConfig.name.split("/").filter(Boolean)[1];
|
|
2072
|
-
mergedConfig.title ??= (0, _stryke_string_format_title_case.titleCase)(mergedConfig.name);
|
|
2073
|
-
if (mergedConfig.resolve.external) mergedConfig.resolve.external = (0, _stryke_helpers_get_unique.getUnique)(mergedConfig.resolve.external);
|
|
2074
|
-
if (mergedConfig.resolve.noExternal) mergedConfig.resolve.noExternal = (0, _stryke_helpers_get_unique.getUnique)(mergedConfig.resolve.noExternal);
|
|
2075
|
-
mergedConfig.plugins = (mergedConfig.plugins ?? []).flatMap((plugin) => (0, _stryke_convert_to_array.toArray)(plugin)).filter(Boolean).reduce((ret, plugin) => {
|
|
2076
|
-
if ((0, _powerlines_core_plugin_utils.isPlugin)(plugin) && (0, _powerlines_core_plugin_utils.isDuplicate)(plugin, ret.filter((p) => (0, _powerlines_core_plugin_utils.isPlugin)(p)))) return ret;
|
|
2077
|
-
ret.push(plugin);
|
|
2078
|
-
return ret;
|
|
2079
|
-
}, []);
|
|
2080
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.logLevel)) if (mergedConfig.mode === "development") mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_DEVELOPMENT_LOG_LEVEL;
|
|
2081
|
-
else if (mergedConfig.mode === "test") mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_TEST_LOG_LEVEL;
|
|
2082
|
-
else mergedConfig.logLevel = _powerlines_core_constants.DEFAULT_PRODUCTION_LOG_LEVEL;
|
|
2083
|
-
mergedConfig.logLevel = (0, _powerlines_core_plugin_utils.resolveLogLevel)(mergedConfig.logLevel);
|
|
2084
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(mergedConfig.tsconfig)) mergedConfig.tsconfig = (0, _stryke_path_replace.replacePath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.tsconfig), mergedConfig.cwd);
|
|
2085
|
-
else mergedConfig.tsconfig = require_tsconfig.getTsconfigFilePath(mergedConfig.cwd, mergedConfig.root);
|
|
2086
|
-
mergedConfig.output.format = (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(mergedConfig.output?.format ?? (mergedConfig.projectType === "library" ? ["cjs", "esm"] : ["esm"])));
|
|
2087
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(mergedConfig.output.path)) mergedConfig.output.path = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.path), mergedConfig.cwd);
|
|
2088
|
-
else mergedConfig.output.path = (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(mergedConfig.root, "dist"), mergedConfig.cwd);
|
|
2089
|
-
mergedConfig.output.copy ??= {};
|
|
2090
|
-
if (mergedConfig.output.copy !== false) if (!mergedConfig.root.replace(/^\.\/?/, "")) mergedConfig.output.copy.path = (0, _stryke_type_checks_is_set_string.isSetString)(mergedConfig.output.copy.path) ? (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.copy.path), mergedConfig.cwd) : mergedConfig.output.path;
|
|
2091
|
-
else mergedConfig.output.copy.path = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, (0, _stryke_type_checks_is_set_string.isSetString)(mergedConfig.output.copy.path) ? mergedConfig.output.copy.path : (0, _stryke_path_join.joinPaths)("dist", mergedConfig.root)), mergedConfig.cwd);
|
|
2092
|
-
if (mergedConfig.output.types !== false) mergedConfig.output.types = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, mergedConfig.output.types || (0, _stryke_path_join.joinPaths)(mergedConfig.root, `${mergedConfig.framework ?? "powerlines"}.d.ts`)), mergedConfig.cwd);
|
|
2093
|
-
if (mergedConfig.output.copy && mergedConfig.output.copy.path && mergedConfig.output.copy.assets && Array.isArray(mergedConfig.output.copy.assets)) mergedConfig.output.copy.assets = (0, _stryke_helpers_get_unique.getUniqueBy)(mergedConfig.output.copy.assets.map((asset) => {
|
|
2094
|
-
return {
|
|
2095
|
-
glob: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) ? asset.glob : asset,
|
|
2096
|
-
input: (0, _stryke_type_checks_is_string.isString)(asset) || !asset.input || asset.input === "." || asset.input === "/" || asset.input === "./" ? mergedConfig.cwd : (0, _stryke_path_is_parent_path.isParentPath)(asset.input, mergedConfig.cwd) || (0, _stryke_path_is_equal.isEqual)(asset.input, mergedConfig.cwd) ? asset.input : (0, _stryke_path_append.appendPath)(asset.input, mergedConfig.cwd),
|
|
2097
|
-
output: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) && asset.output ? (0, _stryke_path_is_parent_path.isParentPath)(asset.output, mergedConfig.cwd) ? asset.output : (0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(mergedConfig.output.copy.path, (0, _stryke_path_replace.replacePath)((0, _stryke_path_replace.replacePath)(asset.output, (0, _stryke_path_replace.replacePath)(mergedConfig.output.copy.path, mergedConfig.cwd)), mergedConfig.output.copy.path)), mergedConfig.cwd) : (0, _stryke_path_append.appendPath)(mergedConfig.output.copy.path, mergedConfig.cwd),
|
|
2098
|
-
ignore: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) && asset.ignore ? (0, _stryke_convert_to_array.toArray)(asset.ignore) : void 0
|
|
2099
|
-
};
|
|
2100
|
-
}), (a) => `${a.input}-${a.glob}-${a.output}`);
|
|
2101
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.output?.sourceMap)) if (mergedConfig.mode === "development") mergedConfig.output.sourceMap = true;
|
|
2102
|
-
else mergedConfig.output.sourceMap = false;
|
|
2103
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.output?.minify)) if (mergedConfig.mode === "production") mergedConfig.output.minify = true;
|
|
2104
|
-
else mergedConfig.output.minify = false;
|
|
2105
|
-
if ((0, _stryke_type_checks_is_undefined.isUndefined)(mergedConfig.output?.artifactsPath)) mergedConfig.output.artifactsPath = `.${mergedConfig.framework || "powerlines"}`;
|
|
2106
|
-
if (mergedConfig.output.copy && mergedConfig.output.copy.assets) mergedConfig.output.copy.assets = mergedConfig.output.copy.assets.map((asset) => ({
|
|
2107
|
-
...asset,
|
|
2108
|
-
glob: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.glob),
|
|
2109
|
-
ignore: asset.ignore ? asset.ignore.map((ignore) => (0, _powerlines_core_plugin_utils.replacePathTokens)(this, ignore)) : void 0,
|
|
2110
|
-
input: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.input),
|
|
2111
|
-
output: (0, _powerlines_core_plugin_utils.replacePathTokens)(this, asset.output)
|
|
2112
|
-
}));
|
|
2113
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(mergedConfig.output?.storage) && mergedConfig.output.storage === "virtual" || (0, _stryke_type_checks_is_set_object.isSetObject)(mergedConfig.output?.storage) && Object.values(mergedConfig.output.storage).every((adapter) => adapter.preset === "virtual")) mergedConfig.output.overwrite = true;
|
|
2114
|
-
this.resolvedConfig = mergedConfig;
|
|
2115
|
-
this.#configProxy = this.createConfigProxy();
|
|
2116
|
-
this.logger.info({
|
|
2117
|
-
meta: { category: "config" },
|
|
2118
|
-
message: `Resolved Powerlines configuration object: \n${(0, _powerlines_core_plugin_utils.formatConfig)(this.resolvedConfig)}`
|
|
2119
|
-
});
|
|
2120
|
-
this.#fs ??= await VirtualFileSystem.create(this);
|
|
2121
|
-
}
|
|
2122
|
-
createConfigProxy() {
|
|
2123
|
-
return new Proxy(this.resolvedConfig, {
|
|
2124
|
-
/**
|
|
2125
|
-
* A trap for the `delete` operator.
|
|
2126
|
-
* @param target - The original object which is being proxied.
|
|
2127
|
-
* @param key - The name or `Symbol` of the property to delete.
|
|
2128
|
-
* @returns A `boolean` indicating whether or not the property was deleted.
|
|
2129
|
-
*/
|
|
2130
|
-
deleteProperty: (target, key) => {
|
|
2131
|
-
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) throw new Error(`Cannot delete property ${key.toString()} from config - it is only intended to be used as a reference.`);
|
|
2132
|
-
Reflect.deleteProperty(this.overriddenConfig, key);
|
|
2133
|
-
return Reflect.deleteProperty(target, key);
|
|
2134
|
-
},
|
|
2135
|
-
/**
|
|
2136
|
-
* A trap for getting a property value.
|
|
2137
|
-
* @param target - The original object which is being proxied.
|
|
2138
|
-
* @param key - The name or `Symbol` of the property to get.
|
|
2139
|
-
* @param receiver - The proxy or an object that inherits from the proxy.
|
|
2140
|
-
*/
|
|
2141
|
-
get: (target, key, receiver) => {
|
|
2142
|
-
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) {
|
|
2143
|
-
if (key === "initialConfig") return this.initialConfig;
|
|
2144
|
-
if (key === "userConfig") return this.userConfig;
|
|
2145
|
-
if (key === "inlineConfig") return this.inlineConfig;
|
|
2146
|
-
if (key === "pluginConfig") return this.pluginConfig;
|
|
2147
|
-
if (key === "environmentConfig") return this.environmentConfig;
|
|
2148
|
-
}
|
|
2149
|
-
return Reflect.get(target, key, receiver);
|
|
2150
|
-
},
|
|
2151
|
-
/**
|
|
2152
|
-
* A trap for the `in` operator.
|
|
2153
|
-
* @param target - The original object which is being proxied.
|
|
2154
|
-
* @param key - The name or `Symbol` of the property to check for existence.
|
|
2155
|
-
*/
|
|
2156
|
-
has: (target, key) => {
|
|
2157
|
-
return Reflect.has(target, key) || UNRESOLVED_CONFIG_NAMES.includes(key.toString());
|
|
2158
|
-
},
|
|
2159
|
-
/**
|
|
2160
|
-
* A trap for `Reflect.ownKeys()`.
|
|
2161
|
-
* @param target - The original object which is being proxied.
|
|
2162
|
-
*/
|
|
2163
|
-
ownKeys: (target) => {
|
|
2164
|
-
return (0, _stryke_helpers_get_unique.getUnique)([...Reflect.ownKeys(target), ...UNRESOLVED_CONFIG_NAMES]);
|
|
2165
|
-
},
|
|
2166
|
-
/**
|
|
2167
|
-
* A trap for setting a property value.
|
|
2168
|
-
* @param target - The original object which is being proxied.
|
|
2169
|
-
* @param key - The name or `Symbol` of the property to set.
|
|
2170
|
-
* @param newValue - The new value to assign to the property.
|
|
2171
|
-
* @param receiver - The object to which the assignment was originally directed.
|
|
2172
|
-
* @returns A `boolean` indicating whether or not the property was set.
|
|
2173
|
-
*/
|
|
2174
|
-
set: (target, key, newValue, receiver) => {
|
|
2175
|
-
if (UNRESOLVED_CONFIG_NAMES.includes(key.toString())) throw new Error(`Cannot change property ${key.toString()} from config - it is only intended to be used as a reference.`);
|
|
2176
|
-
Reflect.set(this.overriddenConfig, key, newValue, receiver);
|
|
2177
|
-
return Reflect.set(target, key, newValue, receiver);
|
|
2178
|
-
}
|
|
2179
|
-
});
|
|
2180
|
-
}
|
|
2181
|
-
};
|
|
2182
|
-
|
|
2183
|
-
//#endregion
|
|
2184
|
-
//#region src/_internal/helpers/hooks.ts
|
|
2185
|
-
/**
|
|
2186
|
-
* Merges the current hook result with the previous results based on their types.
|
|
2187
|
-
*
|
|
2188
|
-
* @param currentResult - The current hook result to merge with the previous results.
|
|
2189
|
-
* @param previousResults - The previous hook results to merge with the current result.
|
|
2190
|
-
* @returns The merged result.
|
|
2191
|
-
*/
|
|
2192
|
-
function mergeResults(currentResult, previousResults) {
|
|
2193
|
-
if (!previousResults || previousResults.length === 0) return [currentResult];
|
|
2194
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(currentResult)) previousResults = [`${(0, _stryke_type_checks_is_set_string.isSetString)(previousResults[0]) ? previousResults[0] || "" : ""}\n${(0, _stryke_type_checks_is_set_string.isSetString)(previousResults[0]) ? currentResult.replace(previousResults[0], "") : currentResult}`.trim()];
|
|
2195
|
-
else if ((0, _stryke_type_checks_is_object.isObject)(currentResult)) previousResults = previousResults.length > 0 ? [(0, defu.defu)(currentResult, previousResults[0])] : [currentResult];
|
|
2196
|
-
return previousResults;
|
|
2197
|
-
}
|
|
2198
|
-
/**
|
|
2199
|
-
* Merges multiple hook results together, with special handling for string values and object values.
|
|
2200
|
-
*
|
|
2201
|
-
* @param currentResult - The current hook result to merge with the previous results.
|
|
2202
|
-
* @param previousResults - The previous hook results to merge with the current result.
|
|
2203
|
-
* @returns The merged result.
|
|
2204
|
-
*/
|
|
2205
|
-
function mergeConfigs(currentResult, previousResults) {
|
|
2206
|
-
if ((0, _stryke_type_checks_is_string.isString)(currentResult)) previousResults = `${(0, _stryke_type_checks_is_string.isString)(previousResults) ? previousResults || "" : ""}\n${currentResult || ""}`.trim();
|
|
2207
|
-
else if ((0, _stryke_type_checks_is_object.isObject)(currentResult)) previousResults = (0, _powerlines_core_plugin_utils.mergeConfig)(currentResult, previousResults ?? {});
|
|
2208
|
-
return previousResults;
|
|
2209
|
-
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Calls a hook with the given context, options, and arguments.
|
|
2212
|
-
*
|
|
2213
|
-
* @param context - The context to use when calling the hook.
|
|
2214
|
-
* @param key - The hook to call.
|
|
2215
|
-
* @param options - Options for calling the hook.
|
|
2216
|
-
* @param args - Arguments to pass to the hook.
|
|
2217
|
-
* @returns The return value of the hook.
|
|
2218
|
-
*/
|
|
2219
|
-
async function callHook(context, key, options, ...args) {
|
|
2220
|
-
const hooks = context.selectHooks(key, options);
|
|
2221
|
-
if (hooks.length > 0) {
|
|
2222
|
-
context.extendLogger({ category: "hooks" }).debug(`🧩 Calling ${hooks.length} ${chalk.default.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)} plugin hook${hooks.length > 1 ? "s" : ""}:\n${hooks.map((hook, index) => ` ${index + 1}. ${(0, _powerlines_core_plugin_utils_logging.colorText)(hook.plugin.name)}`).join("\n")}`);
|
|
2223
|
-
const invokeHook = async (hook, hookArgs) => {
|
|
2224
|
-
return Reflect.apply(hook.handler, hook.context, hookArgs);
|
|
2225
|
-
};
|
|
2226
|
-
let results = [];
|
|
2227
|
-
if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
|
|
2228
|
-
if (!(0, _stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
2229
|
-
return invokeHook(hook, [...args]);
|
|
2230
|
-
}));
|
|
2231
|
-
else for (const hook of hooks) {
|
|
2232
|
-
if (!(0, _stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
2233
|
-
if (options?.result === "first" || options?.asNextParam === false) {
|
|
2234
|
-
results.push(await Promise.resolve(invokeHook(hook, [...args])));
|
|
2235
|
-
if (options?.result === "first" && (0, _stryke_type_checks_is_set.isSet)(results[results.length - 1])) break;
|
|
2236
|
-
} else {
|
|
2237
|
-
const sequenceArgs = [...args];
|
|
2238
|
-
if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = (0, _stryke_type_checks_is_function.isFunction)(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
|
|
2239
|
-
const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
|
|
2240
|
-
if (result) if (options.result === "last") results = [result];
|
|
2241
|
-
else if (options.result === "merge" && options.merge) results = [results.length > 0 && results[0] ? await Promise.resolve(options.merge(result, results[0])) : result];
|
|
2242
|
-
else results = mergeResults(result, results);
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
const definedResults = results.filter((result) => (0, _stryke_type_checks_is_set.isSet)(result));
|
|
2246
|
-
if (definedResults.length > 0) {
|
|
2247
|
-
let mergedResult = void 0;
|
|
2248
|
-
for (const result of definedResults) mergedResult = (0, defu.defu)(result, mergedResult ?? {});
|
|
2249
|
-
return mergedResult;
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
function extractHooks(context, hooks, plugin, key, parentKey) {
|
|
2254
|
-
const combinedKey = parentKey ? `${parentKey}:${key}` : key;
|
|
2255
|
-
const pluginField = (0, _stryke_helpers_get_field.getField)(plugin, combinedKey.replace(/:/g, "."));
|
|
2256
|
-
if ((0, _powerlines_core_plugin_utils.isPluginHookField)(combinedKey) && (0, _powerlines_core_plugin_utils.isPluginHook)(pluginField)) {
|
|
2257
|
-
const pluginHook = pluginField;
|
|
2258
|
-
if (!(0, _powerlines_core_plugin_utils.isPluginHook)(pluginHook)) return hooks;
|
|
2259
|
-
hooks[combinedKey] ??= {
|
|
2260
|
-
preEnforced: [],
|
|
2261
|
-
preOrdered: [],
|
|
2262
|
-
normal: [],
|
|
2263
|
-
postEnforced: [],
|
|
2264
|
-
postOrdered: []
|
|
2265
|
-
};
|
|
2266
|
-
if (plugin.enforce) {
|
|
2267
|
-
const hookListOrder = `${plugin.enforce}Enforced`;
|
|
2268
|
-
hooks[combinedKey][hookListOrder] ??= [];
|
|
2269
|
-
hooks[combinedKey][hookListOrder] = (0, _powerlines_core_plugin_utils.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
|
|
2270
|
-
return hooks;
|
|
2271
|
-
}
|
|
2272
|
-
if ((0, _stryke_type_checks_is_function.isFunction)(pluginHook) || !pluginHook.order) {
|
|
2273
|
-
hooks[combinedKey].normal ??= [];
|
|
2274
|
-
hooks[combinedKey].normal = (0, _powerlines_core_plugin_utils.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey].normal);
|
|
2275
|
-
return hooks;
|
|
2276
|
-
}
|
|
2277
|
-
const hookListOrder = `${pluginHook.order}Ordered`;
|
|
2278
|
-
hooks[combinedKey][hookListOrder] ??= [];
|
|
2279
|
-
hooks[combinedKey][hookListOrder] = (0, _powerlines_core_plugin_utils.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
|
|
2280
|
-
return hooks;
|
|
2281
|
-
} else if ((0, _stryke_type_checks_is_set_object.isSetObject)(pluginField)) return Object.keys(pluginField).map((pluginKey) => extractHooks(context, hooks, plugin, pluginKey, combinedKey)).reduce((ret, current) => {
|
|
2282
|
-
Object.keys(current).forEach((key) => {
|
|
2283
|
-
ret[key] ??= {
|
|
2284
|
-
preEnforced: [],
|
|
2285
|
-
preOrdered: [],
|
|
2286
|
-
normal: [],
|
|
2287
|
-
postEnforced: [],
|
|
2288
|
-
postOrdered: []
|
|
2289
|
-
};
|
|
2290
|
-
[
|
|
2291
|
-
"preEnforced",
|
|
2292
|
-
"preOrdered",
|
|
2293
|
-
"normal",
|
|
2294
|
-
"postEnforced",
|
|
2295
|
-
"postOrdered"
|
|
2296
|
-
].forEach((order) => {
|
|
2297
|
-
if (current[key]?.[order]) {
|
|
2298
|
-
ret[key][order] ??= [];
|
|
2299
|
-
ret[key][order] = ret[key][order].concat(current[key][order]);
|
|
2300
|
-
}
|
|
2301
|
-
});
|
|
2302
|
-
});
|
|
2303
|
-
return ret;
|
|
2304
|
-
}, hooks);
|
|
2305
|
-
return hooks;
|
|
2306
|
-
}
|
|
2307
|
-
|
|
2308
|
-
//#endregion
|
|
2309
|
-
//#region src/context/plugin-context.ts
|
|
2310
|
-
/**
|
|
2311
|
-
* Create a Proxy-based PluginContext
|
|
2312
|
-
*
|
|
2313
|
-
* @param pluginId - The unique identifier of the plugin
|
|
2314
|
-
* @param plugin - The plugin instance
|
|
2315
|
-
* @param environment - The environment context
|
|
2316
|
-
* @returns The proxied plugin context
|
|
2317
|
-
*/
|
|
2318
|
-
function createPluginContext(pluginId, plugin, environment) {
|
|
2319
|
-
const logger = environment.extendLogger({ plugin: plugin.name });
|
|
2320
|
-
const normalizeMessage = (message) => {
|
|
2321
|
-
return {
|
|
2322
|
-
meta: {
|
|
2323
|
-
...(0, _stryke_type_checks_is_set_object.isSetObject)(message) ? message.meta : {},
|
|
2324
|
-
environment: environment.config.environment.name,
|
|
2325
|
-
plugin: plugin.name
|
|
2326
|
-
},
|
|
2327
|
-
message: (0, _stryke_type_checks_is_string.isString)(message) ? message : message.message
|
|
2328
|
-
};
|
|
2329
|
-
};
|
|
2330
|
-
const callHookFn = async (hook, options, ...args) => {
|
|
2331
|
-
return environment.$$internal.api.callHook(hook, {
|
|
2332
|
-
sequential: true,
|
|
2333
|
-
result: "merge",
|
|
2334
|
-
...options,
|
|
2335
|
-
environment
|
|
2336
|
-
}, ...args);
|
|
2337
|
-
};
|
|
2338
|
-
const meta = {};
|
|
2339
|
-
return new Proxy({}, {
|
|
2340
|
-
get(_, prop) {
|
|
2341
|
-
if (prop === "$$internal") return {
|
|
2342
|
-
...environment.$$internal,
|
|
2343
|
-
environment,
|
|
2344
|
-
callHook: callHookFn,
|
|
2345
|
-
meta
|
|
2346
|
-
};
|
|
2347
|
-
if (prop === "api") return environment.$$internal.api;
|
|
2348
|
-
if (prop === "environment") return environment;
|
|
2349
|
-
if (prop === "id") return pluginId;
|
|
2350
|
-
if (prop === "logger") return logger;
|
|
2351
|
-
if (prop === "log") return (type, message) => {
|
|
2352
|
-
logger.log(type, normalizeMessage(message));
|
|
2353
|
-
};
|
|
2354
|
-
if (prop === "fatal") return (message) => {
|
|
2355
|
-
logger.error(normalizeMessage(message));
|
|
2356
|
-
};
|
|
2357
|
-
if (prop === "error") return (message) => {
|
|
2358
|
-
logger.error(normalizeMessage(message));
|
|
2359
|
-
};
|
|
2360
|
-
if (prop === "warn") return (message) => {
|
|
2361
|
-
logger.warn(normalizeMessage(message));
|
|
2362
|
-
};
|
|
2363
|
-
if (prop === "info") return (message) => {
|
|
2364
|
-
logger.info(normalizeMessage(message));
|
|
2365
|
-
};
|
|
2366
|
-
if (prop === "debug") return (message) => {
|
|
2367
|
-
logger.debug(normalizeMessage(message));
|
|
2368
|
-
};
|
|
2369
|
-
if (prop === "trace") return (message) => {
|
|
2370
|
-
logger.trace(normalizeMessage(message));
|
|
2371
|
-
};
|
|
2372
|
-
return environment[prop];
|
|
2373
|
-
},
|
|
2374
|
-
set(_, prop, value) {
|
|
2375
|
-
if ([
|
|
2376
|
-
"$$internal",
|
|
2377
|
-
"id",
|
|
2378
|
-
"environment",
|
|
2379
|
-
"config",
|
|
2380
|
-
"log",
|
|
2381
|
-
"logger",
|
|
2382
|
-
"error",
|
|
2383
|
-
"warn",
|
|
2384
|
-
"plugins",
|
|
2385
|
-
"hooks",
|
|
2386
|
-
"addPlugin",
|
|
2387
|
-
"selectHooks"
|
|
2388
|
-
].includes(prop)) {
|
|
2389
|
-
logger.warn(`Cannot set the read-only "${String(prop)}" property`);
|
|
2390
|
-
return false;
|
|
2391
|
-
}
|
|
2392
|
-
environment[prop] = value;
|
|
2393
|
-
return true;
|
|
2394
|
-
}
|
|
2395
|
-
});
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
//#endregion
|
|
2399
|
-
//#region src/context/environment-context.ts
|
|
2400
|
-
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
2401
|
-
/**
|
|
2402
|
-
* Internal references storage
|
|
2403
|
-
*
|
|
2404
|
-
* @danger
|
|
2405
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2406
|
-
*
|
|
2407
|
-
* @internal
|
|
2408
|
-
*/
|
|
2409
|
-
#internal = {};
|
|
2410
|
-
/**
|
|
2411
|
-
* The hooks registered by plugins in this environment
|
|
2412
|
-
*/
|
|
2413
|
-
#hooks = {};
|
|
2414
|
-
/**
|
|
2415
|
-
* Create a new context from the config.
|
|
2416
|
-
*
|
|
2417
|
-
* @param initialOptions - The resolved execution options.
|
|
2418
|
-
* @param config - The user configuration options.
|
|
2419
|
-
* @param overriddenConfig - The configuration options that should override all other configuration sources, such as CLI flags or environment variables. This is used to ensure that certain configuration values take precedence over any other settings defined in the user configuration or environment configuration, allowing for dynamic overrides based on the execution context.
|
|
2420
|
-
* @param environment - The resolved environment configuration, which may include additional properties or modifications made during the configuration loading process. This is used to provide context about the environment in which the command is being executed, allowing for environment-specific behavior and configuration resolution.
|
|
2421
|
-
* @returns A promise that resolves to an instance of the PowerlinesEnvironmentContext class, initialized with the provided configuration and environment data.
|
|
2422
|
-
*/
|
|
2423
|
-
static async createEnvironment(initialOptions, config, overriddenConfig, environment) {
|
|
2424
|
-
const context = new PowerlinesEnvironmentContext(initialOptions, config, overriddenConfig);
|
|
2425
|
-
await context.setEnvironmentConfig(environment);
|
|
2426
|
-
return context;
|
|
2427
|
-
}
|
|
2428
|
-
/**
|
|
2429
|
-
* The configuration options provided by plugins added by the user (and other plugins)
|
|
2430
|
-
*/
|
|
2431
|
-
environmentConfig = {};
|
|
2432
|
-
/**
|
|
2433
|
-
* The list of plugins applied to this environment
|
|
2434
|
-
*/
|
|
2435
|
-
plugins = [];
|
|
2436
|
-
/**
|
|
2437
|
-
* Internal context fields and methods
|
|
2438
|
-
*
|
|
2439
|
-
* @danger
|
|
2440
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2441
|
-
*
|
|
2442
|
-
* @internal
|
|
2443
|
-
*/
|
|
2444
|
-
get $$internal() {
|
|
2445
|
-
return this.#internal;
|
|
2446
|
-
}
|
|
2447
|
-
/**
|
|
2448
|
-
* Internal context fields and methods
|
|
2449
|
-
*
|
|
2450
|
-
* @danger
|
|
2451
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2452
|
-
*
|
|
2453
|
-
* @internal
|
|
2454
|
-
*/
|
|
2455
|
-
set $$internal(value) {
|
|
2456
|
-
this.#internal = value;
|
|
2457
|
-
}
|
|
2458
|
-
/**
|
|
2459
|
-
* The unique identifier of the environment associated with this context, which can be used for logging and other purposes to distinguish between different environments in the same process.
|
|
2460
|
-
*/
|
|
2461
|
-
get id() {
|
|
2462
|
-
return this.config.environment.id;
|
|
2463
|
-
}
|
|
2464
|
-
/**
|
|
2465
|
-
* The hooks registered by plugins in this environment
|
|
2466
|
-
*/
|
|
2467
|
-
get hooks() {
|
|
2468
|
-
return this.#hooks;
|
|
2469
|
-
}
|
|
2470
|
-
/**
|
|
2471
|
-
* A setter function to populate the environment config values provided during execution of the command, such as CLI flags or other parameters that may be relevant to the command being executed. This function can be used to update the context with the environment configuration values, which may be used during the configuration resolution process to ensure that the final configuration reflects both the user configuration and any environment configuration provided during execution.
|
|
2472
|
-
*
|
|
2473
|
-
* @param config - The environment configuration values to set.
|
|
2474
|
-
* @returns A promise that resolves when the environment configuration values have been set.
|
|
2475
|
-
*/
|
|
2476
|
-
async setEnvironmentConfig(config) {
|
|
2477
|
-
this.logger.debug({
|
|
2478
|
-
meta: { category: "config" },
|
|
2479
|
-
message: `Updating environment configuration object: \n${(0, _powerlines_core_plugin_utils.formatConfig)(config)}`
|
|
2480
|
-
});
|
|
2481
|
-
this.environmentConfig = config;
|
|
2482
|
-
await this.resolveConfig();
|
|
2483
|
-
}
|
|
2484
|
-
/**
|
|
2485
|
-
* Create a new logger instance
|
|
2486
|
-
*
|
|
2487
|
-
* @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.
|
|
2488
|
-
* @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.
|
|
2489
|
-
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
2490
|
-
*/
|
|
2491
|
-
createLogger(options, logFn) {
|
|
2492
|
-
return super.createLogger({
|
|
2493
|
-
...options,
|
|
2494
|
-
environment: this.config.environment?.name
|
|
2495
|
-
}, logFn);
|
|
2496
|
-
}
|
|
2497
|
-
/**
|
|
2498
|
-
* Extend the base logger with additional configuration options
|
|
2499
|
-
*
|
|
2500
|
-
* @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.
|
|
2501
|
-
* @returns A new logger client instance that extends the base logger with the provided configuration options.
|
|
2502
|
-
*/
|
|
2503
|
-
extendLogger(options) {
|
|
2504
|
-
return super.extendLogger({
|
|
2505
|
-
...options,
|
|
2506
|
-
environment: this.config.environment?.name
|
|
2507
|
-
});
|
|
2508
|
-
}
|
|
2509
|
-
async addPlugin(plugin) {
|
|
2510
|
-
let resolvedPlugin = plugin;
|
|
2511
|
-
if ((0, _stryke_type_checks_is_function.isFunction)(plugin.applyToEnvironment)) {
|
|
2512
|
-
const result = await Promise.resolve(plugin.applyToEnvironment(this.config.environment));
|
|
2513
|
-
if (!result || (0, _stryke_type_checks_is_object.isObject)(result) && Object.keys(result).length === 0) return;
|
|
2514
|
-
if ((0, _powerlines_core_plugin_utils.isPluginConfig)(result)) return this.$$internal.addPlugin(result);
|
|
2515
|
-
resolvedPlugin = (0, _powerlines_core_plugin_utils.isPlugin)(result) ? result : plugin;
|
|
2516
|
-
}
|
|
2517
|
-
const id = (0, _stryke_unique_id_uuid.uuid)();
|
|
2518
|
-
const context = createPluginContext(id, resolvedPlugin, this);
|
|
2519
|
-
this.plugins.push({
|
|
2520
|
-
id,
|
|
2521
|
-
plugin: resolvedPlugin,
|
|
2522
|
-
context
|
|
2523
|
-
});
|
|
2524
|
-
this.#hooks = Object.entries(Object.keys(resolvedPlugin).filter((key) => !_powerlines_core_constants.PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => extractHooks(context, ret, resolvedPlugin, key), this.hooks)).reduce((ret, [key, value]) => {
|
|
2525
|
-
if ((0, _stryke_type_checks_is_set_object.isSetObject)(value)) Object.entries(value).forEach(([type, list]) => {
|
|
2526
|
-
ret[key] ??= {};
|
|
2527
|
-
ret[key][type] = (0, _powerlines_core_plugin_utils.dedupeHooklist)(list);
|
|
2528
|
-
});
|
|
2529
|
-
return ret;
|
|
2530
|
-
}, {});
|
|
2531
|
-
}
|
|
2532
|
-
/**
|
|
2533
|
-
* Retrieves the hook handlers for a specific hook name
|
|
2534
|
-
*/
|
|
2535
|
-
selectHooks(key, options) {
|
|
2536
|
-
const result = [];
|
|
2537
|
-
if ((0, _powerlines_core_plugin_utils.isPluginHookField)(key) && this.hooks[key]) {
|
|
2538
|
-
if (this.hooks[key]) if (options?.order) {
|
|
2539
|
-
const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
|
|
2540
|
-
const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
|
|
2541
|
-
if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
|
|
2542
|
-
return {
|
|
2543
|
-
handler: hook.handler,
|
|
2544
|
-
plugin: hook.plugin,
|
|
2545
|
-
context: plugin.context
|
|
2546
|
-
};
|
|
2547
|
-
});
|
|
2548
|
-
if (options?.order === "pre") {
|
|
2549
|
-
result.push(...mapHooksToResult(this.hooks[key].preOrdered ?? []));
|
|
2550
|
-
result.push(...mapHooksToResult(this.hooks[key].preEnforced ?? []));
|
|
2551
|
-
} else if (options?.order === "post") {
|
|
2552
|
-
result.push(...mapHooksToResult(this.hooks[key].postOrdered ?? []));
|
|
2553
|
-
result.push(...mapHooksToResult(this.hooks[key].postEnforced ?? []));
|
|
2554
|
-
} else result.push(...mapHooksToResult(this.hooks[key].normal ?? []));
|
|
2555
|
-
} else {
|
|
2556
|
-
result.push(...this.selectHooks(key, { order: "pre" }));
|
|
2557
|
-
result.push(...this.selectHooks(key, { order: "normal" }));
|
|
2558
|
-
result.push(...this.selectHooks(key, { order: "post" }));
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
return result;
|
|
2562
|
-
}
|
|
2563
|
-
constructor(options, config, overriddenConfig) {
|
|
2564
|
-
super(options, config.initialConfig);
|
|
2565
|
-
this.userConfig = config.userConfig ?? {};
|
|
2566
|
-
this.inlineConfig = config.inlineConfig ?? {};
|
|
2567
|
-
this.pluginConfig = config.pluginConfig ?? {};
|
|
2568
|
-
this.overriddenConfig = overriddenConfig;
|
|
2569
|
-
}
|
|
2570
|
-
/**
|
|
2571
|
-
* A function to merge the various configuration objects (initial, user, inline, and plugin) into a single resolved configuration object that can be used throughout the Powerlines process. This function takes into account the different sources of configuration and their respective priorities, ensuring that the final configuration reflects the intended settings for the project. The merged configuration is then returned as a new object that can be accessed through the `config` property of the context.
|
|
2572
|
-
*
|
|
2573
|
-
* @returns The merged configuration object that combines the initial, user, inline, and plugin configurations.
|
|
2574
|
-
*/
|
|
2575
|
-
mergeConfig() {
|
|
2576
|
-
return (0, _powerlines_core_plugin_utils.mergeConfig)({
|
|
2577
|
-
...(0, _stryke_helpers_omit.omit)(this.environmentConfig ?? {}, [
|
|
2578
|
-
"name",
|
|
2579
|
-
"ssr",
|
|
2580
|
-
"preview",
|
|
2581
|
-
"consumer",
|
|
2582
|
-
"runtime"
|
|
2583
|
-
]),
|
|
2584
|
-
environment: { name: this.environmentConfig?.name || _powerlines_core_constants.DEFAULT_ENVIRONMENT },
|
|
2585
|
-
environmentConfig: this.environmentConfig ?? {}
|
|
2586
|
-
}, super.mergeConfig());
|
|
2587
|
-
}
|
|
2588
|
-
};
|
|
2589
|
-
|
|
2590
|
-
//#endregion
|
|
2591
|
-
//#region src/context/execution-context.ts
|
|
2592
|
-
var PowerlinesExecutionContext = class PowerlinesExecutionContext extends PowerlinesContext {
|
|
2593
|
-
/**
|
|
2594
|
-
* Internal references storage
|
|
2595
|
-
*
|
|
2596
|
-
* @danger
|
|
2597
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2598
|
-
*
|
|
2599
|
-
* @internal
|
|
2600
|
-
*/
|
|
2601
|
-
#internal = {};
|
|
2602
|
-
/**
|
|
2603
|
-
* A record of all environments by name
|
|
2604
|
-
*/
|
|
2605
|
-
#environments = {};
|
|
2606
|
-
/**
|
|
2607
|
-
* 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.
|
|
2608
|
-
*/
|
|
2609
|
-
#plugins = [];
|
|
2610
|
-
/**
|
|
2611
|
-
* Create a new Storm context from the workspace root and user config.
|
|
2612
|
-
*
|
|
2613
|
-
* @param options - The options for resolving the context.
|
|
2614
|
-
* @returns A promise that resolves to the new context.
|
|
2615
|
-
*/
|
|
2616
|
-
static async fromInitialConfig(options, initialConfig) {
|
|
2617
|
-
const context = new PowerlinesExecutionContext(options, initialConfig);
|
|
2618
|
-
await context.init();
|
|
2619
|
-
return context;
|
|
2620
|
-
}
|
|
2621
|
-
/**
|
|
2622
|
-
* Create a new Storm context from the workspace root and user config.
|
|
2623
|
-
*
|
|
2624
|
-
* @param options - The options for resolving the context.
|
|
2625
|
-
* @returns A promise that resolves to the new context.
|
|
2626
|
-
*/
|
|
2627
|
-
static async fromInlineConfig(options, initialConfig, inlineConfig) {
|
|
2628
|
-
const context = new PowerlinesExecutionContext(options, initialConfig);
|
|
2629
|
-
await context.init();
|
|
2630
|
-
await context.setInlineConfig(inlineConfig);
|
|
2631
|
-
return context;
|
|
2632
|
-
}
|
|
2633
|
-
/**
|
|
2634
|
-
* Internal context fields and methods
|
|
2635
|
-
*
|
|
2636
|
-
* @danger
|
|
2637
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2638
|
-
*
|
|
2639
|
-
* @internal
|
|
2640
|
-
*/
|
|
2641
|
-
get $$internal() {
|
|
2642
|
-
return this.#internal;
|
|
2643
|
-
}
|
|
2644
|
-
/**
|
|
2645
|
-
* Internal context fields and methods
|
|
2646
|
-
*
|
|
2647
|
-
* @danger
|
|
2648
|
-
* This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
|
|
2649
|
-
*
|
|
2650
|
-
* @internal
|
|
2651
|
-
*/
|
|
2652
|
-
set $$internal(value) {
|
|
2653
|
-
this.#internal = value;
|
|
2654
|
-
for (const environment of Object.values(this.environments)) environment.$$internal = value;
|
|
2655
|
-
}
|
|
2656
|
-
/**
|
|
2657
|
-
* 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.
|
|
2658
|
-
*/
|
|
2659
|
-
get id() {
|
|
2660
|
-
return this.options.executionId;
|
|
2661
|
-
}
|
|
2662
|
-
/**
|
|
2663
|
-
* A record of all environments by name
|
|
2664
|
-
*/
|
|
2665
|
-
get environments() {
|
|
2666
|
-
return this.#environments;
|
|
2667
|
-
}
|
|
2668
|
-
get plugins() {
|
|
2669
|
-
return this.#plugins;
|
|
2670
|
-
}
|
|
2671
|
-
/**
|
|
2672
|
-
* Creates a new instance.
|
|
2673
|
-
*
|
|
2674
|
-
* @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
|
|
2675
|
-
* @param initialConfig - The initial configuration options to use for the context, which can be used to provide default values for configuration options that may be overridden by user configuration or inline configuration. This is typically the configuration options provided by the user in a configuration file on disk, and can include any relevant settings such as environment definitions, plugin configurations, and other parameters that may be relevant to the execution of a Powerlines command.
|
|
2676
|
-
*/
|
|
2677
|
-
constructor(options, initialConfig = {}) {
|
|
2678
|
-
super(options, initialConfig);
|
|
2679
|
-
this.initialOptions = options;
|
|
2680
|
-
this.initialConfig = initialConfig;
|
|
2681
|
-
}
|
|
2682
|
-
/**
|
|
2683
|
-
* 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.
|
|
2684
|
-
*
|
|
2685
|
-
* @param config - The inline configuration values to set.
|
|
2686
|
-
* @returns A promise that resolves when the inline configuration values have been set.
|
|
2687
|
-
*/
|
|
2688
|
-
async setInlineConfig(config) {
|
|
2689
|
-
await super.setInlineConfig(config);
|
|
2690
|
-
if (this.inlineConfig.command === "new") {
|
|
2691
|
-
const workspacePackageJsonPath = (0, _stryke_path_join.joinPaths)(this.config.cwd, "package.json");
|
|
2692
|
-
if (!(0, _stryke_fs_exists.existsSync)(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
|
|
2693
|
-
this.packageJson = await (0, _stryke_fs_json.readJsonFile)(workspacePackageJsonPath);
|
|
2694
|
-
}
|
|
2695
|
-
}
|
|
2696
|
-
/**
|
|
2697
|
-
* Create a new logger instance
|
|
2698
|
-
*
|
|
2699
|
-
* @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.
|
|
2700
|
-
* @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.
|
|
2701
|
-
* @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
|
|
2702
|
-
*/
|
|
2703
|
-
createLogger(options, logFn) {
|
|
2704
|
-
return super.createLogger({
|
|
2705
|
-
...options,
|
|
2706
|
-
executionId: this.id,
|
|
2707
|
-
executionIndex: this.options.executionIndex
|
|
2708
|
-
}, logFn);
|
|
2709
|
-
}
|
|
2710
|
-
/**
|
|
2711
|
-
* Extend the base logger with additional configuration options
|
|
2712
|
-
*
|
|
2713
|
-
* @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.
|
|
2714
|
-
* @returns A new logger client instance that extends the base logger with the provided configuration options.
|
|
2715
|
-
*/
|
|
2716
|
-
extendLogger(options) {
|
|
2717
|
-
return super.extendLogger({
|
|
2718
|
-
...options,
|
|
2719
|
-
executionId: this.id,
|
|
2720
|
-
executionIndex: this.options.executionIndex
|
|
2721
|
-
});
|
|
2722
|
-
}
|
|
2723
|
-
/**
|
|
2724
|
-
* A function to copy the context and update the fields for a specific environment
|
|
2725
|
-
*
|
|
2726
|
-
* @param environment - The environment configuration to use.
|
|
2727
|
-
* @returns A new context instance with the updated environment.
|
|
2728
|
-
*/
|
|
2729
|
-
async createEnvironment(environment) {
|
|
2730
|
-
const context = await PowerlinesEnvironmentContext.createEnvironment((0, _stryke_helpers_deep_clone.deepClone)(this.initialOptions), (0, _stryke_helpers_deep_clone.deepClone)(this.config), (0, _stryke_helpers_deep_clone.deepClone)(this.overriddenConfig), (0, _stryke_helpers_deep_clone.deepClone)(environment));
|
|
2731
|
-
context.$$internal = this.$$internal;
|
|
2732
|
-
context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
|
|
2733
|
-
context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
|
|
2734
|
-
context.persistedMeta = (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta);
|
|
2735
|
-
context.resolvePatterns = (0, _stryke_helpers_deep_clone.deepClone)(this.resolvePatterns);
|
|
2736
|
-
context.powerlinesPath ??= this.powerlinesPath;
|
|
2737
|
-
context.resolver ??= this.resolver;
|
|
2738
|
-
context.plugins = [];
|
|
2739
|
-
for (const plugin of this.plugins) await context.addPlugin(plugin);
|
|
2740
|
-
for (const [key, value] of Object.entries(this)) if (![
|
|
2741
|
-
"fs",
|
|
2742
|
-
"$$internal",
|
|
2743
|
-
"initialOptions",
|
|
2744
|
-
"options",
|
|
2745
|
-
"config",
|
|
2746
|
-
"initialConfig",
|
|
2747
|
-
"inlineConfig",
|
|
2748
|
-
"userConfig",
|
|
2749
|
-
"pluginConfig",
|
|
2750
|
-
"overriddenConfig",
|
|
2751
|
-
"environmentConfig",
|
|
2752
|
-
"dependencies",
|
|
2753
|
-
"devDependencies",
|
|
2754
|
-
"persistedMeta",
|
|
2755
|
-
"packageJson",
|
|
2756
|
-
"projectJson",
|
|
2757
|
-
"tsconfig",
|
|
2758
|
-
"resolver",
|
|
2759
|
-
"plugins",
|
|
2760
|
-
"environments"
|
|
2761
|
-
].includes(key)) if ((0, _stryke_type_checks_is_object.isObject)(value) || Array.isArray(value)) context[key] = (0, _stryke_helpers_deep_clone.deepClone)(value);
|
|
2762
|
-
else context[key] = value;
|
|
2763
|
-
return context;
|
|
2764
|
-
}
|
|
2765
|
-
/**
|
|
2766
|
-
* Update the context using a new inline configuration options
|
|
2767
|
-
*/
|
|
2768
|
-
async resolveConfig() {
|
|
2769
|
-
await super.resolveConfig();
|
|
2770
|
-
await Promise.all((0, _stryke_convert_to_array.toArray)(this.config.environments && Object.keys(this.config.environments).length > 0 ? Object.keys(this.config.environments).map((name) => createEnvironment(name, this.config)) : createDefaultEnvironment(this.config)).map(async (env) => {
|
|
2771
|
-
this.#environments[env.name] = await this.createEnvironment(env);
|
|
2772
|
-
}));
|
|
2773
|
-
}
|
|
2774
|
-
/**
|
|
2775
|
-
* Add a plugin to the API context and all environments
|
|
2776
|
-
*
|
|
2777
|
-
* @param plugin - The plugin to add.
|
|
2778
|
-
*/
|
|
2779
|
-
async addPlugin(plugin) {
|
|
2780
|
-
this.plugins.push(plugin);
|
|
2781
|
-
await Promise.all(Object.keys(this.environments).map(async (name) => {
|
|
2782
|
-
await this.environments[name].addPlugin(plugin);
|
|
2783
|
-
}));
|
|
2784
|
-
}
|
|
2785
|
-
/**
|
|
2786
|
-
* Get an environment by name, or the default environment if no name is provided
|
|
2787
|
-
*
|
|
2788
|
-
* @param name - The name of the environment to retrieve.
|
|
2789
|
-
* @returns The requested environment context.
|
|
2790
|
-
*/
|
|
2791
|
-
async getEnvironment(name) {
|
|
2792
|
-
let environment;
|
|
2793
|
-
if (name) environment = this.environments[name];
|
|
2794
|
-
if (Object.keys(this.environments).length === 1) {
|
|
2795
|
-
environment = this.environments[Object.keys(this.environments)[0]];
|
|
2796
|
-
this.trace({
|
|
2797
|
-
meta: { category: "plugins" },
|
|
2798
|
-
message: `Applying the only configured environment: ${chalk.default.bold.cyanBright(environment?.config.environment?.name)}`
|
|
2799
|
-
});
|
|
2800
|
-
}
|
|
2801
|
-
if (!environment) {
|
|
2802
|
-
if (name) throw new Error(`Environment "${name}" not found.`);
|
|
2803
|
-
environment = await PowerlinesEnvironmentContext.createEnvironment((0, _stryke_helpers_deep_clone.deepClone)(this.options), (0, _stryke_helpers_deep_clone.deepClone)(this.config), (0, _stryke_helpers_deep_clone.deepClone)(this.overriddenConfig), (0, _stryke_helpers_deep_clone.deepClone)(createDefaultEnvironment(this.config)));
|
|
2804
|
-
environment.plugins = [];
|
|
2805
|
-
for (const plugin of this.plugins) await environment.addPlugin(plugin);
|
|
2806
|
-
this.warn({
|
|
2807
|
-
meta: { category: "plugins" },
|
|
2808
|
-
message: `No environment specified, and no default environment found. Using a temporary default environment: ${chalk.default.bold.cyanBright(environment.config.environment?.name)}`
|
|
2809
|
-
});
|
|
2810
|
-
}
|
|
2811
|
-
return environment;
|
|
2812
|
-
}
|
|
2813
|
-
/**
|
|
2814
|
-
* A safe version of `getEnvironment` that returns `undefined` if the environment is not found
|
|
2815
|
-
*
|
|
2816
|
-
* @param name - The name of the environment to retrieve.
|
|
2817
|
-
* @returns The requested environment context or `undefined` if not found.
|
|
2818
|
-
*/
|
|
2819
|
-
async getEnvironmentSafe(name) {
|
|
2820
|
-
try {
|
|
2821
|
-
return await this.getEnvironment(name);
|
|
2822
|
-
} catch {
|
|
2823
|
-
return;
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
/**
|
|
2827
|
-
* A function to merge all configured environments into a single context.
|
|
2828
|
-
*
|
|
2829
|
-
* @remarks
|
|
2830
|
-
* If only one environment is configured, that environment will be returned directly.
|
|
2831
|
-
*
|
|
2832
|
-
* @returns A promise that resolves to a merged/global environment context.
|
|
2833
|
-
*/
|
|
2834
|
-
async toEnvironment() {
|
|
2835
|
-
let environment;
|
|
2836
|
-
if (Object.keys(this.environments).length > 1) {
|
|
2837
|
-
environment = await this.createEnvironment(createEnvironment(_powerlines_core_constants.GLOBAL_ENVIRONMENT, this.config));
|
|
2838
|
-
this.debug({
|
|
2839
|
-
meta: { category: "plugins" },
|
|
2840
|
-
message: `Combined all ${Object.keys(this.environments).length} environments into a single global context.`
|
|
2841
|
-
});
|
|
2842
|
-
} else environment = await this.getEnvironment();
|
|
2843
|
-
return environment;
|
|
2844
|
-
}
|
|
2845
|
-
};
|
|
2846
|
-
|
|
2847
|
-
//#endregion
|
|
2848
|
-
Object.defineProperty(exports, 'PowerlinesContext', {
|
|
2849
|
-
enumerable: true,
|
|
2850
|
-
get: function () {
|
|
2851
|
-
return PowerlinesContext;
|
|
2852
|
-
}
|
|
2853
|
-
});
|
|
2854
|
-
Object.defineProperty(exports, 'PowerlinesEnvironmentContext', {
|
|
2855
|
-
enumerable: true,
|
|
2856
|
-
get: function () {
|
|
2857
|
-
return PowerlinesEnvironmentContext;
|
|
2858
|
-
}
|
|
2859
|
-
});
|
|
2860
|
-
Object.defineProperty(exports, 'PowerlinesExecutionContext', {
|
|
2861
|
-
enumerable: true,
|
|
2862
|
-
get: function () {
|
|
2863
|
-
return PowerlinesExecutionContext;
|
|
2864
|
-
}
|
|
2865
|
-
});
|
|
2866
|
-
Object.defineProperty(exports, 'callHook', {
|
|
2867
|
-
enumerable: true,
|
|
2868
|
-
get: function () {
|
|
2869
|
-
return callHook;
|
|
2870
|
-
}
|
|
2871
|
-
});
|
|
2872
|
-
Object.defineProperty(exports, 'createPluginContext', {
|
|
2873
|
-
enumerable: true,
|
|
2874
|
-
get: function () {
|
|
2875
|
-
return createPluginContext;
|
|
2876
|
-
}
|
|
2877
|
-
});
|
|
2878
|
-
Object.defineProperty(exports, 'mergeConfigs', {
|
|
2879
|
-
enumerable: true,
|
|
2880
|
-
get: function () {
|
|
2881
|
-
return mergeConfigs;
|
|
2882
|
-
}
|
|
2883
|
-
});
|
|
2884
|
-
Object.defineProperty(exports, 'writeMetaFile', {
|
|
2885
|
-
enumerable: true,
|
|
2886
|
-
get: function () {
|
|
2887
|
-
return writeMetaFile;
|
|
2888
|
-
}
|
|
2889
|
-
});
|