@rg-dev/stdlib 1.0.53 → 1.0.54
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/lib/common-env.cjs +12 -0
- package/lib/common-env.d.cts +2 -1
- package/lib/common-env.d.ts +2 -1
- package/lib/common-env.js +12 -0
- package/lib/node-download.cjs +4 -0
- package/lib/node-download.d.cts +2 -0
- package/lib/node-download.d.ts +2 -0
- package/lib/node-download.js +4 -0
- package/lib/node-env.cjs +70 -10
- package/lib/node-env.d.cts +70 -1
- package/lib/node-env.d.ts +70 -1
- package/lib/node-env.js +79 -19
- package/package.json +5 -7
package/lib/common-env.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(common_env_exports, {
|
|
|
45
45
|
isNonEmptyString: () => isNonEmptyString,
|
|
46
46
|
isNumber: () => isNumber,
|
|
47
47
|
isRunningOnServer: () => isRunningOnServer,
|
|
48
|
+
lazyValue: () => lazyValue,
|
|
48
49
|
promiseRetry: () => promiseRetry,
|
|
49
50
|
promiseWithTimeout: () => promiseWithTimeout,
|
|
50
51
|
sleep: () => sleep,
|
|
@@ -259,3 +260,14 @@ function isPromise(value) {
|
|
|
259
260
|
function isNonEmptyString(str) {
|
|
260
261
|
return typeof str == "string" && str.trim().length > 0;
|
|
261
262
|
}
|
|
263
|
+
function lazyValue(function_) {
|
|
264
|
+
let isCalled = false;
|
|
265
|
+
let result = void 0;
|
|
266
|
+
return () => {
|
|
267
|
+
if (!isCalled) {
|
|
268
|
+
isCalled = true;
|
|
269
|
+
result = function_();
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
272
|
+
};
|
|
273
|
+
}
|
package/lib/common-env.d.cts
CHANGED
|
@@ -75,5 +75,6 @@ declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Erro
|
|
|
75
75
|
declare function isRunningOnServer(): boolean;
|
|
76
76
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
77
77
|
declare function isNonEmptyString(str?: string): boolean;
|
|
78
|
+
declare function lazyValue<T = unknown>(function_: () => T): () => T;
|
|
78
79
|
|
|
79
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
80
|
+
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, lazyValue, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.d.ts
CHANGED
|
@@ -75,5 +75,6 @@ declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Erro
|
|
|
75
75
|
declare function isRunningOnServer(): boolean;
|
|
76
76
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
77
77
|
declare function isNonEmptyString(str?: string): boolean;
|
|
78
|
+
declare function lazyValue<T = unknown>(function_: () => T): () => T;
|
|
78
79
|
|
|
79
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
80
|
+
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, lazyValue, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.js
CHANGED
|
@@ -223,6 +223,17 @@ function isPromise(value) {
|
|
|
223
223
|
function isNonEmptyString(str) {
|
|
224
224
|
return typeof str == "string" && str.trim().length > 0;
|
|
225
225
|
}
|
|
226
|
+
function lazyValue(function_) {
|
|
227
|
+
let isCalled = false;
|
|
228
|
+
let result = void 0;
|
|
229
|
+
return () => {
|
|
230
|
+
if (!isCalled) {
|
|
231
|
+
isCalled = true;
|
|
232
|
+
result = function_();
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
226
237
|
export {
|
|
227
238
|
Optional,
|
|
228
239
|
StringBuilder,
|
|
@@ -235,6 +246,7 @@ export {
|
|
|
235
246
|
isNonEmptyString,
|
|
236
247
|
isNumber,
|
|
237
248
|
isRunningOnServer,
|
|
249
|
+
lazyValue,
|
|
238
250
|
promiseRetry,
|
|
239
251
|
promiseWithTimeout,
|
|
240
252
|
sleep,
|
package/lib/node-download.cjs
CHANGED
|
@@ -6182,12 +6182,16 @@ var init_src = __esm({
|
|
|
6182
6182
|
// src/node-download.ts
|
|
6183
6183
|
var node_download_exports = {};
|
|
6184
6184
|
__export(node_download_exports, {
|
|
6185
|
+
VERSION: () => VERSION,
|
|
6185
6186
|
downloadFile: () => downloadFile
|
|
6186
6187
|
});
|
|
6187
6188
|
module.exports = __toCommonJS(node_download_exports);
|
|
6188
6189
|
var fs2 = __toESM(require("fs"), 1);
|
|
6189
6190
|
var import_stream = require("stream");
|
|
6190
6191
|
|
|
6192
|
+
// src/index.ts
|
|
6193
|
+
var VERSION = "1";
|
|
6194
|
+
|
|
6191
6195
|
// src/common-env.ts
|
|
6192
6196
|
async function catchInline(cb) {
|
|
6193
6197
|
try {
|
package/lib/node-download.d.cts
CHANGED
package/lib/node-download.d.ts
CHANGED
package/lib/node-download.js
CHANGED
|
@@ -6188,6 +6188,9 @@ var init_src = __esm({
|
|
|
6188
6188
|
import * as fs2 from "fs";
|
|
6189
6189
|
import { Readable } from "stream";
|
|
6190
6190
|
|
|
6191
|
+
// src/index.ts
|
|
6192
|
+
var VERSION = "1";
|
|
6193
|
+
|
|
6191
6194
|
// src/common-env.ts
|
|
6192
6195
|
async function catchInline(cb) {
|
|
6193
6196
|
try {
|
|
@@ -6237,6 +6240,7 @@ function downloadFile(url, destination, headers) {
|
|
|
6237
6240
|
);
|
|
6238
6241
|
}
|
|
6239
6242
|
export {
|
|
6243
|
+
VERSION,
|
|
6240
6244
|
downloadFile
|
|
6241
6245
|
};
|
|
6242
6246
|
/*! Bundled license information:
|
package/lib/node-env.cjs
CHANGED
|
@@ -51,7 +51,7 @@ var require_command_exists = __commonJS({
|
|
|
51
51
|
var exec = require("child_process").exec;
|
|
52
52
|
var execSync = require("child_process").execSync;
|
|
53
53
|
var fs2 = require("fs");
|
|
54
|
-
var
|
|
54
|
+
var path3 = require("path");
|
|
55
55
|
var access = fs2.access;
|
|
56
56
|
var accessSync = fs2.accessSync;
|
|
57
57
|
var constants = fs2.constants || fs2;
|
|
@@ -155,8 +155,8 @@ var require_command_exists = __commonJS({
|
|
|
155
155
|
cleanInput = function(s) {
|
|
156
156
|
var isPathName = /[\\]/.test(s);
|
|
157
157
|
if (isPathName) {
|
|
158
|
-
var dirname = '"' +
|
|
159
|
-
var basename = '"' +
|
|
158
|
+
var dirname = '"' + path3.dirname(s) + '"';
|
|
159
|
+
var basename = '"' + path3.basename(s) + '"';
|
|
160
160
|
return dirname + ":" + basename;
|
|
161
161
|
}
|
|
162
162
|
return '"' + s + '"';
|
|
@@ -211,6 +211,7 @@ __export(node_env_exports, {
|
|
|
211
211
|
chmodPlusX: () => chmodPlusX,
|
|
212
212
|
createTempDir: () => createTempDir,
|
|
213
213
|
createTempFilePath: () => createTempFilePath,
|
|
214
|
+
getEnvPaths: () => getEnvPaths,
|
|
214
215
|
isWindows: () => isWindows,
|
|
215
216
|
throwIfDirNotEmpty: () => throwIfDirNotEmpty,
|
|
216
217
|
typedSystemArch: () => typedSystemArch
|
|
@@ -342,7 +343,66 @@ var SSEClient = class extends import_events.EventEmitter {
|
|
|
342
343
|
// src/index.ts
|
|
343
344
|
var VERSION = "1";
|
|
344
345
|
|
|
346
|
+
// node_modules/env-paths/index.js
|
|
347
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
348
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
349
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
350
|
+
var homedir = import_node_os.default.homedir();
|
|
351
|
+
var tmpdir = import_node_os.default.tmpdir();
|
|
352
|
+
var { env } = import_node_process.default;
|
|
353
|
+
var macos = (name) => {
|
|
354
|
+
const library = import_node_path.default.join(homedir, "Library");
|
|
355
|
+
return {
|
|
356
|
+
data: import_node_path.default.join(library, "Application Support", name),
|
|
357
|
+
config: import_node_path.default.join(library, "Preferences", name),
|
|
358
|
+
cache: import_node_path.default.join(library, "Caches", name),
|
|
359
|
+
log: import_node_path.default.join(library, "Logs", name),
|
|
360
|
+
temp: import_node_path.default.join(tmpdir, name)
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
var windows = (name) => {
|
|
364
|
+
const appData = env.APPDATA || import_node_path.default.join(homedir, "AppData", "Roaming");
|
|
365
|
+
const localAppData = env.LOCALAPPDATA || import_node_path.default.join(homedir, "AppData", "Local");
|
|
366
|
+
return {
|
|
367
|
+
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
|
|
368
|
+
data: import_node_path.default.join(localAppData, name, "Data"),
|
|
369
|
+
config: import_node_path.default.join(appData, name, "Config"),
|
|
370
|
+
cache: import_node_path.default.join(localAppData, name, "Cache"),
|
|
371
|
+
log: import_node_path.default.join(localAppData, name, "Log"),
|
|
372
|
+
temp: import_node_path.default.join(tmpdir, name)
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
var linux = (name) => {
|
|
376
|
+
const username = import_node_path.default.basename(homedir);
|
|
377
|
+
return {
|
|
378
|
+
data: import_node_path.default.join(env.XDG_DATA_HOME || import_node_path.default.join(homedir, ".local", "share"), name),
|
|
379
|
+
config: import_node_path.default.join(env.XDG_CONFIG_HOME || import_node_path.default.join(homedir, ".config"), name),
|
|
380
|
+
cache: import_node_path.default.join(env.XDG_CACHE_HOME || import_node_path.default.join(homedir, ".cache"), name),
|
|
381
|
+
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
|
|
382
|
+
log: import_node_path.default.join(env.XDG_STATE_HOME || import_node_path.default.join(homedir, ".local", "state"), name),
|
|
383
|
+
temp: import_node_path.default.join(tmpdir, username, name)
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
function envPaths(name, { suffix = "nodejs" } = {}) {
|
|
387
|
+
if (typeof name !== "string") {
|
|
388
|
+
throw new TypeError(`Expected a string, got ${typeof name}`);
|
|
389
|
+
}
|
|
390
|
+
if (suffix) {
|
|
391
|
+
name += `-${suffix}`;
|
|
392
|
+
}
|
|
393
|
+
if (import_node_process.default.platform === "darwin") {
|
|
394
|
+
return macos(name);
|
|
395
|
+
}
|
|
396
|
+
if (import_node_process.default.platform === "win32") {
|
|
397
|
+
return windows(name);
|
|
398
|
+
}
|
|
399
|
+
return linux(name);
|
|
400
|
+
}
|
|
401
|
+
|
|
345
402
|
// src/node-env.ts
|
|
403
|
+
function getEnvPaths(name, options) {
|
|
404
|
+
return envPaths(name, options);
|
|
405
|
+
}
|
|
346
406
|
function isWindows() {
|
|
347
407
|
return import_os.default.platform() === "win32";
|
|
348
408
|
}
|
|
@@ -362,14 +422,14 @@ function chmodPlusX(filePath) {
|
|
|
362
422
|
console.error(`Failed to chmod +x ${filePath}:`, String((e == null ? void 0 : e.message) || e));
|
|
363
423
|
}
|
|
364
424
|
}
|
|
365
|
-
async function checkIfDirExistsOrThrow(
|
|
366
|
-
if (!
|
|
367
|
-
|
|
368
|
-
if (!await fs.pathExists(
|
|
369
|
-
throw new Error(`path ${
|
|
425
|
+
async function checkIfDirExistsOrThrow(path3) {
|
|
426
|
+
if (!path3) throw "path is empty";
|
|
427
|
+
path3 = removeQuotes(path3);
|
|
428
|
+
if (!await fs.pathExists(path3)) {
|
|
429
|
+
throw new Error(`path ${path3} not exists`);
|
|
370
430
|
}
|
|
371
|
-
if (!(await fs.stat(
|
|
372
|
-
throw new Error(`${
|
|
431
|
+
if (!(await fs.stat(path3)).isDirectory()) {
|
|
432
|
+
throw new Error(`${path3} is a file, require dir`);
|
|
373
433
|
}
|
|
374
434
|
}
|
|
375
435
|
function createTempDir() {
|
package/lib/node-env.d.cts
CHANGED
|
@@ -28,6 +28,75 @@ declare class SSEClient extends EventEmitter {
|
|
|
28
28
|
close(): void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
interface Options {
|
|
32
|
+
/**
|
|
33
|
+
__Don't use this option unless you really have to!__
|
|
34
|
+
|
|
35
|
+
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
|
|
36
|
+
|
|
37
|
+
@default 'nodejs'
|
|
38
|
+
*/
|
|
39
|
+
readonly suffix?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Paths {
|
|
43
|
+
/**
|
|
44
|
+
Directory for data files.
|
|
45
|
+
|
|
46
|
+
Example locations (with the default `nodejs` suffix):
|
|
47
|
+
|
|
48
|
+
- macOS: `~/Library/Application Support/MyApp-nodejs`
|
|
49
|
+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
|
|
50
|
+
- Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
|
|
51
|
+
*/
|
|
52
|
+
readonly data: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
Directory for data files.
|
|
56
|
+
|
|
57
|
+
Example locations (with the default `nodejs` suffix):
|
|
58
|
+
|
|
59
|
+
- macOS: `~/Library/Preferences/MyApp-nodejs`
|
|
60
|
+
- Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
|
|
61
|
+
- Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
|
|
62
|
+
*/
|
|
63
|
+
readonly config: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Directory for non-essential data files.
|
|
67
|
+
|
|
68
|
+
Example locations (with the default `nodejs` suffix):
|
|
69
|
+
|
|
70
|
+
- macOS: `~/Library/Caches/MyApp-nodejs`
|
|
71
|
+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
|
|
72
|
+
- Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
|
|
73
|
+
*/
|
|
74
|
+
readonly cache: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
Directory for log files.
|
|
78
|
+
|
|
79
|
+
Example locations (with the default `nodejs` suffix):
|
|
80
|
+
|
|
81
|
+
- macOS: `~/Library/Logs/MyApp-nodejs`
|
|
82
|
+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
|
|
83
|
+
- Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
|
|
84
|
+
*/
|
|
85
|
+
readonly log: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
Directory for temporary files.
|
|
89
|
+
|
|
90
|
+
Example locations (with the default `nodejs` suffix):
|
|
91
|
+
|
|
92
|
+
- macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
|
|
93
|
+
- Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
|
|
94
|
+
- Linux: `/tmp/USERNAME/MyApp-nodejs`
|
|
95
|
+
*/
|
|
96
|
+
readonly temp: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare function getEnvPaths(name: string, options?: Options): Paths;
|
|
31
100
|
declare function isWindows(): boolean;
|
|
32
101
|
type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";
|
|
33
102
|
declare function typedSystemArch(): SystemArch;
|
|
@@ -42,4 +111,4 @@ declare function throwIfDirNotEmpty(dirPath: string): Promise<void>;
|
|
|
42
111
|
declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
|
|
43
112
|
declare function checkIfFileExistsOrThrow(thePath: string): Promise<void>;
|
|
44
113
|
|
|
45
|
-
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
|
|
114
|
+
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, getEnvPaths, isWindows, throwIfDirNotEmpty, typedSystemArch };
|
package/lib/node-env.d.ts
CHANGED
|
@@ -28,6 +28,75 @@ declare class SSEClient extends EventEmitter {
|
|
|
28
28
|
close(): void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
interface Options {
|
|
32
|
+
/**
|
|
33
|
+
__Don't use this option unless you really have to!__
|
|
34
|
+
|
|
35
|
+
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
|
|
36
|
+
|
|
37
|
+
@default 'nodejs'
|
|
38
|
+
*/
|
|
39
|
+
readonly suffix?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Paths {
|
|
43
|
+
/**
|
|
44
|
+
Directory for data files.
|
|
45
|
+
|
|
46
|
+
Example locations (with the default `nodejs` suffix):
|
|
47
|
+
|
|
48
|
+
- macOS: `~/Library/Application Support/MyApp-nodejs`
|
|
49
|
+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
|
|
50
|
+
- Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
|
|
51
|
+
*/
|
|
52
|
+
readonly data: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
Directory for data files.
|
|
56
|
+
|
|
57
|
+
Example locations (with the default `nodejs` suffix):
|
|
58
|
+
|
|
59
|
+
- macOS: `~/Library/Preferences/MyApp-nodejs`
|
|
60
|
+
- Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
|
|
61
|
+
- Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
|
|
62
|
+
*/
|
|
63
|
+
readonly config: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Directory for non-essential data files.
|
|
67
|
+
|
|
68
|
+
Example locations (with the default `nodejs` suffix):
|
|
69
|
+
|
|
70
|
+
- macOS: `~/Library/Caches/MyApp-nodejs`
|
|
71
|
+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
|
|
72
|
+
- Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
|
|
73
|
+
*/
|
|
74
|
+
readonly cache: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
Directory for log files.
|
|
78
|
+
|
|
79
|
+
Example locations (with the default `nodejs` suffix):
|
|
80
|
+
|
|
81
|
+
- macOS: `~/Library/Logs/MyApp-nodejs`
|
|
82
|
+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
|
|
83
|
+
- Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
|
|
84
|
+
*/
|
|
85
|
+
readonly log: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
Directory for temporary files.
|
|
89
|
+
|
|
90
|
+
Example locations (with the default `nodejs` suffix):
|
|
91
|
+
|
|
92
|
+
- macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
|
|
93
|
+
- Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
|
|
94
|
+
- Linux: `/tmp/USERNAME/MyApp-nodejs`
|
|
95
|
+
*/
|
|
96
|
+
readonly temp: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare function getEnvPaths(name: string, options?: Options): Paths;
|
|
31
100
|
declare function isWindows(): boolean;
|
|
32
101
|
type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";
|
|
33
102
|
declare function typedSystemArch(): SystemArch;
|
|
@@ -42,4 +111,4 @@ declare function throwIfDirNotEmpty(dirPath: string): Promise<void>;
|
|
|
42
111
|
declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
|
|
43
112
|
declare function checkIfFileExistsOrThrow(thePath: string): Promise<void>;
|
|
44
113
|
|
|
45
|
-
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
|
|
114
|
+
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, getEnvPaths, isWindows, throwIfDirNotEmpty, typedSystemArch };
|
package/lib/node-env.js
CHANGED
|
@@ -52,7 +52,7 @@ var require_command_exists = __commonJS({
|
|
|
52
52
|
var exec = __require("child_process").exec;
|
|
53
53
|
var execSync = __require("child_process").execSync;
|
|
54
54
|
var fs2 = __require("fs");
|
|
55
|
-
var
|
|
55
|
+
var path3 = __require("path");
|
|
56
56
|
var access = fs2.access;
|
|
57
57
|
var accessSync = fs2.accessSync;
|
|
58
58
|
var constants = fs2.constants || fs2;
|
|
@@ -156,8 +156,8 @@ var require_command_exists = __commonJS({
|
|
|
156
156
|
cleanInput = function(s) {
|
|
157
157
|
var isPathName = /[\\]/.test(s);
|
|
158
158
|
if (isPathName) {
|
|
159
|
-
var dirname = '"' +
|
|
160
|
-
var basename = '"' +
|
|
159
|
+
var dirname = '"' + path3.dirname(s) + '"';
|
|
160
|
+
var basename = '"' + path3.basename(s) + '"';
|
|
161
161
|
return dirname + ":" + basename;
|
|
162
162
|
}
|
|
163
163
|
return '"' + s + '"';
|
|
@@ -203,8 +203,8 @@ var require_command_exists2 = __commonJS({
|
|
|
203
203
|
// src/node-env.ts
|
|
204
204
|
var import_command_exists = __toESM(require_command_exists2(), 1);
|
|
205
205
|
import * as fs from "fs-extra";
|
|
206
|
-
import
|
|
207
|
-
import
|
|
206
|
+
import os2 from "os";
|
|
207
|
+
import path2 from "path";
|
|
208
208
|
|
|
209
209
|
// src/SSEResponse.ts
|
|
210
210
|
var SSEResponse = class {
|
|
@@ -327,19 +327,78 @@ var SSEClient = class extends EventEmitter {
|
|
|
327
327
|
// src/index.ts
|
|
328
328
|
var VERSION = "1";
|
|
329
329
|
|
|
330
|
+
// node_modules/env-paths/index.js
|
|
331
|
+
import path from "path";
|
|
332
|
+
import os from "os";
|
|
333
|
+
import process2 from "process";
|
|
334
|
+
var homedir = os.homedir();
|
|
335
|
+
var tmpdir = os.tmpdir();
|
|
336
|
+
var { env } = process2;
|
|
337
|
+
var macos = (name) => {
|
|
338
|
+
const library = path.join(homedir, "Library");
|
|
339
|
+
return {
|
|
340
|
+
data: path.join(library, "Application Support", name),
|
|
341
|
+
config: path.join(library, "Preferences", name),
|
|
342
|
+
cache: path.join(library, "Caches", name),
|
|
343
|
+
log: path.join(library, "Logs", name),
|
|
344
|
+
temp: path.join(tmpdir, name)
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
var windows = (name) => {
|
|
348
|
+
const appData = env.APPDATA || path.join(homedir, "AppData", "Roaming");
|
|
349
|
+
const localAppData = env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
|
|
350
|
+
return {
|
|
351
|
+
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
|
|
352
|
+
data: path.join(localAppData, name, "Data"),
|
|
353
|
+
config: path.join(appData, name, "Config"),
|
|
354
|
+
cache: path.join(localAppData, name, "Cache"),
|
|
355
|
+
log: path.join(localAppData, name, "Log"),
|
|
356
|
+
temp: path.join(tmpdir, name)
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
var linux = (name) => {
|
|
360
|
+
const username = path.basename(homedir);
|
|
361
|
+
return {
|
|
362
|
+
data: path.join(env.XDG_DATA_HOME || path.join(homedir, ".local", "share"), name),
|
|
363
|
+
config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, ".config"), name),
|
|
364
|
+
cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, ".cache"), name),
|
|
365
|
+
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
|
|
366
|
+
log: path.join(env.XDG_STATE_HOME || path.join(homedir, ".local", "state"), name),
|
|
367
|
+
temp: path.join(tmpdir, username, name)
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
function envPaths(name, { suffix = "nodejs" } = {}) {
|
|
371
|
+
if (typeof name !== "string") {
|
|
372
|
+
throw new TypeError(`Expected a string, got ${typeof name}`);
|
|
373
|
+
}
|
|
374
|
+
if (suffix) {
|
|
375
|
+
name += `-${suffix}`;
|
|
376
|
+
}
|
|
377
|
+
if (process2.platform === "darwin") {
|
|
378
|
+
return macos(name);
|
|
379
|
+
}
|
|
380
|
+
if (process2.platform === "win32") {
|
|
381
|
+
return windows(name);
|
|
382
|
+
}
|
|
383
|
+
return linux(name);
|
|
384
|
+
}
|
|
385
|
+
|
|
330
386
|
// src/node-env.ts
|
|
387
|
+
function getEnvPaths(name, options) {
|
|
388
|
+
return envPaths(name, options);
|
|
389
|
+
}
|
|
331
390
|
function isWindows() {
|
|
332
|
-
return
|
|
391
|
+
return os2.platform() === "win32";
|
|
333
392
|
}
|
|
334
393
|
function typedSystemArch() {
|
|
335
|
-
return
|
|
394
|
+
return os2.arch();
|
|
336
395
|
}
|
|
337
396
|
function chmodPlusX(filePath) {
|
|
338
|
-
if (
|
|
397
|
+
if (os2.platform() === "win32") {
|
|
339
398
|
return;
|
|
340
399
|
}
|
|
341
400
|
try {
|
|
342
|
-
const resolvedPath =
|
|
401
|
+
const resolvedPath = path2.resolve(filePath);
|
|
343
402
|
const stats = fs.statSync(resolvedPath);
|
|
344
403
|
const newMode = stats.mode | 73;
|
|
345
404
|
fs.chmodSync(resolvedPath, newMode);
|
|
@@ -347,21 +406,21 @@ function chmodPlusX(filePath) {
|
|
|
347
406
|
console.error(`Failed to chmod +x ${filePath}:`, String((e == null ? void 0 : e.message) || e));
|
|
348
407
|
}
|
|
349
408
|
}
|
|
350
|
-
async function checkIfDirExistsOrThrow(
|
|
351
|
-
if (!
|
|
352
|
-
|
|
353
|
-
if (!await fs.pathExists(
|
|
354
|
-
throw new Error(`path ${
|
|
409
|
+
async function checkIfDirExistsOrThrow(path3) {
|
|
410
|
+
if (!path3) throw "path is empty";
|
|
411
|
+
path3 = removeQuotes(path3);
|
|
412
|
+
if (!await fs.pathExists(path3)) {
|
|
413
|
+
throw new Error(`path ${path3} not exists`);
|
|
355
414
|
}
|
|
356
|
-
if (!(await fs.stat(
|
|
357
|
-
throw new Error(`${
|
|
415
|
+
if (!(await fs.stat(path3)).isDirectory()) {
|
|
416
|
+
throw new Error(`${path3} is a file, require dir`);
|
|
358
417
|
}
|
|
359
418
|
}
|
|
360
419
|
function createTempDir() {
|
|
361
|
-
const tmpDir =
|
|
420
|
+
const tmpDir = os2.tmpdir();
|
|
362
421
|
const timestamp = Date.now();
|
|
363
422
|
const tempDirName = `temp_dir_${timestamp}_${Math.random().toString(36).slice(2)}`;
|
|
364
|
-
const tempDirPath =
|
|
423
|
+
const tempDirPath = path2.join(tmpDir, tempDirName);
|
|
365
424
|
console.log("tempDir", tempDirPath);
|
|
366
425
|
fs.mkdirSync(tempDirPath);
|
|
367
426
|
return tempDirPath;
|
|
@@ -375,7 +434,7 @@ function createTempFilePath(ext) {
|
|
|
375
434
|
ext = void 0;
|
|
376
435
|
}
|
|
377
436
|
const name = `temp_file_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2)}${ext ? `.${ext}` : ""}`;
|
|
378
|
-
const fullPath =
|
|
437
|
+
const fullPath = path2.join(os2.tmpdir(), name);
|
|
379
438
|
return {
|
|
380
439
|
getName: () => fullPath,
|
|
381
440
|
cleanUp: () => {
|
|
@@ -429,6 +488,7 @@ export {
|
|
|
429
488
|
chmodPlusX,
|
|
430
489
|
createTempDir,
|
|
431
490
|
createTempFilePath,
|
|
491
|
+
getEnvPaths,
|
|
432
492
|
isWindows,
|
|
433
493
|
throwIfDirNotEmpty,
|
|
434
494
|
typedSystemArch
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rg-dev/stdlib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.54",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
7
|
"build": "tsup && node after-build.mjs",
|
|
8
|
-
"ts":"tsdown"
|
|
8
|
+
"ts": "tsdown"
|
|
9
9
|
},
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
@@ -34,14 +34,11 @@
|
|
|
34
34
|
"types": "./lib/index.d.ts",
|
|
35
35
|
"type": "module",
|
|
36
36
|
"exports": {
|
|
37
|
-
|
|
38
|
-
".":{
|
|
37
|
+
".": {
|
|
39
38
|
"import": "./lib/index.js",
|
|
40
39
|
"require": "./lib/index.cjs",
|
|
41
40
|
"types": "./lib/index.d.ts"
|
|
42
41
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
42
|
"./lib/trpc-helpers": {
|
|
46
43
|
"import": "./lib/trpc-helpers.js",
|
|
47
44
|
"require": "./lib/trpc-helpers.cjs",
|
|
@@ -74,7 +71,7 @@
|
|
|
74
71
|
"access": "public"
|
|
75
72
|
},
|
|
76
73
|
"devDependencies": {
|
|
77
|
-
"
|
|
74
|
+
"env-paths": "^3.0.0",
|
|
78
75
|
"@trpc/server": "^11.1.1",
|
|
79
76
|
"@types/command-exists": "^1.2.3",
|
|
80
77
|
"@types/express": "^5.0.6",
|
|
@@ -85,6 +82,7 @@
|
|
|
85
82
|
"express": "^5.1.0",
|
|
86
83
|
"node-fetch": "^3.3.2",
|
|
87
84
|
"superjson": "^2.2.6",
|
|
85
|
+
"tsdown": "^0.19.0",
|
|
88
86
|
"tsup": "^8.0.1",
|
|
89
87
|
"typescript": "^5.9.3"
|
|
90
88
|
}
|