sonamu 0.0.42 → 0.1.0

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 (208) hide show
  1. package/.pnp.cjs +1963 -951
  2. package/.pnp.loader.mjs +1816 -54
  3. package/.yarnrc.yml +1 -1
  4. package/dist/api/code-converters.d.ts +3 -3
  5. package/dist/api/code-converters.d.ts.map +1 -1
  6. package/dist/api/code-converters.js +5 -15
  7. package/dist/api/code-converters.js.map +1 -1
  8. package/dist/api/context.d.ts +1 -1
  9. package/dist/api/context.d.ts.map +1 -1
  10. package/dist/api/decorators.d.ts +3 -3
  11. package/dist/api/decorators.d.ts.map +1 -1
  12. package/dist/api/sonamu.d.ts +3 -3
  13. package/dist/api/sonamu.d.ts.map +1 -1
  14. package/dist/api/sonamu.js +6 -6
  15. package/dist/api/sonamu.js.map +1 -1
  16. package/dist/bin/cli.js +132 -33
  17. package/dist/bin/cli.js.map +1 -1
  18. package/dist/database/db.d.ts +2 -2
  19. package/dist/database/db.d.ts.map +1 -1
  20. package/dist/database/db.js +1 -1
  21. package/dist/database/db.js.map +1 -1
  22. package/dist/database/upsert-builder.d.ts +2 -2
  23. package/dist/database/upsert-builder.d.ts.map +1 -1
  24. package/dist/database/upsert-builder.js +10 -8
  25. package/dist/database/upsert-builder.js.map +1 -1
  26. package/dist/entity/entity-manager.d.ts +29 -0
  27. package/dist/entity/entity-manager.d.ts.map +1 -0
  28. package/dist/entity/entity-manager.js +128 -0
  29. package/dist/entity/entity-manager.js.map +1 -0
  30. package/dist/entity/entity-utils.d.ts +61 -0
  31. package/dist/entity/entity-utils.d.ts.map +1 -0
  32. package/dist/entity/entity-utils.js +121 -0
  33. package/dist/entity/entity-utils.js.map +1 -0
  34. package/dist/entity/entity.d.ts +49 -0
  35. package/dist/entity/entity.d.ts.map +1 -0
  36. package/dist/entity/entity.js +504 -0
  37. package/dist/entity/entity.js.map +1 -0
  38. package/dist/entity/migrator.d.ts +143 -0
  39. package/dist/entity/migrator.d.ts.map +1 -0
  40. package/dist/entity/migrator.js +1385 -0
  41. package/dist/entity/migrator.js.map +1 -0
  42. package/dist/entity/smd-utils.d.ts +61 -0
  43. package/dist/entity/smd-utils.d.ts.map +1 -0
  44. package/dist/entity/smd-utils.js +121 -0
  45. package/dist/entity/smd-utils.js.map +1 -0
  46. package/dist/index.d.ts +3 -3
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +3 -3
  49. package/dist/index.js.map +1 -1
  50. package/dist/smd/entity-manager.d.ts +28 -0
  51. package/dist/smd/entity-manager.d.ts.map +1 -0
  52. package/dist/smd/entity-manager.js +119 -0
  53. package/dist/smd/entity-manager.js.map +1 -0
  54. package/dist/smd/entity.d.ts +40 -0
  55. package/dist/smd/entity.d.ts.map +1 -0
  56. package/dist/smd/entity.js +430 -0
  57. package/dist/smd/entity.js.map +1 -0
  58. package/dist/smd/migrator.d.ts +2 -2
  59. package/dist/smd/migrator.d.ts.map +1 -1
  60. package/dist/smd/migrator.js +5 -5
  61. package/dist/smd/migrator.js.map +1 -1
  62. package/dist/smd/smd-manager.d.ts +3 -3
  63. package/dist/smd/smd-manager.d.ts.map +1 -1
  64. package/dist/smd/smd-manager.js +2 -2
  65. package/dist/smd/smd-manager.js.map +1 -1
  66. package/dist/smd/smd-utils.d.ts +3 -3
  67. package/dist/smd/smd-utils.d.ts.map +1 -1
  68. package/dist/smd/smd.d.ts +5 -6
  69. package/dist/smd/smd.d.ts.map +1 -1
  70. package/dist/smd/smd.js +3 -3
  71. package/dist/smd/smd.js.map +1 -1
  72. package/dist/syncer/syncer.d.ts +15 -11
  73. package/dist/syncer/syncer.d.ts.map +1 -1
  74. package/dist/syncer/syncer.js +134 -74
  75. package/dist/syncer/syncer.js.map +1 -1
  76. package/dist/templates/base-template.d.ts +2 -2
  77. package/dist/templates/base-template.d.ts.map +1 -1
  78. package/dist/templates/entity.template.d.ts +17 -0
  79. package/dist/templates/entity.template.d.ts.map +1 -0
  80. package/dist/templates/entity.template.js +46 -0
  81. package/dist/templates/entity.template.js.map +1 -0
  82. package/dist/templates/generated.template.d.ts +11 -7
  83. package/dist/templates/generated.template.d.ts.map +1 -1
  84. package/dist/templates/generated.template.js +72 -43
  85. package/dist/templates/generated.template.js.map +1 -1
  86. package/dist/templates/generated_http.template.d.ts +3 -3
  87. package/dist/templates/generated_http.template.d.ts.map +1 -1
  88. package/dist/templates/generated_http.template.js +3 -3
  89. package/dist/templates/generated_http.template.js.map +1 -1
  90. package/dist/templates/init_enums.template.d.ts +2 -2
  91. package/dist/templates/init_enums.template.d.ts.map +1 -1
  92. package/dist/templates/init_enums.template.js +2 -2
  93. package/dist/templates/init_enums.template.js.map +1 -1
  94. package/dist/templates/init_generated.template.d.ts +3 -3
  95. package/dist/templates/init_generated.template.d.ts.map +1 -1
  96. package/dist/templates/init_generated.template.js +13 -14
  97. package/dist/templates/init_generated.template.js.map +1 -1
  98. package/dist/templates/init_types.template.d.ts +3 -3
  99. package/dist/templates/init_types.template.d.ts.map +1 -1
  100. package/dist/templates/init_types.template.js +10 -10
  101. package/dist/templates/init_types.template.js.map +1 -1
  102. package/dist/templates/model.template.d.ts +3 -3
  103. package/dist/templates/model.template.d.ts.map +1 -1
  104. package/dist/templates/model.template.js +28 -28
  105. package/dist/templates/model.template.js.map +1 -1
  106. package/dist/templates/model_test.template.d.ts +3 -3
  107. package/dist/templates/model_test.template.d.ts.map +1 -1
  108. package/dist/templates/model_test.template.js +4 -4
  109. package/dist/templates/model_test.template.js.map +1 -1
  110. package/dist/templates/service.template.d.ts +3 -3
  111. package/dist/templates/service.template.d.ts.map +1 -1
  112. package/dist/templates/service.template.js +3 -3
  113. package/dist/templates/service.template.js.map +1 -1
  114. package/dist/templates/smd.template.d.ts +2 -2
  115. package/dist/templates/smd.template.d.ts.map +1 -1
  116. package/dist/templates/smd.template.js +2 -2
  117. package/dist/templates/smd.template.js.map +1 -1
  118. package/dist/templates/view_enums_buttonset.template.d.ts +3 -3
  119. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -1
  120. package/dist/templates/view_enums_buttonset.template.js +4 -4
  121. package/dist/templates/view_enums_buttonset.template.js.map +1 -1
  122. package/dist/templates/view_enums_dropdown.template.d.ts +3 -3
  123. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -1
  124. package/dist/templates/view_enums_dropdown.template.js +3 -3
  125. package/dist/templates/view_enums_dropdown.template.js.map +1 -1
  126. package/dist/templates/view_enums_select.template.d.ts +3 -3
  127. package/dist/templates/view_enums_select.template.d.ts.map +1 -1
  128. package/dist/templates/view_enums_select.template.js +3 -3
  129. package/dist/templates/view_enums_select.template.js.map +1 -1
  130. package/dist/templates/view_form.template.d.ts +25 -29
  131. package/dist/templates/view_form.template.d.ts.map +1 -1
  132. package/dist/templates/view_form.template.js +19 -19
  133. package/dist/templates/view_form.template.js.map +1 -1
  134. package/dist/templates/view_id_all_select.template.d.ts +3 -3
  135. package/dist/templates/view_id_all_select.template.d.ts.map +1 -1
  136. package/dist/templates/view_id_all_select.template.js +4 -4
  137. package/dist/templates/view_id_all_select.template.js.map +1 -1
  138. package/dist/templates/view_id_async_select.template.d.ts +3 -3
  139. package/dist/templates/view_id_async_select.template.d.ts.map +1 -1
  140. package/dist/templates/view_id_async_select.template.js +6 -6
  141. package/dist/templates/view_id_async_select.template.js.map +1 -1
  142. package/dist/templates/view_list.template.d.ts +30 -34
  143. package/dist/templates/view_list.template.d.ts.map +1 -1
  144. package/dist/templates/view_list.template.js +40 -40
  145. package/dist/templates/view_list.template.js.map +1 -1
  146. package/dist/templates/view_list_columns.template.d.ts +3 -3
  147. package/dist/templates/view_list_columns.template.d.ts.map +1 -1
  148. package/dist/templates/view_list_columns.template.js +3 -3
  149. package/dist/templates/view_list_columns.template.js.map +1 -1
  150. package/dist/templates/view_search_input.template.d.ts +3 -3
  151. package/dist/templates/view_search_input.template.d.ts.map +1 -1
  152. package/dist/templates/view_search_input.template.js +3 -3
  153. package/dist/templates/view_search_input.template.js.map +1 -1
  154. package/dist/testing/fixture-manager.d.ts +2 -2
  155. package/dist/testing/fixture-manager.d.ts.map +1 -1
  156. package/dist/testing/fixture-manager.js +18 -16
  157. package/dist/testing/fixture-manager.js.map +1 -1
  158. package/dist/types/smd.types.d.ts +741 -0
  159. package/dist/types/smd.types.d.ts.map +1 -0
  160. package/dist/types/smd.types.js +292 -0
  161. package/dist/types/smd.types.js.map +1 -0
  162. package/dist/types/types.d.ts +185 -188
  163. package/dist/types/types.d.ts.map +1 -1
  164. package/dist/types/types.js +22 -30
  165. package/dist/types/types.js.map +1 -1
  166. package/dist/utils/model.d.ts +2 -2
  167. package/dist/utils/model.d.ts.map +1 -1
  168. package/dist/utils/utils.d.ts +1 -0
  169. package/dist/utils/utils.d.ts.map +1 -1
  170. package/dist/utils/utils.js +6 -2
  171. package/dist/utils/utils.js.map +1 -1
  172. package/package.json +11 -8
  173. package/src/api/code-converters.ts +9 -17
  174. package/src/api/sonamu.ts +10 -6
  175. package/src/bin/cli.ts +156 -27
  176. package/src/database/upsert-builder.ts +2 -2
  177. package/src/entity/entity-manager.ts +150 -0
  178. package/src/{smd/smd-utils.ts → entity/entity-utils.ts} +3 -3
  179. package/src/entity/entity.ts +666 -0
  180. package/src/{smd → entity}/migrator.ts +426 -106
  181. package/src/index.ts +3 -3
  182. package/src/smd/smd-manager.ts +3 -13
  183. package/src/smd/smd.ts +13 -10
  184. package/src/syncer/syncer.ts +125 -73
  185. package/src/templates/base-template.ts +2 -2
  186. package/src/templates/entity.template.ts +50 -0
  187. package/src/templates/generated.template.ts +93 -57
  188. package/src/templates/generated_http.template.ts +4 -4
  189. package/src/templates/init_types.template.ts +11 -11
  190. package/src/templates/model.template.ts +29 -29
  191. package/src/templates/model_test.template.ts +5 -5
  192. package/src/templates/service.template.ts +4 -4
  193. package/src/templates/view_enums_buttonset.template.ts +5 -5
  194. package/src/templates/view_enums_dropdown.template.ts +4 -4
  195. package/src/templates/view_enums_select.template.ts +8 -4
  196. package/src/templates/view_form.template.ts +21 -21
  197. package/src/templates/view_id_all_select.template.ts +5 -5
  198. package/src/templates/view_id_async_select.template.ts +9 -7
  199. package/src/templates/view_list.template.ts +54 -44
  200. package/src/templates/view_list_columns.template.ts +4 -4
  201. package/src/templates/view_search_input.template.ts +4 -4
  202. package/src/testing/fixture-manager.ts +12 -12
  203. package/src/types/types.ts +59 -39
  204. package/src/utils/utils.ts +4 -0
  205. package/tsconfig.json +4 -1
  206. package/src/templates/init_enums.template.ts +0 -71
  207. package/src/templates/init_generated.template.ts +0 -51
  208. package/src/templates/smd.template.ts +0 -53
