nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-121649-98b56dfe
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/_build/common.mjs +763 -0
- package/dist/_build/rolldown.mjs +216 -0
- package/dist/_build/rollup.mjs +359 -0
- package/dist/_build/vite.build.mjs +67 -0
- package/dist/_build/vite.plugin.mjs +747 -0
- package/dist/_chunks/B-7HiF0V.mjs +1303 -0
- package/dist/_chunks/B3asVbT4.mjs +151 -0
- package/dist/_chunks/B5ooyfLk.mjs +372 -0
- package/dist/_chunks/DXMHy5ca.mjs +43 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +675 -0
- package/dist/_libs/acorn.mjs +5034 -0
- package/dist/_libs/c12.mjs +2798 -0
- package/dist/_libs/chokidar.mjs +1560 -0
- package/dist/_libs/citty.mjs +333 -0
- package/dist/_libs/commondir.mjs +22 -0
- package/dist/_libs/compatx.mjs +46 -0
- package/dist/_libs/confbox.mjs +2920 -0
- package/dist/_libs/debug.mjs +848 -0
- package/dist/_libs/deepmerge.mjs +86 -0
- package/dist/_libs/depd.mjs +314 -0
- package/dist/_libs/dot-prop.mjs +138 -0
- package/dist/_libs/duplexer.mjs +71 -0
- package/dist/_libs/ee-first.mjs +68 -0
- package/dist/_libs/encodeurl.mjs +49 -0
- package/dist/_libs/escape-html.mjs +58 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +330 -0
- package/dist/_libs/etag.mjs +75 -0
- package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
- package/dist/_libs/fresh.mjs +85 -0
- package/dist/_libs/function-bind.mjs +63 -0
- package/dist/_libs/gen-mapping.mjs +612 -0
- package/dist/_libs/giget.mjs +19076 -0
- package/dist/_libs/gzip-size.mjs +21 -0
- package/dist/_libs/hasown.mjs +14 -0
- package/dist/_libs/http-errors.mjs +436 -0
- package/dist/_libs/httpxy.mjs +410 -0
- package/dist/_libs/is-core-module.mjs +220 -0
- package/dist/_libs/is-module.mjs +13 -0
- package/dist/_libs/is-reference.mjs +32 -0
- package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
- package/dist/_libs/klona.mjs +90 -0
- package/dist/_libs/knitwork.mjs +124 -0
- package/dist/_libs/local-pkg.mjs +1686 -0
- package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
- package/dist/_libs/mime-db.mjs +7642 -0
- package/dist/_libs/mime-types.mjs +162 -0
- package/dist/_libs/mime.mjs +1391 -0
- package/dist/_libs/node-fetch-native.mjs +173 -0
- package/dist/_libs/on-finished.mjs +170 -0
- package/dist/_libs/parseurl.mjs +103 -0
- package/dist/_libs/path-parse.mjs +47 -0
- package/dist/_libs/pathe.mjs +41 -0
- package/dist/_libs/picomatch.mjs +1673 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-commonjs.mjs +1489 -0
- package/dist/_libs/plugin-inject.mjs +135 -0
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/plugin-node-resolve.mjs +1553 -0
- package/dist/_libs/plugin-replace.mjs +104 -0
- package/dist/_libs/pretty-bytes.mjs +116 -0
- package/dist/_libs/range-parser.mjs +102 -0
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
- package/dist/_libs/send.mjs +857 -0
- package/dist/_libs/serve-static.mjs +124 -0
- package/dist/_libs/std-env.mjs +158 -0
- package/dist/_libs/strip-literal.mjs +51 -0
- package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/unimport.mjs +3520 -0
- package/dist/_libs/untyped.mjs +271 -0
- package/dist/_libs/unwasm.mjs +5825 -0
- package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
- package/dist/_presets.mjs +1723 -0
- package/dist/builder.d.mts +37 -35
- package/dist/builder.mjs +45 -117
- package/dist/cli/_chunks/build.mjs +43 -0
- package/dist/cli/_chunks/common.mjs +15 -0
- package/dist/cli/_chunks/detect-acorn.mjs +12 -0
- package/dist/cli/_chunks/dev.mjs +79 -0
- package/dist/cli/_chunks/dist.mjs +3 -0
- package/dist/cli/_chunks/dist2.mjs +4 -0
- package/dist/cli/_chunks/esm.mjs +3 -0
- package/dist/cli/_chunks/json5.mjs +4 -0
- package/dist/cli/_chunks/jsonc.mjs +4 -0
- package/dist/cli/_chunks/list.mjs +27 -0
- package/dist/cli/_chunks/multipart-parser.mjs +6 -0
- package/dist/cli/_chunks/prepare.mjs +19 -0
- package/dist/cli/_chunks/run.mjs +55 -0
- package/dist/cli/_chunks/task.mjs +16 -0
- package/dist/cli/_chunks/toml.mjs +4 -0
- package/dist/cli/_chunks/yaml.mjs +4 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +19 -18
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
- package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
- package/dist/presets/azure/runtime/_utils.mjs +43 -43
- package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
- package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
- package/dist/presets/bun/runtime/bun.d.mts +1 -0
- package/dist/presets/bun/runtime/bun.mjs +18 -17
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
- package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
- package/dist/presets/deno/runtime/deno-server.mjs +31 -39
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
- package/dist/presets/netlify/runtime/netlify.mjs +11 -17
- package/dist/presets/node/runtime/node-cluster.mjs +49 -48
- package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
- package/dist/presets/node/runtime/node-middleware.mjs +7 -6
- package/dist/presets/node/runtime/node-server.mjs +33 -23
- package/dist/presets/standard/runtime/server.d.mts +1 -3
- package/dist/presets/standard/runtime/server.mjs +1 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
- package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
- package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
- package/dist/presets/vercel/runtime/vercel.mjs +15 -14
- package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/runtime/index.d.mts +12 -1
- package/dist/runtime/index.mjs +12 -7
- package/dist/runtime/internal/app.mjs +175 -162
- package/dist/runtime/internal/cache.d.mts +10 -4
- package/dist/runtime/internal/cache.mjs +247 -216
- package/dist/runtime/internal/context.d.mts +9 -9
- package/dist/runtime/internal/context.mjs +17 -10
- package/dist/runtime/internal/database.mjs +8 -10
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +106 -105
- package/dist/runtime/internal/error/prod.d.mts +2 -2
- package/dist/runtime/internal/error/prod.mjs +48 -52
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/error/utils.mjs +1 -1
- package/dist/runtime/internal/index.d.mts +2 -0
- package/dist/runtime/internal/index.mjs +2 -0
- package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
- package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/meta.mjs +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/plugin.mjs +1 -1
- package/dist/runtime/internal/renderer.mjs +39 -31
- package/dist/runtime/internal/route-rules.d.mts +8 -8
- package/dist/runtime/internal/route-rules.mjs +53 -51
- package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
- package/dist/runtime/internal/routes/openapi.d.mts +1 -0
- package/dist/runtime/internal/routes/openapi.mjs +81 -87
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +1 -0
- package/dist/runtime/internal/routes/scalar.mjs +22 -23
- package/dist/runtime/internal/routes/swagger.d.mts +1 -0
- package/dist/runtime/internal/routes/swagger.mjs +9 -11
- package/dist/runtime/internal/runtime-config.d.mts +4 -4
- package/dist/runtime/internal/runtime-config.mjs +40 -35
- package/dist/runtime/internal/shutdown.d.mts +2 -7
- package/dist/runtime/internal/shutdown.mjs +30 -29
- package/dist/runtime/internal/static.mjs +63 -74
- package/dist/runtime/internal/storage.mjs +2 -2
- package/dist/runtime/internal/task.d.mts +6 -6
- package/dist/runtime/internal/task.mjs +56 -59
- package/dist/runtime/internal/utils.d.mts +1 -1
- package/dist/runtime/internal/utils.mjs +4 -10
- package/dist/types/index.d.mts +2566 -3851
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +56 -52
- package/dist/vite.mjs +55 -132
- package/package.json +10 -10
- package/dist/_build/build.mjs +0 -368
- package/dist/_build/build2.mjs +0 -556
- package/dist/_build/info.mjs +0 -1002
- package/dist/_build/prepare.mjs +0 -1511
- package/dist/_build/snapshot.mjs +0 -185
- package/dist/_build/vite.mjs +0 -959
- package/dist/_build/vite2.mjs +0 -149
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
- package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
- package/dist/_chunks/_deps/acorn.mjs +0 -6225
- package/dist/_chunks/_deps/c12.mjs +0 -510
- package/dist/_chunks/_deps/chokidar.mjs +0 -1428
- package/dist/_chunks/_deps/citty.mjs +0 -460
- package/dist/_chunks/_deps/commondir.mjs +0 -77
- package/dist/_chunks/_deps/compatx.mjs +0 -76
- package/dist/_chunks/_deps/confbox.mjs +0 -300
- package/dist/_chunks/_deps/debug.mjs +0 -885
- package/dist/_chunks/_deps/deepmerge.mjs +0 -147
- package/dist/_chunks/_deps/depd.mjs +0 -550
- package/dist/_chunks/_deps/dot-prop.mjs +0 -282
- package/dist/_chunks/_deps/dotenv.mjs +0 -555
- package/dist/_chunks/_deps/duplexer.mjs +0 -1
- package/dist/_chunks/_deps/ee-first.mjs +0 -104
- package/dist/_chunks/_deps/encodeurl.mjs +0 -69
- package/dist/_chunks/_deps/escape-html.mjs +0 -87
- package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
- package/dist/_chunks/_deps/estree-walker.mjs +0 -433
- package/dist/_chunks/_deps/etag.mjs +0 -147
- package/dist/_chunks/_deps/exsolve.mjs +0 -1416
- package/dist/_chunks/_deps/fresh.mjs +0 -145
- package/dist/_chunks/_deps/function-bind.mjs +0 -106
- package/dist/_chunks/_deps/giget.mjs +0 -451
- package/dist/_chunks/_deps/gzip-size.mjs +0 -19
- package/dist/_chunks/_deps/hasown.mjs +0 -19
- package/dist/_chunks/_deps/http-errors.mjs +0 -307
- package/dist/_chunks/_deps/httpxy.mjs +0 -580
- package/dist/_chunks/_deps/inherits.mjs +0 -57
- package/dist/_chunks/_deps/is-core-module.mjs +0 -596
- package/dist/_chunks/_deps/is-module.mjs +0 -25
- package/dist/_chunks/_deps/is-reference.mjs +0 -31
- package/dist/_chunks/_deps/klona.mjs +0 -137
- package/dist/_chunks/_deps/knitwork.mjs +0 -172
- package/dist/_chunks/_deps/local-pkg.mjs +0 -163
- package/dist/_chunks/_deps/mime-db.mjs +0 -11685
- package/dist/_chunks/_deps/mime-types.mjs +0 -287
- package/dist/_chunks/_deps/mime.mjs +0 -1172
- package/dist/_chunks/_deps/mlly.mjs +0 -2413
- package/dist/_chunks/_deps/ms.mjs +0 -172
- package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
- package/dist/_chunks/_deps/nypm.mjs +0 -219
- package/dist/_chunks/_deps/on-finished.mjs +0 -246
- package/dist/_chunks/_deps/parseurl.mjs +0 -168
- package/dist/_chunks/_deps/path-parse.mjs +0 -85
- package/dist/_chunks/_deps/pathe.mjs +0 -251
- package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
- package/dist/_chunks/_deps/picomatch.mjs +0 -2144
- package/dist/_chunks/_deps/pkg-types.mjs +0 -247
- package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
- package/dist/_chunks/_deps/quansync.mjs +0 -99
- package/dist/_chunks/_deps/range-parser.mjs +0 -171
- package/dist/_chunks/_deps/rc9.mjs +0 -219
- package/dist/_chunks/_deps/readdirp.mjs +0 -245
- package/dist/_chunks/_deps/resolve.mjs +0 -1260
- package/dist/_chunks/_deps/send.mjs +0 -1022
- package/dist/_chunks/_deps/serve-static.mjs +0 -228
- package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
- package/dist/_chunks/_deps/statuses.mjs +0 -457
- package/dist/_chunks/_deps/std-env.mjs +0 -3
- package/dist/_chunks/_deps/strip-literal.mjs +0 -67
- package/dist/_chunks/_deps/supports-color.mjs +0 -44
- package/dist/_chunks/_deps/tinyexec.mjs +0 -552
- package/dist/_chunks/_deps/toidentifier.mjs +0 -41
- package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
- package/dist/_chunks/_deps/unimport.mjs +0 -2267
- package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
- package/dist/_chunks/_deps/unplugin.mjs +0 -1294
- package/dist/_chunks/_deps/untyped.mjs +0 -375
- package/dist/_chunks/_deps/unwasm.mjs +0 -6959
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
- package/dist/_chunks/_presets/_all.mjs +0 -59
- package/dist/_chunks/_presets/_nitro.mjs +0 -74
- package/dist/_chunks/_presets/_resolve.mjs +0 -64
- package/dist/_chunks/_presets/_static.mjs +0 -69
- package/dist/_chunks/_presets/_types.mjs +0 -3
- package/dist/_chunks/_presets/_utils.mjs +0 -31
- package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
- package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
- package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
- package/dist/_chunks/_presets/azure.mjs +0 -162
- package/dist/_chunks/_presets/bun.mjs +0 -19
- package/dist/_chunks/_presets/cleavr.mjs +0 -15
- package/dist/_chunks/_presets/cloudflare.mjs +0 -608
- package/dist/_chunks/_presets/deno.mjs +0 -196
- package/dist/_chunks/_presets/digitalocean.mjs +0 -14
- package/dist/_chunks/_presets/firebase.mjs +0 -47
- package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
- package/dist/_chunks/_presets/genezio.mjs +0 -13
- package/dist/_chunks/_presets/heroku.mjs +0 -14
- package/dist/_chunks/_presets/iis.mjs +0 -194
- package/dist/_chunks/_presets/index.mjs +0 -62
- package/dist/_chunks/_presets/koyeb.mjs +0 -14
- package/dist/_chunks/_presets/netlify.mjs +0 -241
- package/dist/_chunks/_presets/node.mjs +0 -54
- package/dist/_chunks/_presets/platform.mjs +0 -14
- package/dist/_chunks/_presets/render.mjs +0 -14
- package/dist/_chunks/_presets/standard.mjs +0 -23
- package/dist/_chunks/_presets/stormkit.mjs +0 -18
- package/dist/_chunks/_presets/vercel.mjs +0 -375
- package/dist/_chunks/_presets/winterjs.mjs +0 -22
- package/dist/_chunks/_presets/zeabur.mjs +0 -69
- package/dist/_chunks/_presets/zerops.mjs +0 -27
- package/dist/_chunks/app.mjs +0 -600
- package/dist/_chunks/builder.mjs +0 -648
- package/dist/_chunks/server.mjs +0 -256
- package/dist/_cli/build.mjs +0 -49
- package/dist/_cli/common.mjs +0 -13
- package/dist/_cli/dev.mjs +0 -121
- package/dist/_cli/index.mjs +0 -16
- package/dist/_cli/list.mjs +0 -33
- package/dist/_cli/prepare.mjs +0 -23
- package/dist/_cli/run.mjs +0 -59
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
- package/dist/runtime/internal/empty.d.mts +0 -0
- package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
- package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
- package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
- /package/lib/{indexd.mts → index.d.mts} +0 -0
|
@@ -0,0 +1,1489 @@
|
|
|
1
|
+
import { s as __toESM } from "../_chunks/DXMHy5ca.mjs";
|
|
2
|
+
import { t as MagicString } from "./magic-string.mjs";
|
|
3
|
+
import { t as require_picomatch } from "./picomatch.mjs";
|
|
4
|
+
import { t as Builder } from "./fdir.mjs";
|
|
5
|
+
import { n as walk } from "./estree-walker.mjs";
|
|
6
|
+
import { t as require_commondir } from "./commondir.mjs";
|
|
7
|
+
import { t as require_is_reference } from "./is-reference.mjs";
|
|
8
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
9
|
+
import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "path";
|
|
10
|
+
|
|
11
|
+
//#region node_modules/.pnpm/@rollup+pluginutils@5.3.0_rollup@4.52.5/node_modules/@rollup/pluginutils/dist/es/index.js
|
|
12
|
+
var import_picomatch = /* @__PURE__ */ __toESM(require_picomatch(), 1);
|
|
13
|
+
const extractors = {
|
|
14
|
+
ArrayPattern(names, param) {
|
|
15
|
+
for (const element of param.elements) if (element) extractors[element.type](names, element);
|
|
16
|
+
},
|
|
17
|
+
AssignmentPattern(names, param) {
|
|
18
|
+
extractors[param.left.type](names, param.left);
|
|
19
|
+
},
|
|
20
|
+
Identifier(names, param) {
|
|
21
|
+
names.push(param.name);
|
|
22
|
+
},
|
|
23
|
+
MemberExpression() {},
|
|
24
|
+
ObjectPattern(names, param) {
|
|
25
|
+
for (const prop of param.properties) if (prop.type === "RestElement") extractors.RestElement(names, prop);
|
|
26
|
+
else extractors[prop.value.type](names, prop.value);
|
|
27
|
+
},
|
|
28
|
+
RestElement(names, param) {
|
|
29
|
+
extractors[param.argument.type](names, param.argument);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const extractAssignedNames = function extractAssignedNames$1(param) {
|
|
33
|
+
const names = [];
|
|
34
|
+
extractors[param.type](names, param);
|
|
35
|
+
return names;
|
|
36
|
+
};
|
|
37
|
+
const blockDeclarations = {
|
|
38
|
+
const: true,
|
|
39
|
+
let: true
|
|
40
|
+
};
|
|
41
|
+
var Scope = class {
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.parent = options.parent;
|
|
44
|
+
this.isBlockScope = !!options.block;
|
|
45
|
+
this.declarations = Object.create(null);
|
|
46
|
+
if (options.params) options.params.forEach((param) => {
|
|
47
|
+
extractAssignedNames(param).forEach((name) => {
|
|
48
|
+
this.declarations[name] = true;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
addDeclaration(node, isBlockDeclaration, isVar) {
|
|
53
|
+
if (!isBlockDeclaration && this.isBlockScope) this.parent.addDeclaration(node, isBlockDeclaration, isVar);
|
|
54
|
+
else if (node.id) extractAssignedNames(node.id).forEach((name) => {
|
|
55
|
+
this.declarations[name] = true;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
contains(name) {
|
|
59
|
+
return this.declarations[name] || (this.parent ? this.parent.contains(name) : false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const attachScopes = function attachScopes$1(ast, propertyName = "scope") {
|
|
63
|
+
let scope = new Scope();
|
|
64
|
+
walk(ast, {
|
|
65
|
+
enter(n, parent) {
|
|
66
|
+
const node = n;
|
|
67
|
+
if (/(?:Function|Class)Declaration/.test(node.type)) scope.addDeclaration(node, false, false);
|
|
68
|
+
if (node.type === "VariableDeclaration") {
|
|
69
|
+
const { kind } = node;
|
|
70
|
+
const isBlockDeclaration = blockDeclarations[kind];
|
|
71
|
+
node.declarations.forEach((declaration) => {
|
|
72
|
+
scope.addDeclaration(declaration, isBlockDeclaration, true);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
let newScope;
|
|
76
|
+
if (node.type.includes("Function")) {
|
|
77
|
+
const func = node;
|
|
78
|
+
newScope = new Scope({
|
|
79
|
+
parent: scope,
|
|
80
|
+
block: false,
|
|
81
|
+
params: func.params
|
|
82
|
+
});
|
|
83
|
+
if (func.type === "FunctionExpression" && func.id) newScope.addDeclaration(func, false, false);
|
|
84
|
+
}
|
|
85
|
+
if (/For(?:In|Of)?Statement/.test(node.type)) newScope = new Scope({
|
|
86
|
+
parent: scope,
|
|
87
|
+
block: true
|
|
88
|
+
});
|
|
89
|
+
if (node.type === "BlockStatement" && !parent.type.includes("Function")) newScope = new Scope({
|
|
90
|
+
parent: scope,
|
|
91
|
+
block: true
|
|
92
|
+
});
|
|
93
|
+
if (node.type === "CatchClause") newScope = new Scope({
|
|
94
|
+
parent: scope,
|
|
95
|
+
params: node.param ? [node.param] : [],
|
|
96
|
+
block: true
|
|
97
|
+
});
|
|
98
|
+
if (newScope) {
|
|
99
|
+
Object.defineProperty(node, propertyName, {
|
|
100
|
+
value: newScope,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
scope = newScope;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
leave(n) {
|
|
107
|
+
if (n[propertyName]) scope = scope.parent;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return scope;
|
|
111
|
+
};
|
|
112
|
+
function isArray(arg) {
|
|
113
|
+
return Array.isArray(arg);
|
|
114
|
+
}
|
|
115
|
+
function ensureArray(thing) {
|
|
116
|
+
if (isArray(thing)) return thing;
|
|
117
|
+
if (thing == null) return [];
|
|
118
|
+
return [thing];
|
|
119
|
+
}
|
|
120
|
+
const normalizePathRegExp = new RegExp(`\\${win32.sep}`, "g");
|
|
121
|
+
const normalizePath = function normalizePath$1(filename) {
|
|
122
|
+
return filename.replace(normalizePathRegExp, posix.sep);
|
|
123
|
+
};
|
|
124
|
+
function getMatcherString(id, resolutionBase) {
|
|
125
|
+
if (resolutionBase === false || isAbsolute(id) || id.startsWith("**")) return normalizePath(id);
|
|
126
|
+
const basePath = normalizePath(resolve(resolutionBase || "")).replace(/[-^$*+?.()|[\]{}]/g, "\\$&");
|
|
127
|
+
return posix.join(basePath, normalizePath(id));
|
|
128
|
+
}
|
|
129
|
+
const createFilter = function createFilter$1(include, exclude, options) {
|
|
130
|
+
const resolutionBase = options && options.resolve;
|
|
131
|
+
const getMatcher = (id) => id instanceof RegExp ? id : { test: (what) => {
|
|
132
|
+
return (0, import_picomatch.default)(getMatcherString(id, resolutionBase), { dot: true })(what);
|
|
133
|
+
} };
|
|
134
|
+
const includeMatchers = ensureArray(include).map(getMatcher);
|
|
135
|
+
const excludeMatchers = ensureArray(exclude).map(getMatcher);
|
|
136
|
+
if (!includeMatchers.length && !excludeMatchers.length) return (id) => typeof id === "string" && !id.includes("\0");
|
|
137
|
+
return function result(id) {
|
|
138
|
+
if (typeof id !== "string") return false;
|
|
139
|
+
if (id.includes("\0")) return false;
|
|
140
|
+
const pathId = normalizePath(id);
|
|
141
|
+
for (let i = 0; i < excludeMatchers.length; ++i) {
|
|
142
|
+
const matcher = excludeMatchers[i];
|
|
143
|
+
if (matcher instanceof RegExp) matcher.lastIndex = 0;
|
|
144
|
+
if (matcher.test(pathId)) return false;
|
|
145
|
+
}
|
|
146
|
+
for (let i = 0; i < includeMatchers.length; ++i) {
|
|
147
|
+
const matcher = includeMatchers[i];
|
|
148
|
+
if (matcher instanceof RegExp) matcher.lastIndex = 0;
|
|
149
|
+
if (matcher.test(pathId)) return true;
|
|
150
|
+
}
|
|
151
|
+
return !includeMatchers.length;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
const forbiddenIdentifiers = new Set(`break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl`.split(" "));
|
|
155
|
+
forbiddenIdentifiers.add("");
|
|
156
|
+
const makeLegalIdentifier = function makeLegalIdentifier$1(str) {
|
|
157
|
+
let identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, "_");
|
|
158
|
+
if (/\d/.test(identifier[0]) || forbiddenIdentifiers.has(identifier)) identifier = `_${identifier}`;
|
|
159
|
+
return identifier || "_";
|
|
160
|
+
};
|
|
161
|
+
function stringify(obj) {
|
|
162
|
+
return (JSON.stringify(obj) || "undefined").replace(/[\u2028\u2029]/g, (char) => `\\u${`000${char.charCodeAt(0).toString(16)}`.slice(-4)}`);
|
|
163
|
+
}
|
|
164
|
+
function serializeArray(arr, indent, baseIndent) {
|
|
165
|
+
let output = "[";
|
|
166
|
+
const separator = indent ? `\n${baseIndent}${indent}` : "";
|
|
167
|
+
for (let i = 0; i < arr.length; i++) {
|
|
168
|
+
const key = arr[i];
|
|
169
|
+
output += `${i > 0 ? "," : ""}${separator}${serialize(key, indent, baseIndent + indent)}`;
|
|
170
|
+
}
|
|
171
|
+
return `${output}${indent ? `\n${baseIndent}` : ""}]`;
|
|
172
|
+
}
|
|
173
|
+
function serializeObject(obj, indent, baseIndent) {
|
|
174
|
+
let output = "{";
|
|
175
|
+
const separator = indent ? `\n${baseIndent}${indent}` : "";
|
|
176
|
+
const entries = Object.entries(obj);
|
|
177
|
+
for (let i = 0; i < entries.length; i++) {
|
|
178
|
+
const [key, value] = entries[i];
|
|
179
|
+
const stringKey = makeLegalIdentifier(key) === key ? key : stringify(key);
|
|
180
|
+
output += `${i > 0 ? "," : ""}${separator}${stringKey}:${indent ? " " : ""}${serialize(value, indent, baseIndent + indent)}`;
|
|
181
|
+
}
|
|
182
|
+
return `${output}${indent ? `\n${baseIndent}` : ""}}`;
|
|
183
|
+
}
|
|
184
|
+
function serialize(obj, indent, baseIndent) {
|
|
185
|
+
if (typeof obj === "object" && obj !== null) {
|
|
186
|
+
if (Array.isArray(obj)) return serializeArray(obj, indent, baseIndent);
|
|
187
|
+
if (obj instanceof Date) return `new Date(${obj.getTime()})`;
|
|
188
|
+
if (obj instanceof RegExp) return obj.toString();
|
|
189
|
+
return serializeObject(obj, indent, baseIndent);
|
|
190
|
+
}
|
|
191
|
+
if (typeof obj === "number") {
|
|
192
|
+
if (obj === Infinity) return "Infinity";
|
|
193
|
+
if (obj === -Infinity) return "-Infinity";
|
|
194
|
+
if (obj === 0) return 1 / obj === Infinity ? "0" : "-0";
|
|
195
|
+
if (obj !== obj) return "NaN";
|
|
196
|
+
}
|
|
197
|
+
if (typeof obj === "symbol") {
|
|
198
|
+
const key = Symbol.keyFor(obj);
|
|
199
|
+
if (key !== void 0) return `Symbol.for(${stringify(key)})`;
|
|
200
|
+
}
|
|
201
|
+
if (typeof obj === "bigint") return `${obj}n`;
|
|
202
|
+
return stringify(obj);
|
|
203
|
+
}
|
|
204
|
+
const hasStringIsWellFormed = "isWellFormed" in String.prototype;
|
|
205
|
+
function isWellFormedString(input) {
|
|
206
|
+
if (hasStringIsWellFormed) return input.isWellFormed();
|
|
207
|
+
return !/\p{Surrogate}/u.test(input);
|
|
208
|
+
}
|
|
209
|
+
const dataToEsm = function dataToEsm$1(data, options = {}) {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
const t = options.compact ? "" : "indent" in options ? options.indent : " ";
|
|
212
|
+
const _ = options.compact ? "" : " ";
|
|
213
|
+
const n = options.compact ? "" : "\n";
|
|
214
|
+
const declarationType = options.preferConst ? "const" : "var";
|
|
215
|
+
if (options.namedExports === false || typeof data !== "object" || Array.isArray(data) || data instanceof Date || data instanceof RegExp || data === null) {
|
|
216
|
+
const code = serialize(data, options.compact ? null : t, "");
|
|
217
|
+
return `export default${_ || (/^[{[\-\/]/.test(code) ? "" : " ")}${code};`;
|
|
218
|
+
}
|
|
219
|
+
let maxUnderbarPrefixLength = 0;
|
|
220
|
+
for (const key of Object.keys(data)) {
|
|
221
|
+
const underbarPrefixLength = (_b = (_a = /^(_+)/.exec(key)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
222
|
+
if (underbarPrefixLength > maxUnderbarPrefixLength) maxUnderbarPrefixLength = underbarPrefixLength;
|
|
223
|
+
}
|
|
224
|
+
const arbitraryNamePrefix = `${"_".repeat(maxUnderbarPrefixLength + 1)}arbitrary`;
|
|
225
|
+
let namedExportCode = "";
|
|
226
|
+
const defaultExportRows = [];
|
|
227
|
+
const arbitraryNameExportRows = [];
|
|
228
|
+
for (const [key, value] of Object.entries(data)) if (key === makeLegalIdentifier(key)) {
|
|
229
|
+
if (options.objectShorthand) defaultExportRows.push(key);
|
|
230
|
+
else defaultExportRows.push(`${key}:${_}${key}`);
|
|
231
|
+
namedExportCode += `export ${declarationType} ${key}${_}=${_}${serialize(value, options.compact ? null : t, "")};${n}`;
|
|
232
|
+
} else {
|
|
233
|
+
defaultExportRows.push(`${stringify(key)}:${_}${serialize(value, options.compact ? null : t, "")}`);
|
|
234
|
+
if (options.includeArbitraryNames && isWellFormedString(key)) {
|
|
235
|
+
const variableName = `${arbitraryNamePrefix}${arbitraryNameExportRows.length}`;
|
|
236
|
+
namedExportCode += `${declarationType} ${variableName}${_}=${_}${serialize(value, options.compact ? null : t, "")};${n}`;
|
|
237
|
+
arbitraryNameExportRows.push(`${variableName} as ${JSON.stringify(key)}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const arbitraryExportCode = arbitraryNameExportRows.length > 0 ? `export${_}{${n}${t}${arbitraryNameExportRows.join(`,${n}${t}`)}${n}};${n}` : "";
|
|
241
|
+
const defaultExportCode = `export default${_}{${n}${t}${defaultExportRows.join(`,${n}${t}`)}${n}};${n}`;
|
|
242
|
+
return `${namedExportCode}${arbitraryExportCode}${defaultExportCode}`;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region node_modules/.pnpm/@rollup+plugin-commonjs@28.0.9_rollup@4.52.5/node_modules/@rollup/plugin-commonjs/dist/es/index.js
|
|
247
|
+
var import_commondir = /* @__PURE__ */ __toESM(require_commondir(), 1);
|
|
248
|
+
var import_is_reference = /* @__PURE__ */ __toESM(require_is_reference(), 1);
|
|
249
|
+
var version = "28.0.9";
|
|
250
|
+
var peerDependencies = { rollup: "^2.68.0||^3.0.0||^4.0.0" };
|
|
251
|
+
function tryParse(parse, code, id) {
|
|
252
|
+
try {
|
|
253
|
+
return parse(code, { allowReturnOutsideFunction: true });
|
|
254
|
+
} catch (err) {
|
|
255
|
+
err.message += ` in ${id}`;
|
|
256
|
+
throw err;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const firstpassGlobal = /\b(?:require|module|exports|global)\b/;
|
|
260
|
+
const firstpassNoGlobal = /\b(?:require|module|exports)\b/;
|
|
261
|
+
function hasCjsKeywords(code, ignoreGlobal) {
|
|
262
|
+
return (ignoreGlobal ? firstpassNoGlobal : firstpassGlobal).test(code);
|
|
263
|
+
}
|
|
264
|
+
function analyzeTopLevelStatements(parse, code, id) {
|
|
265
|
+
const ast = tryParse(parse, code, id);
|
|
266
|
+
let isEsModule = false;
|
|
267
|
+
let hasDefaultExport = false;
|
|
268
|
+
let hasNamedExports = false;
|
|
269
|
+
for (const node of ast.body) switch (node.type) {
|
|
270
|
+
case "ExportDefaultDeclaration":
|
|
271
|
+
isEsModule = true;
|
|
272
|
+
hasDefaultExport = true;
|
|
273
|
+
break;
|
|
274
|
+
case "ExportNamedDeclaration":
|
|
275
|
+
isEsModule = true;
|
|
276
|
+
if (node.declaration) hasNamedExports = true;
|
|
277
|
+
else for (const specifier of node.specifiers) if (specifier.exported.name === "default") hasDefaultExport = true;
|
|
278
|
+
else hasNamedExports = true;
|
|
279
|
+
break;
|
|
280
|
+
case "ExportAllDeclaration":
|
|
281
|
+
isEsModule = true;
|
|
282
|
+
if (node.exported && node.exported.name === "default") hasDefaultExport = true;
|
|
283
|
+
else hasNamedExports = true;
|
|
284
|
+
break;
|
|
285
|
+
case "ImportDeclaration":
|
|
286
|
+
isEsModule = true;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
isEsModule,
|
|
291
|
+
hasDefaultExport,
|
|
292
|
+
hasNamedExports,
|
|
293
|
+
ast
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function deconflict(scopes, globals, identifier) {
|
|
297
|
+
let i = 1;
|
|
298
|
+
let deconflicted = makeLegalIdentifier(identifier);
|
|
299
|
+
const hasConflicts = () => scopes.some((scope) => scope.contains(deconflicted)) || globals.has(deconflicted);
|
|
300
|
+
while (hasConflicts()) {
|
|
301
|
+
deconflicted = makeLegalIdentifier(`${identifier}_${i}`);
|
|
302
|
+
i += 1;
|
|
303
|
+
}
|
|
304
|
+
for (const scope of scopes) scope.declarations[deconflicted] = true;
|
|
305
|
+
return deconflicted;
|
|
306
|
+
}
|
|
307
|
+
function getName(id) {
|
|
308
|
+
const name = makeLegalIdentifier(basename(id, extname(id)));
|
|
309
|
+
if (name !== "index") return name;
|
|
310
|
+
return makeLegalIdentifier(basename(dirname(id)));
|
|
311
|
+
}
|
|
312
|
+
function normalizePathSlashes(path$1) {
|
|
313
|
+
return path$1.replace(/\\/g, "/");
|
|
314
|
+
}
|
|
315
|
+
const getVirtualPathForDynamicRequirePath = (path$1, commonDir) => `/${normalizePathSlashes(relative(commonDir, path$1))}`;
|
|
316
|
+
function capitalize(name) {
|
|
317
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
318
|
+
}
|
|
319
|
+
function getStrictRequiresFilter({ strictRequires }) {
|
|
320
|
+
switch (strictRequires) {
|
|
321
|
+
case void 0:
|
|
322
|
+
case true: return {
|
|
323
|
+
strictRequiresFilter: () => true,
|
|
324
|
+
detectCyclesAndConditional: false
|
|
325
|
+
};
|
|
326
|
+
case "auto":
|
|
327
|
+
case "debug":
|
|
328
|
+
case null: return {
|
|
329
|
+
strictRequiresFilter: () => false,
|
|
330
|
+
detectCyclesAndConditional: true
|
|
331
|
+
};
|
|
332
|
+
case false: return {
|
|
333
|
+
strictRequiresFilter: () => false,
|
|
334
|
+
detectCyclesAndConditional: false
|
|
335
|
+
};
|
|
336
|
+
default:
|
|
337
|
+
if (typeof strictRequires === "string" || Array.isArray(strictRequires)) return {
|
|
338
|
+
strictRequiresFilter: createFilter(strictRequires),
|
|
339
|
+
detectCyclesAndConditional: false
|
|
340
|
+
};
|
|
341
|
+
throw new Error("Unexpected value for \"strictRequires\" option.");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function getPackageEntryPoint(dirPath) {
|
|
345
|
+
let entryPoint = "index.js";
|
|
346
|
+
try {
|
|
347
|
+
if (existsSync(join(dirPath, "package.json"))) entryPoint = JSON.parse(readFileSync(join(dirPath, "package.json"), { encoding: "utf8" })).main || entryPoint;
|
|
348
|
+
} catch (ignored) {}
|
|
349
|
+
return entryPoint;
|
|
350
|
+
}
|
|
351
|
+
function isDirectory(path$1) {
|
|
352
|
+
try {
|
|
353
|
+
if (statSync(path$1).isDirectory()) return true;
|
|
354
|
+
} catch (ignored) {}
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
function getDynamicRequireModules(patterns, dynamicRequireRoot) {
|
|
358
|
+
const dynamicRequireModules = /* @__PURE__ */ new Map();
|
|
359
|
+
const dirNames = /* @__PURE__ */ new Set();
|
|
360
|
+
for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) {
|
|
361
|
+
const isNegated = pattern.startsWith("!");
|
|
362
|
+
const modifyMap = (targetPath, resolvedPath) => isNegated ? dynamicRequireModules.delete(targetPath) : dynamicRequireModules.set(targetPath, resolvedPath);
|
|
363
|
+
for (const path$1 of new Builder().withBasePath().withDirs().glob(isNegated ? pattern.substr(1) : pattern).crawl(relative(".", dynamicRequireRoot)).sync().sort((a, b) => a.localeCompare(b, "en"))) {
|
|
364
|
+
const resolvedPath = resolve(path$1);
|
|
365
|
+
const requirePath = normalizePathSlashes(resolvedPath);
|
|
366
|
+
if (isDirectory(resolvedPath)) {
|
|
367
|
+
dirNames.add(resolvedPath);
|
|
368
|
+
const modulePath = resolve(join(resolvedPath, getPackageEntryPoint(path$1)));
|
|
369
|
+
modifyMap(requirePath, modulePath);
|
|
370
|
+
modifyMap(normalizePathSlashes(modulePath), modulePath);
|
|
371
|
+
} else {
|
|
372
|
+
dirNames.add(dirname(resolvedPath));
|
|
373
|
+
modifyMap(requirePath, resolvedPath);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
commonDir: dirNames.size ? (0, import_commondir.default)([...dirNames, dynamicRequireRoot]) : null,
|
|
379
|
+
dynamicRequireModules
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
const FAILED_REQUIRE_ERROR = `throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');`;
|
|
383
|
+
const COMMONJS_REQUIRE_EXPORT = "commonjsRequire";
|
|
384
|
+
const CREATE_COMMONJS_REQUIRE_EXPORT = "createCommonjsRequire";
|
|
385
|
+
function getDynamicModuleRegistry(isDynamicRequireModulesEnabled, dynamicRequireModules, commonDir, ignoreDynamicRequires) {
|
|
386
|
+
if (!isDynamicRequireModulesEnabled) return `export function ${COMMONJS_REQUIRE_EXPORT}(path) {
|
|
387
|
+
${FAILED_REQUIRE_ERROR}
|
|
388
|
+
}`;
|
|
389
|
+
return `${[...dynamicRequireModules.values()].map((id, index) => `import ${id.endsWith(".json") ? `json${index}` : `{ __require as require${index} }`} from ${JSON.stringify(id)};`).join("\n")}
|
|
390
|
+
|
|
391
|
+
var dynamicModules;
|
|
392
|
+
|
|
393
|
+
function getDynamicModules() {
|
|
394
|
+
return dynamicModules || (dynamicModules = {
|
|
395
|
+
${[...dynamicRequireModules.keys()].map((id, index) => `\t\t${JSON.stringify(getVirtualPathForDynamicRequirePath(id, commonDir))}: ${id.endsWith(".json") ? `function () { return json${index}; }` : `require${index}`}`).join(",\n")}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function ${CREATE_COMMONJS_REQUIRE_EXPORT}(originalModuleDir) {
|
|
400
|
+
function handleRequire(path) {
|
|
401
|
+
var resolvedPath = commonjsResolve(path, originalModuleDir);
|
|
402
|
+
if (resolvedPath !== null) {
|
|
403
|
+
return getDynamicModules()[resolvedPath]();
|
|
404
|
+
}
|
|
405
|
+
${ignoreDynamicRequires ? "return require(path);" : FAILED_REQUIRE_ERROR}
|
|
406
|
+
}
|
|
407
|
+
handleRequire.resolve = function (path) {
|
|
408
|
+
var resolvedPath = commonjsResolve(path, originalModuleDir);
|
|
409
|
+
if (resolvedPath !== null) {
|
|
410
|
+
return resolvedPath;
|
|
411
|
+
}
|
|
412
|
+
return require.resolve(path);
|
|
413
|
+
}
|
|
414
|
+
return handleRequire;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function commonjsResolve (path, originalModuleDir) {
|
|
418
|
+
var shouldTryNodeModules = isPossibleNodeModulesPath(path);
|
|
419
|
+
path = normalize(path);
|
|
420
|
+
var relPath;
|
|
421
|
+
if (path[0] === '/') {
|
|
422
|
+
originalModuleDir = '';
|
|
423
|
+
}
|
|
424
|
+
var modules = getDynamicModules();
|
|
425
|
+
var checkedExtensions = ['', '.js', '.json'];
|
|
426
|
+
while (true) {
|
|
427
|
+
if (!shouldTryNodeModules) {
|
|
428
|
+
relPath = normalize(originalModuleDir + '/' + path);
|
|
429
|
+
} else {
|
|
430
|
+
relPath = normalize(originalModuleDir + '/node_modules/' + path);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (relPath.endsWith('/..')) {
|
|
434
|
+
break; // Travelled too far up, avoid infinite loop
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
for (var extensionIndex = 0; extensionIndex < checkedExtensions.length; extensionIndex++) {
|
|
438
|
+
var resolvedPath = relPath + checkedExtensions[extensionIndex];
|
|
439
|
+
if (modules[resolvedPath]) {
|
|
440
|
+
return resolvedPath;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (!shouldTryNodeModules) break;
|
|
444
|
+
var nextDir = normalize(originalModuleDir + '/..');
|
|
445
|
+
if (nextDir === originalModuleDir) break;
|
|
446
|
+
originalModuleDir = nextDir;
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function isPossibleNodeModulesPath (modulePath) {
|
|
452
|
+
var c0 = modulePath[0];
|
|
453
|
+
if (c0 === '/' || c0 === '\\\\') return false;
|
|
454
|
+
var c1 = modulePath[1], c2 = modulePath[2];
|
|
455
|
+
if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||
|
|
456
|
+
(c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;
|
|
457
|
+
if (c1 === ':' && (c2 === '/' || c2 === '\\\\')) return false;
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function normalize (path) {
|
|
462
|
+
path = path.replace(/\\\\/g, '/');
|
|
463
|
+
var parts = path.split('/');
|
|
464
|
+
var slashed = parts[0] === '';
|
|
465
|
+
for (var i = 1; i < parts.length; i++) {
|
|
466
|
+
if (parts[i] === '.' || parts[i] === '') {
|
|
467
|
+
parts.splice(i--, 1);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
for (var i = 1; i < parts.length; i++) {
|
|
471
|
+
if (parts[i] !== '..') continue;
|
|
472
|
+
if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {
|
|
473
|
+
parts.splice(--i, 2);
|
|
474
|
+
i--;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
path = parts.join('/');
|
|
478
|
+
if (slashed && path[0] !== '/') path = '/' + path;
|
|
479
|
+
else if (path.length === 0) path = '.';
|
|
480
|
+
return path;
|
|
481
|
+
}`;
|
|
482
|
+
}
|
|
483
|
+
const isWrappedId = (id, suffix) => id.endsWith(suffix);
|
|
484
|
+
const wrapId = (id, suffix) => `\0${id}${suffix}`;
|
|
485
|
+
const unwrapId = (wrappedId, suffix) => wrappedId.slice(1, -suffix.length);
|
|
486
|
+
const PROXY_SUFFIX = "?commonjs-proxy";
|
|
487
|
+
const WRAPPED_SUFFIX = "?commonjs-wrapped";
|
|
488
|
+
const EXTERNAL_SUFFIX = "?commonjs-external";
|
|
489
|
+
const EXPORTS_SUFFIX = "?commonjs-exports";
|
|
490
|
+
const MODULE_SUFFIX = "?commonjs-module";
|
|
491
|
+
const ENTRY_SUFFIX = "?commonjs-entry";
|
|
492
|
+
const ES_IMPORT_SUFFIX = "?commonjs-es-import";
|
|
493
|
+
const DYNAMIC_MODULES_ID = "\0commonjs-dynamic-modules";
|
|
494
|
+
const HELPERS_ID = "\0commonjsHelpers.js";
|
|
495
|
+
const IS_WRAPPED_COMMONJS = "withRequireFunction";
|
|
496
|
+
const HELPERS = `
|
|
497
|
+
export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
498
|
+
|
|
499
|
+
export function getDefaultExportFromCjs (x) {
|
|
500
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export function getDefaultExportFromNamespaceIfPresent (n) {
|
|
504
|
+
return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export function getDefaultExportFromNamespaceIfNotNamed (n) {
|
|
508
|
+
return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export function getAugmentedNamespace(n) {
|
|
512
|
+
if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
|
|
513
|
+
var f = n.default;
|
|
514
|
+
if (typeof f == "function") {
|
|
515
|
+
var a = function a () {
|
|
516
|
+
var isInstance = false;
|
|
517
|
+
try {
|
|
518
|
+
isInstance = this instanceof a;
|
|
519
|
+
} catch {}
|
|
520
|
+
if (isInstance) {
|
|
521
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
522
|
+
}
|
|
523
|
+
return f.apply(this, arguments);
|
|
524
|
+
};
|
|
525
|
+
a.prototype = f.prototype;
|
|
526
|
+
} else a = {};
|
|
527
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
528
|
+
Object.keys(n).forEach(function (k) {
|
|
529
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
530
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
531
|
+
enumerable: true,
|
|
532
|
+
get: function () {
|
|
533
|
+
return n[k];
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
return a;
|
|
538
|
+
}
|
|
539
|
+
`;
|
|
540
|
+
function getHelpersModule() {
|
|
541
|
+
return HELPERS;
|
|
542
|
+
}
|
|
543
|
+
function getUnknownRequireProxy(id, requireReturnsDefault) {
|
|
544
|
+
if (requireReturnsDefault === true || id.endsWith(".json")) return `export { default } from ${JSON.stringify(id)};`;
|
|
545
|
+
const name = getName(id);
|
|
546
|
+
const exported = requireReturnsDefault === "auto" ? `import { getDefaultExportFromNamespaceIfNotNamed } from "${HELPERS_ID}"; export default /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(${name});` : requireReturnsDefault === "preferred" ? `import { getDefaultExportFromNamespaceIfPresent } from "${HELPERS_ID}"; export default /*@__PURE__*/getDefaultExportFromNamespaceIfPresent(${name});` : !requireReturnsDefault ? `import { getAugmentedNamespace } from "${HELPERS_ID}"; export default /*@__PURE__*/getAugmentedNamespace(${name});` : `export default ${name};`;
|
|
547
|
+
return `import * as ${name} from ${JSON.stringify(id)}; ${exported}`;
|
|
548
|
+
}
|
|
549
|
+
async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
|
|
550
|
+
const name = getName(id);
|
|
551
|
+
const { meta: { commonjs: commonjsMeta } } = await loadModule({ id });
|
|
552
|
+
if (!commonjsMeta) return getUnknownRequireProxy(id, requireReturnsDefault);
|
|
553
|
+
if (commonjsMeta.isCommonJS) return `export { __moduleExports as default } from ${JSON.stringify(id)};`;
|
|
554
|
+
if (!requireReturnsDefault) return `import { getAugmentedNamespace } from "${HELPERS_ID}"; import * as ${name} from ${JSON.stringify(id)}; export default /*@__PURE__*/getAugmentedNamespace(${name});`;
|
|
555
|
+
if (requireReturnsDefault !== true && (requireReturnsDefault === "namespace" || !commonjsMeta.hasDefaultExport || requireReturnsDefault === "auto" && commonjsMeta.hasNamedExports)) return `import * as ${name} from ${JSON.stringify(id)}; export default ${name};`;
|
|
556
|
+
return `export { default } from ${JSON.stringify(id)};`;
|
|
557
|
+
}
|
|
558
|
+
function getEntryProxy(id, defaultIsModuleExports, getModuleInfo, shebang) {
|
|
559
|
+
const { meta: { commonjs: commonjsMeta }, hasDefaultExport } = getModuleInfo(id);
|
|
560
|
+
if (!commonjsMeta || commonjsMeta.isCommonJS !== IS_WRAPPED_COMMONJS) {
|
|
561
|
+
const stringifiedId = JSON.stringify(id);
|
|
562
|
+
let code = `export * from ${stringifiedId};`;
|
|
563
|
+
if (hasDefaultExport) code += `export { default } from ${stringifiedId};`;
|
|
564
|
+
return shebang + code;
|
|
565
|
+
}
|
|
566
|
+
const result = getEsImportProxy(id, defaultIsModuleExports, true);
|
|
567
|
+
return {
|
|
568
|
+
...result,
|
|
569
|
+
code: shebang + result.code
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function getEsImportProxy(id, defaultIsModuleExports, moduleSideEffects) {
|
|
573
|
+
const name = getName(id);
|
|
574
|
+
const exportsName = `${name}Exports`;
|
|
575
|
+
const requireModule = `require${capitalize(name)}`;
|
|
576
|
+
let code = `import { getDefaultExportFromCjs } from "${HELPERS_ID}";\nimport { __require as ${requireModule} } from ${JSON.stringify(id)};\nvar ${exportsName} = ${moduleSideEffects ? "" : "/*@__PURE__*/ "}${requireModule}();\nexport { ${exportsName} as __moduleExports };`;
|
|
577
|
+
if (defaultIsModuleExports === true) code += `\nexport { ${exportsName} as default };`;
|
|
578
|
+
else if (defaultIsModuleExports === false) code += `\nexport default ${exportsName}.default;`;
|
|
579
|
+
else code += `\nexport default /*@__PURE__*/getDefaultExportFromCjs(${exportsName});`;
|
|
580
|
+
return {
|
|
581
|
+
code,
|
|
582
|
+
syntheticNamedExports: "__moduleExports"
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function getExternalBuiltinRequireProxy(id) {
|
|
586
|
+
return `import { createRequire } from 'node:module';
|
|
587
|
+
const require = createRequire(import.meta.url);
|
|
588
|
+
export function __require() { return require(${JSON.stringify(id)}); }`;
|
|
589
|
+
}
|
|
590
|
+
function getCandidatesForExtension(resolved, extension) {
|
|
591
|
+
return [resolved + extension, `${resolved}${sep}index${extension}`];
|
|
592
|
+
}
|
|
593
|
+
function getCandidates(resolved, extensions) {
|
|
594
|
+
return extensions.reduce((paths, extension) => paths.concat(getCandidatesForExtension(resolved, extension)), [resolved]);
|
|
595
|
+
}
|
|
596
|
+
function resolveExtensions(importee, importer, extensions) {
|
|
597
|
+
if (importee[0] !== "." || !importer) return void 0;
|
|
598
|
+
const candidates = getCandidates(resolve(dirname(importer), importee), extensions);
|
|
599
|
+
for (let i = 0; i < candidates.length; i += 1) try {
|
|
600
|
+
if (statSync(candidates[i]).isFile()) return { id: candidates[i] };
|
|
601
|
+
} catch (err) {}
|
|
602
|
+
}
|
|
603
|
+
function getResolveId(extensions, isPossibleCjsId) {
|
|
604
|
+
const currentlyResolving = /* @__PURE__ */ new Map();
|
|
605
|
+
return {
|
|
606
|
+
currentlyResolving,
|
|
607
|
+
async resolveId(importee, importer, resolveOptions) {
|
|
608
|
+
if (resolveOptions.custom?.["node-resolve"]?.isRequire) return null;
|
|
609
|
+
const currentlyResolvingForParent = currentlyResolving.get(importer);
|
|
610
|
+
if (currentlyResolvingForParent && currentlyResolvingForParent.has(importee)) {
|
|
611
|
+
this.warn({
|
|
612
|
+
code: "THIS_RESOLVE_WITHOUT_OPTIONS",
|
|
613
|
+
message: "It appears a plugin has implemented a \"resolveId\" hook that uses \"this.resolve\" without forwarding the third \"options\" parameter of \"resolveId\". This is problematic as it can lead to wrong module resolutions especially for the node-resolve plugin and in certain cases cause early exit errors for the commonjs plugin.\nIn rare cases, this warning can appear if the same file is both imported and required from the same mixed ES/CommonJS module, in which case it can be ignored.",
|
|
614
|
+
url: "https://rollupjs.org/guide/en/#resolveid"
|
|
615
|
+
});
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
if (isWrappedId(importee, WRAPPED_SUFFIX)) return unwrapId(importee, WRAPPED_SUFFIX);
|
|
619
|
+
if (importee.endsWith(ENTRY_SUFFIX) || isWrappedId(importee, MODULE_SUFFIX) || isWrappedId(importee, EXPORTS_SUFFIX) || isWrappedId(importee, PROXY_SUFFIX) || isWrappedId(importee, ES_IMPORT_SUFFIX) || isWrappedId(importee, EXTERNAL_SUFFIX) || importee.startsWith(HELPERS_ID) || importee === DYNAMIC_MODULES_ID) return importee;
|
|
620
|
+
if (importer) {
|
|
621
|
+
if (importer === DYNAMIC_MODULES_ID || isWrappedId(importer, PROXY_SUFFIX) || isWrappedId(importer, ES_IMPORT_SUFFIX) || importer.endsWith(ENTRY_SUFFIX)) return importee;
|
|
622
|
+
if (isWrappedId(importer, EXTERNAL_SUFFIX)) {
|
|
623
|
+
if (!await this.resolve(importee, importer, Object.assign({ skipSelf: true }, resolveOptions))) return null;
|
|
624
|
+
return {
|
|
625
|
+
id: importee,
|
|
626
|
+
external: true
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (importee.startsWith("\0")) return null;
|
|
631
|
+
const resolved = await this.resolve(importee, importer, Object.assign({ skipSelf: true }, resolveOptions)) || resolveExtensions(importee, importer, extensions);
|
|
632
|
+
if (!resolved || resolved.external || resolved.id.endsWith(ENTRY_SUFFIX) || isWrappedId(resolved.id, ES_IMPORT_SUFFIX) || !isPossibleCjsId(resolved.id)) return resolved;
|
|
633
|
+
const moduleInfo = await this.load(resolved);
|
|
634
|
+
const { meta: { commonjs: commonjsMeta } } = moduleInfo;
|
|
635
|
+
if (commonjsMeta) {
|
|
636
|
+
const { isCommonJS } = commonjsMeta;
|
|
637
|
+
if (isCommonJS) {
|
|
638
|
+
if (resolveOptions.isEntry) {
|
|
639
|
+
moduleInfo.moduleSideEffects = true;
|
|
640
|
+
return resolved.id + ENTRY_SUFFIX;
|
|
641
|
+
}
|
|
642
|
+
if (isCommonJS === IS_WRAPPED_COMMONJS) return {
|
|
643
|
+
id: wrapId(resolved.id, ES_IMPORT_SUFFIX),
|
|
644
|
+
meta: { commonjs: { resolved } }
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return resolved;
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
function getRequireResolver(extensions, detectCyclesAndConditional, currentlyResolving) {
|
|
653
|
+
const knownCjsModuleTypes = Object.create(null);
|
|
654
|
+
const requiredIds = Object.create(null);
|
|
655
|
+
const unconditionallyRequiredIds = Object.create(null);
|
|
656
|
+
const dependencies = Object.create(null);
|
|
657
|
+
const getDependencies = (id) => dependencies[id] || (dependencies[id] = /* @__PURE__ */ new Set());
|
|
658
|
+
const isCyclic = (id) => {
|
|
659
|
+
const dependenciesToCheck = new Set(getDependencies(id));
|
|
660
|
+
for (const dependency of dependenciesToCheck) {
|
|
661
|
+
if (dependency === id) return true;
|
|
662
|
+
for (const childDependency of getDependencies(dependency)) dependenciesToCheck.add(childDependency);
|
|
663
|
+
}
|
|
664
|
+
return false;
|
|
665
|
+
};
|
|
666
|
+
const fullyAnalyzedModules = Object.create(null);
|
|
667
|
+
const getTypeForFullyAnalyzedModule = (id) => {
|
|
668
|
+
const knownType = knownCjsModuleTypes[id];
|
|
669
|
+
if (knownType !== true || !detectCyclesAndConditional || fullyAnalyzedModules[id]) return knownType;
|
|
670
|
+
if (isCyclic(id)) return knownCjsModuleTypes[id] = IS_WRAPPED_COMMONJS;
|
|
671
|
+
return knownType;
|
|
672
|
+
};
|
|
673
|
+
const setInitialParentType = (id, initialCommonJSType) => {
|
|
674
|
+
if (fullyAnalyzedModules[id]) return;
|
|
675
|
+
knownCjsModuleTypes[id] = initialCommonJSType;
|
|
676
|
+
if (detectCyclesAndConditional && knownCjsModuleTypes[id] === true && requiredIds[id] && !unconditionallyRequiredIds[id]) knownCjsModuleTypes[id] = IS_WRAPPED_COMMONJS;
|
|
677
|
+
};
|
|
678
|
+
const analyzeRequiredModule = async (parentId, resolved, isConditional, loadModule) => {
|
|
679
|
+
const childId = resolved.id;
|
|
680
|
+
requiredIds[childId] = true;
|
|
681
|
+
if (!(isConditional || knownCjsModuleTypes[parentId] === IS_WRAPPED_COMMONJS)) unconditionallyRequiredIds[childId] = true;
|
|
682
|
+
getDependencies(parentId).add(childId);
|
|
683
|
+
if (!isCyclic(childId)) await loadModule(resolved);
|
|
684
|
+
};
|
|
685
|
+
const getTypeForImportedModule = async (resolved, loadModule) => {
|
|
686
|
+
if (resolved.id in knownCjsModuleTypes) return knownCjsModuleTypes[resolved.id];
|
|
687
|
+
const { meta: { commonjs: commonjs$1 } } = await loadModule(resolved);
|
|
688
|
+
return commonjs$1 && commonjs$1.isCommonJS || false;
|
|
689
|
+
};
|
|
690
|
+
return {
|
|
691
|
+
getWrappedIds: () => Object.keys(knownCjsModuleTypes).filter((id) => knownCjsModuleTypes[id] === IS_WRAPPED_COMMONJS),
|
|
692
|
+
isRequiredId: (id) => requiredIds[id],
|
|
693
|
+
async shouldTransformCachedModule({ id: parentId, resolvedSources, meta: { commonjs: parentMeta } }) {
|
|
694
|
+
if (!(parentMeta && parentMeta.isCommonJS)) knownCjsModuleTypes[parentId] = false;
|
|
695
|
+
if (isWrappedId(parentId, ES_IMPORT_SUFFIX)) return false;
|
|
696
|
+
const parentRequires = parentMeta && parentMeta.requires;
|
|
697
|
+
if (parentRequires) {
|
|
698
|
+
setInitialParentType(parentId, parentMeta.initialCommonJSType);
|
|
699
|
+
await Promise.all(parentRequires.map(({ resolved, isConditional }) => analyzeRequiredModule(parentId, resolved, isConditional, this.load)));
|
|
700
|
+
if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) return true;
|
|
701
|
+
for (const { resolved: { id } } of parentRequires) if (getTypeForFullyAnalyzedModule(id) !== parentMeta.isRequiredCommonJS[id]) return true;
|
|
702
|
+
fullyAnalyzedModules[parentId] = true;
|
|
703
|
+
for (const { resolved: { id } } of parentRequires) fullyAnalyzedModules[id] = true;
|
|
704
|
+
}
|
|
705
|
+
const parentRequireSet = new Set((parentRequires || []).map(({ resolved: { id } }) => id));
|
|
706
|
+
return (await Promise.all(Object.keys(resolvedSources).map((source) => resolvedSources[source]).filter(({ id, external }) => !(external || parentRequireSet.has(id))).map(async (resolved) => {
|
|
707
|
+
if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) return await getTypeForImportedModule((await this.load(resolved)).meta.commonjs.resolved, this.load) !== IS_WRAPPED_COMMONJS;
|
|
708
|
+
return await getTypeForImportedModule(resolved, this.load) === IS_WRAPPED_COMMONJS;
|
|
709
|
+
}))).some((shouldTransform) => shouldTransform);
|
|
710
|
+
},
|
|
711
|
+
resolveRequireSourcesAndUpdateMeta: (rollupContext) => async (parentId, isParentCommonJS, parentMeta, sources) => {
|
|
712
|
+
parentMeta.initialCommonJSType = isParentCommonJS;
|
|
713
|
+
parentMeta.requires = [];
|
|
714
|
+
parentMeta.isRequiredCommonJS = Object.create(null);
|
|
715
|
+
setInitialParentType(parentId, isParentCommonJS);
|
|
716
|
+
const currentlyResolvingForParent = currentlyResolving.get(parentId) || /* @__PURE__ */ new Set();
|
|
717
|
+
currentlyResolving.set(parentId, currentlyResolvingForParent);
|
|
718
|
+
const requireTargets = await Promise.all(sources.map(async ({ source, isConditional }) => {
|
|
719
|
+
if (source.startsWith("\0")) return {
|
|
720
|
+
id: source,
|
|
721
|
+
allowProxy: false
|
|
722
|
+
};
|
|
723
|
+
currentlyResolvingForParent.add(source);
|
|
724
|
+
const resolved = await rollupContext.resolve(source, parentId, {
|
|
725
|
+
skipSelf: false,
|
|
726
|
+
custom: { "node-resolve": { isRequire: true } }
|
|
727
|
+
}) || resolveExtensions(source, parentId, extensions);
|
|
728
|
+
currentlyResolvingForParent.delete(source);
|
|
729
|
+
if (!resolved) return {
|
|
730
|
+
id: wrapId(source, EXTERNAL_SUFFIX),
|
|
731
|
+
allowProxy: false
|
|
732
|
+
};
|
|
733
|
+
const childId = resolved.id;
|
|
734
|
+
if (resolved.external) return {
|
|
735
|
+
id: wrapId(childId, EXTERNAL_SUFFIX),
|
|
736
|
+
allowProxy: false
|
|
737
|
+
};
|
|
738
|
+
parentMeta.requires.push({
|
|
739
|
+
resolved,
|
|
740
|
+
isConditional
|
|
741
|
+
});
|
|
742
|
+
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
|
|
743
|
+
return {
|
|
744
|
+
id: childId,
|
|
745
|
+
allowProxy: true
|
|
746
|
+
};
|
|
747
|
+
}));
|
|
748
|
+
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
|
|
749
|
+
fullyAnalyzedModules[parentId] = true;
|
|
750
|
+
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
|
|
751
|
+
let isCommonJS = parentMeta.isRequiredCommonJS[dependencyId] = getTypeForFullyAnalyzedModule(dependencyId);
|
|
752
|
+
const isExternalWrapped = isWrappedId(dependencyId, EXTERNAL_SUFFIX);
|
|
753
|
+
let resolvedDependencyId = dependencyId;
|
|
754
|
+
if (parentMeta.isCommonJS === IS_WRAPPED_COMMONJS && !allowProxy && isExternalWrapped) {
|
|
755
|
+
if (unwrapId(dependencyId, EXTERNAL_SUFFIX).startsWith("node:")) {
|
|
756
|
+
isCommonJS = IS_WRAPPED_COMMONJS;
|
|
757
|
+
parentMeta.isRequiredCommonJS[dependencyId] = isCommonJS;
|
|
758
|
+
}
|
|
759
|
+
} else if (isExternalWrapped && !allowProxy) {
|
|
760
|
+
const actualExternalId = unwrapId(dependencyId, EXTERNAL_SUFFIX);
|
|
761
|
+
if (actualExternalId.startsWith("node:")) resolvedDependencyId = actualExternalId;
|
|
762
|
+
}
|
|
763
|
+
const isWrappedCommonJS = isCommonJS === IS_WRAPPED_COMMONJS;
|
|
764
|
+
fullyAnalyzedModules[dependencyId] = true;
|
|
765
|
+
const moduleInfo = isWrappedCommonJS && !isExternalWrapped ? rollupContext.getModuleInfo(dependencyId) : null;
|
|
766
|
+
return {
|
|
767
|
+
wrappedModuleSideEffects: !isWrappedCommonJS ? false : moduleInfo?.moduleSideEffects ?? true,
|
|
768
|
+
source: sources[index].source,
|
|
769
|
+
id: allowProxy ? wrapId(resolvedDependencyId, isWrappedCommonJS ? WRAPPED_SUFFIX : PROXY_SUFFIX) : resolvedDependencyId,
|
|
770
|
+
isCommonJS
|
|
771
|
+
};
|
|
772
|
+
});
|
|
773
|
+
},
|
|
774
|
+
isCurrentlyResolving(source, parentId) {
|
|
775
|
+
const currentlyResolvingForParent = currentlyResolving.get(parentId);
|
|
776
|
+
return currentlyResolvingForParent && currentlyResolvingForParent.has(source);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
function validateVersion(actualVersion, peerDependencyVersion, name) {
|
|
781
|
+
const versionRegexp = /\^(\d+\.\d+\.\d+)/g;
|
|
782
|
+
let minMajor = Infinity;
|
|
783
|
+
let minMinor = Infinity;
|
|
784
|
+
let minPatch = Infinity;
|
|
785
|
+
let foundVersion;
|
|
786
|
+
while (foundVersion = versionRegexp.exec(peerDependencyVersion)) {
|
|
787
|
+
const [foundMajor, foundMinor, foundPatch] = foundVersion[1].split(".").map(Number);
|
|
788
|
+
if (foundMajor < minMajor) {
|
|
789
|
+
minMajor = foundMajor;
|
|
790
|
+
minMinor = foundMinor;
|
|
791
|
+
minPatch = foundPatch;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (!actualVersion) throw new Error(`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch}.`);
|
|
795
|
+
const [major, minor, patch] = actualVersion.split(".").map(Number);
|
|
796
|
+
if (major < minMajor || major === minMajor && (minor < minMinor || minor === minMinor && patch < minPatch)) throw new Error(`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch} but found ${name}@${actualVersion}.`);
|
|
797
|
+
}
|
|
798
|
+
const operators = {
|
|
799
|
+
"==": (x) => equals(x.left, x.right, false),
|
|
800
|
+
"!=": (x) => not(operators["=="](x)),
|
|
801
|
+
"===": (x) => equals(x.left, x.right, true),
|
|
802
|
+
"!==": (x) => not(operators["==="](x)),
|
|
803
|
+
"!": (x) => isFalsy(x.argument),
|
|
804
|
+
"&&": (x) => isTruthy(x.left) && isTruthy(x.right),
|
|
805
|
+
"||": (x) => isTruthy(x.left) || isTruthy(x.right)
|
|
806
|
+
};
|
|
807
|
+
function not(value) {
|
|
808
|
+
return value === null ? value : !value;
|
|
809
|
+
}
|
|
810
|
+
function equals(a, b, strict) {
|
|
811
|
+
if (a.type !== b.type) return null;
|
|
812
|
+
if (a.type === "Literal") return strict ? a.value === b.value : a.value == b.value;
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
function isTruthy(node) {
|
|
816
|
+
if (!node) return false;
|
|
817
|
+
if (node.type === "Literal") return !!node.value;
|
|
818
|
+
if (node.type === "ParenthesizedExpression") return isTruthy(node.expression);
|
|
819
|
+
if (node.operator in operators) return operators[node.operator](node);
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
function isFalsy(node) {
|
|
823
|
+
return not(isTruthy(node));
|
|
824
|
+
}
|
|
825
|
+
function getKeypath(node) {
|
|
826
|
+
const parts = [];
|
|
827
|
+
while (node.type === "MemberExpression") {
|
|
828
|
+
if (node.computed) return null;
|
|
829
|
+
parts.unshift(node.property.name);
|
|
830
|
+
node = node.object;
|
|
831
|
+
}
|
|
832
|
+
if (node.type !== "Identifier") return null;
|
|
833
|
+
const { name } = node;
|
|
834
|
+
parts.unshift(name);
|
|
835
|
+
return {
|
|
836
|
+
name,
|
|
837
|
+
keypath: parts.join(".")
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
const KEY_COMPILED_ESM = "__esModule";
|
|
841
|
+
function getDefineCompiledEsmType(node) {
|
|
842
|
+
const definedPropertyWithExports = getDefinePropertyCallName(node, "exports");
|
|
843
|
+
const definedProperty = definedPropertyWithExports || getDefinePropertyCallName(node, "module.exports");
|
|
844
|
+
if (definedProperty && definedProperty.key === KEY_COMPILED_ESM) return isTruthy(definedProperty.value) ? definedPropertyWithExports ? "exports" : "module" : false;
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
function getDefinePropertyCallName(node, targetName) {
|
|
848
|
+
const { callee: { object, property } } = node;
|
|
849
|
+
if (!object || object.type !== "Identifier" || object.name !== "Object") return;
|
|
850
|
+
if (!property || property.type !== "Identifier" || property.name !== "defineProperty") return;
|
|
851
|
+
if (node.arguments.length !== 3) return;
|
|
852
|
+
const targetNames = targetName.split(".");
|
|
853
|
+
const [target, key, value] = node.arguments;
|
|
854
|
+
if (targetNames.length === 1) {
|
|
855
|
+
if (target.type !== "Identifier" || target.name !== targetNames[0]) return;
|
|
856
|
+
}
|
|
857
|
+
if (targetNames.length === 2) {
|
|
858
|
+
if (target.type !== "MemberExpression" || target.object.name !== targetNames[0] || target.property.name !== targetNames[1]) return;
|
|
859
|
+
}
|
|
860
|
+
if (value.type !== "ObjectExpression" || !value.properties) return;
|
|
861
|
+
const valueProperty = value.properties.find((p) => p.key && p.key.name === "value");
|
|
862
|
+
if (!valueProperty || !valueProperty.value) return;
|
|
863
|
+
return {
|
|
864
|
+
key: key.value,
|
|
865
|
+
value: valueProperty.value
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
function isShorthandProperty(parent) {
|
|
869
|
+
return parent && parent.type === "Property" && parent.shorthand;
|
|
870
|
+
}
|
|
871
|
+
function wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges) {
|
|
872
|
+
const args = [];
|
|
873
|
+
const passedArgs = [];
|
|
874
|
+
if (uses.module) {
|
|
875
|
+
args.push("module");
|
|
876
|
+
passedArgs.push(moduleName);
|
|
877
|
+
}
|
|
878
|
+
if (uses.exports) {
|
|
879
|
+
args.push("exports");
|
|
880
|
+
passedArgs.push(uses.module ? `${moduleName}.exports` : exportsName);
|
|
881
|
+
}
|
|
882
|
+
magicString.trim().indent(" ", { exclude: indentExclusionRanges }).prepend(`(function (${args.join(", ")}) {\n`).append(` \n} (${passedArgs.join(", ")}));`);
|
|
883
|
+
}
|
|
884
|
+
function rewriteExportsAndGetExportsBlock(magicString, moduleName, exportsName, exportedExportsName, wrapped, moduleExportsAssignments, firstTopLevelModuleExportsAssignment, exportsAssignmentsByName, topLevelAssignments, defineCompiledEsmExpressions, deconflictedExportNames, code, HELPERS_NAME, exportMode, defaultIsModuleExports, usesRequireWrapper, requireName) {
|
|
885
|
+
const exports = [];
|
|
886
|
+
const exportDeclarations = [];
|
|
887
|
+
if (usesRequireWrapper) getExportsWhenUsingRequireWrapper(magicString, wrapped, exportMode, exports, moduleExportsAssignments, exportsAssignmentsByName, moduleName, exportsName, requireName, defineCompiledEsmExpressions);
|
|
888
|
+
else if (exportMode === "replace") getExportsForReplacedModuleExports(magicString, exports, exportDeclarations, moduleExportsAssignments, firstTopLevelModuleExportsAssignment, exportsName, defaultIsModuleExports, HELPERS_NAME);
|
|
889
|
+
else {
|
|
890
|
+
if (exportMode === "module") {
|
|
891
|
+
exportDeclarations.push(`var ${exportedExportsName} = ${moduleName}.exports`);
|
|
892
|
+
exports.push(`${exportedExportsName} as __moduleExports`);
|
|
893
|
+
} else exports.push(`${exportsName} as __moduleExports`);
|
|
894
|
+
if (wrapped) exportDeclarations.push(getDefaultExportDeclaration(exportedExportsName, defaultIsModuleExports, HELPERS_NAME));
|
|
895
|
+
else getExports(magicString, exports, exportDeclarations, moduleExportsAssignments, exportsAssignmentsByName, deconflictedExportNames, topLevelAssignments, moduleName, exportsName, exportedExportsName, defineCompiledEsmExpressions, HELPERS_NAME, defaultIsModuleExports, exportMode);
|
|
896
|
+
}
|
|
897
|
+
if (exports.length) exportDeclarations.push(`export { ${exports.join(", ")} }`);
|
|
898
|
+
return `\n\n${exportDeclarations.join(";\n")};`;
|
|
899
|
+
}
|
|
900
|
+
function getExportsWhenUsingRequireWrapper(magicString, wrapped, exportMode, exports, moduleExportsAssignments, exportsAssignmentsByName, moduleName, exportsName, requireName, defineCompiledEsmExpressions) {
|
|
901
|
+
exports.push(`${requireName} as __require`);
|
|
902
|
+
if (wrapped) return;
|
|
903
|
+
if (exportMode === "replace") rewriteModuleExportsAssignments(magicString, moduleExportsAssignments, exportsName);
|
|
904
|
+
else {
|
|
905
|
+
rewriteModuleExportsAssignments(magicString, moduleExportsAssignments, `${moduleName}.exports`);
|
|
906
|
+
for (const [exportName, { nodes }] of exportsAssignmentsByName) for (const { node, type } of nodes) magicString.overwrite(node.start, node.left.end, `${exportMode === "module" && type === "module" ? `${moduleName}.exports` : exportsName}.${exportName}`);
|
|
907
|
+
replaceDefineCompiledEsmExpressionsAndGetIfRestorable(defineCompiledEsmExpressions, magicString, exportMode, moduleName, exportsName);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
function getExportsForReplacedModuleExports(magicString, exports, exportDeclarations, moduleExportsAssignments, firstTopLevelModuleExportsAssignment, exportsName, defaultIsModuleExports, HELPERS_NAME) {
|
|
911
|
+
for (const { left } of moduleExportsAssignments) magicString.overwrite(left.start, left.end, exportsName);
|
|
912
|
+
magicString.prependRight(firstTopLevelModuleExportsAssignment.left.start, "var ");
|
|
913
|
+
exports.push(`${exportsName} as __moduleExports`);
|
|
914
|
+
exportDeclarations.push(getDefaultExportDeclaration(exportsName, defaultIsModuleExports, HELPERS_NAME));
|
|
915
|
+
}
|
|
916
|
+
function getDefaultExportDeclaration(exportedExportsName, defaultIsModuleExports, HELPERS_NAME) {
|
|
917
|
+
return `export default ${defaultIsModuleExports === true ? exportedExportsName : defaultIsModuleExports === false ? `${exportedExportsName}.default` : `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportedExportsName})`}`;
|
|
918
|
+
}
|
|
919
|
+
function getExports(magicString, exports, exportDeclarations, moduleExportsAssignments, exportsAssignmentsByName, deconflictedExportNames, topLevelAssignments, moduleName, exportsName, exportedExportsName, defineCompiledEsmExpressions, HELPERS_NAME, defaultIsModuleExports, exportMode) {
|
|
920
|
+
let deconflictedDefaultExportName;
|
|
921
|
+
for (const { left } of moduleExportsAssignments) magicString.overwrite(left.start, left.end, `${moduleName}.exports`);
|
|
922
|
+
for (const [exportName, { nodes }] of exportsAssignmentsByName) {
|
|
923
|
+
const deconflicted = deconflictedExportNames[exportName];
|
|
924
|
+
let needsDeclaration = true;
|
|
925
|
+
for (const { node, type } of nodes) {
|
|
926
|
+
let replacement = `${deconflicted} = ${exportMode === "module" && type === "module" ? `${moduleName}.exports` : exportsName}.${exportName}`;
|
|
927
|
+
if (needsDeclaration && topLevelAssignments.has(node)) {
|
|
928
|
+
replacement = `var ${replacement}`;
|
|
929
|
+
needsDeclaration = false;
|
|
930
|
+
}
|
|
931
|
+
magicString.overwrite(node.start, node.left.end, replacement);
|
|
932
|
+
}
|
|
933
|
+
if (needsDeclaration) magicString.prepend(`var ${deconflicted};\n`);
|
|
934
|
+
if (exportName === "default") deconflictedDefaultExportName = deconflicted;
|
|
935
|
+
else exports.push(exportName === deconflicted ? exportName : `${deconflicted} as ${exportName}`);
|
|
936
|
+
}
|
|
937
|
+
const isRestorableCompiledEsm = replaceDefineCompiledEsmExpressionsAndGetIfRestorable(defineCompiledEsmExpressions, magicString, exportMode, moduleName, exportsName);
|
|
938
|
+
if (defaultIsModuleExports === false || defaultIsModuleExports === "auto" && isRestorableCompiledEsm && moduleExportsAssignments.length === 0) exports.push(`${deconflictedDefaultExportName || exportedExportsName} as default`);
|
|
939
|
+
else if (defaultIsModuleExports === true || !isRestorableCompiledEsm && moduleExportsAssignments.length === 0) exports.push(`${exportedExportsName} as default`);
|
|
940
|
+
else exportDeclarations.push(getDefaultExportDeclaration(exportedExportsName, defaultIsModuleExports, HELPERS_NAME));
|
|
941
|
+
}
|
|
942
|
+
function rewriteModuleExportsAssignments(magicString, moduleExportsAssignments, exportsName) {
|
|
943
|
+
for (const { left } of moduleExportsAssignments) magicString.overwrite(left.start, left.end, exportsName);
|
|
944
|
+
}
|
|
945
|
+
function replaceDefineCompiledEsmExpressionsAndGetIfRestorable(defineCompiledEsmExpressions, magicString, exportMode, moduleName, exportsName) {
|
|
946
|
+
let isRestorableCompiledEsm = false;
|
|
947
|
+
for (const { node, type } of defineCompiledEsmExpressions) {
|
|
948
|
+
isRestorableCompiledEsm = true;
|
|
949
|
+
const moduleExportsExpression = node.type === "CallExpression" ? node.arguments[0] : node.left.object;
|
|
950
|
+
magicString.overwrite(moduleExportsExpression.start, moduleExportsExpression.end, exportMode === "module" && type === "module" ? `${moduleName}.exports` : exportsName);
|
|
951
|
+
}
|
|
952
|
+
return isRestorableCompiledEsm;
|
|
953
|
+
}
|
|
954
|
+
function isRequireExpression(node, scope) {
|
|
955
|
+
if (!node) return false;
|
|
956
|
+
if (node.type !== "CallExpression") return false;
|
|
957
|
+
if (node.arguments.length === 0) return false;
|
|
958
|
+
return isRequire(node.callee, scope);
|
|
959
|
+
}
|
|
960
|
+
function isRequire(node, scope) {
|
|
961
|
+
return node.type === "Identifier" && node.name === "require" && !scope.contains("require") || node.type === "MemberExpression" && isModuleRequire(node, scope);
|
|
962
|
+
}
|
|
963
|
+
function isModuleRequire({ object, property }, scope) {
|
|
964
|
+
return object.type === "Identifier" && object.name === "module" && property.type === "Identifier" && property.name === "require" && !scope.contains("module");
|
|
965
|
+
}
|
|
966
|
+
function hasDynamicArguments(node) {
|
|
967
|
+
return node.arguments.length > 1 || node.arguments[0].type !== "Literal" && (node.arguments[0].type !== "TemplateLiteral" || node.arguments[0].expressions.length > 0);
|
|
968
|
+
}
|
|
969
|
+
const reservedMethod = {
|
|
970
|
+
resolve: true,
|
|
971
|
+
cache: true,
|
|
972
|
+
main: true
|
|
973
|
+
};
|
|
974
|
+
function isNodeRequirePropertyAccess(parent) {
|
|
975
|
+
return parent && parent.property && reservedMethod[parent.property.name];
|
|
976
|
+
}
|
|
977
|
+
function getRequireStringArg(node) {
|
|
978
|
+
return node.arguments[0].type === "Literal" ? node.arguments[0].value : node.arguments[0].quasis[0].value.cooked;
|
|
979
|
+
}
|
|
980
|
+
function getRequireHandlers() {
|
|
981
|
+
const requireExpressions = [];
|
|
982
|
+
function addRequireExpression(sourceId, node, scope, usesReturnValue, isInsideTryBlock, isInsideConditional, toBeRemoved) {
|
|
983
|
+
requireExpressions.push({
|
|
984
|
+
sourceId,
|
|
985
|
+
node,
|
|
986
|
+
scope,
|
|
987
|
+
usesReturnValue,
|
|
988
|
+
isInsideTryBlock,
|
|
989
|
+
isInsideConditional,
|
|
990
|
+
toBeRemoved
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
async function rewriteRequireExpressionsAndGetImportBlock(magicString, topLevelDeclarations, reassignedNames, helpersName, dynamicRequireName, moduleName, exportsName, id, exportMode, resolveRequireSourcesAndUpdateMeta, needsRequireWrapper, isEsModule, isDynamicRequireModulesEnabled, getIgnoreTryCatchRequireStatementMode, commonjsMeta) {
|
|
994
|
+
const imports = [];
|
|
995
|
+
imports.push(`import * as ${helpersName} from "${HELPERS_ID}"`);
|
|
996
|
+
if (dynamicRequireName) imports.push(`import { ${isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT} as ${dynamicRequireName} } from "${DYNAMIC_MODULES_ID}"`);
|
|
997
|
+
if (exportMode === "module") imports.push(`import { __module as ${moduleName} } from ${JSON.stringify(wrapId(id, MODULE_SUFFIX))}`, `var ${exportsName} = ${moduleName}.exports`);
|
|
998
|
+
else if (exportMode === "exports") imports.push(`import { __exports as ${exportsName} } from ${JSON.stringify(wrapId(id, EXPORTS_SUFFIX))}`);
|
|
999
|
+
const requiresBySource = collectSources(requireExpressions);
|
|
1000
|
+
processRequireExpressions(imports, await resolveRequireSourcesAndUpdateMeta(id, needsRequireWrapper ? IS_WRAPPED_COMMONJS : !isEsModule, commonjsMeta, Object.keys(requiresBySource).map((source) => {
|
|
1001
|
+
return {
|
|
1002
|
+
source,
|
|
1003
|
+
isConditional: requiresBySource[source].every((require) => require.isInsideConditional)
|
|
1004
|
+
};
|
|
1005
|
+
})), requiresBySource, getIgnoreTryCatchRequireStatementMode, magicString);
|
|
1006
|
+
return imports.length ? `${imports.join(";\n")};\n\n` : "";
|
|
1007
|
+
}
|
|
1008
|
+
return {
|
|
1009
|
+
addRequireExpression,
|
|
1010
|
+
rewriteRequireExpressionsAndGetImportBlock
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
function collectSources(requireExpressions) {
|
|
1014
|
+
const requiresBySource = Object.create(null);
|
|
1015
|
+
for (const requireExpression of requireExpressions) {
|
|
1016
|
+
const { sourceId } = requireExpression;
|
|
1017
|
+
if (!requiresBySource[sourceId]) requiresBySource[sourceId] = [];
|
|
1018
|
+
requiresBySource[sourceId].push(requireExpression);
|
|
1019
|
+
}
|
|
1020
|
+
return requiresBySource;
|
|
1021
|
+
}
|
|
1022
|
+
function processRequireExpressions(imports, requireTargets, requiresBySource, getIgnoreTryCatchRequireStatementMode, magicString) {
|
|
1023
|
+
const generateRequireName = getGenerateRequireName();
|
|
1024
|
+
for (const { source, id: resolvedId, isCommonJS, wrappedModuleSideEffects } of requireTargets) {
|
|
1025
|
+
const requires = requiresBySource[source];
|
|
1026
|
+
const name = generateRequireName(requires);
|
|
1027
|
+
let usesRequired = false;
|
|
1028
|
+
let needsImport = false;
|
|
1029
|
+
for (const { node, usesReturnValue, toBeRemoved, isInsideTryBlock } of requires) {
|
|
1030
|
+
const { canConvertRequire, shouldRemoveRequire } = isInsideTryBlock && isWrappedId(resolvedId, EXTERNAL_SUFFIX) ? getIgnoreTryCatchRequireStatementMode(source) : {
|
|
1031
|
+
canConvertRequire: true,
|
|
1032
|
+
shouldRemoveRequire: false
|
|
1033
|
+
};
|
|
1034
|
+
if (shouldRemoveRequire) if (usesReturnValue) magicString.overwrite(node.start, node.end, "undefined");
|
|
1035
|
+
else magicString.remove(toBeRemoved.start, toBeRemoved.end);
|
|
1036
|
+
else if (canConvertRequire) {
|
|
1037
|
+
needsImport = true;
|
|
1038
|
+
if (isCommonJS === IS_WRAPPED_COMMONJS) magicString.overwrite(node.start, node.end, `${wrappedModuleSideEffects ? "" : "/*@__PURE__*/ "}${name}()`);
|
|
1039
|
+
else if (usesReturnValue) {
|
|
1040
|
+
usesRequired = true;
|
|
1041
|
+
magicString.overwrite(node.start, node.end, name);
|
|
1042
|
+
} else magicString.remove(toBeRemoved.start, toBeRemoved.end);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (needsImport) if (isCommonJS === IS_WRAPPED_COMMONJS) imports.push(`import { __require as ${name} } from ${JSON.stringify(resolvedId)}`);
|
|
1046
|
+
else imports.push(`import ${usesRequired ? `${name} from ` : ""}${JSON.stringify(resolvedId)}`);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
function getGenerateRequireName() {
|
|
1050
|
+
let uid = 0;
|
|
1051
|
+
return (requires) => {
|
|
1052
|
+
let name;
|
|
1053
|
+
const hasNameConflict = ({ scope }) => scope.contains(name);
|
|
1054
|
+
do {
|
|
1055
|
+
name = `require$$${uid}`;
|
|
1056
|
+
uid += 1;
|
|
1057
|
+
} while (requires.some(hasNameConflict));
|
|
1058
|
+
return name;
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
|
|
1062
|
+
const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
|
|
1063
|
+
async function transformCommonjs(parse, code, id, isEsModule, ignoreGlobal, ignoreRequire, ignoreDynamicRequires, getIgnoreTryCatchRequireStatementMode, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModules, commonDir, astCache, defaultIsModuleExports, needsRequireWrapper, resolveRequireSourcesAndUpdateMeta, isRequired, checkDynamicRequire, commonjsMeta) {
|
|
1064
|
+
const ast = astCache || tryParse(parse, code, id);
|
|
1065
|
+
const magicString = new MagicString(code);
|
|
1066
|
+
const uses = {
|
|
1067
|
+
module: false,
|
|
1068
|
+
exports: false,
|
|
1069
|
+
global: false,
|
|
1070
|
+
require: false
|
|
1071
|
+
};
|
|
1072
|
+
const virtualDynamicRequirePath = isDynamicRequireModulesEnabled && getVirtualPathForDynamicRequirePath(dirname(id), commonDir);
|
|
1073
|
+
let scope = attachScopes(ast, "scope");
|
|
1074
|
+
let lexicalDepth = 0;
|
|
1075
|
+
let programDepth = 0;
|
|
1076
|
+
let classBodyDepth = 0;
|
|
1077
|
+
let currentTryBlockEnd = null;
|
|
1078
|
+
let shouldWrap = false;
|
|
1079
|
+
const globals = /* @__PURE__ */ new Set();
|
|
1080
|
+
let currentConditionalNodeEnd = null;
|
|
1081
|
+
const conditionalNodes = /* @__PURE__ */ new Set();
|
|
1082
|
+
const { addRequireExpression, rewriteRequireExpressionsAndGetImportBlock } = getRequireHandlers();
|
|
1083
|
+
const reassignedNames = /* @__PURE__ */ new Set();
|
|
1084
|
+
const topLevelDeclarations = [];
|
|
1085
|
+
const skippedNodes = /* @__PURE__ */ new Set();
|
|
1086
|
+
const moduleAccessScopes = new Set([scope]);
|
|
1087
|
+
const exportsAccessScopes = new Set([scope]);
|
|
1088
|
+
const moduleExportsAssignments = [];
|
|
1089
|
+
let firstTopLevelModuleExportsAssignment = null;
|
|
1090
|
+
const exportsAssignmentsByName = /* @__PURE__ */ new Map();
|
|
1091
|
+
const topLevelAssignments = /* @__PURE__ */ new Set();
|
|
1092
|
+
const topLevelDefineCompiledEsmExpressions = [];
|
|
1093
|
+
const replacedGlobal = [];
|
|
1094
|
+
const replacedThis = [];
|
|
1095
|
+
const replacedDynamicRequires = [];
|
|
1096
|
+
const importedVariables = /* @__PURE__ */ new Set();
|
|
1097
|
+
const indentExclusionRanges = [];
|
|
1098
|
+
walk(ast, {
|
|
1099
|
+
enter(node, parent) {
|
|
1100
|
+
if (skippedNodes.has(node)) {
|
|
1101
|
+
this.skip();
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
if (currentTryBlockEnd !== null && node.start > currentTryBlockEnd) currentTryBlockEnd = null;
|
|
1105
|
+
if (currentConditionalNodeEnd !== null && node.start > currentConditionalNodeEnd) currentConditionalNodeEnd = null;
|
|
1106
|
+
if (currentConditionalNodeEnd === null && conditionalNodes.has(node)) currentConditionalNodeEnd = node.end;
|
|
1107
|
+
programDepth += 1;
|
|
1108
|
+
if (node.scope) ({scope} = node);
|
|
1109
|
+
if (functionType.test(node.type)) lexicalDepth += 1;
|
|
1110
|
+
if (sourceMap) {
|
|
1111
|
+
magicString.addSourcemapLocation(node.start);
|
|
1112
|
+
magicString.addSourcemapLocation(node.end);
|
|
1113
|
+
}
|
|
1114
|
+
switch (node.type) {
|
|
1115
|
+
case "AssignmentExpression":
|
|
1116
|
+
if (node.left.type === "MemberExpression") {
|
|
1117
|
+
const flattened = getKeypath(node.left);
|
|
1118
|
+
if (!flattened || scope.contains(flattened.name)) return;
|
|
1119
|
+
const exportsPatternMatch = exportsPattern.exec(flattened.keypath);
|
|
1120
|
+
if (!exportsPatternMatch || flattened.keypath === "exports") return;
|
|
1121
|
+
const [, exportName] = exportsPatternMatch;
|
|
1122
|
+
uses[flattened.name] = true;
|
|
1123
|
+
if (flattened.keypath === "module.exports") {
|
|
1124
|
+
moduleExportsAssignments.push(node);
|
|
1125
|
+
if (programDepth > 3) moduleAccessScopes.add(scope);
|
|
1126
|
+
else if (!firstTopLevelModuleExportsAssignment) firstTopLevelModuleExportsAssignment = node;
|
|
1127
|
+
} else if (exportName === KEY_COMPILED_ESM) if (programDepth > 3) shouldWrap = true;
|
|
1128
|
+
else topLevelDefineCompiledEsmExpressions.push({
|
|
1129
|
+
node,
|
|
1130
|
+
type: flattened.name
|
|
1131
|
+
});
|
|
1132
|
+
else {
|
|
1133
|
+
const exportsAssignments = exportsAssignmentsByName.get(exportName) || {
|
|
1134
|
+
nodes: [],
|
|
1135
|
+
scopes: /* @__PURE__ */ new Set()
|
|
1136
|
+
};
|
|
1137
|
+
exportsAssignments.nodes.push({
|
|
1138
|
+
node,
|
|
1139
|
+
type: flattened.name
|
|
1140
|
+
});
|
|
1141
|
+
exportsAssignments.scopes.add(scope);
|
|
1142
|
+
exportsAccessScopes.add(scope);
|
|
1143
|
+
exportsAssignmentsByName.set(exportName, exportsAssignments);
|
|
1144
|
+
if (programDepth <= 3) topLevelAssignments.add(node);
|
|
1145
|
+
}
|
|
1146
|
+
skippedNodes.add(node.left);
|
|
1147
|
+
} else for (const name of extractAssignedNames(node.left)) reassignedNames.add(name);
|
|
1148
|
+
return;
|
|
1149
|
+
case "CallExpression": {
|
|
1150
|
+
const defineCompiledEsmType = getDefineCompiledEsmType(node);
|
|
1151
|
+
if (defineCompiledEsmType) {
|
|
1152
|
+
if (programDepth === 3 && parent.type === "ExpressionStatement") {
|
|
1153
|
+
skippedNodes.add(node.arguments[0]);
|
|
1154
|
+
topLevelDefineCompiledEsmExpressions.push({
|
|
1155
|
+
node,
|
|
1156
|
+
type: defineCompiledEsmType
|
|
1157
|
+
});
|
|
1158
|
+
} else shouldWrap = true;
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
if (isDynamicRequireModulesEnabled && node.callee.object && isRequire(node.callee.object, scope) && node.callee.property.name === "resolve") {
|
|
1162
|
+
checkDynamicRequire(node.start);
|
|
1163
|
+
uses.require = true;
|
|
1164
|
+
const requireNode = node.callee.object;
|
|
1165
|
+
replacedDynamicRequires.push(requireNode);
|
|
1166
|
+
skippedNodes.add(node.callee);
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
if (!isRequireExpression(node, scope)) {
|
|
1170
|
+
const keypath = getKeypath(node.callee);
|
|
1171
|
+
if (keypath && importedVariables.has(keypath.name)) currentConditionalNodeEnd = Infinity;
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
skippedNodes.add(node.callee);
|
|
1175
|
+
uses.require = true;
|
|
1176
|
+
if (hasDynamicArguments(node)) {
|
|
1177
|
+
if (isDynamicRequireModulesEnabled) checkDynamicRequire(node.start);
|
|
1178
|
+
if (!ignoreDynamicRequires) replacedDynamicRequires.push(node.callee);
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
const requireStringArg = getRequireStringArg(node);
|
|
1182
|
+
if (!ignoreRequire(requireStringArg)) {
|
|
1183
|
+
const usesReturnValue = parent.type !== "ExpressionStatement";
|
|
1184
|
+
const toBeRemoved = parent.type === "ExpressionStatement" && (!currentConditionalNodeEnd || currentTryBlockEnd !== null && currentTryBlockEnd < currentConditionalNodeEnd) ? parent : node;
|
|
1185
|
+
addRequireExpression(requireStringArg, node, scope, usesReturnValue, currentTryBlockEnd !== null, currentConditionalNodeEnd !== null, toBeRemoved);
|
|
1186
|
+
if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier") for (const name of extractAssignedNames(parent.id)) importedVariables.add(name);
|
|
1187
|
+
}
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
case "ClassBody":
|
|
1191
|
+
classBodyDepth += 1;
|
|
1192
|
+
return;
|
|
1193
|
+
case "ConditionalExpression":
|
|
1194
|
+
case "IfStatement":
|
|
1195
|
+
if (isFalsy(node.test)) skippedNodes.add(node.consequent);
|
|
1196
|
+
else if (isTruthy(node.test)) {
|
|
1197
|
+
if (node.alternate) skippedNodes.add(node.alternate);
|
|
1198
|
+
} else {
|
|
1199
|
+
conditionalNodes.add(node.consequent);
|
|
1200
|
+
if (node.alternate) conditionalNodes.add(node.alternate);
|
|
1201
|
+
}
|
|
1202
|
+
return;
|
|
1203
|
+
case "ArrowFunctionExpression":
|
|
1204
|
+
case "FunctionDeclaration":
|
|
1205
|
+
case "FunctionExpression":
|
|
1206
|
+
if (currentConditionalNodeEnd === null && !(parent.type === "CallExpression" && parent.callee === node)) currentConditionalNodeEnd = node.end;
|
|
1207
|
+
return;
|
|
1208
|
+
case "Identifier": {
|
|
1209
|
+
const { name } = node;
|
|
1210
|
+
if (!(0, import_is_reference.default)(node, parent) || scope.contains(name) || parent.type === "PropertyDefinition" && parent.key === node) return;
|
|
1211
|
+
switch (name) {
|
|
1212
|
+
case "require":
|
|
1213
|
+
uses.require = true;
|
|
1214
|
+
if (isNodeRequirePropertyAccess(parent)) return;
|
|
1215
|
+
if (!ignoreDynamicRequires) {
|
|
1216
|
+
if (isShorthandProperty(parent)) {
|
|
1217
|
+
skippedNodes.add(parent.value);
|
|
1218
|
+
magicString.prependRight(node.start, "require: ");
|
|
1219
|
+
}
|
|
1220
|
+
replacedDynamicRequires.push(node);
|
|
1221
|
+
}
|
|
1222
|
+
return;
|
|
1223
|
+
case "module":
|
|
1224
|
+
case "exports":
|
|
1225
|
+
shouldWrap = true;
|
|
1226
|
+
uses[name] = true;
|
|
1227
|
+
return;
|
|
1228
|
+
case "global":
|
|
1229
|
+
uses.global = true;
|
|
1230
|
+
if (!ignoreGlobal) replacedGlobal.push(node);
|
|
1231
|
+
return;
|
|
1232
|
+
case "define":
|
|
1233
|
+
magicString.overwrite(node.start, node.end, "undefined", { storeName: true });
|
|
1234
|
+
return;
|
|
1235
|
+
default:
|
|
1236
|
+
globals.add(name);
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
case "LogicalExpression":
|
|
1241
|
+
if (node.operator === "&&") {
|
|
1242
|
+
if (isFalsy(node.left)) skippedNodes.add(node.right);
|
|
1243
|
+
else if (!isTruthy(node.left)) conditionalNodes.add(node.right);
|
|
1244
|
+
} else if (node.operator === "||") {
|
|
1245
|
+
if (isTruthy(node.left)) skippedNodes.add(node.right);
|
|
1246
|
+
else if (!isFalsy(node.left)) conditionalNodes.add(node.right);
|
|
1247
|
+
}
|
|
1248
|
+
return;
|
|
1249
|
+
case "MemberExpression":
|
|
1250
|
+
if (!isDynamicRequireModulesEnabled && isModuleRequire(node, scope)) {
|
|
1251
|
+
uses.require = true;
|
|
1252
|
+
replacedDynamicRequires.push(node);
|
|
1253
|
+
skippedNodes.add(node.object);
|
|
1254
|
+
skippedNodes.add(node.property);
|
|
1255
|
+
}
|
|
1256
|
+
return;
|
|
1257
|
+
case "ReturnStatement":
|
|
1258
|
+
if (lexicalDepth === 0) shouldWrap = true;
|
|
1259
|
+
return;
|
|
1260
|
+
case "ThisExpression":
|
|
1261
|
+
if (lexicalDepth === 0 && !classBodyDepth) {
|
|
1262
|
+
uses.global = true;
|
|
1263
|
+
if (!ignoreGlobal) replacedThis.push(node);
|
|
1264
|
+
}
|
|
1265
|
+
return;
|
|
1266
|
+
case "TryStatement":
|
|
1267
|
+
if (currentTryBlockEnd === null) currentTryBlockEnd = node.block.end;
|
|
1268
|
+
if (currentConditionalNodeEnd === null) currentConditionalNodeEnd = node.end;
|
|
1269
|
+
return;
|
|
1270
|
+
case "UnaryExpression":
|
|
1271
|
+
if (node.operator === "typeof") {
|
|
1272
|
+
const flattened = getKeypath(node.argument);
|
|
1273
|
+
if (!flattened) return;
|
|
1274
|
+
if (scope.contains(flattened.name)) return;
|
|
1275
|
+
if (!isEsModule && (flattened.keypath === "module.exports" || flattened.keypath === "module" || flattened.keypath === "exports")) magicString.overwrite(node.start, node.end, `'object'`, { storeName: false });
|
|
1276
|
+
}
|
|
1277
|
+
return;
|
|
1278
|
+
case "VariableDeclaration":
|
|
1279
|
+
if (!scope.parent) topLevelDeclarations.push(node);
|
|
1280
|
+
return;
|
|
1281
|
+
case "TemplateElement": if (node.value.raw.includes("\n")) indentExclusionRanges.push([node.start, node.end]);
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
leave(node) {
|
|
1285
|
+
programDepth -= 1;
|
|
1286
|
+
if (node.scope) scope = scope.parent;
|
|
1287
|
+
if (functionType.test(node.type)) lexicalDepth -= 1;
|
|
1288
|
+
if (node.type === "ClassBody") classBodyDepth -= 1;
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
const nameBase = getName(id);
|
|
1292
|
+
const exportsName = deconflict([...exportsAccessScopes], globals, nameBase);
|
|
1293
|
+
const moduleName = deconflict([...moduleAccessScopes], globals, `${nameBase}Module`);
|
|
1294
|
+
const requireName = deconflict([scope], globals, `require${capitalize(nameBase)}`);
|
|
1295
|
+
const isRequiredName = deconflict([scope], globals, `hasRequired${capitalize(nameBase)}`);
|
|
1296
|
+
const helpersName = deconflict([scope], globals, "commonjsHelpers");
|
|
1297
|
+
const dynamicRequireName = replacedDynamicRequires.length > 0 && deconflict([scope], globals, isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT);
|
|
1298
|
+
const deconflictedExportNames = Object.create(null);
|
|
1299
|
+
for (const [exportName, { scopes }] of exportsAssignmentsByName) deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
|
|
1300
|
+
for (const node of replacedGlobal) magicString.overwrite(node.start, node.end, `${helpersName}.commonjsGlobal`, { storeName: true });
|
|
1301
|
+
for (const node of replacedThis) magicString.overwrite(node.start, node.end, exportsName, { storeName: true });
|
|
1302
|
+
for (const node of replacedDynamicRequires) magicString.overwrite(node.start, node.end, isDynamicRequireModulesEnabled ? `${dynamicRequireName}(${JSON.stringify(virtualDynamicRequirePath)})` : dynamicRequireName, {
|
|
1303
|
+
contentOnly: true,
|
|
1304
|
+
storeName: true
|
|
1305
|
+
});
|
|
1306
|
+
shouldWrap = !isEsModule && (shouldWrap || uses.exports && moduleExportsAssignments.length > 0);
|
|
1307
|
+
if (!(shouldWrap || isRequired || needsRequireWrapper || uses.module || uses.exports || uses.require || topLevelDefineCompiledEsmExpressions.length > 0) && (ignoreGlobal || !uses.global)) return { meta: { commonjs: { isCommonJS: false } } };
|
|
1308
|
+
let leadingComment = "";
|
|
1309
|
+
if (code.startsWith("/*")) {
|
|
1310
|
+
const commentEnd = code.indexOf("*/", 2) + 2;
|
|
1311
|
+
leadingComment = `${code.slice(0, commentEnd)}\n`;
|
|
1312
|
+
magicString.remove(0, commentEnd).trim();
|
|
1313
|
+
}
|
|
1314
|
+
let shebang = "";
|
|
1315
|
+
if (code.startsWith("#!")) {
|
|
1316
|
+
const shebangEndPosition = code.indexOf("\n") + 1;
|
|
1317
|
+
shebang = code.slice(0, shebangEndPosition);
|
|
1318
|
+
magicString.remove(0, shebangEndPosition).trim();
|
|
1319
|
+
}
|
|
1320
|
+
const exportMode = isEsModule ? "none" : shouldWrap ? uses.module ? "module" : "exports" : firstTopLevelModuleExportsAssignment ? exportsAssignmentsByName.size === 0 && topLevelDefineCompiledEsmExpressions.length === 0 ? "replace" : "module" : moduleExportsAssignments.length === 0 ? "exports" : "module";
|
|
1321
|
+
const exportedExportsName = exportMode === "module" ? deconflict([], globals, `${nameBase}Exports`) : exportsName;
|
|
1322
|
+
const importBlock = await rewriteRequireExpressionsAndGetImportBlock(magicString, topLevelDeclarations, reassignedNames, helpersName, dynamicRequireName, moduleName, exportsName, id, exportMode, resolveRequireSourcesAndUpdateMeta, needsRequireWrapper, isEsModule, isDynamicRequireModulesEnabled, getIgnoreTryCatchRequireStatementMode, commonjsMeta);
|
|
1323
|
+
const usesRequireWrapper = commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS;
|
|
1324
|
+
const exportBlock = isEsModule ? "" : rewriteExportsAndGetExportsBlock(magicString, moduleName, exportsName, exportedExportsName, shouldWrap, moduleExportsAssignments, firstTopLevelModuleExportsAssignment, exportsAssignmentsByName, topLevelAssignments, topLevelDefineCompiledEsmExpressions, deconflictedExportNames, code, helpersName, exportMode, defaultIsModuleExports, usesRequireWrapper, requireName);
|
|
1325
|
+
if (shouldWrap) wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges);
|
|
1326
|
+
if (usesRequireWrapper) {
|
|
1327
|
+
magicString.trim().indent(" ", { exclude: indentExclusionRanges });
|
|
1328
|
+
const exported = exportMode === "module" ? `${moduleName}.exports` : exportsName;
|
|
1329
|
+
magicString.prepend(`var ${isRequiredName};
|
|
1330
|
+
|
|
1331
|
+
function ${requireName} () {
|
|
1332
|
+
\tif (${isRequiredName}) return ${exported};
|
|
1333
|
+
\t${isRequiredName} = 1;
|
|
1334
|
+
`).append(`
|
|
1335
|
+
\treturn ${exported};
|
|
1336
|
+
}`);
|
|
1337
|
+
if (exportMode === "replace") magicString.prepend(`var ${exportsName};\n`);
|
|
1338
|
+
}
|
|
1339
|
+
magicString.trim().prepend(shebang + leadingComment + importBlock).append(exportBlock);
|
|
1340
|
+
return {
|
|
1341
|
+
code: magicString.toString(),
|
|
1342
|
+
map: sourceMap ? magicString.generateMap() : null,
|
|
1343
|
+
syntheticNamedExports: isEsModule || usesRequireWrapper ? false : "__moduleExports",
|
|
1344
|
+
meta: { commonjs: {
|
|
1345
|
+
...commonjsMeta,
|
|
1346
|
+
shebang
|
|
1347
|
+
} }
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
const PLUGIN_NAME = "commonjs";
|
|
1351
|
+
function commonjs(options = {}) {
|
|
1352
|
+
const { ignoreGlobal, ignoreDynamicRequires, requireReturnsDefault: requireReturnsDefaultOption, defaultIsModuleExports: defaultIsModuleExportsOption, esmExternals } = options;
|
|
1353
|
+
const extensions = options.extensions || [".js"];
|
|
1354
|
+
const filter = createFilter(options.include, options.exclude);
|
|
1355
|
+
const isPossibleCjsId = (id) => {
|
|
1356
|
+
const extName = extname(id);
|
|
1357
|
+
return extName === ".cjs" || extensions.includes(extName) && filter(id);
|
|
1358
|
+
};
|
|
1359
|
+
const { strictRequiresFilter, detectCyclesAndConditional } = getStrictRequiresFilter(options);
|
|
1360
|
+
const getRequireReturnsDefault = typeof requireReturnsDefaultOption === "function" ? requireReturnsDefaultOption : () => requireReturnsDefaultOption;
|
|
1361
|
+
let esmExternalIds;
|
|
1362
|
+
const isEsmExternal = typeof esmExternals === "function" ? esmExternals : Array.isArray(esmExternals) ? (esmExternalIds = new Set(esmExternals), (id) => esmExternalIds.has(id)) : () => esmExternals;
|
|
1363
|
+
const getDefaultIsModuleExports = typeof defaultIsModuleExportsOption === "function" ? defaultIsModuleExportsOption : () => typeof defaultIsModuleExportsOption === "boolean" ? defaultIsModuleExportsOption : "auto";
|
|
1364
|
+
const dynamicRequireRoot = typeof options.dynamicRequireRoot === "string" ? resolve(options.dynamicRequireRoot) : process.cwd();
|
|
1365
|
+
const { commonDir, dynamicRequireModules } = getDynamicRequireModules(options.dynamicRequireTargets, dynamicRequireRoot);
|
|
1366
|
+
const isDynamicRequireModulesEnabled = dynamicRequireModules.size > 0;
|
|
1367
|
+
const ignoreRequire = typeof options.ignore === "function" ? options.ignore : Array.isArray(options.ignore) ? (id) => options.ignore.includes(id) : () => false;
|
|
1368
|
+
const getIgnoreTryCatchRequireStatementMode = (id) => {
|
|
1369
|
+
const mode = typeof options.ignoreTryCatch === "function" ? options.ignoreTryCatch(id) : Array.isArray(options.ignoreTryCatch) ? options.ignoreTryCatch.includes(id) : typeof options.ignoreTryCatch !== "undefined" ? options.ignoreTryCatch : true;
|
|
1370
|
+
return {
|
|
1371
|
+
canConvertRequire: mode !== "remove" && mode !== true,
|
|
1372
|
+
shouldRemoveRequire: mode === "remove"
|
|
1373
|
+
};
|
|
1374
|
+
};
|
|
1375
|
+
const { currentlyResolving, resolveId } = getResolveId(extensions, isPossibleCjsId);
|
|
1376
|
+
const sourceMap = options.sourceMap !== false;
|
|
1377
|
+
let requireResolver;
|
|
1378
|
+
function transformAndCheckExports(code, id) {
|
|
1379
|
+
const normalizedId = normalizePathSlashes(id);
|
|
1380
|
+
const { isEsModule, hasDefaultExport, hasNamedExports, ast } = analyzeTopLevelStatements(this.parse, code, id);
|
|
1381
|
+
const commonjsMeta = this.getModuleInfo(id).meta.commonjs || {};
|
|
1382
|
+
if (hasDefaultExport) commonjsMeta.hasDefaultExport = true;
|
|
1383
|
+
if (hasNamedExports) commonjsMeta.hasNamedExports = true;
|
|
1384
|
+
if (!dynamicRequireModules.has(normalizedId) && (!(hasCjsKeywords(code, ignoreGlobal) || requireResolver.isRequiredId(id)) || isEsModule && !options.transformMixedEsModules)) {
|
|
1385
|
+
commonjsMeta.isCommonJS = false;
|
|
1386
|
+
return { meta: { commonjs: commonjsMeta } };
|
|
1387
|
+
}
|
|
1388
|
+
const needsRequireWrapper = !isEsModule && (dynamicRequireModules.has(normalizedId) || strictRequiresFilter(id));
|
|
1389
|
+
const checkDynamicRequire = (position) => {
|
|
1390
|
+
const normalizedDynamicRequireRoot = normalizePathSlashes(dynamicRequireRoot);
|
|
1391
|
+
if (normalizedId.indexOf(normalizedDynamicRequireRoot) !== 0) this.error({
|
|
1392
|
+
code: "DYNAMIC_REQUIRE_OUTSIDE_ROOT",
|
|
1393
|
+
normalizedId,
|
|
1394
|
+
normalizedDynamicRequireRoot,
|
|
1395
|
+
message: `"${normalizedId}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${normalizedDynamicRequireRoot}". You should set dynamicRequireRoot to "${dirname(normalizedId)}" or one of its parent directories.`
|
|
1396
|
+
}, position);
|
|
1397
|
+
};
|
|
1398
|
+
return transformCommonjs(this.parse, code, id, isEsModule, ignoreGlobal || isEsModule, ignoreRequire, ignoreDynamicRequires && !isDynamicRequireModulesEnabled, getIgnoreTryCatchRequireStatementMode, sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModules, commonDir, ast, getDefaultIsModuleExports(id), needsRequireWrapper, requireResolver.resolveRequireSourcesAndUpdateMeta(this), requireResolver.isRequiredId(id), checkDynamicRequire, commonjsMeta);
|
|
1399
|
+
}
|
|
1400
|
+
return {
|
|
1401
|
+
name: PLUGIN_NAME,
|
|
1402
|
+
version,
|
|
1403
|
+
options(rawOptions) {
|
|
1404
|
+
const plugins = Array.isArray(rawOptions.plugins) ? [...rawOptions.plugins] : rawOptions.plugins ? [rawOptions.plugins] : [];
|
|
1405
|
+
plugins.unshift({
|
|
1406
|
+
name: "commonjs--resolver",
|
|
1407
|
+
resolveId
|
|
1408
|
+
});
|
|
1409
|
+
return {
|
|
1410
|
+
...rawOptions,
|
|
1411
|
+
plugins
|
|
1412
|
+
};
|
|
1413
|
+
},
|
|
1414
|
+
buildStart({ plugins }) {
|
|
1415
|
+
validateVersion(this.meta.rollupVersion, peerDependencies.rollup, "rollup");
|
|
1416
|
+
const nodeResolve = plugins.find(({ name }) => name === "node-resolve");
|
|
1417
|
+
if (nodeResolve) validateVersion(nodeResolve.version, "^13.0.6", "@rollup/plugin-node-resolve");
|
|
1418
|
+
if (options.namedExports != null) this.warn("The namedExports option from \"@rollup/plugin-commonjs\" is deprecated. Named exports are now handled automatically.");
|
|
1419
|
+
requireResolver = getRequireResolver(extensions, detectCyclesAndConditional, currentlyResolving);
|
|
1420
|
+
},
|
|
1421
|
+
buildEnd() {
|
|
1422
|
+
if (options.strictRequires === "debug") {
|
|
1423
|
+
const wrappedIds = requireResolver.getWrappedIds();
|
|
1424
|
+
if (wrappedIds.length) this.warn({
|
|
1425
|
+
code: "WRAPPED_IDS",
|
|
1426
|
+
ids: wrappedIds,
|
|
1427
|
+
message: `The commonjs plugin automatically wrapped the following files:\n[\n${wrappedIds.map((id) => `\t${JSON.stringify(relative(process.cwd(), id))}`).join(",\n")}\n]`
|
|
1428
|
+
});
|
|
1429
|
+
else this.warn({
|
|
1430
|
+
code: "WRAPPED_IDS",
|
|
1431
|
+
ids: wrappedIds,
|
|
1432
|
+
message: "The commonjs plugin did not wrap any files."
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
},
|
|
1436
|
+
async load(id) {
|
|
1437
|
+
if (id === HELPERS_ID) return getHelpersModule();
|
|
1438
|
+
if (isWrappedId(id, MODULE_SUFFIX)) {
|
|
1439
|
+
const name = getName(unwrapId(id, MODULE_SUFFIX));
|
|
1440
|
+
return {
|
|
1441
|
+
code: `var ${name} = {exports: {}}; export {${name} as __module}`,
|
|
1442
|
+
meta: { commonjs: { isCommonJS: false } }
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
if (isWrappedId(id, EXPORTS_SUFFIX)) {
|
|
1446
|
+
const name = getName(unwrapId(id, EXPORTS_SUFFIX));
|
|
1447
|
+
return {
|
|
1448
|
+
code: `var ${name} = {}; export {${name} as __exports}`,
|
|
1449
|
+
meta: { commonjs: { isCommonJS: false } }
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
if (isWrappedId(id, EXTERNAL_SUFFIX)) {
|
|
1453
|
+
const actualId = unwrapId(id, EXTERNAL_SUFFIX);
|
|
1454
|
+
if (actualId.startsWith("node:")) return getExternalBuiltinRequireProxy(actualId);
|
|
1455
|
+
return getUnknownRequireProxy(actualId, isEsmExternal(actualId) ? getRequireReturnsDefault(actualId) : true);
|
|
1456
|
+
}
|
|
1457
|
+
if (id.endsWith(ENTRY_SUFFIX)) {
|
|
1458
|
+
const acutalId = id.slice(0, -15);
|
|
1459
|
+
const { meta: { commonjs: commonjsMeta } } = this.getModuleInfo(acutalId);
|
|
1460
|
+
const shebang = commonjsMeta?.shebang ?? "";
|
|
1461
|
+
return getEntryProxy(acutalId, getDefaultIsModuleExports(acutalId), this.getModuleInfo, shebang);
|
|
1462
|
+
}
|
|
1463
|
+
if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
|
|
1464
|
+
const actualId = unwrapId(id, ES_IMPORT_SUFFIX);
|
|
1465
|
+
return getEsImportProxy(actualId, getDefaultIsModuleExports(actualId), (await this.load({ id: actualId })).moduleSideEffects);
|
|
1466
|
+
}
|
|
1467
|
+
if (id === DYNAMIC_MODULES_ID) return getDynamicModuleRegistry(isDynamicRequireModulesEnabled, dynamicRequireModules, commonDir, ignoreDynamicRequires);
|
|
1468
|
+
if (isWrappedId(id, PROXY_SUFFIX)) {
|
|
1469
|
+
const actualId = unwrapId(id, PROXY_SUFFIX);
|
|
1470
|
+
return getStaticRequireProxy(actualId, getRequireReturnsDefault(actualId), this.load);
|
|
1471
|
+
}
|
|
1472
|
+
return null;
|
|
1473
|
+
},
|
|
1474
|
+
shouldTransformCachedModule(...args) {
|
|
1475
|
+
return requireResolver.shouldTransformCachedModule.call(this, ...args);
|
|
1476
|
+
},
|
|
1477
|
+
transform(code, id) {
|
|
1478
|
+
if (!isPossibleCjsId(id)) return null;
|
|
1479
|
+
try {
|
|
1480
|
+
return transformAndCheckExports.call(this, code, id);
|
|
1481
|
+
} catch (err) {
|
|
1482
|
+
return this.error(err, err.pos);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
//#endregion
|
|
1489
|
+
export { makeLegalIdentifier as a, dataToEsm as i, attachScopes as n, createFilter as r, commonjs as t };
|