rolldown-require 1.0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1151 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkQ6XJHTDBcjs = require('./chunk-Q6XJHTDB.cjs');
5
+
6
+ // src/index.ts
7
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
8
+ var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
9
+ var _module = require('module');
10
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
11
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
12
+ var _url = require('url');
13
+ var _util = require('util');
14
+ var _gettsconfig = require('get-tsconfig');
15
+ var _rolldown = require('rolldown');
16
+
17
+ // src/packages.ts
18
+
19
+
20
+
21
+
22
+
23
+ // src/utils.ts
24
+ var _child_process = require('child_process');
25
+ var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
26
+ var _dns = require('dns');
27
+
28
+
29
+
30
+
31
+
32
+
33
+ var _pluginutils = require('@rollup/pluginutils');
34
+
35
+ // src/constants.ts
36
+
37
+
38
+
39
+ var { version } = JSON.parse(
40
+ _fs.readFileSync.call(void 0, new URL("../package.json", _chunkQ6XJHTDBcjs.importMetaUrl)).toString()
41
+ );
42
+ var DEFAULT_MAIN_FIELDS = [
43
+ "browser",
44
+ "module",
45
+ "jsnext:main",
46
+ // moment still uses this...
47
+ "jsnext"
48
+ ];
49
+ var DEFAULT_CLIENT_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS);
50
+ var DEFAULT_SERVER_MAIN_FIELDS = Object.freeze(
51
+ DEFAULT_MAIN_FIELDS.filter((f) => f !== "browser")
52
+ );
53
+ var DEV_PROD_CONDITION = `development|production`;
54
+ var DEFAULT_CONDITIONS = ["module", "browser", "node", DEV_PROD_CONDITION];
55
+ var DEFAULT_CLIENT_CONDITIONS = Object.freeze(
56
+ DEFAULT_CONDITIONS.filter((c) => c !== "node")
57
+ );
58
+ var DEFAULT_SERVER_CONDITIONS = Object.freeze(
59
+ DEFAULT_CONDITIONS.filter((c) => c !== "browser")
60
+ );
61
+ var OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
62
+ var SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
63
+ var FS_PREFIX = `/@fs/`;
64
+ var CLIENT_PUBLIC_PATH = `/@vite/client`;
65
+ var ENV_PUBLIC_PATH = `/@vite/env`;
66
+ var VITE_PACKAGE_DIR = _path.resolve.call(void 0,
67
+ // import.meta.url is `dist/node/constants.js` after bundle
68
+ _url.fileURLToPath.call(void 0, _chunkQ6XJHTDBcjs.importMetaUrl),
69
+ "../../.."
70
+ );
71
+ var CLIENT_ENTRY = _path.resolve.call(void 0, VITE_PACKAGE_DIR, "dist/client/client.mjs");
72
+ var ENV_ENTRY = _path.resolve.call(void 0, VITE_PACKAGE_DIR, "dist/client/env.mjs");
73
+ var CLIENT_DIR = _path2.default.dirname(CLIENT_ENTRY);
74
+ var VALID_ID_PREFIX = `/@id/`;
75
+ var SOURCEMAPPING_URL = "sourceMa";
76
+ SOURCEMAPPING_URL += "ppingURL";
77
+
78
+ // src/sharedUtils.ts
79
+
80
+ var isWindows = typeof _process2.default !== "undefined" && _process2.default.platform === "win32";
81
+ var windowsSlashRE = /\\/g;
82
+ function slash(p) {
83
+ return p.replace(windowsSlashRE, "/");
84
+ }
85
+ var postfixRE = /[?#].*$/;
86
+ function cleanUrl(url) {
87
+ return url.replace(postfixRE, "");
88
+ }
89
+ function splitFileAndPostfix(path7) {
90
+ const file = cleanUrl(path7);
91
+ return { file, postfix: path7.slice(file.length) };
92
+ }
93
+ var AsyncFunction = async function() {
94
+ }.constructor;
95
+
96
+ // src/utils.ts
97
+
98
+ var _filter = require('rolldown/filter');
99
+ var createFilter = _pluginutils.createFilter;
100
+ var NODE_BUILTIN_NAMESPACE = "node:";
101
+ var NPM_BUILTIN_NAMESPACE = "npm:";
102
+ var BUN_BUILTIN_NAMESPACE = "bun:";
103
+ var nodeBuiltins = _module.builtinModules.filter((id) => !id.includes(":"));
104
+ var isBuiltinCache = /* @__PURE__ */ new WeakMap();
105
+ function isBuiltin(builtins, id) {
106
+ let isBuiltin2 = isBuiltinCache.get(builtins);
107
+ if (!isBuiltin2) {
108
+ isBuiltin2 = createIsBuiltin(builtins);
109
+ isBuiltinCache.set(builtins, isBuiltin2);
110
+ }
111
+ return isBuiltin2(id);
112
+ }
113
+ function createIsBuiltin(builtins) {
114
+ const plainBuiltinsSet = new Set(
115
+ builtins.filter((builtin) => typeof builtin === "string")
116
+ );
117
+ const regexBuiltins = builtins.filter(
118
+ (builtin) => typeof builtin !== "string"
119
+ );
120
+ return (id) => plainBuiltinsSet.has(id) || regexBuiltins.some((regexp) => regexp.test(id));
121
+ }
122
+ var nodeLikeBuiltins = [
123
+ ...nodeBuiltins,
124
+ new RegExp(`^${NODE_BUILTIN_NAMESPACE}`),
125
+ new RegExp(`^${NPM_BUILTIN_NAMESPACE}`),
126
+ new RegExp(`^${BUN_BUILTIN_NAMESPACE}`)
127
+ ];
128
+ function isNodeLikeBuiltin(id) {
129
+ return isBuiltin(nodeLikeBuiltins, id);
130
+ }
131
+ function isNodeBuiltin(id) {
132
+ if (id.startsWith(NODE_BUILTIN_NAMESPACE)) {
133
+ return true;
134
+ }
135
+ return nodeBuiltins.includes(id);
136
+ }
137
+ function isInNodeModules(id) {
138
+ return id.includes("node_modules");
139
+ }
140
+ function isOptimizable(id, optimizeDeps) {
141
+ const { extensions } = optimizeDeps;
142
+ return OPTIMIZABLE_ENTRY_RE.test(id) || (_nullishCoalesce(_optionalChain([extensions, 'optionalAccess', _ => _.some, 'call', _2 => _2((ext) => id.endsWith(ext))]), () => ( false)));
143
+ }
144
+ var bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
145
+ var deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
146
+ var _require = _module.createRequire.call(void 0, _chunkQ6XJHTDBcjs.importMetaUrl);
147
+ var _dirname = _path2.default.dirname(_url.fileURLToPath.call(void 0, _chunkQ6XJHTDBcjs.importMetaUrl));
148
+ var urlCanParse = _nullishCoalesce(_url.URL.canParse, () => ( ((path7, base) => {
149
+ try {
150
+ new (0, _url.URL)(path7, base);
151
+ return true;
152
+ } catch (e2) {
153
+ return false;
154
+ }
155
+ })));
156
+ function normalizePath(id) {
157
+ return _path2.default.posix.normalize(isWindows ? slash(id) : id);
158
+ }
159
+ var internalPrefixes = [
160
+ FS_PREFIX,
161
+ VALID_ID_PREFIX,
162
+ CLIENT_PUBLIC_PATH,
163
+ ENV_PUBLIC_PATH
164
+ ];
165
+ var InternalPrefixRE = new RegExp(`^(?:${internalPrefixes.join("|")})`);
166
+ function injectQuery(url, queryToInject) {
167
+ const { file, postfix } = splitFileAndPostfix(url);
168
+ const normalizedFile = isWindows ? slash(file) : file;
169
+ return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : (
170
+ /* hash only */
171
+ postfix
172
+ )}`;
173
+ }
174
+ function isObject(value) {
175
+ return Object.prototype.toString.call(value) === "[object Object]";
176
+ }
177
+ function tryStatSync(file) {
178
+ try {
179
+ return _fs2.default.statSync(file, { throwIfNoEntry: false });
180
+ } catch (e3) {
181
+ }
182
+ }
183
+ function isFilePathESM(filePath, packageCache) {
184
+ if (/\.m[jt]s$/.test(filePath)) {
185
+ return true;
186
+ } else if (/\.c[jt]s$/.test(filePath)) {
187
+ return false;
188
+ } else {
189
+ try {
190
+ const pkg = findNearestPackageData(_path2.default.dirname(filePath), packageCache);
191
+ return _optionalChain([pkg, 'optionalAccess', _3 => _3.data, 'access', _4 => _4.type]) === "module";
192
+ } catch (e4) {
193
+ return false;
194
+ }
195
+ }
196
+ }
197
+ var safeRealpathSync = isWindows ? windowsSafeRealPathSync : _fs2.default.realpathSync.native;
198
+ var windowsNetworkMap = /* @__PURE__ */ new Map();
199
+ function windowsMappedRealpathSync(path7) {
200
+ const realPath = _fs2.default.realpathSync.native(path7);
201
+ if (realPath.startsWith("\\\\")) {
202
+ for (const [network, volume] of windowsNetworkMap) {
203
+ if (realPath.startsWith(network)) {
204
+ return realPath.replace(network, volume);
205
+ }
206
+ }
207
+ }
208
+ return realPath;
209
+ }
210
+ var parseNetUseRE = /^\w* +(\w:) +([^ ]+)\s/;
211
+ var firstSafeRealPathSyncRun = false;
212
+ function windowsSafeRealPathSync(path7) {
213
+ if (!firstSafeRealPathSyncRun) {
214
+ optimizeSafeRealPathSync();
215
+ firstSafeRealPathSyncRun = true;
216
+ }
217
+ return _fs2.default.realpathSync(path7);
218
+ }
219
+ function optimizeSafeRealPathSync() {
220
+ const nodeVersion = _process2.default.versions.node.split(".").map(Number);
221
+ if (nodeVersion[0] < 18 || nodeVersion[0] === 18 && nodeVersion[1] < 10) {
222
+ safeRealpathSync = _fs2.default.realpathSync;
223
+ return;
224
+ }
225
+ try {
226
+ _fs2.default.realpathSync.native(_path2.default.resolve("./"));
227
+ } catch (error) {
228
+ if (error.message.includes("EISDIR: illegal operation on a directory")) {
229
+ safeRealpathSync = _fs2.default.realpathSync;
230
+ return;
231
+ }
232
+ }
233
+ _child_process.exec.call(void 0, "net use", (error, stdout) => {
234
+ if (error) {
235
+ return;
236
+ }
237
+ const lines = stdout.split("\n");
238
+ for (const line of lines) {
239
+ const m = parseNetUseRE.exec(line);
240
+ if (m) {
241
+ windowsNetworkMap.set(m[2], m[1]);
242
+ }
243
+ }
244
+ if (windowsNetworkMap.size === 0) {
245
+ safeRealpathSync = _fs2.default.realpathSync.native;
246
+ } else {
247
+ safeRealpathSync = windowsMappedRealpathSync;
248
+ }
249
+ });
250
+ }
251
+ var hash = _nullishCoalesce(_crypto2.default.hash, () => ( ((algorithm, data, outputEncoding) => _crypto2.default.createHash(algorithm).update(data).digest(outputEncoding))));
252
+ function stripBomTag(content) {
253
+ if (content.charCodeAt(0) === 65279) {
254
+ return content.slice(1);
255
+ }
256
+ return content;
257
+ }
258
+ function getNpmPackageName(importPath) {
259
+ const parts = importPath.split("/");
260
+ if (parts[0][0] === "@") {
261
+ if (!parts[1]) {
262
+ return null;
263
+ }
264
+ return `${parts[0]}/${parts[1]}`;
265
+ } else {
266
+ return parts[0];
267
+ }
268
+ }
269
+ var dynamicImport = async (id, { format }) => {
270
+ const fn = format === "esm" ? (file) => Promise.resolve().then(() => _interopRequireWildcard(require(file))) : false ? _module.createRequire.call(void 0, _chunkQ6XJHTDBcjs.importMetaUrl) : _chunkQ6XJHTDBcjs.__require;
271
+ return fn(id);
272
+ };
273
+
274
+ // src/packages.ts
275
+ var pnp;
276
+ if (_process2.default.versions.pnp) {
277
+ try {
278
+ pnp = _module.createRequire.call(void 0, (0, _chunkQ6XJHTDBcjs.importMetaUrl))("pnpapi");
279
+ } catch (e5) {
280
+ }
281
+ }
282
+ function resolvePackageData(pkgName, basedir, preserveSymlinks = false, packageCache) {
283
+ if (pnp) {
284
+ const cacheKey = getRpdCacheKey(pkgName, basedir, preserveSymlinks);
285
+ if (_optionalChain([packageCache, 'optionalAccess', _5 => _5.has, 'call', _6 => _6(cacheKey)])) {
286
+ return packageCache.get(cacheKey);
287
+ }
288
+ try {
289
+ const pkg = pnp.resolveToUnqualified(pkgName, basedir, {
290
+ considerBuiltins: false
291
+ });
292
+ if (!pkg) {
293
+ return null;
294
+ }
295
+ const pkgData = loadPackageData(_path2.default.join(pkg, "package.json"));
296
+ _optionalChain([packageCache, 'optionalAccess', _7 => _7.set, 'call', _8 => _8(cacheKey, pkgData)]);
297
+ return pkgData;
298
+ } catch (e6) {
299
+ return null;
300
+ }
301
+ }
302
+ const originalBasedir = basedir;
303
+ while (basedir) {
304
+ if (packageCache) {
305
+ const cached = getRpdCache(
306
+ packageCache,
307
+ pkgName,
308
+ basedir,
309
+ originalBasedir,
310
+ preserveSymlinks
311
+ );
312
+ if (cached) {
313
+ return cached;
314
+ }
315
+ }
316
+ const pkg = _path2.default.join(basedir, "node_modules", pkgName, "package.json");
317
+ try {
318
+ if (_fs2.default.existsSync(pkg)) {
319
+ const pkgPath = preserveSymlinks ? pkg : safeRealpathSync(pkg);
320
+ const pkgData = loadPackageData(pkgPath);
321
+ if (packageCache) {
322
+ setRpdCache(
323
+ packageCache,
324
+ pkgData,
325
+ pkgName,
326
+ basedir,
327
+ originalBasedir,
328
+ preserveSymlinks
329
+ );
330
+ }
331
+ return pkgData;
332
+ }
333
+ } catch (e7) {
334
+ }
335
+ const nextBasedir = _path2.default.dirname(basedir);
336
+ if (nextBasedir === basedir) {
337
+ break;
338
+ }
339
+ basedir = nextBasedir;
340
+ }
341
+ return null;
342
+ }
343
+ function findNearestPackageData(basedir, packageCache) {
344
+ const originalBasedir = basedir;
345
+ while (basedir) {
346
+ if (packageCache) {
347
+ const cached = getFnpdCache(packageCache, basedir, originalBasedir);
348
+ if (cached) {
349
+ return cached;
350
+ }
351
+ }
352
+ const pkgPath = _path2.default.join(basedir, "package.json");
353
+ if (_optionalChain([tryStatSync, 'call', _9 => _9(pkgPath), 'optionalAccess', _10 => _10.isFile, 'call', _11 => _11()])) {
354
+ try {
355
+ const pkgData = loadPackageData(pkgPath);
356
+ if (packageCache) {
357
+ setFnpdCache(packageCache, pkgData, basedir, originalBasedir);
358
+ }
359
+ return pkgData;
360
+ } catch (e8) {
361
+ }
362
+ }
363
+ const nextBasedir = _path2.default.dirname(basedir);
364
+ if (nextBasedir === basedir) {
365
+ break;
366
+ }
367
+ basedir = nextBasedir;
368
+ }
369
+ return null;
370
+ }
371
+ function findNearestMainPackageData(basedir, packageCache) {
372
+ const nearestPackage = findNearestPackageData(basedir, packageCache);
373
+ return nearestPackage && (nearestPackage.data.name ? nearestPackage : findNearestMainPackageData(
374
+ _path2.default.dirname(nearestPackage.dir),
375
+ packageCache
376
+ ));
377
+ }
378
+ function loadPackageData(pkgPath) {
379
+ const data = JSON.parse(stripBomTag(_fs2.default.readFileSync(pkgPath, "utf-8")));
380
+ const pkgDir = normalizePath(_path2.default.dirname(pkgPath));
381
+ const { sideEffects } = data;
382
+ let hasSideEffects;
383
+ if (typeof sideEffects === "boolean") {
384
+ hasSideEffects = () => sideEffects;
385
+ } else if (Array.isArray(sideEffects)) {
386
+ if (sideEffects.length <= 0) {
387
+ hasSideEffects = () => false;
388
+ } else {
389
+ const finalPackageSideEffects = sideEffects.map((sideEffect) => {
390
+ if (sideEffect.includes("/")) {
391
+ return sideEffect;
392
+ }
393
+ return `**/${sideEffect}`;
394
+ });
395
+ hasSideEffects = createFilter(finalPackageSideEffects, null, {
396
+ resolve: pkgDir
397
+ });
398
+ }
399
+ } else {
400
+ hasSideEffects = () => null;
401
+ }
402
+ const resolvedCache = {};
403
+ const pkg = {
404
+ dir: pkgDir,
405
+ data,
406
+ hasSideEffects,
407
+ setResolvedCache(key, entry, options) {
408
+ resolvedCache[getResolveCacheKey(key, options)] = entry;
409
+ },
410
+ getResolvedCache(key, options) {
411
+ return resolvedCache[getResolveCacheKey(key, options)];
412
+ }
413
+ };
414
+ return pkg;
415
+ }
416
+ function getResolveCacheKey(key, options) {
417
+ return [
418
+ key,
419
+ options.isRequire ? "1" : "0",
420
+ options.conditions.join("_"),
421
+ options.extensions.join("_"),
422
+ options.mainFields.join("_")
423
+ ].join("|");
424
+ }
425
+ function findNearestNodeModules(basedir) {
426
+ while (basedir) {
427
+ const pkgPath = _path2.default.join(basedir, "node_modules");
428
+ if (_optionalChain([tryStatSync, 'call', _12 => _12(pkgPath), 'optionalAccess', _13 => _13.isDirectory, 'call', _14 => _14()])) {
429
+ return pkgPath;
430
+ }
431
+ const nextBasedir = _path2.default.dirname(basedir);
432
+ if (nextBasedir === basedir) {
433
+ break;
434
+ }
435
+ basedir = nextBasedir;
436
+ }
437
+ return null;
438
+ }
439
+ function getRpdCache(packageCache, pkgName, basedir, originalBasedir, preserveSymlinks) {
440
+ const cacheKey = getRpdCacheKey(pkgName, basedir, preserveSymlinks);
441
+ const pkgData = packageCache.get(cacheKey);
442
+ if (pkgData) {
443
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
444
+ packageCache.set(getRpdCacheKey(pkgName, dir, preserveSymlinks), pkgData);
445
+ });
446
+ return pkgData;
447
+ }
448
+ }
449
+ function setRpdCache(packageCache, pkgData, pkgName, basedir, originalBasedir, preserveSymlinks) {
450
+ packageCache.set(getRpdCacheKey(pkgName, basedir, preserveSymlinks), pkgData);
451
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
452
+ packageCache.set(getRpdCacheKey(pkgName, dir, preserveSymlinks), pkgData);
453
+ });
454
+ }
455
+ function getRpdCacheKey(pkgName, basedir, preserveSymlinks) {
456
+ return `rpd_${pkgName}_${basedir}_${preserveSymlinks}`;
457
+ }
458
+ function getFnpdCache(packageCache, basedir, originalBasedir) {
459
+ const cacheKey = getFnpdCacheKey(basedir);
460
+ const pkgData = packageCache.get(cacheKey);
461
+ if (pkgData) {
462
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
463
+ packageCache.set(getFnpdCacheKey(dir), pkgData);
464
+ });
465
+ return pkgData;
466
+ }
467
+ }
468
+ function setFnpdCache(packageCache, pkgData, basedir, originalBasedir) {
469
+ packageCache.set(getFnpdCacheKey(basedir), pkgData);
470
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
471
+ packageCache.set(getFnpdCacheKey(dir), pkgData);
472
+ });
473
+ }
474
+ function getFnpdCacheKey(basedir) {
475
+ return `fnpd_${basedir}`;
476
+ }
477
+ function traverseBetweenDirs(longerDir, shorterDir, cb) {
478
+ while (longerDir !== shorterDir) {
479
+ cb(longerDir);
480
+ longerDir = _path2.default.dirname(longerDir);
481
+ }
482
+ }
483
+
484
+ // src/plugins/resolve.ts
485
+
486
+
487
+ var _mlly = require('mlly');
488
+ var _resolveexports = require('resolve.exports');
489
+
490
+ // src/external.ts
491
+
492
+ function canExternalizeFile(filePath) {
493
+ const ext = _path2.default.extname(filePath);
494
+ return !ext || ext === ".js" || ext === ".mjs" || ext === ".cjs";
495
+ }
496
+
497
+ // src/plugins/resolve.ts
498
+ var ERR_RESOLVE_PACKAGE_ENTRY_FAIL = "ERR_RESOLVE_PACKAGE_ENTRY_FAIL";
499
+ var browserExternalId = "__vite-browser-external";
500
+ var optionalPeerDepId = "__vite-optional-peer-dep";
501
+ function tryFsResolve(fsPath, options, tryIndex = true, skipPackageJson = false) {
502
+ const hashIndex = fsPath.indexOf("#");
503
+ if (hashIndex >= 0 && isInNodeModules(fsPath)) {
504
+ const queryIndex = fsPath.indexOf("?");
505
+ if (queryIndex < 0 || queryIndex > hashIndex) {
506
+ const file2 = queryIndex > hashIndex ? fsPath.slice(0, queryIndex) : fsPath;
507
+ const res2 = tryCleanFsResolve(file2, options, tryIndex, skipPackageJson);
508
+ if (res2) {
509
+ return res2 + fsPath.slice(file2.length);
510
+ }
511
+ }
512
+ }
513
+ const { file, postfix } = splitFileAndPostfix(fsPath);
514
+ const res = tryCleanFsResolve(file, options, tryIndex, skipPackageJson);
515
+ if (res) {
516
+ return res + postfix;
517
+ }
518
+ }
519
+ var knownTsOutputRE = /\.(?:js|mjs|cjs|jsx)$/;
520
+ var isPossibleTsOutput = (url) => knownTsOutputRE.test(url);
521
+ function tryCleanFsResolve(file, options, tryIndex = true, skipPackageJson = false) {
522
+ const { tryPrefix, extensions, preserveSymlinks } = options;
523
+ const fileResult = tryResolveRealFileOrType(file, options.preserveSymlinks);
524
+ if (_optionalChain([fileResult, 'optionalAccess', _15 => _15.path])) {
525
+ return fileResult.path;
526
+ }
527
+ let res;
528
+ const possibleJsToTs = isPossibleTsOutput(file);
529
+ if (possibleJsToTs || options.extensions.length || tryPrefix) {
530
+ const dirPath = _path2.default.dirname(file);
531
+ if (isDirectory(dirPath)) {
532
+ if (possibleJsToTs) {
533
+ const fileExt = _path2.default.extname(file);
534
+ const fileName = file.slice(0, -fileExt.length);
535
+ if (res = tryResolveRealFile(
536
+ fileName + fileExt.replace("js", "ts"),
537
+ preserveSymlinks
538
+ )) {
539
+ return res;
540
+ }
541
+ if (fileExt === ".js" && (res = tryResolveRealFile(`${fileName}.tsx`, preserveSymlinks))) {
542
+ return res;
543
+ }
544
+ }
545
+ if (res = tryResolveRealFileWithExtensions(
546
+ file,
547
+ extensions,
548
+ preserveSymlinks
549
+ )) {
550
+ return res;
551
+ }
552
+ if (tryPrefix) {
553
+ const prefixed = `${dirPath}/${options.tryPrefix}${_path2.default.basename(file)}`;
554
+ if (res = tryResolveRealFile(prefixed, preserveSymlinks)) {
555
+ return res;
556
+ }
557
+ if (res = tryResolveRealFileWithExtensions(
558
+ prefixed,
559
+ extensions,
560
+ preserveSymlinks
561
+ )) {
562
+ return res;
563
+ }
564
+ }
565
+ }
566
+ }
567
+ if (tryIndex && _optionalChain([fileResult, 'optionalAccess', _16 => _16.type]) === "directory") {
568
+ const dirPath = file;
569
+ if (!skipPackageJson) {
570
+ let pkgPath = `${dirPath}/package.json`;
571
+ try {
572
+ if (_fs2.default.existsSync(pkgPath)) {
573
+ if (!options.preserveSymlinks) {
574
+ pkgPath = safeRealpathSync(pkgPath);
575
+ }
576
+ const pkg = loadPackageData(pkgPath);
577
+ return resolvePackageEntry(dirPath, pkg, options);
578
+ }
579
+ } catch (e) {
580
+ if (e.code !== ERR_RESOLVE_PACKAGE_ENTRY_FAIL && e.code !== "ENOENT") {
581
+ throw e;
582
+ }
583
+ }
584
+ }
585
+ if (res = tryResolveRealFileWithExtensions(
586
+ `${dirPath}/index`,
587
+ extensions,
588
+ preserveSymlinks
589
+ )) {
590
+ return res;
591
+ }
592
+ if (tryPrefix) {
593
+ if (res = tryResolveRealFileWithExtensions(
594
+ `${dirPath}/${options.tryPrefix}index`,
595
+ extensions,
596
+ preserveSymlinks
597
+ )) {
598
+ return res;
599
+ }
600
+ }
601
+ }
602
+ }
603
+ function tryNodeResolve(id, importer, options, depsOptimizer, externalize) {
604
+ const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options;
605
+ const deepMatch = deepImportRE.exec(id);
606
+ const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : cleanUrl(id);
607
+ let basedir;
608
+ if (dedupe.includes(pkgId)) {
609
+ basedir = root;
610
+ } else if (importer && _path2.default.isAbsolute(importer) && (importer.endsWith("*") || _fs2.default.existsSync(cleanUrl(importer)))) {
611
+ basedir = _path2.default.dirname(importer);
612
+ } else {
613
+ basedir = root;
614
+ }
615
+ const isModuleBuiltin = (id2) => isBuiltin(options.builtins, id2);
616
+ let selfPkg = null;
617
+ if (!isModuleBuiltin(id) && !id.includes("\0") && bareImportRE.test(id)) {
618
+ const selfPackageData = findNearestPackageData(basedir, packageCache);
619
+ selfPkg = _optionalChain([selfPackageData, 'optionalAccess', _17 => _17.data, 'access', _18 => _18.exports]) && selfPackageData.data.name === pkgId ? selfPackageData : null;
620
+ }
621
+ const pkg = selfPkg || resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
622
+ if (!pkg) {
623
+ if (basedir !== root && !isModuleBuiltin(id) && !id.includes("\0") && bareImportRE.test(id)) {
624
+ const mainPkg = _optionalChain([findNearestMainPackageData, 'call', _19 => _19(basedir, packageCache), 'optionalAccess', _20 => _20.data]);
625
+ if (mainPkg) {
626
+ const pkgName = getNpmPackageName(id);
627
+ if (pkgName != null && _optionalChain([mainPkg, 'access', _21 => _21.peerDependencies, 'optionalAccess', _22 => _22[pkgName]]) && _optionalChain([mainPkg, 'access', _23 => _23.peerDependenciesMeta, 'optionalAccess', _24 => _24[pkgName], 'optionalAccess', _25 => _25.optional])) {
628
+ return {
629
+ id: `${optionalPeerDepId}:${id}:${mainPkg.name}`
630
+ };
631
+ }
632
+ }
633
+ }
634
+ return;
635
+ }
636
+ const resolveId = deepMatch ? resolveDeepImport : resolvePackageEntry;
637
+ const unresolvedId = deepMatch ? `.${id.slice(pkgId.length)}` : id;
638
+ let resolved = resolveId(unresolvedId, pkg, options);
639
+ if (!resolved) {
640
+ return;
641
+ }
642
+ const processResult = (resolved2) => {
643
+ if (!externalize) {
644
+ return resolved2;
645
+ }
646
+ if (!canExternalizeFile(resolved2.id)) {
647
+ return resolved2;
648
+ }
649
+ let resolvedId = id;
650
+ if (deepMatch && !pkg.data.exports && _path2.default.extname(id) !== _path2.default.extname(resolved2.id)) {
651
+ const index = resolved2.id.indexOf(id);
652
+ if (index > -1) {
653
+ resolvedId = resolved2.id.slice(index);
654
+ }
655
+ }
656
+ return { ...resolved2, id: resolvedId, external: true };
657
+ };
658
+ if (!options.idOnly && (!options.scan && isBuild || externalize)) {
659
+ return processResult({
660
+ id: resolved,
661
+ moduleSideEffects: pkg.hasSideEffects(resolved)
662
+ });
663
+ }
664
+ if (!isInNodeModules(resolved) || !depsOptimizer || options.scan) {
665
+ return { id: resolved };
666
+ }
667
+ const isJsType = isOptimizable(resolved, depsOptimizer.options);
668
+ const exclude = depsOptimizer.options.exclude;
669
+ const skipOptimization = depsOptimizer.options.noDiscovery || !isJsType || importer && isInNodeModules(importer) || _optionalChain([exclude, 'optionalAccess', _26 => _26.includes, 'call', _27 => _27(pkgId)]) || _optionalChain([exclude, 'optionalAccess', _28 => _28.includes, 'call', _29 => _29(id)]) || SPECIAL_QUERY_RE.test(resolved);
670
+ if (skipOptimization) {
671
+ const versionHash = depsOptimizer.metadata.browserHash;
672
+ if (versionHash && isJsType) {
673
+ resolved = injectQuery(resolved, `v=${versionHash}`);
674
+ }
675
+ } else {
676
+ const optimizedInfo = depsOptimizer.registerMissingImport(id, resolved);
677
+ resolved = depsOptimizer.getOptimizedDepId(optimizedInfo);
678
+ }
679
+ return { id: resolved };
680
+ }
681
+ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache }, options) {
682
+ const { postfix } = splitFileAndPostfix(id);
683
+ const cached = getResolvedCache(".", options);
684
+ if (cached) {
685
+ return cached + postfix;
686
+ }
687
+ try {
688
+ let entryPoint;
689
+ if (data.exports) {
690
+ entryPoint = resolveExportsOrImports(data, ".", options, "exports");
691
+ }
692
+ if (!entryPoint) {
693
+ for (const field of options.mainFields) {
694
+ if (field === "browser") {
695
+ entryPoint = tryResolveBrowserEntry(dir, data, options);
696
+ if (entryPoint) {
697
+ break;
698
+ }
699
+ } else if (typeof data[field] === "string") {
700
+ entryPoint = data[field];
701
+ break;
702
+ }
703
+ }
704
+ }
705
+ entryPoint ||= data.main;
706
+ const entryPoints = entryPoint ? [entryPoint] : ["index.js", "index.json", "index.node"];
707
+ for (let entry of entryPoints) {
708
+ let skipPackageJson = false;
709
+ if (options.mainFields[0] === "sass" && !options.extensions.includes(_path2.default.extname(entry))) {
710
+ entry = "";
711
+ skipPackageJson = true;
712
+ } else {
713
+ const { browser: browserField } = data;
714
+ if (options.mainFields.includes("browser") && isObject(browserField)) {
715
+ entry = mapWithBrowserField(entry, browserField) || entry;
716
+ }
717
+ }
718
+ const entryPointPath = _path2.default.join(dir, entry);
719
+ const resolvedEntryPoint = tryFsResolve(
720
+ entryPointPath,
721
+ options,
722
+ true,
723
+ skipPackageJson
724
+ );
725
+ if (resolvedEntryPoint) {
726
+ setResolvedCache(".", resolvedEntryPoint, options);
727
+ return resolvedEntryPoint + postfix;
728
+ }
729
+ }
730
+ } catch (e) {
731
+ packageEntryFailure(
732
+ id,
733
+ // @ts-ignore
734
+ e.message
735
+ );
736
+ }
737
+ packageEntryFailure(id);
738
+ }
739
+ function packageEntryFailure(id, details) {
740
+ const err = new Error(
741
+ `Failed to resolve entry for package "${id}". The package may have incorrect main/module/exports specified in its package.json${details ? `: ${details}` : "."}`
742
+ );
743
+ err.code = ERR_RESOLVE_PACKAGE_ENTRY_FAIL;
744
+ throw err;
745
+ }
746
+ function getConditions(conditions, isProduction, isRequire) {
747
+ const resolvedConditions = conditions.map((condition) => {
748
+ if (condition === DEV_PROD_CONDITION) {
749
+ return isProduction ? "production" : "development";
750
+ }
751
+ return condition;
752
+ });
753
+ if (isRequire) {
754
+ resolvedConditions.push("require");
755
+ } else {
756
+ resolvedConditions.push("import");
757
+ }
758
+ return resolvedConditions;
759
+ }
760
+ function resolveExportsOrImports(pkg, key, options, type) {
761
+ const conditions = getConditions(
762
+ options.conditions,
763
+ options.isProduction,
764
+ options.isRequire
765
+ );
766
+ const fn = type === "imports" ? _resolveexports.imports : _resolveexports.exports;
767
+ const result = fn(pkg, key, { conditions, unsafe: true });
768
+ return result ? result[0] : void 0;
769
+ }
770
+ function resolveDeepImport(id, { setResolvedCache, getResolvedCache, dir, data }, options) {
771
+ const cache = getResolvedCache(id, options);
772
+ if (cache) {
773
+ return cache;
774
+ }
775
+ let relativeId = id;
776
+ const { exports: exportsField, browser: browserField } = data;
777
+ if (exportsField) {
778
+ if (isObject(exportsField) && !Array.isArray(exportsField)) {
779
+ const { file, postfix } = splitFileAndPostfix(relativeId);
780
+ const exportsId = resolveExportsOrImports(data, file, options, "exports");
781
+ if (exportsId !== void 0) {
782
+ relativeId = exportsId + postfix;
783
+ } else {
784
+ relativeId = void 0;
785
+ }
786
+ } else {
787
+ relativeId = void 0;
788
+ }
789
+ if (!relativeId) {
790
+ throw new Error(
791
+ `Package subpath '${relativeId}' is not defined by "exports" in ${_path2.default.join(dir, "package.json")}.`
792
+ );
793
+ }
794
+ } else if (options.mainFields.includes("browser") && isObject(browserField)) {
795
+ const { file, postfix } = splitFileAndPostfix(relativeId);
796
+ const mapped = mapWithBrowserField(file, browserField);
797
+ if (mapped) {
798
+ relativeId = mapped + postfix;
799
+ } else if (mapped === false) {
800
+ setResolvedCache(id, browserExternalId, options);
801
+ return browserExternalId;
802
+ }
803
+ }
804
+ if (relativeId) {
805
+ const resolved = tryFsResolve(
806
+ _path2.default.join(dir, relativeId),
807
+ options,
808
+ !exportsField
809
+ // try index only if no exports field
810
+ );
811
+ if (resolved) {
812
+ setResolvedCache(id, resolved, options);
813
+ return resolved;
814
+ }
815
+ }
816
+ }
817
+ function tryResolveBrowserEntry(dir, data, options) {
818
+ const browserEntry = typeof data.browser === "string" ? data.browser : isObject(data.browser) && data.browser["."];
819
+ if (browserEntry) {
820
+ if (!options.isRequire && options.mainFields.includes("module") && typeof data.module === "string" && data.module !== browserEntry) {
821
+ const resolvedBrowserEntry = tryFsResolve(
822
+ _path2.default.join(dir, browserEntry),
823
+ options
824
+ );
825
+ if (resolvedBrowserEntry) {
826
+ const content = _fs2.default.readFileSync(resolvedBrowserEntry, "utf-8");
827
+ if (_mlly.hasESMSyntax.call(void 0, content)) {
828
+ return browserEntry;
829
+ } else {
830
+ return data.module;
831
+ }
832
+ }
833
+ } else {
834
+ return browserEntry;
835
+ }
836
+ }
837
+ }
838
+ function mapWithBrowserField(relativePathInPkgDir, map) {
839
+ const normalizedPath = _path2.default.posix.normalize(relativePathInPkgDir);
840
+ for (const key in map) {
841
+ const normalizedKey = _path2.default.posix.normalize(key);
842
+ if (normalizedPath === normalizedKey || equalWithoutSuffix(normalizedPath, normalizedKey, ".js") || equalWithoutSuffix(normalizedPath, normalizedKey, "/index.js")) {
843
+ return map[key];
844
+ }
845
+ }
846
+ }
847
+ function equalWithoutSuffix(path7, key, suffix) {
848
+ return key.endsWith(suffix) && key.slice(0, -suffix.length) === path7;
849
+ }
850
+ function tryResolveRealFile(file, preserveSymlinks) {
851
+ const stat = tryStatSync(file);
852
+ if (_optionalChain([stat, 'optionalAccess', _30 => _30.isFile, 'call', _31 => _31()])) {
853
+ return getRealPath(file, preserveSymlinks);
854
+ }
855
+ }
856
+ function tryResolveRealFileWithExtensions(filePath, extensions, preserveSymlinks) {
857
+ for (const ext of extensions) {
858
+ const res = tryResolveRealFile(filePath + ext, preserveSymlinks);
859
+ if (res) {
860
+ return res;
861
+ }
862
+ }
863
+ }
864
+ function tryResolveRealFileOrType(file, preserveSymlinks) {
865
+ const fileStat = tryStatSync(file);
866
+ if (_optionalChain([fileStat, 'optionalAccess', _32 => _32.isFile, 'call', _33 => _33()])) {
867
+ return { path: getRealPath(file, preserveSymlinks), type: "file" };
868
+ }
869
+ if (_optionalChain([fileStat, 'optionalAccess', _34 => _34.isDirectory, 'call', _35 => _35()])) {
870
+ return { type: "directory" };
871
+ }
872
+ }
873
+ function getRealPath(resolved, preserveSymlinks) {
874
+ if (!preserveSymlinks) {
875
+ resolved = safeRealpathSync(resolved);
876
+ }
877
+ return normalizePath(resolved);
878
+ }
879
+ function isDirectory(path7) {
880
+ const stat = tryStatSync(path7);
881
+ return _nullishCoalesce(_optionalChain([stat, 'optionalAccess', _36 => _36.isDirectory, 'call', _37 => _37()]), () => ( false));
882
+ }
883
+
884
+ // src/index.ts
885
+ var promisifiedRealpath = _util.promisify.call(void 0, _fs2.default.realpath);
886
+ var configDefaults = Object.freeze({
887
+ resolve: {
888
+ extensions: [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"]
889
+ }
890
+ });
891
+ var defaultGetOutputFile = (filepath, _format) => {
892
+ return filepath;
893
+ };
894
+ function collectAllModules(bundle, fileName, allModules, analyzedModules = /* @__PURE__ */ new Set()) {
895
+ if (analyzedModules.has(fileName)) {
896
+ return;
897
+ }
898
+ analyzedModules.add(fileName);
899
+ const chunk = bundle[fileName];
900
+ for (const mod of chunk.moduleIds) {
901
+ allModules.add(mod);
902
+ }
903
+ for (const i of chunk.imports) {
904
+ analyzedModules.add(i);
905
+ collectAllModules(bundle, i, allModules, analyzedModules);
906
+ }
907
+ for (const i of chunk.dynamicImports) {
908
+ analyzedModules.add(i);
909
+ collectAllModules(bundle, i, allModules, analyzedModules);
910
+ }
911
+ }
912
+ async function bundleFile(fileName, options) {
913
+ const { isESM } = options;
914
+ const isModuleSyncConditionEnabled = (await Promise.resolve().then(() => _interopRequireWildcard(require(
915
+ // @ts-ignore
916
+ "./false-SI6OY5LO.cjs"
917
+ )))).default;
918
+ const dirnameVarName = "__vite_injected_original_dirname";
919
+ const filenameVarName = "__vite_injected_original_filename";
920
+ const importMetaUrlVarName = "__vite_injected_original_import_meta_url";
921
+ const rolldownOptions = _optionalChain([options, 'optionalAccess', _38 => _38.rolldownOptions]) || {};
922
+ const bundle = await _rolldown.rolldown.call(void 0, {
923
+ ...rolldownOptions,
924
+ input: fileName,
925
+ // target: [`node${process.versions.node}`],
926
+ platform: "node",
927
+ resolve: {
928
+ mainFields: ["main"],
929
+ tsconfigFilename: options.tsconfig
930
+ },
931
+ define: {
932
+ "__dirname": dirnameVarName,
933
+ "__filename": filenameVarName,
934
+ "import.meta.url": importMetaUrlVarName,
935
+ "import.meta.dirname": dirnameVarName,
936
+ "import.meta.filename": filenameVarName
937
+ },
938
+ // disable treeshake to include files that is not sideeffectful to `moduleIds`
939
+ treeshake: false,
940
+ plugins: [
941
+ /* @__PURE__ */ (() => {
942
+ const packageCache = /* @__PURE__ */ new Map();
943
+ const resolveByViteResolver = (id, importer, isRequire) => {
944
+ return _optionalChain([tryNodeResolve, 'call', _39 => _39(id, importer, {
945
+ root: _path2.default.dirname(fileName),
946
+ isBuild: true,
947
+ isProduction: true,
948
+ preferRelative: false,
949
+ tryIndex: true,
950
+ mainFields: [],
951
+ conditions: [
952
+ "node",
953
+ ...isModuleSyncConditionEnabled ? ["module-sync"] : []
954
+ ],
955
+ externalConditions: [],
956
+ external: [],
957
+ noExternal: [],
958
+ dedupe: [],
959
+ extensions: configDefaults.resolve.extensions,
960
+ preserveSymlinks: false,
961
+ packageCache,
962
+ isRequire,
963
+ builtins: nodeLikeBuiltins
964
+ }), 'optionalAccess', _40 => _40.id]);
965
+ };
966
+ return {
967
+ name: "externalize-deps",
968
+ resolveId: {
969
+ filter: { id: /^[^.#].*/ },
970
+ async handler(id, importer, { kind }) {
971
+ if (!importer || _path2.default.isAbsolute(id) || isNodeBuiltin(id)) {
972
+ return;
973
+ }
974
+ if (isNodeLikeBuiltin(id)) {
975
+ return { id, external: true };
976
+ }
977
+ const isImport = isESM || kind === "dynamic-import";
978
+ let idFsPath;
979
+ try {
980
+ idFsPath = resolveByViteResolver(id, importer, !isImport);
981
+ } catch (e) {
982
+ if (!isImport) {
983
+ let canResolveWithImport = false;
984
+ try {
985
+ canResolveWithImport = !!resolveByViteResolver(
986
+ id,
987
+ importer,
988
+ false
989
+ );
990
+ } catch (e9) {
991
+ }
992
+ if (canResolveWithImport) {
993
+ throw new Error(
994
+ `Failed to resolve ${JSON.stringify(
995
+ id
996
+ )}. This package is ESM only but it was tried to load by \`require\`. See https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`
997
+ );
998
+ }
999
+ }
1000
+ throw e;
1001
+ }
1002
+ if (!idFsPath) {
1003
+ return;
1004
+ }
1005
+ if (idFsPath.endsWith(".json")) {
1006
+ return idFsPath;
1007
+ }
1008
+ if (idFsPath && isImport) {
1009
+ idFsPath = _url.pathToFileURL.call(void 0, idFsPath).href;
1010
+ }
1011
+ return { id: idFsPath, external: true };
1012
+ }
1013
+ }
1014
+ };
1015
+ })(),
1016
+ {
1017
+ name: "inject-file-scope-variables",
1018
+ transform: {
1019
+ filter: { id: /\.[cm]?[jt]s$/ },
1020
+ async handler(code, id) {
1021
+ const injectValues = `const ${dirnameVarName} = ${JSON.stringify(_path2.default.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(
1022
+ _url.pathToFileURL.call(void 0, id).href
1023
+ )};`;
1024
+ return { code: injectValues + code, map: null };
1025
+ }
1026
+ }
1027
+ }
1028
+ ],
1029
+ external: options.external
1030
+ // preserveEntrySignatures: 'exports-only'
1031
+ });
1032
+ const result = await bundle.generate({
1033
+ format: options.format,
1034
+ sourcemap: "inline",
1035
+ sourcemapPathTransform(relative) {
1036
+ return _path2.default.resolve(fileName, relative);
1037
+ },
1038
+ // we want to generate a single chunk like esbuild does with `splitting: false`
1039
+ inlineDynamicImports: true
1040
+ });
1041
+ await bundle.close();
1042
+ const entryChunk = result.output.find(
1043
+ (chunk) => chunk.type === "chunk" && chunk.isEntry
1044
+ );
1045
+ const bundleChunks = Object.fromEntries(
1046
+ result.output.flatMap((c) => c.type === "chunk" ? [[c.fileName, c]] : [])
1047
+ );
1048
+ const allModules = /* @__PURE__ */ new Set();
1049
+ collectAllModules(bundleChunks, entryChunk.fileName, allModules);
1050
+ allModules.delete(fileName);
1051
+ return {
1052
+ code: entryChunk.code,
1053
+ dependencies: [...allModules]
1054
+ };
1055
+ }
1056
+ var _require2 = _module.createRequire.call(void 0, _chunkQ6XJHTDBcjs.importMetaUrl);
1057
+ async function loadFromBundledFile(fileName, bundledCode, options) {
1058
+ const { isESM } = options;
1059
+ if (isESM) {
1060
+ let nodeModulesDir = typeof _process2.default.versions.deno === "string" ? void 0 : findNearestNodeModules(_path2.default.dirname(fileName));
1061
+ if (nodeModulesDir) {
1062
+ try {
1063
+ await _promises2.default.mkdir(_path2.default.resolve(nodeModulesDir, ".vite-temp/"), {
1064
+ recursive: true
1065
+ });
1066
+ } catch (e) {
1067
+ if (e.code === "EACCES") {
1068
+ nodeModulesDir = void 0;
1069
+ } else {
1070
+ throw e;
1071
+ }
1072
+ }
1073
+ }
1074
+ const hash2 = `timestamp-${Date.now()}-${Math.random().toString(16).slice(2)}`;
1075
+ const tempFileName = nodeModulesDir ? _path2.default.resolve(
1076
+ nodeModulesDir,
1077
+ `.vite-temp/${_path2.default.basename(fileName)}.${hash2}.${isESM ? "mjs" : "cjs"}`
1078
+ ) : `${fileName}.${hash2}.mjs`;
1079
+ const getOutputFile = options.getOutputFile || defaultGetOutputFile;
1080
+ const outfile = getOutputFile(tempFileName, options.format);
1081
+ await _promises2.default.writeFile(outfile, bundledCode);
1082
+ let mod;
1083
+ const req = options.require || dynamicImport;
1084
+ try {
1085
+ mod = await req(
1086
+ options.format === "esm" ? _url.pathToFileURL.call(void 0, outfile).href : outfile,
1087
+ { format: options.format }
1088
+ );
1089
+ return mod;
1090
+ } finally {
1091
+ if (!_optionalChain([options, 'optionalAccess', _41 => _41.preserveTemporaryFile])) {
1092
+ _fs2.default.unlink(outfile, () => {
1093
+ });
1094
+ }
1095
+ }
1096
+ } else {
1097
+ const extension = _path2.default.extname(fileName);
1098
+ const realFileName = await promisifiedRealpath(fileName);
1099
+ const loaderExt = extension in _require2.extensions ? extension : ".js";
1100
+ const defaultLoader = _require2.extensions[loaderExt];
1101
+ _require2.extensions[loaderExt] = (module, filename) => {
1102
+ if (filename === realFileName) {
1103
+ ;
1104
+ module._compile(bundledCode, filename);
1105
+ } else {
1106
+ defaultLoader(module, filename);
1107
+ }
1108
+ };
1109
+ delete _require2.cache[_require2.resolve(fileName)];
1110
+ const raw = _require2(fileName);
1111
+ _require2.extensions[loaderExt] = defaultLoader;
1112
+ return raw.__esModule ? raw.default : raw;
1113
+ }
1114
+ }
1115
+ async function bundleRequire(options) {
1116
+ const resolvedPath = _path2.default.isAbsolute(options.filepath) ? options.filepath : _path2.default.resolve(options.cwd || _process2.default.cwd(), options.filepath);
1117
+ const isESM = typeof _process2.default.versions.deno === "string" || isFilePathESM(resolvedPath);
1118
+ if (options.tsconfig !== false) {
1119
+ options.tsconfig = _nullishCoalesce(_nullishCoalesce(options.tsconfig, () => ( _optionalChain([_gettsconfig.getTsconfig.call(void 0, options.cwd, "tsconfig.json"), 'optionalAccess', _42 => _42.path]))), () => ( void 0));
1120
+ } else {
1121
+ options.tsconfig = void 0;
1122
+ }
1123
+ if (!options.format) {
1124
+ options.format = isESM ? "esm" : "cjs";
1125
+ }
1126
+ const internalOptions = {
1127
+ ...options,
1128
+ isESM,
1129
+ format: options.format,
1130
+ tsconfig: options.tsconfig
1131
+ };
1132
+ const bundled = await bundleFile(
1133
+ resolvedPath,
1134
+ internalOptions
1135
+ );
1136
+ const mod = await loadFromBundledFile(
1137
+ resolvedPath,
1138
+ bundled.code,
1139
+ internalOptions
1140
+ );
1141
+ return {
1142
+ mod,
1143
+ dependencies: bundled.dependencies
1144
+ };
1145
+ }
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+ exports.bundleFile = bundleFile; exports.bundleRequire = bundleRequire; exports.configDefaults = configDefaults; exports.loadFromBundledFile = loadFromBundledFile;