@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,158 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { createJiti } from "jiti";
3
+ import { readdirSync, statSync } from "node:fs";
4
+ import fsp from "node:fs/promises";
5
+ import { dirname, resolve } from "pathe";
6
+ import { autoPreset } from "./auto.js";
7
+ export function arrayIncludes(arr, searchElement) {
8
+ return arr.some(
9
+ (entry) => entry instanceof RegExp ? entry.test(searchElement) : entry === searchElement
10
+ );
11
+ }
12
+ export function dumpObject(obj) {
13
+ return `{ ${Object.keys(obj).map((key) => `${key}: ${JSON.stringify(obj[key])}`).join(", ")} }`;
14
+ }
15
+ export async function ensuredir(path) {
16
+ await fsp.mkdir(dirname(path), { recursive: true });
17
+ }
18
+ export function extractExportFilenames(exports, conditions = []) {
19
+ if (!exports) {
20
+ return [];
21
+ }
22
+ if (typeof exports === "string") {
23
+ return [{ file: exports, type: "esm" }];
24
+ }
25
+ return Object.entries(exports).filter(([subpath]) => !subpath.endsWith(".json")).flatMap(
26
+ ([condition, exports2]) => typeof exports2 === "string" ? {
27
+ file: exports2,
28
+ type: inferExportType(condition, conditions, exports2)
29
+ } : extractExportFilenames(exports2, [...conditions, condition])
30
+ );
31
+ }
32
+ export function getpkg(id = "") {
33
+ const s = id.split("/");
34
+ return s[0]?.startsWith("@") ? `${s[0]}/${s[1] || ""}` : s[0] || "";
35
+ }
36
+ export function inferPkgExternals(pkg) {
37
+ const externals = [
38
+ ...Object.keys(pkg.dependencies || {}),
39
+ ...Object.keys(pkg.peerDependencies || {}),
40
+ ...Object.keys(pkg.devDependencies || {}).filter(
41
+ (dep) => dep.startsWith("@types/")
42
+ ),
43
+ ...Object.keys(pkg.optionalDependencies || {})
44
+ ];
45
+ if (pkg.name) {
46
+ externals.push(pkg.name);
47
+ if (pkg.exports) {
48
+ for (const subpath of Object.keys(pkg.exports)) {
49
+ if (subpath.startsWith("./")) {
50
+ externals.push(pathToRegex(`${pkg.name}/${subpath.slice(2)}`));
51
+ }
52
+ }
53
+ }
54
+ }
55
+ if (pkg.imports) {
56
+ for (const importName of Object.keys(pkg.imports)) {
57
+ if (importName.startsWith("#")) {
58
+ externals.push(pathToRegex(importName));
59
+ }
60
+ }
61
+ }
62
+ return [...new Set(externals)];
63
+ }
64
+ export function listRecursively(path) {
65
+ const filenames = /* @__PURE__ */ new Set();
66
+ const walk = (path2) => {
67
+ const files = readdirSync(path2);
68
+ for (const file of files) {
69
+ const fullPath = resolve(path2, file);
70
+ if (statSync(fullPath).isDirectory()) {
71
+ filenames.add(`${fullPath}/`);
72
+ walk(fullPath);
73
+ } else {
74
+ filenames.add(fullPath);
75
+ }
76
+ }
77
+ };
78
+ walk(path);
79
+ return [...filenames];
80
+ }
81
+ export function removeExtension(filename) {
82
+ return filename.replace(/\.(js|mjs|cjs|ts|mts|cts|json|jsx|tsx)$/, "");
83
+ }
84
+ export async function resolvePreset(preset, rootDir) {
85
+ let resolvedPreset = preset;
86
+ if (preset === "auto") {
87
+ resolvedPreset = autoPreset;
88
+ } else if (typeof preset === "string") {
89
+ resolvedPreset = await createJiti(rootDir, { interopDefault: true }).import(preset, {
90
+ default: true
91
+ }) || {};
92
+ }
93
+ if (typeof resolvedPreset === "function") {
94
+ resolvedPreset = resolvedPreset();
95
+ }
96
+ return resolvedPreset;
97
+ }
98
+ export async function rmdir(dir) {
99
+ await fsp.unlink(dir).catch(() => {
100
+ });
101
+ await fsp.rm(dir, { force: true, recursive: true }).catch(() => {
102
+ });
103
+ }
104
+ export async function symlink(from, to, force = true) {
105
+ await ensuredir(to);
106
+ if (force) {
107
+ await fsp.unlink(to).catch(() => {
108
+ });
109
+ }
110
+ await fsp.symlink(from, to, "junction");
111
+ }
112
+ export function warn(ctx, message) {
113
+ if (ctx.warnings.has(message)) {
114
+ return;
115
+ }
116
+ relinka("verbose", "[dler] [warn]", message);
117
+ ctx.warnings.add(message);
118
+ }
119
+ export function withTrailingSlash(path) {
120
+ return path.endsWith("/") ? path : `${path}/`;
121
+ }
122
+ function inferExportType(condition, previousConditions = [], filename = "") {
123
+ if (filename) {
124
+ if (filename.endsWith(".d.ts")) {
125
+ return "esm";
126
+ }
127
+ if (filename.endsWith(".mjs")) {
128
+ return "esm";
129
+ }
130
+ if (filename.endsWith(".cjs")) {
131
+ return "cjs";
132
+ }
133
+ }
134
+ switch (condition) {
135
+ case "import": {
136
+ return "esm";
137
+ }
138
+ case "require": {
139
+ return "cjs";
140
+ }
141
+ default: {
142
+ if (previousConditions.length === 0) {
143
+ return "esm";
144
+ }
145
+ const [newCondition] = previousConditions;
146
+ return inferExportType(
147
+ newCondition || "import",
148
+ previousConditions.slice(1),
149
+ filename
150
+ );
151
+ }
152
+ }
153
+ }
154
+ function pathToRegex(path) {
155
+ return path.includes("*") ? new RegExp(
156
+ `^${path.replace(/\./g, String.raw`\.`).replace(/\*/g, ".*")}$`
157
+ ) : path;
158
+ }
@@ -0,0 +1,68 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "pathe";
3
+ import {
4
+ arrayIncludes,
5
+ extractExportFilenames,
6
+ getpkg,
7
+ warn
8
+ } from "./utils.js";
9
+ export function validateDependencies(ctx) {
10
+ const usedDependencies = /* @__PURE__ */ new Set();
11
+ const unusedDependencies = new Set(
12
+ Object.keys(ctx.pkg.dependencies || {})
13
+ );
14
+ const implicitDependencies = /* @__PURE__ */ new Set();
15
+ for (const id of ctx.usedImports) {
16
+ unusedDependencies.delete(id);
17
+ usedDependencies.add(id);
18
+ }
19
+ if (Array.isArray(ctx.options.dependencies)) {
20
+ for (const id of ctx.options.dependencies) {
21
+ unusedDependencies.delete(id);
22
+ }
23
+ }
24
+ for (const id of usedDependencies) {
25
+ if (!arrayIncludes(ctx.options.externals, id) && !id.startsWith("chunks/") && !ctx.options.dependencies.includes(getpkg(id)) && !ctx.options.peerDependencies.includes(getpkg(id))) {
26
+ implicitDependencies.add(id);
27
+ }
28
+ }
29
+ if (unusedDependencies.size > 0) {
30
+ warn(
31
+ ctx,
32
+ `Potential unused dependencies found: ${[...unusedDependencies].join(", ")}`
33
+ );
34
+ }
35
+ if (implicitDependencies.size > 0 && !ctx.options.rollup.inlineDependencies) {
36
+ warn(
37
+ ctx,
38
+ `Potential implicit dependencies found: ${[...implicitDependencies].join(", ")}`
39
+ );
40
+ }
41
+ }
42
+ export function validatePackage(pkg, rootDir, ctx) {
43
+ if (!pkg) {
44
+ return;
45
+ }
46
+ const filenames = new Set(
47
+ [
48
+ ...typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin || {}),
49
+ pkg.main,
50
+ pkg.module,
51
+ pkg.types,
52
+ pkg.typings,
53
+ ...extractExportFilenames(pkg.exports).map((i) => i.file)
54
+ ].map((i) => i && resolve(rootDir, i.replace(/\/[^/]*\*.*$/, "")))
55
+ );
56
+ const missingOutputs = [];
57
+ for (const filename of filenames) {
58
+ if (filename && !filename.includes("*") && !existsSync(filename)) {
59
+ missingOutputs.push(filename.replace(`${rootDir}/`, ""));
60
+ }
61
+ }
62
+ if (missingOutputs.length > 0) {
63
+ warn(
64
+ ctx,
65
+ `Potential missing package.json files: ${missingOutputs.join(", ")}`
66
+ );
67
+ }
68
+ }
@@ -0,0 +1,169 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import pAll from "p-all";
3
+ import path from "pathe";
4
+ import { library_buildLibrary } from "./build/build-library.js";
5
+ import { library_publishLibrary } from "./pub/pub-library.js";
6
+ import { CONCURRENCY_DEFAULT, PROJECT_ROOT } from "./utils/utils-consts.js";
7
+ export async function processLibraryFlow(timer, isDev, libsActMode, libsList, distJsrDryRun, distJsrFailOnWarn, libsDirDist, libsDirSrc, commonPubPause, commonPubRegistry, unifiedBundlerOutExt, distNpmBuilder, coreEntrySrcDir, rmDepsMode, rmDepsPatterns, transpileEsbuild, transpileTarget, transpileFormat, transpileSplitting, transpileSourcemap, transpilePublicPath, distJsrBuilder, transpileStub, transpileWatch, distJsrOutFilesExt) {
8
+ if (libsActMode !== "libs-only" && libsActMode !== "main-and-libs") {
9
+ relinka(
10
+ "verbose",
11
+ "Skipping libs build/publish as libsActMode is set to 'main-project-only'"
12
+ );
13
+ return;
14
+ }
15
+ await libraries_buildPublish(
16
+ isDev,
17
+ timer,
18
+ libsList,
19
+ distJsrDryRun,
20
+ distJsrFailOnWarn,
21
+ libsDirDist,
22
+ libsDirSrc,
23
+ commonPubPause,
24
+ commonPubRegistry,
25
+ unifiedBundlerOutExt,
26
+ distNpmBuilder,
27
+ coreEntrySrcDir,
28
+ rmDepsMode,
29
+ rmDepsPatterns,
30
+ transpileEsbuild,
31
+ transpileTarget,
32
+ transpileFormat,
33
+ transpileSplitting,
34
+ transpileSourcemap,
35
+ transpilePublicPath,
36
+ distJsrBuilder,
37
+ transpileStub,
38
+ transpileWatch,
39
+ distJsrOutFilesExt
40
+ );
41
+ }
42
+ function extractFolderName(libName, libConfig) {
43
+ if (libConfig?.libDirName) {
44
+ return libConfig.libDirName;
45
+ }
46
+ const parts = libName.split("/");
47
+ let baseName = parts[parts.length - 1];
48
+ if (baseName?.includes("-")) {
49
+ const dashParts = baseName.split("-");
50
+ baseName = dashParts[dashParts.length - 1];
51
+ }
52
+ if (!baseName) {
53
+ baseName = libName;
54
+ }
55
+ return baseName;
56
+ }
57
+ export async function libraries_buildPublish(isDev, timer, libsList, distJsrDryRun, distJsrFailOnWarn, libsDirDist, libsDirSrc, commonPubPause, commonPubRegistry, unifiedBundlerOutExt, distNpmBuilder, coreEntrySrcDir, rmDepsMode, rmDepsPatterns, transpileEsbuild, transpileTarget, transpileFormat, transpileSplitting, transpileSourcemap, transpilePublicPath, distJsrBuilder, transpileStub, transpileWatch, distJsrOutFilesExt) {
58
+ relinka("verbose", "Starting libraries_buildPublish");
59
+ if (!libsList || Object.keys(libsList).length === 0) {
60
+ relinka("info", "No lib configs found in config, skipping libs build.");
61
+ return;
62
+ }
63
+ const libsEntries = Object.entries(libsList);
64
+ const tasks = libsEntries.map(([libName, libConfig]) => {
65
+ return async () => {
66
+ try {
67
+ if (!libConfig.libMainFile) {
68
+ throw new Error(
69
+ `Library ${libName} is missing "libMainFile" property.`
70
+ );
71
+ }
72
+ const folderName = extractFolderName(libName, libConfig);
73
+ const libBaseDir = path.resolve(PROJECT_ROOT, libsDirDist, folderName);
74
+ const npmOutDir = path.join(libBaseDir, "npm");
75
+ const jsrOutDir = path.join(libBaseDir, "jsr");
76
+ const libMainPath = path.parse(libConfig.libMainFile);
77
+ const libMainFile = libMainPath.base;
78
+ let libMainDir;
79
+ if (libConfig.libMainFile.startsWith(libsDirSrc)) {
80
+ libMainDir = libMainPath.dir || ".";
81
+ } else if (libMainPath.dir) {
82
+ libMainDir = path.join(libsDirSrc, libMainPath.dir);
83
+ } else {
84
+ libMainDir = path.join(libsDirSrc, folderName);
85
+ }
86
+ relinka(
87
+ "verbose",
88
+ `Processing library ${libName}: libMainDir=${libMainDir}, libMainFile=${libMainFile}`
89
+ );
90
+ const libTranspileMinify = libConfig?.libTranspileMinify === true;
91
+ await library_buildLibrary({
92
+ commonPubRegistry,
93
+ libName,
94
+ mainDir: libMainDir,
95
+ npm: {
96
+ npmOutDir,
97
+ distNpmBuilder,
98
+ coreEntrySrcDir
99
+ },
100
+ jsr: {
101
+ jsrOutDir,
102
+ distJsrBuilder,
103
+ distJsrOutFilesExt
104
+ },
105
+ libMainFile,
106
+ isDev,
107
+ libsList,
108
+ unifiedBundlerOutExt,
109
+ rmDepsMode,
110
+ rmDepsPatterns,
111
+ transpileEsbuild,
112
+ transpileTarget,
113
+ transpileFormat,
114
+ transpileSplitting,
115
+ libTranspileMinify,
116
+ transpileSourcemap,
117
+ transpilePublicPath,
118
+ timer,
119
+ transpileStub,
120
+ transpileWatch
121
+ });
122
+ if (!commonPubPause) {
123
+ await library_publishLibrary(
124
+ commonPubRegistry,
125
+ libName,
126
+ npmOutDir,
127
+ jsrOutDir,
128
+ distJsrDryRun,
129
+ distJsrFailOnWarn,
130
+ false,
131
+ false,
132
+ isDev,
133
+ timer
134
+ );
135
+ }
136
+ } catch (error) {
137
+ relinka(
138
+ "error",
139
+ `Failed to process library ${libName}: ${error instanceof Error ? error.message : String(error)}`
140
+ );
141
+ if (isDev && error instanceof Error) {
142
+ relinka("verbose", `Error details: ${error.stack}`);
143
+ }
144
+ throw error;
145
+ }
146
+ };
147
+ });
148
+ try {
149
+ await pAll(tasks, {
150
+ concurrency: CONCURRENCY_DEFAULT
151
+ });
152
+ relinka("verbose", "Completed libraries_buildPublish");
153
+ } catch (error) {
154
+ if (error instanceof AggregateError) {
155
+ for (const individualError of error.errors) {
156
+ relinka(
157
+ "error",
158
+ `AggregateError: ${individualError instanceof Error ? individualError.message : String(individualError)}`
159
+ );
160
+ }
161
+ } else {
162
+ relinka(
163
+ "error",
164
+ `Unhandled error in libraries_buildPublish: ${error instanceof Error ? error.message : String(error)}`
165
+ );
166
+ }
167
+ throw error;
168
+ }
169
+ }
@@ -0,0 +1,132 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { execaCommand } from "execa";
3
+ import pAll from "p-all";
4
+ import { CONCURRENCY_DEFAULT } from "../utils/utils-consts.js";
5
+ import { withWorkingDirectory } from "../utils/utils-cwd.js";
6
+ import {
7
+ pausePerfTimer,
8
+ resumePerfTimer
9
+ } from "../utils/utils-perf.js";
10
+ export async function library_publishLibrary(commonPubRegistry, libName, npmOutDir, jsrOutDir, distJsrDryRun, distJsrFailOnWarn, distJsrAllowDirty, distJsrSlowTypes, isDev, timer) {
11
+ if (isDev) {
12
+ relinka(
13
+ "info",
14
+ `Skipping publishing for lib ${libName} in development mode`
15
+ );
16
+ return;
17
+ }
18
+ switch (commonPubRegistry) {
19
+ case "jsr":
20
+ relinka("info", `Publishing lib ${libName} to JSR only...`);
21
+ await library_pubToJsr(
22
+ jsrOutDir,
23
+ distJsrDryRun,
24
+ distJsrFailOnWarn,
25
+ distJsrAllowDirty,
26
+ distJsrSlowTypes,
27
+ libName,
28
+ isDev,
29
+ timer
30
+ );
31
+ break;
32
+ case "npm":
33
+ relinka("info", `Publishing lib ${libName} to NPM only...`);
34
+ await library_pubToNpm(
35
+ npmOutDir,
36
+ distJsrDryRun,
37
+ distJsrFailOnWarn,
38
+ libName,
39
+ isDev,
40
+ timer
41
+ );
42
+ break;
43
+ case "npm-jsr": {
44
+ relinka("info", `Publishing lib ${libName} to both NPM and JSR...`);
45
+ const publishTasks = [
46
+ () => library_pubToNpm(
47
+ npmOutDir,
48
+ distJsrDryRun,
49
+ distJsrFailOnWarn,
50
+ libName,
51
+ isDev,
52
+ timer
53
+ ),
54
+ () => library_pubToJsr(
55
+ jsrOutDir,
56
+ distJsrDryRun,
57
+ distJsrFailOnWarn,
58
+ distJsrAllowDirty,
59
+ distJsrSlowTypes,
60
+ libName,
61
+ isDev,
62
+ timer
63
+ )
64
+ ];
65
+ await pAll(publishTasks, { concurrency: CONCURRENCY_DEFAULT });
66
+ break;
67
+ }
68
+ default:
69
+ relinka(
70
+ "info",
71
+ `Registry "${commonPubRegistry}" not recognized for lib ${libName}. Skipping publishing for this lib.`
72
+ );
73
+ }
74
+ }
75
+ async function library_pubToJsr(libOutDir, distJsrDryRun, distJsrFailOnWarn, distJsrAllowDirty, distJsrSlowTypes, libName, isDev, timer) {
76
+ relinka("verbose", `Starting library_pubToJsr for lib: ${libName}`);
77
+ if (isDev) {
78
+ relinka("info", `Skipping lib ${libName} JSR publish in development mode`);
79
+ return;
80
+ }
81
+ try {
82
+ if (timer) pausePerfTimer(timer);
83
+ await withWorkingDirectory(libOutDir, async () => {
84
+ relinka("info", `Publishing lib ${libName} to JSR from ${libOutDir}`);
85
+ const command = [
86
+ "bun x jsr publish",
87
+ distJsrDryRun ? "--dry-run" : "",
88
+ distJsrFailOnWarn ? "--fail-on-warn" : "",
89
+ distJsrAllowDirty ? "--allow-dirty" : "",
90
+ distJsrSlowTypes ? "--allow-slow-types" : ""
91
+ ].filter(Boolean).join(" ");
92
+ await execaCommand(command, { stdio: "inherit" });
93
+ relinka(
94
+ "success",
95
+ `Successfully ${distJsrDryRun ? "validated" : "published"} lib ${libName} to JSR registry`
96
+ );
97
+ });
98
+ if (timer) resumePerfTimer(timer);
99
+ } catch (error) {
100
+ if (timer) resumePerfTimer(timer);
101
+ relinka("error", `Failed to publish lib ${libName} to JSR`, error);
102
+ throw error;
103
+ } finally {
104
+ relinka("verbose", `Exiting library_pubToJsr for lib: ${libName}`);
105
+ }
106
+ }
107
+ async function library_pubToNpm(libOutDir, distJsrDryRun, distJsrFailOnWarn, libName, isDev, timer) {
108
+ relinka("verbose", `Starting library_pubToNpm for lib: ${libName}`);
109
+ if (isDev) {
110
+ relinka("info", `Skipping lib ${libName} NPM publish in development mode`);
111
+ return;
112
+ }
113
+ try {
114
+ if (timer) pausePerfTimer(timer);
115
+ await withWorkingDirectory(libOutDir, async () => {
116
+ relinka("info", `Publishing lib ${libName} to NPM from ${libOutDir}`);
117
+ const command = ["bun publish", distJsrDryRun ? "--dry-run" : ""].filter(Boolean).join(" ");
118
+ await execaCommand(command, { stdio: "inherit" });
119
+ relinka(
120
+ "success",
121
+ `Successfully ${distJsrDryRun ? "validated" : "published"} lib ${libName} to NPM registry`
122
+ );
123
+ });
124
+ if (timer) resumePerfTimer(timer);
125
+ } catch (error) {
126
+ if (timer) resumePerfTimer(timer);
127
+ relinka("error", `Failed to publish lib ${libName} to NPM`, error);
128
+ throw error;
129
+ } finally {
130
+ relinka("verbose", `Exiting library_pubToNpm for lib: ${libName}`);
131
+ }
132
+ }
@@ -0,0 +1,69 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { execaCommand } from "execa";
3
+ import path from "pathe";
4
+ import { PROJECT_ROOT } from "../utils/utils-consts.js";
5
+ import { withWorkingDirectory } from "../utils/utils-cwd.js";
6
+ import {
7
+ pausePerfTimer,
8
+ resumePerfTimer
9
+ } from "../utils/utils-perf.js";
10
+ export async function regular_pubToJsr(distJsrDryRun, distJsrFailOnWarn, isDev, commonPubPause, distJsrDirName, distJsrAllowDirty, distJsrSlowTypes, timer) {
11
+ try {
12
+ if (isDev) {
13
+ relinka("info", "Skipping JSR publish in development mode");
14
+ return;
15
+ }
16
+ if (!commonPubPause) {
17
+ relinka("info", "Publishing to JSR...");
18
+ const distJsrDirNameResolved = path.resolve(PROJECT_ROOT, distJsrDirName);
19
+ if (timer) pausePerfTimer(timer);
20
+ await withWorkingDirectory(distJsrDirNameResolved, async () => {
21
+ const command = [
22
+ "bun x jsr publish",
23
+ distJsrDryRun ? "--dry-run" : "",
24
+ distJsrFailOnWarn ? "--fail-on-warn" : "",
25
+ distJsrAllowDirty ? "--allow-dirty" : "",
26
+ distJsrSlowTypes ? "--allow-slow-types" : ""
27
+ ].filter(Boolean).join(" ");
28
+ relinka("verbose", `Running publish command: ${command}`);
29
+ await execaCommand(command, { stdio: "inherit" });
30
+ relinka(
31
+ "success",
32
+ `Successfully ${distJsrDryRun ? "validated" : "published"} to JSR registry`
33
+ );
34
+ });
35
+ if (timer) resumePerfTimer(timer);
36
+ }
37
+ } catch (error) {
38
+ if (timer) resumePerfTimer(timer);
39
+ relinka("error", "Failed to publish to JSR:", error);
40
+ throw error;
41
+ }
42
+ }
43
+ export async function regular_pubToNpm(distJsrDryRun, isDev, commonPubPause, distNpmDirName, timer) {
44
+ try {
45
+ if (isDev) {
46
+ relinka("info", "Skipping NPM publish in development mode");
47
+ return;
48
+ }
49
+ if (!commonPubPause) {
50
+ relinka("info", "Publishing to NPM...");
51
+ const distNpmDirNameResolved = path.resolve(PROJECT_ROOT, distNpmDirName);
52
+ if (timer) pausePerfTimer(timer);
53
+ await withWorkingDirectory(distNpmDirNameResolved, async () => {
54
+ const command = ["bun publish", distJsrDryRun ? "--dry-run" : ""].filter(Boolean).join(" ");
55
+ relinka("verbose", `Running publish command: ${command}`);
56
+ await execaCommand(command, { stdio: "inherit" });
57
+ relinka(
58
+ "success",
59
+ `Successfully ${distJsrDryRun ? "validated" : "published"} to NPM registry`
60
+ );
61
+ });
62
+ if (timer) resumePerfTimer(timer);
63
+ }
64
+ } catch (error) {
65
+ if (timer) resumePerfTimer(timer);
66
+ relinka("error", "Failed to publish to NPM:", error);
67
+ throw error;
68
+ }
69
+ }