@reliverse/dler 1.7.60 → 1.7.62

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 (62) hide show
  1. package/LICENSES +3 -0
  2. package/README.md +12 -7
  3. package/bin/app/build/prebuild.js +1 -2
  4. package/bin/app/{copy → fs}/cmd.d.ts +33 -2
  5. package/bin/app/fs/cmd.js +302 -0
  6. package/bin/app/x/cmd.d.ts +92 -0
  7. package/bin/app/x/cmd.js +270 -0
  8. package/bin/libs/cfg/cfg-impl/rse-config/rse-impl/rse-create.js +1 -1
  9. package/bin/libs/cfg/cfg-impl/rse-config/rse-impl/rse-define.d.ts +14 -14
  10. package/bin/libs/sdk/sdk-impl/config/info.js +1 -1
  11. package/bin/libs/sdk/sdk-impl/utils/exec/exec-enoent.d.ts +15 -0
  12. package/bin/libs/sdk/sdk-impl/utils/exec/exec-enoent.js +38 -0
  13. package/bin/libs/sdk/sdk-impl/utils/exec/exec-env.d.ts +6 -0
  14. package/bin/libs/sdk/sdk-impl/utils/exec/exec-env.js +34 -0
  15. package/bin/libs/sdk/sdk-impl/utils/exec/exec-error.d.ts +7 -0
  16. package/bin/libs/sdk/sdk-impl/utils/exec/exec-error.js +15 -0
  17. package/bin/libs/sdk/sdk-impl/utils/exec/exec-escape.d.ts +2 -0
  18. package/bin/libs/sdk/sdk-impl/utils/exec/exec-escape.js +15 -0
  19. package/bin/libs/sdk/sdk-impl/utils/exec/exec-mod.d.ts +58 -0
  20. package/bin/libs/sdk/sdk-impl/utils/exec/exec-mod.js +231 -0
  21. package/bin/libs/sdk/sdk-impl/utils/exec/exec-parse.d.ts +2 -0
  22. package/bin/libs/sdk/sdk-impl/utils/exec/exec-parse.js +56 -0
  23. package/bin/libs/sdk/sdk-impl/utils/exec/exec-resolve.d.ts +2 -0
  24. package/bin/libs/sdk/sdk-impl/utils/exec/exec-resolve.js +39 -0
  25. package/bin/libs/sdk/sdk-impl/utils/exec/exec-shebang.d.ts +1 -0
  26. package/bin/libs/sdk/sdk-impl/utils/exec/exec-shebang.js +14 -0
  27. package/bin/libs/sdk/sdk-impl/utils/exec/exec-spawn.d.ts +3 -0
  28. package/bin/libs/sdk/sdk-impl/utils/exec/exec-spawn.js +18 -0
  29. package/bin/libs/sdk/sdk-impl/utils/exec/exec-stream.d.ts +4 -0
  30. package/bin/libs/sdk/sdk-impl/utils/exec/exec-stream.js +20 -0
  31. package/bin/libs/sdk/sdk-impl/utils/exec/exec-types.d.ts +13 -0
  32. package/bin/libs/sdk/sdk-impl/utils/exec/exec-types.js +9 -0
  33. package/bin/libs/sdk/sdk-impl/utils/fs-rename.d.ts +2 -0
  34. package/bin/libs/sdk/sdk-impl/utils/fs-rename.js +108 -0
  35. package/bin/libs/sdk/sdk-impl/utils/pm/pm-api.d.ts +85 -0
  36. package/bin/libs/sdk/sdk-impl/utils/pm/pm-api.js +168 -0
  37. package/bin/libs/sdk/sdk-impl/utils/pm/pm-detect.d.ts +12 -0
  38. package/bin/libs/sdk/sdk-impl/utils/pm/pm-detect.js +99 -0
  39. package/bin/libs/sdk/sdk-impl/utils/pm/pm-parse.d.ts +8 -0
  40. package/bin/libs/sdk/sdk-impl/utils/pm/pm-parse.js +29 -0
  41. package/bin/libs/sdk/sdk-impl/utils/pm/pm-types.d.ts +43 -0
  42. package/bin/libs/sdk/sdk-impl/utils/pm/pm-types.js +0 -0
  43. package/bin/libs/sdk/sdk-impl/utils/pm/pm-utils.d.ts +12 -0
  44. package/bin/libs/sdk/sdk-impl/utils/pm/pm-utils.js +86 -0
  45. package/bin/libs/sdk/sdk-mod.d.ts +24 -0
  46. package/bin/libs/sdk/sdk-mod.js +53 -0
  47. package/package.json +9 -8
  48. package/bin/app/copy/cmd.js +0 -186
  49. package/bin/app/init/cmd.d.ts +0 -29
  50. package/bin/app/init/cmd.js +0 -82
  51. package/bin/app/rename/cmd.d.ts +0 -32
  52. package/bin/app/rename/cmd.js +0 -182
  53. package/bin/app/rm/cmd.d.ts +0 -13
  54. package/bin/app/rm/cmd.js +0 -70
  55. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-const.d.ts +0 -0
  56. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-const.js +0 -0
  57. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-impl.d.ts +0 -0
  58. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-impl.js +0 -0
  59. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-tmpl.d.ts +0 -0
  60. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-tmpl.js +0 -0
  61. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-types.d.ts +0 -0
  62. /package/bin/{app → libs/sdk/sdk-impl/utils}/init/init-types.js +0 -0
