@reliverse/dler 1.7.15 → 1.7.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +164 -191
  2. package/bin/app/agg/run.js +2 -8
  3. package/bin/app/build/cmd.js +4 -4
  4. package/bin/app/build/impl.d.ts +2 -6
  5. package/bin/app/build/impl.js +2 -46
  6. package/bin/app/conv/cmd.d.ts +8 -33
  7. package/bin/app/conv/cmd.js +185 -163
  8. package/bin/app/copy/cmd.js +1 -1
  9. package/bin/app/init/init-impl.js +3 -3
  10. package/bin/app/init/init-types.d.ts +8 -8
  11. package/bin/app/merge/cmd.d.ts +17 -17
  12. package/bin/app/merge/cmd.js +70 -310
  13. package/bin/app/migrate/codemods/anything-bun.js +1 -1
  14. package/bin/app/migrate/codemods/fs-relifso.d.ts +2 -2
  15. package/bin/app/migrate/codemods/fs-relifso.js +1 -1
  16. package/bin/app/migrate/codemods/nodenext-bundler.d.ts +2 -2
  17. package/bin/app/migrate/codemods/nodenext-bundler.js +1 -1
  18. package/bin/app/migrate/codemods/path-pathkit.d.ts +2 -2
  19. package/bin/app/migrate/codemods/path-pathkit.js +1 -1
  20. package/bin/app/migrate/codemods/readdir-glob.d.ts +2 -2
  21. package/bin/app/migrate/codemods/readdir-glob.js +1 -1
  22. package/bin/app/mkdist/cmd.js +4 -2
  23. package/bin/app/pack/cmd.d.ts +44 -0
  24. package/bin/app/pack/cmd.js +313 -0
  25. package/bin/app/pub/cmd.js +4 -4
  26. package/bin/app/pub/impl.d.ts +7 -0
  27. package/bin/app/pub/impl.js +97 -0
  28. package/bin/app/rename/cmd.js +1 -1
  29. package/bin/app/spell/cmd.d.ts +14 -5
  30. package/bin/app/spell/cmd.js +33 -33
  31. package/bin/app/spell/old.js +0 -0
  32. package/bin/app/{mock → unpack}/cmd.d.ts +10 -14
  33. package/bin/app/unpack/cmd.js +200 -0
  34. package/bin/cli.js +2 -2
  35. package/bin/libs/cfg/cfg-mod.d.ts +69 -0
  36. package/bin/libs/cfg/cfg-mod.js +61 -0
  37. package/bin/libs/cfg/rse/rse-impl/rse-biome.d.ts +2 -0
  38. package/bin/libs/cfg/rse/rse-impl/rse-biome.js +34 -0
  39. package/bin/libs/cfg/rse/rse-impl/rse-consts.d.ts +35 -0
  40. package/bin/libs/cfg/rse/rse-impl/rse-consts.js +37 -0
  41. package/bin/libs/cfg/rse/rse-impl/rse-content.d.ts +14 -0
  42. package/bin/libs/cfg/rse/rse-impl/rse-content.js +15 -0
  43. package/bin/libs/cfg/rse/rse-impl/rse-core.d.ts +14 -0
  44. package/bin/libs/cfg/rse/rse-impl/rse-core.js +63 -0
  45. package/bin/libs/cfg/rse/rse-impl/rse-create.d.ts +36 -0
  46. package/bin/libs/cfg/rse/rse-impl/rse-create.js +254 -0
  47. package/bin/libs/cfg/rse/rse-impl/rse-def-utils.d.ts +6 -0
  48. package/bin/libs/cfg/rse/rse-impl/rse-def-utils.js +225 -0
  49. package/bin/libs/cfg/rse/rse-impl/rse-default.d.ts +3 -0
  50. package/bin/libs/cfg/rse/rse-impl/rse-default.js +155 -0
  51. package/bin/libs/cfg/rse/rse-impl/rse-define.d.ts +125 -0
  52. package/bin/libs/cfg/rse/rse-impl/rse-define.js +4 -0
  53. package/bin/libs/cfg/rse/rse-impl/rse-detect.d.ts +23 -0
  54. package/bin/libs/cfg/rse/rse-impl/rse-detect.js +347 -0
  55. package/bin/libs/cfg/rse/rse-impl/rse-gen-cfg.d.ts +3 -0
  56. package/bin/libs/cfg/rse/rse-impl/rse-gen-cfg.js +186 -0
  57. package/bin/libs/cfg/rse/rse-impl/rse-inject.d.ts +1 -0
  58. package/bin/libs/cfg/rse/rse-impl/rse-inject.js +57 -0
  59. package/bin/libs/cfg/rse/rse-impl/rse-migrate.d.ts +5 -0
  60. package/bin/libs/cfg/rse/rse-impl/rse-migrate.js +56 -0
  61. package/bin/libs/cfg/rse/rse-impl/rse-path.d.ts +11 -0
  62. package/bin/libs/cfg/rse/rse-impl/rse-path.js +33 -0
  63. package/bin/libs/cfg/rse/rse-impl/rse-prompts.d.ts +5 -0
  64. package/bin/libs/cfg/rse/rse-impl/rse-prompts.js +12 -0
  65. package/bin/libs/cfg/rse/rse-impl/rse-read.d.ts +11 -0
  66. package/bin/libs/cfg/rse/rse-impl/rse-read.js +84 -0
  67. package/bin/libs/cfg/rse/rse-impl/rse-repair.d.ts +16 -0
  68. package/bin/libs/cfg/rse/rse-impl/rse-repair.js +137 -0
  69. package/bin/libs/cfg/rse/rse-impl/rse-schema.d.ts +130 -0
  70. package/bin/libs/cfg/rse/rse-impl/rse-schema.js +444 -0
  71. package/bin/libs/cfg/rse/rse-impl/rse-types.d.ts +75 -0
  72. package/bin/libs/cfg/rse/rse-impl/rse-types.js +0 -0
  73. package/bin/libs/cfg/rse/rse-impl/rse-unstable.d.ts +11 -0
  74. package/bin/libs/cfg/rse/rse-impl/rse-unstable.js +41 -0
  75. package/bin/libs/cfg/rse/rse-impl/rse-update.d.ts +10 -0
  76. package/bin/libs/cfg/rse/rse-impl/rse-update.js +152 -0
  77. package/bin/libs/cfg/rse/rse-impl/rse-utils.d.ts +17 -0
  78. package/bin/libs/cfg/rse/rse-impl/rse-utils.js +86 -0
  79. package/bin/libs/cfg/rse/rse-mod.d.ts +20 -0
  80. package/bin/libs/cfg/rse/rse-mod.js +20 -0
  81. package/bin/libs/cfg/types.d.ts +533 -0
  82. package/bin/libs/cfg/types.js +0 -0
  83. package/bin/libs/sdk/sdk-impl/build/build-library.d.ts +5 -5
  84. package/bin/libs/sdk/sdk-impl/build/build-library.js +1 -174
  85. package/bin/libs/sdk/sdk-impl/build/build-regular.d.ts +2 -1
  86. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +287 -240
  87. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/loaders/vue.d.ts +4 -4
  88. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.d.ts +8 -5
  89. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.js +199 -119
  90. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/utils/spinner.d.ts +99 -0
  91. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/utils/spinner.js +206 -0
  92. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-mod.js +92 -46
  93. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.d.ts +2 -2
  94. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.d.ts +2 -2
  95. package/bin/libs/sdk/sdk-impl/config/default.d.ts +6 -0
  96. package/bin/libs/sdk/sdk-impl/{cfg → config}/default.js +8 -18
  97. package/bin/libs/sdk/sdk-impl/{cfg → config}/info.js +1 -1
  98. package/bin/libs/sdk/sdk-impl/{cfg → config}/init.js +53 -43
  99. package/bin/libs/sdk/sdk-impl/{cfg → config}/load.d.ts +2 -2
  100. package/bin/libs/sdk/sdk-impl/{cfg → config}/load.js +6 -6
  101. package/bin/libs/sdk/sdk-impl/config/types.d.ts +533 -0
  102. package/bin/libs/sdk/sdk-impl/config/types.js +0 -0
  103. package/bin/libs/sdk/sdk-impl/library-flow.d.ts +2 -1
  104. package/bin/libs/sdk/sdk-impl/pub/pub-library.js +7 -0
  105. package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +4 -8
  106. package/bin/libs/sdk/sdk-impl/regular-flow.d.ts +2 -1
  107. package/bin/libs/sdk/sdk-impl/rules/reliverse/dler-config-health/dler-config-health.js +2 -2
  108. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/deps-types.d.ts +6 -6
  109. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/filesystem.js +1 -1
  110. package/bin/libs/sdk/sdk-impl/rules/reliverse/no-index-files/no-index-files.js +1 -1
  111. package/bin/libs/sdk/sdk-impl/rules/reliverse/self-include/self-include.js +2 -2
  112. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.d.ts +38 -0
  113. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.js +474 -0
  114. package/bin/libs/sdk/sdk-impl/spell/spells.d.ts +31 -0
  115. package/bin/libs/sdk/sdk-impl/spell/spells.js +85 -0
  116. package/bin/libs/sdk/sdk-impl/utils/binary.js +1 -1
  117. package/bin/libs/sdk/sdk-impl/utils/comments.d.ts +6 -0
  118. package/bin/libs/sdk/sdk-impl/utils/comments.js +41 -0
  119. package/bin/libs/sdk/sdk-impl/utils/finalize.d.ts +2 -1
  120. package/bin/libs/sdk/sdk-impl/utils/finalize.js +1 -0
  121. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.d.ts +6 -0
  122. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.js +7 -0
  123. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.d.ts +5 -0
  124. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.js +40 -0
  125. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.d.ts +24 -0
  126. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.js +0 -0
  127. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.d.ts +17 -0
  128. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.js +46 -0
  129. package/bin/libs/sdk/sdk-impl/utils/replacements.d.ts +0 -0
  130. package/bin/libs/sdk/sdk-impl/utils/replacements.js +0 -0
  131. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.d.ts +3 -0
  132. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.js +194 -0
  133. package/bin/libs/sdk/sdk-impl/utils/utils-build.d.ts +1 -2
  134. package/bin/libs/sdk/sdk-impl/utils/utils-clean.d.ts +1 -1
  135. package/bin/libs/sdk/sdk-impl/utils/utils-deps.d.ts +1 -1
  136. package/bin/libs/sdk/sdk-impl/utils/utils-determine.d.ts +1 -1
  137. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.d.ts +4 -0
  138. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.js +1 -0
  139. package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.d.ts +1 -1
  140. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-libraries.d.ts +1 -1
  141. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-regular.d.ts +1 -1
  142. package/bin/libs/sdk/sdk-impl/utils/utils-security.d.ts +1 -3
  143. package/bin/libs/sdk/sdk-impl/utils/utils-security.js +11 -10
  144. package/bin/libs/sdk/sdk-mod.d.ts +1 -6
  145. package/bin/libs/sdk/sdk-mod.js +0 -31
  146. package/bin/libs/sdk/sdk-types.d.ts +39 -582
  147. package/bin/mod.d.ts +1 -1
  148. package/bin/mod.js +1 -1
  149. package/package.json +11 -4
  150. package/bin/app/mock/cmd.js +0 -284
  151. package/bin/app/mock/mock.d.ts +0 -11
  152. package/bin/app/mock/mock.js +0 -97
  153. package/bin/libs/sdk/sdk-impl/cfg/default.d.ts +0 -5
  154. package/bin/libs/sdk/sdk-impl/cfg/define.d.ts +0 -2
  155. package/bin/libs/sdk/sdk-impl/cfg/define.js +0 -4
  156. package/bin/libs/sdk/sdk-impl/spell/spell-executors.d.ts +0 -10
  157. package/bin/libs/sdk/sdk-impl/spell/spell-executors.js +0 -307
  158. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.d.ts +0 -7
  159. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.js +0 -74
  160. package/bin/libs/sdk/sdk-impl/spell/spell-mod.d.ts +0 -4
  161. package/bin/libs/sdk/sdk-impl/spell/spell-mod.js +0 -87
  162. package/bin/libs/sdk/sdk-impl/spell/spell-parser.d.ts +0 -4
  163. package/bin/libs/sdk/sdk-impl/spell/spell-parser.js +0 -58
  164. package/bin/libs/sdk/sdk-impl/spell/spell-types.d.ts +0 -60
  165. /package/bin/{libs/sdk/sdk-impl/spell/spell-types.js → app/spell/old.d.ts} +0 -0
  166. /package/bin/libs/sdk/sdk-impl/{cfg → config}/info.d.ts +0 -0
  167. /package/bin/libs/sdk/sdk-impl/{cfg → config}/init.d.ts +0 -0
