@reliverse/dler 1.7.16 → 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 (165) hide show
  1. package/README.md +134 -206
  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 +10 -24
  12. package/bin/app/merge/cmd.js +47 -464
  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/regular-flow.d.ts +2 -1
  105. package/bin/libs/sdk/sdk-impl/rules/reliverse/dler-config-health/dler-config-health.js +2 -2
  106. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/deps-types.d.ts +6 -6
  107. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/filesystem.js +1 -1
  108. package/bin/libs/sdk/sdk-impl/rules/reliverse/no-index-files/no-index-files.js +1 -1
  109. package/bin/libs/sdk/sdk-impl/rules/reliverse/self-include/self-include.js +2 -2
  110. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.d.ts +38 -0
  111. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.js +474 -0
  112. package/bin/libs/sdk/sdk-impl/spell/spells.d.ts +31 -0
  113. package/bin/libs/sdk/sdk-impl/spell/spells.js +85 -0
  114. package/bin/libs/sdk/sdk-impl/utils/binary.js +1 -1
  115. package/bin/libs/sdk/sdk-impl/utils/comments.d.ts +6 -0
  116. package/bin/libs/sdk/sdk-impl/utils/comments.js +41 -0
  117. package/bin/libs/sdk/sdk-impl/utils/finalize.d.ts +2 -1
  118. package/bin/libs/sdk/sdk-impl/utils/finalize.js +1 -0
  119. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.d.ts +6 -0
  120. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.js +7 -0
  121. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.d.ts +5 -0
  122. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.js +40 -0
  123. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.d.ts +24 -0
  124. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.js +0 -0
  125. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.d.ts +17 -0
  126. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.js +46 -0
  127. package/bin/libs/sdk/sdk-impl/utils/replacements.d.ts +0 -0
  128. package/bin/libs/sdk/sdk-impl/utils/replacements.js +0 -0
  129. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.d.ts +3 -0
  130. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.js +194 -0
  131. package/bin/libs/sdk/sdk-impl/utils/utils-build.d.ts +1 -2
  132. package/bin/libs/sdk/sdk-impl/utils/utils-clean.d.ts +1 -1
  133. package/bin/libs/sdk/sdk-impl/utils/utils-deps.d.ts +1 -1
  134. package/bin/libs/sdk/sdk-impl/utils/utils-determine.d.ts +1 -1
  135. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.d.ts +4 -0
  136. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.js +1 -0
  137. package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.d.ts +1 -1
  138. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-libraries.d.ts +1 -1
  139. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-regular.d.ts +1 -1
  140. package/bin/libs/sdk/sdk-impl/utils/utils-security.d.ts +1 -3
  141. package/bin/libs/sdk/sdk-impl/utils/utils-security.js +11 -10
  142. package/bin/libs/sdk/sdk-mod.d.ts +1 -6
  143. package/bin/libs/sdk/sdk-mod.js +0 -31
  144. package/bin/libs/sdk/sdk-types.d.ts +39 -582
  145. package/bin/mod.d.ts +1 -1
  146. package/bin/mod.js +1 -1
  147. package/package.json +11 -4
  148. package/bin/app/mock/cmd.js +0 -284
  149. package/bin/app/mock/mock.d.ts +0 -11
  150. package/bin/app/mock/mock.js +0 -97
  151. package/bin/libs/sdk/sdk-impl/cfg/default.d.ts +0 -5
  152. package/bin/libs/sdk/sdk-impl/cfg/define.d.ts +0 -2
  153. package/bin/libs/sdk/sdk-impl/cfg/define.js +0 -4
  154. package/bin/libs/sdk/sdk-impl/spell/spell-executors.d.ts +0 -10
  155. package/bin/libs/sdk/sdk-impl/spell/spell-executors.js +0 -307
  156. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.d.ts +0 -7
  157. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.js +0 -74
  158. package/bin/libs/sdk/sdk-impl/spell/spell-mod.d.ts +0 -4
  159. package/bin/libs/sdk/sdk-impl/spell/spell-mod.js +0 -87
  160. package/bin/libs/sdk/sdk-impl/spell/spell-parser.d.ts +0 -4
  161. package/bin/libs/sdk/sdk-impl/spell/spell-parser.js +0 -58
  162. package/bin/libs/sdk/sdk-impl/spell/spell-types.d.ts +0 -60
  163. /package/bin/{libs/sdk/sdk-impl/spell/spell-types.js → app/spell/old.d.ts} +0 -0
  164. /package/bin/libs/sdk/sdk-impl/{cfg → config}/info.d.ts +0 -0
  165. /package/bin/libs/sdk/sdk-impl/{cfg → config}/init.d.ts +0 -0
