@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.
Files changed (190) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/buffer.cjs +60 -1
  4. package/dist/buffer.mjs +56 -1
  5. package/dist/buffer.mjs.map +1 -1
  6. package/dist/chmod-x.cjs +93 -1
  7. package/dist/chmod-x.mjs +87 -1
  8. package/dist/chmod-x.mjs.map +1 -1
  9. package/dist/command-exists.cjs +102 -1
  10. package/dist/command-exists.mjs +100 -1
  11. package/dist/command-exists.mjs.map +1 -1
  12. package/dist/compress.cjs +29 -1
  13. package/dist/compress.mjs +28 -1
  14. package/dist/compress.mjs.map +1 -1
  15. package/dist/constants.mjs +1 -1
  16. package/dist/convert/src/array-buffer-to-string.cjs +19 -1
  17. package/dist/convert/src/array-buffer-to-string.mjs +18 -1
  18. package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
  19. package/dist/convert/src/to-array.cjs +15 -1
  20. package/dist/convert/src/to-array.mjs +14 -1
  21. package/dist/convert/src/to-array.mjs.map +1 -1
  22. package/dist/convert/src/uint8-array-to-string.cjs +15 -1
  23. package/dist/convert/src/uint8-array-to-string.mjs +15 -1
  24. package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
  25. package/dist/copy-file.cjs +87 -1
  26. package/dist/copy-file.mjs +83 -1
  27. package/dist/copy-file.mjs.map +1 -1
  28. package/dist/exists.cjs +27 -1
  29. package/dist/exists.mjs +25 -1
  30. package/dist/exists.mjs.map +1 -1
  31. package/dist/get-parent-path.cjs +35 -1
  32. package/dist/get-parent-path.mjs +34 -1
  33. package/dist/get-parent-path.mjs.map +1 -1
  34. package/dist/get-workspace-root.cjs +158 -1
  35. package/dist/get-workspace-root.mjs +150 -1
  36. package/dist/get-workspace-root.mjs.map +1 -1
  37. package/dist/helpers/src/get-unique.cjs +14 -1
  38. package/dist/helpers/src/get-unique.mjs +13 -1
  39. package/dist/helpers/src/get-unique.mjs.map +1 -1
  40. package/dist/helpers.cjs +83 -1
  41. package/dist/helpers.mjs +77 -1
  42. package/dist/helpers.mjs.map +1 -1
  43. package/dist/index.cjs +122 -1
  44. package/dist/index.mjs +25 -1
  45. package/dist/install.cjs +35 -1
  46. package/dist/install.mjs +33 -1
  47. package/dist/install.mjs.map +1 -1
  48. package/dist/is-file.cjs +51 -1
  49. package/dist/is-file.mjs +47 -1
  50. package/dist/is-file.mjs.map +1 -1
  51. package/dist/json/src/storm-json.cjs +117 -1
  52. package/dist/json/src/storm-json.mjs +115 -1
  53. package/dist/json/src/storm-json.mjs.map +1 -1
  54. package/dist/json/src/utils/code-frames.cjs +77 -3
  55. package/dist/json/src/utils/code-frames.mjs +76 -3
  56. package/dist/json/src/utils/code-frames.mjs.map +1 -1
  57. package/dist/json/src/utils/parse-error.cjs +34 -1
  58. package/dist/json/src/utils/parse-error.mjs +33 -1
  59. package/dist/json/src/utils/parse-error.mjs.map +1 -1
  60. package/dist/json/src/utils/parse.cjs +45 -1
  61. package/dist/json/src/utils/parse.mjs +45 -1
  62. package/dist/json/src/utils/parse.mjs.map +1 -1
  63. package/dist/json/src/utils/stringify.cjs +67 -1
  64. package/dist/json/src/utils/stringify.mjs +67 -1
  65. package/dist/json/src/utils/stringify.mjs.map +1 -1
  66. package/dist/json/src/utils/strip-comments.cjs +86 -4
  67. package/dist/json/src/utils/strip-comments.mjs +86 -4
  68. package/dist/json/src/utils/strip-comments.mjs.map +1 -1
  69. package/dist/json.cjs +74 -1
  70. package/dist/json.mjs +71 -1
  71. package/dist/json.mjs.map +1 -1
  72. package/dist/list-files.cjs +86 -1
  73. package/dist/list-files.mjs +79 -1
  74. package/dist/list-files.mjs.map +1 -1
  75. package/dist/package-fns.cjs +148 -1
  76. package/dist/package-fns.mjs +141 -1
  77. package/dist/package-fns.mjs.map +1 -1
  78. package/dist/path/src/append.cjs +57 -1
  79. package/dist/path/src/append.mjs +56 -1
  80. package/dist/path/src/append.mjs.map +1 -1
  81. package/dist/path/src/correct-path.cjs +138 -1
  82. package/dist/path/src/correct-path.mjs +134 -1
  83. package/dist/path/src/correct-path.mjs.map +1 -1
  84. package/dist/path/src/cwd.cjs +17 -1
  85. package/dist/path/src/cwd.mjs +16 -1
  86. package/dist/path/src/cwd.mjs.map +1 -1
  87. package/dist/path/src/file-path-fns.cjs +169 -1
  88. package/dist/path/src/file-path-fns.mjs +164 -1
  89. package/dist/path/src/file-path-fns.mjs.map +1 -1
  90. package/dist/path/src/is-parent-path.cjs +32 -1
  91. package/dist/path/src/is-parent-path.mjs +32 -1
  92. package/dist/path/src/is-parent-path.mjs.map +1 -1
  93. package/dist/path/src/is-root-dir.cjs +14 -1
  94. package/dist/path/src/is-root-dir.mjs +13 -1
  95. package/dist/path/src/is-root-dir.mjs.map +1 -1
  96. package/dist/path/src/is-type.cjs +68 -1
  97. package/dist/path/src/is-type.mjs +66 -1
  98. package/dist/path/src/is-type.mjs.map +1 -1
  99. package/dist/path/src/join-paths.cjs +106 -1
  100. package/dist/path/src/join-paths.mjs +106 -1
  101. package/dist/path/src/join-paths.mjs.map +1 -1
  102. package/dist/path/src/regex.cjs +18 -1
  103. package/dist/path/src/regex.mjs +11 -1
  104. package/dist/path/src/regex.mjs.map +1 -1
  105. package/dist/path/src/replace.cjs +24 -1
  106. package/dist/path/src/replace.mjs +24 -1
  107. package/dist/path/src/replace.mjs.map +1 -1
  108. package/dist/path/src/resolve-parent-path.cjs +18 -1
  109. package/dist/path/src/resolve-parent-path.mjs +18 -1
  110. package/dist/path/src/resolve-parent-path.mjs.map +1 -1
  111. package/dist/path/src/slash.cjs +15 -1
  112. package/dist/path/src/slash.mjs +14 -1
  113. package/dist/path/src/slash.mjs.map +1 -1
  114. package/dist/read-file.cjs +47 -1
  115. package/dist/read-file.mjs +43 -1
  116. package/dist/read-file.mjs.map +1 -1
  117. package/dist/registry.cjs +142 -1
  118. package/dist/registry.mjs +137 -1
  119. package/dist/registry.mjs.map +1 -1
  120. package/dist/remove-file.cjs +27 -1
  121. package/dist/remove-file.mjs +25 -1
  122. package/dist/remove-file.mjs.map +1 -1
  123. package/dist/resolve.cjs +228 -3
  124. package/dist/resolve.mjs +217 -3
  125. package/dist/resolve.mjs.map +1 -1
  126. package/dist/semver-fns.cjs +129 -1
  127. package/dist/semver-fns.mjs +119 -1
  128. package/dist/semver-fns.mjs.map +1 -1
  129. package/dist/string-format/src/package.cjs +92 -1
  130. package/dist/string-format/src/package.mjs +91 -1
  131. package/dist/string-format/src/package.mjs.map +1 -1
  132. package/dist/toml.cjs +66 -3
  133. package/dist/toml.mjs +61 -3
  134. package/dist/toml.mjs.map +1 -1
  135. package/dist/tsconfig.cjs +37 -1
  136. package/dist/tsconfig.mjs +35 -1
  137. package/dist/tsconfig.mjs.map +1 -1
  138. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  139. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  140. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  141. package/dist/type-checks/src/index.cjs +14 -1
  142. package/dist/type-checks/src/index.mjs +16 -1
  143. package/dist/type-checks/src/is-buffer.cjs +12 -1
  144. package/dist/type-checks/src/is-buffer.mjs +11 -1
  145. package/dist/type-checks/src/is-buffer.mjs.map +1 -1
  146. package/dist/type-checks/src/is-collection.cjs +1 -1
  147. package/dist/type-checks/src/is-collection.mjs +3 -1
  148. package/dist/type-checks/src/is-empty.cjs +20 -1
  149. package/dist/type-checks/src/is-empty.mjs +20 -1
  150. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  151. package/dist/type-checks/src/is-error.cjs +29 -1
  152. package/dist/type-checks/src/is-error.mjs +29 -1
  153. package/dist/type-checks/src/is-error.mjs.map +1 -1
  154. package/dist/type-checks/src/is-null.cjs +12 -1
  155. package/dist/type-checks/src/is-null.mjs +11 -1
  156. package/dist/type-checks/src/is-null.mjs.map +1 -1
  157. package/dist/type-checks/src/is-number.cjs +18 -1
  158. package/dist/type-checks/src/is-number.mjs +17 -1
  159. package/dist/type-checks/src/is-number.mjs.map +1 -1
  160. package/dist/type-checks/src/is-object.cjs +19 -1
  161. package/dist/type-checks/src/is-object.mjs +19 -1
  162. package/dist/type-checks/src/is-object.mjs.map +1 -1
  163. package/dist/type-checks/src/is-plain-object.cjs +64 -1
  164. package/dist/type-checks/src/is-plain-object.mjs +63 -1
  165. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  166. package/dist/type-checks/src/is-set-string.cjs +20 -1
  167. package/dist/type-checks/src/is-set-string.mjs +20 -1
  168. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  169. package/dist/type-checks/src/is-set.cjs +19 -1
  170. package/dist/type-checks/src/is-set.mjs +19 -1
  171. package/dist/type-checks/src/is-set.mjs.map +1 -1
  172. package/dist/type-checks/src/is-string.cjs +12 -1
  173. package/dist/type-checks/src/is-string.mjs +11 -1
  174. package/dist/type-checks/src/is-string.mjs.map +1 -1
  175. package/dist/type-checks/src/is-undefined.cjs +8 -1
  176. package/dist/type-checks/src/is-undefined.mjs +7 -1
  177. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  178. package/dist/type-checks/src/type-detect.cjs +15 -1
  179. package/dist/type-checks/src/type-detect.mjs +16 -1
  180. package/dist/type-checks/src/type-detect.mjs.map +1 -1
  181. package/dist/types/src/base.cjs +6 -1
  182. package/dist/types/src/base.mjs +5 -1
  183. package/dist/types/src/base.mjs.map +1 -1
  184. package/dist/write-file.cjs +40 -1
  185. package/dist/write-file.mjs +38 -1
  186. package/dist/write-file.mjs.map +1 -1
  187. package/dist/yaml.cjs +29 -1
  188. package/dist/yaml.mjs +27 -1
  189. package/dist/yaml.mjs.map +1 -1
  190. package/package.json +6 -6