package/.pnp.loader.mjs CHANGED
@@ -1,14 +1,17 @@
1
- import { URL, fileURLToPath, pathToFileURL } from 'url';
1
+ import { URL as URL$1, fileURLToPath, pathToFileURL } from 'url';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import moduleExports, { Module } from 'module';
5
+ import { EOL } from 'os';
6
+ import assert from 'assert';
5
7
 
6
- var PathType;
7
- (function(PathType2) {
8
- PathType2[PathType2["File"] = 0] = "File";
9
- PathType2[PathType2["Portable"] = 1] = "Portable";
10
- PathType2[PathType2["Native"] = 2] = "Native";
11
- })(PathType || (PathType = {}));
8
+ const SAFE_TIME = 456789e3;
9
+
10
+ const PortablePath = {
11
+ root: `/`,
12
+ dot: `.`,
13
+ parent: `..`
14
+ };
12
15
  const npath = Object.create(path);
13
16
  const ppath = Object.create(path.posix);
14
17
  npath.cwd = () => process.cwd();
@@ -64,6 +67,1273 @@ function toPortablePath(p) {
64
67
  p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
65
68
  return p;
66
69
  }
70
+ function convertPath(targetPathUtils, sourcePath) {
71
+ return targetPathUtils === npath ? fromPortablePath(sourcePath) : toPortablePath(sourcePath);
72
+ }
73
+
74
+ const defaultTime = new Date(SAFE_TIME * 1e3);
75
+ async function copyPromise(destinationFs, destination, sourceFs, source, opts) {
76
+ const normalizedDestination = destinationFs.pathUtils.normalize(destination);
77
+ const normalizedSource = sourceFs.pathUtils.normalize(source);
78
+ const prelayout = [];
79
+ const postlayout = [];
80
+ const { atime, mtime } = opts.stableTime ? { atime: defaultTime, mtime: defaultTime } : await sourceFs.lstatPromise(normalizedSource);
81
+ await destinationFs.mkdirpPromise(destinationFs.pathUtils.dirname(destination), { utimes: [atime, mtime] });
82
+ const updateTime = typeof destinationFs.lutimesPromise === `function` ? destinationFs.lutimesPromise.bind(destinationFs) : destinationFs.utimesPromise.bind(destinationFs);
83
+ await copyImpl(prelayout, postlayout, updateTime, destinationFs, normalizedDestination, sourceFs, normalizedSource, { ...opts, didParentExist: true });
84
+ for (const operation of prelayout)
85
+ await operation();
86
+ await Promise.all(postlayout.map((operation) => {
87
+ return operation();
88
+ }));
89
+ }
90
+ async function copyImpl(prelayout, postlayout, updateTime, destinationFs, destination, sourceFs, source, opts) {
91
+ var _a, _b;
92
+ const destinationStat = opts.didParentExist ? await maybeLStat(destinationFs, destination) : null;
93
+ const sourceStat = await sourceFs.lstatPromise(source);
94
+ const { atime, mtime } = opts.stableTime ? { atime: defaultTime, mtime: defaultTime } : sourceStat;
95
+ let updated;
96
+ switch (true) {
97
+ case sourceStat.isDirectory():
98
+ {
99
+ updated = await copyFolder(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts);
100
+ }
101
+ break;
102
+ case sourceStat.isFile():
103
+ {
104
+ updated = await copyFile(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts);
105
+ }
106
+ break;
107
+ case sourceStat.isSymbolicLink():
108
+ {
109
+ updated = await copySymlink(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts);
110
+ }
111
+ break;
112
+ default:
113
+ {
114
+ throw new Error(`Unsupported file type (${sourceStat.mode})`);
115
+ }
116
+ }
117
+ if (updated || ((_a = destinationStat == null ? void 0 : destinationStat.mtime) == null ? void 0 : _a.getTime()) !== mtime.getTime() || ((_b = destinationStat == null ? void 0 : destinationStat.atime) == null ? void 0 : _b.getTime()) !== atime.getTime()) {
118
+ postlayout.push(() => updateTime(destination, atime, mtime));
119
+ updated = true;
120
+ }
121
+ if (destinationStat === null || (destinationStat.mode & 511) !== (sourceStat.mode & 511)) {
122
+ postlayout.push(() => destinationFs.chmodPromise(destination, sourceStat.mode & 511));
123
+ updated = true;
124
+ }
125
+ return updated;
126
+ }
127
+ async function maybeLStat(baseFs, p) {
128
+ try {
129
+ return await baseFs.lstatPromise(p);
130
+ } catch (e) {
131
+ return null;
132
+ }
133
+ }
134
+ async function copyFolder(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) {
135
+ if (destinationStat !== null && !destinationStat.isDirectory()) {
136
+ if (opts.overwrite) {
137
+ prelayout.push(async () => destinationFs.removePromise(destination));
138
+ destinationStat = null;
139
+ } else {
140
+ return false;
141
+ }
142
+ }
143
+ let updated = false;
144
+ if (destinationStat === null) {
145
+ prelayout.push(async () => {
146
+ try {
147
+ await destinationFs.mkdirPromise(destination, { mode: sourceStat.mode });
148
+ } catch (err) {
149
+ if (err.code !== `EEXIST`) {
150
+ throw err;
151
+ }
152
+ }
153
+ });
154
+ updated = true;
155
+ }
156
+ const entries = await sourceFs.readdirPromise(source);
157
+ const nextOpts = opts.didParentExist && !destinationStat ? { ...opts, didParentExist: false } : opts;
158
+ if (opts.stableSort) {
159
+ for (const entry of entries.sort()) {
160
+ if (await copyImpl(prelayout, postlayout, updateTime, destinationFs, destinationFs.pathUtils.join(destination, entry), sourceFs, sourceFs.pathUtils.join(source, entry), nextOpts)) {
161
+ updated = true;
162
+ }
163
+ }
164
+ } else {
165
+ const entriesUpdateStatus = await Promise.all(entries.map(async (entry) => {
166
+ await copyImpl(prelayout, postlayout, updateTime, destinationFs, destinationFs.pathUtils.join(destination, entry), sourceFs, sourceFs.pathUtils.join(source, entry), nextOpts);
167
+ }));
168
+ if (entriesUpdateStatus.some((status) => status)) {
169
+ updated = true;
170
+ }
171
+ }
172
+ return updated;
173
+ }
174
+ const isCloneSupportedCache = /* @__PURE__ */ new WeakMap();
175
+ function makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy) {
176
+ return async () => {
177
+ await opFs.linkPromise(source, destination);
178
+ if (linkStrategy === "readOnly" /* ReadOnly */) {
179
+ sourceStat.mode &= ~146;
180
+ await opFs.chmodPromise(destination, sourceStat.mode);
181
+ }
182
+ };
183
+ }
184
+ function makeCloneLinkOperation(opFs, destination, source, sourceStat, linkStrategy) {
185
+ const isCloneSupported = isCloneSupportedCache.get(opFs);
186
+ if (typeof isCloneSupported === `undefined`) {
187
+ return async () => {
188
+ try {
189
+ await opFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE_FORCE);
190
+ isCloneSupportedCache.set(opFs, true);
191
+ } catch (err) {
192
+ if (err.code === `ENOSYS` || err.code === `ENOTSUP`) {
193
+ isCloneSupportedCache.set(opFs, false);
194
+ await makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy)();
195
+ } else {
196
+ throw err;
197
+ }
198
+ }
199
+ };
200
+ } else {
201
+ if (isCloneSupported) {
202
+ return async () => opFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE_FORCE);
203
+ } else {
204
+ return makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy);
205
+ }
206
+ }
207
+ }
208
+ async function copyFile(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) {
209
+ var _a;
210
+ if (destinationStat !== null) {
211
+ if (opts.overwrite) {
212
+ prelayout.push(async () => destinationFs.removePromise(destination));
213
+ destinationStat = null;
214
+ } else {
215
+ return false;
216
+ }
217
+ }
218
+ const linkStrategy = (_a = opts.linkStrategy) != null ? _a : null;
219
+ const op = destinationFs === sourceFs ? linkStrategy !== null ? makeCloneLinkOperation(destinationFs, destination, source, sourceStat, linkStrategy) : async () => destinationFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE) : linkStrategy !== null ? makeLinkOperation(destinationFs, destination, source, sourceStat, linkStrategy) : async () => destinationFs.writeFilePromise(destination, await sourceFs.readFilePromise(source));
220
+ prelayout.push(async () => op());
221
+ return true;
222
+ }
223
+ async function copySymlink(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) {
224
+ if (destinationStat !== null) {
225
+ if (opts.overwrite) {
226
+ prelayout.push(async () => destinationFs.removePromise(destination));
227
+ destinationStat = null;
228
+ } else {
229
+ return false;
230
+ }
231
+ }
232
+ prelayout.push(async () => {
233
+ await destinationFs.symlinkPromise(convertPath(destinationFs.pathUtils, await sourceFs.readlinkPromise(source)), destination);
234
+ });
235
+ return true;
236
+ }
237
+
238
+ function makeError(code, message) {
239
+ return Object.assign(new Error(`${code}: ${message}`), { code });
240
+ }
241
+ function ENOSYS(message, reason) {
242
+ return makeError(`ENOSYS`, `${message}, ${reason}`);
243
+ }
244
+
245
+ class FakeFS {
246
+ constructor(pathUtils) {
247
+ this.pathUtils = pathUtils;
248
+ }
249
+ async *genTraversePromise(init, { stableSort = false } = {}) {
250
+ const stack = [init];
251
+ while (stack.length > 0) {
252
+ const p = stack.shift();
253
+ const entry = await this.lstatPromise(p);
254
+ if (entry.isDirectory()) {
255
+ const entries = await this.readdirPromise(p);
256
+ if (stableSort) {
257
+ for (const entry2 of entries.sort()) {
258
+ stack.push(this.pathUtils.join(p, entry2));
259
+ }
260
+ } else {
261
+ throw new Error(`Not supported`);
262
+ }
263
+ } else {
264
+ yield p;
265
+ }
266
+ }
267
+ }
268
+ async removePromise(p, { recursive = true, maxRetries = 5 } = {}) {
269
+ let stat;
270
+ try {
271
+ stat = await this.lstatPromise(p);
272
+ } catch (error) {
273
+ if (error.code === `ENOENT`) {
274
+ return;
275
+ } else {
276
+ throw error;
277
+ }
278
+ }
279
+ if (stat.isDirectory()) {
280
+ if (recursive) {
281
+ const entries = await this.readdirPromise(p);
282
+ await Promise.all(entries.map((entry) => {
283
+ return this.removePromise(this.pathUtils.resolve(p, entry));
284
+ }));
285
+ }
286
+ for (let t = 0; t <= maxRetries; t++) {
287
+ try {
288
+ await this.rmdirPromise(p);
289
+ break;
290
+ } catch (error) {
291
+ if (error.code !== `EBUSY` && error.code !== `ENOTEMPTY`) {
292
+ throw error;
293
+ } else if (t < maxRetries) {
294
+ await new Promise((resolve) => setTimeout(resolve, t * 100));
295
+ }
296
+ }
297
+ }
298
+ } else {
299
+ await this.unlinkPromise(p);
300
+ }
301
+ }
302
+ removeSync(p, { recursive = true } = {}) {
303
+ let stat;
304
+ try {
305
+ stat = this.lstatSync(p);
306
+ } catch (error) {
307
+ if (error.code === `ENOENT`) {
308
+ return;
309
+ } else {
310
+ throw error;
311
+ }
312
+ }
313
+ if (stat.isDirectory()) {
314
+ if (recursive)
315
+ for (const entry of this.readdirSync(p))
316
+ this.removeSync(this.pathUtils.resolve(p, entry));
317
+ this.rmdirSync(p);
318
+ } else {
319
+ this.unlinkSync(p);
320
+ }
321
+ }
322
+ async mkdirpPromise(p, { chmod, utimes } = {}) {
323
+ p = this.resolve(p);
324
+ if (p === this.pathUtils.dirname(p))
325
+ return void 0;
326
+ const parts = p.split(this.pathUtils.sep);
327
+ let createdDirectory;
328
+ for (let u = 2; u <= parts.length; ++u) {
329
+ const subPath = parts.slice(0, u).join(this.pathUtils.sep);
330
+ if (!this.existsSync(subPath)) {
331
+ try {
332
+ await this.mkdirPromise(subPath);
333
+ } catch (error) {
334
+ if (error.code === `EEXIST`) {
335
+ continue;
336
+ } else {
337
+ throw error;
338
+ }
339
+ }
340
+ createdDirectory != null ? createdDirectory : createdDirectory = subPath;
341
+ if (chmod != null)
342
+ await this.chmodPromise(subPath, chmod);
343
+ if (utimes != null) {
344
+ await this.utimesPromise(subPath, utimes[0], utimes[1]);
345
+ } else {
346
+ const parentStat = await this.statPromise(this.pathUtils.dirname(subPath));
347
+ await this.utimesPromise(subPath, parentStat.atime, parentStat.mtime);
348
+ }
349
+ }
350
+ }
351
+ return createdDirectory;
352
+ }
353
+ mkdirpSync(p, { chmod, utimes } = {}) {
354
+ p = this.resolve(p);
355
+ if (p === this.pathUtils.dirname(p))
356
+ return void 0;
357
+ const parts = p.split(this.pathUtils.sep);
358
+ let createdDirectory;
359
+ for (let u = 2; u <= parts.length; ++u) {
360
+ const subPath = parts.slice(0, u).join(this.pathUtils.sep);
361
+ if (!this.existsSync(subPath)) {
362
+ try {
363
+ this.mkdirSync(subPath);
364
+ } catch (error) {
365
+ if (error.code === `EEXIST`) {
366
+ continue;
367
+ } else {
368
+ throw error;
369
+ }
370
+ }
371
+ createdDirectory != null ? createdDirectory : createdDirectory = subPath;
372
+ if (chmod != null)
373
+ this.chmodSync(subPath, chmod);
374
+ if (utimes != null) {
375
+ this.utimesSync(subPath, utimes[0], utimes[1]);
376
+ } else {
377
+ const parentStat = this.statSync(this.pathUtils.dirname(subPath));
378
+ this.utimesSync(subPath, parentStat.atime, parentStat.mtime);
379
+ }
380
+ }
381
+ }
382
+ return createdDirectory;
383
+ }
384
+ async copyPromise(destination, source, { baseFs = this, overwrite = true, stableSort = false, stableTime = false, linkStrategy = null } = {}) {
385
+ return await copyPromise(this, destination, baseFs, source, { overwrite, stableSort, stableTime, linkStrategy });
386
+ }
387
+ copySync(destination, source, { baseFs = this, overwrite = true } = {}) {
388
+ const stat = baseFs.lstatSync(source);
389
+ const exists = this.existsSync(destination);
390
+ if (stat.isDirectory()) {
391
+ this.mkdirpSync(destination);
392
+ const directoryListing = baseFs.readdirSync(source);
393
+ for (const entry of directoryListing) {
394
+ this.copySync(this.pathUtils.join(destination, entry), baseFs.pathUtils.join(source, entry), { baseFs, overwrite });
395
+ }
396
+ } else if (stat.isFile()) {
397
+ if (!exists || overwrite) {
398
+ if (exists)
399
+ this.removeSync(destination);
400
+ const content = baseFs.readFileSync(source);
401
+ this.writeFileSync(destination, content);
402
+ }
403
+ } else if (stat.isSymbolicLink()) {
404
+ if (!exists || overwrite) {
405
+ if (exists)
406
+ this.removeSync(destination);
407
+ const target = baseFs.readlinkSync(source);
408
+ this.symlinkSync(convertPath(this.pathUtils, target), destination);
409
+ }
410
+ } else {
411
+ throw new Error(`Unsupported file type (file: ${source}, mode: 0o${stat.mode.toString(8).padStart(6, `0`)})`);
412
+ }
413
+ const mode = stat.mode & 511;
414
+ this.chmodSync(destination, mode);
415
+ }
416
+ async changeFilePromise(p, content, opts = {}) {
417
+ if (Buffer.isBuffer(content)) {
418
+ return this.changeFileBufferPromise(p, content, opts);
419
+ } else {
420
+ return this.changeFileTextPromise(p, content, opts);
421
+ }
422
+ }
423
+ async changeFileBufferPromise(p, content, { mode } = {}) {
424
+ let current = Buffer.alloc(0);
425
+ try {
426
+ current = await this.readFilePromise(p);
427
+ } catch (error) {
428
+ }
429
+ if (Buffer.compare(current, content) === 0)
430
+ return;
431
+ await this.writeFilePromise(p, content, { mode });
432
+ }
433
+ async changeFileTextPromise(p, content, { automaticNewlines, mode } = {}) {
434
+ let current = ``;
435
+ try {
436
+ current = await this.readFilePromise(p, `utf8`);
437
+ } catch (error) {
438
+ }
439
+ const normalizedContent = automaticNewlines ? normalizeLineEndings(current, content) : content;
440
+ if (current === normalizedContent)
441
+ return;
442
+ await this.writeFilePromise(p, normalizedContent, { mode });
443
+ }
444
+ changeFileSync(p, content, opts = {}) {
445
+ if (Buffer.isBuffer(content)) {
446
+ return this.changeFileBufferSync(p, content, opts);
447
+ } else {
448
+ return this.changeFileTextSync(p, content, opts);
449
+ }
450
+ }
451
+ changeFileBufferSync(p, content, { mode } = {}) {
452
+ let current = Buffer.alloc(0);
453
+ try {
454
+ current = this.readFileSync(p);
455
+ } catch (error) {
456
+ }
457
+ if (Buffer.compare(current, content) === 0)
458
+ return;
459
+ this.writeFileSync(p, content, { mode });
460
+ }
461
+ changeFileTextSync(p, content, { automaticNewlines = false, mode } = {}) {
462
+ let current = ``;
463
+ try {
464
+ current = this.readFileSync(p, `utf8`);
465
+ } catch (error) {
466
+ }
467
+ const normalizedContent = automaticNewlines ? normalizeLineEndings(current, content) : content;
468
+ if (current === normalizedContent)
469
+ return;
470
+ this.writeFileSync(p, normalizedContent, { mode });
471
+ }
472
+ async movePromise(fromP, toP) {
473
+ try {
474
+ await this.renamePromise(fromP, toP);
475
+ } catch (error) {
476
+ if (error.code === `EXDEV`) {
477
+ await this.copyPromise(toP, fromP);
478
+ await this.removePromise(fromP);
479
+ } else {
480
+ throw error;
481
+ }
482
+ }
483
+ }
484
+ moveSync(fromP, toP) {
485
+ try {
486
+ this.renameSync(fromP, toP);
487
+ } catch (error) {
488
+ if (error.code === `EXDEV`) {
489
+ this.copySync(toP, fromP);
490
+ this.removeSync(fromP);
491
+ } else {
492
+ throw error;
493
+ }
494
+ }
495
+ }
496
+ async lockPromise(affectedPath, callback) {
497
+ const lockPath = `${affectedPath}.flock`;
498
+ const interval = 1e3 / 60;
499
+ const startTime = Date.now();
500
+ let fd = null;
501
+ const isAlive = async () => {
502
+ let pid;
503
+ try {
504
+ [pid] = await this.readJsonPromise(lockPath);
505
+ } catch (error) {
506
+ return Date.now() - startTime < 500;
507
+ }
508
+ try {
509
+ process.kill(pid, 0);
510
+ return true;
511
+ } catch (error) {
512
+ return false;
513
+ }
514
+ };
515
+ while (fd === null) {
516
+ try {
517
+ fd = await this.openPromise(lockPath, `wx`);
518
+ } catch (error) {
519
+ if (error.code === `EEXIST`) {
520
+ if (!await isAlive()) {
521
+ try {
522
+ await this.unlinkPromise(lockPath);
523
+ continue;
524
+ } catch (error2) {
525
+ }
526
+ }
527
+ if (Date.now() - startTime < 60 * 1e3) {
528
+ await new Promise((resolve) => setTimeout(resolve, interval));
529
+ } else {
530
+ throw new Error(`Couldn't acquire a lock in a reasonable time (via ${lockPath})`);
531
+ }
532
+ } else {
533
+ throw error;
534
+ }
535
+ }
536
+ }
537
+ await this.writePromise(fd, JSON.stringify([process.pid]));
538
+ try {
539
+ return await callback();
540
+ } finally {
541
+ try {
542
+ await this.closePromise(fd);
543
+ await this.unlinkPromise(lockPath);
544
+ } catch (error) {
545
+ }
546
+ }
547
+ }
548
+ async readJsonPromise(p) {
549
+ const content = await this.readFilePromise(p, `utf8`);
550
+ try {
551
+ return JSON.parse(content);
552
+ } catch (error) {
553
+ error.message += ` (in ${p})`;
554
+ throw error;
555
+ }
556
+ }
557
+ readJsonSync(p) {
558
+ const content = this.readFileSync(p, `utf8`);
559
+ try {
560
+ return JSON.parse(content);
561
+ } catch (error) {
562
+ error.message += ` (in ${p})`;
563
+ throw error;
564
+ }
565
+ }
566
+ async writeJsonPromise(p, data) {
567
+ return await this.writeFilePromise(p, `${JSON.stringify(data, null, 2)}
568
+ `);
569
+ }
570
+ writeJsonSync(p, data) {
571
+ return this.writeFileSync(p, `${JSON.stringify(data, null, 2)}
572
+ `);
573
+ }
574
+ async preserveTimePromise(p, cb) {
575
+ const stat = await this.lstatPromise(p);
576
+ const result = await cb();
577
+ if (typeof result !== `undefined`)
578
+ p = result;
579
+ if (this.lutimesPromise) {
580
+ await this.lutimesPromise(p, stat.atime, stat.mtime);
581
+ } else if (!stat.isSymbolicLink()) {
582
+ await this.utimesPromise(p, stat.atime, stat.mtime);
583
+ }
584
+ }
585
+ async preserveTimeSync(p, cb) {
586
+ const stat = this.lstatSync(p);
587
+ const result = cb();
588
+ if (typeof result !== `undefined`)
589
+ p = result;
590
+ if (this.lutimesSync) {
591
+ this.lutimesSync(p, stat.atime, stat.mtime);
592
+ } else if (!stat.isSymbolicLink()) {
593
+ this.utimesSync(p, stat.atime, stat.mtime);
594
+ }
595
+ }
596
+ }
597
+ class BasePortableFakeFS extends FakeFS {
598
+ constructor() {
599
+ super(ppath);
600
+ }
601
+ }
602
+ function getEndOfLine(content) {
603
+ const matches = content.match(/\r?\n/g);
604
+ if (matches === null)
605
+ return EOL;
606
+ const crlf = matches.filter((nl) => nl === `\r
607
+ `).length;
608
+ const lf = matches.length - crlf;
609
+ return crlf > lf ? `\r
610
+ ` : `
611
+ `;
612
+ }
613
+ function normalizeLineEndings(originalContent, newContent) {
614
+ return newContent.replace(/\r?\n/g, getEndOfLine(originalContent));
615
+ }
616
+
617
+ class NodeFS extends BasePortableFakeFS {
618
+ constructor(realFs = fs) {
619
+ super();
620
+ this.realFs = realFs;
621
+ if (typeof this.realFs.lutimes !== `undefined`) {
622
+ this.lutimesPromise = this.lutimesPromiseImpl;
623
+ this.lutimesSync = this.lutimesSyncImpl;
624
+ }
625
+ }
626
+ getExtractHint() {
627
+ return false;
628
+ }
629
+ getRealPath() {
630
+ return PortablePath.root;
631
+ }
632
+ resolve(p) {
633
+ return ppath.resolve(p);
634
+ }
635
+ async openPromise(p, flags, mode) {
636
+ return await new Promise((resolve, reject) => {
637
+ this.realFs.open(npath.fromPortablePath(p), flags, mode, this.makeCallback(resolve, reject));
638
+ });
639
+ }
640
+ openSync(p, flags, mode) {
641
+ return this.realFs.openSync(npath.fromPortablePath(p), flags, mode);
642
+ }
643
+ async opendirPromise(p, opts) {
644
+ return await new Promise((resolve, reject) => {
645
+ if (typeof opts !== `undefined`) {
646
+ this.realFs.opendir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
647
+ } else {
648
+ this.realFs.opendir(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
649
+ }
650
+ }).then((dir) => {
651
+ return Object.defineProperty(dir, `path`, { value: p, configurable: true, writable: true });
652
+ });
653
+ }
654
+ opendirSync(p, opts) {
655
+ const dir = typeof opts !== `undefined` ? this.realFs.opendirSync(npath.fromPortablePath(p), opts) : this.realFs.opendirSync(npath.fromPortablePath(p));
656
+ return Object.defineProperty(dir, `path`, { value: p, configurable: true, writable: true });
657
+ }
658
+ async readPromise(fd, buffer, offset = 0, length = 0, position = -1) {
659
+ return await new Promise((resolve, reject) => {
660
+ this.realFs.read(fd, buffer, offset, length, position, (error, bytesRead) => {
661
+ if (error) {
662
+ reject(error);
663
+ } else {
664
+ resolve(bytesRead);
665
+ }
666
+ });
667
+ });
668
+ }
669
+ readSync(fd, buffer, offset, length, position) {
670
+ return this.realFs.readSync(fd, buffer, offset, length, position);
671
+ }
672
+ async writePromise(fd, buffer, offset, length, position) {
673
+ return await new Promise((resolve, reject) => {
674
+ if (typeof buffer === `string`) {
675
+ return this.realFs.write(fd, buffer, offset, this.makeCallback(resolve, reject));
676
+ } else {
677
+ return this.realFs.write(fd, buffer, offset, length, position, this.makeCallback(resolve, reject));
678
+ }
679
+ });
680
+ }
681
+ writeSync(fd, buffer, offset, length, position) {
682
+ if (typeof buffer === `string`) {
683
+ return this.realFs.writeSync(fd, buffer, offset);
684
+ } else {
685
+ return this.realFs.writeSync(fd, buffer, offset, length, position);
686
+ }
687
+ }
688
+ async closePromise(fd) {
689
+ await new Promise((resolve, reject) => {
690
+ this.realFs.close(fd, this.makeCallback(resolve, reject));
691
+ });
692
+ }
693
+ closeSync(fd) {
694
+ this.realFs.closeSync(fd);
695
+ }
696
+ createReadStream(p, opts) {
697
+ const realPath = p !== null ? npath.fromPortablePath(p) : p;
698
+ return this.realFs.createReadStream(realPath, opts);
699
+ }
700
+ createWriteStream(p, opts) {
701
+ const realPath = p !== null ? npath.fromPortablePath(p) : p;
702
+ return this.realFs.createWriteStream(realPath, opts);
703
+ }
704
+ async realpathPromise(p) {
705
+ return await new Promise((resolve, reject) => {
706
+ this.realFs.realpath(npath.fromPortablePath(p), {}, this.makeCallback(resolve, reject));
707
+ }).then((path) => {
708
+ return npath.toPortablePath(path);
709
+ });
710
+ }
711
+ realpathSync(p) {
712
+ return npath.toPortablePath(this.realFs.realpathSync(npath.fromPortablePath(p), {}));
713
+ }
714
+ async existsPromise(p) {
715
+ return await new Promise((resolve) => {
716
+ this.realFs.exists(npath.fromPortablePath(p), resolve);
717
+ });
718
+ }
719
+ accessSync(p, mode) {
720
+ return this.realFs.accessSync(npath.fromPortablePath(p), mode);
721
+ }
722
+ async accessPromise(p, mode) {
723
+ return await new Promise((resolve, reject) => {
724
+ this.realFs.access(npath.fromPortablePath(p), mode, this.makeCallback(resolve, reject));
725
+ });
726
+ }
727
+ existsSync(p) {
728
+ return this.realFs.existsSync(npath.fromPortablePath(p));
729
+ }
730
+ async statPromise(p, opts) {
731
+ return await new Promise((resolve, reject) => {
732
+ if (opts) {
733
+ this.realFs.stat(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
734
+ } else {
735
+ this.realFs.stat(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
736
+ }
737
+ });
738
+ }
739
+ statSync(p, opts) {
740
+ if (opts) {
741
+ return this.realFs.statSync(npath.fromPortablePath(p), opts);
742
+ } else {
743
+ return this.realFs.statSync(npath.fromPortablePath(p));
744
+ }
745
+ }
746
+ async fstatPromise(fd, opts) {
747
+ return await new Promise((resolve, reject) => {
748
+ if (opts) {
749
+ this.realFs.fstat(fd, opts, this.makeCallback(resolve, reject));
750
+ } else {
751
+ this.realFs.fstat(fd, this.makeCallback(resolve, reject));
752
+ }
753
+ });
754
+ }
755
+ fstatSync(fd, opts) {
756
+ if (opts) {
757
+ return this.realFs.fstatSync(fd, opts);
758
+ } else {
759
+ return this.realFs.fstatSync(fd);
760
+ }
761
+ }
762
+ async lstatPromise(p, opts) {
763
+ return await new Promise((resolve, reject) => {
764
+ if (opts) {
765
+ this.realFs.lstat(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
766
+ } else {
767
+ this.realFs.lstat(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
768
+ }
769
+ });
770
+ }
771
+ lstatSync(p, opts) {
772
+ if (opts) {
773
+ return this.realFs.lstatSync(npath.fromPortablePath(p), opts);
774
+ } else {
775
+ return this.realFs.lstatSync(npath.fromPortablePath(p));
776
+ }
777
+ }
778
+ async fchmodPromise(fd, mask) {
779
+ return await new Promise((resolve, reject) => {
780
+ this.realFs.fchmod(fd, mask, this.makeCallback(resolve, reject));
781
+ });
782
+ }
783
+ fchmodSync(fd, mask) {
784
+ return this.realFs.fchmodSync(fd, mask);
785
+ }
786
+ async chmodPromise(p, mask) {
787
+ return await new Promise((resolve, reject) => {
788
+ this.realFs.chmod(npath.fromPortablePath(p), mask, this.makeCallback(resolve, reject));
789
+ });
790
+ }
791
+ chmodSync(p, mask) {
792
+ return this.realFs.chmodSync(npath.fromPortablePath(p), mask);
793
+ }
794
+ async fchownPromise(fd, uid, gid) {
795
+ return await new Promise((resolve, reject) => {
796
+ this.realFs.fchown(fd, uid, gid, this.makeCallback(resolve, reject));
797
+ });
798
+ }
799
+ fchownSync(fd, uid, gid) {
800
+ return this.realFs.fchownSync(fd, uid, gid);
801
+ }
802
+ async chownPromise(p, uid, gid) {
803
+ return await new Promise((resolve, reject) => {
804
+ this.realFs.chown(npath.fromPortablePath(p), uid, gid, this.makeCallback(resolve, reject));
805
+ });
806
+ }
807
+ chownSync(p, uid, gid) {
808
+ return this.realFs.chownSync(npath.fromPortablePath(p), uid, gid);
809
+ }
810
+ async renamePromise(oldP, newP) {
811
+ return await new Promise((resolve, reject) => {
812
+ this.realFs.rename(npath.fromPortablePath(oldP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject));
813
+ });
814
+ }
815
+ renameSync(oldP, newP) {
816
+ return this.realFs.renameSync(npath.fromPortablePath(oldP), npath.fromPortablePath(newP));
817
+ }
818
+ async copyFilePromise(sourceP, destP, flags = 0) {
819
+ return await new Promise((resolve, reject) => {
820
+ this.realFs.copyFile(npath.fromPortablePath(sourceP), npath.fromPortablePath(destP), flags, this.makeCallback(resolve, reject));
821
+ });
822
+ }
823
+ copyFileSync(sourceP, destP, flags = 0) {
824
+ return this.realFs.copyFileSync(npath.fromPortablePath(sourceP), npath.fromPortablePath(destP), flags);
825
+ }
826
+ async appendFilePromise(p, content, opts) {
827
+ return await new Promise((resolve, reject) => {
828
+ const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
829
+ if (opts) {
830
+ this.realFs.appendFile(fsNativePath, content, opts, this.makeCallback(resolve, reject));
831
+ } else {
832
+ this.realFs.appendFile(fsNativePath, content, this.makeCallback(resolve, reject));
833
+ }
834
+ });
835
+ }
836
+ appendFileSync(p, content, opts) {
837
+ const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
838
+ if (opts) {
839
+ this.realFs.appendFileSync(fsNativePath, content, opts);
840
+ } else {
841
+ this.realFs.appendFileSync(fsNativePath, content);
842
+ }
843
+ }
844
+ async writeFilePromise(p, content, opts) {
845
+ return await new Promise((resolve, reject) => {
846
+ const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
847
+ if (opts) {
848
+ this.realFs.writeFile(fsNativePath, content, opts, this.makeCallback(resolve, reject));
849
+ } else {
850
+ this.realFs.writeFile(fsNativePath, content, this.makeCallback(resolve, reject));
851
+ }
852
+ });
853
+ }
854
+ writeFileSync(p, content, opts) {
855
+ const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
856
+ if (opts) {
857
+ this.realFs.writeFileSync(fsNativePath, content, opts);
858
+ } else {
859
+ this.realFs.writeFileSync(fsNativePath, content);
860
+ }
861
+ }
862
+ async unlinkPromise(p) {
863
+ return await new Promise((resolve, reject) => {
864
+ this.realFs.unlink(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
865
+ });
866
+ }
867
+ unlinkSync(p) {
868
+ return this.realFs.unlinkSync(npath.fromPortablePath(p));
869
+ }
870
+ async utimesPromise(p, atime, mtime) {
871
+ return await new Promise((resolve, reject) => {
872
+ this.realFs.utimes(npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject));
873
+ });
874
+ }
875
+ utimesSync(p, atime, mtime) {
876
+ this.realFs.utimesSync(npath.fromPortablePath(p), atime, mtime);
877
+ }
878
+ async lutimesPromiseImpl(p, atime, mtime) {
879
+ const lutimes = this.realFs.lutimes;
880
+ if (typeof lutimes === `undefined`)
881
+ throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`);
882
+ return await new Promise((resolve, reject) => {
883
+ lutimes.call(this.realFs, npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject));
884
+ });
885
+ }
886
+ lutimesSyncImpl(p, atime, mtime) {
887
+ const lutimesSync = this.realFs.lutimesSync;
888
+ if (typeof lutimesSync === `undefined`)
889
+ throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`);
890
+ lutimesSync.call(this.realFs, npath.fromPortablePath(p), atime, mtime);
891
+ }
892
+ async mkdirPromise(p, opts) {
893
+ return await new Promise((resolve, reject) => {
894
+ this.realFs.mkdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
895
+ });
896
+ }
897
+ mkdirSync(p, opts) {
898
+ return this.realFs.mkdirSync(npath.fromPortablePath(p), opts);
899
+ }
900
+ async rmdirPromise(p, opts) {
901
+ return await new Promise((resolve, reject) => {
902
+ if (opts) {
903
+ this.realFs.rmdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
904
+ } else {
905
+ this.realFs.rmdir(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
906
+ }
907
+ });
908
+ }
909
+ rmdirSync(p, opts) {
910
+ return this.realFs.rmdirSync(npath.fromPortablePath(p), opts);
911
+ }
912
+ async linkPromise(existingP, newP) {
913
+ return await new Promise((resolve, reject) => {
914
+ this.realFs.link(npath.fromPortablePath(existingP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject));
915
+ });
916
+ }
917
+ linkSync(existingP, newP) {
918
+ return this.realFs.linkSync(npath.fromPortablePath(existingP), npath.fromPortablePath(newP));
919
+ }
920
+ async symlinkPromise(target, p, type) {
921
+ return await new Promise((resolve, reject) => {
922
+ this.realFs.symlink(npath.fromPortablePath(target.replace(/\/+$/, ``)), npath.fromPortablePath(p), type, this.makeCallback(resolve, reject));
923
+ });
924
+ }
925
+ symlinkSync(target, p, type) {
926
+ return this.realFs.symlinkSync(npath.fromPortablePath(target.replace(/\/+$/, ``)), npath.fromPortablePath(p), type);
927
+ }
928
+ async readFilePromise(p, encoding) {
929
+ return await new Promise((resolve, reject) => {
930
+ const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
931
+ this.realFs.readFile(fsNativePath, encoding, this.makeCallback(resolve, reject));
932
+ });
933
+ }
934
+ readFileSync(p, encoding) {
935
+ const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
936
+ return this.realFs.readFileSync(fsNativePath, encoding);
937
+ }
938
+ async readdirPromise(p, opts) {
939
+ return await new Promise((resolve, reject) => {
940
+ if (opts == null ? void 0 : opts.withFileTypes) {
941
+ this.realFs.readdir(npath.fromPortablePath(p), { withFileTypes: true }, this.makeCallback(resolve, reject));
942
+ } else {
943
+ this.realFs.readdir(npath.fromPortablePath(p), this.makeCallback((value) => resolve(value), reject));
944
+ }
945
+ });
946
+ }
947
+ readdirSync(p, opts) {
948
+ if (opts == null ? void 0 : opts.withFileTypes) {
949
+ return this.realFs.readdirSync(npath.fromPortablePath(p), { withFileTypes: true });
950
+ } else {
951
+ return this.realFs.readdirSync(npath.fromPortablePath(p));
952
+ }
953
+ }
954
+ async readlinkPromise(p) {
955
+ return await new Promise((resolve, reject) => {
956
+ this.realFs.readlink(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
957
+ }).then((path) => {
958
+ return npath.toPortablePath(path);
959
+ });
960
+ }
961
+ readlinkSync(p) {
962
+ return npath.toPortablePath(this.realFs.readlinkSync(npath.fromPortablePath(p)));
963
+ }
964
+ async truncatePromise(p, len) {
965
+ return await new Promise((resolve, reject) => {
966
+ this.realFs.truncate(npath.fromPortablePath(p), len, this.makeCallback(resolve, reject));
967
+ });
968
+ }
969
+ truncateSync(p, len) {
970
+ return this.realFs.truncateSync(npath.fromPortablePath(p), len);
971
+ }
972
+ async ftruncatePromise(fd, len) {
973
+ return await new Promise((resolve, reject) => {
974
+ this.realFs.ftruncate(fd, len, this.makeCallback(resolve, reject));
975
+ });
976
+ }
977
+ ftruncateSync(fd, len) {
978
+ return this.realFs.ftruncateSync(fd, len);
979
+ }
980
+ watch(p, a, b) {
981
+ return this.realFs.watch(
982
+ npath.fromPortablePath(p),
983
+ a,
984
+ b
985
+ );
986
+ }
987
+ watchFile(p, a, b) {
988
+ return this.realFs.watchFile(
989
+ npath.fromPortablePath(p),
990
+ a,
991
+ b
992
+ );
993
+ }
994
+ unwatchFile(p, cb) {
995
+ return this.realFs.unwatchFile(npath.fromPortablePath(p), cb);
996
+ }
997
+ makeCallback(resolve, reject) {
998
+ return (err, result) => {
999
+ if (err) {
1000
+ reject(err);
1001
+ } else {
1002
+ resolve(result);
1003
+ }
1004
+ };
1005
+ }
1006
+ }
1007
+
1008
+ class ProxiedFS extends FakeFS {
1009
+ getExtractHint(hints) {
1010
+ return this.baseFs.getExtractHint(hints);
1011
+ }
1012
+ resolve(path) {
1013
+ return this.mapFromBase(this.baseFs.resolve(this.mapToBase(path)));
1014
+ }
1015
+ getRealPath() {
1016
+ return this.mapFromBase(this.baseFs.getRealPath());
1017
+ }
1018
+ async openPromise(p, flags, mode) {
1019
+ return this.baseFs.openPromise(this.mapToBase(p), flags, mode);
1020
+ }
1021
+ openSync(p, flags, mode) {
1022
+ return this.baseFs.openSync(this.mapToBase(p), flags, mode);
1023
+ }
1024
+ async opendirPromise(p, opts) {
1025
+ return Object.assign(await this.baseFs.opendirPromise(this.mapToBase(p), opts), { path: p });
1026
+ }
1027
+ opendirSync(p, opts) {
1028
+ return Object.assign(this.baseFs.opendirSync(this.mapToBase(p), opts), { path: p });
1029
+ }
1030
+ async readPromise(fd, buffer, offset, length, position) {
1031
+ return await this.baseFs.readPromise(fd, buffer, offset, length, position);
1032
+ }
1033
+ readSync(fd, buffer, offset, length, position) {
1034
+ return this.baseFs.readSync(fd, buffer, offset, length, position);
1035
+ }
1036
+ async writePromise(fd, buffer, offset, length, position) {
1037
+ if (typeof buffer === `string`) {
1038
+ return await this.baseFs.writePromise(fd, buffer, offset);
1039
+ } else {
1040
+ return await this.baseFs.writePromise(fd, buffer, offset, length, position);
1041
+ }
1042
+ }
1043
+ writeSync(fd, buffer, offset, length, position) {
1044
+ if (typeof buffer === `string`) {
1045
+ return this.baseFs.writeSync(fd, buffer, offset);
1046
+ } else {
1047
+ return this.baseFs.writeSync(fd, buffer, offset, length, position);
1048
+ }
1049
+ }
1050
+ async closePromise(fd) {
1051
+ return this.baseFs.closePromise(fd);
1052
+ }
1053
+ closeSync(fd) {
1054
+ this.baseFs.closeSync(fd);
1055
+ }
1056
+ createReadStream(p, opts) {
1057
+ return this.baseFs.createReadStream(p !== null ? this.mapToBase(p) : p, opts);
1058
+ }
1059
+ createWriteStream(p, opts) {
1060
+ return this.baseFs.createWriteStream(p !== null ? this.mapToBase(p) : p, opts);
1061
+ }
1062
+ async realpathPromise(p) {
1063
+ return this.mapFromBase(await this.baseFs.realpathPromise(this.mapToBase(p)));
1064
+ }
1065
+ realpathSync(p) {
1066
+ return this.mapFromBase(this.baseFs.realpathSync(this.mapToBase(p)));
1067
+ }
1068
+ async existsPromise(p) {
1069
+ return this.baseFs.existsPromise(this.mapToBase(p));
1070
+ }
1071
+ existsSync(p) {
1072
+ return this.baseFs.existsSync(this.mapToBase(p));
1073
+ }
1074
+ accessSync(p, mode) {
1075
+ return this.baseFs.accessSync(this.mapToBase(p), mode);
1076
+ }
1077
+ async accessPromise(p, mode) {
1078
+ return this.baseFs.accessPromise(this.mapToBase(p), mode);
1079
+ }
1080
+ async statPromise(p, opts) {
1081
+ return this.baseFs.statPromise(this.mapToBase(p), opts);
1082
+ }
1083
+ statSync(p, opts) {
1084
+ return this.baseFs.statSync(this.mapToBase(p), opts);
1085
+ }
1086
+ async fstatPromise(fd, opts) {
1087
+ return this.baseFs.fstatPromise(fd, opts);
1088
+ }
1089
+ fstatSync(fd, opts) {
1090
+ return this.baseFs.fstatSync(fd, opts);
1091
+ }
1092
+ lstatPromise(p, opts) {
1093
+ return this.baseFs.lstatPromise(this.mapToBase(p), opts);
1094
+ }
1095
+ lstatSync(p, opts) {
1096
+ return this.baseFs.lstatSync(this.mapToBase(p), opts);
1097
+ }
1098
+ async fchmodPromise(fd, mask) {
1099
+ return this.baseFs.fchmodPromise(fd, mask);
1100
+ }
1101
+ fchmodSync(fd, mask) {
1102
+ return this.baseFs.fchmodSync(fd, mask);
1103
+ }
1104
+ async chmodPromise(p, mask) {
1105
+ return this.baseFs.chmodPromise(this.mapToBase(p), mask);
1106
+ }
1107
+ chmodSync(p, mask) {
1108
+ return this.baseFs.chmodSync(this.mapToBase(p), mask);
1109
+ }
1110
+ async fchownPromise(fd, uid, gid) {
1111
+ return this.baseFs.fchownPromise(fd, uid, gid);
1112
+ }
1113
+ fchownSync(fd, uid, gid) {
1114
+ return this.baseFs.fchownSync(fd, uid, gid);
1115
+ }
1116
+ async chownPromise(p, uid, gid) {
1117
+ return this.baseFs.chownPromise(this.mapToBase(p), uid, gid);
1118
+ }
1119
+ chownSync(p, uid, gid) {
1120
+ return this.baseFs.chownSync(this.mapToBase(p), uid, gid);
1121
+ }
1122
+ async renamePromise(oldP, newP) {
1123
+ return this.baseFs.renamePromise(this.mapToBase(oldP), this.mapToBase(newP));
1124
+ }
1125
+ renameSync(oldP, newP) {
1126
+ return this.baseFs.renameSync(this.mapToBase(oldP), this.mapToBase(newP));
1127
+ }
1128
+ async copyFilePromise(sourceP, destP, flags = 0) {
1129
+ return this.baseFs.copyFilePromise(this.mapToBase(sourceP), this.mapToBase(destP), flags);
1130
+ }
1131
+ copyFileSync(sourceP, destP, flags = 0) {
1132
+ return this.baseFs.copyFileSync(this.mapToBase(sourceP), this.mapToBase(destP), flags);
1133
+ }
1134
+ async appendFilePromise(p, content, opts) {
1135
+ return this.baseFs.appendFilePromise(this.fsMapToBase(p), content, opts);
1136
+ }
1137
+ appendFileSync(p, content, opts) {
1138
+ return this.baseFs.appendFileSync(this.fsMapToBase(p), content, opts);
1139
+ }
1140
+ async writeFilePromise(p, content, opts) {
1141
+ return this.baseFs.writeFilePromise(this.fsMapToBase(p), content, opts);
1142
+ }
1143
+ writeFileSync(p, content, opts) {
1144
+ return this.baseFs.writeFileSync(this.fsMapToBase(p), content, opts);
1145
+ }
1146
+ async unlinkPromise(p) {
1147
+ return this.baseFs.unlinkPromise(this.mapToBase(p));
1148
+ }
1149
+ unlinkSync(p) {
1150
+ return this.baseFs.unlinkSync(this.mapToBase(p));
1151
+ }
1152
+ async utimesPromise(p, atime, mtime) {
1153
+ return this.baseFs.utimesPromise(this.mapToBase(p), atime, mtime);
1154
+ }
1155
+ utimesSync(p, atime, mtime) {
1156
+ return this.baseFs.utimesSync(this.mapToBase(p), atime, mtime);
1157
+ }
1158
+ async mkdirPromise(p, opts) {
1159
+ return this.baseFs.mkdirPromise(this.mapToBase(p), opts);
1160
+ }
1161
+ mkdirSync(p, opts) {
1162
+ return this.baseFs.mkdirSync(this.mapToBase(p), opts);
1163
+ }
1164
+ async rmdirPromise(p, opts) {
1165
+ return this.baseFs.rmdirPromise(this.mapToBase(p), opts);
1166
+ }
1167
+ rmdirSync(p, opts) {
1168
+ return this.baseFs.rmdirSync(this.mapToBase(p), opts);
1169
+ }
1170
+ async linkPromise(existingP, newP) {
1171
+ return this.baseFs.linkPromise(this.mapToBase(existingP), this.mapToBase(newP));
1172
+ }
1173
+ linkSync(existingP, newP) {
1174
+ return this.baseFs.linkSync(this.mapToBase(existingP), this.mapToBase(newP));
1175
+ }
1176
+ async symlinkPromise(target, p, type) {
1177
+ const mappedP = this.mapToBase(p);
1178
+ if (this.pathUtils.isAbsolute(target))
1179
+ return this.baseFs.symlinkPromise(this.mapToBase(target), mappedP, type);
1180
+ const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target));
1181
+ const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget);
1182
+ return this.baseFs.symlinkPromise(mappedTarget, mappedP, type);
1183
+ }
1184
+ symlinkSync(target, p, type) {
1185
+ const mappedP = this.mapToBase(p);
1186
+ if (this.pathUtils.isAbsolute(target))
1187
+ return this.baseFs.symlinkSync(this.mapToBase(target), mappedP, type);
1188
+ const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target));
1189
+ const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget);
1190
+ return this.baseFs.symlinkSync(mappedTarget, mappedP, type);
1191
+ }
1192
+ async readFilePromise(p, encoding) {
1193
+ if (encoding === `utf8`) {
1194
+ return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
1195
+ } else {
1196
+ return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
1197
+ }
1198
+ }
1199
+ readFileSync(p, encoding) {
1200
+ if (encoding === `utf8`) {
1201
+ return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
1202
+ } else {
1203
+ return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
1204
+ }
1205
+ }
1206
+ async readdirPromise(p, opts) {
1207
+ return this.baseFs.readdirPromise(this.mapToBase(p), opts);
1208
+ }
1209
+ readdirSync(p, opts) {
1210
+ return this.baseFs.readdirSync(this.mapToBase(p), opts);
1211
+ }
1212
+ async readlinkPromise(p) {
1213
+ return this.mapFromBase(await this.baseFs.readlinkPromise(this.mapToBase(p)));
1214
+ }
1215
+ readlinkSync(p) {
1216
+ return this.mapFromBase(this.baseFs.readlinkSync(this.mapToBase(p)));
1217
+ }
1218
+ async truncatePromise(p, len) {
1219
+ return this.baseFs.truncatePromise(this.mapToBase(p), len);
1220
+ }
1221
+ truncateSync(p, len) {
1222
+ return this.baseFs.truncateSync(this.mapToBase(p), len);
1223
+ }
1224
+ async ftruncatePromise(fd, len) {
1225
+ return this.baseFs.ftruncatePromise(fd, len);
1226
+ }
1227
+ ftruncateSync(fd, len) {
1228
+ return this.baseFs.ftruncateSync(fd, len);
1229
+ }
1230
+ watch(p, a, b) {
1231
+ return this.baseFs.watch(
1232
+ this.mapToBase(p),
1233
+ a,
1234
+ b
1235
+ );
1236
+ }
1237
+ watchFile(p, a, b) {
1238
+ return this.baseFs.watchFile(
1239
+ this.mapToBase(p),
1240
+ a,
1241
+ b
1242
+ );
1243
+ }
1244
+ unwatchFile(p, cb) {
1245
+ return this.baseFs.unwatchFile(this.mapToBase(p), cb);
1246
+ }
1247
+ fsMapToBase(p) {
1248
+ if (typeof p === `number`) {
1249
+ return p;
1250
+ } else {
1251
+ return this.mapToBase(p);
1252
+ }
1253
+ }
1254
+ }
1255
+
1256
+ const NUMBER_REGEXP = /^[0-9]+$/;
1257
+ const VIRTUAL_REGEXP = /^(\/(?:[^/]+\/)*?(?:\$\$virtual|__virtual__))((?:\/((?:[^/]+-)?[a-f0-9]+)(?:\/([^/]+))?)?((?:\/.*)?))$/;
1258
+ const VALID_COMPONENT = /^([^/]+-)?[a-f0-9]+$/;
1259
+ class VirtualFS extends ProxiedFS {
1260
+ constructor({ baseFs = new NodeFS() } = {}) {
1261
+ super(ppath);
1262
+ this.baseFs = baseFs;
1263
+ }
1264
+ static makeVirtualPath(base, component, to) {
1265
+ if (ppath.basename(base) !== `__virtual__`)
1266
+ throw new Error(`Assertion failed: Virtual folders must be named "__virtual__"`);
1267
+ if (!ppath.basename(component).match(VALID_COMPONENT))
1268
+ throw new Error(`Assertion failed: Virtual components must be ended by an hexadecimal hash`);
1269
+ const target = ppath.relative(ppath.dirname(base), to);
1270
+ const segments = target.split(`/`);
1271
+ let depth = 0;
1272
+ while (depth < segments.length && segments[depth] === `..`)
1273
+ depth += 1;
1274
+ const finalSegments = segments.slice(depth);
1275
+ const fullVirtualPath = ppath.join(base, component, String(depth), ...finalSegments);
1276
+ return fullVirtualPath;
1277
+ }
1278
+ static resolveVirtual(p) {
1279
+ const match = p.match(VIRTUAL_REGEXP);
1280
+ if (!match || !match[3] && match[5])
1281
+ return p;
1282
+ const target = ppath.dirname(match[1]);
1283
+ if (!match[3] || !match[4])
1284
+ return target;
1285
+ const isnum = NUMBER_REGEXP.test(match[4]);
1286
+ if (!isnum)
1287
+ return p;
1288
+ const depth = Number(match[4]);
1289
+ const backstep = `../`.repeat(depth);
1290
+ const subpath = match[5] || `.`;
1291
+ return VirtualFS.resolveVirtual(ppath.join(target, backstep, subpath));
1292
+ }
1293
+ getExtractHint(hints) {
1294
+ return this.baseFs.getExtractHint(hints);
1295
+ }
1296
+ getRealPath() {
1297
+ return this.baseFs.getRealPath();
1298
+ }
1299
+ realpathSync(p) {
1300
+ const match = p.match(VIRTUAL_REGEXP);
1301
+ if (!match)
1302
+ return this.baseFs.realpathSync(p);
1303
+ if (!match[5])
1304
+ return p;
1305
+ const realpath = this.baseFs.realpathSync(this.mapToBase(p));
1306
+ return VirtualFS.makeVirtualPath(match[1], match[3], realpath);
1307
+ }
1308
+ async realpathPromise(p) {
1309
+ const match = p.match(VIRTUAL_REGEXP);
1310
+ if (!match)
1311
+ return await this.baseFs.realpathPromise(p);
1312
+ if (!match[5])
1313
+ return p;
1314
+ const realpath = await this.baseFs.realpathPromise(this.mapToBase(p));
1315
+ return VirtualFS.makeVirtualPath(match[1], match[3], realpath);
1316
+ }
1317
+ mapToBase(p) {
1318
+ if (p === ``)
1319
+ return p;
1320
+ if (this.pathUtils.isAbsolute(p))
1321
+ return VirtualFS.resolveVirtual(p);
1322
+ const resolvedRoot = VirtualFS.resolveVirtual(this.baseFs.resolve(PortablePath.dot));
1323
+ const resolvedP = VirtualFS.resolveVirtual(this.baseFs.resolve(p));
1324
+ return ppath.relative(resolvedRoot, resolvedP) || PortablePath.dot;
1325
+ }
1326
+ mapFromBase(p) {
1327
+ return p;
1328
+ }
1329
+ }
1330
+
1331
+ const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10));
1332
+ const HAS_CONSOLIDATED_HOOKS = major > 16 || major === 16 && minor >= 12;
1333
+ const HAS_UNFLAGGED_JSON_MODULES = major > 17 || major === 17 && minor >= 5 || major === 16 && minor >= 15;
1334
+ const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || major === 17 && minor >= 1 || major === 16 && minor > 14;
1335
+ const WATCH_MODE_MESSAGE_USES_ARRAYS = major > 19 || major === 19 && minor >= 2 || major === 18 && minor >= 13;
1336
+ const HAS_LAZY_LOADED_TRANSLATORS = major > 19 || major === 19 && minor >= 3;
67
1337
 