@@ -5,129 +5,209 @@ import { glob } from "tinyglobby";
5
5
  import { createLoader } from "./loader.js";
6
6
  import { getDeclarations, normalizeCompilerOptions } from "./utils/dts.js";
7
7
  import { copyFileWithStream } from "./utils/fs.js";
8
+ import { useSpinner } from "./utils/spinner.js";
8
9
  import { getVueDeclarations } from "./utils/vue-dts.js";
9
10
  export async function mkdist(options = {}) {
10
- options.rootDir = resolve(process.cwd(), options.rootDir || ".");
11
- options.srcDir = resolve(options.rootDir, options.srcDir || "src");
12
- options.distDir = resolve(options.rootDir, options.distDir || "dist");
13
- if (options.cleanDist !== false) {
14
- await fsp.unlink(options.distDir).catch(() => {
15
- });
16
- await fsp.rm(options.distDir, { recursive: true, force: true });
17
- await fsp.mkdir(options.distDir, { recursive: true });
18
- }
19
- const filePaths = await glob(options.pattern || "**", {
20
- absolute: false,
21
- ignore: ["**/node_modules", "**/coverage", "**/.git"],
22
- cwd: options.srcDir,
23
- dot: true,
24
- ...options.globOptions
25
- });
26
- const files = filePaths.map((path) => {
27
- const sourcePath = resolve(options.srcDir, path);
28
- return {
29
- path,
30
- srcPath: sourcePath,
31
- extension: extname(path),
32
- getContents: () => fsp.readFile(sourcePath, { encoding: "utf8" })
33
- };
34
- });
35
- options.typescript ||= {};
36
- if (options.typescript.compilerOptions) {
37
- options.typescript.compilerOptions = await normalizeCompilerOptions(
38
- options.typescript.compilerOptions
39
- );
40
- }
41
- options.typescript.compilerOptions = defu(
42
- { noEmit: false },
43
- options.typescript.compilerOptions,
44
- {
45
- allowJs: true,
46
- declaration: true,
47
- skipLibCheck: true,
48
- strictNullChecks: true,
49
- emitDeclarationOnly: true,
50
- allowImportingTsExtensions: true,
51
- allowNonTsExtensions: true
52
- }
53
- );
54
- const { loadFile } = createLoader(options);
55
- const outputs = [];
56
- for (const file of files) {
57
- outputs.push(...await loadFile(file) || []);
58
- }
59
- for (const output of outputs.filter((o) => o.extension)) {
60
- const renamed = basename(output.path, extname(output.path)) + output.extension;
61
- output.path = join(dirname(output.path), renamed);
62
- if (outputs.some((o) => o !== output && o.path === output.path)) {
63
- output.skip = true;
64
- }
65
- }
66
- const dtsOutputs = outputs.filter((o) => o.declaration && !o.skip);
67
- if (dtsOutputs.length > 0) {
68
- const vfs = new Map(dtsOutputs.map((o) => [o.srcPath, o.contents || ""]));
69
- const declarations = /* @__PURE__ */ Object.create(null);
70
- for (const loader of [getVueDeclarations, getDeclarations]) {
71
- Object.assign(declarations, await loader(vfs, options));
72
- }
73
- for (const output of dtsOutputs) {
74
- const result = declarations[output.srcPath];
75
- output.contents = result?.contents || "";
76
- if (result.errors) {
77
- output.errors = result.errors;
11
+ return await useSpinner.withTiming(
12
+ async (mainSpinner) => {
13
+ options.rootDir = resolve(process.cwd(), options.rootDir || ".");
14
+ options.srcDir = resolve(options.rootDir, options.srcDir || "src");
15
+ options.distDir = resolve(options.rootDir, options.distDir || "dist");
16
+ if (options.cleanDist !== false) {
17
+ mainSpinner.setText("Cleaning distribution directory...");
18
+ await fsp.unlink(options.distDir).catch(() => {
19
+ });
20
+ await fsp.rm(options.distDir, { recursive: true, force: true });
21
+ await fsp.mkdir(options.distDir, { recursive: true });
78
22
  }
79
- }
80
- }
81
- const outPaths = new Set(outputs.map((o) => o.path));
82
- const resolveId = (from, id = "", resolveExtensions) => {
83
- if (!id.startsWith(".")) {
84
- return id;
85
- }
86
- for (const extension of resolveExtensions) {
87
- if (outPaths.has(join(dirname(from), id + extension))) {
88
- return id + extension;
23
+ mainSpinner.setText("Scanning input files...");
24
+ const filePaths = await glob(options.pattern || "**", {
25
+ absolute: false,
26
+ ignore: ["**/node_modules", "**/coverage", "**/.git"],
27
+ cwd: options.srcDir,
28
+ dot: true,
29
+ ...options.globOptions
30
+ });
31
+ const files = filePaths.map((path) => {
32
+ const sourcePath = resolve(options.srcDir, path);
33
+ return {
34
+ path,
35
+ srcPath: sourcePath,
36
+ extension: extname(path),
37
+ getContents: () => fsp.readFile(sourcePath, { encoding: "utf8" })
38
+ };
39
+ });
40
+ mainSpinner.setText(`Found ${files.length} files to process`);
41
+ options.typescript ||= {};
42
+ if (options.typescript.compilerOptions) {
43
+ mainSpinner.setText("Normalizing TypeScript compiler options...");
44
+ options.typescript.compilerOptions = await normalizeCompilerOptions(
45
+ options.typescript.compilerOptions
46
+ );
89
47
  }
90
- }
91
- return id;
92
- };
93
- const esmResolveExtensions = ["", "/index.mjs", "/index.js", ".mjs", ".ts", ".js"];
94
- for (const output of outputs.filter((o) => o.extension === ".mjs" || o.extension === ".js")) {
95
- output.contents = output.contents.replace(
96
- /(import|export)(\s+(?:.+|{[\s\w,]+})\s+from\s+["'])(.*)(["'])/g,
97
- (_, type, head, id, tail) => type + head + resolveId(output.path, id, esmResolveExtensions) + tail
98
- ).replace(
99
- /import\((["'])(.*)(["'])\)/g,
100
- (_, head, id, tail) => "import(" + head + resolveId(output.path, id, esmResolveExtensions) + tail + ")"
101
- );
102
- }
103
- const cjsResolveExtensions = ["", "/index.cjs", ".cjs"];
104
- for (const output of outputs.filter((o) => o.extension === ".cjs")) {
105
- output.contents = output.contents.replace(
106
- /require\((["'])(.*)(["'])\)/g,
107
- (_, head, id, tail) => "require(" + head + resolveId(output.path, id, cjsResolveExtensions) + tail + ")"
108
- );
109
- }
110
- const writtenFiles = [];
111
- const errors = [];
112
- await Promise.all(
113
- outputs.filter((o) => !o.skip).map(async (output) => {
114
- const outFile = join(options.distDir, output.path);
115
- await fsp.mkdir(dirname(outFile), { recursive: true });
116
- await (output.raw ? (
117
- // @ts-expect-error TODO: fix ts
118
- copyFileWithStream(output.srcPath, outFile)
119
- ) : (
120
- // @ts-expect-error TODO: fix ts
121
- fsp.writeFile(outFile, output.contents, "utf8")
122
- ));
123
- writtenFiles.push(outFile);
124
- if (output.errors) {
125
- errors.push({ filename: outFile, errors: output.errors });
48
+ options.typescript.compilerOptions = defu(
49
+ { noEmit: false },
50
+ options.typescript.compilerOptions,
51
+ {
52
+ allowJs: true,
53
+ declaration: true,
54
+ skipLibCheck: true,
55
+ strictNullChecks: true,
56
+ emitDeclarationOnly: true,
57
+ allowImportingTsExtensions: true,
58
+ allowNonTsExtensions: true
59
+ }
60
+ );
61
+ mainSpinner.setText("Creating file loaders...");
62
+ const { loadFile } = createLoader(options);
63
+ mainSpinner.setText("Processing files with loaders...");
64
+ const outputs = [];
65
+ let processedCount = 0;
66
+ await Promise.all(
67
+ files.map(async (file) => {
68
+ const result = await loadFile(file);
69
+ if (result) {
70
+ outputs.push(...result);
71
+ }
72
+ processedCount++;
73
+ const shouldUpdate = processedCount % Math.max(1, Math.floor(files.length / 10)) === 0 || processedCount === files.length;
74
+ if (shouldUpdate) {
75
+ mainSpinner.setProgress({
76
+ current: processedCount,
77
+ total: files.length
78
+ });
79
+ mainSpinner.setText(`Processing files: ${file.path}`);
80
+ }
81
+ })
82
+ );
83
+ mainSpinner.setText("Normalizing output extensions...");
84
+ const pathConflicts = [];
85
+ for (const output of outputs.filter((o) => o.extension)) {
86
+ const renamed = basename(output.path, extname(output.path)) + output.extension;
87
+ output.path = join(dirname(output.path), renamed);
88
+ const conflictingOutput = outputs.find((o) => o !== output && o.path === output.path);
89
+ if (conflictingOutput) {
90
+ pathConflicts.push(output.path);
91
+ }
126
92
  }
127
- })
93
+ if (pathConflicts.length > 0) {
94
+ const errorMessage = `Output path conflict detected for paths: ${pathConflicts.join(", ")}. Multiple files would write to the same output path.`;
95
+ mainSpinner.fail(errorMessage);
96
+ throw new Error(errorMessage);
97
+ }
98
+ const dtsOutputs = outputs.filter((o) => o.declaration && !o.skip);
99
+ if (dtsOutputs.length > 0) {
100
+ mainSpinner.setText(`Generating TypeScript declarations for ${dtsOutputs.length} files...`);
101
+ const vfs = new Map(dtsOutputs.map((o) => [o.srcPath, o.contents || ""]));
102
+ const declarations = /* @__PURE__ */ Object.create(null);
103
+ for (const loader of [getVueDeclarations, getDeclarations]) {
104
+ Object.assign(declarations, await loader(vfs, options));
105
+ }
106
+ let dtsProcessed = 0;
107
+ for (const output of dtsOutputs) {
108
+ const result = declarations[output.srcPath];
109
+ output.contents = result?.contents || "";
110
+ if (result.errors) {
111
+ output.errors = result.errors;
112
+ }
113
+ dtsProcessed++;
114
+ if (dtsProcessed % Math.max(1, Math.floor(dtsOutputs.length / 5)) === 0) {
115
+ mainSpinner.setProgress({
116
+ current: dtsProcessed,
117
+ total: dtsOutputs.length
118
+ });
119
+ }
120
+ }
121
+ }
122
+ mainSpinner.setText("Resolving relative imports...");
123
+ const outPaths = new Set(outputs.map((o) => o.path));
124
+ const resolveId = (from, id = "", resolveExtensions) => {
125
+ if (!id.startsWith(".")) {
126
+ return id;
127
+ }
128
+ for (const extension of resolveExtensions) {
129
+ if (outPaths.has(join(dirname(from), id + extension))) {
130
+ return id + extension;
131
+ }
132
+ }
133
+ return id;
134
+ };
135
+ const esmResolveExtensions = ["", "/index.mjs", "/index.js", ".mjs", ".ts", ".js"];
136
+ const esmOutputs = outputs.filter((o) => o.extension === ".mjs" || o.extension === ".js");
137
+ for (const output of esmOutputs) {
138
+ output.contents = output.contents.replace(
139
+ /(import|export)(\s+(?:.+|{[\s\w,]+})\s+from\s+["'])(.*)(["'])/g,
140
+ (_, type, head, id, tail) => type + head + resolveId(output.path, id, esmResolveExtensions) + tail
141
+ ).replace(
142
+ /import\((["'])(.*)(["'])\)/g,
143
+ (_, head, id, tail) => "import(" + head + resolveId(output.path, id, esmResolveExtensions) + tail + ")"
144
+ );
145
+ }
146
+ const cjsResolveExtensions = ["", "/index.cjs", ".cjs"];
147
+ const cjsOutputs = outputs.filter((o) => o.extension === ".cjs");
148
+ for (const output of cjsOutputs) {
149
+ output.contents = output.contents.replace(
150
+ /require\((["'])(.*)(["'])\)/g,
151
+ (_, head, id, tail) => "require(" + head + resolveId(output.path, id, cjsResolveExtensions) + tail + ")"
152
+ );
153
+ }
154
+ const outputsToWrite = outputs.filter((o) => !o.skip);
155
+ mainSpinner.setText(`Writing ${outputsToWrite.length} output files...`);
156
+ const writtenFiles = [];
157
+ const errors = [];
158
+ let writtenCount = 0;
159
+ await Promise.all(
160
+ outputsToWrite.map(async (output) => {
161
+ try {
162
+ const outFile = join(options.distDir, output.path);
163
+ await fsp.mkdir(dirname(outFile), { recursive: true });
164
+ await (output.raw ? (
165
+ // @ts-expect-error TODO: fix ts
166
+ copyFileWithStream(output.srcPath, outFile)
167
+ ) : (
168
+ // @ts-expect-error TODO: fix ts
169
+ fsp.writeFile(outFile, output.contents, "utf8")
170
+ ));
171
+ writtenFiles.push(outFile);
172
+ if (output.errors) {
173
+ errors.push({ filename: outFile, errors: output.errors });
174
+ }
175
+ } catch (error) {
176
+ const errorMessage = `Failed to write file ${output.path}: ${error instanceof Error ? error.message : "Unknown error"}`;
177
+ errors.push({
178
+ filename: output.path,
179
+ errors: [new TypeError(errorMessage)]
180
+ });
181
+ }
182
+ writtenCount++;
183
+ const progressUpdateInterval = Math.max(10, Math.floor(outputsToWrite.length / 10));
184
+ if (writtenCount % progressUpdateInterval === 0 || writtenCount === outputsToWrite.length) {
185
+ mainSpinner.setProgress({
186
+ current: writtenCount,
187
+ total: outputsToWrite.length
188
+ });
189
+ }
190
+ })
191
+ );
192
+ if (errors.length > 0) {
193
+ mainSpinner.warn(`Build completed with ${errors.length} errors`);
194
+ for (const error of errors.slice(0, 5)) {
195
+ console.error(`Error in ${error.filename}:`, error.errors[0]?.message || "Unknown error");
196
+ }
197
+ if (errors.length > 5) {
198
+ console.error(`... and ${errors.length - 5} more errors`);
199
+ }
200
+ }
201
+ return {
202
+ errors,
203
+ writtenFiles
204
+ };
205
+ },
206
+ {
207
+ text: "Starting mkdist build...",
208
+ color: "cyan",
209
+ successText: "Build completed successfully!",
210
+ failText: "Build failed!"
211
+ }
128
212
  );
129
- return {
130
- errors,
131
- writtenFiles
132
- };
133
213
  }
@@ -0,0 +1,99 @@
1
+ import { type Color, type Options as OraOptions } from "ora";
2
+ interface SpinnerOptions {
3
+ text: string;
4
+ color?: Color;
5
+ spinner?: OraOptions["spinner"];
6
+ successText?: string;
7
+ failText?: string;
8
+ prefixText?: string;
9
+ silent?: boolean;
10
+ hideCursor?: boolean;
11
+ }
12
+ interface ProgressOptions {
13
+ current: number;
14
+ total: number;
15
+ format?: "percentage" | "count" | "both";
16
+ }
17
+ interface SpinnerControls {
18
+ start: (text?: string) => SpinnerControls;
19
+ stop: () => void;
20
+ setText: (text: string) => void;
21
+ setProgress: (progress: ProgressOptions) => void;
22
+ succeed: (text?: string) => void;
23
+ fail: (text?: string) => void;
24
+ warn: (text?: string) => void;
25
+ info: (text?: string) => void;
26
+ isSpinning: () => boolean;
27
+ clear: () => void;
28
+ getElapsedTime: () => number;
29
+ pause: () => void;
30
+ resume: () => void;
31
+ dispose: () => void;
32
+ }
33
+ /**
34
+ * Creates a terminal spinner with enhanced controls and styling options.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Basic usage
39
+ * const spinner = useSpinner({ text: "Loading..." }).start();
40
+ * spinner.stop();
41
+ *
42
+ * // With progress tracking
43
+ * const spinner = useSpinner({ text: "Processing files..." }).start();
44
+ * for (let i = 0; i < files.length; i++) {
45
+ * spinner.setProgress({ current: i + 1, total: files.length });
46
+ * await processFile(files[i]);
47
+ * }
48
+ * spinner.succeed();
49
+ *
50
+ * // With custom color and spinner
51
+ * const spinner = useSpinner({
52
+ * text: "Processing...",
53
+ * color: "cyan",
54
+ * spinner: "dots"
55
+ * }).start();
56
+ *
57
+ * // With success/failure states
58
+ * const spinner = useSpinner({
59
+ * text: "Uploading...",
60
+ * successText: "Upload complete!",
61
+ * failText: "Upload failed!"
62
+ * }).start();
63
+ * try {
64
+ * await uploadFile();
65
+ * spinner.succeed();
66
+ * } catch (error) {
67
+ * spinner.fail();
68
+ * }
69
+ *
70
+ * // Using the wrapper for async operations
71
+ * await useSpinner.promise(
72
+ * async (spinner) => {
73
+ * await longOperation();
74
+ * spinner.setProgress({ current: 50, total: 100 });
75
+ * },
76
+ * {
77
+ * text: "Working...",
78
+ * successText: "Done!",
79
+ * failText: "Failed!"
80
+ * }
81
+ * );
82
+ * ```
83
+ */
84
+ export declare function useSpinner(options: SpinnerOptions): SpinnerControls;
85
+ export declare namespace useSpinner {
86
+ var promise: <T>(operation: (spinner: SpinnerControls) => Promise<T>, options: SpinnerOptions) => Promise<T>;
87
+ var nested: (parentOptions: SpinnerOptions) => {
88
+ start: () => {
89
+ child: (childOptions: SpinnerOptions) => SpinnerControls;
90
+ finish: (success: boolean, text?: string) => void;
91
+ dispose: () => void;
92
+ };
93
+ };
94
+ var withTiming: <T>(operation: (spinner: SpinnerControls) => Promise<T>, options: SpinnerOptions) => Promise<{
95
+ result: T;
96
+ duration: number;
97
+ }>;
98
+ }
99
+ export {};
@@ -0,0 +1,206 @@
1
+ import ora from "ora";
2
+ function isInteractive() {
3
+ return process.stdout.isTTY && !process.env.CI && !process.env.GITHUB_ACTIONS && !process.env.GITLAB_CI && !process.env.BUILDKITE && process.env.TERM !== "dumb";
4
+ }
5
+ function formatProgress(options) {
6
+ const { current, total, format = "both" } = options;
7
+ const percentage = Math.round(current / total * 100);
8
+ switch (format) {
9
+ case "percentage":
10
+ return `${percentage}%`;
11
+ case "count":
12
+ return `${current}/${total}`;
13
+ case "both":
14
+ return `${current}/${total} (${percentage}%)`;
15
+ default:
16
+ return `${current}/${total}`;
17
+ }
18
+ }
19
+ export function useSpinner(options) {
20
+ let spinnerInstance = null;
21
+ const interactive = isInteractive();
22
+ const state = {
23
+ isActive: false,
24
+ isPaused: false,
25
+ startTime: null,
26
+ pausedTime: 0,
27
+ text: options.text
28
+ };
29
+ const controls = {
30
+ start: (text) => {
31
+ if (text) {
32
+ options.text = text;
33
+ state.text = text;
34
+ }
35
+ if (options.silent || !interactive) {
36
+ console.log(options.prefixText ? `${options.prefixText} ${options.text}` : options.text);
37
+ state.isActive = true;
38
+ state.startTime = Date.now();
39
+ return controls;
40
+ }
41
+ if (!spinnerInstance) {
42
+ spinnerInstance = ora({
43
+ text: options.text,
44
+ color: options.color,
45
+ spinner: options.spinner,
46
+ hideCursor: options.hideCursor,
47
+ prefixText: options.prefixText
48
+ });
49
+ } else {
50
+ spinnerInstance.text = options.text;
51
+ }
52
+ spinnerInstance.start();
53
+ state.isActive = true;
54
+ state.startTime = Date.now();
55
+ return controls;
56
+ },
57
+ stop: () => {
58
+ if (spinnerInstance) {
59
+ spinnerInstance.stop();
60
+ }
61
+ state.isActive = false;
62
+ },
63
+ setText: (text) => {
64
+ state.text = text;
65
+ if (spinnerInstance && !state.isPaused) {
66
+ spinnerInstance.text = text;
67
+ } else if (options.silent || !interactive) {
68
+ console.log(options.prefixText ? `${options.prefixText} ${text}` : text);
69
+ }
70
+ options.text = text;
71
+ },
72
+ setProgress: (progress) => {
73
+ const progressText = formatProgress(progress);
74
+ const newText = `${state.text} [${progressText}]`;
75
+ if (spinnerInstance && !state.isPaused) {
76
+ spinnerInstance.text = newText;
77
+ } else if (options.silent || !interactive) {
78
+ console.log(options.prefixText ? `${options.prefixText} ${newText}` : newText);
79
+ }
80
+ },
81
+ succeed: (text) => {
82
+ const successText = text ?? options.successText ?? state.text;
83
+ if (spinnerInstance) {
84
+ spinnerInstance.succeed(successText);
85
+ } else {
86
+ console.log(`\u2713 ${successText}`);
87
+ }
88
+ state.isActive = false;
89
+ },
90
+ fail: (text) => {
91
+ const failText = text ?? options.failText ?? state.text;
92
+ if (spinnerInstance) {
93
+ spinnerInstance.fail(failText);
94
+ } else {
95
+ console.error(`\u2717 ${failText}`);
96
+ }
97
+ state.isActive = false;
98
+ },
99
+ warn: (text) => {
100
+ const warnText = text ?? state.text;
101
+ if (spinnerInstance) {
102
+ spinnerInstance.warn(warnText);
103
+ } else {
104
+ console.warn(`\u26A0 ${warnText}`);
105
+ }
106
+ },
107
+ info: (text) => {
108
+ const infoText = text ?? state.text;
109
+ if (spinnerInstance) {
110
+ spinnerInstance.info(infoText);
111
+ } else {
112
+ console.info(`\u2139 ${infoText}`);
113
+ }
114
+ },
115
+ isSpinning: () => {
116
+ return state.isActive && !state.isPaused;
117
+ },
118
+ clear: () => {
119
+ if (spinnerInstance) {
120
+ spinnerInstance.clear();
121
+ }
122
+ },
123
+ getElapsedTime: () => {
124
+ if (!state.startTime) return 0;
125
+ const currentTime = Date.now();
126
+ return currentTime - state.startTime - state.pausedTime;
127
+ },
128
+ pause: () => {
129
+ if (state.isActive && !state.isPaused) {
130
+ if (spinnerInstance) {
131
+ spinnerInstance.stop();
132
+ }
133
+ state.isPaused = true;
134
+ }
135
+ },
136
+ resume: () => {
137
+ if (state.isActive && state.isPaused) {
138
+ if (spinnerInstance) {
139
+ spinnerInstance.start();
140
+ }
141
+ state.isPaused = false;
142
+ }
143
+ },
144
+ dispose: () => {
145
+ if (spinnerInstance) {
146
+ spinnerInstance.stop();
147
+ spinnerInstance = null;
148
+ }
149
+ state.isActive = false;
150
+ state.isPaused = false;
151
+ }
152
+ };
153
+ return controls;
154
+ }
155
+ useSpinner.promise = async (operation, options) => {
156
+ const spinner = useSpinner(options).start();
157
+ try {
158
+ const result = await operation(spinner);
159
+ spinner.succeed();
160
+ return result;
161
+ } catch (error) {
162
+ spinner.fail();
163
+ throw error;
164
+ } finally {
165
+ spinner.dispose();
166
+ }
167
+ };
168
+ useSpinner.nested = (parentOptions) => {
169
+ const parentSpinner = useSpinner({
170
+ ...parentOptions,
171
+ silent: true
172
+ // Parent is silent, children will show progress
173
+ });
174
+ return {
175
+ start: () => {
176
+ parentSpinner.start();
177
+ return {
178
+ child: (childOptions) => useSpinner(childOptions),
179
+ finish: (success, text) => {
180
+ if (success) {
181
+ parentSpinner.succeed(text);
182
+ } else {
183
+ parentSpinner.fail(text);
184
+ }
185
+ },
186
+ dispose: () => parentSpinner.dispose()
187
+ };
188
+ }
189
+ };
190
+ };
191
+ useSpinner.withTiming = async (operation, options) => {
192
+ const spinner = useSpinner(options).start();
193
+ const startTime = Date.now();
194
+ try {
195
+ const result = await operation(spinner);
196
+ const duration = Date.now() - startTime;
197
+ spinner.succeed(`${options.successText || options.text} (${duration}ms)`);
198
+ return { result, duration };
199
+ } catch (error) {
200
+ const duration = Date.now() - startTime;
201
+ spinner.fail(`${options.failText || options.text} (failed after ${duration}ms)`);
202
+ throw error;
203
+ } finally {
204
+ spinner.dispose();
205
+ }
206
+ };