@reliverse/dler 1.2.0

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 (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +312 -0
  3. package/bin/cli/args/agg/main.js +0 -0
  4. package/bin/cli/args/conv/README.md +3 -0
  5. package/bin/cli/args/conv/main.js +0 -0
  6. package/bin/cli/args/deps/analyzer.js +42 -0
  7. package/bin/cli/args/deps/filesystem.js +42 -0
  8. package/bin/cli/args/deps/formatter.js +65 -0
  9. package/bin/cli/args/deps/mod.js +48 -0
  10. package/bin/cli/args/deps/parser.js +59 -0
  11. package/bin/cli/args/deps/types.js +0 -0
  12. package/bin/cli/args/init/README.md +121 -0
  13. package/bin/cli/args/init/libs/reinit/reinit-main.js +5 -0
  14. package/bin/cli/args/init/libs/reinit/reint-impl/const.js +26 -0
  15. package/bin/cli/args/init/libs/reinit/reint-impl/mod.txt +395 -0
  16. package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-gitignore.js +9 -0
  17. package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-license.js +22 -0
  18. package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-readme.js +59 -0
  19. package/bin/cli/args/init/libs/reinit/reint-impl/types.js +0 -0
  20. package/bin/cli/args/init/libs/reinit/reint-impl/utils.js +3 -0
  21. package/bin/cli/args/init/main.txt +121 -0
  22. package/bin/cli/args/init/types.js +1 -0
  23. package/bin/cli/args/inject/README.md +148 -0
  24. package/bin/cli/args/inject/arg-ts-expect-error.txt +49 -0
  25. package/bin/cli/args/inject/cli-mod.js +32 -0
  26. package/bin/cli/args/inject/main.txt +28 -0
  27. package/bin/cli/args/inject/reinject.config.js +4 -0
  28. package/bin/cli/args/inject/ts-expect-error.txt +277 -0
  29. package/bin/cli/args/merger/README.md +125 -0
  30. package/bin/cli/args/merger/main.txt +306 -0
  31. package/bin/cli/args/mono/main.js +0 -0
  32. package/bin/cli/args/spells/mod.js +44 -0
  33. package/bin/cli/args/split/README.md +13 -0
  34. package/bin/cli/args/split/split-main.js +26 -0
  35. package/bin/cli/args/split/split-mod.js +117 -0
  36. package/bin/cli/args/tools/index.js +81 -0
  37. package/bin/cli/args/tools/tools-impl.js +296 -0
  38. package/bin/cli.js +111 -0
  39. package/bin/init.js +157 -0
  40. package/bin/libs/cfg/cfg-default.js +50 -0
  41. package/bin/libs/cfg/cfg-main.js +1 -0
  42. package/bin/libs/cfg/cfg-mod.js +4 -0
  43. package/bin/libs/cfg/cfg-types.js +1 -0
  44. package/bin/libs/sdk/sdk-impl/build/build-library.js +865 -0
  45. package/bin/libs/sdk/sdk-impl/build/build-regular.js +373 -0
  46. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/auto.js +110 -0
  47. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +322 -0
  48. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/copy.js +62 -0
  49. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/types.js +0 -0
  50. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist.js +57 -0
  51. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/types.js +0 -0
  52. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/build.js +104 -0
  53. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/config.js +124 -0
  54. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/cjs.js +48 -0
  55. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/esbuild.js +91 -0
  56. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/json.js +17 -0
  57. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.js +20 -0
  58. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/shebang.js +42 -0
  59. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/stub.js +137 -0
  60. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/types.js +0 -0
  61. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/utils.js +41 -0
  62. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/watch.js +33 -0
  63. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/types.js +6 -0
  64. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/index.js +125 -0
  65. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/types.js +0 -0
  66. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.js +158 -0
  67. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/validate.js +68 -0
  68. package/bin/libs/sdk/sdk-impl/library-flow.js +169 -0
  69. package/bin/libs/sdk/sdk-impl/pub/pub-library.js +132 -0
  70. package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +69 -0
  71. package/bin/libs/sdk/sdk-impl/regular-flow.js +219 -0
  72. package/bin/libs/sdk/sdk-impl/spells/spells-executors.js +307 -0
  73. package/bin/libs/sdk/sdk-impl/spells/spells-filesystem.js +72 -0
  74. package/bin/libs/sdk/sdk-impl/spells/spells-main.js +87 -0
  75. package/bin/libs/sdk/sdk-impl/spells/spells-parser.js +60 -0
  76. package/bin/libs/sdk/sdk-impl/spells/spells-types.js +0 -0
  77. package/bin/libs/sdk/sdk-impl/utils/tools/tools-agg.js +149 -0
  78. package/bin/libs/sdk/sdk-impl/utils/tools/tools-impl.js +21 -0
  79. package/bin/libs/sdk/sdk-impl/utils/utils-build.js +102 -0
  80. package/bin/libs/sdk/sdk-impl/utils/utils-bump.js +238 -0
  81. package/bin/libs/sdk/sdk-impl/utils/utils-clean.js +35 -0
  82. package/bin/libs/sdk/sdk-impl/utils/utils-consts.js +17 -0
  83. package/bin/libs/sdk/sdk-impl/utils/utils-cwd.js +36 -0
  84. package/bin/libs/sdk/sdk-impl/utils/utils-deps.js +73 -0
  85. package/bin/libs/sdk/sdk-impl/utils/utils-determine.js +25 -0
  86. package/bin/libs/sdk/sdk-impl/utils/utils-error.js +17 -0
  87. package/bin/libs/sdk/sdk-impl/utils/utils-fs.js +202 -0
  88. package/bin/libs/sdk/sdk-impl/utils/utils-info.js +42 -0
  89. package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.js +51 -0
  90. package/bin/libs/sdk/sdk-impl/utils/utils-paths.js +658 -0
  91. package/bin/libs/sdk/sdk-impl/utils/utils-perf.js +22 -0
  92. package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.js +259 -0
  93. package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.js +207 -0
  94. package/bin/libs/sdk/sdk-impl/utils/utils-tsconfig.js +44 -0
  95. package/bin/libs/sdk/sdk-main.js +114 -0
  96. package/bin/libs/sdk/sdk-types.js +1 -0
  97. package/bin/load.js +27 -0
  98. package/bin/main.js +46 -0
  99. package/bin/tools.txt +92 -0
  100. package/bin/types.js +0 -0
  101. package/package.json +93 -0
@@ -0,0 +1,60 @@
1
+ const SPELL_REGEX = /<dler-([a-z-]+)-(?:"([^"]+)")?-?(?:{([^}]+)})?>/;
2
+ export const parseParams = (paramsStr) => {
3
+ const defaultParams = {
4
+ hooked: false
5
+ };
6
+ if (!paramsStr) return defaultParams;
7
+ const params = { ...defaultParams };
8
+ for (const param of paramsStr.split(",")) {
9
+ const [key, value] = param.trim().split("=");
10
+ if (key && value !== void 0) {
11
+ if (value === "true") params[key] = true;
12
+ else if (value === "false") params[key] = false;
13
+ else if (!Number.isNaN(Number(value))) params[key] = Number(value);
14
+ else params[key] = value;
15
+ }
16
+ }
17
+ return params;
18
+ };
19
+ export const parseSpellFromComment = (line, lineNumber, fileName) => {
20
+ const match = line.match(SPELL_REGEX);
21
+ if (!match) return null;
22
+ const [fullMatch, spellType, value, paramsStr] = match;
23
+ if (!spellType || !isValidSpellType(spellType)) {
24
+ console.warn(
25
+ `Unknown spell type: ${spellType} in file ${fileName}:${lineNumber}`
26
+ );
27
+ return null;
28
+ }
29
+ return {
30
+ type: spellType,
31
+ params: parseParams(paramsStr),
32
+ value,
33
+ lineNumber,
34
+ fullMatch,
35
+ fileName
36
+ };
37
+ };
38
+ export const extractSpellsFromFile = async (filePath, content) => {
39
+ const lines = content.split("\n");
40
+ const spells = [];
41
+ lines.forEach((line, index) => {
42
+ const spell = parseSpellFromComment(line, index + 1, filePath);
43
+ if (spell) spells.push(spell);
44
+ });
45
+ return spells;
46
+ };
47
+ const isValidSpellType = (type) => {
48
+ const validTypes = [
49
+ "replace-line",
50
+ "rename-file",
51
+ "remove-comment",
52
+ "remove-line",
53
+ "remove-file",
54
+ "transform-content",
55
+ "copy-file",
56
+ "move-file",
57
+ "insert-at"
58
+ ];
59
+ return validTypes.includes(type);
60
+ };
File without changes
@@ -0,0 +1,149 @@
1
+ import fs from "fs-extra";
2
+ import path from "pathe";
3
+ export async function useAggregator({
4
+ inputDir,
5
+ isRecursive,
6
+ outFile,
7
+ stripPrefix,
8
+ useImport,
9
+ useNamed
10
+ }) {
11
+ const st = await fs.stat(inputDir).catch(() => null);
12
+ if (!st?.isDirectory()) {
13
+ console.error(`Error: --input is not a valid directory: ${inputDir}`);
14
+ process.exit(1);
15
+ }
16
+ const exts = [".ts", ".js"];
17
+ const filePaths = await collectFiles(inputDir, exts, isRecursive);
18
+ if (!filePaths.length) {
19
+ console.warn(`No matching .ts/.js files found in ${inputDir}`);
20
+ }
21
+ const allLines = [];
22
+ for (const fp of filePaths) {
23
+ const lines = await generateAggregatorLines(
24
+ fp,
25
+ inputDir,
26
+ stripPrefix,
27
+ useImport,
28
+ useNamed
29
+ );
30
+ allLines.push(...lines);
31
+ }
32
+ if (outFile.startsWith(inputDir)) {
33
+ console.warn(
34
+ `Warning: The output file is inside (or overlaps with) the input directory.
35
+ Might re-import (or re-export) itself.
36
+ input: ${inputDir}
37
+ out: ${outFile}
38
+ `
39
+ );
40
+ }
41
+ const finalText = `${allLines.join("\n")}
42
+ `;
43
+ await fs.ensureFile(outFile);
44
+ await fs.writeFile(outFile, finalText, "utf8");
45
+ console.log(
46
+ `
47
+ Aggregator done: wrote ${allLines.length} lines to:
48
+ ${outFile}`
49
+ );
50
+ }
51
+ function buildPathRelative(filePath, inputDir, stripPrefix) {
52
+ let resolved = path.resolve(filePath);
53
+ const resolvedStrip = stripPrefix ? path.resolve(stripPrefix) : "";
54
+ if (resolvedStrip && resolved.startsWith(resolvedStrip)) {
55
+ resolved = resolved.slice(resolvedStrip.length);
56
+ } else {
57
+ resolved = path.relative(path.resolve(inputDir), resolved);
58
+ }
59
+ while (resolved.startsWith(path.sep)) {
60
+ resolved = resolved.slice(1);
61
+ }
62
+ resolved = resolved.replace(/\\/g, "/");
63
+ if (resolved.toLowerCase().endsWith(".ts")) {
64
+ resolved = `${resolved.slice(0, -3)}.js`;
65
+ }
66
+ if (!resolved.startsWith("./") && !resolved.startsWith("../")) {
67
+ resolved = `./${resolved}`;
68
+ }
69
+ return resolved;
70
+ }
71
+ async function collectFiles(dir, exts, recursive) {
72
+ const found = [];
73
+ const entries = await fs.readdir(dir, { withFileTypes: true });
74
+ for (const entry of entries) {
75
+ const fullPath = path.join(dir, entry.name);
76
+ if (entry.isDirectory()) {
77
+ if (recursive) {
78
+ const sub = await collectFiles(fullPath, exts, recursive);
79
+ found.push(...sub);
80
+ }
81
+ } else if (entry.isFile()) {
82
+ if (exts.some((ext) => entry.name.toLowerCase().endsWith(ext))) {
83
+ found.push(fullPath);
84
+ }
85
+ }
86
+ }
87
+ return found;
88
+ }
89
+ async function generateAggregatorLines(filePath, inputDir, stripPrefix, useImport, useNamed) {
90
+ const importPath = buildPathRelative(filePath, inputDir, stripPrefix);
91
+ if (!useNamed) {
92
+ if (useImport) {
93
+ const ident = guessStarImportIdentifier(filePath);
94
+ return [`import * as ${ident} from "${importPath}";`];
95
+ }
96
+ return [`export * from "${importPath}";`];
97
+ }
98
+ const { typeNames, valueNames } = await getNamedExports(filePath);
99
+ if (!typeNames.length && !valueNames.length) {
100
+ return [];
101
+ }
102
+ if (useImport) {
103
+ const lines2 = [];
104
+ if (typeNames.length > 0) {
105
+ lines2.push(
106
+ `import type { ${typeNames.join(", ")} } from "${importPath}";`
107
+ );
108
+ }
109
+ if (valueNames.length > 0) {
110
+ lines2.push(`import { ${valueNames.join(", ")} } from "${importPath}";`);
111
+ }
112
+ return lines2;
113
+ }
114
+ const lines = [];
115
+ if (typeNames.length > 0) {
116
+ lines.push(`export type { ${typeNames.join(", ")} } from "${importPath}";`);
117
+ }
118
+ if (valueNames.length > 0) {
119
+ lines.push(`export { ${valueNames.join(", ")} } from "${importPath}";`);
120
+ }
121
+ return lines;
122
+ }
123
+ async function getNamedExports(filePath) {
124
+ const code = await fs.readFile(filePath, "utf-8");
125
+ const pattern = /^export\s+(?:async\s+)?(function|const|class|let|type|interface)\s+([A-Za-z0-9_$]+)/gm;
126
+ const typeNames = [];
127
+ const valueNames = [];
128
+ let match = null;
129
+ while (true) {
130
+ match = pattern.exec(code);
131
+ if (match === null) break;
132
+ const keyword = match[1];
133
+ const name = match[2];
134
+ if (keyword === "type" || keyword === "interface") {
135
+ typeNames.push(name);
136
+ } else {
137
+ valueNames.push(name);
138
+ }
139
+ }
140
+ return { typeNames, valueNames };
141
+ }
142
+ function guessStarImportIdentifier(filePath) {
143
+ const base = path.basename(filePath, path.extname(filePath));
144
+ let identifier = base.replace(/[^a-zA-Z0-9_$]/g, "_");
145
+ if (/^\d/.test(identifier)) {
146
+ identifier = `_${identifier}`;
147
+ }
148
+ return identifier || "file";
149
+ }
@@ -0,0 +1,21 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ export function printUsage(isDev) {
3
+ relinka("info", "====================");
4
+ relinka("info", "TOOLS USAGE EXAMPLES");
5
+ relinka("info", "====================");
6
+ relinka(
7
+ "info",
8
+ `${isDev ? "bun dev:agg" : "dler tools"} --tool agg --input <dir> --out <file> [options]`
9
+ );
10
+ if (isDev) {
11
+ relinka(
12
+ "info",
13
+ "bun dev:tools agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-main.ts --recursive --named --strip src/libs/sdk"
14
+ );
15
+ } else {
16
+ relinka(
17
+ "info",
18
+ "dler tools --tool agg --input src/libs --out aggregator.ts --recursive --named"
19
+ );
20
+ }
21
+ }
@@ -0,0 +1,102 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import fs from "fs-extra";
3
+ import path from "pathe";
4
+ export function getBunSourcemapOption(transpileSourcemap) {
5
+ relinka(
6
+ "verbose",
7
+ `Converting Bun sourcemap option from: ${transpileSourcemap}`
8
+ );
9
+ switch (transpileSourcemap) {
10
+ case "inline":
11
+ return "inline";
12
+ case "none":
13
+ case false:
14
+ return "none";
15
+ default:
16
+ return "external";
17
+ }
18
+ }
19
+ export function getUnifiedSourcemapOption(transpileSourcemap) {
20
+ relinka(
21
+ "verbose",
22
+ `Converting Unified/Rollup sourcemap option from: ${transpileSourcemap}`
23
+ );
24
+ switch (transpileSourcemap) {
25
+ case "external":
26
+ case "linked":
27
+ return true;
28
+ // Indicates separate sourcemap file
29
+ case "inline":
30
+ return "inline";
31
+ // Indicates inline sourcemap
32
+ case "none":
33
+ case false:
34
+ return false;
35
+ // No sourcemap
36
+ default:
37
+ return !!transpileSourcemap;
38
+ }
39
+ }
40
+ export async function renameEntryFile(isJsr, outDirBin, originalEntryFileBasename, unifiedBundlerOutExt, distJsrOutFilesExt) {
41
+ relinka(
42
+ "verbose",
43
+ `Attempting to rename entry file. Original basename: ${originalEntryFileBasename}, Output Dir: ${outDirBin}, isJsr=${isJsr}`
44
+ );
45
+ let sourceEntryBasename;
46
+ let targetEntryBasename;
47
+ let sourceDeclarationBasename = null;
48
+ let targetDeclarationBasename = null;
49
+ const outputExt = isJsr ? distJsrOutFilesExt : unifiedBundlerOutExt;
50
+ const originalBasenameNoExt = originalEntryFileBasename.split(".").slice(0, -1).join(".");
51
+ if (isJsr) {
52
+ if (originalEntryFileBasename.endsWith(".ts")) {
53
+ sourceEntryBasename = originalEntryFileBasename;
54
+ targetEntryBasename = "main.ts";
55
+ } else {
56
+ sourceEntryBasename = `${originalBasenameNoExt}.${outputExt}`;
57
+ targetEntryBasename = `main.${outputExt}`;
58
+ }
59
+ } else {
60
+ sourceEntryBasename = `${originalBasenameNoExt}.${outputExt}`;
61
+ targetEntryBasename = `main.${outputExt}`;
62
+ sourceDeclarationBasename = `${originalBasenameNoExt}.d.ts`;
63
+ targetDeclarationBasename = "main.d.ts";
64
+ }
65
+ const sourceEntryPath = path.join(outDirBin, sourceEntryBasename);
66
+ const targetEntryPath = path.join(outDirBin, targetEntryBasename);
67
+ const sourceDeclarationPath = sourceDeclarationBasename ? path.join(outDirBin, sourceDeclarationBasename) : null;
68
+ const targetDeclarationPath = targetDeclarationBasename ? path.join(outDirBin, targetDeclarationBasename) : null;
69
+ if (!await fs.pathExists(sourceEntryPath)) {
70
+ throw new Error(
71
+ `Entry file expected for renaming not found: ${sourceEntryPath}`
72
+ );
73
+ }
74
+ relinka(
75
+ "verbose",
76
+ `Found source entry file: ${sourceEntryPath}. Renaming to: ${targetEntryPath}`
77
+ );
78
+ if (sourceDeclarationPath && targetDeclarationPath) {
79
+ if (await fs.pathExists(sourceDeclarationPath)) {
80
+ relinka(
81
+ "verbose",
82
+ `Renaming declaration ${sourceDeclarationPath} to ${targetDeclarationPath}`
83
+ );
84
+ await fs.rename(sourceDeclarationPath, targetDeclarationPath);
85
+ } else {
86
+ relinka(
87
+ "verbose",
88
+ `Source declaration file not found, skipping rename: ${sourceDeclarationPath}`
89
+ );
90
+ }
91
+ }
92
+ if (sourceEntryPath !== targetEntryPath) {
93
+ await fs.rename(sourceEntryPath, targetEntryPath);
94
+ relinka("info", `Renamed entry file to ${targetEntryPath}`);
95
+ } else {
96
+ relinka(
97
+ "info",
98
+ `Source entry file ${sourceEntryPath} already has the target name. Skipping rename.`
99
+ );
100
+ }
101
+ return { updatedEntryFile: targetEntryBasename };
102
+ }
@@ -0,0 +1,238 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import fs from "fs-extra";
3
+ import pMap from "p-map";
4
+ import path from "pathe";
5
+ import { readPackageJSON } from "pkg-types";
6
+ import semver from "semver";
7
+ import { glob } from "tinyglobby";
8
+ import { CONCURRENCY_DEFAULT, PROJECT_ROOT } from "./utils-consts.js";
9
+ import { readFileSafe, writeFileSafe } from "./utils-fs.js";
10
+ const IGNORE_PATTERNS = [
11
+ "**/node_modules/**",
12
+ "**/.git/**",
13
+ "**/dist/**",
14
+ "**/build/**",
15
+ "**/.next/**",
16
+ "**/coverage/**",
17
+ "**/.cache/**",
18
+ "**/tmp/**",
19
+ "**/.temp/**",
20
+ "**/package-lock.json",
21
+ "**/pnpm-lock.yaml",
22
+ "**/yarn.lock",
23
+ "**/bun.lock"
24
+ ];
25
+ const createJsonVersionRegex = (oldVer) => new RegExp(`"version"\\s*:\\s*"${oldVer}"`, "g");
26
+ const TS_VERSION_REGEXES = [
27
+ (oldVer) => new RegExp(`(export\\s+const\\s+version\\s*=\\s*["'])${oldVer}(["'])`, "g"),
28
+ (oldVer) => new RegExp(`(const\\s+version\\s*=\\s*["'])${oldVer}(["'])`, "g"),
29
+ (oldVer) => new RegExp(`(version\\s*:\\s*["'])${oldVer}(["'])`, "g"),
30
+ (oldVer) => new RegExp(`(VERSION\\s*=\\s*["'])${oldVer}(["'])`, "g"),
31
+ (oldVer) => new RegExp(
32
+ `(export\\s+const\\s+cliVersion\\s*=\\s*["'])${oldVer}(["'])`,
33
+ "g"
34
+ ),
35
+ (oldVer) => new RegExp(`(const\\s+cliVersion\\s*=\\s*["'])${oldVer}(["'])`, "g")
36
+ ];
37
+ export async function bumpHandler(bumpMode, bumpDisable, commonPubPause, bumpFilter) {
38
+ if (bumpDisable || commonPubPause) {
39
+ relinka(
40
+ "info",
41
+ "Skipping version bump because it is either `bumpDisable: true` or `commonPubPause: true` in your dler config."
42
+ );
43
+ return;
44
+ }
45
+ const pkgPath = path.resolve("package.json");
46
+ if (!await fs.pathExists(pkgPath)) {
47
+ throw new Error("package.json not found");
48
+ }
49
+ const pkgJson = await readPackageJSON();
50
+ if (!pkgJson.version) {
51
+ throw new Error("No version field found in package.json");
52
+ }
53
+ const oldVersion = pkgJson.version;
54
+ if (!semver.valid(oldVersion)) {
55
+ throw new Error(`Invalid existing version in package.json: ${oldVersion}`);
56
+ }
57
+ relinka(
58
+ "info",
59
+ `Auto-incrementing version from ${oldVersion} using "${bumpMode}"`
60
+ );
61
+ const incremented = autoIncrementVersion(oldVersion, bumpMode);
62
+ if (oldVersion !== incremented) {
63
+ await bumpVersions(oldVersion, incremented, bumpFilter);
64
+ await setBumpDisabled(true, commonPubPause);
65
+ } else {
66
+ relinka("info", `Version is already at ${oldVersion}, no bump needed.`);
67
+ }
68
+ }
69
+ export async function setBumpDisabled(value, commonPubPause) {
70
+ if (commonPubPause && value) {
71
+ return;
72
+ }
73
+ const dlerCfgPath = path.join(PROJECT_ROOT, ".config/dler.ts");
74
+ if (!await fs.pathExists(dlerCfgPath)) {
75
+ relinka("info", "No .config/dler.ts found to update bumpDisable");
76
+ return;
77
+ }
78
+ let content = await readFileSafe(dlerCfgPath, "", "bumpDisable update");
79
+ content = content.replace(
80
+ /bumpDisable\s*:\s*(true|false)/,
81
+ `bumpDisable: ${value}`
82
+ );
83
+ await writeFileSafe(dlerCfgPath, content, "bumpDisable update");
84
+ }
85
+ function autoIncrementVersion(oldVersion, bumpMode) {
86
+ if (!semver.valid(oldVersion)) {
87
+ throw new Error(`Can't auto-increment invalid version: ${oldVersion}`);
88
+ }
89
+ const releaseTypeMap = {
90
+ autoMajor: "major",
91
+ autoMinor: "minor",
92
+ autoPatch: "patch"
93
+ };
94
+ const newVer = semver.inc(oldVersion, releaseTypeMap[bumpMode]);
95
+ if (!newVer) {
96
+ throw new Error(`semver.inc failed for ${oldVersion} and mode ${bumpMode}`);
97
+ }
98
+ return newVer;
99
+ }
100
+ async function bumpVersions(oldVersion, newVersion, bumpFilter = [
101
+ "package.json",
102
+ ".config/rse.jsonc",
103
+ ".config/rse.ts"
104
+ ]) {
105
+ relinka(
106
+ "verbose",
107
+ `Starting bumpVersions from ${oldVersion} to ${newVersion}`
108
+ );
109
+ try {
110
+ const filePatterns = [];
111
+ if (bumpFilter.length > 0) {
112
+ for (const filter of bumpFilter) {
113
+ if (filter.includes("/") || filter.includes("\\")) {
114
+ filePatterns.push(`**/${filter}`);
115
+ continue;
116
+ }
117
+ if (filter.includes(".")) {
118
+ filePatterns.push(`**/${filter}`);
119
+ continue;
120
+ }
121
+ filePatterns.push(`**/${filter}.*`);
122
+ }
123
+ relinka(
124
+ "verbose",
125
+ `Generated patterns from filters: ${filePatterns.join(", ")}`
126
+ );
127
+ } else {
128
+ filePatterns.push("**/package.json");
129
+ relinka(
130
+ "verbose",
131
+ "No filters provided, falling back to only process package.json"
132
+ );
133
+ }
134
+ const ignorePatterns = [
135
+ "**/node_modules/**",
136
+ "**/.git/**",
137
+ ...IGNORE_PATTERNS
138
+ ];
139
+ try {
140
+ const gitignorePath = path.join(PROJECT_ROOT, ".gitignore");
141
+ if (await fs.pathExists(gitignorePath)) {
142
+ const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
143
+ const gitignorePatterns = gitignoreContent.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#")).map((pattern) => {
144
+ if (pattern.startsWith("/")) {
145
+ return pattern.substring(1);
146
+ }
147
+ if (pattern.endsWith("/")) {
148
+ return `**/${pattern}**`;
149
+ }
150
+ return `**/${pattern}`;
151
+ });
152
+ if (gitignorePatterns.length > 0) {
153
+ relinka(
154
+ "verbose",
155
+ `Bump will not process ${gitignorePatterns.length} patterns listed in .gitignore`
156
+ );
157
+ ignorePatterns.push(...gitignorePatterns);
158
+ }
159
+ }
160
+ } catch (err) {
161
+ relinka("verbose", `Could not process .gitignore: ${err}`);
162
+ }
163
+ const matchedFiles = await glob(filePatterns, {
164
+ absolute: true,
165
+ cwd: PROJECT_ROOT,
166
+ dot: false,
167
+ // Skip hidden files
168
+ ignore: ignorePatterns
169
+ });
170
+ relinka(
171
+ "verbose",
172
+ `Found ${matchedFiles.length} files to check for version bumping`
173
+ );
174
+ let modifiedCount = 0;
175
+ await pMap(
176
+ matchedFiles,
177
+ async (file) => {
178
+ try {
179
+ if (!await fs.pathExists(file)) {
180
+ relinka("verbose", `File does not exist (skipped): ${file}`);
181
+ return;
182
+ }
183
+ const content = await readFileSafe(file, "", "bumpVersions");
184
+ const modified = await updateVersionInContent(
185
+ file,
186
+ content,
187
+ oldVersion,
188
+ newVersion
189
+ );
190
+ if (modified) {
191
+ modifiedCount++;
192
+ relinka("verbose", `Updated version in: ${file}`);
193
+ }
194
+ } catch (err) {
195
+ relinka("error", `Error processing file ${file}: ${err}`);
196
+ }
197
+ },
198
+ { concurrency: CONCURRENCY_DEFAULT }
199
+ );
200
+ if (modifiedCount > 0) {
201
+ relinka(
202
+ "success",
203
+ `Updated version from ${oldVersion} to ${newVersion} in ${modifiedCount} file(s)`
204
+ );
205
+ } else {
206
+ relinka("warn", "No files were updated with the new version");
207
+ }
208
+ } catch (error) {
209
+ relinka("error", "Failed to bump versions:", error);
210
+ throw error;
211
+ }
212
+ relinka("verbose", "Exiting bumpVersions");
213
+ }
214
+ async function updateVersionInContent(filePath, content, oldVersion, newVersion) {
215
+ let updatedContent = content;
216
+ let changed = false;
217
+ if (/\.(json|jsonc|json5)$/.test(filePath)) {
218
+ if (content.includes(`"version": "${oldVersion}"`)) {
219
+ updatedContent = content.replace(
220
+ createJsonVersionRegex(oldVersion),
221
+ `"version": "${newVersion}"`
222
+ );
223
+ changed = true;
224
+ }
225
+ } else if (filePath.endsWith(".ts")) {
226
+ for (const regexFactory of TS_VERSION_REGEXES) {
227
+ const regex = regexFactory(oldVersion);
228
+ if (regex.test(updatedContent)) {
229
+ updatedContent = updatedContent.replace(regex, `$1${newVersion}$2`);
230
+ changed = true;
231
+ }
232
+ }
233
+ }
234
+ if (changed) {
235
+ await writeFileSafe(filePath, updatedContent, "version update");
236
+ }
237
+ return changed;
238
+ }
@@ -0,0 +1,35 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import fs from "fs-extra";
3
+ import pMap from "p-map";
4
+ import path from "pathe";
5
+ import { CONCURRENCY_DEFAULT, PROJECT_ROOT } from "./utils-consts.js";
6
+ export async function removeDistFolders(distNpmDirName, distJsrDirName, libsDirDist, libsList) {
7
+ const foldersToRemove = [];
8
+ foldersToRemove.push(distNpmDirName);
9
+ foldersToRemove.push(distJsrDirName);
10
+ if (libsList && Object.keys(libsList).length > 0) {
11
+ foldersToRemove.push(libsDirDist);
12
+ }
13
+ const existingFolders = [];
14
+ for (const folder of foldersToRemove) {
15
+ const folderPath = path.resolve(PROJECT_ROOT, folder);
16
+ if (await fs.pathExists(folderPath)) {
17
+ existingFolders.push(folder);
18
+ }
19
+ }
20
+ if (existingFolders.length > 0) {
21
+ await pMap(
22
+ existingFolders,
23
+ async (folder) => {
24
+ const folderPath = path.resolve(PROJECT_ROOT, folder);
25
+ if (await fs.pathExists(folderPath)) {
26
+ await fs.remove(folderPath);
27
+ relinka("verbose", `Removed: ${folderPath}`);
28
+ }
29
+ },
30
+ { concurrency: CONCURRENCY_DEFAULT }
31
+ );
32
+ relinka("success", "Distribution folders removed successfully");
33
+ }
34
+ return true;
35
+ }
@@ -0,0 +1,17 @@
1
+ import path from "pathe";
2
+ export const PROJECT_ROOT = path.resolve(process.cwd());
3
+ export const CONCURRENCY_DEFAULT = 1;
4
+ export const tsconfigJson = "tsconfig.json";
5
+ export const cliDomainDocs = "https://docs.reliverse.org";
6
+ export const validExtensions = [
7
+ "cjs",
8
+ "js",
9
+ "mjs",
10
+ "ts",
11
+ "mts",
12
+ "cts"
13
+ ];
14
+ export const SHOW_VERBOSE = {
15
+ getDirectorySize: false,
16
+ readFileSafe: false
17
+ };
@@ -0,0 +1,36 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ export async function validateDevCwd(isDev, paths, cliName, cliOrg = "") {
3
+ if (!isDev) return;
4
+ const projectName = cliOrg ? `@${cliOrg}/${cliName}` : cliName;
5
+ const currentDir = process.cwd();
6
+ if (!paths.some((path) => currentDir.includes(path))) {
7
+ const pathsList = paths.map((p) => `'${p}'`).join(", ");
8
+ throw new Error(
9
+ [
10
+ `\u2502 The '--dev' flag is reserved exclusively for ${projectName} developers`,
11
+ `\u2502 Your current directory must include one of the following paths: ${pathsList}`,
12
+ `\u2502 Also please make sure to use 'bun dev' instead of '${cliName} --dev'`,
13
+ `\u2502 Current working directory: ${currentDir}`
14
+ ].join("\n")
15
+ );
16
+ }
17
+ }
18
+ export async function withWorkingDirectory(transpileTargetDir, fn) {
19
+ relinka(
20
+ "verbose",
21
+ `Entering withWorkingDirectory, transpileTargetDir: ${transpileTargetDir}`
22
+ );
23
+ const originalDir = process.cwd();
24
+ try {
25
+ process.chdir(transpileTargetDir);
26
+ relinka("verbose", `Changed working directory to: ${transpileTargetDir}`);
27
+ const result = await fn();
28
+ return result;
29
+ } catch (error) {
30
+ relinka("error", `Error in directory ${transpileTargetDir}:`, error);
31
+ throw error;
32
+ } finally {
33
+ process.chdir(originalDir);
34
+ relinka("verbose", `Restored working directory to: ${originalDir}`);
35
+ }
36
+ }