@@ -0,0 +1,231 @@
1
+ import { spawn } from "node:child_process";
2
+ import { normalize as normalizePath } from "node:path";
3
+ import { cwd as getCwd } from "node:process";
4
+ import readline from "node:readline";
5
+ import { computeEnv } from "./exec-env.js";
6
+ import { NonZeroExitError } from "./exec-error.js";
7
+ import { combineStreams } from "./exec-stream.js";
8
+ import { _parse } from "./exec-types.js";
9
+ const defaultOptions = {
10
+ timeout: void 0,
11
+ persist: false
12
+ };
13
+ const defaultNodeOptions = {
14
+ windowsHide: true
15
+ };
16
+ function normaliseCommandAndArgs(command, args) {
17
+ const normalisedPath = normalizePath(command);
18
+ const normalisedArgs = args ?? [];
19
+ return {
20
+ command: normalisedPath,
21
+ args: normalisedArgs
22
+ };
23
+ }
24
+ function combineSignals(signals) {
25
+ const controller = new AbortController();
26
+ for (const signal of signals) {
27
+ if (signal.aborted) {
28
+ controller.abort();
29
+ return signal;
30
+ }
31
+ const onAbort = () => {
32
+ controller.abort(signal.reason);
33
+ };
34
+ signal.addEventListener("abort", onAbort, {
35
+ signal: controller.signal
36
+ });
37
+ }
38
+ return controller.signal;
39
+ }
40
+ export class ExecProcess {
41
+ _process;
42
+ _aborted = false;
43
+ _options;
44
+ _command;
45
+ _args;
46
+ _resolveClose;
47
+ _processClosed;
48
+ _thrownError;
49
+ get process() {
50
+ return this._process;
51
+ }
52
+ get pid() {
53
+ return this._process?.pid;
54
+ }
55
+ get exitCode() {
56
+ if (this._process && this._process.exitCode !== null) {
57
+ return this._process.exitCode;
58
+ }
59
+ return void 0;
60
+ }
61
+ constructor(command, args, options) {
62
+ this._options = {
63
+ ...defaultOptions,
64
+ ...options
65
+ };
66
+ this._command = command;
67
+ this._args = args ?? [];
68
+ this._processClosed = new Promise((resolve) => {
69
+ this._resolveClose = resolve;
70
+ });
71
+ }
72
+ kill(signal) {
73
+ return this._process?.kill(signal) === true;
74
+ }
75
+ get aborted() {
76
+ return this._aborted;
77
+ }
78
+ get killed() {
79
+ return this._process?.killed === true;
80
+ }
81
+ pipe(command, args, options) {
82
+ return exec(command, args, {
83
+ ...options,
84
+ stdin: this
85
+ });
86
+ }
87
+ async *[Symbol.asyncIterator]() {
88
+ const proc = this._process;
89
+ if (!proc) {
90
+ return;
91
+ }
92
+ const streams = [];
93
+ if (this._streamErr) {
94
+ streams.push(this._streamErr);
95
+ }
96
+ if (this._streamOut) {
97
+ streams.push(this._streamOut);
98
+ }
99
+ const streamCombined = combineStreams(streams);
100
+ const rl = readline.createInterface({
101
+ input: streamCombined
102
+ });
103
+ for await (const chunk of rl) {
104
+ yield chunk.toString();
105
+ }
106
+ await this._processClosed;
107
+ proc.removeAllListeners();
108
+ if (this._thrownError) {
109
+ throw this._thrownError;
110
+ }
111
+ if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) {
112
+ throw new NonZeroExitError(this);
113
+ }
114
+ }
115
+ async _waitForOutput() {
116
+ const proc = this._process;
117
+ if (!proc) {
118
+ throw new Error("No process was started");
119
+ }
120
+ let stderr = "";
121
+ let stdout = "";
122
+ if (this._streamOut) {
123
+ for await (const chunk of this._streamOut) {
124
+ stdout += chunk.toString();
125
+ }
126
+ }
127
+ if (this._streamErr) {
128
+ for await (const chunk of this._streamErr) {
129
+ stderr += chunk.toString();
130
+ }
131
+ }
132
+ await this._processClosed;
133
+ if (this._options?.stdin) {
134
+ await this._options.stdin;
135
+ }
136
+ proc.removeAllListeners();
137
+ if (this._thrownError) {
138
+ throw this._thrownError;
139
+ }
140
+ const result = {
141
+ stderr,
142
+ stdout,
143
+ exitCode: this.exitCode
144
+ };
145
+ if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) {
146
+ throw new NonZeroExitError(this, result);
147
+ }
148
+ return result;
149
+ }
150
+ // biome-ignore lint/suspicious/noThenProperty: <>
151
+ then(onfulfilled, onrejected) {
152
+ return this._waitForOutput().then(onfulfilled, onrejected);
153
+ }
154
+ _streamOut;
155
+ _streamErr;
156
+ spawn() {
157
+ const cwd = getCwd();
158
+ const options = this._options;
159
+ const nodeOptions = {
160
+ ...defaultNodeOptions,
161
+ ...options.nodeOptions
162
+ };
163
+ const signals = [];
164
+ this._resetState();
165
+ if (options.timeout !== void 0) {
166
+ signals.push(AbortSignal.timeout(options.timeout));
167
+ }
168
+ if (options.signal !== void 0) {
169
+ signals.push(options.signal);
170
+ }
171
+ if (options.persist === true) {
172
+ nodeOptions.detached = true;
173
+ }
174
+ if (signals.length > 0) {
175
+ nodeOptions.signal = combineSignals(signals);
176
+ }
177
+ nodeOptions.env = computeEnv(cwd, nodeOptions.env);
178
+ const { command: normalisedCommand, args: normalisedArgs } = normaliseCommandAndArgs(
179
+ this._command,
180
+ this._args
181
+ );
182
+ const crossResult = _parse(normalisedCommand, normalisedArgs, nodeOptions);
183
+ let handle;
184
+ if (process.versions.bun) {
185
+ const bunSpawn = Bun.spawn;
186
+ handle = bunSpawn(crossResult.command, crossResult.args, crossResult.options);
187
+ } else {
188
+ handle = spawn(crossResult.command, crossResult.args, crossResult.options);
189
+ }
190
+ if (handle.stderr) {
191
+ this._streamErr = handle.stderr;
192
+ }
193
+ if (handle.stdout) {
194
+ this._streamOut = handle.stdout;
195
+ }
196
+ this._process = handle;
197
+ handle.once("error", this._onError);
198
+ handle.once("close", this._onClose);
199
+ if (options.stdin !== void 0 && handle.stdin && options.stdin.process) {
200
+ const { stdout } = options.stdin.process;
201
+ if (stdout) {
202
+ stdout.pipe(handle.stdin);
203
+ }
204
+ }
205
+ }
206
+ _resetState() {
207
+ this._aborted = false;
208
+ this._processClosed = new Promise((resolve) => {
209
+ this._resolveClose = resolve;
210
+ });
211
+ this._thrownError = void 0;
212
+ }
213
+ _onError = (err) => {
214
+ if (err.name === "AbortError" && (!(err.cause instanceof Error) || err.cause.name !== "TimeoutError")) {
215
+ this._aborted = true;
216
+ return;
217
+ }
218
+ this._thrownError = err;
219
+ };
220
+ _onClose = () => {
221
+ if (this._resolveClose) {
222
+ this._resolveClose();
223
+ }
224
+ };
225
+ }
226
+ export const x = (command, args, userOptions) => {
227
+ const proc = new ExecProcess(command, args, userOptions);
228
+ proc.spawn();
229
+ return proc;
230
+ };
231
+ export const exec = x;
@@ -0,0 +1,2 @@
1
+ import type { ExecParseResult } from "./exec-types.js";
2
+ export declare function parse(command: string, args?: string[] | any, options?: any): Promise<ExecParseResult>;
@@ -0,0 +1,56 @@
1
+ import path from "node:path";
2
+ import { escapeCommand, escapeArgument } from "./exec-escape.js";
3
+ import { resolveCommand } from "./exec-resolve.js";
4
+ import { readShebang } from "./exec-shebang.js";
5
+ const isWin = process.platform === "win32";
6
+ const isExecutableRegExp = /\.(?:com|exe)$/i;
7
+ const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
8
+ async function detectShebang(parsed) {
9
+ parsed.file = await resolveCommand(parsed);
10
+ if (parsed.file) {
11
+ const shebang = readShebang(parsed.file);
12
+ if (shebang) {
13
+ parsed.args.unshift(parsed.file);
14
+ parsed.command = shebang;
15
+ return await resolveCommand(parsed);
16
+ }
17
+ }
18
+ return parsed.file;
19
+ }
20
+ async function parseNonShell(parsed) {
21
+ if (!isWin) return parsed;
22
+ const commandFile = await detectShebang(parsed);
23
+ const needsShell = !isExecutableRegExp.test(commandFile ?? "");
24
+ if (parsed.options.forceShell || needsShell) {
25
+ const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile ?? "");
26
+ let cmd = path.normalize(parsed.command);
27
+ cmd = escapeCommand(cmd);
28
+ const args = parsed.args.map((arg) => escapeArgument(arg, needsDoubleEscapeMetaChars));
29
+ const shellCommand = [cmd].concat(args).join(" ");
30
+ parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
31
+ parsed.command = process.env.comspec || "cmd.exe";
32
+ parsed.options.windowsVerbatimArguments = true;
33
+ }
34
+ return parsed;
35
+ }
36
+ export async function parse(command, args, options) {
37
+ let actualArgs = args;
38
+ let actualOptions = options;
39
+ if (actualArgs && !Array.isArray(actualArgs)) {
40
+ actualOptions = actualArgs;
41
+ actualArgs = null;
42
+ }
43
+ actualArgs = actualArgs ? actualArgs.slice(0) : [];
44
+ actualOptions = Object.assign({}, actualOptions);
45
+ const parsed = {
46
+ command,
47
+ args: actualArgs,
48
+ options: actualOptions,
49
+ file: void 0,
50
+ original: {
51
+ command,
52
+ args: actualArgs
53
+ }
54
+ };
55
+ return actualOptions.shell ? parsed : await parseNonShell(parsed);
56
+ }
@@ -0,0 +1,2 @@
1
+ import type { ExecParseResult } from "./exec-types.js";
2
+ export declare function resolveCommand(parsed: ExecParseResult): Promise<string | undefined>;
@@ -0,0 +1,39 @@
1
+ import { lookpath } from "lookpath";
2
+ import path from "node:path";
3
+ import getPathKey from "path-key";
4
+ async function resolveCommandAttempt(parsed, withoutPathExt) {
5
+ const env = parsed.options.env || process.env;
6
+ const cwd = process.cwd();
7
+ const hasCustomCwd = parsed.options.cwd != null;
8
+ const shouldSwitchCwd = hasCustomCwd && typeof process.chdir === "function" && !process.chdir.disabled;
9
+ if (shouldSwitchCwd) {
10
+ try {
11
+ process.chdir(String(parsed.options.cwd ?? cwd));
12
+ } catch {
13
+ }
14
+ }
15
+ let resolved;
16
+ try {
17
+ const pathEnv = env[getPathKey({ env })];
18
+ const lookpathOptions = {
19
+ path: pathEnv?.split(path.delimiter),
20
+ include: withoutPathExt ? [] : void 0
21
+ };
22
+ resolved = await lookpath(parsed.command, lookpathOptions);
23
+ } catch {
24
+ } finally {
25
+ if (shouldSwitchCwd) {
26
+ process.chdir(cwd);
27
+ }
28
+ }
29
+ if (resolved) {
30
+ resolved = path.resolve(
31
+ hasCustomCwd ? String(parsed.options.cwd ?? cwd) : cwd,
32
+ typeof resolved === "string" ? resolved : String(resolved)
33
+ );
34
+ }
35
+ return resolved;
36
+ }
37
+ export async function resolveCommand(parsed) {
38
+ return await resolveCommandAttempt(parsed) || await resolveCommandAttempt(parsed, true);
39
+ }
@@ -0,0 +1 @@
1
+ export declare function readShebang(command: string): string | null;
@@ -0,0 +1,14 @@
1
+ import fs from "node:fs";
2
+ import shebangCommand from "shebang-command";
3
+ export function readShebang(command) {
4
+ const size = 150;
5
+ const buffer = Buffer.alloc(size);
6
+ let fd;
7
+ try {
8
+ fd = fs.openSync(command, "r");
9
+ fs.readSync(fd, buffer, 0, size, 0);
10
+ fs.closeSync(fd);
11
+ } catch {
12
+ }
13
+ return shebangCommand(buffer.toString());
14
+ }
@@ -0,0 +1,3 @@
1
+ import { type ChildProcess, type SpawnOptions, type SpawnSyncReturns } from "node:child_process";
2
+ export declare function spawn(command: string, args?: string[], options?: SpawnOptions): Promise<ChildProcess>;
3
+ export declare function spawnSync(command: string, args?: string[], options?: SpawnOptions): Promise<SpawnSyncReturns<string | Buffer<ArrayBufferLike>>>;
@@ -0,0 +1,18 @@
1
+ import {
2
+ spawn as nodeSpawn,
3
+ spawnSync as nodeSpawnSync
4
+ } from "node:child_process";
5
+ import { hookChildProcess, verifyENOENTSync } from "./exec-enoent.js";
6
+ import { parse } from "./exec-parse.js";
7
+ export async function spawn(command, args, options) {
8
+ const parsed = await parse(command, args, options);
9
+ const spawned = nodeSpawn(parsed.command, parsed.args, parsed.options);
10
+ hookChildProcess(spawned, parsed);
11
+ return spawned;
12
+ }
13
+ export async function spawnSync(command, args, options) {
14
+ const parsed = await parse(command, args, options);
15
+ const result = nodeSpawnSync(parsed.command, parsed.args, parsed.options);
16
+ result.error = result.error || verifyENOENTSync(result.status, parsed);
17
+ return result;
18
+ }
@@ -0,0 +1,4 @@
1
+ import type { EventEmitter } from "node:events";
2
+ import { type Readable } from "node:stream";
3
+ export declare const waitForEvent: (emitter: EventEmitter, name: string) => Promise<void>;
4
+ export declare const combineStreams: (streams: Readable[]) => Readable;
@@ -0,0 +1,20 @@
1
+ import { PassThrough } from "node:stream";
2
+ export const waitForEvent = (emitter, name) => {
3
+ return new Promise((resolve) => {
4
+ emitter.on(name, resolve);
5
+ });
6
+ };
7
+ export const combineStreams = (streams) => {
8
+ let streamCount = streams.length;
9
+ const combined = new PassThrough();
10
+ const maybeEmitEnd = () => {
11
+ if (--streamCount === 0) {
12
+ combined.emit("end");
13
+ }
14
+ };
15
+ for (const stream of streams) {
16
+ stream.pipe(combined, { end: false });
17
+ stream.on("end", maybeEmitEnd);
18
+ }
19
+ return combined;
20
+ };
@@ -0,0 +1,13 @@
1
+ import type { ChildProcess, SpawnOptions } from "node:child_process";
2
+ export type { ChildProcess, SpawnOptions };
3
+ export interface ExecParseResult {
4
+ command: string;
5
+ args: string[];
6
+ options: SpawnOptions;
7
+ file?: string;
8
+ original: {
9
+ command: string;
10
+ args: string[];
11
+ };
12
+ }
13
+ export declare function _parse(file: string, args: string[], options?: SpawnOptions): ExecParseResult;
@@ -0,0 +1,9 @@
1
+ export function _parse(file, args, options) {
2
+ return {
3
+ command: file,
4
+ args,
5
+ options: options ?? {},
6
+ file,
7
+ original: { command: file, args }
8
+ };
9
+ }
@@ -0,0 +1,2 @@
1
+ export declare function safeRename(source: string, destination: string): Promise<void>;
2
+ export declare function prepareCLIFiles(revert?: boolean, recursive?: boolean, useDtsTxtForPrepareMyCLI?: boolean): Promise<void>;
@@ -0,0 +1,108 @@
1
+ import path from "@reliverse/pathkit";
2
+ import fs from "@reliverse/relifso";
3
+ import { relinka } from "@reliverse/relinka";
4
+ async function fileExists(path2) {
5
+ try {
6
+ await fs.access(path2);
7
+ return true;
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
12
+ export async function safeRename(source, destination) {
13
+ if (await fileExists(destination)) {
14
+ throw new Error(`Destination file already exists: ${destination}`);
15
+ }
16
+ await fs.rename(source, destination);
17
+ }
18
+ function isCommonJSFile(content) {
19
+ return content.includes("module.exports") || content.includes("require(");
20
+ }
21
+ async function getAllFilesAsync(dir, baseDir = dir, recursive = true) {
22
+ let fileList = [];
23
+ const entries = await fs.readdir(dir, {
24
+ encoding: "utf8",
25
+ withFileTypes: true
26
+ });
27
+ for (const entry of entries) {
28
+ const fullPath = path.join(dir, entry.name);
29
+ if (entry.isDirectory()) {
30
+ if (recursive) {
31
+ const subFiles = await getAllFilesAsync(fullPath, baseDir, recursive);
32
+ fileList = fileList.concat(subFiles);
33
+ }
34
+ } else if (entry.isFile()) {
35
+ fileList.push(fullPath.slice(baseDir.length + 1));
36
+ }
37
+ }
38
+ return fileList;
39
+ }
40
+ export async function prepareCLIFiles(revert = false, recursive = true, useDtsTxtForPrepareMyCLI = false) {
41
+ relinka("log", "Starting CLI file preparation...");
42
+ const configPath = ".config/dler.ts";
43
+ let srcDir = "src";
44
+ if (fs.existsSync(configPath)) {
45
+ const configContent = fs.readFileSync(configPath, "utf8");
46
+ const configMatch = configContent.match(/coreEntrySrcDir:\s*["']([^"']+)["']/);
47
+ srcDir = configMatch?.[1] ?? srcDir;
48
+ }
49
+ if (!fs.existsSync(srcDir)) {
50
+ throw new Error(`Source directory not found: ${srcDir}`);
51
+ }
52
+ const files = await getAllFilesAsync(srcDir, srcDir, recursive);
53
+ relinka("log", `Found ${files.length} files to process.`);
54
+ let renamedCount = 0;
55
+ for (const file of files) {
56
+ const fullPath = path.join(srcDir, file);
57
+ if (!await fileExists(fullPath)) continue;
58
+ const ext = path.extname(file);
59
+ const fileName = path.basename(file);
60
+ const baseName = path.basename(file, ext);
61
+ const dir = path.dirname(fullPath);
62
+ if (revert) {
63
+ if (file.endsWith(".json.json")) {
64
+ const originalName = path.join(dir, fileName.replace(".json.json", ".json"));
65
+ relinka("log", `Reverting ${fullPath} to ${originalName}`);
66
+ await safeRename(fullPath, originalName);
67
+ renamedCount++;
68
+ } else if (file.endsWith(".d.ts.txt") && useDtsTxtForPrepareMyCLI) {
69
+ const originalName = path.join(dir, fileName.replace(".d.ts.txt", ".d.ts"));
70
+ relinka("log", `Reverting ${fullPath} to ${originalName}`);
71
+ await safeRename(fullPath, originalName);
72
+ renamedCount++;
73
+ } else if (file.endsWith(".cjs")) {
74
+ const originalName = path.join(dir, `${baseName}.js`);
75
+ relinka("log", `Reverting ${fullPath} to ${originalName}`);
76
+ await safeRename(fullPath, originalName);
77
+ renamedCount++;
78
+ }
79
+ } else {
80
+ if (fileName === "tsconfig.json" && !fileName.endsWith(".json.json")) {
81
+ const newName = path.join(dir, "tsconfig.json.json");
82
+ relinka("log", `Renaming ${fullPath} to ${newName}`);
83
+ await safeRename(fullPath, newName);
84
+ renamedCount++;
85
+ } else if (fileName === "package.json" && !fileName.endsWith(".json.json")) {
86
+ const newName = path.join(dir, "package.json.json");
87
+ relinka("log", `Renaming ${fullPath} to ${newName}`);
88
+ await safeRename(fullPath, newName);
89
+ renamedCount++;
90
+ } else if (fileName.endsWith(".d.ts") && !fileName.endsWith(".d.ts.txt") && useDtsTxtForPrepareMyCLI) {
91
+ const baseWithoutD = baseName.slice(0, -2);
92
+ const newName = path.join(dir, `${baseWithoutD}.d.ts.txt`);
93
+ relinka("log", `Renaming ${fullPath} to ${newName}`);
94
+ await safeRename(fullPath, newName);
95
+ renamedCount++;
96
+ } else if (fileName.endsWith(".js") && !fileName.endsWith(".cjs")) {
97
+ const content = fs.readFileSync(fullPath, "utf8");
98
+ if (isCommonJSFile(content)) {
99
+ const newName = path.join(dir, `${baseName}.cjs`);
100
+ relinka("log", `Renaming ${fullPath} to ${newName}`);
101
+ await safeRename(fullPath, newName);
102
+ renamedCount++;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ relinka("log", `CLI file preparation completed. Renamed ${renamedCount} files.`);
108
+ }
@@ -0,0 +1,85 @@
1
+ import type { OperationOptions } from "./pm-types";
2
+ /**
3
+ * Installs project dependencies.
4
+ *
5
+ * @param options - Options to pass to the API call.
6
+ * @param options.cwd - The directory to run the command in.
7
+ * @param options.silent - Whether to run the command in silent mode.
8
+ * @param options.packageManager - The package manager info to use (auto-detected).
9
+ * @param options.frozenLockFile - Whether to install dependencies with frozen lock file.
10
+ */
11
+ export declare function installDependencies(options?: Pick<OperationOptions, "cwd" | "silent" | "packageManager"> & {
12
+ frozenLockFile?: boolean;
13
+ }): Promise<void>;
14
+ /**
15
+ * Adds dependency to the project.
16
+ *
17
+ * @param name - Name of the dependency to add.
18
+ * @param options - Options to pass to the API call.
19
+ * @param options.cwd - The directory to run the command in.
20
+ * @param options.silent - Whether to run the command in silent mode.
21
+ * @param options.packageManager - The package manager info to use (auto-detected).
22
+ * @param options.dev - Whether to add the dependency as dev dependency.
23
+ * @param options.workspace - The name of the workspace to use.
24
+ * @param options.global - Whether to run the command in global mode.
25
+ */
26
+ export declare function addDependency(name: string | string[], options?: OperationOptions): Promise<void>;
27
+ /**
28
+ * Adds dev dependency to the project.
29
+ *
30
+ * @param name - Name of the dev dependency to add.
31
+ * @param options - Options to pass to the API call.
32
+ * @param options.cwd - The directory to run the command in.
33
+ * @param options.silent - Whether to run the command in silent mode.
34
+ * @param options.packageManager - The package manager info to use (auto-detected).
35
+ * @param options.workspace - The name of the workspace to use.
36
+ * @param options.global - Whether to run the command in global mode.
37
+ *
38
+ */
39
+ export declare function addDevDependency(name: string | string[], options?: Omit<OperationOptions, "dev">): Promise<void>;
40
+ /**
41
+ * Removes dependency from the project.
42
+ *
43
+ * @param name - Name of the dependency to remove.
44
+ * @param options - Options to pass to the API call.
45
+ * @param options.cwd - The directory to run the command in.
46
+ * @param options.silent - Whether to run the command in silent mode.
47
+ * @param options.packageManager - The package manager info to use (auto-detected).
48
+ * @param options.dev - Whether to remove dev dependency.
49
+ * @param options.workspace - The name of the workspace to use.
50
+ * @param options.global - Whether to run the command in global mode.
51
+ */
52
+ export declare function removeDependency(name: string | string[], options?: OperationOptions): Promise<void>;
53
+ /**
54
+ * Ensures dependency is installed.
55
+ *
56
+ * @param name - Name of the dependency.
57
+ * @param options - Options to pass to the API call.
58
+ * @param options.cwd - The directory to run the command in.
59
+ * @param options.dev - Whether to install as dev dependency (if not already installed).
60
+ * @param options.workspace - The name of the workspace to install dependency in (if not already installed).
61
+ */
62
+ export declare function ensureDependencyInstalled(name: string, options?: Pick<OperationOptions, "cwd" | "dev" | "workspace">): Promise<true | undefined>;
63
+ /**
64
+ * Dedupe dependencies in the project.
65
+ *
66
+ * @param options - Options to pass to the API call.
67
+ * @param options.cwd - The directory to run the command in.
68
+ * @param options.packageManager - The package manager info to use (auto-detected).
69
+ * @param options.silent - Whether to run the command in silent mode.
70
+ * @param options.recreateLockfile - Whether to recreate the lockfile instead of deduping.
71
+ */
72
+ export declare function dedupeDependencies(options?: Pick<OperationOptions, "cwd" | "silent" | "packageManager"> & {
73
+ recreateLockfile?: boolean;
74
+ }): Promise<void>;
75
+ export declare function updateDependencies(latest?: boolean, options?: OperationOptions): Promise<void>;
76
+ /**
77
+ * Runs a script defined in the package.json file.
78
+ *
79
+ * @param name - Name of the script to run.
80
+ * @param options - Options to pass to the API call.
81
+ * @param options.cwd - The directory to run the command in.
82
+ * @param options.silent - Whether to run the command in silent mode.
83
+ * @param options.packageManager - The package manager info to use (auto-detected).
84
+ */
85
+ export declare function runScript(name: string, options?: Pick<OperationOptions, "cwd" | "silent" | "packageManager">): Promise<void>;