@stryke/fs 0.33.32 → 0.33.34
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/CHANGELOG.md +18 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/buffer.cjs +60 -1
- package/dist/buffer.mjs +56 -1
- package/dist/buffer.mjs.map +1 -1
- package/dist/chmod-x.cjs +93 -1
- package/dist/chmod-x.mjs +87 -1
- package/dist/chmod-x.mjs.map +1 -1
- package/dist/command-exists.cjs +102 -1
- package/dist/command-exists.mjs +100 -1
- package/dist/command-exists.mjs.map +1 -1
- package/dist/compress.cjs +29 -1
- package/dist/compress.mjs +28 -1
- package/dist/compress.mjs.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/convert/src/array-buffer-to-string.cjs +19 -1
- package/dist/convert/src/array-buffer-to-string.mjs +18 -1
- package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
- package/dist/convert/src/to-array.cjs +15 -1
- package/dist/convert/src/to-array.mjs +14 -1
- package/dist/convert/src/to-array.mjs.map +1 -1
- package/dist/convert/src/uint8-array-to-string.cjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
- package/dist/copy-file.cjs +87 -1
- package/dist/copy-file.mjs +83 -1
- package/dist/copy-file.mjs.map +1 -1
- package/dist/exists.cjs +27 -1
- package/dist/exists.mjs +25 -1
- package/dist/exists.mjs.map +1 -1
- package/dist/get-parent-path.cjs +35 -1
- package/dist/get-parent-path.mjs +34 -1
- package/dist/get-parent-path.mjs.map +1 -1
- package/dist/get-workspace-root.cjs +158 -1
- package/dist/get-workspace-root.mjs +150 -1
- package/dist/get-workspace-root.mjs.map +1 -1
- package/dist/helpers/src/get-unique.cjs +14 -1
- package/dist/helpers/src/get-unique.mjs +13 -1
- package/dist/helpers/src/get-unique.mjs.map +1 -1
- package/dist/helpers.cjs +83 -1
- package/dist/helpers.mjs +77 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +122 -1
- package/dist/index.mjs +25 -1
- package/dist/install.cjs +35 -1
- package/dist/install.mjs +33 -1
- package/dist/install.mjs.map +1 -1
- package/dist/is-file.cjs +51 -1
- package/dist/is-file.mjs +47 -1
- package/dist/is-file.mjs.map +1 -1
- package/dist/json/src/storm-json.cjs +117 -1
- package/dist/json/src/storm-json.mjs +115 -1
- package/dist/json/src/storm-json.mjs.map +1 -1
- package/dist/json/src/utils/code-frames.cjs +77 -3
- package/dist/json/src/utils/code-frames.mjs +76 -3
- package/dist/json/src/utils/code-frames.mjs.map +1 -1
- package/dist/json/src/utils/parse-error.cjs +34 -1
- package/dist/json/src/utils/parse-error.mjs +33 -1
- package/dist/json/src/utils/parse-error.mjs.map +1 -1
- package/dist/json/src/utils/parse.cjs +45 -1
- package/dist/json/src/utils/parse.mjs +45 -1
- package/dist/json/src/utils/parse.mjs.map +1 -1
- package/dist/json/src/utils/stringify.cjs +67 -1
- package/dist/json/src/utils/stringify.mjs +67 -1
- package/dist/json/src/utils/stringify.mjs.map +1 -1
- package/dist/json/src/utils/strip-comments.cjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs.map +1 -1
- package/dist/json.cjs +74 -1
- package/dist/json.mjs +71 -1
- package/dist/json.mjs.map +1 -1
- package/dist/list-files.cjs +86 -1
- package/dist/list-files.mjs +79 -1
- package/dist/list-files.mjs.map +1 -1
- package/dist/package-fns.cjs +148 -1
- package/dist/package-fns.mjs +141 -1
- package/dist/package-fns.mjs.map +1 -1
- package/dist/path/src/append.cjs +57 -1
- package/dist/path/src/append.mjs +56 -1
- package/dist/path/src/append.mjs.map +1 -1
- package/dist/path/src/correct-path.cjs +138 -1
- package/dist/path/src/correct-path.mjs +134 -1
- package/dist/path/src/correct-path.mjs.map +1 -1
- package/dist/path/src/cwd.cjs +17 -1
- package/dist/path/src/cwd.mjs +16 -1
- package/dist/path/src/cwd.mjs.map +1 -1
- package/dist/path/src/file-path-fns.cjs +169 -1
- package/dist/path/src/file-path-fns.mjs +164 -1
- package/dist/path/src/file-path-fns.mjs.map +1 -1
- package/dist/path/src/is-parent-path.cjs +32 -1
- package/dist/path/src/is-parent-path.mjs +32 -1
- package/dist/path/src/is-parent-path.mjs.map +1 -1
- package/dist/path/src/is-root-dir.cjs +14 -1
- package/dist/path/src/is-root-dir.mjs +13 -1
- package/dist/path/src/is-root-dir.mjs.map +1 -1
- package/dist/path/src/is-type.cjs +68 -1
- package/dist/path/src/is-type.mjs +66 -1
- package/dist/path/src/is-type.mjs.map +1 -1
- package/dist/path/src/join-paths.cjs +106 -1
- package/dist/path/src/join-paths.mjs +106 -1
- package/dist/path/src/join-paths.mjs.map +1 -1
- package/dist/path/src/regex.cjs +18 -1
- package/dist/path/src/regex.mjs +11 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/replace.cjs +24 -1
- package/dist/path/src/replace.mjs +24 -1
- package/dist/path/src/replace.mjs.map +1 -1
- package/dist/path/src/resolve-parent-path.cjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs.map +1 -1
- package/dist/path/src/slash.cjs +15 -1
- package/dist/path/src/slash.mjs +14 -1
- package/dist/path/src/slash.mjs.map +1 -1
- package/dist/read-file.cjs +47 -1
- package/dist/read-file.mjs +43 -1
- package/dist/read-file.mjs.map +1 -1
- package/dist/registry.cjs +142 -1
- package/dist/registry.mjs +137 -1
- package/dist/registry.mjs.map +1 -1
- package/dist/remove-file.cjs +27 -1
- package/dist/remove-file.mjs +25 -1
- package/dist/remove-file.mjs.map +1 -1
- package/dist/resolve.cjs +228 -3
- package/dist/resolve.mjs +217 -3
- package/dist/resolve.mjs.map +1 -1
- package/dist/semver-fns.cjs +129 -1
- package/dist/semver-fns.mjs +119 -1
- package/dist/semver-fns.mjs.map +1 -1
- package/dist/string-format/src/package.cjs +92 -1
- package/dist/string-format/src/package.mjs +91 -1
- package/dist/string-format/src/package.mjs.map +1 -1
- package/dist/toml.cjs +66 -3
- package/dist/toml.mjs +61 -3
- package/dist/toml.mjs.map +1 -1
- package/dist/tsconfig.cjs +37 -1
- package/dist/tsconfig.mjs +35 -1
- package/dist/tsconfig.mjs.map +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +15 -1
- package/dist/type-checks/src/get-object-tag.mjs +14 -1
- package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
- package/dist/type-checks/src/index.cjs +14 -1
- package/dist/type-checks/src/index.mjs +16 -1
- package/dist/type-checks/src/is-buffer.cjs +12 -1
- package/dist/type-checks/src/is-buffer.mjs +11 -1
- package/dist/type-checks/src/is-buffer.mjs.map +1 -1
- package/dist/type-checks/src/is-collection.cjs +1 -1
- package/dist/type-checks/src/is-collection.mjs +3 -1
- package/dist/type-checks/src/is-empty.cjs +20 -1
- package/dist/type-checks/src/is-empty.mjs +20 -1
- package/dist/type-checks/src/is-empty.mjs.map +1 -1
- package/dist/type-checks/src/is-error.cjs +29 -1
- package/dist/type-checks/src/is-error.mjs +29 -1
- package/dist/type-checks/src/is-error.mjs.map +1 -1
- package/dist/type-checks/src/is-null.cjs +12 -1
- package/dist/type-checks/src/is-null.mjs +11 -1
- package/dist/type-checks/src/is-null.mjs.map +1 -1
- package/dist/type-checks/src/is-number.cjs +18 -1
- package/dist/type-checks/src/is-number.mjs +17 -1
- package/dist/type-checks/src/is-number.mjs.map +1 -1
- package/dist/type-checks/src/is-object.cjs +19 -1
- package/dist/type-checks/src/is-object.mjs +19 -1
- package/dist/type-checks/src/is-object.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +64 -1
- package/dist/type-checks/src/is-plain-object.mjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs.map +1 -1
- package/dist/type-checks/src/is-set.cjs +19 -1
- package/dist/type-checks/src/is-set.mjs +19 -1
- package/dist/type-checks/src/is-set.mjs.map +1 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/type-checks/src/type-detect.cjs +15 -1
- package/dist/type-checks/src/type-detect.mjs +16 -1
- package/dist/type-checks/src/type-detect.mjs.map +1 -1
- package/dist/types/src/base.cjs +6 -1
- package/dist/types/src/base.mjs +5 -1
- package/dist/types/src/base.mjs.map +1 -1
- package/dist/write-file.cjs +40 -1
- package/dist/write-file.mjs +38 -1
- package/dist/write-file.mjs.map +1 -1
- package/dist/yaml.cjs +29 -1
- package/dist/yaml.mjs +27 -1
- package/dist/yaml.mjs.map +1 -1
- package/package.json +6 -6
package/dist/registry.cjs
CHANGED
|
@@ -1 +1,142 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_get_workspace_root = require('./get-workspace-root.cjs');
|
|
3
|
+
let node_child_process = require("node:child_process");
|
|
4
|
+
let __antfu_install_pkg = require("@antfu/install-pkg");
|
|
5
|
+
let node_util = require("node:util");
|
|
6
|
+
|
|
7
|
+
//#region src/registry.ts
|
|
8
|
+
const parseNodeArgs = (args) => {
|
|
9
|
+
const { values, tokens } = (0, node_util.parseArgs)({
|
|
10
|
+
args,
|
|
11
|
+
strict: false,
|
|
12
|
+
tokens: true
|
|
13
|
+
});
|
|
14
|
+
let orphan = null;
|
|
15
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
16
|
+
const token = tokens[i];
|
|
17
|
+
if (token.kind === "option-terminator") break;
|
|
18
|
+
if (token.kind === "option") {
|
|
19
|
+
orphan = typeof token.value === "undefined" ? token : null;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (token.kind !== "positional") {
|
|
23
|
+
orphan = null;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (!orphan) continue;
|
|
27
|
+
if (orphan.name in values && typeof values[orphan.name] === "string") values[orphan.name] += ` ${token.value}`;
|
|
28
|
+
else values[orphan.name] = token.value;
|
|
29
|
+
}
|
|
30
|
+
return values;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Tokenizes the arguments string into an array of strings, supporting quoted
|
|
34
|
+
* values and escaped characters.
|
|
35
|
+
* Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401
|
|
36
|
+
*
|
|
37
|
+
* @param input - The arguments string to be tokenized.
|
|
38
|
+
* @returns An array of strings with the tokenized arguments.
|
|
39
|
+
*/
|
|
40
|
+
const tokenizeArgs = (input) => {
|
|
41
|
+
const args = [];
|
|
42
|
+
let isInString = false;
|
|
43
|
+
let willStartNewArg = true;
|
|
44
|
+
for (let i = 0; i < input.length; i++) {
|
|
45
|
+
let char = input[i];
|
|
46
|
+
if (char === "\\" && isInString) {
|
|
47
|
+
if (input.length === i + 1) throw new Error("Invalid escape character at the end.");
|
|
48
|
+
char = input[++i];
|
|
49
|
+
} else if (char === " " && !isInString) {
|
|
50
|
+
willStartNewArg = true;
|
|
51
|
+
continue;
|
|
52
|
+
} else if (char === "\"") {
|
|
53
|
+
isInString = !isInString;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (willStartNewArg) {
|
|
57
|
+
args.push(char);
|
|
58
|
+
willStartNewArg = false;
|
|
59
|
+
} else args[args.length - 1] += char;
|
|
60
|
+
}
|
|
61
|
+
if (isInString) throw new Error("Unterminated string");
|
|
62
|
+
return args;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Get the node options from the environment variable `NODE_OPTIONS` and returns
|
|
66
|
+
* them as an array of strings.
|
|
67
|
+
*
|
|
68
|
+
* @returns An array of strings with the node options.
|
|
69
|
+
*/
|
|
70
|
+
const getNodeOptionsArgs = () => {
|
|
71
|
+
if (!process.env.NODE_OPTIONS) return [];
|
|
72
|
+
return tokenizeArgs(process.env.NODE_OPTIONS);
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Stringify the arguments to be used in a command line. It will ignore any
|
|
76
|
+
* argument that has a value of `undefined`.
|
|
77
|
+
*
|
|
78
|
+
* @param args - The arguments to be stringified.
|
|
79
|
+
* @returns A string with the arguments.
|
|
80
|
+
*/
|
|
81
|
+
function formatNodeOptions(args) {
|
|
82
|
+
return Object.entries(args).map(([key, value]) => {
|
|
83
|
+
if (value === true) return `--${key}`;
|
|
84
|
+
if (value) return `--${key}=${value.includes(" ") && !value.startsWith("\"") ? JSON.stringify(value) : value}`;
|
|
85
|
+
return null;
|
|
86
|
+
}).filter((arg) => arg !== null).join(" ");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the node options from the `NODE_OPTIONS` environment variable and parse
|
|
90
|
+
* them into an object without the inspect options.
|
|
91
|
+
*
|
|
92
|
+
* @returns An object with the parsed node options.
|
|
93
|
+
*/
|
|
94
|
+
function getParsedNodeOptionsWithoutInspect() {
|
|
95
|
+
const args = getNodeOptionsArgs();
|
|
96
|
+
if (args.length === 0) return {};
|
|
97
|
+
const parsed = parseNodeArgs(args);
|
|
98
|
+
delete parsed.inspect;
|
|
99
|
+
delete parsed["inspect-brk"];
|
|
100
|
+
delete parsed.inspect_brk;
|
|
101
|
+
return parsed;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the node options from the `NODE_OPTIONS` environment variable and format
|
|
105
|
+
* them into a string without the inspect options.
|
|
106
|
+
*
|
|
107
|
+
* @returns A string with the formatted node options.
|
|
108
|
+
*/
|
|
109
|
+
function getFormattedNodeOptionsWithoutInspect() {
|
|
110
|
+
const args = getParsedNodeOptionsWithoutInspect();
|
|
111
|
+
if (Object.keys(args).length === 0) return "";
|
|
112
|
+
return formatNodeOptions(args);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the package registry using the user's package manager. The URL will have a trailing slash.
|
|
116
|
+
*
|
|
117
|
+
* @param baseDir - The base directory to detect the package manager from.
|
|
118
|
+
* @returns The package registry URL with a trailing slash.
|
|
119
|
+
* @throws Will throw an error if the package manager cannot be detected or if the registry cannot be retrieved.
|
|
120
|
+
*/
|
|
121
|
+
async function getRegistry(baseDir) {
|
|
122
|
+
const pkgManager = await (0, __antfu_install_pkg.detectPackageManager)(require_get_workspace_root.getWorkspaceRoot(baseDir));
|
|
123
|
+
const resolvedFlags = pkgManager === "npm" ? "--no-workspaces" : "";
|
|
124
|
+
let registry = `https://registry.npmjs.org/`;
|
|
125
|
+
try {
|
|
126
|
+
const output = (0, node_child_process.execSync)(`${pkgManager} config get registry ${resolvedFlags}`, { env: {
|
|
127
|
+
...process.env,
|
|
128
|
+
NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()
|
|
129
|
+
} }).toString().trim();
|
|
130
|
+
if (output.startsWith("http")) registry = output.endsWith("/") ? output : `${output}/`;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
throw new Error(`Failed to get registry from "${pkgManager}".`, { cause: err });
|
|
133
|
+
}
|
|
134
|
+
return registry;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
exports.formatNodeOptions = formatNodeOptions;
|
|
139
|
+
exports.getFormattedNodeOptionsWithoutInspect = getFormattedNodeOptionsWithoutInspect;
|
|
140
|
+
exports.getParsedNodeOptionsWithoutInspect = getParsedNodeOptionsWithoutInspect;
|
|
141
|
+
exports.getRegistry = getRegistry;
|
|
142
|
+
exports.tokenizeArgs = tokenizeArgs;
|
package/dist/registry.mjs
CHANGED
|
@@ -1,2 +1,138 @@
|
|
|
1
|
-
import{getWorkspaceRoot
|
|
1
|
+
import { getWorkspaceRoot } from "./get-workspace-root.mjs";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { detectPackageManager } from "@antfu/install-pkg";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
|
|
6
|
+
//#region src/registry.ts
|
|
7
|
+
const parseNodeArgs = (args) => {
|
|
8
|
+
const { values, tokens } = parseArgs({
|
|
9
|
+
args,
|
|
10
|
+
strict: false,
|
|
11
|
+
tokens: true
|
|
12
|
+
});
|
|
13
|
+
let orphan = null;
|
|
14
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
15
|
+
const token = tokens[i];
|
|
16
|
+
if (token.kind === "option-terminator") break;
|
|
17
|
+
if (token.kind === "option") {
|
|
18
|
+
orphan = typeof token.value === "undefined" ? token : null;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (token.kind !== "positional") {
|
|
22
|
+
orphan = null;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!orphan) continue;
|
|
26
|
+
if (orphan.name in values && typeof values[orphan.name] === "string") values[orphan.name] += ` ${token.value}`;
|
|
27
|
+
else values[orphan.name] = token.value;
|
|
28
|
+
}
|
|
29
|
+
return values;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Tokenizes the arguments string into an array of strings, supporting quoted
|
|
33
|
+
* values and escaped characters.
|
|
34
|
+
* Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401
|
|
35
|
+
*
|
|
36
|
+
* @param input - The arguments string to be tokenized.
|
|
37
|
+
* @returns An array of strings with the tokenized arguments.
|
|
38
|
+
*/
|
|
39
|
+
const tokenizeArgs = (input) => {
|
|
40
|
+
const args = [];
|
|
41
|
+
let isInString = false;
|
|
42
|
+
let willStartNewArg = true;
|
|
43
|
+
for (let i = 0; i < input.length; i++) {
|
|
44
|
+
let char = input[i];
|
|
45
|
+
if (char === "\\" && isInString) {
|
|
46
|
+
if (input.length === i + 1) throw new Error("Invalid escape character at the end.");
|
|
47
|
+
char = input[++i];
|
|
48
|
+
} else if (char === " " && !isInString) {
|
|
49
|
+
willStartNewArg = true;
|
|
50
|
+
continue;
|
|
51
|
+
} else if (char === "\"") {
|
|
52
|
+
isInString = !isInString;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (willStartNewArg) {
|
|
56
|
+
args.push(char);
|
|
57
|
+
willStartNewArg = false;
|
|
58
|
+
} else args[args.length - 1] += char;
|
|
59
|
+
}
|
|
60
|
+
if (isInString) throw new Error("Unterminated string");
|
|
61
|
+
return args;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Get the node options from the environment variable `NODE_OPTIONS` and returns
|
|
65
|
+
* them as an array of strings.
|
|
66
|
+
*
|
|
67
|
+
* @returns An array of strings with the node options.
|
|
68
|
+
*/
|
|
69
|
+
const getNodeOptionsArgs = () => {
|
|
70
|
+
if (!process.env.NODE_OPTIONS) return [];
|
|
71
|
+
return tokenizeArgs(process.env.NODE_OPTIONS);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Stringify the arguments to be used in a command line. It will ignore any
|
|
75
|
+
* argument that has a value of `undefined`.
|
|
76
|
+
*
|
|
77
|
+
* @param args - The arguments to be stringified.
|
|
78
|
+
* @returns A string with the arguments.
|
|
79
|
+
*/
|
|
80
|
+
function formatNodeOptions(args) {
|
|
81
|
+
return Object.entries(args).map(([key, value]) => {
|
|
82
|
+
if (value === true) return `--${key}`;
|
|
83
|
+
if (value) return `--${key}=${value.includes(" ") && !value.startsWith("\"") ? JSON.stringify(value) : value}`;
|
|
84
|
+
return null;
|
|
85
|
+
}).filter((arg) => arg !== null).join(" ");
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the node options from the `NODE_OPTIONS` environment variable and parse
|
|
89
|
+
* them into an object without the inspect options.
|
|
90
|
+
*
|
|
91
|
+
* @returns An object with the parsed node options.
|
|
92
|
+
*/
|
|
93
|
+
function getParsedNodeOptionsWithoutInspect() {
|
|
94
|
+
const args = getNodeOptionsArgs();
|
|
95
|
+
if (args.length === 0) return {};
|
|
96
|
+
const parsed = parseNodeArgs(args);
|
|
97
|
+
delete parsed.inspect;
|
|
98
|
+
delete parsed["inspect-brk"];
|
|
99
|
+
delete parsed.inspect_brk;
|
|
100
|
+
return parsed;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the node options from the `NODE_OPTIONS` environment variable and format
|
|
104
|
+
* them into a string without the inspect options.
|
|
105
|
+
*
|
|
106
|
+
* @returns A string with the formatted node options.
|
|
107
|
+
*/
|
|
108
|
+
function getFormattedNodeOptionsWithoutInspect() {
|
|
109
|
+
const args = getParsedNodeOptionsWithoutInspect();
|
|
110
|
+
if (Object.keys(args).length === 0) return "";
|
|
111
|
+
return formatNodeOptions(args);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the package registry using the user's package manager. The URL will have a trailing slash.
|
|
115
|
+
*
|
|
116
|
+
* @param baseDir - The base directory to detect the package manager from.
|
|
117
|
+
* @returns The package registry URL with a trailing slash.
|
|
118
|
+
* @throws Will throw an error if the package manager cannot be detected or if the registry cannot be retrieved.
|
|
119
|
+
*/
|
|
120
|
+
async function getRegistry(baseDir) {
|
|
121
|
+
const pkgManager = await detectPackageManager(getWorkspaceRoot(baseDir));
|
|
122
|
+
const resolvedFlags = pkgManager === "npm" ? "--no-workspaces" : "";
|
|
123
|
+
let registry = `https://registry.npmjs.org/`;
|
|
124
|
+
try {
|
|
125
|
+
const output = execSync(`${pkgManager} config get registry ${resolvedFlags}`, { env: {
|
|
126
|
+
...process.env,
|
|
127
|
+
NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()
|
|
128
|
+
} }).toString().trim();
|
|
129
|
+
if (output.startsWith("http")) registry = output.endsWith("/") ? output : `${output}/`;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
throw new Error(`Failed to get registry from "${pkgManager}".`, { cause: err });
|
|
132
|
+
}
|
|
133
|
+
return registry;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
export { formatNodeOptions, getFormattedNodeOptionsWithoutInspect, getParsedNodeOptionsWithoutInspect, getRegistry, tokenizeArgs };
|
|
2
138
|
//# sourceMappingURL=registry.mjs.map
|
package/dist/registry.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.mjs","names":["orphan: NodeOptionsToken | null | undefined","args: string[]"],"sources":["../src/registry.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { detectPackageManager } from \"@antfu/install-pkg\";\nimport { execSync } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport interface NodeOptionsToken {\n kind: \"option\";\n index: number;\n name: string;\n rawName: string;\n value: undefined;\n inlineValue: undefined;\n}\n\nconst parseNodeArgs = (args: string[]) => {\n const { values, tokens } = parseArgs({ args, strict: false, tokens: true });\n\n // For the `NODE_OPTIONS`, we support arguments with values without the `=`\n // sign. We need to parse them manually.\n let orphan: NodeOptionsToken | null | undefined = null;\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i]!;\n\n if (token.kind === \"option-terminator\") {\n break;\n }\n\n // When we encounter an option, if it's value is undefined, we should check\n // to see if the following tokens are positional parameters. If they are,\n // then the option is orphaned, and we can assign it.\n if (token.kind === \"option\") {\n orphan = typeof token.value === \"undefined\" ? token : null;\n continue;\n }\n\n // If the token isn't a positional one, then we can't assign it to the found\n // orphaned option.\n if (token.kind !== \"positional\") {\n orphan = null;\n continue;\n }\n\n // If we don't have an orphan, then we can skip this token.\n if (!orphan) {\n continue;\n }\n\n // If the token is a positional one, and it has a value, so add it to the\n // values object. If it already exists, append it with a space.\n if (orphan.name in values && typeof values[orphan.name] === \"string\") {\n values[orphan.name] += ` ${token.value}`;\n } else {\n values[orphan.name] = token.value;\n }\n }\n\n return values;\n};\n\n/**\n * Tokenizes the arguments string into an array of strings, supporting quoted\n * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input - The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nexport const tokenizeArgs = (input: string): string[] => {\n const args: string[] = [];\n let isInString = false;\n let willStartNewArg = true;\n\n for (let i = 0; i < input.length; i++) {\n let char = input[i]!;\n\n // Skip any escaped characters in strings.\n if (char === \"\\\\\" && isInString) {\n // Ensure we don't have an escape character at the end.\n if (input.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = input[++i]!;\n }\n // If we find a space outside of a string, we should start a new argument.\n else if (char === \" \" && !isInString) {\n willStartNewArg = true;\n continue;\n }\n\n // If we find a quote, we should toggle the string flag.\n else if (char === '\"') {\n isInString = !isInString;\n continue;\n }\n\n // If we're starting a new argument, we should add it to the array.\n if (willStartNewArg) {\n args.push(char);\n willStartNewArg = false;\n }\n // Otherwise, add it to the last argument.\n else {\n args[args.length - 1] += char;\n }\n }\n\n if (isInString) {\n throw new Error(\"Unterminated string\");\n }\n\n return args;\n};\n\n/**\n * Get the node options from the environment variable `NODE_OPTIONS` and returns\n * them as an array of strings.\n *\n * @returns An array of strings with the node options.\n */\nconst getNodeOptionsArgs = () => {\n if (!process.env.NODE_OPTIONS) return [];\n\n return tokenizeArgs(process.env.NODE_OPTIONS);\n};\n\n/**\n * Stringify the arguments to be used in a command line. It will ignore any\n * argument that has a value of `undefined`.\n *\n * @param args - The arguments to be stringified.\n * @returns A string with the arguments.\n */\nexport function formatNodeOptions(\n args: Record<string, string | boolean | undefined>\n): string {\n return Object.entries(args)\n .map(([key, value]) => {\n if (value === true) {\n return `--${key}`;\n }\n\n if (value) {\n return `--${key}=${\n // Values with spaces need to be quoted. We use JSON.stringify to\n // also escape any nested quotes.\n value.includes(\" \") && !value.startsWith('\"')\n ? JSON.stringify(value)\n : value\n }`;\n }\n\n return null;\n })\n .filter(arg => arg !== null)\n .join(\" \");\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and parse\n * them into an object without the inspect options.\n *\n * @returns An object with the parsed node options.\n */\nexport function getParsedNodeOptionsWithoutInspect() {\n const args = getNodeOptionsArgs();\n if (args.length === 0) return {};\n\n const parsed = parseNodeArgs(args);\n\n // Remove inspect options.\n delete parsed.inspect;\n delete parsed[\"inspect-brk\"];\n delete parsed.inspect_brk;\n\n return parsed;\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and format\n * them into a string without the inspect options.\n *\n * @returns A string with the formatted node options.\n */\nexport function getFormattedNodeOptionsWithoutInspect() {\n const args = getParsedNodeOptionsWithoutInspect();\n if (Object.keys(args).length === 0) return \"\";\n\n return formatNodeOptions(args);\n}\n\n/**\n * Returns the package registry using the user's package manager. The URL will have a trailing slash.\n *\n * @param baseDir - The base directory to detect the package manager from.\n * @returns The package registry URL with a trailing slash.\n * @throws Will throw an error if the package manager cannot be detected or if the registry cannot be retrieved.\n */\nexport async function getRegistry(baseDir?: string) {\n const workspaceRoot = getWorkspaceRoot(baseDir);\n const pkgManager = await detectPackageManager(workspaceRoot);\n\n // Since `npm config` command fails in npm workspace to prevent workspace config conflicts,\n // add `--no-workspaces` flag to run under the context of the root project only.\n // Safe for non-workspace projects as it's equivalent to default `--workspaces=false`.\n // x-ref: https://github.com/vercel/next.js/issues/47121#issuecomment-1499044345\n // x-ref: https://github.com/npm/statusboard/issues/371#issue-920669998\n const resolvedFlags = pkgManager === \"npm\" ? \"--no-workspaces\" : \"\";\n let registry = `https://registry.npmjs.org/`;\n\n try {\n const output = execSync(\n `${pkgManager} config get registry ${resolvedFlags}`,\n {\n env: {\n ...process.env,\n NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()\n }\n }\n )\n .toString()\n .trim();\n\n if (output.startsWith(\"http\")) {\n registry = output.endsWith(\"/\") ? output : `${output}/`;\n }\n } catch (err) {\n throw new Error(`Failed to get registry from \"${pkgManager}\".`, {\n cause: err\n });\n }\n\n return registry;\n}\n"],"mappings":"0MAgCA,MAAM,EAAiB,GAAmB,CACxC,GAAM,CAAE,SAAQ,UAAW,EAAU,CAAE,OAAM,OAAQ,GAAO,OAAQ,GAAM,CAAC,CAIvEA,EAA8C,KAClD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAQ,EAAO,GAErB,GAAI,EAAM,OAAS,oBACjB,MAMF,GAAI,EAAM,OAAS,SAAU,CAC3B,EAAgB,EAAM,QAAU,OAAc,EAAQ,KACtD,SAKF,GAAI,EAAM,OAAS,aAAc,CAC/B,EAAS,KACT,SAIG,IAMD,EAAO,QAAQ,GAAU,OAAO,EAAO,EAAO,OAAU,SAC1D,EAAO,EAAO,OAAS,IAAI,EAAM,QAEjC,EAAO,EAAO,MAAQ,EAAM,OAIhC,OAAO,GAWI,EAAgB,GAA4B,CACvD,IAAMC,EAAiB,EAAE,CACrB,EAAa,GACb,EAAkB,GAEtB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAI,EAAO,EAAM,GAGjB,GAAI,IAAS,MAAQ,EAAY,CAE/B,GAAI,EAAM,SAAW,EAAI,EACvB,MAAU,MAAM,uCAAuC,CAIzD,EAAO,EAAM,EAAE,WAGR,IAAS,KAAO,CAAC,EAAY,CACpC,EAAkB,GAClB,iBAIO,IAAS,IAAK,CACrB,EAAa,CAAC,EACd,SAIE,GACF,EAAK,KAAK,EAAK,CACf,EAAkB,IAIlB,EAAK,EAAK,OAAS,IAAM,EAI7B,GAAI,EACF,MAAU,MAAM,sBAAsB,CAGxC,OAAO,GASH,MACC,QAAQ,IAAI,aAEV,EAAa,QAAQ,IAAI,aAAa,CAFP,EAAE,CAY1C,SAAgB,EACd,EACQ,CACR,OAAO,OAAO,QAAQ,EAAK,CACxB,KAAK,CAAC,EAAK,KACN,IAAU,GACL,KAAK,IAGV,EACK,KAAK,EAAI,GAGd,EAAM,SAAS,IAAI,EAAI,CAAC,EAAM,WAAW,IAAI,CACzC,KAAK,UAAU,EAAM,CACrB,IAID,KACP,CACD,OAAO,GAAO,IAAQ,KAAK,CAC3B,KAAK,IAAI,CASd,SAAgB,GAAqC,CACnD,IAAM,EAAO,GAAoB,CACjC,GAAI,EAAK,SAAW,EAAG,MAAO,EAAE,CAEhC,IAAM,EAAS,EAAc,EAAK,CAOlC,OAJA,OAAO,EAAO,QACd,OAAO,EAAO,eACd,OAAO,EAAO,YAEP,EAST,SAAgB,GAAwC,CACtD,IAAM,EAAO,GAAoC,CAGjD,OAFI,OAAO,KAAK,EAAK,CAAC,SAAW,EAAU,GAEpC,EAAkB,EAAK,CAUhC,eAAsB,EAAY,EAAkB,CAElD,IAAM,EAAa,MAAM,EADH,EAAiB,EAAQ,CACa,CAOtD,EAAgB,IAAe,MAAQ,kBAAoB,GAC7D,EAAW,8BAEf,GAAI,CACF,IAAM,EAAS,EACb,GAAG,EAAW,uBAAuB,IACrC,CACE,IAAK,CACH,GAAG,QAAQ,IACX,aAAc,GAAuC,CACtD,CACF,CACF,CACE,UAAU,CACV,MAAM,CAEL,EAAO,WAAW,OAAO,GAC3B,EAAW,EAAO,SAAS,IAAI,CAAG,EAAS,GAAG,EAAO,UAEhD,EAAK,CACZ,MAAU,MAAM,gCAAgC,EAAW,IAAK,CAC9D,MAAO,EACR,CAAC,CAGJ,OAAO"}
|
|
1
|
+
{"version":3,"file":"registry.mjs","names":["orphan: NodeOptionsToken | null | undefined","args: string[]"],"sources":["../src/registry.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { detectPackageManager } from \"@antfu/install-pkg\";\nimport { execSync } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport interface NodeOptionsToken {\n kind: \"option\";\n index: number;\n name: string;\n rawName: string;\n value: undefined;\n inlineValue: undefined;\n}\n\nconst parseNodeArgs = (args: string[]) => {\n const { values, tokens } = parseArgs({ args, strict: false, tokens: true });\n\n // For the `NODE_OPTIONS`, we support arguments with values without the `=`\n // sign. We need to parse them manually.\n let orphan: NodeOptionsToken | null | undefined = null;\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i]!;\n\n if (token.kind === \"option-terminator\") {\n break;\n }\n\n // When we encounter an option, if it's value is undefined, we should check\n // to see if the following tokens are positional parameters. If they are,\n // then the option is orphaned, and we can assign it.\n if (token.kind === \"option\") {\n orphan = typeof token.value === \"undefined\" ? token : null;\n continue;\n }\n\n // If the token isn't a positional one, then we can't assign it to the found\n // orphaned option.\n if (token.kind !== \"positional\") {\n orphan = null;\n continue;\n }\n\n // If we don't have an orphan, then we can skip this token.\n if (!orphan) {\n continue;\n }\n\n // If the token is a positional one, and it has a value, so add it to the\n // values object. If it already exists, append it with a space.\n if (orphan.name in values && typeof values[orphan.name] === \"string\") {\n values[orphan.name] += ` ${token.value}`;\n } else {\n values[orphan.name] = token.value;\n }\n }\n\n return values;\n};\n\n/**\n * Tokenizes the arguments string into an array of strings, supporting quoted\n * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input - The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nexport const tokenizeArgs = (input: string): string[] => {\n const args: string[] = [];\n let isInString = false;\n let willStartNewArg = true;\n\n for (let i = 0; i < input.length; i++) {\n let char = input[i]!;\n\n // Skip any escaped characters in strings.\n if (char === \"\\\\\" && isInString) {\n // Ensure we don't have an escape character at the end.\n if (input.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = input[++i]!;\n }\n // If we find a space outside of a string, we should start a new argument.\n else if (char === \" \" && !isInString) {\n willStartNewArg = true;\n continue;\n }\n\n // If we find a quote, we should toggle the string flag.\n else if (char === '\"') {\n isInString = !isInString;\n continue;\n }\n\n // If we're starting a new argument, we should add it to the array.\n if (willStartNewArg) {\n args.push(char);\n willStartNewArg = false;\n }\n // Otherwise, add it to the last argument.\n else {\n args[args.length - 1] += char;\n }\n }\n\n if (isInString) {\n throw new Error(\"Unterminated string\");\n }\n\n return args;\n};\n\n/**\n * Get the node options from the environment variable `NODE_OPTIONS` and returns\n * them as an array of strings.\n *\n * @returns An array of strings with the node options.\n */\nconst getNodeOptionsArgs = () => {\n if (!process.env.NODE_OPTIONS) return [];\n\n return tokenizeArgs(process.env.NODE_OPTIONS);\n};\n\n/**\n * Stringify the arguments to be used in a command line. It will ignore any\n * argument that has a value of `undefined`.\n *\n * @param args - The arguments to be stringified.\n * @returns A string with the arguments.\n */\nexport function formatNodeOptions(\n args: Record<string, string | boolean | undefined>\n): string {\n return Object.entries(args)\n .map(([key, value]) => {\n if (value === true) {\n return `--${key}`;\n }\n\n if (value) {\n return `--${key}=${\n // Values with spaces need to be quoted. We use JSON.stringify to\n // also escape any nested quotes.\n value.includes(\" \") && !value.startsWith('\"')\n ? JSON.stringify(value)\n : value\n }`;\n }\n\n return null;\n })\n .filter(arg => arg !== null)\n .join(\" \");\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and parse\n * them into an object without the inspect options.\n *\n * @returns An object with the parsed node options.\n */\nexport function getParsedNodeOptionsWithoutInspect() {\n const args = getNodeOptionsArgs();\n if (args.length === 0) return {};\n\n const parsed = parseNodeArgs(args);\n\n // Remove inspect options.\n delete parsed.inspect;\n delete parsed[\"inspect-brk\"];\n delete parsed.inspect_brk;\n\n return parsed;\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and format\n * them into a string without the inspect options.\n *\n * @returns A string with the formatted node options.\n */\nexport function getFormattedNodeOptionsWithoutInspect() {\n const args = getParsedNodeOptionsWithoutInspect();\n if (Object.keys(args).length === 0) return \"\";\n\n return formatNodeOptions(args);\n}\n\n/**\n * Returns the package registry using the user's package manager. The URL will have a trailing slash.\n *\n * @param baseDir - The base directory to detect the package manager from.\n * @returns The package registry URL with a trailing slash.\n * @throws Will throw an error if the package manager cannot be detected or if the registry cannot be retrieved.\n */\nexport async function getRegistry(baseDir?: string) {\n const workspaceRoot = getWorkspaceRoot(baseDir);\n const pkgManager = await detectPackageManager(workspaceRoot);\n\n // Since `npm config` command fails in npm workspace to prevent workspace config conflicts,\n // add `--no-workspaces` flag to run under the context of the root project only.\n // Safe for non-workspace projects as it's equivalent to default `--workspaces=false`.\n // x-ref: https://github.com/vercel/next.js/issues/47121#issuecomment-1499044345\n // x-ref: https://github.com/npm/statusboard/issues/371#issue-920669998\n const resolvedFlags = pkgManager === \"npm\" ? \"--no-workspaces\" : \"\";\n let registry = `https://registry.npmjs.org/`;\n\n try {\n const output = execSync(\n `${pkgManager} config get registry ${resolvedFlags}`,\n {\n env: {\n ...process.env,\n NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()\n }\n }\n )\n .toString()\n .trim();\n\n if (output.startsWith(\"http\")) {\n registry = output.endsWith(\"/\") ? output : `${output}/`;\n }\n } catch (err) {\n throw new Error(`Failed to get registry from \"${pkgManager}\".`, {\n cause: err\n });\n }\n\n return registry;\n}\n"],"mappings":";;;;;;AAgCA,MAAM,iBAAiB,SAAmB;CACxC,MAAM,EAAE,QAAQ,WAAW,UAAU;EAAE;EAAM,QAAQ;EAAO,QAAQ;EAAM,CAAC;CAI3E,IAAIA,SAA8C;AAClD,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;AAErB,MAAI,MAAM,SAAS,oBACjB;AAMF,MAAI,MAAM,SAAS,UAAU;AAC3B,YAAS,OAAO,MAAM,UAAU,cAAc,QAAQ;AACtD;;AAKF,MAAI,MAAM,SAAS,cAAc;AAC/B,YAAS;AACT;;AAIF,MAAI,CAAC,OACH;AAKF,MAAI,OAAO,QAAQ,UAAU,OAAO,OAAO,OAAO,UAAU,SAC1D,QAAO,OAAO,SAAS,IAAI,MAAM;MAEjC,QAAO,OAAO,QAAQ,MAAM;;AAIhC,QAAO;;;;;;;;;;AAWT,MAAa,gBAAgB,UAA4B;CACvD,MAAMC,OAAiB,EAAE;CACzB,IAAI,aAAa;CACjB,IAAI,kBAAkB;AAEtB,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,IAAI,OAAO,MAAM;AAGjB,MAAI,SAAS,QAAQ,YAAY;AAE/B,OAAI,MAAM,WAAW,IAAI,EACvB,OAAM,IAAI,MAAM,uCAAuC;AAIzD,UAAO,MAAM,EAAE;aAGR,SAAS,OAAO,CAAC,YAAY;AACpC,qBAAkB;AAClB;aAIO,SAAS,MAAK;AACrB,gBAAa,CAAC;AACd;;AAIF,MAAI,iBAAiB;AACnB,QAAK,KAAK,KAAK;AACf,qBAAkB;QAIlB,MAAK,KAAK,SAAS,MAAM;;AAI7B,KAAI,WACF,OAAM,IAAI,MAAM,sBAAsB;AAGxC,QAAO;;;;;;;;AAST,MAAM,2BAA2B;AAC/B,KAAI,CAAC,QAAQ,IAAI,aAAc,QAAO,EAAE;AAExC,QAAO,aAAa,QAAQ,IAAI,aAAa;;;;;;;;;AAU/C,SAAgB,kBACd,MACQ;AACR,QAAO,OAAO,QAAQ,KAAK,CACxB,KAAK,CAAC,KAAK,WAAW;AACrB,MAAI,UAAU,KACZ,QAAO,KAAK;AAGd,MAAI,MACF,QAAO,KAAK,IAAI,GAGd,MAAM,SAAS,IAAI,IAAI,CAAC,MAAM,WAAW,KAAI,GACzC,KAAK,UAAU,MAAM,GACrB;AAIR,SAAO;GACP,CACD,QAAO,QAAO,QAAQ,KAAK,CAC3B,KAAK,IAAI;;;;;;;;AASd,SAAgB,qCAAqC;CACnD,MAAM,OAAO,oBAAoB;AACjC,KAAI,KAAK,WAAW,EAAG,QAAO,EAAE;CAEhC,MAAM,SAAS,cAAc,KAAK;AAGlC,QAAO,OAAO;AACd,QAAO,OAAO;AACd,QAAO,OAAO;AAEd,QAAO;;;;;;;;AAST,SAAgB,wCAAwC;CACtD,MAAM,OAAO,oCAAoC;AACjD,KAAI,OAAO,KAAK,KAAK,CAAC,WAAW,EAAG,QAAO;AAE3C,QAAO,kBAAkB,KAAK;;;;;;;;;AAUhC,eAAsB,YAAY,SAAkB;CAElD,MAAM,aAAa,MAAM,qBADH,iBAAiB,QAAQ,CACa;CAO5D,MAAM,gBAAgB,eAAe,QAAQ,oBAAoB;CACjE,IAAI,WAAW;AAEf,KAAI;EACF,MAAM,SAAS,SACb,GAAG,WAAW,uBAAuB,iBACrC,EACE,KAAK;GACH,GAAG,QAAQ;GACX,cAAc,uCAAuC;GACtD,EACF,CACF,CACE,UAAU,CACV,MAAM;AAET,MAAI,OAAO,WAAW,OAAO,CAC3B,YAAW,OAAO,SAAS,IAAI,GAAG,SAAS,GAAG,OAAO;UAEhD,KAAK;AACZ,QAAM,IAAI,MAAM,gCAAgC,WAAW,KAAK,EAC9D,OAAO,KACR,CAAC;;AAGJ,QAAO"}
|
package/dist/remove-file.cjs
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
|
|
5
|
+
//#region src/remove-file.ts
|
|
6
|
+
/**
|
|
7
|
+
* Remove the given content to the given file path
|
|
8
|
+
*
|
|
9
|
+
* @param filePath - The file path to remove to
|
|
10
|
+
*/
|
|
11
|
+
const removeFileSync = (filePath) => {
|
|
12
|
+
if (!filePath || !(0, node_fs.existsSync)(filePath)) return;
|
|
13
|
+
(0, node_fs.rmSync)(filePath);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Remove the given content to the given file path
|
|
17
|
+
*
|
|
18
|
+
* @param filePath - The file path to read to
|
|
19
|
+
*/
|
|
20
|
+
const removeFile = async (filePath) => {
|
|
21
|
+
if (!filePath || !(0, node_fs.existsSync)(filePath)) return;
|
|
22
|
+
return (0, node_fs_promises.rm)(filePath);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.removeFile = removeFile;
|
|
27
|
+
exports.removeFileSync = removeFileSync;
|
package/dist/remove-file.mjs
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, rmSync } from "node:fs";
|
|
2
|
+
import { rm } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region src/remove-file.ts
|
|
5
|
+
/**
|
|
6
|
+
* Remove the given content to the given file path
|
|
7
|
+
*
|
|
8
|
+
* @param filePath - The file path to remove to
|
|
9
|
+
*/
|
|
10
|
+
const removeFileSync = (filePath) => {
|
|
11
|
+
if (!filePath || !existsSync(filePath)) return;
|
|
12
|
+
rmSync(filePath);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Remove the given content to the given file path
|
|
16
|
+
*
|
|
17
|
+
* @param filePath - The file path to read to
|
|
18
|
+
*/
|
|
19
|
+
const removeFile = async (filePath) => {
|
|
20
|
+
if (!filePath || !existsSync(filePath)) return;
|
|
21
|
+
return rm(filePath);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { removeFile, removeFileSync };
|
|
2
26
|
//# sourceMappingURL=remove-file.mjs.map
|
package/dist/remove-file.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-file.mjs","names":[],"sources":["../src/remove-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, rmSync } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to remove to\n */\nexport const removeFileSync = (filePath: string): void => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath);\n};\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const removeFile = async (filePath: string): Promise<void> => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n return rm(filePath);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"remove-file.mjs","names":[],"sources":["../src/remove-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, rmSync } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to remove to\n */\nexport const removeFileSync = (filePath: string): void => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath);\n};\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const removeFile = async (filePath: string): Promise<void> => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n return rm(filePath);\n};\n"],"mappings":";;;;;;;;;AA0BA,MAAa,kBAAkB,aAA2B;AACxD,KAAI,CAAC,YAAY,CAAC,WAAW,SAAS,CACpC;AAGF,QAAO,SAAS;;;;;;;AAQlB,MAAa,aAAa,OAAO,aAAoC;AACnE,KAAI,CAAC,YAAY,CAAC,WAAW,SAAS,CACpC;AAGF,QAAO,GAAG,SAAS"}
|
package/dist/resolve.cjs
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_cwd = require('./path/src/cwd.cjs');
|
|
3
|
+
const require_is_type = require('./path/src/is-type.cjs');
|
|
4
|
+
const require_join_paths = require('./path/src/join-paths.cjs');
|
|
5
|
+
const require_append = require('./path/src/append.cjs');
|
|
6
|
+
const require_correct_path = require('./path/src/correct-path.cjs');
|
|
7
|
+
const require_file_path_fns = require('./path/src/file-path-fns.cjs');
|
|
8
|
+
const require_exists = require('./exists.cjs');
|
|
9
|
+
const require_get_workspace_root = require('./get-workspace-root.cjs');
|
|
10
|
+
const require_get_unique = require('./helpers/src/get-unique.cjs');
|
|
11
|
+
let mlly = require("mlly");
|
|
12
|
+
|
|
13
|
+
//#region src/resolve.ts
|
|
14
|
+
const DEFAULT_EXTENSIONS = [
|
|
15
|
+
"js",
|
|
16
|
+
"jsx",
|
|
17
|
+
"mjs",
|
|
18
|
+
"cjs",
|
|
19
|
+
"ts",
|
|
20
|
+
"tsx",
|
|
21
|
+
"mts",
|
|
22
|
+
"cts",
|
|
23
|
+
"json",
|
|
24
|
+
"jsonc",
|
|
25
|
+
"json5",
|
|
26
|
+
"node"
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Get the resolution paths based on the provided paths, current working directory, and workspace root.
|
|
30
|
+
*
|
|
31
|
+
* @param paths - An array of paths to include in the resolution.
|
|
32
|
+
* @returns An array of unique, corrected resolution paths.
|
|
33
|
+
*/
|
|
34
|
+
function getResolutionPaths(paths = []) {
|
|
35
|
+
let resolutionPaths = paths;
|
|
36
|
+
if (!resolutionPaths.includes(require_cwd.cwd())) resolutionPaths.push(require_cwd.cwd());
|
|
37
|
+
const workspaceRoot = require_get_workspace_root.getWorkspaceRoot();
|
|
38
|
+
if (!resolutionPaths.includes(workspaceRoot)) resolutionPaths.push(workspaceRoot);
|
|
39
|
+
resolutionPaths = require_get_unique.getUnique(resolutionPaths.filter(Boolean).map((path) => require_correct_path.correctPath(path)).reduce((ret, path, _, arr) => {
|
|
40
|
+
ret.push(path);
|
|
41
|
+
if (!require_is_type.isAbsolutePath(path)) {
|
|
42
|
+
ret.push(require_correct_path.toAbsolutePath(path, require_cwd.cwd()));
|
|
43
|
+
ret.push(require_correct_path.toAbsolutePath(path, workspaceRoot));
|
|
44
|
+
arr.forEach((existing) => {
|
|
45
|
+
ret.push(require_correct_path.toAbsolutePath(path, existing));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return ret;
|
|
49
|
+
}, []));
|
|
50
|
+
return resolutionPaths;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the node_modules resolution paths based on the provided paths.
|
|
54
|
+
*
|
|
55
|
+
* @param paths - An array of paths to include in the resolution.
|
|
56
|
+
* @returns An array of unique, corrected node_modules resolution paths.
|
|
57
|
+
*/
|
|
58
|
+
function getNodeModulesPaths(paths = []) {
|
|
59
|
+
return require_get_unique.getUnique(paths.reduce((ret, path) => {
|
|
60
|
+
if (require_file_path_fns.findFolderName(path) === "node_modules") ret.push(require_correct_path.correctPath(path));
|
|
61
|
+
if (require_exists.existsSync(require_join_paths.joinPaths(path, "node_modules"))) ret.push(require_correct_path.correctPath(require_join_paths.joinPaths(path, "node_modules")));
|
|
62
|
+
return ret;
|
|
63
|
+
}, []));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all combinations of resolution paths for a given path and options.
|
|
67
|
+
*
|
|
68
|
+
* @param path - The base path to combine with resolution paths.
|
|
69
|
+
* @param options - The options containing resolution paths.
|
|
70
|
+
* @returns An array of unique, corrected resolution paths.
|
|
71
|
+
*/
|
|
72
|
+
function getResolutionCombinations(path, options = {}) {
|
|
73
|
+
let paths = getResolutionPaths(options.paths);
|
|
74
|
+
if (require_is_type.isNpmScopedPackage(path)) paths = getNodeModulesPaths(paths);
|
|
75
|
+
else paths.push(...getNodeModulesPaths(paths));
|
|
76
|
+
const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
77
|
+
let combinations = paths.map((base) => require_join_paths.joinPaths(base, path));
|
|
78
|
+
if (require_file_path_fns.findFileName(path, { withExtension: false }) !== "index") combinations = combinations.reduce((ret, combination) => {
|
|
79
|
+
ret.push(combination);
|
|
80
|
+
ret.push(require_join_paths.joinPaths(combination, "index"));
|
|
81
|
+
return ret;
|
|
82
|
+
}, []);
|
|
83
|
+
if (!require_file_path_fns.findFileExtension(path)) combinations = combinations.reduce((ret, combination) => {
|
|
84
|
+
ret.push(combination);
|
|
85
|
+
extensions.forEach((ext) => {
|
|
86
|
+
ret.push(require_append.appendExtension(combination, ext));
|
|
87
|
+
});
|
|
88
|
+
return ret;
|
|
89
|
+
}, []);
|
|
90
|
+
return require_get_unique.getUnique(combinations.filter(Boolean)).map((p) => require_correct_path.correctPath(p));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Resolve the path to a specified module
|
|
94
|
+
*
|
|
95
|
+
* @param path - The path to the module
|
|
96
|
+
* @param options - The options to use when resolving the module
|
|
97
|
+
* @returns A promise for the path to the module
|
|
98
|
+
*/
|
|
99
|
+
async function resolve(path, options = {}) {
|
|
100
|
+
let paths = getResolutionPaths(options.paths);
|
|
101
|
+
if (require_is_type.isNpmScopedPackage(path)) paths = getNodeModulesPaths(paths);
|
|
102
|
+
else paths.push(...getNodeModulesPaths(paths));
|
|
103
|
+
let result;
|
|
104
|
+
let error;
|
|
105
|
+
try {
|
|
106
|
+
result = await (0, mlly.resolvePath)(path, {
|
|
107
|
+
url: paths,
|
|
108
|
+
extensions: options.extensions ?? DEFAULT_EXTENSIONS,
|
|
109
|
+
conditions: options.conditions
|
|
110
|
+
});
|
|
111
|
+
} catch (err) {
|
|
112
|
+
error = err;
|
|
113
|
+
}
|
|
114
|
+
if (!result) throw new Error(`Unable to resolve module "${path}". The following import paths were tried: \n${paths.join("\n")}`, { cause: error });
|
|
115
|
+
return require_correct_path.correctPath(result);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Resolve the path to a specified module
|
|
119
|
+
*
|
|
120
|
+
* @param path - The path to the module
|
|
121
|
+
* @param options - The options to use when resolving the module
|
|
122
|
+
* @returns The path to the module or undefined
|
|
123
|
+
*/
|
|
124
|
+
function resolveSync(path, options = {}) {
|
|
125
|
+
let paths = getResolutionPaths(options.paths);
|
|
126
|
+
if (require_is_type.isNpmScopedPackage(path)) paths = getNodeModulesPaths(paths);
|
|
127
|
+
else paths.push(...getNodeModulesPaths(paths));
|
|
128
|
+
let result;
|
|
129
|
+
let error;
|
|
130
|
+
try {
|
|
131
|
+
result = (0, mlly.resolvePathSync)(path, {
|
|
132
|
+
url: paths,
|
|
133
|
+
extensions: options.extensions ?? DEFAULT_EXTENSIONS,
|
|
134
|
+
conditions: options.conditions
|
|
135
|
+
});
|
|
136
|
+
} catch (err) {
|
|
137
|
+
error = err;
|
|
138
|
+
}
|
|
139
|
+
if (!result) throw new Error(`Unable to resolve module "${path}". The following import paths were tried: \n${paths.join("\n")}`, { cause: error });
|
|
140
|
+
return require_correct_path.correctPath(result);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Resolve the path to a specified module with error handling
|
|
144
|
+
*
|
|
145
|
+
* @param name - The name of the module
|
|
146
|
+
* @param options - The options to use when resolving the module
|
|
147
|
+
* @returns A promise for the path to the module
|
|
148
|
+
*/
|
|
149
|
+
async function resolveSafe(name, options = {}) {
|
|
150
|
+
try {
|
|
151
|
+
return await resolve(name, options);
|
|
152
|
+
} catch {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolve the path to a specified module with error handling
|
|
158
|
+
*
|
|
159
|
+
* @param name - The name of the module
|
|
160
|
+
* @param options - The options to use when resolving the module
|
|
161
|
+
* @returns The path to the module or undefined
|
|
162
|
+
*/
|
|
163
|
+
function resolveSafeSync(name, options = {}) {
|
|
164
|
+
try {
|
|
165
|
+
return resolveSync(name, options);
|
|
166
|
+
} catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Import a module from a specified path
|
|
172
|
+
*
|
|
173
|
+
* @param path - The path to the module
|
|
174
|
+
* @returns The module
|
|
175
|
+
*/
|
|
176
|
+
async function importModule(path) {
|
|
177
|
+
const i = await import(path);
|
|
178
|
+
if (i) return (0, mlly.interopDefault)(i);
|
|
179
|
+
return i;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Resolve the path to a specified package asynchronously
|
|
183
|
+
*
|
|
184
|
+
* @remarks
|
|
185
|
+
* This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
|
|
186
|
+
*
|
|
187
|
+
* @param name - The name of the module
|
|
188
|
+
* @returns A promise for the module or undefined
|
|
189
|
+
*/
|
|
190
|
+
async function resolvePackage(name, options = {}) {
|
|
191
|
+
let result = await resolveSafe(require_join_paths.joinPaths(name, "package.json"), options);
|
|
192
|
+
if (!result) {
|
|
193
|
+
result = await resolveSafe(require_join_paths.joinPaths(name, "index.js"), options);
|
|
194
|
+
if (!result) result = await resolveSafe(name, options);
|
|
195
|
+
}
|
|
196
|
+
return result ? require_file_path_fns.findFilePath(result) : void 0;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Resolve the path to a specified package synchronously
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
|
|
203
|
+
*
|
|
204
|
+
* @param name - The name of the module
|
|
205
|
+
* @param options - The options to use when resolving the module
|
|
206
|
+
* @returns The module or undefined
|
|
207
|
+
*/
|
|
208
|
+
function resolvePackageSync(name, options = {}) {
|
|
209
|
+
let result = resolveSafeSync(require_join_paths.joinPaths(name, "package.json"), options);
|
|
210
|
+
if (!result) {
|
|
211
|
+
result = resolveSafeSync(require_join_paths.joinPaths(name, "index.js"), options);
|
|
212
|
+
if (!result) result = resolveSafeSync(name, options);
|
|
213
|
+
}
|
|
214
|
+
return result ? require_file_path_fns.findFilePath(result) : void 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//#endregion
|
|
218
|
+
exports.DEFAULT_EXTENSIONS = DEFAULT_EXTENSIONS;
|
|
219
|
+
exports.getNodeModulesPaths = getNodeModulesPaths;
|
|
220
|
+
exports.getResolutionCombinations = getResolutionCombinations;
|
|
221
|
+
exports.getResolutionPaths = getResolutionPaths;
|
|
222
|
+
exports.importModule = importModule;
|
|
223
|
+
exports.resolve = resolve;
|
|
224
|
+
exports.resolvePackage = resolvePackage;
|
|
225
|
+
exports.resolvePackageSync = resolvePackageSync;
|
|
226
|
+
exports.resolveSafe = resolveSafe;
|
|
227
|
+
exports.resolveSafeSync = resolveSafeSync;
|
|
228
|
+
exports.resolveSync = resolveSync;
|