@@ -1,171 +1,193 @@
1
- import fs from "@reliverse/relifso";
1
+ import * as path from "@reliverse/pathkit";
2
+ import { convertImportsAliasToRelative } from "@reliverse/pathkit";
2
3
  import { relinka } from "@reliverse/relinka";
3
- import { defineArgs, defineCommand } from "@reliverse/rempts";
4
- import { executeSpell } from "../../libs/sdk/sdk-mod.js";
5
- export default defineCommand({
6
- meta: {
7
- name: "conv",
8
- version: "1.0.0",
9
- description: "Convert files using various SDK converters."
10
- },
11
- args: defineArgs({
12
- type: {
13
- type: "string",
14
- required: true,
15
- description: "Type of conversion to perform (replace, rename, remove-comment, remove-line, remove-file, copy, move, transform, insert)"
16
- },
17
- input: {
18
- type: "string",
19
- required: true,
20
- description: "Input file or directory path"
21
- },
22
- output: {
23
- type: "string",
24
- description: "Output file or directory path (required for copy/move/rename operations)"
25
- },
26
- pattern: {
27
- type: "string",
28
- description: "Pattern to match (for replace/remove operations)"
29
- },
30
- replacement: {
31
- type: "string",
32
- description: "Replacement text (for replace/insert operations)"
33
- },
34
- line: {
35
- type: "number",
36
- description: "Line number (for insert/remove-line operations)"
37
- },
38
- transform: {
39
- type: "string",
40
- description: "Transform function name (for transform operation)"
4
+ import { promises as fs } from "node:fs";
5
+ async function validateAliasConfig(alias) {
6
+ try {
7
+ const tsconfigPath = path.resolve("tsconfig.json");
8
+ const tsconfig = JSON.parse(await fs.readFile(tsconfigPath, "utf8"));
9
+ const paths = tsconfig?.compilerOptions?.paths;
10
+ if (!paths) {
11
+ throw new Error("tsconfig.json is missing compilerOptions.paths configuration");
41
12
  }
42
- }),
43
- async run({ args }) {
44
- const { type, input, output, pattern, replacement, line, transform } = args;
45
- if (!await fs.pathExists(input)) {
46
- relinka("error", `\u274C Input path does not exist: ${input}`);
47
- return;
13
+ const aliasPattern = `${alias}/*`;
14
+ if (!paths[aliasPattern]) {
15
+ throw new Error(
16
+ `Alias "${alias}" is not configured in tsconfig.json. Add "${aliasPattern}": ["./src/*"] to compilerOptions.paths`
17
+ );
48
18
  }
49
- let spell;
50
- switch (type) {
51
- case "replace":
52
- if (!pattern || !replacement) {
53
- relinka("error", "\u274C Pattern and replacement are required for replace operation");
54
- return;
55
- }
56
- spell = {
57
- type: "replace-line",
58
- params: { hooked: false },
59
- value: replacement,
60
- fullMatch: pattern
61
- };
62
- break;
63
- case "rename":
64
- if (!output) {
65
- relinka("error", "\u274C Output path is required for rename operation");
66
- return;
67
- }
68
- spell = {
69
- type: "rename-file",
70
- params: { hooked: false },
71
- fileName: output
72
- };
73
- break;
74
- case "remove-comment":
75
- if (!pattern) {
76
- relinka("error", "\u274C Pattern is required for remove-comment operation");
77
- return;
78
- }
79
- spell = {
80
- type: "remove-comment",
81
- params: { hooked: false },
82
- fullMatch: pattern
83
- };
84
- break;
85
- case "remove-line":
86
- if (!pattern) {
87
- relinka("error", "\u274C Pattern is required for remove-line operation");
88
- return;
89
- }
90
- spell = {
91
- type: "remove-line",
92
- params: { hooked: false },
93
- fullMatch: pattern
94
- };
95
- break;
96
- case "remove-file":
97
- spell = {
98
- type: "remove-file",
99
- params: { hooked: false }
100
- };
101
- break;
102
- case "copy":
103
- if (!output) {
104
- relinka("error", "\u274C Output path is required for copy operation");
105
- return;
106
- }
107
- spell = {
108
- type: "copy-file",
109
- params: { hooked: false },
110
- fileName: output
111
- };
112
- break;
113
- case "move":
114
- if (!output) {
115
- relinka("error", "\u274C Output path is required for move operation");
116
- return;
117
- }
118
- spell = {
119
- type: "move-file",
120
- params: { hooked: false },
121
- fileName: output
122
- };
123
- break;
124
- case "transform":
125
- if (!transform) {
126
- relinka("error", "\u274C Transform function name is required for transform operation");
127
- return;
128
- }
129
- spell = {
130
- type: "transform-content",
131
- params: { hooked: false },
132
- value: transform
133
- };
134
- break;
135
- case "insert":
136
- if (!line || !replacement) {
137
- relinka("error", "\u274C Line number and replacement are required for insert operation");
138
- return;
139
- }
140
- spell = {
141
- type: "insert-at",
142
- params: { hooked: false },
143
- value: replacement,
144
- lineNumber: line
145
- };
146
- break;
147
- default:
148
- relinka("error", `\u274C Unknown conversion type: ${type}`);
149
- return;
19
+ } catch (error) {
20
+ if (error instanceof Error) {
21
+ throw new Error(`Failed to validate alias configuration: ${error.message}`);
150
22
  }
151
- try {
152
- const content = await fs.readFile(input, "utf8");
153
- const result = await executeSpell(spell, input, content);
154
- if (result.success) {
155
- relinka("log", `\u2705 Successfully performed ${type} operation on ${input}`);
156
- if (result.changes) {
157
- relinka(
158
- "log",
159
- `\u{1F4DD} Changes:
160
- Before: ${result.changes.before}
161
- After: ${result.changes.after}`
162
- );
23
+ throw new Error("Failed to validate alias configuration: Unknown error");
24
+ }
25
+ }
26
+ export async function resolveCrossLibs(alias = "~", subFolders = ["npm", "jsr"]) {
27
+ await validateAliasConfig(alias);
28
+ const distLibsPath = path.resolve("dist-libs");
29
+ const allModified = [];
30
+ try {
31
+ const libs = await fs.readdir(distLibsPath);
32
+ for (const lib of libs) {
33
+ for (const subFolder of subFolders) {
34
+ const libBinDir = path.join("dist-libs", lib, subFolder, "bin");
35
+ try {
36
+ await fs.access(libBinDir);
37
+ const modified = await resolveCrossLibsInternal(libBinDir, alias, subFolders);
38
+ allModified.push(...modified);
39
+ } catch {
163
40
  }
164
- } else {
165
- relinka("error", `\u274C Failed to perform ${type} operation: ${result.message}`);
166
41
  }
167
- } catch (error) {
168
- relinka("error", `\u274C Error during conversion: ${error}`);
42
+ }
43
+ } catch (error) {
44
+ throw new Error(`Failed to process dist-libs directory: ${error}`);
45
+ }
46
+ return allModified;
47
+ }
48
+ async function resolveCrossLibsInternal(libBinDir, alias = "~", subFolders = ["npm", "jsr"]) {
49
+ relinka(
50
+ "verbose",
51
+ `[resolveCrossLibs] dir=${libBinDir}, alias=${alias}, subs=${subFolders.join("/")}`
52
+ );
53
+ if (!libBinDir.startsWith("dist-libs")) {
54
+ throw new Error(`libBinDir must start with "dist-libs": ${libBinDir}`);
55
+ }
56
+ const absBinDir = path.resolve(libBinDir);
57
+ const [currentLib] = path.relative("dist-libs", libBinDir).split(path.sep);
58
+ await convertImportsAliasToRelative({
59
+ targetDir: absBinDir,
60
+ aliasToReplace: alias,
61
+ pathExtFilter: "js-ts-none"
62
+ });
63
+ async function collect(dir) {
64
+ const entries = await fs.readdir(dir, { withFileTypes: true });
65
+ const files = await Promise.all(
66
+ entries.map(
67
+ (e) => e.isDirectory() ? collect(path.join(dir, e.name)) : e.name.endsWith(".d.ts") || !(e.name.endsWith(".ts") || e.name.endsWith(".js")) ? [] : [path.join(dir, e.name)]
68
+ )
69
+ );
70
+ return files.flat();
71
+ }
72
+ const allFiles = await collect(absBinDir);
73
+ const modified = [];
74
+ await Promise.all(
75
+ allFiles.map(async (filePath) => {
76
+ const original = await fs.readFile(filePath, "utf8");
77
+ if (!original) {
78
+ throw new Error(`Failed to read file: ${filePath}`);
79
+ }
80
+ if (!currentLib) throw new Error("Current library is undefined");
81
+ const updated = await transformFile(original, filePath, currentLib, alias, subFolders);
82
+ if (updated !== original) {
83
+ await fs.writeFile(filePath, updated, "utf8");
84
+ modified.push(filePath);
85
+ relinka("verbose", `[inline] \u21B3 modified ${path.relative(process.cwd(), filePath)}`);
86
+ }
87
+ })
88
+ );
89
+ return modified;
90
+ }
91
+ async function transformFile(source, _filePath, currentLib, alias, subFolders) {
92
+ if (!source) {
93
+ throw new Error("Source content is undefined");
94
+ }
95
+ const ALIAS_RE = alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
96
+ const importRe = new RegExp(
97
+ String.raw`^\s*` + // leading space
98
+ String.raw`(` + String.raw`export\s+\{[\s\S]*?\}\s+from\s+` + // export {...} from
99
+ "|" + String.raw`import\s+[\s\S]*?\s+from\s+` + // import ... from
100
+ String.raw`)` + String.raw`(['"])` + // opening quote (group 2)
101
+ ALIAS_RE + String.raw`/libs/` + String.raw`([^/]+)` + // libName (group 3)
102
+ String.raw`/` + String.raw`([^'"]+)` + // rest path (group 4)
103
+ String.raw`\2` + // same quote
104
+ String.raw`\s*;?` + // optional semicolon
105
+ String.raw`(?:\s*(?://.*|/\*[\s\S]*?\*/))?` + // optional trailing comment
106
+ String.raw`\s*$`,
107
+ "s"
108
+ // dotAll
109
+ );
110
+ const output = [];
111
+ const lines = source.split(/\r?\n/);
112
+ let inInlineBlock = false;
113
+ let buffer = [];
114
+ const flushBuffer = async () => {
115
+ if (buffer.length === 0) return;
116
+ const stmt = buffer.join("\n");
117
+ relinka("verbose", ` [scan] candidate:
118
+ --------
119
+ ${stmt}
120
+ --------`);
121
+ if (!importRe.test(stmt) || inInlineBlock) {
122
+ output.push(...buffer);
123
+ buffer = [];
124
+ return;
125
+ }
126
+ const match = importRe.exec(stmt);
127
+ if (!match) {
128
+ output.push(...buffer);
129
+ buffer = [];
130
+ return;
131
+ }
132
+ const [, _prefix, _quote, libName, restRaw] = match;
133
+ if (!restRaw || !libName) {
134
+ throw new Error(`Invalid import statement: ${stmt}`);
135
+ }
136
+ const indentMatch = stmt.match(/^\s*/);
137
+ if (!indentMatch) {
138
+ throw new Error(`Invalid statement format: ${stmt}`);
139
+ }
140
+ const indent = indentMatch[0];
141
+ const rest = restRaw.replace(/^\/+/, "");
142
+ if (libName === currentLib) {
143
+ output.push(stmt);
144
+ relinka("verbose", ` [skip] ${libName} (self-import handled by pathkit)`);
145
+ buffer = [];
146
+ return;
147
+ }
148
+ const targetFile = await resolveTargetFile(libName, rest, subFolders);
149
+ const embedded = await fs.readFile(targetFile, "utf8");
150
+ relinka("verbose", ` [inline] ${libName} \u21A6 ${targetFile}`);
151
+ const inlinedBlock = `${indent}/* inlined-start ${alias}/libs/${libName}/${rest} */
152
+ ` + embedded.split(/\r?\n/).map((l) => indent + l).join("\n") + `
153
+ ${indent}/* inlined-end */`;
154
+ output.push(inlinedBlock);
155
+ buffer = [];
156
+ };
157
+ for (const line of lines) {
158
+ if (line.includes("/* inlined-start")) inInlineBlock = true;
159
+ if (line.includes("/* inlined-end")) inInlineBlock = false;
160
+ if (buffer.length) {
161
+ buffer.push(line);
162
+ if (line.trimEnd().endsWith(";")) await flushBuffer();
163
+ continue;
164
+ }
165
+ if (line.includes(`${alias}/libs/`) && /(export|import)\s/.test(line)) {
166
+ buffer.push(line);
167
+ if (line.trimEnd().endsWith(";")) await flushBuffer();
168
+ continue;
169
+ }
170
+ output.push(line);
171
+ }
172
+ await flushBuffer();
173
+ return output.join("\n");
174
+ }
175
+ async function resolveTargetFile(lib, rest, subFolders) {
176
+ const cleaned = rest.replace(/^\/+/, "");
177
+ for (const sub of subFolders) {
178
+ const base = path.join("dist-libs", lib, sub, "bin", cleaned);
179
+ const tsPath = `${base}.ts`;
180
+ try {
181
+ await fs.access(tsPath);
182
+ return tsPath;
183
+ } catch {
184
+ }
185
+ const jsPath = `${base}.js`;
186
+ try {
187
+ await fs.access(jsPath);
188
+ return jsPath;
189
+ } catch {
169
190
  }
170
191
  }
171
- });
192
+ throw new Error(`Cannot inline ~/libs/${lib}/${rest}: tried [${subFolders.join(", ")}]`);
193
+ }
@@ -1,7 +1,7 @@
1
+ import { join, dirname, basename } from "@reliverse/pathkit";
1
2
  import { relinka } from "@reliverse/relinka";
2
3
  import { defineCommand, selectPrompt, inputPrompt } from "@reliverse/rempts";
3
4
  import { copyFile, access, mkdir } from "node:fs/promises";
4
- import { join, dirname, basename } from "node:path";
5
5
  import pMap from "p-map";
6
6
  import prettyMilliseconds from "pretty-ms";
7
7
  import { glob } from "tinyglobby";
@@ -5,7 +5,7 @@ import { selectPrompt } from "@reliverse/rempts";
5
5
  import pMap from "p-map";
6
6
  import { FILE_TYPES } from "./init-const.js";
7
7
  import { gitignoreTemplate, licenseTemplate, readmeTemplate } from "./init-tmpl.js";
8
- const DEFAULT_CONFIG = {
8
+ const DEFAULT_CONFIG_INIT = {
9
9
  defaultInitBehaviour: "create",
10
10
  defaultDestFileExistsBehaviour: "prompt",
11
11
  parallelByDefault: false,
@@ -41,7 +41,7 @@ export async function createFileFromScratch(destPath, fileType, contentCreateMod
41
41
  }
42
42
  }
43
43
  export async function initFile(req, userCfg) {
44
- const config = { ...DEFAULT_CONFIG, ...userCfg };
44
+ const config = { ...DEFAULT_CONFIG_INIT, ...userCfg };
45
45
  const initBehaviour = req.initBehaviour ?? config.defaultInitBehaviour;
46
46
  const existsBehaviour = req.destFileExistsBehaviour ?? config.defaultDestFileExistsBehaviour;
47
47
  config.onFileStart?.(req);
@@ -63,7 +63,7 @@ export async function initFile(req, userCfg) {
63
63
  return result;
64
64
  }
65
65
  export async function initFiles(items, options, userCfg) {
66
- const config = { ...DEFAULT_CONFIG, ...userCfg };
66
+ const config = { ...DEFAULT_CONFIG_INIT, ...userCfg };
67
67
  const parallel = options?.parallel ?? config.parallelByDefault;
68
68
  const concurrency = options?.concurrency ?? config.parallelConcurrency;
69
69
  if (parallel) {
@@ -3,7 +3,7 @@ export type FileType = (typeof FILE_TYPES)[number]["type"];
3
3
  export type InitBehaviour = (typeof INIT_BEHAVIOURS)[number];
4
4
  export type DestFileExistsBehaviour = (typeof DEST_FILE_EXISTS_BEHAVIOURS)[number];
5
5
  /** Library-level interface for hooking into the file init process. */
6
- export type ReinitUserConfig = {
6
+ export interface ReinitUserConfig {
7
7
  /** The default approach for copying vs. creating. */
8
8
  defaultInitBehaviour?: InitBehaviour;
9
9
  /** Default approach if a file already exists. */
@@ -16,26 +16,26 @@ export type ReinitUserConfig = {
16
16
  onFileStart?: (req: InitFileRequest) => void;
17
17
  /** Called after each file operation. */
18
18
  onFileComplete?: (res: InitFileResult) => void;
19
- };
19
+ }
20
20
  /** Data describing a single request to initFile. */
21
- export type InitFileRequest = {
21
+ export interface InitFileRequest {
22
22
  fileType: FileType;
23
23
  destDir: string;
24
24
  initBehaviour?: InitBehaviour;
25
25
  destFileExistsBehaviour?: DestFileExistsBehaviour;
26
26
  options?: InitFileOptions;
27
- };
27
+ }
28
28
  /** Extended per-file options. */
29
- export type InitFileOptions = {
29
+ export interface InitFileOptions {
30
30
  destFileName?: string;
31
31
  srcCopyMode?: string;
32
32
  contentCreateMode?: string;
33
33
  fallbackSource?: string;
34
- };
34
+ }
35
35
  /** The result of a single initFile operation. */
36
- export type InitFileResult = {
36
+ export interface InitFileResult {
37
37
  requested: InitFileRequest;
38
38
  finalPath?: string;
39
39
  status: "created" | "copied" | "skipped" | "error";
40
40
  error?: any;
41
- };
41
+ }
@@ -1,8 +1,4 @@
1
1
  declare const _default: import("@reliverse/rempts").Command<{
2
- dev: {
3
- type: "boolean";
4
- description: string;
5
- };
6
2
  s: {
7
3
  type: "array";
8
4
  description: string;
@@ -20,6 +16,14 @@ declare const _default: import("@reliverse/rempts").Command<{
20
16
  default: string;
21
17
  description: string;
22
18
  };
19
+ "max-file-size": {
20
+ type: "number";
21
+ description: string;
22
+ };
23
+ "max-merge-size": {
24
+ type: "number";
25
+ description: string;
26
+ };
23
27
  stdout: {
24
28
  type: "boolean";
25
29
  description: string;
@@ -101,27 +105,23 @@ declare const _default: import("@reliverse/rempts").Command<{
101
105
  type: "boolean";
102
106
  description: string;
103
107
  };
104
- "as-template": {
105
- type: "boolean";
106
- description: string;
107
- };
108
- "custom-template-name": {
109
- type: "string";
108
+ depth: {
109
+ type: "number";
110
110
  description: string;
111
+ default: number;
111
112
  };
112
- whitelabel: {
113
- type: "string";
113
+ sourcemap: {
114
+ type: "boolean";
114
115
  description: string;
115
- default: string;
116
116
  };
117
- sourcemap: {
117
+ verbose: {
118
118
  type: "boolean";
119
119
  description: string;
120
120
  };
121
- "update-template": {
122
- type: "string";
121
+ force: {
122
+ type: "boolean";
123
123
  description: string;
124
- dependencies: string[];
124
+ default: true;
125
125
  };
126
126
  }>;
127
127
  export default _default;