@powerlines/plugin-webpack 0.5.241 → 0.5.243
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/helpers/unplugin.cjs +2 -3
- package/dist/helpers/unplugin.mjs +1 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +3 -3
- package/dist/types/plugin.d.cts +3 -3
- package/dist/types/plugin.d.mts +3 -3
- package/package.json +96 -15
- package/dist/powerlines/package.cjs +0 -11
- package/dist/powerlines/package.mjs +0 -5
- package/dist/powerlines/schemas/fs.cjs +0 -226
- package/dist/powerlines/schemas/fs.mjs +0 -224
- package/dist/powerlines/src/api.cjs +0 -568
- package/dist/powerlines/src/api.mjs +0 -566
- package/dist/powerlines/src/internal/helpers/environment.cjs +0 -50
- package/dist/powerlines/src/internal/helpers/environment.mjs +0 -47
- package/dist/powerlines/src/internal/helpers/generate-types.cjs +0 -78
- package/dist/powerlines/src/internal/helpers/generate-types.mjs +0 -76
- package/dist/powerlines/src/internal/helpers/hooks.cjs +0 -65
- package/dist/powerlines/src/internal/helpers/hooks.d.cts +0 -47
- package/dist/powerlines/src/internal/helpers/hooks.d.mts +0 -49
- package/dist/powerlines/src/internal/helpers/hooks.mjs +0 -63
- package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +0 -24
- package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +0 -23
- package/dist/powerlines/src/internal/helpers/install.cjs +0 -36
- package/dist/powerlines/src/internal/helpers/install.mjs +0 -35
- package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +0 -97
- package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +0 -93
- package/dist/powerlines/src/internal/helpers/resolver.cjs +0 -43
- package/dist/powerlines/src/internal/helpers/resolver.mjs +0 -41
- package/dist/powerlines/src/lib/build/webpack.cjs +0 -38
- package/dist/powerlines/src/lib/build/webpack.mjs +0 -36
- package/dist/powerlines/src/lib/config-file.cjs +0 -79
- package/dist/powerlines/src/lib/config-file.mjs +0 -76
- package/dist/powerlines/src/lib/constants/environments.cjs +0 -8
- package/dist/powerlines/src/lib/constants/environments.mjs +0 -6
- package/dist/powerlines/src/lib/contexts/api-context.cjs +0 -184
- package/dist/powerlines/src/lib/contexts/api-context.mjs +0 -182
- package/dist/powerlines/src/lib/contexts/context.cjs +0 -951
- package/dist/powerlines/src/lib/contexts/context.mjs +0 -949
- package/dist/powerlines/src/lib/contexts/environment-context.cjs +0 -195
- package/dist/powerlines/src/lib/contexts/environment-context.mjs +0 -194
- package/dist/powerlines/src/lib/contexts/plugin-context.cjs +0 -78
- package/dist/powerlines/src/lib/contexts/plugin-context.mjs +0 -77
- package/dist/powerlines/src/lib/entry.cjs +0 -85
- package/dist/powerlines/src/lib/entry.mjs +0 -83
- package/dist/powerlines/src/lib/fs/helpers.cjs +0 -85
- package/dist/powerlines/src/lib/fs/helpers.mjs +0 -81
- package/dist/powerlines/src/lib/fs/storage/base.cjs +0 -196
- package/dist/powerlines/src/lib/fs/storage/base.mjs +0 -195
- package/dist/powerlines/src/lib/fs/storage/file-system.cjs +0 -170
- package/dist/powerlines/src/lib/fs/storage/file-system.mjs +0 -169
- package/dist/powerlines/src/lib/fs/storage/virtual.cjs +0 -88
- package/dist/powerlines/src/lib/fs/storage/virtual.mjs +0 -87
- package/dist/powerlines/src/lib/fs/vfs.cjs +0 -912
- package/dist/powerlines/src/lib/fs/vfs.mjs +0 -910
- package/dist/powerlines/src/lib/logger.cjs +0 -58
- package/dist/powerlines/src/lib/logger.mjs +0 -55
- package/dist/powerlines/src/lib/typescript/ts-morph.cjs +0 -103
- package/dist/powerlines/src/lib/typescript/ts-morph.mjs +0 -101
- package/dist/powerlines/src/lib/typescript/tsconfig.cjs +0 -149
- package/dist/powerlines/src/lib/typescript/tsconfig.mjs +0 -144
- package/dist/powerlines/src/lib/unplugin/factory.cjs +0 -6
- package/dist/powerlines/src/lib/unplugin/factory.mjs +0 -8
- package/dist/powerlines/src/lib/unplugin/helpers.cjs +0 -29
- package/dist/powerlines/src/lib/unplugin/helpers.mjs +0 -27
- package/dist/powerlines/src/lib/unplugin/index.cjs +0 -4
- package/dist/powerlines/src/lib/unplugin/index.mjs +0 -6
- package/dist/powerlines/src/lib/unplugin/module-resolution.cjs +0 -66
- package/dist/powerlines/src/lib/unplugin/module-resolution.mjs +0 -65
- package/dist/powerlines/src/lib/unplugin/plugin.cjs +0 -71
- package/dist/powerlines/src/lib/unplugin/plugin.mjs +0 -70
- package/dist/powerlines/src/lib/utilities/file-header.cjs +0 -22
- package/dist/powerlines/src/lib/utilities/file-header.mjs +0 -21
- package/dist/powerlines/src/lib/utilities/format.cjs +0 -48
- package/dist/powerlines/src/lib/utilities/format.mjs +0 -46
- package/dist/powerlines/src/lib/utilities/meta.cjs +0 -44
- package/dist/powerlines/src/lib/utilities/meta.mjs +0 -40
- package/dist/powerlines/src/lib/utilities/source-file.cjs +0 -22
- package/dist/powerlines/src/lib/utilities/source-file.mjs +0 -21
- package/dist/powerlines/src/plugin-utils/helpers.cjs +0 -167
- package/dist/powerlines/src/plugin-utils/helpers.mjs +0 -156
- package/dist/powerlines/src/plugin-utils/paths.cjs +0 -36
- package/dist/powerlines/src/plugin-utils/paths.mjs +0 -35
- package/dist/powerlines/src/types/api.d.cts +0 -104
- package/dist/powerlines/src/types/api.d.mts +0 -104
- package/dist/powerlines/src/types/babel.d.mts +0 -2
- package/dist/powerlines/src/types/build.cjs +0 -23
- package/dist/powerlines/src/types/build.d.cts +0 -185
- package/dist/powerlines/src/types/build.d.mts +0 -185
- package/dist/powerlines/src/types/build.mjs +0 -21
- package/dist/powerlines/src/types/commands.cjs +0 -16
- package/dist/powerlines/src/types/commands.d.cts +0 -8
- package/dist/powerlines/src/types/commands.d.mts +0 -9
- package/dist/powerlines/src/types/commands.mjs +0 -15
- package/dist/powerlines/src/types/config.d.cts +0 -424
- package/dist/powerlines/src/types/config.d.mts +0 -425
- package/dist/powerlines/src/types/context.d.cts +0 -514
- package/dist/powerlines/src/types/context.d.mts +0 -514
- package/dist/powerlines/src/types/fs.d.cts +0 -486
- package/dist/powerlines/src/types/fs.d.mts +0 -486
- package/dist/powerlines/src/types/hooks.d.cts +0 -32
- package/dist/powerlines/src/types/hooks.d.mts +0 -32
- package/dist/powerlines/src/types/plugin.cjs +0 -33
- package/dist/powerlines/src/types/plugin.d.cts +0 -205
- package/dist/powerlines/src/types/plugin.d.mts +0 -205
- package/dist/powerlines/src/types/plugin.mjs +0 -32
- package/dist/powerlines/src/types/resolved.d.cts +0 -93
- package/dist/powerlines/src/types/resolved.d.mts +0 -93
- package/dist/powerlines/src/types/tsconfig.d.cts +0 -69
- package/dist/powerlines/src/types/tsconfig.d.mts +0 -69
- package/dist/powerlines/src/types/unplugin.d.cts +0 -22
- package/dist/powerlines/src/types/unplugin.d.mts +0 -23
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_ts_morph = require('../../lib/typescript/ts-morph.cjs');
|
|
3
|
-
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
4
|
-
let __stryke_path_append = require("@stryke/path/append");
|
|
5
|
-
let __stryke_path_replace = require("@stryke/path/replace");
|
|
6
|
-
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
7
|
-
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
8
|
-
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
9
|
-
let __stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
|
|
10
|
-
let ts_morph = require("ts-morph");
|
|
11
|
-
|
|
12
|
-
//#region ../powerlines/src/internal/helpers/generate-types.ts
|
|
13
|
-
const getModuleCommentBlockRegex = (moduleId) => /* @__PURE__ */ new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${moduleId}(?s:.)*?\\*\\/\\s+`);
|
|
14
|
-
/**
|
|
15
|
-
* Formats the generated TypeScript types source code.
|
|
16
|
-
*
|
|
17
|
-
* @param code - The generated TypeScript code.
|
|
18
|
-
* @returns The formatted TypeScript code.
|
|
19
|
-
*/
|
|
20
|
-
function formatTypes(code) {
|
|
21
|
-
return code.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g, "").replaceAll("#private;", "").replace(/__Ω/g, "");
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
|
|
25
|
-
*
|
|
26
|
-
* @param context - The context containing options and environment paths.
|
|
27
|
-
* @param files - The list of files to generate types for.
|
|
28
|
-
* @returns A promise that resolves to the generated TypeScript declaration types.
|
|
29
|
-
*/
|
|
30
|
-
async function emitBuiltinTypes(context, files) {
|
|
31
|
-
if (files.length === 0) {
|
|
32
|
-
context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
|
|
33
|
-
return "";
|
|
34
|
-
}
|
|
35
|
-
context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
|
|
36
|
-
const program = require_ts_morph.createProgram(context, {
|
|
37
|
-
skipAddingFilesFromTsConfig: true,
|
|
38
|
-
compilerOptions: {
|
|
39
|
-
declaration: true,
|
|
40
|
-
declarationMap: false,
|
|
41
|
-
emitDeclarationOnly: true,
|
|
42
|
-
sourceMap: false,
|
|
43
|
-
outDir: (0, __stryke_path_replace.replacePath)(context.builtinsPath, context.workspaceConfig.workspaceRoot),
|
|
44
|
-
composite: false,
|
|
45
|
-
incremental: false,
|
|
46
|
-
tsBuildInfoFile: void 0
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
program.addSourceFilesAtPaths(files);
|
|
50
|
-
const result = program.emitToMemory({ emitOnlyDtsFiles: true });
|
|
51
|
-
const diagnostics = result.getDiagnostics();
|
|
52
|
-
if (diagnostics && diagnostics.length > 0) if (diagnostics.some((d) => d.getCategory() === ts_morph.DiagnosticCategory.Error)) throw new Error(`The Typescript emit process failed while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === ts_morph.DiagnosticCategory.Error).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
53
|
-
else if (diagnostics.some((d) => d.getCategory() === ts_morph.DiagnosticCategory.Warning)) context.warn(`The Typescript emit process completed with warnings while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === ts_morph.DiagnosticCategory.Warning).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
54
|
-
else context.debug(`The Typescript emit process completed with diagnostic messages while generating built-in types: \n ${diagnostics.map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
55
|
-
const emittedFiles = result.getFiles();
|
|
56
|
-
context.debug(`The TypeScript compiler emitted ${emittedFiles.length} files for built-in types.`);
|
|
57
|
-
let builtinModules = "";
|
|
58
|
-
for (const emittedFile of emittedFiles) {
|
|
59
|
-
context.trace(`Processing emitted type declaration file: ${emittedFile.filePath}`);
|
|
60
|
-
const filePath = (0, __stryke_path_append.appendPath)(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
|
|
61
|
-
if (!filePath.endsWith(".map") && (0, __stryke_path_file_path_fns.findFileName)(filePath) !== "tsconfig.tsbuildinfo" && (0, __stryke_path_is_parent_path.isParentPath)(filePath, context.builtinsPath)) {
|
|
62
|
-
const moduleId = `${context.config.framework}:${(0, __stryke_path_replace.replaceExtension)((0, __stryke_path_replace.replacePath)(filePath, context.builtinsPath), "", { fullExtension: true })}`;
|
|
63
|
-
const moduleComment = emittedFile.text.match(getModuleCommentBlockRegex(moduleId))?.find((comment) => (0, __stryke_type_checks_is_set_string.isSetString)(comment?.trim()));
|
|
64
|
-
builtinModules += `${moduleComment ? `\n${moduleComment.trim()}` : ""}
|
|
65
|
-
declare module "${moduleId}" {
|
|
66
|
-
${emittedFile.text.replace(moduleComment ?? "", "").trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
builtinModules = formatTypes(builtinModules);
|
|
72
|
-
context.debug(`A TypeScript declaration file (size: ${(0, __stryke_string_format_pretty_bytes.prettyBytes)(new Blob((0, __stryke_convert_to_array.toArray)(builtinModules)).size)}) emitted for the built-in modules types.`);
|
|
73
|
-
return builtinModules;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
exports.emitBuiltinTypes = emitBuiltinTypes;
|
|
78
|
-
exports.formatTypes = formatTypes;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { createProgram } from "../../lib/typescript/ts-morph.mjs";
|
|
2
|
-
import { toArray } from "@stryke/convert/to-array";
|
|
3
|
-
import { appendPath } from "@stryke/path/append";
|
|
4
|
-
import { replaceExtension, replacePath } from "@stryke/path/replace";
|
|
5
|
-
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
6
|
-
import { findFileName } from "@stryke/path/file-path-fns";
|
|
7
|
-
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
8
|
-
import { prettyBytes } from "@stryke/string-format/pretty-bytes";
|
|
9
|
-
import { DiagnosticCategory } from "ts-morph";
|
|
10
|
-
|
|
11
|
-
//#region ../powerlines/src/internal/helpers/generate-types.ts
|
|
12
|
-
const getModuleCommentBlockRegex = (moduleId) => /* @__PURE__ */ new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${moduleId}(?s:.)*?\\*\\/\\s+`);
|
|
13
|
-
/**
|
|
14
|
-
* Formats the generated TypeScript types source code.
|
|
15
|
-
*
|
|
16
|
-
* @param code - The generated TypeScript code.
|
|
17
|
-
* @returns The formatted TypeScript code.
|
|
18
|
-
*/
|
|
19
|
-
function formatTypes(code) {
|
|
20
|
-
return code.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g, "").replaceAll("#private;", "").replace(/__Ω/g, "");
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
|
|
24
|
-
*
|
|
25
|
-
* @param context - The context containing options and environment paths.
|
|
26
|
-
* @param files - The list of files to generate types for.
|
|
27
|
-
* @returns A promise that resolves to the generated TypeScript declaration types.
|
|
28
|
-
*/
|
|
29
|
-
async function emitBuiltinTypes(context, files) {
|
|
30
|
-
if (files.length === 0) {
|
|
31
|
-
context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
|
|
32
|
-
return "";
|
|
33
|
-
}
|
|
34
|
-
context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
|
|
35
|
-
const program = createProgram(context, {
|
|
36
|
-
skipAddingFilesFromTsConfig: true,
|
|
37
|
-
compilerOptions: {
|
|
38
|
-
declaration: true,
|
|
39
|
-
declarationMap: false,
|
|
40
|
-
emitDeclarationOnly: true,
|
|
41
|
-
sourceMap: false,
|
|
42
|
-
outDir: replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot),
|
|
43
|
-
composite: false,
|
|
44
|
-
incremental: false,
|
|
45
|
-
tsBuildInfoFile: void 0
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
program.addSourceFilesAtPaths(files);
|
|
49
|
-
const result = program.emitToMemory({ emitOnlyDtsFiles: true });
|
|
50
|
-
const diagnostics = result.getDiagnostics();
|
|
51
|
-
if (diagnostics && diagnostics.length > 0) if (diagnostics.some((d) => d.getCategory() === DiagnosticCategory.Error)) throw new Error(`The Typescript emit process failed while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === DiagnosticCategory.Error).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
52
|
-
else if (diagnostics.some((d) => d.getCategory() === DiagnosticCategory.Warning)) context.warn(`The Typescript emit process completed with warnings while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === DiagnosticCategory.Warning).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
53
|
-
else context.debug(`The Typescript emit process completed with diagnostic messages while generating built-in types: \n ${diagnostics.map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
54
|
-
const emittedFiles = result.getFiles();
|
|
55
|
-
context.debug(`The TypeScript compiler emitted ${emittedFiles.length} files for built-in types.`);
|
|
56
|
-
let builtinModules = "";
|
|
57
|
-
for (const emittedFile of emittedFiles) {
|
|
58
|
-
context.trace(`Processing emitted type declaration file: ${emittedFile.filePath}`);
|
|
59
|
-
const filePath = appendPath(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
|
|
60
|
-
if (!filePath.endsWith(".map") && findFileName(filePath) !== "tsconfig.tsbuildinfo" && isParentPath(filePath, context.builtinsPath)) {
|
|
61
|
-
const moduleId = `${context.config.framework}:${replaceExtension(replacePath(filePath, context.builtinsPath), "", { fullExtension: true })}`;
|
|
62
|
-
const moduleComment = emittedFile.text.match(getModuleCommentBlockRegex(moduleId))?.find((comment) => isSetString(comment?.trim()));
|
|
63
|
-
builtinModules += `${moduleComment ? `\n${moduleComment.trim()}` : ""}
|
|
64
|
-
declare module "${moduleId}" {
|
|
65
|
-
${emittedFile.text.replace(moduleComment ?? "", "").trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
|
|
66
|
-
}
|
|
67
|
-
`;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
builtinModules = formatTypes(builtinModules);
|
|
71
|
-
context.debug(`A TypeScript declaration file (size: ${prettyBytes(new Blob(toArray(builtinModules)).size)}) emitted for the built-in modules types.`);
|
|
72
|
-
return builtinModules;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
export { emitBuiltinTypes, formatTypes };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let defu = require("defu");
|
|
3
|
-
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
4
|
-
let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
5
|
-
let __stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
6
|
-
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
7
|
-
let chalk = require("chalk");
|
|
8
|
-
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
9
|
-
|
|
10
|
-
//#region ../powerlines/src/internal/helpers/hooks.ts
|
|
11
|
-
const mergeResults = (0, defu.createDefu)((obj, key, value) => {
|
|
12
|
-
if ((0, __stryke_type_checks_is_string.isString)(obj[key]) && (0, __stryke_type_checks_is_string.isString)(value)) {
|
|
13
|
-
obj[key] = `${obj[key] || ""}\n${value || ""}`.trim();
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Calls a hook with the given context, options, and arguments.
|
|
20
|
-
*
|
|
21
|
-
* @param context - The context to use when calling the hook.
|
|
22
|
-
* @param key - The hook to call.
|
|
23
|
-
* @param options - Options for calling the hook.
|
|
24
|
-
* @param args - Arguments to pass to the hook.
|
|
25
|
-
* @returns The return value of the hook.
|
|
26
|
-
*/
|
|
27
|
-
async function callHook(context, key, options, ...args) {
|
|
28
|
-
const hooks = context.selectHooks(key, options);
|
|
29
|
-
if (hooks.length > 0) {
|
|
30
|
-
context.debug(` 🧩 Calling plugin hook: ${chalk.default.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
|
|
31
|
-
const invokeHook = async (hook, hookArgs) => {
|
|
32
|
-
return Reflect.apply(hook.handler, hook.context, hookArgs);
|
|
33
|
-
};
|
|
34
|
-
let results = [];
|
|
35
|
-
if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
|
|
36
|
-
if (!(0, __stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
37
|
-
return invokeHook(hook, [...args]);
|
|
38
|
-
}));
|
|
39
|
-
else for (const hook of hooks) {
|
|
40
|
-
if (!(0, __stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
41
|
-
if (options?.result === "first" || options?.asNextParam === false) {
|
|
42
|
-
results.push(await Promise.resolve(invokeHook(hook, [...args])));
|
|
43
|
-
if (options?.result === "first" && (0, __stryke_type_checks_is_set.isSet)(results[results.length - 1])) break;
|
|
44
|
-
} else {
|
|
45
|
-
const sequenceArgs = [...args];
|
|
46
|
-
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];
|
|
47
|
-
const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
|
|
48
|
-
if (result) {
|
|
49
|
-
if (options?.result === "last") results = [result];
|
|
50
|
-
else if ((0, __stryke_type_checks_is_string.isString)(result)) results = [`${(0, __stryke_type_checks_is_string.isString)(results[0]) ? results[0] || "" : ""}\n${result || ""}`.trim()];
|
|
51
|
-
else if ((0, __stryke_type_checks_is_object.isObject)(result)) results = [mergeResults(result, results[0] ?? {})];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const definedResults = results.filter((result) => (0, __stryke_type_checks_is_set.isSet)(result));
|
|
56
|
-
if (definedResults.length > 0) {
|
|
57
|
-
let mergedResult = void 0;
|
|
58
|
-
for (const result of definedResults) mergedResult = (0, defu.defu)(result, mergedResult ?? {});
|
|
59
|
-
return mergedResult;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
|
-
exports.callHook = callHook;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { SelectHooksOptions } from "../../types/context.cjs";
|
|
2
|
-
import { MaybePromise } from "@stryke/types/base";
|
|
3
|
-
|
|
4
|
-
//#region ../powerlines/src/internal/helpers/hooks.d.ts
|
|
5
|
-
type CallHookOptions = SelectHooksOptions & (({
|
|
6
|
-
/**
|
|
7
|
-
* Whether to call the hooks sequentially or in parallel.
|
|
8
|
-
*
|
|
9
|
-
* @defaultValue true
|
|
10
|
-
*/
|
|
11
|
-
sequential?: true;
|
|
12
|
-
} & ({
|
|
13
|
-
/**
|
|
14
|
-
* How to handle multiple return values from hooks.
|
|
15
|
-
* - "merge": Merge all non-undefined return values (if they are objects).
|
|
16
|
-
* - "first": Return the first non-undefined value.
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* Merging only works if the return values are objects.
|
|
20
|
-
*
|
|
21
|
-
* @defaultValue "merge"
|
|
22
|
-
*/
|
|
23
|
-
result: "first";
|
|
24
|
-
} | {
|
|
25
|
-
/**
|
|
26
|
-
* How to handle multiple return values from hooks.
|
|
27
|
-
* - "merge": Merge all non-undefined return values (if they are objects).
|
|
28
|
-
* - "first": Return the first non-undefined value.
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* Merging only works if the return values are objects.
|
|
32
|
-
*
|
|
33
|
-
* @defaultValue "merge"
|
|
34
|
-
*/
|
|
35
|
-
result?: "merge" | "last";
|
|
36
|
-
/**
|
|
37
|
-
* An indicator specifying if the results of the previous hook should be provided as the **first** parameter of the next hook function, or a function to process the result of the previous hook function and pass the returned value as the next hook's **first** parameter
|
|
38
|
-
*/
|
|
39
|
-
asNextParam?: false | ((previousResult: any) => MaybePromise<any>);
|
|
40
|
-
})) | {
|
|
41
|
-
/**
|
|
42
|
-
* Whether to call the hooks sequentially or in parallel.
|
|
43
|
-
*/
|
|
44
|
-
sequential: false;
|
|
45
|
-
});
|
|
46
|
-
//#endregion
|
|
47
|
-
export { CallHookOptions };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import "../../types/resolved.mjs";
|
|
2
|
-
import "../../types/hooks.mjs";
|
|
3
|
-
import { SelectHooksOptions } from "../../types/context.mjs";
|
|
4
|
-
import { MaybePromise } from "@stryke/types/base";
|
|
5
|
-
|
|
6
|
-
//#region ../powerlines/src/internal/helpers/hooks.d.ts
|
|
7
|
-
type CallHookOptions = SelectHooksOptions & (({
|
|
8
|
-
/**
|
|
9
|
-
* Whether to call the hooks sequentially or in parallel.
|
|
10
|
-
*
|
|
11
|
-
* @defaultValue true
|
|
12
|
-
*/
|
|
13
|
-
sequential?: true;
|
|
14
|
-
} & ({
|
|
15
|
-
/**
|
|
16
|
-
* How to handle multiple return values from hooks.
|
|
17
|
-
* - "merge": Merge all non-undefined return values (if they are objects).
|
|
18
|
-
* - "first": Return the first non-undefined value.
|
|
19
|
-
*
|
|
20
|
-
* @remarks
|
|
21
|
-
* Merging only works if the return values are objects.
|
|
22
|
-
*
|
|
23
|
-
* @defaultValue "merge"
|
|
24
|
-
*/
|
|
25
|
-
result: "first";
|
|
26
|
-
} | {
|
|
27
|
-
/**
|
|
28
|
-
* How to handle multiple return values from hooks.
|
|
29
|
-
* - "merge": Merge all non-undefined return values (if they are objects).
|
|
30
|
-
* - "first": Return the first non-undefined value.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* Merging only works if the return values are objects.
|
|
34
|
-
*
|
|
35
|
-
* @defaultValue "merge"
|
|
36
|
-
*/
|
|
37
|
-
result?: "merge" | "last";
|
|
38
|
-
/**
|
|
39
|
-
* An indicator specifying if the results of the previous hook should be provided as the **first** parameter of the next hook function, or a function to process the result of the previous hook function and pass the returned value as the next hook's **first** parameter
|
|
40
|
-
*/
|
|
41
|
-
asNextParam?: false | ((previousResult: any) => MaybePromise<any>);
|
|
42
|
-
})) | {
|
|
43
|
-
/**
|
|
44
|
-
* Whether to call the hooks sequentially or in parallel.
|
|
45
|
-
*/
|
|
46
|
-
sequential: false;
|
|
47
|
-
});
|
|
48
|
-
//#endregion
|
|
49
|
-
export { CallHookOptions };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { createDefu, defu } from "defu";
|
|
2
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
3
|
-
import { isObject } from "@stryke/type-checks/is-object";
|
|
4
|
-
import { isSet } from "@stryke/type-checks/is-set";
|
|
5
|
-
import { isString } from "@stryke/type-checks/is-string";
|
|
6
|
-
import chalk from "chalk";
|
|
7
|
-
|
|
8
|
-
//#region ../powerlines/src/internal/helpers/hooks.ts
|
|
9
|
-
const mergeResults = createDefu((obj, key, value) => {
|
|
10
|
-
if (isString(obj[key]) && isString(value)) {
|
|
11
|
-
obj[key] = `${obj[key] || ""}\n${value || ""}`.trim();
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* Calls a hook with the given context, options, and arguments.
|
|
18
|
-
*
|
|
19
|
-
* @param context - The context to use when calling the hook.
|
|
20
|
-
* @param key - The hook to call.
|
|
21
|
-
* @param options - Options for calling the hook.
|
|
22
|
-
* @param args - Arguments to pass to the hook.
|
|
23
|
-
* @returns The return value of the hook.
|
|
24
|
-
*/
|
|
25
|
-
async function callHook(context, key, options, ...args) {
|
|
26
|
-
const hooks = context.selectHooks(key, options);
|
|
27
|
-
if (hooks.length > 0) {
|
|
28
|
-
context.debug(` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
|
|
29
|
-
const invokeHook = async (hook, hookArgs) => {
|
|
30
|
-
return Reflect.apply(hook.handler, hook.context, hookArgs);
|
|
31
|
-
};
|
|
32
|
-
let results = [];
|
|
33
|
-
if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
|
|
34
|
-
if (!isFunction(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
35
|
-
return invokeHook(hook, [...args]);
|
|
36
|
-
}));
|
|
37
|
-
else for (const hook of hooks) {
|
|
38
|
-
if (!isFunction(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
39
|
-
if (options?.result === "first" || options?.asNextParam === false) {
|
|
40
|
-
results.push(await Promise.resolve(invokeHook(hook, [...args])));
|
|
41
|
-
if (options?.result === "first" && isSet(results[results.length - 1])) break;
|
|
42
|
-
} else {
|
|
43
|
-
const sequenceArgs = [...args];
|
|
44
|
-
if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = isFunction(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
|
|
45
|
-
const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
|
|
46
|
-
if (result) {
|
|
47
|
-
if (options?.result === "last") results = [result];
|
|
48
|
-
else if (isString(result)) results = [`${isString(results[0]) ? results[0] || "" : ""}\n${result || ""}`.trim()];
|
|
49
|
-
else if (isObject(result)) results = [mergeResults(result, results[0] ?? {})];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const definedResults = results.filter((result) => isSet(result));
|
|
54
|
-
if (definedResults.length > 0) {
|
|
55
|
-
let mergedResult = void 0;
|
|
56
|
-
for (const result of definedResults) mergedResult = defu(result, mergedResult ?? {});
|
|
57
|
-
return mergedResult;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
export { callHook };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_install = require('./install.cjs');
|
|
3
|
-
let __stryke_string_format_package = require("@stryke/string-format/package");
|
|
4
|
-
|
|
5
|
-
//#region ../powerlines/src/internal/helpers/install-dependencies.ts
|
|
6
|
-
/**
|
|
7
|
-
* Install missing project dependencies.
|
|
8
|
-
*
|
|
9
|
-
* @param context - The build context.
|
|
10
|
-
*/
|
|
11
|
-
async function installDependencies(context) {
|
|
12
|
-
context.debug(`Checking and installing missing project dependencies.`);
|
|
13
|
-
context.dependencies ??= {};
|
|
14
|
-
context.devDependencies ??= {};
|
|
15
|
-
if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
|
|
16
|
-
context.debug(`No dependencies or devDependencies to install. Skipping installation step.`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
context.debug(`The following packages are required: \nDependencies: \n${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}\n\nDevDependencies: \n${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
|
|
20
|
-
await Promise.all([Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => require_install.installPackage(context, `${(0, __stryke_string_format_package.getPackageName)(name)}@${String(version)}`, false))), Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => require_install.installPackage(context, `${(0, __stryke_string_format_package.getPackageName)(name)}@${String(version)}`, true)))]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.installDependencies = installDependencies;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { installPackage } from "./install.mjs";
|
|
2
|
-
import { getPackageName } from "@stryke/string-format/package";
|
|
3
|
-
|
|
4
|
-
//#region ../powerlines/src/internal/helpers/install-dependencies.ts
|
|
5
|
-
/**
|
|
6
|
-
* Install missing project dependencies.
|
|
7
|
-
*
|
|
8
|
-
* @param context - The build context.
|
|
9
|
-
*/
|
|
10
|
-
async function installDependencies(context) {
|
|
11
|
-
context.debug(`Checking and installing missing project dependencies.`);
|
|
12
|
-
context.dependencies ??= {};
|
|
13
|
-
context.devDependencies ??= {};
|
|
14
|
-
if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
|
|
15
|
-
context.debug(`No dependencies or devDependencies to install. Skipping installation step.`);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
context.debug(`The following packages are required: \nDependencies: \n${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}\n\nDevDependencies: \n${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
|
|
19
|
-
await Promise.all([Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, false))), Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, true)))]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
export { installDependencies };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let __stryke_fs_install = require("@stryke/fs/install");
|
|
3
|
-
let __stryke_fs_package_fns = require("@stryke/fs/package-fns");
|
|
4
|
-
let __stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
5
|
-
let __stryke_string_format_package = require("@stryke/string-format/package");
|
|
6
|
-
|
|
7
|
-
//#region ../powerlines/src/internal/helpers/install.ts
|
|
8
|
-
/**
|
|
9
|
-
* Installs a package if it is not already installed.
|
|
10
|
-
*
|
|
11
|
-
* @param context - The resolved options
|
|
12
|
-
* @param packageName - The name of the package to install
|
|
13
|
-
* @param dev - Whether to install the package as a dev dependency
|
|
14
|
-
*/
|
|
15
|
-
async function installPackage(context, packageName, dev = false) {
|
|
16
|
-
if (!await (0, __stryke_fs_package_fns.isPackageListed)((0, __stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.projectRoot })) if (context.config.autoInstall) {
|
|
17
|
-
context.warn(`The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
18
|
-
const result = await (0, __stryke_fs_install.install)(packageName, {
|
|
19
|
-
cwd: context.config.projectRoot,
|
|
20
|
-
dev
|
|
21
|
-
});
|
|
22
|
-
if ((0, __stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
|
|
23
|
-
context.error(result.stderr);
|
|
24
|
-
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
25
|
-
}
|
|
26
|
-
} else context.warn(`The package "${packageName}" is not installed. Since the "autoInstall" option is set to false, it will not be installed automatically.`);
|
|
27
|
-
else if ((0, __stryke_string_format_package.hasPackageVersion)(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
|
|
28
|
-
if (!await (0, __stryke_fs_package_fns.doesPackageMatch)((0, __stryke_string_format_package.getPackageName)(packageName), (0, __stryke_string_format_package.getPackageVersion)(packageName), context.config.projectRoot)) {
|
|
29
|
-
const packageListing = await (0, __stryke_fs_package_fns.getPackageListing)((0, __stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.projectRoot });
|
|
30
|
-
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.warn(`The package "${(0, __stryke_string_format_package.getPackageName)(packageName)}" is installed but does not match the expected version ${(0, __stryke_string_format_package.getPackageVersion)(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
exports.installPackage = installPackage;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { install } from "@stryke/fs/install";
|
|
2
|
-
import { doesPackageMatch, getPackageListing, isPackageListed } from "@stryke/fs/package-fns";
|
|
3
|
-
import { isNumber } from "@stryke/type-checks/is-number";
|
|
4
|
-
import { getPackageName, getPackageVersion, hasPackageVersion } from "@stryke/string-format/package";
|
|
5
|
-
|
|
6
|
-
//#region ../powerlines/src/internal/helpers/install.ts
|
|
7
|
-
/**
|
|
8
|
-
* Installs a package if it is not already installed.
|
|
9
|
-
*
|
|
10
|
-
* @param context - The resolved options
|
|
11
|
-
* @param packageName - The name of the package to install
|
|
12
|
-
* @param dev - Whether to install the package as a dev dependency
|
|
13
|
-
*/
|
|
14
|
-
async function installPackage(context, packageName, dev = false) {
|
|
15
|
-
if (!await isPackageListed(getPackageName(packageName), { cwd: context.config.projectRoot })) if (context.config.autoInstall) {
|
|
16
|
-
context.warn(`The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
17
|
-
const result = await install(packageName, {
|
|
18
|
-
cwd: context.config.projectRoot,
|
|
19
|
-
dev
|
|
20
|
-
});
|
|
21
|
-
if (isNumber(result.exitCode) && result.exitCode > 0) {
|
|
22
|
-
context.error(result.stderr);
|
|
23
|
-
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
24
|
-
}
|
|
25
|
-
} else context.warn(`The package "${packageName}" is not installed. Since the "autoInstall" option is set to false, it will not be installed automatically.`);
|
|
26
|
-
else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
|
|
27
|
-
if (!await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot)) {
|
|
28
|
-
const packageListing = await getPackageListing(getPackageName(packageName), { cwd: context.config.projectRoot });
|
|
29
|
-
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.warn(`The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
export { installPackage };
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_tsconfig = require('../../lib/typescript/tsconfig.cjs');
|
|
3
|
-
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
4
|
-
let __stryke_fs_package_fns = require("@stryke/fs/package-fns");
|
|
5
|
-
let chalk = require("chalk");
|
|
6
|
-
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
7
|
-
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
8
|
-
let __donedeal0_superdiff = require("@donedeal0/superdiff");
|
|
9
|
-
let __stryke_fs_json = require("@stryke/fs/json");
|
|
10
|
-
let __stryke_json_storm_json = require("@stryke/json/storm-json");
|
|
11
|
-
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
12
|
-
|
|
13
|
-
//#region ../powerlines/src/internal/helpers/resolve-tsconfig.ts
|
|
14
|
-
function getTsconfigDtsPath(context) {
|
|
15
|
-
return (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_file_path_fns.relativePath)((0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot), (0, __stryke_path_file_path_fns.findFilePath)(context.dtsPath)), (0, __stryke_path_file_path_fns.findFileName)(context.dtsPath));
|
|
16
|
-
}
|
|
17
|
-
async function resolveTsconfigChanges(context) {
|
|
18
|
-
const tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
|
|
19
|
-
const tsconfigJson = await (0, __stryke_fs_json.readJsonFile)(require_tsconfig.getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig));
|
|
20
|
-
tsconfigJson.compilerOptions ??= {};
|
|
21
|
-
if (context.config.output.dts !== false) {
|
|
22
|
-
const dtsRelativePath = getTsconfigDtsPath(context);
|
|
23
|
-
if (!tsconfigJson.include?.some((filePattern) => require_tsconfig.isIncludeMatchFound(filePattern, [context.dtsPath, dtsRelativePath]))) {
|
|
24
|
-
tsconfigJson.include ??= [];
|
|
25
|
-
tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (!tsconfig.options.lib?.some((lib) => [
|
|
29
|
-
"lib.esnext.d.ts",
|
|
30
|
-
"lib.es2021.d.ts",
|
|
31
|
-
"lib.es2022.d.ts",
|
|
32
|
-
"lib.es2023.d.ts"
|
|
33
|
-
].includes(lib.toLowerCase()))) {
|
|
34
|
-
tsconfigJson.compilerOptions.lib ??= [];
|
|
35
|
-
tsconfigJson.compilerOptions.lib.push("esnext");
|
|
36
|
-
}
|
|
37
|
-
if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
|
|
38
|
-
if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
|
|
39
|
-
if (context.config.build.platform === "node") {
|
|
40
|
-
if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
|
|
41
|
-
tsconfigJson.compilerOptions.types ??= [];
|
|
42
|
-
tsconfigJson.compilerOptions.types.push("node");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return tsconfigJson;
|
|
46
|
-
}
|
|
47
|
-
async function initializeTsconfig(context) {
|
|
48
|
-
context.debug("Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
|
|
49
|
-
if (!(0, __stryke_fs_package_fns.isPackageExists)("typescript")) throw new Error("The TypeScript package is not installed. Please install the package using the command: \"npm install typescript --save-dev\"");
|
|
50
|
-
const tsconfigFilePath = require_tsconfig.getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
51
|
-
context.tsconfig.originalTsconfigJson = await (0, __stryke_fs_json.readJsonFile)(tsconfigFilePath);
|
|
52
|
-
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
53
|
-
context.debug("Writing updated TypeScript configuration (tsconfig.json) file to disk.");
|
|
54
|
-
await context.fs.write(tsconfigFilePath, __stryke_json_storm_json.StormJSON.stringify(context.tsconfig.tsconfigJson));
|
|
55
|
-
context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
56
|
-
}
|
|
57
|
-
async function resolveTsconfig(context) {
|
|
58
|
-
const updateTsconfigJson = await (0, __stryke_fs_json.readJsonFile)(context.tsconfig.tsconfigFilePath);
|
|
59
|
-
if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
|
|
60
|
-
const result = (0, __donedeal0_superdiff.getObjectDiff)(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
|
|
61
|
-
ignoreArrayOrder: true,
|
|
62
|
-
showOnly: {
|
|
63
|
-
statuses: [
|
|
64
|
-
"added",
|
|
65
|
-
"deleted",
|
|
66
|
-
"updated"
|
|
67
|
-
],
|
|
68
|
-
granularity: "deep"
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const changes = [];
|
|
72
|
-
const getChanges = (difference, property) => {
|
|
73
|
-
if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") if (difference.diff) for (const diff of difference.diff) getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
|
|
74
|
-
else changes.push({
|
|
75
|
-
field: property ? `${property}.${difference.property}` : difference.property,
|
|
76
|
-
status: difference.status,
|
|
77
|
-
previous: difference.status === "added" ? "---" : __stryke_json_storm_json.StormJSON.stringify(difference.previousValue),
|
|
78
|
-
current: difference.status === "deleted" ? "---" : __stryke_json_storm_json.StormJSON.stringify(difference.currentValue)
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
for (const diff of result.diff) getChanges(diff);
|
|
82
|
-
if (changes.length > 0) context.warn(`Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
|
|
83
|
-
|
|
84
|
-
${changes.map((change, i) => `${chalk.default.bold.whiteBright(`${i + 1}. ${(0, __stryke_string_format_title_case.titleCase)(change.status)} the ${change.field} field: `)}
|
|
85
|
-
${chalk.default.red(` - Previous: ${change.previous} `)}
|
|
86
|
-
${chalk.default.green(` - Updated: ${change.current} `)}
|
|
87
|
-
`).join("\n")}
|
|
88
|
-
`);
|
|
89
|
-
await context.fs.write(context.tsconfig.tsconfigFilePath, __stryke_json_storm_json.StormJSON.stringify(updateTsconfigJson));
|
|
90
|
-
context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
|
|
91
|
-
if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
exports.getTsconfigDtsPath = getTsconfigDtsPath;
|
|
96
|
-
exports.initializeTsconfig = initializeTsconfig;
|
|
97
|
-
exports.resolveTsconfig = resolveTsconfig;
|