package/dist/registry.cjs CHANGED
@@ -1 +1,142 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./get-workspace-root.cjs`);let n=require(`node:child_process`),r=require(`@antfu/install-pkg`),i=require(`node:util`);const a=e=>{let{values:t,tokens:n}=(0,i.parseArgs)({args:e,strict:!1,tokens:!0}),r=null;for(let e=0;e<n.length;e++){let i=n[e];if(i.kind===`option-terminator`)break;if(i.kind===`option`){r=i.value===void 0?i:null;continue}if(i.kind!==`positional`){r=null;continue}r&&(r.name in t&&typeof t[r.name]==`string`?t[r.name]+=` ${i.value}`:t[r.name]=i.value)}return t},o=e=>{let t=[],n=!1,r=!0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`&&n){if(e.length===i+1)throw Error(`Invalid escape character at the end.`);a=e[++i]}else if(a===` `&&!n){r=!0;continue}else if(a===`"`){n=!n;continue}r?(t.push(a),r=!1):t[t.length-1]+=a}if(n)throw Error(`Unterminated string`);return t},s=()=>process.env.NODE_OPTIONS?o(process.env.NODE_OPTIONS):[];function c(e){return Object.entries(e).map(([e,t])=>t===!0?`--${e}`:t?`--${e}=${t.includes(` `)&&!t.startsWith(`"`)?JSON.stringify(t):t}`:null).filter(e=>e!==null).join(` `)}function l(){let e=s();if(e.length===0)return{};let t=a(e);return delete t.inspect,delete t[`inspect-brk`],delete t.inspect_brk,t}function u(){let e=l();return Object.keys(e).length===0?``:c(e)}async function d(e){let i=await(0,r.detectPackageManager)(t.getWorkspaceRoot(e)),a=i===`npm`?`--no-workspaces`:``,o=`https://registry.npmjs.org/`;try{let e=(0,n.execSync)(`${i} config get registry ${a}`,{env:{...process.env,NODE_OPTIONS:u()}}).toString().trim();e.startsWith(`http`)&&(o=e.endsWith(`/`)?e:`${e}/`)}catch(e){throw Error(`Failed to get registry from "${i}".`,{cause:e})}return o}exports.formatNodeOptions=c,exports.getFormattedNodeOptionsWithoutInspect=u,exports.getParsedNodeOptionsWithoutInspect=l,exports.getRegistry=d,exports.tokenizeArgs=o;
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 as e}from"./get-workspace-root.mjs";import{execSync as t}from"node:child_process";import{detectPackageManager as n}from"@antfu/install-pkg";import{parseArgs as r}from"node:util";const i=e=>{let{values:t,tokens:n}=r({args:e,strict:!1,tokens:!0}),i=null;for(let e=0;e<n.length;e++){let r=n[e];if(r.kind===`option-terminator`)break;if(r.kind===`option`){i=r.value===void 0?r:null;continue}if(r.kind!==`positional`){i=null;continue}i&&(i.name in t&&typeof t[i.name]==`string`?t[i.name]+=` ${r.value}`:t[i.name]=r.value)}return t},a=e=>{let t=[],n=!1,r=!0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`&&n){if(e.length===i+1)throw Error(`Invalid escape character at the end.`);a=e[++i]}else if(a===` `&&!n){r=!0;continue}else if(a===`"`){n=!n;continue}r?(t.push(a),r=!1):t[t.length-1]+=a}if(n)throw Error(`Unterminated string`);return t},o=()=>process.env.NODE_OPTIONS?a(process.env.NODE_OPTIONS):[];function s(e){return Object.entries(e).map(([e,t])=>t===!0?`--${e}`:t?`--${e}=${t.includes(` `)&&!t.startsWith(`"`)?JSON.stringify(t):t}`:null).filter(e=>e!==null).join(` `)}function c(){let e=o();if(e.length===0)return{};let t=i(e);return delete t.inspect,delete t[`inspect-brk`],delete t.inspect_brk,t}function l(){let e=c();return Object.keys(e).length===0?``:s(e)}async function u(r){let i=await n(e(r)),a=i===`npm`?`--no-workspaces`:``,o=`https://registry.npmjs.org/`;try{let e=t(`${i} config get registry ${a}`,{env:{...process.env,NODE_OPTIONS:l()}}).toString().trim();e.startsWith(`http`)&&(o=e.endsWith(`/`)?e:`${e}/`)}catch(e){throw Error(`Failed to get registry from "${i}".`,{cause:e})}return o}export{s as formatNodeOptions,l as getFormattedNodeOptionsWithoutInspect,c as getParsedNodeOptionsWithoutInspect,u as getRegistry,a as tokenizeArgs};
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
@@ -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"}
@@ -1 +1,27 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`node:fs`),n=require(`node:fs/promises`);const r=e=>{!e||!(0,t.existsSync)(e)||(0,t.rmSync)(e)},i=async e=>{if(!(!e||!(0,t.existsSync)(e)))return(0,n.rm)(e)};exports.removeFile=i,exports.removeFileSync=r;
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;
@@ -1,2 +1,26 @@
1
- import{existsSync as e,rmSync as t}from"node:fs";import{rm as n}from"node:fs/promises";const r=n=>{!n||!e(n)||t(n)},i=async t=>{if(!(!t||!e(t)))return n(t)};export{i as removeFile,r as removeFileSync};
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
@@ -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":"uFA0BA,MAAa,EAAkB,GAA2B,CACpD,CAAC,GAAY,CAAC,EAAW,EAAS,EAItC,EAAO,EAAS,EAQL,EAAa,KAAO,IAAoC,CAC/D,MAAC,GAAY,CAAC,EAAW,EAAS,EAItC,OAAO,EAAG,EAAS"}
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 e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./path/src/cwd.cjs`),n=require(`./path/src/is-type.cjs`),r=require(`./path/src/join-paths.cjs`),i=require(`./path/src/append.cjs`),a=require(`./path/src/correct-path.cjs`),o=require(`./path/src/file-path-fns.cjs`),s=require(`./exists.cjs`),c=require(`./get-workspace-root.cjs`),l=require(`./helpers/src/get-unique.cjs`);let u=require(`mlly`);const d=[`js`,`jsx`,`mjs`,`cjs`,`ts`,`tsx`,`mts`,`cts`,`json`,`jsonc`,`json5`,`node`];function f(e=[]){let r=e;r.includes(t.cwd())||r.push(t.cwd());let i=c.getWorkspaceRoot();return r.includes(i)||r.push(i),r=l.getUnique(r.filter(Boolean).map(e=>a.correctPath(e)).reduce((e,r,o,s)=>(e.push(r),n.isAbsolutePath(r)||(e.push(a.toAbsolutePath(r,t.cwd())),e.push(a.toAbsolutePath(r,i)),s.forEach(t=>{e.push(a.toAbsolutePath(r,t))})),e),[])),r}function p(e=[]){return l.getUnique(e.reduce((e,t)=>(o.findFolderName(t)===`node_modules`&&e.push(a.correctPath(t)),s.existsSync(r.joinPaths(t,`node_modules`))&&e.push(a.correctPath(r.joinPaths(t,`node_modules`))),e),[]))}function m(e,t={}){let s=f(t.paths);n.isNpmScopedPackage(e)?s=p(s):s.push(...p(s));let c=t.extensions??d,u=s.map(t=>r.joinPaths(t,e));return o.findFileName(e,{withExtension:!1})!==`index`&&(u=u.reduce((e,t)=>(e.push(t),e.push(r.joinPaths(t,`index`)),e),[])),o.findFileExtension(e)||(u=u.reduce((e,t)=>(e.push(t),c.forEach(n=>{e.push(i.appendExtension(t,n))}),e),[])),l.getUnique(u.filter(Boolean)).map(e=>a.correctPath(e))}async function h(e,t={}){let r=f(t.paths);n.isNpmScopedPackage(e)?r=p(r):r.push(...p(r));let i,o;try{i=await(0,u.resolvePath)(e,{url:r,extensions:t.extensions??d,conditions:t.conditions})}catch(e){o=e}if(!i)throw Error(`Unable to resolve module "${e}". The following import paths were tried: \n${r.join(`
2
- `)}`,{cause:o});return a.correctPath(i)}function g(e,t={}){let r=f(t.paths);n.isNpmScopedPackage(e)?r=p(r):r.push(...p(r));let i,o;try{i=(0,u.resolvePathSync)(e,{url:r,extensions:t.extensions??d,conditions:t.conditions})}catch(e){o=e}if(!i)throw Error(`Unable to resolve module "${e}". The following import paths were tried: \n${r.join(`
3
- `)}`,{cause:o});return a.correctPath(i)}async function _(e,t={}){try{return await h(e,t)}catch{return}}function v(e,t={}){try{return g(e,t)}catch{return}}async function y(e){let t=await import(e);return t&&(0,u.interopDefault)(t)}async function b(e,t={}){let n=await _(r.joinPaths(e,`package.json`),t);return n||(n=await _(r.joinPaths(e,`index.js`),t),n||=await _(e,t)),n?o.findFilePath(n):void 0}function x(e,t={}){let n=v(r.joinPaths(e,`package.json`),t);return n||(n=v(r.joinPaths(e,`index.js`),t),n||=v(e,t)),n?o.findFilePath(n):void 0}exports.DEFAULT_EXTENSIONS=d,exports.getNodeModulesPaths=p,exports.getResolutionCombinations=m,exports.getResolutionPaths=f,exports.importModule=y,exports.resolve=h,exports.resolvePackage=b,exports.resolvePackageSync=x,exports.resolveSafe=_,exports.resolveSafeSync=v,exports.resolveSync=g;
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;