68
1338
  const builtinModules = new Set(Module.builtinModules || Object.keys(process.binding(`natives`)));
69
1339
  const isBuiltinModule = (request) => request.startsWith(`node:`) || builtinModules.has(request);
@@ -92,12 +1362,7 @@ function readPackage(requestPath) {
92
1362
  return JSON.parse(fs.readFileSync(jsonPath, `utf8`));
93
1363
  }
94
1364
 
95
- const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10));
96
- const HAS_CONSOLIDATED_HOOKS = major > 16 || major === 16 && minor >= 12;
97
- const HAS_UNFLAGGED_JSON_MODULES = major > 17 || major === 17 && minor >= 5 || major === 16 && minor >= 15;
98
- const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || major === 17 && minor >= 1 || major === 16 && minor > 14;
99
-
100
- async function tryReadFile(path2) {
1365
+ async function tryReadFile$1(path2) {
101
1366
  try {
102
1367
  return await fs.promises.readFile(path2, `utf8`);
103
1368
  } catch (error) {
@@ -108,7 +1373,7 @@ async function tryReadFile(path2) {
108
1373
  }
109
1374
  function tryParseURL(str, base) {
110
1375
  try {
111
- return new URL(str, base);
1376
+ return new URL$1(str, base);
112
1377
  } catch {
113
1378
  return null;
114
1379
  }
@@ -128,12 +1393,16 @@ function getFileFormat(filepath) {
128
1393
  return `commonjs`;
129
1394
  }
130
1395
  case `.wasm`: {
131
- throw new Error(`Unknown file extension ".wasm" for ${filepath}`);
1396
+ throw new Error(
1397
+ `Unknown file extension ".wasm" for ${filepath}`
1398
+ );
132
1399
  }
133
1400
  case `.json`: {
134
1401
  if (HAS_UNFLAGGED_JSON_MODULES)
135
1402
  return `json`;
136
- throw new Error(`Unknown file extension ".json" for ${filepath}`);
1403
+ throw new Error(
1404
+ `Unknown file extension ".json" for ${filepath}`
1405
+ );
137
1406
  }
138
1407
  case `.js`: {
139
1408
  const pkg = readPackageScope(filepath);
@@ -190,18 +1459,500 @@ async function load$1(urlString, context, nextLoad) {
190
1459
  err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`;
191
1460
  throw err;
192
1461
  }
1462
+ if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) {
1463
+ const pathToSend = pathToFileURL(
1464
+ npath.fromPortablePath(
1465
+ VirtualFS.resolveVirtual(npath.toPortablePath(filePath))
1466
+ )
1467
+ ).href;
1468
+ process.send({
1469
+ "watch:import": WATCH_MODE_MESSAGE_USES_ARRAYS ? [pathToSend] : pathToSend
1470
+ });
1471
+ }
193
1472
  return {
194
1473
  format,
195
- source: await fs.promises.readFile(filePath, `utf8`),
1474
+ source: format === `commonjs` ? void 0 : await fs.promises.readFile(filePath, `utf8`),
196
1475
  shortCircuit: true
197
1476
  };
198
1477
  }
199
1478
 
1479
+ const ArrayIsArray = Array.isArray;
1480
+ const JSONStringify = JSON.stringify;
1481
+ const ObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
1482
+ const ObjectPrototypeHasOwnProperty = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
1483
+ const RegExpPrototypeExec = (obj, string) => RegExp.prototype.exec.call(obj, string);
1484
+ const RegExpPrototypeSymbolReplace = (obj, ...rest) => RegExp.prototype[Symbol.replace].apply(obj, rest);
1485
+ const StringPrototypeEndsWith = (str, ...rest) => String.prototype.endsWith.apply(str, rest);
1486
+ const StringPrototypeIncludes = (str, ...rest) => String.prototype.includes.apply(str, rest);
1487
+ const StringPrototypeLastIndexOf = (str, ...rest) => String.prototype.lastIndexOf.apply(str, rest);
1488
+ const StringPrototypeIndexOf = (str, ...rest) => String.prototype.indexOf.apply(str, rest);
1489
+ const StringPrototypeReplace = (str, ...rest) => String.prototype.replace.apply(str, rest);
1490
+ const StringPrototypeSlice = (str, ...rest) => String.prototype.slice.apply(str, rest);
1491
+ const StringPrototypeStartsWith = (str, ...rest) => String.prototype.startsWith.apply(str, rest);
1492
+ const SafeMap = Map;
1493
+ const JSONParse = JSON.parse;
1494
+
1495
+ function createErrorType(code, messageCreator, errorType) {
1496
+ return class extends errorType {
1497
+ constructor(...args) {
1498
+ super(messageCreator(...args));
1499
+ this.code = code;
1500
+ this.name = `${errorType.name} [${code}]`;
1501
+ }
1502
+ };
1503
+ }
1504
+ const ERR_PACKAGE_IMPORT_NOT_DEFINED = createErrorType(
1505
+ `ERR_PACKAGE_IMPORT_NOT_DEFINED`,
1506
+ (specifier, packagePath, base) => {
1507
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ``} imported from ${base}`;
1508
+ },
1509
+ TypeError
1510
+ );
1511
+ const ERR_INVALID_MODULE_SPECIFIER = createErrorType(
1512
+ `ERR_INVALID_MODULE_SPECIFIER`,
1513
+ (request, reason, base = void 0) => {
1514
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ``}`;
1515
+ },
1516
+ TypeError
1517
+ );
1518
+ const ERR_INVALID_PACKAGE_TARGET = createErrorType(
1519
+ `ERR_INVALID_PACKAGE_TARGET`,
1520
+ (pkgPath, key, target, isImport = false, base = void 0) => {
1521
+ const relError = typeof target === `string` && !isImport && target.length && !StringPrototypeStartsWith(target, `./`);
1522
+ if (key === `.`) {
1523
+ assert(isImport === false);
1524
+ return `Invalid "exports" main target ${JSONStringify(target)} defined in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ``}${relError ? `; targets must start with "./"` : ``}`;
1525
+ }
1526
+ return `Invalid "${isImport ? `imports` : `exports`}" target ${JSONStringify(
1527
+ target
1528
+ )} defined for '${key}' in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ``}${relError ? `; targets must start with "./"` : ``}`;
1529
+ },
1530
+ Error
1531
+ );
1532
+ const ERR_INVALID_PACKAGE_CONFIG = createErrorType(
1533
+ `ERR_INVALID_PACKAGE_CONFIG`,
1534
+ (path, base, message) => {
1535
+ return `Invalid package config ${path}${base ? ` while importing ${base}` : ``}${message ? `. ${message}` : ``}`;
1536
+ },
1537
+ Error
1538
+ );
1539
+
1540
+ function filterOwnProperties(source, keys) {
1541
+ const filtered = /* @__PURE__ */ Object.create(null);
1542
+ for (let i = 0; i < keys.length; i++) {
1543
+ const key = keys[i];
1544
+ if (ObjectPrototypeHasOwnProperty(source, key)) {
1545
+ filtered[key] = source[key];
1546
+ }
1547
+ }
1548
+ return filtered;
1549
+ }
1550
+
1551
+ const packageJSONCache = new SafeMap();
1552
+ function getPackageConfig(path, specifier, base, readFileSyncFn) {
1553
+ const existing = packageJSONCache.get(path);
1554
+ if (existing !== void 0) {
1555
+ return existing;
1556
+ }
1557
+ const source = readFileSyncFn(path);
1558
+ if (source === void 0) {
1559
+ const packageConfig2 = {
1560
+ pjsonPath: path,
1561
+ exists: false,
1562
+ main: void 0,
1563
+ name: void 0,
1564
+ type: "none",
1565
+ exports: void 0,
1566
+ imports: void 0
1567
+ };
1568
+ packageJSONCache.set(path, packageConfig2);
1569
+ return packageConfig2;
1570
+ }
1571
+ let packageJSON;
1572
+ try {
1573
+ packageJSON = JSONParse(source);
1574
+ } catch (error) {
1575
+ throw new ERR_INVALID_PACKAGE_CONFIG(
1576
+ path,
1577
+ (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier),
1578
+ error.message
1579
+ );
1580
+ }
1581
+ let { imports, main, name, type } = filterOwnProperties(packageJSON, [
1582
+ "imports",
1583
+ "main",
1584
+ "name",
1585
+ "type"
1586
+ ]);
1587
+ const exports = ObjectPrototypeHasOwnProperty(packageJSON, "exports") ? packageJSON.exports : void 0;
1588
+ if (typeof imports !== "object" || imports === null) {
1589
+ imports = void 0;
1590
+ }
1591
+ if (typeof main !== "string") {
1592
+ main = void 0;
1593
+ }
1594
+ if (typeof name !== "string") {
1595
+ name = void 0;
1596
+ }
1597
+ if (type !== "module" && type !== "commonjs") {
1598
+ type = "none";
1599
+ }
1600
+ const packageConfig = {
1601
+ pjsonPath: path,
1602
+ exists: true,
1603
+ main,
1604
+ name,
1605
+ type,
1606
+ exports,
1607
+ imports
1608
+ };
1609
+ packageJSONCache.set(path, packageConfig);
1610
+ return packageConfig;
1611
+ }
1612
+ function getPackageScopeConfig(resolved, readFileSyncFn) {
1613
+ let packageJSONUrl = new URL("./package.json", resolved);
1614
+ while (true) {
1615
+ const packageJSONPath2 = packageJSONUrl.pathname;
1616
+ if (StringPrototypeEndsWith(packageJSONPath2, "node_modules/package.json")) {
1617
+ break;
1618
+ }
1619
+ const packageConfig2 = getPackageConfig(
1620
+ fileURLToPath(packageJSONUrl),
1621
+ resolved,
1622
+ void 0,
1623
+ readFileSyncFn
1624
+ );
1625
+ if (packageConfig2.exists) {
1626
+ return packageConfig2;
1627
+ }
1628
+ const lastPackageJSONUrl = packageJSONUrl;
1629
+ packageJSONUrl = new URL("../package.json", packageJSONUrl);
1630
+ if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
1631
+ break;
1632
+ }
1633
+ }
1634
+ const packageJSONPath = fileURLToPath(packageJSONUrl);
1635
+ const packageConfig = {
1636
+ pjsonPath: packageJSONPath,
1637
+ exists: false,
1638
+ main: void 0,
1639
+ name: void 0,
1640
+ type: "none",
1641
+ exports: void 0,
1642
+ imports: void 0
1643
+ };
1644
+ packageJSONCache.set(packageJSONPath, packageConfig);
1645
+ return packageConfig;
1646
+ }
1647
+
1648
+ /**
1649
+ @license
1650
+ Copyright Node.js contributors. All rights reserved.
1651
+
1652
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1653
+ of this software and associated documentation files (the "Software"), to
1654
+ deal in the Software without restriction, including without limitation the
1655
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1656
+ sell copies of the Software, and to permit persons to whom the Software is
1657
+ furnished to do so, subject to the following conditions:
1658
+
1659
+ The above copyright notice and this permission notice shall be included in
1660
+ all copies or substantial portions of the Software.
1661
+
1662
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1663
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1664
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1665
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1666
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1667
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1668
+ IN THE SOFTWARE.
1669
+ */
1670
+ function throwImportNotDefined(specifier, packageJSONUrl, base) {
1671
+ throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
1672
+ specifier,
1673
+ packageJSONUrl && fileURLToPath(new URL(".", packageJSONUrl)),
1674
+ fileURLToPath(base)
1675
+ );
1676
+ }
1677
+ function throwInvalidSubpath(subpath, packageJSONUrl, internal, base) {
1678
+ const reason = `request is not a valid subpath for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJSONUrl)}`;
1679
+ throw new ERR_INVALID_MODULE_SPECIFIER(
1680
+ subpath,
1681
+ reason,
1682
+ base && fileURLToPath(base)
1683
+ );
1684
+ }
1685
+ function throwInvalidPackageTarget(subpath, target, packageJSONUrl, internal, base) {
1686
+ if (typeof target === "object" && target !== null) {
1687
+ target = JSONStringify(target, null, "");
1688
+ } else {
1689
+ target = `${target}`;
1690
+ }
1691
+ throw new ERR_INVALID_PACKAGE_TARGET(
1692
+ fileURLToPath(new URL(".", packageJSONUrl)),
1693
+ subpath,
1694
+ target,
1695
+ internal,
1696
+ base && fileURLToPath(base)
1697
+ );
1698
+ }
1699
+ const invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
1700
+ const patternRegEx = /\*/g;
1701
+ function resolvePackageTargetString(target, subpath, match, packageJSONUrl, base, pattern, internal, conditions) {
1702
+ if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
1703
+ throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
1704
+ if (!StringPrototypeStartsWith(target, "./")) {
1705
+ if (internal && !StringPrototypeStartsWith(target, "../") && !StringPrototypeStartsWith(target, "/")) {
1706
+ let isURL = false;
1707
+ try {
1708
+ new URL(target);
1709
+ isURL = true;
1710
+ } catch {
1711
+ }
1712
+ if (!isURL) {
1713
+ const exportTarget = pattern ? RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) : target + subpath;
1714
+ return exportTarget;
1715
+ }
1716
+ }
1717
+ throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
1718
+ }
1719
+ if (RegExpPrototypeExec(
1720
+ invalidSegmentRegEx,
1721
+ StringPrototypeSlice(target, 2)
1722
+ ) !== null)
1723
+ throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
1724
+ const resolved = new URL(target, packageJSONUrl);
1725
+ const resolvedPath = resolved.pathname;
1726
+ const packagePath = new URL(".", packageJSONUrl).pathname;
1727
+ if (!StringPrototypeStartsWith(resolvedPath, packagePath))
1728
+ throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
1729
+ if (subpath === "")
1730
+ return resolved;
1731
+ if (RegExpPrototypeExec(invalidSegmentRegEx, subpath) !== null) {
1732
+ const request = pattern ? StringPrototypeReplace(match, "*", () => subpath) : match + subpath;
1733
+ throwInvalidSubpath(request, packageJSONUrl, internal, base);
1734
+ }
1735
+ if (pattern) {
1736
+ return new URL(
1737
+ RegExpPrototypeSymbolReplace(patternRegEx, resolved.href, () => subpath)
1738
+ );
1739
+ }
1740
+ return new URL(subpath, resolved);
1741
+ }
1742
+ function isArrayIndex(key) {
1743
+ const keyNum = +key;
1744
+ if (`${keyNum}` !== key)
1745
+ return false;
1746
+ return keyNum >= 0 && keyNum < 4294967295;
1747
+ }
1748
+ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, base, pattern, internal, conditions) {
1749
+ if (typeof target === "string") {
1750
+ return resolvePackageTargetString(
1751
+ target,
1752
+ subpath,
1753
+ packageSubpath,
1754
+ packageJSONUrl,
1755
+ base,
1756
+ pattern,
1757
+ internal);
1758
+ } else if (ArrayIsArray(target)) {
1759
+ if (target.length === 0) {
1760
+ return null;
1761
+ }
1762
+ let lastException;
1763
+ for (let i = 0; i < target.length; i++) {
1764
+ const targetItem = target[i];
1765
+ let resolveResult;
1766
+ try {
1767
+ resolveResult = resolvePackageTarget(
1768
+ packageJSONUrl,
1769
+ targetItem,
1770
+ subpath,
1771
+ packageSubpath,
1772
+ base,
1773
+ pattern,
1774
+ internal,
1775
+ conditions
1776
+ );
1777
+ } catch (e) {
1778
+ lastException = e;
1779
+ if (e.code === "ERR_INVALID_PACKAGE_TARGET") {
1780
+ continue;
1781
+ }
1782
+ throw e;
1783
+ }
1784
+ if (resolveResult === void 0) {
1785
+ continue;
1786
+ }
1787
+ if (resolveResult === null) {
1788
+ lastException = null;
1789
+ continue;
1790
+ }
1791
+ return resolveResult;
1792
+ }
1793
+ if (lastException === void 0 || lastException === null)
1794
+ return lastException;
1795
+ throw lastException;
1796
+ } else if (typeof target === "object" && target !== null) {
1797
+ const keys = ObjectGetOwnPropertyNames(target);
1798
+ for (let i = 0; i < keys.length; i++) {
1799
+ const key = keys[i];
1800
+ if (isArrayIndex(key)) {
1801
+ throw new ERR_INVALID_PACKAGE_CONFIG(
1802
+ fileURLToPath(packageJSONUrl),
1803
+ base,
1804
+ '"exports" cannot contain numeric property keys.'
1805
+ );
1806
+ }
1807
+ }
1808
+ for (let i = 0; i < keys.length; i++) {
1809
+ const key = keys[i];
1810
+ if (key === "default" || conditions.has(key)) {
1811
+ const conditionalTarget = target[key];
1812
+ const resolveResult = resolvePackageTarget(
1813
+ packageJSONUrl,
1814
+ conditionalTarget,
1815
+ subpath,
1816
+ packageSubpath,
1817
+ base,
1818
+ pattern,
1819
+ internal,
1820
+ conditions
1821
+ );
1822
+ if (resolveResult === void 0)
1823
+ continue;
1824
+ return resolveResult;
1825
+ }
1826
+ }
1827
+ return void 0;
1828
+ } else if (target === null) {
1829
+ return null;
1830
+ }
1831
+ throwInvalidPackageTarget(
1832
+ packageSubpath,
1833
+ target,
1834
+ packageJSONUrl,
1835
+ internal,
1836
+ base
1837
+ );
1838
+ }
1839
+ function patternKeyCompare(a, b) {
1840
+ const aPatternIndex = StringPrototypeIndexOf(a, "*");
1841
+ const bPatternIndex = StringPrototypeIndexOf(b, "*");
1842
+ const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
1843
+ const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
1844
+ if (baseLenA > baseLenB)
1845
+ return -1;
1846
+ if (baseLenB > baseLenA)
1847
+ return 1;
1848
+ if (aPatternIndex === -1)
1849
+ return 1;
1850
+ if (bPatternIndex === -1)
1851
+ return -1;
1852
+ if (a.length > b.length)
1853
+ return -1;
1854
+ if (b.length > a.length)
1855
+ return 1;
1856
+ return 0;
1857
+ }
1858
+ function packageImportsResolve({ name, base, conditions, readFileSyncFn }) {
1859
+ if (name === "#" || StringPrototypeStartsWith(name, "#/") || StringPrototypeEndsWith(name, "/")) {
1860
+ const reason = "is not a valid internal imports specifier name";
1861
+ throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath(base));
1862
+ }
1863
+ let packageJSONUrl;
1864
+ const packageConfig = getPackageScopeConfig(base, readFileSyncFn);
1865
+ if (packageConfig.exists) {
1866
+ packageJSONUrl = pathToFileURL(packageConfig.pjsonPath);
1867
+ const imports = packageConfig.imports;
1868
+ if (imports) {
1869
+ if (ObjectPrototypeHasOwnProperty(imports, name) && !StringPrototypeIncludes(name, "*")) {
1870
+ const resolveResult = resolvePackageTarget(
1871
+ packageJSONUrl,
1872
+ imports[name],
1873
+ "",
1874
+ name,
1875
+ base,
1876
+ false,
1877
+ true,
1878
+ conditions
1879
+ );
1880
+ if (resolveResult != null) {
1881
+ return resolveResult;
1882
+ }
1883
+ } else {
1884
+ let bestMatch = "";
1885
+ let bestMatchSubpath;
1886
+ const keys = ObjectGetOwnPropertyNames(imports);
1887
+ for (let i = 0; i < keys.length; i++) {
1888
+ const key = keys[i];
1889
+ const patternIndex = StringPrototypeIndexOf(key, "*");
1890
+ if (patternIndex !== -1 && StringPrototypeStartsWith(
1891
+ name,
1892
+ StringPrototypeSlice(key, 0, patternIndex)
1893
+ )) {
1894
+ const patternTrailer = StringPrototypeSlice(key, patternIndex + 1);
1895
+ if (name.length >= key.length && StringPrototypeEndsWith(name, patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && StringPrototypeLastIndexOf(key, "*") === patternIndex) {
1896
+ bestMatch = key;
1897
+ bestMatchSubpath = StringPrototypeSlice(
1898
+ name,
1899
+ patternIndex,
1900
+ name.length - patternTrailer.length
1901
+ );
1902
+ }
1903
+ }
1904
+ }
1905
+ if (bestMatch) {
1906
+ const target = imports[bestMatch];
1907
+ const resolveResult = resolvePackageTarget(
1908
+ packageJSONUrl,
1909
+ target,
1910
+ bestMatchSubpath,
1911
+ bestMatch,
1912
+ base,
1913
+ true,
1914
+ true,
1915
+ conditions
1916
+ );
1917
+ if (resolveResult != null) {
1918
+ return resolveResult;
1919
+ }
1920
+ }
1921
+ }
1922
+ }
1923
+ }
1924
+ throwImportNotDefined(name, packageJSONUrl, base);
1925
+ }
1926
+
200
1927
  const pathRegExp = /^(?![a-zA-Z]:[\\/]|\\\\|\.{0,2}(?:\/|$))((?:node:)?(?:@[^/]+\/)?[^/]+)\/*(.*|)$/;
201
1928
  const isRelativeRegexp = /^\.{0,2}\//;
1929
+ function tryReadFile(filePath) {
1930
+ try {
1931
+ return fs.readFileSync(filePath, `utf8`);
1932
+ } catch (err) {
1933
+ if (err.code === `ENOENT`)
1934
+ return void 0;
1935
+ throw err;
1936
+ }
1937
+ }
1938
+ async function resolvePrivateRequest(specifier, issuer, context, nextResolve) {
1939
+ const resolved = packageImportsResolve({
1940
+ name: specifier,
1941
+ base: pathToFileURL(issuer),
1942
+ conditions: new Set(context.conditions),
1943
+ readFileSyncFn: tryReadFile
1944
+ });
1945
+ if (resolved instanceof URL$1) {
1946
+ return { url: resolved.href, shortCircuit: true };
1947
+ } else {
1948
+ if (resolved.startsWith(`#`))
1949
+ throw new Error(`Mapping from one private import to another isn't allowed`);
1950
+ return resolve$1(resolved, context, nextResolve);
1951
+ }
1952
+ }
202
1953
  async function resolve$1(originalSpecifier, context, nextResolve) {
203
- var _a;
204
- const {findPnpApi} = moduleExports;
1954
+ var _a, _b;
1955
+ const { findPnpApi } = moduleExports;
205
1956
  if (!findPnpApi || isBuiltinModule(originalSpecifier))
206
1957
  return nextResolve(originalSpecifier, context, nextResolve);
207
1958
  let specifier = originalSpecifier;
@@ -211,19 +1962,21 @@ async function resolve$1(originalSpecifier, context, nextResolve) {
211
1962
  return nextResolve(originalSpecifier, context, nextResolve);
212
1963
  specifier = fileURLToPath(url);
213
1964
  }
214
- const {parentURL, conditions = []} = context;
215
- const issuer = parentURL ? fileURLToPath(parentURL) : process.cwd();
216
- const pnpapi = (_a = findPnpApi(issuer)) != null ? _a : url ? findPnpApi(specifier) : null;
1965
+ const { parentURL, conditions = [] } = context;
1966
+ const issuer = parentURL && ((_a = tryParseURL(parentURL)) == null ? void 0 : _a.protocol) === `file:` ? fileURLToPath(parentURL) : process.cwd();
1967
+ const pnpapi = (_b = findPnpApi(issuer)) != null ? _b : url ? findPnpApi(specifier) : null;
217
1968
  if (!pnpapi)
218
1969
  return nextResolve(originalSpecifier, context, nextResolve);
1970
+ if (specifier.startsWith(`#`))
1971
+ return resolvePrivateRequest(specifier, issuer, context, nextResolve);
219
1972
  const dependencyNameMatch = specifier.match(pathRegExp);
220
1973
  let allowLegacyResolve = false;
221
1974
  if (dependencyNameMatch) {
222
1975
  const [, dependencyName, subPath] = dependencyNameMatch;
223
- if (subPath === ``) {
1976
+ if (subPath === `` && dependencyName !== `pnpapi`) {
224
1977
  const resolved = pnpapi.resolveToUnqualified(`${dependencyName}/package.json`, issuer);
225
1978
  if (resolved) {
226
- const content = await tryReadFile(resolved);
1979
+ const content = await tryReadFile$1(resolved);
227
1980
  if (content) {
228
1981
  const pkg = JSON.parse(content);
229
1982
  allowLegacyResolve = pkg.exports == null;
@@ -231,10 +1984,17 @@ async function resolve$1(originalSpecifier, context, nextResolve) {
231
1984
  }
232
1985
  }
233
1986
  }
234
- const result = pnpapi.resolveRequest(specifier, issuer, {
235
- conditions: new Set(conditions),
236
- extensions: allowLegacyResolve ? void 0 : []
237
- });
1987
+ let result;
1988
+ try {
1989
+ result = pnpapi.resolveRequest(specifier, issuer, {
1990
+ conditions: new Set(conditions),
1991
+ extensions: allowLegacyResolve ? void 0 : []
1992
+ });
1993
+ } catch (err) {
1994
+ if (err instanceof Error && `code` in err && err.code === `MODULE_NOT_FOUND`)
1995
+ err.code = `ERR_MODULE_NOT_FOUND`;
1996
+ throw err;
1997
+ }
238
1998
  if (!result)
239
1999
  throw new Error(`Resolving '${specifier}' from '${issuer}' failed`);
240
2000
  const resultURL = pathToFileURL(result);
@@ -250,32 +2010,34 @@ async function resolve$1(originalSpecifier, context, nextResolve) {
250
2010
  };
251
2011
  }
252
2012
 
253
- const binding = process.binding(`fs`);
254
- const originalfstat = binding.fstat;
255
- const ZIP_MASK = 4278190080;
256
- const ZIP_MAGIC = 704643072;
257
- binding.fstat = function(...args) {
258
- const [fd, useBigint, req] = args;
259
- if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
260
- try {
261
- const stats = fs.fstatSync(fd);
262
- return new Float64Array([
263
- stats.dev,
264
- stats.mode,
265
- stats.nlink,
266
- stats.uid,
267
- stats.gid,
268
- stats.rdev,
269
- stats.blksize,
270
- stats.ino,
271
- stats.size,
272
- stats.blocks
273
- ]);
274
- } catch {
275
- }
276
- }
277
- return originalfstat.apply(this, args);
278
- };
2013
+ if (!HAS_LAZY_LOADED_TRANSLATORS) {
2014
+ const binding = process.binding(`fs`);
2015
+ const originalfstat = binding.fstat;
2016
+ const ZIP_MASK = 4278190080;
2017
+ const ZIP_MAGIC = 704643072;
2018
+ binding.fstat = function(...args) {
2019
+ const [fd, useBigint, req] = args;
2020
+ if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
2021
+ try {
2022
+ const stats = fs.fstatSync(fd);
2023
+ return new Float64Array([
2024
+ stats.dev,
2025
+ stats.mode,
2026
+ stats.nlink,
2027
+ stats.uid,
2028
+ stats.gid,
2029
+ stats.rdev,
2030
+ stats.blksize,
2031
+ stats.ino,
2032
+ stats.size,
2033
+ stats.blocks
2034
+ ]);
2035
+ } catch {
2036
+ }
2037
+ }
2038
+ return originalfstat.apply(this, args);
2039
+ };
2040
+ }
279
2041
 
280
2042
  const resolve = resolve$1;
281
2043
  const getFormat = HAS_CONSOLIDATED_HOOKS ? void 0 : getFormat$1;