@settlemint/sdk-utils 2.3.2-pr6cb5dd2e → 2.3.2-pr74f654b5
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.
- package/README.md +51 -7
- package/dist/environment.cjs +25 -408
- package/dist/environment.d.cts +3 -176
- package/dist/environment.d.ts +3 -176
- package/dist/environment.js +4 -0
- package/dist/filesystem.cjs +39 -123
- package/dist/filesystem.d.cts +4 -59
- package/dist/filesystem.d.ts +4 -59
- package/dist/filesystem.js +5 -0
- package/dist/http.cjs +35 -147
- package/dist/http.d.cts +4 -50
- package/dist/http.d.ts +4 -50
- package/dist/http.js +5 -0
- package/dist/index.cjs +27 -184
- package/dist/index.d.cts +4 -122
- package/dist/index.d.ts +4 -122
- package/dist/index.js +7 -0
- package/dist/json.cjs +83 -0
- package/dist/json.cjs.map +1 -0
- package/dist/json.d.cts +56 -0
- package/dist/json.d.ts +56 -0
- package/dist/json.js +80 -0
- package/dist/json.js.map +1 -0
- package/dist/logging.cjs +34 -141
- package/dist/logging.d.cts +4 -70
- package/dist/logging.d.ts +4 -70
- package/dist/logging.js +5 -0
- package/dist/package-manager.cjs +51 -196
- package/dist/package-manager.d.cts +7 -114
- package/dist/package-manager.d.ts +7 -114
- package/dist/package-manager.js +9 -0
- package/dist/retry.cjs +69 -0
- package/dist/retry.cjs.map +1 -0
- package/dist/retry.d.cts +19 -0
- package/dist/retry.d.ts +19 -0
- package/dist/retry.js +46 -0
- package/dist/retry.js.map +1 -0
- package/dist/runtime.cjs +38 -42
- package/dist/runtime.d.cts +2 -32
- package/dist/runtime.d.ts +2 -32
- package/dist/runtime.js +3 -0
- package/dist/string.cjs +76 -0
- package/dist/string.cjs.map +1 -0
- package/dist/string.d.cts +58 -0
- package/dist/string.d.ts +58 -0
- package/dist/string.js +72 -0
- package/dist/string.js.map +1 -0
- package/dist/terminal.cjs +91 -258
- package/dist/terminal.d.cts +11 -219
- package/dist/terminal.d.ts +11 -219
- package/dist/terminal.js +12 -0
- package/dist/url.cjs +25 -0
- package/dist/url.cjs.map +1 -0
- package/dist/url.d.cts +20 -0
- package/dist/url.d.ts +20 -0
- package/dist/url.js +24 -0
- package/dist/url.js.map +1 -0
- package/dist/validation.cjs +89 -183
- package/dist/validation.d.cts +7 -239
- package/dist/validation.d.ts +7 -239
- package/dist/validation.js +8 -0
- package/package.json +6 -6
- package/dist/environment.cjs.map +0 -1
- package/dist/environment.mjs +0 -383
- package/dist/environment.mjs.map +0 -1
- package/dist/filesystem.cjs.map +0 -1
- package/dist/filesystem.mjs +0 -105
- package/dist/filesystem.mjs.map +0 -1
- package/dist/http.cjs.map +0 -1
- package/dist/http.mjs +0 -129
- package/dist/http.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs +0 -156
- package/dist/index.mjs.map +0 -1
- package/dist/logging.cjs.map +0 -1
- package/dist/logging.mjs +0 -123
- package/dist/logging.mjs.map +0 -1
- package/dist/package-manager.cjs.map +0 -1
- package/dist/package-manager.mjs +0 -167
- package/dist/package-manager.mjs.map +0 -1
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.mjs +0 -23
- package/dist/runtime.mjs.map +0 -1
- package/dist/terminal.cjs.map +0 -1
- package/dist/terminal.mjs +0 -230
- package/dist/terminal.mjs.map +0 -1
- package/dist/validation.cjs.map +0 -1
- package/dist/validation.mjs +0 -159
- package/dist/validation.mjs.map +0 -1
package/dist/logging.d.cts
CHANGED
|
@@ -1,70 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for the logger
|
|
7
|
-
* @interface LoggerOptions
|
|
8
|
-
*/
|
|
9
|
-
interface LoggerOptions {
|
|
10
|
-
/** The minimum log level to output */
|
|
11
|
-
level?: LogLevel;
|
|
12
|
-
/** The prefix to add to the log message */
|
|
13
|
-
prefix?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Simple logger interface with basic logging methods
|
|
17
|
-
* @interface Logger
|
|
18
|
-
*/
|
|
19
|
-
interface Logger {
|
|
20
|
-
/** Log debug information */
|
|
21
|
-
debug: (message: string, ...args: unknown[]) => void;
|
|
22
|
-
/** Log general information */
|
|
23
|
-
info: (message: string, ...args: unknown[]) => void;
|
|
24
|
-
/** Log warnings */
|
|
25
|
-
warn: (message: string, ...args: unknown[]) => void;
|
|
26
|
-
/** Log errors */
|
|
27
|
-
error: (message: string, ...args: unknown[]) => void;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Creates a simple logger with configurable log level
|
|
31
|
-
*
|
|
32
|
-
* @param options - Configuration options for the logger
|
|
33
|
-
* @param options.level - The minimum log level to output (default: warn)
|
|
34
|
-
* @param options.prefix - The prefix to add to the log message (default: "")
|
|
35
|
-
* @returns A logger instance with debug, info, warn, and error methods
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* import { createLogger } from "@/utils/logging/logger";
|
|
39
|
-
*
|
|
40
|
-
* const logger = createLogger({ level: 'info' });
|
|
41
|
-
*
|
|
42
|
-
* logger.info('User logged in', { userId: '123' });
|
|
43
|
-
* logger.error('Operation failed', new Error('Connection timeout'));
|
|
44
|
-
*/
|
|
45
|
-
declare function createLogger(options?: LoggerOptions): Logger;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Logs the request and duration of a fetch call (> 500ms is logged as warn, otherwise info)
|
|
49
|
-
* @param logger - The logger to use
|
|
50
|
-
* @param name - The name of the request
|
|
51
|
-
* @param fn - The fetch function to use
|
|
52
|
-
* @returns The fetch function
|
|
53
|
-
*/
|
|
54
|
-
declare function requestLogger(logger: Logger, name: string, fn: typeof fetch): (...args: Parameters<typeof fetch>) => Promise<Response>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Masks sensitive SettleMint tokens in output text by replacing them with asterisks.
|
|
58
|
-
* Handles personal access tokens (PAT), application access tokens (AAT), and service account tokens (SAT).
|
|
59
|
-
*
|
|
60
|
-
* @param output - The text string that may contain sensitive tokens
|
|
61
|
-
* @returns The text with any sensitive tokens masked with asterisks
|
|
62
|
-
* @example
|
|
63
|
-
* import { maskTokens } from "@settlemint/sdk-utils/terminal";
|
|
64
|
-
*
|
|
65
|
-
* // Masks a token in text
|
|
66
|
-
* const masked = maskTokens("Token: sm_pat_****"); // "Token: ***"
|
|
67
|
-
*/
|
|
68
|
-
declare const maskTokens: (output: string) => string;
|
|
69
|
-
|
|
70
|
-
export { type LogLevel, type Logger, type LoggerOptions, createLogger, maskTokens, requestLogger };
|
|
1
|
+
import { LogLevel, Logger, LoggerOptions, createLogger } from "./logging/logger.js";
|
|
2
|
+
import { requestLogger } from "./logging/request-logger.js";
|
|
3
|
+
import { maskTokens } from "./logging/mask-tokens.js";
|
|
4
|
+
export { LogLevel, Logger, LoggerOptions, createLogger, maskTokens, requestLogger };
|
package/dist/logging.d.ts
CHANGED
|
@@ -1,70 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for the logger
|
|
7
|
-
* @interface LoggerOptions
|
|
8
|
-
*/
|
|
9
|
-
interface LoggerOptions {
|
|
10
|
-
/** The minimum log level to output */
|
|
11
|
-
level?: LogLevel;
|
|
12
|
-
/** The prefix to add to the log message */
|
|
13
|
-
prefix?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Simple logger interface with basic logging methods
|
|
17
|
-
* @interface Logger
|
|
18
|
-
*/
|
|
19
|
-
interface Logger {
|
|
20
|
-
/** Log debug information */
|
|
21
|
-
debug: (message: string, ...args: unknown[]) => void;
|
|
22
|
-
/** Log general information */
|
|
23
|
-
info: (message: string, ...args: unknown[]) => void;
|
|
24
|
-
/** Log warnings */
|
|
25
|
-
warn: (message: string, ...args: unknown[]) => void;
|
|
26
|
-
/** Log errors */
|
|
27
|
-
error: (message: string, ...args: unknown[]) => void;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Creates a simple logger with configurable log level
|
|
31
|
-
*
|
|
32
|
-
* @param options - Configuration options for the logger
|
|
33
|
-
* @param options.level - The minimum log level to output (default: warn)
|
|
34
|
-
* @param options.prefix - The prefix to add to the log message (default: "")
|
|
35
|
-
* @returns A logger instance with debug, info, warn, and error methods
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* import { createLogger } from "@/utils/logging/logger";
|
|
39
|
-
*
|
|
40
|
-
* const logger = createLogger({ level: 'info' });
|
|
41
|
-
*
|
|
42
|
-
* logger.info('User logged in', { userId: '123' });
|
|
43
|
-
* logger.error('Operation failed', new Error('Connection timeout'));
|
|
44
|
-
*/
|
|
45
|
-
declare function createLogger(options?: LoggerOptions): Logger;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Logs the request and duration of a fetch call (> 500ms is logged as warn, otherwise info)
|
|
49
|
-
* @param logger - The logger to use
|
|
50
|
-
* @param name - The name of the request
|
|
51
|
-
* @param fn - The fetch function to use
|
|
52
|
-
* @returns The fetch function
|
|
53
|
-
*/
|
|
54
|
-
declare function requestLogger(logger: Logger, name: string, fn: typeof fetch): (...args: Parameters<typeof fetch>) => Promise<Response>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Masks sensitive SettleMint tokens in output text by replacing them with asterisks.
|
|
58
|
-
* Handles personal access tokens (PAT), application access tokens (AAT), and service account tokens (SAT).
|
|
59
|
-
*
|
|
60
|
-
* @param output - The text string that may contain sensitive tokens
|
|
61
|
-
* @returns The text with any sensitive tokens masked with asterisks
|
|
62
|
-
* @example
|
|
63
|
-
* import { maskTokens } from "@settlemint/sdk-utils/terminal";
|
|
64
|
-
*
|
|
65
|
-
* // Masks a token in text
|
|
66
|
-
* const masked = maskTokens("Token: sm_pat_****"); // "Token: ***"
|
|
67
|
-
*/
|
|
68
|
-
declare const maskTokens: (output: string) => string;
|
|
69
|
-
|
|
70
|
-
export { type LogLevel, type Logger, type LoggerOptions, createLogger, maskTokens, requestLogger };
|
|
1
|
+
import { LogLevel, Logger, LoggerOptions, createLogger } from "./logging/logger.js";
|
|
2
|
+
import { requestLogger } from "./logging/request-logger.js";
|
|
3
|
+
import { maskTokens } from "./logging/mask-tokens.js";
|
|
4
|
+
export { LogLevel, Logger, LoggerOptions, createLogger, maskTokens, requestLogger };
|
package/dist/logging.js
ADDED
package/dist/package-manager.cjs
CHANGED
|
@@ -1,211 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
8
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
getPackageManagerExecutable: () => getPackageManagerExecutable,
|
|
37
|
-
installDependencies: () => installDependencies,
|
|
38
|
-
isEmpty: () => isEmpty,
|
|
39
|
-
isPackageInstalled: () => isPackageInstalled,
|
|
40
|
-
setName: () => setName
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(package_manager_exports);
|
|
43
|
-
|
|
44
|
-
// src/package-manager/download-and-extract.ts
|
|
45
|
-
var import_promises3 = require("fs/promises");
|
|
46
|
-
var import_node_path3 = require("path");
|
|
47
|
-
|
|
48
|
-
// src/filesystem/project-root.ts
|
|
49
|
-
var import_node_path = require("path");
|
|
50
|
-
var import_find_up = require("find-up");
|
|
51
|
-
async function projectRoot(fallbackToCwd = false, cwd) {
|
|
52
|
-
const packageJsonPath = await (0, import_find_up.findUp)("package.json", { cwd });
|
|
53
|
-
if (!packageJsonPath) {
|
|
54
|
-
if (fallbackToCwd) {
|
|
55
|
-
return process.cwd();
|
|
56
|
-
}
|
|
57
|
-
throw new Error("Unable to find project root (no package.json found)");
|
|
58
|
-
}
|
|
59
|
-
return (0, import_node_path.dirname)(packageJsonPath);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/filesystem/exists.ts
|
|
63
|
-
var import_promises = require("fs/promises");
|
|
64
|
-
async function exists(path) {
|
|
65
|
-
try {
|
|
66
|
-
await (0, import_promises.stat)(path);
|
|
67
|
-
return true;
|
|
68
|
-
} catch {
|
|
69
|
-
return false;
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const src_package_manager_get_package_manager_js = __toESM(require("./package-manager/get-package-manager.js"));
|
|
25
|
+
const src_package_manager_get_package_manager_executable_js = __toESM(require("./package-manager/get-package-manager-executable.js"));
|
|
26
|
+
const src_package_manager_install_dependencies_js = __toESM(require("./package-manager/install-dependencies.js"));
|
|
27
|
+
const src_package_manager_is_package_installed_js = __toESM(require("./package-manager/is-package-installed.js"));
|
|
28
|
+
const src_package_manager_set_name_js = __toESM(require("./package-manager/set-name.js"));
|
|
29
|
+
|
|
30
|
+
Object.defineProperty(exports, 'getPackageManager', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return src_package_manager_get_package_manager_js.getPackageManager;
|
|
70
34
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var import_find_up2 = require("find-up");
|
|
77
|
-
var import_glob = require("glob");
|
|
78
|
-
|
|
79
|
-
// src/package-manager/download-and-extract.ts
|
|
80
|
-
function formatTargetDir(targetDir) {
|
|
81
|
-
return targetDir?.trim().replace(/\/+$/g, "");
|
|
82
|
-
}
|
|
83
|
-
async function isEmpty(path) {
|
|
84
|
-
const files = await (0, import_promises3.readdir)(path);
|
|
85
|
-
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
86
|
-
}
|
|
87
|
-
async function emptyDir(dir) {
|
|
88
|
-
if (!await exists(dir)) return;
|
|
89
|
-
for (const file of await (0, import_promises3.readdir)(dir)) {
|
|
90
|
-
if (file === ".git") continue;
|
|
91
|
-
await (0, import_promises3.rm)((0, import_node_path3.resolve)(dir, file), { recursive: true, force: true });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// src/package-manager/get-package-manager.ts
|
|
96
|
-
var import_detect = require("package-manager-detector/detect");
|
|
97
|
-
async function getPackageManager(targetDir) {
|
|
98
|
-
const packageManager = await (0, import_detect.detect)({ cwd: targetDir || process.cwd() });
|
|
99
|
-
return packageManager?.name ?? "npm";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/package-manager/get-package-manager-executable.ts
|
|
103
|
-
async function getPackageManagerExecutable(targetDir) {
|
|
104
|
-
const packageManager = await getPackageManager(targetDir ?? process.cwd());
|
|
105
|
-
switch (packageManager) {
|
|
106
|
-
case "pnpm":
|
|
107
|
-
return { command: "pnpm", args: ["dlx"] };
|
|
108
|
-
case "bun":
|
|
109
|
-
return { command: "bunx", args: [] };
|
|
110
|
-
case "yarn":
|
|
111
|
-
return { command: "yarn", args: ["create"] };
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, 'getPackageManagerExecutable', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return src_package_manager_get_package_manager_executable_js.getPackageManagerExecutable;
|
|
112
40
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// src/terminal/ascii.ts
|
|
120
|
-
var import_yoctocolors = require("yoctocolors");
|
|
121
|
-
|
|
122
|
-
// src/terminal/should-print.ts
|
|
123
|
-
function shouldPrint() {
|
|
124
|
-
return process.env.SETTLEMINT_DISABLE_TERMINAL !== "true";
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/logging/mask-tokens.ts
|
|
128
|
-
var maskTokens = (output) => {
|
|
129
|
-
return output.replace(/sm_(pat|aat|sat)_[0-9a-zA-Z]+/g, "***");
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// src/terminal/cancel.ts
|
|
133
|
-
var import_yoctocolors2 = require("yoctocolors");
|
|
134
|
-
|
|
135
|
-
// src/terminal/execute-command.ts
|
|
136
|
-
var import_node_child_process = require("child_process");
|
|
137
|
-
|
|
138
|
-
// src/terminal/intro.ts
|
|
139
|
-
var import_yoctocolors3 = require("yoctocolors");
|
|
140
|
-
|
|
141
|
-
// src/terminal/note.ts
|
|
142
|
-
var import_yoctocolors4 = require("yoctocolors");
|
|
143
|
-
var note = (message, level = "info") => {
|
|
144
|
-
if (!shouldPrint()) {
|
|
145
|
-
return;
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, 'installDependencies', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return src_package_manager_install_dependencies_js.installDependencies;
|
|
146
46
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return;
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, 'isPackageInstalled', {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return src_package_manager_is_package_installed_js.isPackageInstalled;
|
|
152
52
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// src/terminal/spinner.ts
|
|
160
|
-
var import_is_in_ci = __toESM(require("is-in-ci"), 1);
|
|
161
|
-
var import_yocto_spinner = __toESM(require("yocto-spinner"), 1);
|
|
162
|
-
var import_yoctocolors6 = require("yoctocolors");
|
|
163
|
-
|
|
164
|
-
// src/terminal/table.ts
|
|
165
|
-
var import_console_table_printer = require("console-table-printer");
|
|
166
|
-
var import_yoctocolors7 = require("yoctocolors");
|
|
167
|
-
|
|
168
|
-
// src/package-manager/install-dependencies.ts
|
|
169
|
-
async function installDependencies(pkgs, cwd) {
|
|
170
|
-
try {
|
|
171
|
-
await (0, import_install_pkg.installPackage)(pkgs, { silent: true, additionalArgs: ["--exact"], cwd });
|
|
172
|
-
} catch (err) {
|
|
173
|
-
const error = err instanceof Error ? err.message : "Unknown error";
|
|
174
|
-
note(
|
|
175
|
-
`Failed to install ${Array.isArray(pkgs) ? `dependencies '${pkgs.join(", ")}'` : `dependency '${pkgs}'`}: ${error}`,
|
|
176
|
-
"warn"
|
|
177
|
-
);
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, 'setName', {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return src_package_manager_set_name_js.setName;
|
|
178
58
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const inDependencies = !!pkgJson.content.dependencies?.[name];
|
|
186
|
-
const inDevDependencies = !!pkgJson.content.devDependencies?.[name];
|
|
187
|
-
const inPeerDependencies = !!pkgJson.content.peerDependencies?.[name];
|
|
188
|
-
return inDependencies || inDevDependencies || inPeerDependencies;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// src/package-manager/set-name.ts
|
|
192
|
-
var import_package_json2 = __toESM(require("@npmcli/package-json"), 1);
|
|
193
|
-
async function setName(name, path) {
|
|
194
|
-
const pkgJson = await import_package_json2.default.load(path ?? await projectRoot());
|
|
195
|
-
pkgJson.update({
|
|
196
|
-
name
|
|
59
|
+
});
|
|
60
|
+
var src_package_manager_download_and_extract_js = require("./package-manager/download-and-extract.js");
|
|
61
|
+
Object.keys(src_package_manager_download_and_extract_js).forEach(function (k) {
|
|
62
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () { return src_package_manager_download_and_extract_js[k]; }
|
|
197
65
|
});
|
|
198
|
-
await pkgJson.save();
|
|
199
|
-
}
|
|
200
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
-
0 && (module.exports = {
|
|
202
|
-
emptyDir,
|
|
203
|
-
formatTargetDir,
|
|
204
|
-
getPackageManager,
|
|
205
|
-
getPackageManagerExecutable,
|
|
206
|
-
installDependencies,
|
|
207
|
-
isEmpty,
|
|
208
|
-
isPackageInstalled,
|
|
209
|
-
setName
|
|
210
66
|
});
|
|
211
|
-
//# sourceMappingURL=package-manager.cjs.map
|
|
@@ -1,114 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* @example
|
|
9
|
-
* import { formatTargetDir } from "@settlemint/sdk-utils/package-manager";
|
|
10
|
-
*
|
|
11
|
-
* const formatted = formatTargetDir("/path/to/dir/ "); // "/path/to/dir"
|
|
12
|
-
*/
|
|
13
|
-
declare function formatTargetDir(targetDir: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a directory is empty or contains only a .git folder
|
|
16
|
-
*
|
|
17
|
-
* @param path - The directory path to check
|
|
18
|
-
* @returns True if directory is empty or contains only .git, false otherwise
|
|
19
|
-
* @example
|
|
20
|
-
* import { isEmpty } from "@settlemint/sdk-utils/package-manager";
|
|
21
|
-
*
|
|
22
|
-
* if (await isEmpty("/path/to/dir")) {
|
|
23
|
-
* // Directory is empty
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
declare function isEmpty(path: string): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Removes all contents of a directory except the .git folder
|
|
29
|
-
*
|
|
30
|
-
* @param dir - The directory path to empty
|
|
31
|
-
* @example
|
|
32
|
-
* import { emptyDir } from "@settlemint/sdk-utils/package-manager";
|
|
33
|
-
*
|
|
34
|
-
* await emptyDir("/path/to/dir"); // Removes all contents except .git
|
|
35
|
-
*/
|
|
36
|
-
declare function emptyDir(dir: string): Promise<void>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Detects the package manager used in the current project
|
|
40
|
-
*
|
|
41
|
-
* @param targetDir - The directory to check for package manager (optional, defaults to process.cwd())
|
|
42
|
-
* @returns The name of the package manager
|
|
43
|
-
* @example
|
|
44
|
-
* import { getPackageManager } from "@settlemint/sdk-utils/package-manager";
|
|
45
|
-
*
|
|
46
|
-
* const packageManager = await getPackageManager();
|
|
47
|
-
* console.log(`Using ${packageManager}`);
|
|
48
|
-
*/
|
|
49
|
-
declare function getPackageManager(targetDir?: string): Promise<AgentName>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves the executable command and arguments for the package manager
|
|
53
|
-
*
|
|
54
|
-
* @param targetDir - The directory to check for package manager (optional, defaults to process.cwd())
|
|
55
|
-
* @returns An object containing the command and arguments for the package manager
|
|
56
|
-
* @example
|
|
57
|
-
* import { getPackageManagerExecutable } from "@settlemint/sdk-utils/package-manager";
|
|
58
|
-
*
|
|
59
|
-
* const { command, args } = await getPackageManagerExecutable();
|
|
60
|
-
* console.log(`Using ${command} with args: ${args.join(" ")}`);
|
|
61
|
-
*/
|
|
62
|
-
declare function getPackageManagerExecutable(targetDir?: string): Promise<{
|
|
63
|
-
command: string;
|
|
64
|
-
args: string[];
|
|
65
|
-
}>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Installs one or more packages as dependencies using the detected package manager
|
|
69
|
-
*
|
|
70
|
-
* @param pkgs - A single package name or array of package names to install
|
|
71
|
-
* @param cwd - The directory to run the installation in
|
|
72
|
-
* @returns A promise that resolves when installation is complete
|
|
73
|
-
* @throws If package installation fails
|
|
74
|
-
* @example
|
|
75
|
-
* import { installDependencies } from "@settlemint/sdk-utils/package-manager";
|
|
76
|
-
*
|
|
77
|
-
* // Install a single package
|
|
78
|
-
* await installDependencies("express");
|
|
79
|
-
*
|
|
80
|
-
* // Install multiple packages
|
|
81
|
-
* await installDependencies(["express", "cors"]);
|
|
82
|
-
*/
|
|
83
|
-
declare function installDependencies(pkgs: string | string[], cwd?: string): Promise<void>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Checks if a package is installed in the project's dependencies, devDependencies, or peerDependencies.
|
|
87
|
-
*
|
|
88
|
-
* @param name - The name of the package to check
|
|
89
|
-
* @param path - The path to the project root directory. If not provided, will be automatically determined
|
|
90
|
-
* @returns Whether the package is installed
|
|
91
|
-
* @throws If unable to read or parse the package.json file
|
|
92
|
-
* @example
|
|
93
|
-
* import { isPackageInstalled } from "@settlemint/sdk-utils/package-manager";
|
|
94
|
-
*
|
|
95
|
-
* const isInstalled = await isPackageInstalled("@settlemint/sdk-utils");
|
|
96
|
-
* console.log(`@settlemint/sdk-utils is installed: ${isInstalled}`);
|
|
97
|
-
*/
|
|
98
|
-
declare function isPackageInstalled(name: string, path?: string): Promise<boolean>;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Sets the name field in the package.json file
|
|
102
|
-
*
|
|
103
|
-
* @param name - The new name to set in the package.json file
|
|
104
|
-
* @param path - The path to the project root directory. If not provided, will be automatically determined
|
|
105
|
-
* @returns A promise that resolves when the package.json has been updated
|
|
106
|
-
* @throws If unable to read, update or save the package.json file
|
|
107
|
-
* @example
|
|
108
|
-
* import { setName } from "@settlemint/sdk-utils/package-manager";
|
|
109
|
-
*
|
|
110
|
-
* await setName("my-new-project-name");
|
|
111
|
-
*/
|
|
112
|
-
declare function setName(name: string, path?: string): Promise<void>;
|
|
113
|
-
|
|
114
|
-
export { emptyDir, formatTargetDir, getPackageManager, getPackageManagerExecutable, installDependencies, isEmpty, isPackageInstalled, setName };
|
|
1
|
+
import { getPackageManager } from "./package-manager/get-package-manager.js";
|
|
2
|
+
import { getPackageManagerExecutable } from "./package-manager/get-package-manager-executable.js";
|
|
3
|
+
import { installDependencies } from "./package-manager/install-dependencies.js";
|
|
4
|
+
import { isPackageInstalled } from "./package-manager/is-package-installed.js";
|
|
5
|
+
import { setName } from "./package-manager/set-name.js";
|
|
6
|
+
export * from "./package-manager/download-and-extract.js";
|
|
7
|
+
export { getPackageManager, getPackageManagerExecutable, installDependencies, isPackageInstalled, setName };
|
|
@@ -1,114 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* @example
|
|
9
|
-
* import { formatTargetDir } from "@settlemint/sdk-utils/package-manager";
|
|
10
|
-
*
|
|
11
|
-
* const formatted = formatTargetDir("/path/to/dir/ "); // "/path/to/dir"
|
|
12
|
-
*/
|
|
13
|
-
declare function formatTargetDir(targetDir: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a directory is empty or contains only a .git folder
|
|
16
|
-
*
|
|
17
|
-
* @param path - The directory path to check
|
|
18
|
-
* @returns True if directory is empty or contains only .git, false otherwise
|
|
19
|
-
* @example
|
|
20
|
-
* import { isEmpty } from "@settlemint/sdk-utils/package-manager";
|
|
21
|
-
*
|
|
22
|
-
* if (await isEmpty("/path/to/dir")) {
|
|
23
|
-
* // Directory is empty
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
declare function isEmpty(path: string): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Removes all contents of a directory except the .git folder
|
|
29
|
-
*
|
|
30
|
-
* @param dir - The directory path to empty
|
|
31
|
-
* @example
|
|
32
|
-
* import { emptyDir } from "@settlemint/sdk-utils/package-manager";
|
|
33
|
-
*
|
|
34
|
-
* await emptyDir("/path/to/dir"); // Removes all contents except .git
|
|
35
|
-
*/
|
|
36
|
-
declare function emptyDir(dir: string): Promise<void>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Detects the package manager used in the current project
|
|
40
|
-
*
|
|
41
|
-
* @param targetDir - The directory to check for package manager (optional, defaults to process.cwd())
|
|
42
|
-
* @returns The name of the package manager
|
|
43
|
-
* @example
|
|
44
|
-
* import { getPackageManager } from "@settlemint/sdk-utils/package-manager";
|
|
45
|
-
*
|
|
46
|
-
* const packageManager = await getPackageManager();
|
|
47
|
-
* console.log(`Using ${packageManager}`);
|
|
48
|
-
*/
|
|
49
|
-
declare function getPackageManager(targetDir?: string): Promise<AgentName>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves the executable command and arguments for the package manager
|
|
53
|
-
*
|
|
54
|
-
* @param targetDir - The directory to check for package manager (optional, defaults to process.cwd())
|
|
55
|
-
* @returns An object containing the command and arguments for the package manager
|
|
56
|
-
* @example
|
|
57
|
-
* import { getPackageManagerExecutable } from "@settlemint/sdk-utils/package-manager";
|
|
58
|
-
*
|
|
59
|
-
* const { command, args } = await getPackageManagerExecutable();
|
|
60
|
-
* console.log(`Using ${command} with args: ${args.join(" ")}`);
|
|
61
|
-
*/
|
|
62
|
-
declare function getPackageManagerExecutable(targetDir?: string): Promise<{
|
|
63
|
-
command: string;
|
|
64
|
-
args: string[];
|
|
65
|
-
}>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Installs one or more packages as dependencies using the detected package manager
|
|
69
|
-
*
|
|
70
|
-
* @param pkgs - A single package name or array of package names to install
|
|
71
|
-
* @param cwd - The directory to run the installation in
|
|
72
|
-
* @returns A promise that resolves when installation is complete
|
|
73
|
-
* @throws If package installation fails
|
|
74
|
-
* @example
|
|
75
|
-
* import { installDependencies } from "@settlemint/sdk-utils/package-manager";
|
|
76
|
-
*
|
|
77
|
-
* // Install a single package
|
|
78
|
-
* await installDependencies("express");
|
|
79
|
-
*
|
|
80
|
-
* // Install multiple packages
|
|
81
|
-
* await installDependencies(["express", "cors"]);
|
|
82
|
-
*/
|
|
83
|
-
declare function installDependencies(pkgs: string | string[], cwd?: string): Promise<void>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Checks if a package is installed in the project's dependencies, devDependencies, or peerDependencies.
|
|
87
|
-
*
|
|
88
|
-
* @param name - The name of the package to check
|
|
89
|
-
* @param path - The path to the project root directory. If not provided, will be automatically determined
|
|
90
|
-
* @returns Whether the package is installed
|
|
91
|
-
* @throws If unable to read or parse the package.json file
|
|
92
|
-
* @example
|
|
93
|
-
* import { isPackageInstalled } from "@settlemint/sdk-utils/package-manager";
|
|
94
|
-
*
|
|
95
|
-
* const isInstalled = await isPackageInstalled("@settlemint/sdk-utils");
|
|
96
|
-
* console.log(`@settlemint/sdk-utils is installed: ${isInstalled}`);
|
|
97
|
-
*/
|
|
98
|
-
declare function isPackageInstalled(name: string, path?: string): Promise<boolean>;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Sets the name field in the package.json file
|
|
102
|
-
*
|
|
103
|
-
* @param name - The new name to set in the package.json file
|
|
104
|
-
* @param path - The path to the project root directory. If not provided, will be automatically determined
|
|
105
|
-
* @returns A promise that resolves when the package.json has been updated
|
|
106
|
-
* @throws If unable to read, update or save the package.json file
|
|
107
|
-
* @example
|
|
108
|
-
* import { setName } from "@settlemint/sdk-utils/package-manager";
|
|
109
|
-
*
|
|
110
|
-
* await setName("my-new-project-name");
|
|
111
|
-
*/
|
|
112
|
-
declare function setName(name: string, path?: string): Promise<void>;
|
|
113
|
-
|
|
114
|
-
export { emptyDir, formatTargetDir, getPackageManager, getPackageManagerExecutable, installDependencies, isEmpty, isPackageInstalled, setName };
|
|
1
|
+
import { getPackageManager } from "./package-manager/get-package-manager.js";
|
|
2
|
+
import { getPackageManagerExecutable } from "./package-manager/get-package-manager-executable.js";
|
|
3
|
+
import { installDependencies } from "./package-manager/install-dependencies.js";
|
|
4
|
+
import { isPackageInstalled } from "./package-manager/is-package-installed.js";
|
|
5
|
+
import { setName } from "./package-manager/set-name.js";
|
|
6
|
+
export * from "./package-manager/download-and-extract.js";
|
|
7
|
+
export { getPackageManager, getPackageManagerExecutable, installDependencies, isPackageInstalled, setName };
|