nitro-nightly 4.0.0-20251010-091516-7cafddba → 4.0.0-20251030-091344-d4418b98
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/{_chunks/build2.mjs → _build/build.mjs} +108 -58
- package/dist/_build/build2.mjs +556 -0
- package/dist/_build/info.mjs +1002 -0
- package/dist/_build/prepare.mjs +1511 -0
- package/dist/_build/snapshot.mjs +185 -0
- package/dist/{_chunks/plugin.mjs → _build/vite.mjs} +295 -296
- package/dist/_build/vite2.mjs +149 -0
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +189 -0
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +137 -0
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +231 -0
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +173 -0
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +170 -0
- package/dist/_chunks/_deps/@pi0/vite-plugin-fullstack.mjs +575 -0
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +89 -0
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +2376 -0
- package/dist/_chunks/{index2.mjs → _deps/@rollup/plugin-inject.mjs} +5 -90
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +37 -0
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +1386 -0
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +133 -0
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +346 -0
- package/dist/_chunks/_deps/acorn.mjs +6225 -0
- package/dist/_chunks/_deps/c12.mjs +510 -0
- package/dist/_chunks/_deps/chokidar.mjs +1428 -0
- package/dist/_chunks/_deps/citty.mjs +460 -0
- package/dist/_chunks/_deps/commondir.mjs +77 -0
- package/dist/_chunks/_deps/compatx.mjs +76 -0
- package/dist/_chunks/_deps/confbox.mjs +300 -0
- package/dist/_chunks/_deps/debug.mjs +885 -0
- package/dist/_chunks/_deps/deepmerge.mjs +147 -0
- package/dist/_chunks/_deps/depd.mjs +550 -0
- package/dist/_chunks/_deps/dot-prop.mjs +282 -0
- package/dist/_chunks/_deps/dotenv.mjs +555 -0
- package/dist/_chunks/_deps/duplexer.mjs +1 -0
- package/dist/_chunks/_deps/ee-first.mjs +104 -0
- package/dist/_chunks/_deps/encodeurl.mjs +69 -0
- package/dist/_chunks/_deps/escape-html.mjs +87 -0
- package/dist/_chunks/_deps/escape-string-regexp.mjs +13 -0
- package/dist/_chunks/_deps/estree-walker.mjs +433 -0
- package/dist/_chunks/_deps/etag.mjs +147 -0
- package/dist/_chunks/_deps/exsolve.mjs +1416 -0
- package/dist/_chunks/_deps/fdir.mjs +569 -0
- package/dist/_chunks/_deps/fresh.mjs +145 -0
- package/dist/_chunks/_deps/function-bind.mjs +106 -0
- package/dist/_chunks/{index4.mjs → _deps/giget.mjs} +21 -776
- package/dist/_chunks/_deps/gzip-size.mjs +19 -0
- package/dist/_chunks/_deps/hasown.mjs +19 -0
- package/dist/_chunks/_deps/http-errors.mjs +307 -0
- package/dist/_chunks/_deps/httpxy.mjs +580 -0
- package/dist/_chunks/_deps/inherits.mjs +57 -0
- package/dist/_chunks/_deps/is-core-module.mjs +596 -0
- package/dist/_chunks/_deps/is-module.mjs +25 -0
- package/dist/_chunks/_deps/is-reference.mjs +31 -0
- package/dist/_chunks/_deps/js-tokens.mjs +411 -0
- package/dist/_chunks/_deps/klona.mjs +137 -0
- package/dist/_chunks/_deps/knitwork.mjs +172 -0
- package/dist/_chunks/_deps/local-pkg.mjs +163 -0
- package/dist/_chunks/_deps/magic-string.mjs +1296 -0
- package/dist/_chunks/_deps/mime-db.mjs +11685 -0
- package/dist/_chunks/_deps/mime-types.mjs +287 -0
- package/dist/_chunks/_deps/mime.mjs +1172 -0
- package/dist/_chunks/_deps/mlly.mjs +2413 -0
- package/dist/_chunks/_deps/ms.mjs +172 -0
- package/dist/_chunks/_deps/node-fetch-native.mjs +3 -0
- package/dist/_chunks/_deps/nypm.mjs +219 -0
- package/dist/_chunks/_deps/on-finished.mjs +246 -0
- package/dist/_chunks/_deps/parseurl.mjs +168 -0
- package/dist/_chunks/_deps/path-parse.mjs +85 -0
- package/dist/_chunks/{pathe.M-eThtNZ.mjs → _deps/pathe.mjs} +48 -1
- package/dist/_chunks/_deps/perfect-debounce.mjs +88 -0
- package/dist/_chunks/_deps/picomatch.mjs +2144 -0
- package/dist/_chunks/_deps/pkg-types.mjs +247 -0
- package/dist/_chunks/{snapshot.mjs → _deps/pretty-bytes.mjs} +1 -105
- package/dist/_chunks/_deps/quansync.mjs +99 -0
- package/dist/_chunks/_deps/range-parser.mjs +171 -0
- package/dist/_chunks/_deps/rc9.mjs +219 -0
- package/dist/_chunks/_deps/readdirp.mjs +245 -0
- package/dist/_chunks/_deps/resolve.mjs +1260 -0
- package/dist/_chunks/_deps/rou3.mjs +326 -0
- package/dist/_chunks/_deps/send.mjs +1022 -0
- package/dist/_chunks/_deps/serve-static.mjs +228 -0
- package/dist/_chunks/_deps/setprototypeof.mjs +26 -0
- package/dist/_chunks/_deps/statuses.mjs +457 -0
- package/dist/_chunks/_deps/std-env.mjs +3 -0
- package/dist/_chunks/_deps/strip-literal.mjs +67 -0
- package/dist/_chunks/_deps/supports-color.mjs +44 -0
- package/dist/_chunks/_deps/tinyexec.mjs +552 -0
- package/dist/_chunks/_deps/tinyglobby.mjs +293 -0
- package/dist/_chunks/_deps/toidentifier.mjs +41 -0
- package/dist/_chunks/_deps/ultrahtml.mjs +3 -0
- package/dist/_chunks/_deps/unimport.mjs +2267 -0
- package/dist/_chunks/_deps/unplugin-utils.mjs +65 -0
- package/dist/_chunks/_deps/unplugin.mjs +1294 -0
- package/dist/_chunks/_deps/untyped.mjs +375 -0
- package/dist/_chunks/{info.mjs → _deps/unwasm.mjs} +8 -4206
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +360 -0
- package/dist/_chunks/_presets/_all.mjs +59 -0
- package/dist/_chunks/_presets/_nitro.mjs +74 -0
- package/dist/_chunks/_presets/_resolve.mjs +64 -0
- package/dist/_chunks/_presets/_static.mjs +69 -0
- package/dist/_chunks/_presets/_types.mjs +3 -0
- package/dist/_chunks/_presets/_utils.mjs +31 -0
- package/dist/_chunks/_presets/alwaysdata.mjs +17 -0
- package/dist/_chunks/_presets/aws-amplify.mjs +111 -0
- package/dist/_chunks/_presets/aws-lambda.mjs +23 -0
- package/dist/_chunks/_presets/azure.mjs +162 -0
- package/dist/_chunks/_presets/bun.mjs +19 -0
- package/dist/_chunks/_presets/cleavr.mjs +15 -0
- package/dist/_chunks/_presets/cloudflare.mjs +608 -0
- package/dist/_chunks/_presets/deno.mjs +196 -0
- package/dist/_chunks/_presets/digitalocean.mjs +14 -0
- package/dist/_chunks/_presets/firebase.mjs +47 -0
- package/dist/_chunks/_presets/flightcontrol.mjs +14 -0
- package/dist/_chunks/_presets/genezio.mjs +13 -0
- package/dist/_chunks/_presets/heroku.mjs +14 -0
- package/dist/_chunks/_presets/iis.mjs +194 -0
- package/dist/_chunks/_presets/index.mjs +62 -0
- package/dist/_chunks/_presets/koyeb.mjs +14 -0
- package/dist/_chunks/_presets/netlify.mjs +241 -0
- package/dist/_chunks/_presets/node.mjs +54 -0
- package/dist/_chunks/_presets/platform.mjs +14 -0
- package/dist/_chunks/_presets/render.mjs +14 -0
- package/dist/_chunks/_presets/standard.mjs +23 -0
- package/dist/_chunks/_presets/stormkit.mjs +18 -0
- package/dist/_chunks/_presets/vercel.mjs +375 -0
- package/dist/_chunks/_presets/winterjs.mjs +22 -0
- package/dist/_chunks/_presets/zeabur.mjs +69 -0
- package/dist/_chunks/_presets/zerops.mjs +27 -0
- package/dist/_chunks/app.mjs +9 -19206
- package/dist/_chunks/{index3.mjs → builder.mjs} +560 -970
- package/dist/_chunks/server.mjs +6 -4
- package/dist/{cli → _cli}/build.mjs +3 -8
- package/dist/{cli → _cli}/dev.mjs +38 -12
- package/dist/{cli/index2.mjs → _cli/index.mjs} +1 -2
- package/dist/{cli → _cli}/list.mjs +3 -4
- package/dist/{cli → _cli}/prepare.mjs +3 -4
- package/dist/{cli → _cli}/run.mjs +3 -4
- package/dist/{index.d.mts → builder.d.mts} +11 -11
- package/dist/builder.mjs +117 -0
- package/dist/cli/index.mjs +7 -464
- package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
- package/dist/node_modules/@speed-highlight/core/package.json +7 -3
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/hookable/dist/index.mjs +243 -266
- package/dist/node_modules/hookable/package.json +29 -26
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +4 -7
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +5 -4
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +7 -6
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -5
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +7 -10
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +21 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/node/runtime/node-server.mjs +1 -1
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/index.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +3 -1
- package/dist/runtime/internal/app.mjs +90 -64
- package/dist/runtime/internal/error/prod.d.mts +3 -2
- package/dist/runtime/internal/error/prod.mjs +9 -13
- package/dist/runtime/internal/renderer.mjs +4 -4
- package/dist/runtime/internal/routes/dev-tasks.d.mts +30 -2
- package/dist/runtime/internal/shutdown.d.mts +1 -2
- package/dist/runtime/internal/shutdown.mjs +3 -2
- package/dist/runtime/internal/task.mjs +1 -2
- package/dist/types/index.d.mts +1603 -10
- package/dist/vite.d.mts +5 -0
- package/dist/vite.mjs +94 -30
- package/lib/index.mjs +1 -0
- package/lib/indexd.mts +1 -0
- package/lib/runtime/meta.mjs +35 -0
- package/package.json +40 -41
- package/dist/_chunks/build.mjs +0 -84
- package/dist/_chunks/build3.mjs +0 -6452
- package/dist/_chunks/detect-acorn.mjs +0 -503
- package/dist/_chunks/index.mjs +0 -22242
- package/dist/_chunks/json5.mjs +0 -68
- package/dist/_chunks/jsonc.mjs +0 -51
- package/dist/_chunks/toml.mjs +0 -259
- package/dist/_chunks/yaml.mjs +0 -86
- package/dist/index.mjs +0 -55
- package/dist/node_modules/klona/dist/index.mjs +0 -81
- package/dist/node_modules/klona/full/index.mjs +0 -53
- package/dist/node_modules/klona/package.json +0 -74
- package/dist/node_modules/std-env/dist/index.mjs +0 -1
- package/dist/node_modules/std-env/package.json +0 -46
- package/dist/presets.mjs +0 -2460
- package/dist/runtime/internal/debug.d.mts +0 -2
- package/dist/runtime/internal/debug.mjs +0 -5
- package/lib/runtime-meta.mjs +0 -38
- /package/dist/{cli → _cli}/common.mjs +0 -0
- /package/lib/{runtime-meta.d.mts → runtime/meta.d.mts} +0 -0
|
@@ -1,3281 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { runtimeDir, runtimeDependencies } from 'nitro/runtime/meta';
|
|
5
|
-
import { j as join, r as resolve$2, i as isAbsolute$3, b as basename$1, d as dirname$1, e as extname$1, a as relative } from './pathe.M-eThtNZ.mjs';
|
|
6
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
-
import { createRequire, builtinModules } from 'node:module';
|
|
8
|
-
import { hash } from 'ohash';
|
|
9
|
-
import { defu } from 'defu';
|
|
10
|
-
import fs, { promises, existsSync } from 'node:fs';
|
|
11
|
-
import path, { resolve as resolve$3, isAbsolute as isAbsolute$2, normalize, dirname, basename, extname } from 'node:path';
|
|
12
|
-
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
13
|
-
import process$1 from 'node:process';
|
|
14
|
-
import * as querystring from 'node:querystring';
|
|
15
|
-
import { g as getDefaultExportFromCjs, r as requireEtag } from './app.mjs';
|
|
16
|
-
import require$$0 from 'constants';
|
|
17
|
-
import { camelCase } from 'scule';
|
|
18
|
-
import { readFile, mkdir, unlink, symlink } from 'node:fs/promises';
|
|
19
|
-
import 'node:os';
|
|
1
|
+
import { existsSync, promises } from 'node:fs';
|
|
2
|
+
import { M as MagicString } from './magic-string.mjs';
|
|
3
|
+
import { c as createUnplugin } from './unplugin.mjs';
|
|
20
4
|
import { createHash } from 'node:crypto';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { withTrailingSlash } from 'ufo';
|
|
24
|
-
import { normalizeKey, builtinDrivers } from 'unstorage';
|
|
25
|
-
import { rollupNodeFileTrace } from 'nf3';
|
|
26
|
-
import { hasTemplateSyntax, compileTemplateToString, RENDER_CONTEXT_KEYS } from 'rendu';
|
|
27
|
-
import { version } from 'nitro/meta';
|
|
28
|
-
|
|
29
|
-
// @ts-check
|
|
30
|
-
/** @typedef { import('estree').BaseNode} BaseNode */
|
|
31
|
-
|
|
32
|
-
/** @typedef {{
|
|
33
|
-
skip: () => void;
|
|
34
|
-
remove: () => void;
|
|
35
|
-
replace: (node: BaseNode) => void;
|
|
36
|
-
}} WalkerContext */
|
|
37
|
-
|
|
38
|
-
class WalkerBase {
|
|
39
|
-
constructor() {
|
|
40
|
-
/** @type {boolean} */
|
|
41
|
-
this.should_skip = false;
|
|
42
|
-
|
|
43
|
-
/** @type {boolean} */
|
|
44
|
-
this.should_remove = false;
|
|
45
|
-
|
|
46
|
-
/** @type {BaseNode | null} */
|
|
47
|
-
this.replacement = null;
|
|
48
|
-
|
|
49
|
-
/** @type {WalkerContext} */
|
|
50
|
-
this.context = {
|
|
51
|
-
skip: () => (this.should_skip = true),
|
|
52
|
-
remove: () => (this.should_remove = true),
|
|
53
|
-
replace: (node) => (this.replacement = node)
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
* @param {any} parent
|
|
60
|
-
* @param {string} prop
|
|
61
|
-
* @param {number} index
|
|
62
|
-
* @param {BaseNode} node
|
|
63
|
-
*/
|
|
64
|
-
replace(parent, prop, index, node) {
|
|
65
|
-
if (parent) {
|
|
66
|
-
if (index !== null) {
|
|
67
|
-
parent[prop][index] = node;
|
|
68
|
-
} else {
|
|
69
|
-
parent[prop] = node;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @param {any} parent
|
|
77
|
-
* @param {string} prop
|
|
78
|
-
* @param {number} index
|
|
79
|
-
*/
|
|
80
|
-
remove(parent, prop, index) {
|
|
81
|
-
if (parent) {
|
|
82
|
-
if (index !== null) {
|
|
83
|
-
parent[prop].splice(index, 1);
|
|
84
|
-
} else {
|
|
85
|
-
delete parent[prop];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// @ts-check
|
|
92
|
-
|
|
93
|
-
/** @typedef { import('estree').BaseNode} BaseNode */
|
|
94
|
-
/** @typedef { import('./walker.js').WalkerContext} WalkerContext */
|
|
95
|
-
|
|
96
|
-
/** @typedef {(
|
|
97
|
-
* this: WalkerContext,
|
|
98
|
-
* node: BaseNode,
|
|
99
|
-
* parent: BaseNode,
|
|
100
|
-
* key: string,
|
|
101
|
-
* index: number
|
|
102
|
-
* ) => void} SyncHandler */
|
|
103
|
-
|
|
104
|
-
class SyncWalker extends WalkerBase {
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
* @param {SyncHandler} enter
|
|
108
|
-
* @param {SyncHandler} leave
|
|
109
|
-
*/
|
|
110
|
-
constructor(enter, leave) {
|
|
111
|
-
super();
|
|
112
|
-
|
|
113
|
-
/** @type {SyncHandler} */
|
|
114
|
-
this.enter = enter;
|
|
115
|
-
|
|
116
|
-
/** @type {SyncHandler} */
|
|
117
|
-
this.leave = leave;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
* @param {BaseNode} node
|
|
123
|
-
* @param {BaseNode} parent
|
|
124
|
-
* @param {string} [prop]
|
|
125
|
-
* @param {number} [index]
|
|
126
|
-
* @returns {BaseNode}
|
|
127
|
-
*/
|
|
128
|
-
visit(node, parent, prop, index) {
|
|
129
|
-
if (node) {
|
|
130
|
-
if (this.enter) {
|
|
131
|
-
const _should_skip = this.should_skip;
|
|
132
|
-
const _should_remove = this.should_remove;
|
|
133
|
-
const _replacement = this.replacement;
|
|
134
|
-
this.should_skip = false;
|
|
135
|
-
this.should_remove = false;
|
|
136
|
-
this.replacement = null;
|
|
137
|
-
|
|
138
|
-
this.enter.call(this.context, node, parent, prop, index);
|
|
139
|
-
|
|
140
|
-
if (this.replacement) {
|
|
141
|
-
node = this.replacement;
|
|
142
|
-
this.replace(parent, prop, index, node);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (this.should_remove) {
|
|
146
|
-
this.remove(parent, prop, index);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const skipped = this.should_skip;
|
|
150
|
-
const removed = this.should_remove;
|
|
151
|
-
|
|
152
|
-
this.should_skip = _should_skip;
|
|
153
|
-
this.should_remove = _should_remove;
|
|
154
|
-
this.replacement = _replacement;
|
|
155
|
-
|
|
156
|
-
if (skipped) return node;
|
|
157
|
-
if (removed) return null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (const key in node) {
|
|
161
|
-
const value = node[key];
|
|
162
|
-
|
|
163
|
-
if (typeof value !== "object") {
|
|
164
|
-
continue;
|
|
165
|
-
} else if (Array.isArray(value)) {
|
|
166
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
167
|
-
if (value[i] !== null && typeof value[i].type === 'string') {
|
|
168
|
-
if (!this.visit(value[i], node, key, i)) {
|
|
169
|
-
// removed
|
|
170
|
-
i--;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
} else if (value !== null && typeof value.type === "string") {
|
|
175
|
-
this.visit(value, node, key, null);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (this.leave) {
|
|
180
|
-
const _replacement = this.replacement;
|
|
181
|
-
const _should_remove = this.should_remove;
|
|
182
|
-
this.replacement = null;
|
|
183
|
-
this.should_remove = false;
|
|
184
|
-
|
|
185
|
-
this.leave.call(this.context, node, parent, prop, index);
|
|
186
|
-
|
|
187
|
-
if (this.replacement) {
|
|
188
|
-
node = this.replacement;
|
|
189
|
-
this.replace(parent, prop, index, node);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this.should_remove) {
|
|
193
|
-
this.remove(parent, prop, index);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const removed = this.should_remove;
|
|
197
|
-
|
|
198
|
-
this.replacement = _replacement;
|
|
199
|
-
this.should_remove = _should_remove;
|
|
200
|
-
|
|
201
|
-
if (removed) return null;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return node;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// @ts-check
|
|
210
|
-
|
|
211
|
-
/** @typedef { import('estree').BaseNode} BaseNode */
|
|
212
|
-
/** @typedef { import('./sync.js').SyncHandler} SyncHandler */
|
|
213
|
-
/** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
*
|
|
217
|
-
* @param {BaseNode} ast
|
|
218
|
-
* @param {{
|
|
219
|
-
* enter?: SyncHandler
|
|
220
|
-
* leave?: SyncHandler
|
|
221
|
-
* }} walker
|
|
222
|
-
* @returns {BaseNode}
|
|
223
|
-
*/
|
|
224
|
-
function walk(ast, { enter, leave }) {
|
|
225
|
-
const instance = new SyncWalker(enter, leave);
|
|
226
|
-
return instance.visit(ast, null);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const extractors = {
|
|
230
|
-
ArrayPattern(names, param) {
|
|
231
|
-
for (const element of param.elements) {
|
|
232
|
-
if (element)
|
|
233
|
-
extractors[element.type](names, element);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
AssignmentPattern(names, param) {
|
|
237
|
-
extractors[param.left.type](names, param.left);
|
|
238
|
-
},
|
|
239
|
-
Identifier(names, param) {
|
|
240
|
-
names.push(param.name);
|
|
241
|
-
},
|
|
242
|
-
MemberExpression() { },
|
|
243
|
-
ObjectPattern(names, param) {
|
|
244
|
-
for (const prop of param.properties) {
|
|
245
|
-
// @ts-ignore Typescript reports that this is not a valid type
|
|
246
|
-
if (prop.type === 'RestElement') {
|
|
247
|
-
extractors.RestElement(names, prop);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
extractors[prop.value.type](names, prop.value);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
RestElement(names, param) {
|
|
255
|
-
extractors[param.argument.type](names, param.argument);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
const extractAssignedNames = function extractAssignedNames(param) {
|
|
259
|
-
const names = [];
|
|
260
|
-
extractors[param.type](names, param);
|
|
261
|
-
return names;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
const blockDeclarations = {
|
|
265
|
-
const: true,
|
|
266
|
-
let: true
|
|
267
|
-
};
|
|
268
|
-
class Scope {
|
|
269
|
-
constructor(options = {}) {
|
|
270
|
-
this.parent = options.parent;
|
|
271
|
-
this.isBlockScope = !!options.block;
|
|
272
|
-
this.declarations = Object.create(null);
|
|
273
|
-
if (options.params) {
|
|
274
|
-
options.params.forEach((param) => {
|
|
275
|
-
extractAssignedNames(param).forEach((name) => {
|
|
276
|
-
this.declarations[name] = true;
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
addDeclaration(node, isBlockDeclaration, isVar) {
|
|
282
|
-
if (!isBlockDeclaration && this.isBlockScope) {
|
|
283
|
-
// it's a `var` or function node, and this
|
|
284
|
-
// is a block scope, so we need to go up
|
|
285
|
-
this.parent.addDeclaration(node, isBlockDeclaration, isVar);
|
|
286
|
-
}
|
|
287
|
-
else if (node.id) {
|
|
288
|
-
extractAssignedNames(node.id).forEach((name) => {
|
|
289
|
-
this.declarations[name] = true;
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
contains(name) {
|
|
294
|
-
return this.declarations[name] || (this.parent ? this.parent.contains(name) : false);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const attachScopes = function attachScopes(ast, propertyName = 'scope') {
|
|
298
|
-
let scope = new Scope();
|
|
299
|
-
walk(ast, {
|
|
300
|
-
enter(n, parent) {
|
|
301
|
-
const node = n;
|
|
302
|
-
// function foo () {...}
|
|
303
|
-
// class Foo {...}
|
|
304
|
-
if (/(?:Function|Class)Declaration/.test(node.type)) {
|
|
305
|
-
scope.addDeclaration(node, false, false);
|
|
306
|
-
}
|
|
307
|
-
// var foo = 1
|
|
308
|
-
if (node.type === 'VariableDeclaration') {
|
|
309
|
-
const { kind } = node;
|
|
310
|
-
const isBlockDeclaration = blockDeclarations[kind];
|
|
311
|
-
node.declarations.forEach((declaration) => {
|
|
312
|
-
scope.addDeclaration(declaration, isBlockDeclaration, true);
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
let newScope;
|
|
316
|
-
// create new function scope
|
|
317
|
-
if (node.type.includes('Function')) {
|
|
318
|
-
const func = node;
|
|
319
|
-
newScope = new Scope({
|
|
320
|
-
parent: scope,
|
|
321
|
-
block: false,
|
|
322
|
-
params: func.params
|
|
323
|
-
});
|
|
324
|
-
// named function expressions - the name is considered
|
|
325
|
-
// part of the function's scope
|
|
326
|
-
if (func.type === 'FunctionExpression' && func.id) {
|
|
327
|
-
newScope.addDeclaration(func, false, false);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
// create new for scope
|
|
331
|
-
if (/For(?:In|Of)?Statement/.test(node.type)) {
|
|
332
|
-
newScope = new Scope({
|
|
333
|
-
parent: scope,
|
|
334
|
-
block: true
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
// create new block scope
|
|
338
|
-
if (node.type === 'BlockStatement' && !parent.type.includes('Function')) {
|
|
339
|
-
newScope = new Scope({
|
|
340
|
-
parent: scope,
|
|
341
|
-
block: true
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
// catch clause has its own block scope
|
|
345
|
-
if (node.type === 'CatchClause') {
|
|
346
|
-
newScope = new Scope({
|
|
347
|
-
parent: scope,
|
|
348
|
-
params: node.param ? [node.param] : [],
|
|
349
|
-
block: true
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
if (newScope) {
|
|
353
|
-
Object.defineProperty(node, propertyName, {
|
|
354
|
-
value: newScope,
|
|
355
|
-
configurable: true
|
|
356
|
-
});
|
|
357
|
-
scope = newScope;
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
leave(n) {
|
|
361
|
-
const node = n;
|
|
362
|
-
if (node[propertyName])
|
|
363
|
-
scope = scope.parent;
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
return scope;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
// Helper since Typescript can't detect readonly arrays with Array.isArray
|
|
370
|
-
function isArray$1(arg) {
|
|
371
|
-
return Array.isArray(arg);
|
|
372
|
-
}
|
|
373
|
-
function ensureArray(thing) {
|
|
374
|
-
if (isArray$1(thing))
|
|
375
|
-
return thing;
|
|
376
|
-
if (thing == null)
|
|
377
|
-
return [];
|
|
378
|
-
return [thing];
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
const normalizePathRegExp = new RegExp(`\\${win32.sep}`, 'g');
|
|
382
|
-
const normalizePath$2 = function normalizePath(filename) {
|
|
383
|
-
return filename.replace(normalizePathRegExp, posix.sep);
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
function getMatcherString$2(id, resolutionBase) {
|
|
387
|
-
if (resolutionBase === false || isAbsolute(id) || id.startsWith('**')) {
|
|
388
|
-
return normalizePath$2(id);
|
|
389
|
-
}
|
|
390
|
-
// resolve('') is valid and will default to process.cwd()
|
|
391
|
-
const basePath = normalizePath$2(resolve$1(resolutionBase || ''))
|
|
392
|
-
// escape all possible (posix + win) path characters that might interfere with regex
|
|
393
|
-
.replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
|
|
394
|
-
// Note that we use posix.join because:
|
|
395
|
-
// 1. the basePath has been normalized to use /
|
|
396
|
-
// 2. the incoming glob (id) matcher, also uses /
|
|
397
|
-
// otherwise Node will force backslash (\) on windows
|
|
398
|
-
return posix.join(basePath, normalizePath$2(id));
|
|
399
|
-
}
|
|
400
|
-
const createFilter$2 = function createFilter(include, exclude, options) {
|
|
401
|
-
const resolutionBase = options && options.resolve;
|
|
402
|
-
const getMatcher = (id) => id instanceof RegExp
|
|
403
|
-
? id
|
|
404
|
-
: {
|
|
405
|
-
test: (what) => {
|
|
406
|
-
// this refactor is a tad overly verbose but makes for easy debugging
|
|
407
|
-
const pattern = getMatcherString$2(id, resolutionBase);
|
|
408
|
-
const fn = pm(pattern, { dot: true });
|
|
409
|
-
const result = fn(what);
|
|
410
|
-
return result;
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
const includeMatchers = ensureArray(include).map(getMatcher);
|
|
414
|
-
const excludeMatchers = ensureArray(exclude).map(getMatcher);
|
|
415
|
-
if (!includeMatchers.length && !excludeMatchers.length)
|
|
416
|
-
return (id) => typeof id === 'string' && !id.includes('\0');
|
|
417
|
-
return function result(id) {
|
|
418
|
-
if (typeof id !== 'string')
|
|
419
|
-
return false;
|
|
420
|
-
if (id.includes('\0'))
|
|
421
|
-
return false;
|
|
422
|
-
const pathId = normalizePath$2(id);
|
|
423
|
-
for (let i = 0; i < excludeMatchers.length; ++i) {
|
|
424
|
-
const matcher = excludeMatchers[i];
|
|
425
|
-
if (matcher instanceof RegExp) {
|
|
426
|
-
matcher.lastIndex = 0;
|
|
427
|
-
}
|
|
428
|
-
if (matcher.test(pathId))
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
for (let i = 0; i < includeMatchers.length; ++i) {
|
|
432
|
-
const matcher = includeMatchers[i];
|
|
433
|
-
if (matcher instanceof RegExp) {
|
|
434
|
-
matcher.lastIndex = 0;
|
|
435
|
-
}
|
|
436
|
-
if (matcher.test(pathId))
|
|
437
|
-
return true;
|
|
438
|
-
}
|
|
439
|
-
return !includeMatchers.length;
|
|
440
|
-
};
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const reservedWords = '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';
|
|
444
|
-
const builtins = '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';
|
|
445
|
-
const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
446
|
-
forbiddenIdentifiers.add('');
|
|
447
|
-
const makeLegalIdentifier = function makeLegalIdentifier(str) {
|
|
448
|
-
let identifier = str
|
|
449
|
-
.replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
|
|
450
|
-
.replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
451
|
-
if (/\d/.test(identifier[0]) || forbiddenIdentifiers.has(identifier)) {
|
|
452
|
-
identifier = `_${identifier}`;
|
|
453
|
-
}
|
|
454
|
-
return identifier || '_';
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
function stringify(obj) {
|
|
458
|
-
return (JSON.stringify(obj) || 'undefined').replace(/[\u2028\u2029]/g, (char) => `\\u${`000${char.charCodeAt(0).toString(16)}`.slice(-4)}`);
|
|
459
|
-
}
|
|
460
|
-
function serializeArray(arr, indent, baseIndent) {
|
|
461
|
-
let output = '[';
|
|
462
|
-
const separator = indent ? `\n${baseIndent}${indent}` : '';
|
|
463
|
-
for (let i = 0; i < arr.length; i++) {
|
|
464
|
-
const key = arr[i];
|
|
465
|
-
output += `${i > 0 ? ',' : ''}${separator}${serialize(key, indent, baseIndent + indent)}`;
|
|
466
|
-
}
|
|
467
|
-
return `${output}${indent ? `\n${baseIndent}` : ''}]`;
|
|
468
|
-
}
|
|
469
|
-
function serializeObject(obj, indent, baseIndent) {
|
|
470
|
-
let output = '{';
|
|
471
|
-
const separator = indent ? `\n${baseIndent}${indent}` : '';
|
|
472
|
-
const entries = Object.entries(obj);
|
|
473
|
-
for (let i = 0; i < entries.length; i++) {
|
|
474
|
-
const [key, value] = entries[i];
|
|
475
|
-
const stringKey = makeLegalIdentifier(key) === key ? key : stringify(key);
|
|
476
|
-
output += `${i > 0 ? ',' : ''}${separator}${stringKey}:${indent ? ' ' : ''}${serialize(value, indent, baseIndent + indent)}`;
|
|
477
|
-
}
|
|
478
|
-
return `${output}${indent ? `\n${baseIndent}` : ''}}`;
|
|
479
|
-
}
|
|
480
|
-
function serialize(obj, indent, baseIndent) {
|
|
481
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
482
|
-
if (Array.isArray(obj))
|
|
483
|
-
return serializeArray(obj, indent, baseIndent);
|
|
484
|
-
if (obj instanceof Date)
|
|
485
|
-
return `new Date(${obj.getTime()})`;
|
|
486
|
-
if (obj instanceof RegExp)
|
|
487
|
-
return obj.toString();
|
|
488
|
-
return serializeObject(obj, indent, baseIndent);
|
|
489
|
-
}
|
|
490
|
-
if (typeof obj === 'number') {
|
|
491
|
-
if (obj === Infinity)
|
|
492
|
-
return 'Infinity';
|
|
493
|
-
if (obj === -Infinity)
|
|
494
|
-
return '-Infinity';
|
|
495
|
-
if (obj === 0)
|
|
496
|
-
return 1 / obj === Infinity ? '0' : '-0';
|
|
497
|
-
if (obj !== obj)
|
|
498
|
-
return 'NaN'; // eslint-disable-line no-self-compare
|
|
499
|
-
}
|
|
500
|
-
if (typeof obj === 'symbol') {
|
|
501
|
-
const key = Symbol.keyFor(obj);
|
|
502
|
-
// eslint-disable-next-line no-undefined
|
|
503
|
-
if (key !== undefined)
|
|
504
|
-
return `Symbol.for(${stringify(key)})`;
|
|
505
|
-
}
|
|
506
|
-
if (typeof obj === 'bigint')
|
|
507
|
-
return `${obj}n`;
|
|
508
|
-
return stringify(obj);
|
|
509
|
-
}
|
|
510
|
-
// isWellFormed exists from Node.js 20
|
|
511
|
-
const hasStringIsWellFormed = 'isWellFormed' in String.prototype;
|
|
512
|
-
function isWellFormedString(input) {
|
|
513
|
-
// @ts-expect-error String::isWellFormed exists from ES2024. tsconfig lib is set to ES6
|
|
514
|
-
if (hasStringIsWellFormed)
|
|
515
|
-
return input.isWellFormed();
|
|
516
|
-
// https://github.com/tc39/proposal-is-usv-string/blob/main/README.md#algorithm
|
|
517
|
-
return !/\p{Surrogate}/u.test(input);
|
|
518
|
-
}
|
|
519
|
-
const dataToEsm = function dataToEsm(data, options = {}) {
|
|
520
|
-
var _a, _b;
|
|
521
|
-
const t = options.compact ? '' : 'indent' in options ? options.indent : '\t';
|
|
522
|
-
const _ = options.compact ? '' : ' ';
|
|
523
|
-
const n = options.compact ? '' : '\n';
|
|
524
|
-
const declarationType = options.preferConst ? 'const' : 'var';
|
|
525
|
-
if (options.namedExports === false ||
|
|
526
|
-
typeof data !== 'object' ||
|
|
527
|
-
Array.isArray(data) ||
|
|
528
|
-
data instanceof Date ||
|
|
529
|
-
data instanceof RegExp ||
|
|
530
|
-
data === null) {
|
|
531
|
-
const code = serialize(data, options.compact ? null : t, '');
|
|
532
|
-
const magic = _ || (/^[{[\-\/]/.test(code) ? '' : ' '); // eslint-disable-line no-useless-escape
|
|
533
|
-
return `export default${magic}${code};`;
|
|
534
|
-
}
|
|
535
|
-
let maxUnderbarPrefixLength = 0;
|
|
536
|
-
for (const key of Object.keys(data)) {
|
|
537
|
-
const underbarPrefixLength = (_b = (_a = /^(_+)/.exec(key)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
538
|
-
if (underbarPrefixLength > maxUnderbarPrefixLength) {
|
|
539
|
-
maxUnderbarPrefixLength = underbarPrefixLength;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
const arbitraryNamePrefix = `${'_'.repeat(maxUnderbarPrefixLength + 1)}arbitrary`;
|
|
543
|
-
let namedExportCode = '';
|
|
544
|
-
const defaultExportRows = [];
|
|
545
|
-
const arbitraryNameExportRows = [];
|
|
546
|
-
for (const [key, value] of Object.entries(data)) {
|
|
547
|
-
if (key === makeLegalIdentifier(key)) {
|
|
548
|
-
if (options.objectShorthand)
|
|
549
|
-
defaultExportRows.push(key);
|
|
550
|
-
else
|
|
551
|
-
defaultExportRows.push(`${key}:${_}${key}`);
|
|
552
|
-
namedExportCode += `export ${declarationType} ${key}${_}=${_}${serialize(value, options.compact ? null : t, '')};${n}`;
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
defaultExportRows.push(`${stringify(key)}:${_}${serialize(value, options.compact ? null : t, '')}`);
|
|
556
|
-
if (options.includeArbitraryNames && isWellFormedString(key)) {
|
|
557
|
-
const variableName = `${arbitraryNamePrefix}${arbitraryNameExportRows.length}`;
|
|
558
|
-
namedExportCode += `${declarationType} ${variableName}${_}=${_}${serialize(value, options.compact ? null : t, '')};${n}`;
|
|
559
|
-
arbitraryNameExportRows.push(`${variableName} as ${JSON.stringify(key)}`);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
const arbitraryExportCode = arbitraryNameExportRows.length > 0
|
|
564
|
-
? `export${_}{${n}${t}${arbitraryNameExportRows.join(`,${n}${t}`)}${n}};${n}`
|
|
565
|
-
: '';
|
|
566
|
-
const defaultExportCode = `export default${_}{${n}${t}${defaultExportRows.join(`,${n}${t}`)}${n}};${n}`;
|
|
567
|
-
return `${namedExportCode}${arbitraryExportCode}${defaultExportCode}`;
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
function escape(str) {
|
|
571
|
-
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function ensureFunction(functionOrValue) {
|
|
575
|
-
if (typeof functionOrValue === 'function') { return functionOrValue; }
|
|
576
|
-
return function () { return functionOrValue; };
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
function longest(a, b) {
|
|
580
|
-
return b.length - a.length;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function getReplacements(options) {
|
|
584
|
-
if (options.values) {
|
|
585
|
-
return Object.assign({}, options.values);
|
|
586
|
-
}
|
|
587
|
-
var values = Object.assign({}, options);
|
|
588
|
-
delete values.delimiters;
|
|
589
|
-
delete values.include;
|
|
590
|
-
delete values.exclude;
|
|
591
|
-
delete values.sourcemap;
|
|
592
|
-
delete values.sourceMap;
|
|
593
|
-
delete values.objectGuards;
|
|
594
|
-
delete values.preventAssignment;
|
|
595
|
-
return values;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
function mapToFunctions(object) {
|
|
599
|
-
return Object.keys(object).reduce(function (fns, key) {
|
|
600
|
-
var functions = Object.assign({}, fns);
|
|
601
|
-
functions[key] = ensureFunction(object[key]);
|
|
602
|
-
return functions;
|
|
603
|
-
}, {});
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
var objKeyRegEx =
|
|
607
|
-
/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)(\.([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))+$/;
|
|
608
|
-
function expandTypeofReplacements(replacements) {
|
|
609
|
-
Object.keys(replacements).forEach(function (key) {
|
|
610
|
-
var objMatch = key.match(objKeyRegEx);
|
|
611
|
-
if (!objMatch) { return; }
|
|
612
|
-
var dotIndex = objMatch[1].length;
|
|
613
|
-
do {
|
|
614
|
-
// eslint-disable-next-line no-param-reassign
|
|
615
|
-
replacements[("typeof " + (key.slice(0, dotIndex)))] = '"object"';
|
|
616
|
-
dotIndex = key.indexOf('.', dotIndex + 1);
|
|
617
|
-
} while (dotIndex !== -1);
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
function replace$1(options) {
|
|
622
|
-
if ( options === void 0 ) options = {};
|
|
623
|
-
|
|
624
|
-
var filter = createFilter$2(options.include, options.exclude);
|
|
625
|
-
var delimiters = options.delimiters; if ( delimiters === void 0 ) delimiters = ['\\b', '\\b(?!\\.)'];
|
|
626
|
-
var preventAssignment = options.preventAssignment;
|
|
627
|
-
var objectGuards = options.objectGuards;
|
|
628
|
-
var replacements = getReplacements(options);
|
|
629
|
-
if (objectGuards) { expandTypeofReplacements(replacements); }
|
|
630
|
-
var functionValues = mapToFunctions(replacements);
|
|
631
|
-
var keys = Object.keys(functionValues).sort(longest).map(escape);
|
|
632
|
-
var lookbehind = preventAssignment ? '(?<!\\b(?:const|let|var)\\s*)' : '';
|
|
633
|
-
var lookahead = preventAssignment ? '(?!\\s*=[^=])' : '';
|
|
634
|
-
var pattern = new RegExp(
|
|
635
|
-
("" + lookbehind + (delimiters[0]) + "(" + (keys.join('|')) + ")" + (delimiters[1]) + lookahead),
|
|
636
|
-
'g'
|
|
637
|
-
);
|
|
638
|
-
|
|
639
|
-
return {
|
|
640
|
-
name: 'replace',
|
|
641
|
-
|
|
642
|
-
buildStart: function buildStart() {
|
|
643
|
-
if (![true, false].includes(preventAssignment)) {
|
|
644
|
-
this.warn({
|
|
645
|
-
message:
|
|
646
|
-
"@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`."
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
|
|
651
|
-
renderChunk: function renderChunk(code, chunk) {
|
|
652
|
-
var id = chunk.fileName;
|
|
653
|
-
if (!keys.length) { return null; }
|
|
654
|
-
if (!filter(id)) { return null; }
|
|
655
|
-
return executeReplacement(code, id);
|
|
656
|
-
},
|
|
657
|
-
|
|
658
|
-
transform: function transform(code, id) {
|
|
659
|
-
if (!keys.length) { return null; }
|
|
660
|
-
if (!filter(id)) { return null; }
|
|
661
|
-
return executeReplacement(code, id);
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
function executeReplacement(code, id) {
|
|
666
|
-
var magicString = new MagicString(code);
|
|
667
|
-
if (!codeHasReplacements(code, id, magicString)) {
|
|
668
|
-
return null;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
var result = { code: magicString.toString() };
|
|
672
|
-
if (isSourceMapEnabled()) {
|
|
673
|
-
result.map = magicString.generateMap({ hires: true });
|
|
674
|
-
}
|
|
675
|
-
return result;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
function codeHasReplacements(code, id, magicString) {
|
|
679
|
-
var result = false;
|
|
680
|
-
var match;
|
|
681
|
-
|
|
682
|
-
// eslint-disable-next-line no-cond-assign
|
|
683
|
-
while ((match = pattern.exec(code))) {
|
|
684
|
-
result = true;
|
|
685
|
-
|
|
686
|
-
var start = match.index;
|
|
687
|
-
var end = start + match[0].length;
|
|
688
|
-
var replacement = String(functionValues[match[1]](id));
|
|
689
|
-
magicString.overwrite(start, end, replacement);
|
|
690
|
-
}
|
|
691
|
-
return result;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
function isSourceMapEnabled() {
|
|
695
|
-
return options.sourceMap !== false && options.sourcemap !== false;
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
const NO_REPLACE_RE = /ROLLUP_NO_REPLACE|\\0raw:/;
|
|
700
|
-
function replace(options) {
|
|
701
|
-
const _plugin = replace$1(options);
|
|
702
|
-
return {
|
|
703
|
-
..._plugin,
|
|
704
|
-
// https://github.com/rollup/plugins/blob/master/packages/replace/src/index.js#L94
|
|
705
|
-
renderChunk(code, chunk, options2) {
|
|
706
|
-
if (!NO_REPLACE_RE.test(code)) {
|
|
707
|
-
return _plugin.renderChunk.call(this, code, chunk, options2);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function baseBuildConfig(nitro) {
|
|
714
|
-
const buildServerDir = join(nitro.options.buildDir, "dist/server");
|
|
715
|
-
const presetsDir = resolve$2(runtimeDir, "../presets");
|
|
716
|
-
const extensions = [".ts", ".mjs", ".js", ".json", ".node", ".tsx", ".jsx"];
|
|
717
|
-
const isNodeless = nitro.options.node === false;
|
|
718
|
-
let NODE_ENV = nitro.options.dev ? "development" : "production";
|
|
719
|
-
if (nitro.options.preset === "nitro-prerender") {
|
|
720
|
-
NODE_ENV = "prerender";
|
|
721
|
-
}
|
|
722
|
-
const buildEnvVars = {
|
|
723
|
-
NODE_ENV,
|
|
724
|
-
prerender: nitro.options.preset === "nitro-prerender",
|
|
725
|
-
server: true,
|
|
726
|
-
client: false,
|
|
727
|
-
dev: String(nitro.options.dev),
|
|
728
|
-
DEBUG: nitro.options.dev
|
|
729
|
-
};
|
|
730
|
-
const staticFlags = {
|
|
731
|
-
dev: nitro.options.dev,
|
|
732
|
-
preset: nitro.options.preset,
|
|
733
|
-
prerender: nitro.options.preset === "nitro-prerender",
|
|
734
|
-
server: true,
|
|
735
|
-
client: false,
|
|
736
|
-
nitro: true,
|
|
737
|
-
baseURL: nitro.options.baseURL,
|
|
738
|
-
// @ts-expect-error
|
|
739
|
-
"versions.nitro": "",
|
|
740
|
-
"versions?.nitro": "",
|
|
741
|
-
// Internal
|
|
742
|
-
_asyncContext: nitro.options.experimental.asyncContext,
|
|
743
|
-
_websocket: nitro.options.experimental.websocket,
|
|
744
|
-
_tasks: nitro.options.experimental.tasks
|
|
745
|
-
};
|
|
746
|
-
const replacements = {
|
|
747
|
-
"typeof window": '"undefined"',
|
|
748
|
-
_import_meta_url_: "import.meta.url",
|
|
749
|
-
"globalThis.process.": "process.",
|
|
750
|
-
"process.env.RUNTIME_CONFIG": () => JSON.stringify(nitro.options.runtimeConfig, null, 2),
|
|
751
|
-
...Object.fromEntries(
|
|
752
|
-
Object.entries(buildEnvVars).map(([key, val]) => [
|
|
753
|
-
`process.env.${key}`,
|
|
754
|
-
JSON.stringify(val)
|
|
755
|
-
])
|
|
756
|
-
),
|
|
757
|
-
...Object.fromEntries(
|
|
758
|
-
Object.entries(buildEnvVars).map(([key, val]) => [
|
|
759
|
-
`import.meta.env.${key}`,
|
|
760
|
-
JSON.stringify(val)
|
|
761
|
-
])
|
|
762
|
-
),
|
|
763
|
-
...Object.fromEntries(
|
|
764
|
-
Object.entries(staticFlags).map(([key, val]) => [
|
|
765
|
-
`process.${key}`,
|
|
766
|
-
JSON.stringify(val)
|
|
767
|
-
])
|
|
768
|
-
),
|
|
769
|
-
...Object.fromEntries(
|
|
770
|
-
Object.entries(staticFlags).map(([key, val]) => [
|
|
771
|
-
`import.meta.${key}`,
|
|
772
|
-
JSON.stringify(val)
|
|
773
|
-
])
|
|
774
|
-
),
|
|
775
|
-
...nitro.options.replace
|
|
776
|
-
};
|
|
777
|
-
const { env } = defineEnv({
|
|
778
|
-
nodeCompat: isNodeless,
|
|
779
|
-
npmShims: true,
|
|
780
|
-
resolve: true,
|
|
781
|
-
presets: nitro.options.unenv,
|
|
782
|
-
overrides: {
|
|
783
|
-
alias: nitro.options.alias
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
const aliases = resolveAliases({
|
|
787
|
-
"#internal/nitro": runtimeDir,
|
|
788
|
-
"nitro/runtime": runtimeDir,
|
|
789
|
-
"nitropack/runtime": runtimeDir,
|
|
790
|
-
// Backwards compatibility
|
|
791
|
-
...env.alias
|
|
792
|
-
});
|
|
793
|
-
return {
|
|
794
|
-
buildServerDir,
|
|
795
|
-
presetsDir,
|
|
796
|
-
extensions,
|
|
797
|
-
isNodeless,
|
|
798
|
-
buildEnvVars,
|
|
799
|
-
staticFlags,
|
|
800
|
-
replacements,
|
|
801
|
-
env,
|
|
802
|
-
aliases
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
function resolveAliases(_aliases) {
|
|
806
|
-
const aliases = Object.fromEntries(
|
|
807
|
-
Object.entries(_aliases).sort(
|
|
808
|
-
([a], [b]) => b.split("/").length - a.split("/").length || b.length - a.length
|
|
809
|
-
)
|
|
810
|
-
);
|
|
811
|
-
for (const key in aliases) {
|
|
812
|
-
for (const alias in aliases) {
|
|
813
|
-
if (!["~", "@", "#"].includes(alias[0])) {
|
|
814
|
-
continue;
|
|
815
|
-
}
|
|
816
|
-
if (alias === "@" && !aliases[key].startsWith("@/")) {
|
|
817
|
-
continue;
|
|
818
|
-
}
|
|
819
|
-
if (aliases[key].startsWith(alias)) {
|
|
820
|
-
aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return aliases;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
//#region src/utils/general.ts
|
|
828
|
-
function toArray$2(array) {
|
|
829
|
-
array = array || [];
|
|
830
|
-
if (Array.isArray(array)) return array;
|
|
831
|
-
return [array];
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
//#endregion
|
|
835
|
-
//#region src/utils/filter.ts
|
|
836
|
-
const BACKSLASH_REGEX = /\\/g;
|
|
837
|
-
function normalize$1(path$1) {
|
|
838
|
-
return path$1.replace(BACKSLASH_REGEX, "/");
|
|
839
|
-
}
|
|
840
|
-
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
841
|
-
function isAbsolute$1(path$1) {
|
|
842
|
-
return ABSOLUTE_PATH_REGEX.test(path$1);
|
|
843
|
-
}
|
|
844
|
-
function getMatcherString$1(glob, cwd) {
|
|
845
|
-
if (glob.startsWith("**") || isAbsolute$1(glob)) return normalize$1(glob);
|
|
846
|
-
const resolved = resolve$3(cwd, glob);
|
|
847
|
-
return normalize$1(resolved);
|
|
848
|
-
}
|
|
849
|
-
function patternToIdFilter(pattern) {
|
|
850
|
-
if (pattern instanceof RegExp) return (id) => {
|
|
851
|
-
const normalizedId = normalize$1(id);
|
|
852
|
-
const result = pattern.test(normalizedId);
|
|
853
|
-
pattern.lastIndex = 0;
|
|
854
|
-
return result;
|
|
855
|
-
};
|
|
856
|
-
const cwd = process.cwd();
|
|
857
|
-
const glob = getMatcherString$1(pattern, cwd);
|
|
858
|
-
const matcher = pm(glob, { dot: true });
|
|
859
|
-
return (id) => {
|
|
860
|
-
const normalizedId = normalize$1(id);
|
|
861
|
-
return matcher(normalizedId);
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
function patternToCodeFilter(pattern) {
|
|
865
|
-
if (pattern instanceof RegExp) return (code) => {
|
|
866
|
-
const result = pattern.test(code);
|
|
867
|
-
pattern.lastIndex = 0;
|
|
868
|
-
return result;
|
|
869
|
-
};
|
|
870
|
-
return (code) => code.includes(pattern);
|
|
871
|
-
}
|
|
872
|
-
function createFilter$1(exclude, include) {
|
|
873
|
-
if (!exclude && !include) return;
|
|
874
|
-
return (input) => {
|
|
875
|
-
if (exclude?.some((filter) => filter(input))) return false;
|
|
876
|
-
if (include?.some((filter) => filter(input))) return true;
|
|
877
|
-
return !(include && include.length > 0);
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
function normalizeFilter(filter) {
|
|
881
|
-
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
882
|
-
if (Array.isArray(filter)) return { include: filter };
|
|
883
|
-
return {
|
|
884
|
-
exclude: filter.exclude ? toArray$2(filter.exclude) : void 0,
|
|
885
|
-
include: filter.include ? toArray$2(filter.include) : void 0
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
function createIdFilter(filter) {
|
|
889
|
-
if (!filter) return;
|
|
890
|
-
const { exclude, include } = normalizeFilter(filter);
|
|
891
|
-
const excludeFilter = exclude?.map(patternToIdFilter);
|
|
892
|
-
const includeFilter = include?.map(patternToIdFilter);
|
|
893
|
-
return createFilter$1(excludeFilter, includeFilter);
|
|
894
|
-
}
|
|
895
|
-
function createCodeFilter(filter) {
|
|
896
|
-
if (!filter) return;
|
|
897
|
-
const { exclude, include } = normalizeFilter(filter);
|
|
898
|
-
const excludeFilter = exclude?.map(patternToCodeFilter);
|
|
899
|
-
const includeFilter = include?.map(patternToCodeFilter);
|
|
900
|
-
return createFilter$1(excludeFilter, includeFilter);
|
|
901
|
-
}
|
|
902
|
-
function createFilterForId(filter) {
|
|
903
|
-
const filterFunction = createIdFilter(filter);
|
|
904
|
-
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
905
|
-
}
|
|
906
|
-
function createFilterForTransform(idFilter, codeFilter) {
|
|
907
|
-
if (!idFilter && !codeFilter) return;
|
|
908
|
-
const idFilterFunction = createIdFilter(idFilter);
|
|
909
|
-
const codeFilterFunction = createCodeFilter(codeFilter);
|
|
910
|
-
return (id, code) => {
|
|
911
|
-
let fallback = true;
|
|
912
|
-
if (idFilterFunction) fallback &&= idFilterFunction(id);
|
|
913
|
-
if (!fallback) return false;
|
|
914
|
-
if (codeFilterFunction) fallback &&= codeFilterFunction(code);
|
|
915
|
-
return fallback;
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
function normalizeObjectHook(name, hook) {
|
|
919
|
-
let handler;
|
|
920
|
-
let filter;
|
|
921
|
-
if (typeof hook === "function") handler = hook;
|
|
922
|
-
else {
|
|
923
|
-
handler = hook.handler;
|
|
924
|
-
const hookFilter = hook.filter;
|
|
925
|
-
if (name === "resolveId" || name === "load") filter = createFilterForId(hookFilter?.id);
|
|
926
|
-
else filter = createFilterForTransform(hookFilter?.id, hookFilter?.code);
|
|
927
|
-
}
|
|
928
|
-
return {
|
|
929
|
-
handler,
|
|
930
|
-
filter: filter || (() => true)
|
|
931
|
-
};
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
//#endregion
|
|
935
|
-
//#region src/utils/context.ts
|
|
936
|
-
function parse$1(code, opts = {}) {
|
|
937
|
-
return Parser.parse(code, {
|
|
938
|
-
sourceType: "module",
|
|
939
|
-
ecmaVersion: "latest",
|
|
940
|
-
locations: true,
|
|
941
|
-
...opts
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
//#region src/utils/webpack-like.ts
|
|
946
|
-
function transformUse(data, plugin, transformLoader) {
|
|
947
|
-
if (data.resource == null) return [];
|
|
948
|
-
const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || ""));
|
|
949
|
-
if (plugin.transformInclude && !plugin.transformInclude(id)) return [];
|
|
950
|
-
const { filter } = normalizeObjectHook("load", plugin.transform);
|
|
951
|
-
if (!filter(id)) return [];
|
|
952
|
-
return [{
|
|
953
|
-
loader: transformLoader,
|
|
954
|
-
options: { plugin },
|
|
955
|
-
ident: plugin.name
|
|
956
|
-
}];
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* Normalizes a given path when it's absolute. Normalizing means returning a new path by converting
|
|
960
|
-
* the input path to the native os format. This is useful in cases where we want to normalize
|
|
961
|
-
* the `id` argument of a hook. Any absolute ids should be in the default format
|
|
962
|
-
* of the operating system. Any relative imports or node_module imports should remain
|
|
963
|
-
* untouched.
|
|
964
|
-
*
|
|
965
|
-
* @param path - Path to normalize.
|
|
966
|
-
* @returns a new normalized path.
|
|
967
|
-
*/
|
|
968
|
-
function normalizeAbsolutePath(path$1) {
|
|
969
|
-
if (isAbsolute$2(path$1)) return normalize(path$1);
|
|
970
|
-
else return path$1;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
//#region src/rspack/context.ts
|
|
974
|
-
function createBuildContext$1(compiler, compilation, loaderContext) {
|
|
975
|
-
return {
|
|
976
|
-
getNativeBuildContext() {
|
|
977
|
-
return {
|
|
978
|
-
framework: "rspack",
|
|
979
|
-
compiler,
|
|
980
|
-
compilation,
|
|
981
|
-
loaderContext
|
|
982
|
-
};
|
|
983
|
-
},
|
|
984
|
-
addWatchFile(file) {
|
|
985
|
-
const cwd = process.cwd();
|
|
986
|
-
compilation.fileDependencies.add(resolve$3(cwd, file));
|
|
987
|
-
},
|
|
988
|
-
getWatchFiles() {
|
|
989
|
-
return Array.from(compilation.fileDependencies);
|
|
990
|
-
},
|
|
991
|
-
parse: parse$1,
|
|
992
|
-
emitFile(emittedFile) {
|
|
993
|
-
const outFileName = emittedFile.fileName || emittedFile.name;
|
|
994
|
-
if (emittedFile.source && outFileName) {
|
|
995
|
-
const { sources } = compilation.compiler.webpack;
|
|
996
|
-
compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer$1.from(emittedFile.source)));
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
function normalizeMessage$1(error) {
|
|
1002
|
-
const err = new Error(typeof error === "string" ? error : error.message);
|
|
1003
|
-
if (typeof error === "object") {
|
|
1004
|
-
err.stack = error.stack;
|
|
1005
|
-
err.cause = error.meta;
|
|
1006
|
-
}
|
|
1007
|
-
return err;
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
//#region src/rspack/utils.ts
|
|
1011
|
-
function encodeVirtualModuleId(id, plugin) {
|
|
1012
|
-
return resolve$3(plugin.__virtualModulePrefix, encodeURIComponent(id));
|
|
1013
|
-
}
|
|
1014
|
-
function decodeVirtualModuleId(encoded, _plugin) {
|
|
1015
|
-
return decodeURIComponent(basename(encoded));
|
|
1016
|
-
}
|
|
1017
|
-
function isVirtualModuleId(encoded, plugin) {
|
|
1018
|
-
return dirname(encoded) === plugin.__virtualModulePrefix;
|
|
1019
|
-
}
|
|
1020
|
-
var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin {
|
|
1021
|
-
name = "FakeVirtualModulesPlugin";
|
|
1022
|
-
static counters = /* @__PURE__ */ new Map();
|
|
1023
|
-
static initCleanup = false;
|
|
1024
|
-
constructor(plugin) {
|
|
1025
|
-
this.plugin = plugin;
|
|
1026
|
-
if (!FakeVirtualModulesPlugin.initCleanup) {
|
|
1027
|
-
FakeVirtualModulesPlugin.initCleanup = true;
|
|
1028
|
-
process.once("exit", () => {
|
|
1029
|
-
FakeVirtualModulesPlugin.counters.forEach((_, dir) => {
|
|
1030
|
-
fs.rmSync(dir, {
|
|
1031
|
-
recursive: true,
|
|
1032
|
-
force: true
|
|
1033
|
-
});
|
|
1034
|
-
});
|
|
1035
|
-
});
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
apply(compiler) {
|
|
1039
|
-
const dir = this.plugin.__virtualModulePrefix;
|
|
1040
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
1041
|
-
const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0;
|
|
1042
|
-
FakeVirtualModulesPlugin.counters.set(dir, counter + 1);
|
|
1043
|
-
compiler.hooks.shutdown.tap(this.name, () => {
|
|
1044
|
-
const counter$1 = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1;
|
|
1045
|
-
if (counter$1 === 0) {
|
|
1046
|
-
FakeVirtualModulesPlugin.counters.delete(dir);
|
|
1047
|
-
fs.rmSync(dir, {
|
|
1048
|
-
recursive: true,
|
|
1049
|
-
force: true
|
|
1050
|
-
});
|
|
1051
|
-
} else FakeVirtualModulesPlugin.counters.set(dir, counter$1);
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
async writeModule(file) {
|
|
1055
|
-
return fs.promises.writeFile(file, "");
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
//#region src/webpack/context.ts
|
|
1060
|
-
function contextOptionsFromCompilation(compilation) {
|
|
1061
|
-
return {
|
|
1062
|
-
addWatchFile(file) {
|
|
1063
|
-
(compilation.fileDependencies ?? compilation.compilationDependencies).add(file);
|
|
1064
|
-
},
|
|
1065
|
-
getWatchFiles() {
|
|
1066
|
-
return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies);
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
const require = createRequire(import.meta.url);
|
|
1071
|
-
function getSource(fileSource) {
|
|
1072
|
-
const webpack = require("webpack");
|
|
1073
|
-
return new webpack.sources.RawSource(typeof fileSource === "string" ? fileSource : Buffer$1.from(fileSource.buffer));
|
|
1074
|
-
}
|
|
1075
|
-
function createBuildContext(options, compiler, compilation, loaderContext) {
|
|
1076
|
-
return {
|
|
1077
|
-
parse: parse$1,
|
|
1078
|
-
addWatchFile(id) {
|
|
1079
|
-
options.addWatchFile(resolve$3(process$1.cwd(), id));
|
|
1080
|
-
},
|
|
1081
|
-
emitFile(emittedFile) {
|
|
1082
|
-
const outFileName = emittedFile.fileName || emittedFile.name;
|
|
1083
|
-
if (emittedFile.source && outFileName) {
|
|
1084
|
-
if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
|
|
1085
|
-
compilation.emitAsset(outFileName, getSource(emittedFile.source));
|
|
1086
|
-
}
|
|
1087
|
-
},
|
|
1088
|
-
getWatchFiles() {
|
|
1089
|
-
return options.getWatchFiles();
|
|
1090
|
-
},
|
|
1091
|
-
getNativeBuildContext() {
|
|
1092
|
-
return {
|
|
1093
|
-
framework: "webpack",
|
|
1094
|
-
compiler,
|
|
1095
|
-
compilation,
|
|
1096
|
-
loaderContext
|
|
1097
|
-
};
|
|
1098
|
-
}
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
function normalizeMessage(error) {
|
|
1102
|
-
const err = new Error(typeof error === "string" ? error : error.message);
|
|
1103
|
-
if (typeof error === "object") {
|
|
1104
|
-
err.stack = error.stack;
|
|
1105
|
-
err.cause = error.meta;
|
|
1106
|
-
}
|
|
1107
|
-
return err;
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
// Matches the scheme of a URL, eg "http://"
|
|
1111
|
-
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
1112
|
-
/**
|
|
1113
|
-
* Matches the parts of a URL:
|
|
1114
|
-
* 1. Scheme, including ":", guaranteed.
|
|
1115
|
-
* 2. User/password, including "@", optional.
|
|
1116
|
-
* 3. Host, guaranteed.
|
|
1117
|
-
* 4. Port, including ":", optional.
|
|
1118
|
-
* 5. Path, including "/", optional.
|
|
1119
|
-
* 6. Query, including "?", optional.
|
|
1120
|
-
* 7. Hash, including "#", optional.
|
|
1121
|
-
*/
|
|
1122
|
-
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
1123
|
-
/**
|
|
1124
|
-
* File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
|
|
1125
|
-
* with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
|
|
1126
|
-
*
|
|
1127
|
-
* 1. Host, optional.
|
|
1128
|
-
* 2. Path, which may include "/", guaranteed.
|
|
1129
|
-
* 3. Query, including "?", optional.
|
|
1130
|
-
* 4. Hash, including "#", optional.
|
|
1131
|
-
*/
|
|
1132
|
-
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
1133
|
-
function isAbsoluteUrl(input) {
|
|
1134
|
-
return schemeRegex.test(input);
|
|
1135
|
-
}
|
|
1136
|
-
function isSchemeRelativeUrl(input) {
|
|
1137
|
-
return input.startsWith('//');
|
|
1138
|
-
}
|
|
1139
|
-
function isAbsolutePath(input) {
|
|
1140
|
-
return input.startsWith('/');
|
|
1141
|
-
}
|
|
1142
|
-
function isFileUrl(input) {
|
|
1143
|
-
return input.startsWith('file:');
|
|
1144
|
-
}
|
|
1145
|
-
function isRelative(input) {
|
|
1146
|
-
return /^[.?#]/.test(input);
|
|
1147
|
-
}
|
|
1148
|
-
function parseAbsoluteUrl(input) {
|
|
1149
|
-
const match = urlRegex.exec(input);
|
|
1150
|
-
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
|
|
1151
|
-
}
|
|
1152
|
-
function parseFileUrl(input) {
|
|
1153
|
-
const match = fileRegex.exec(input);
|
|
1154
|
-
const path = match[2];
|
|
1155
|
-
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
|
|
1156
|
-
}
|
|
1157
|
-
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
1158
|
-
return {
|
|
1159
|
-
scheme,
|
|
1160
|
-
user,
|
|
1161
|
-
host,
|
|
1162
|
-
port,
|
|
1163
|
-
path,
|
|
1164
|
-
query,
|
|
1165
|
-
hash,
|
|
1166
|
-
type: 7 /* Absolute */,
|
|
1167
|
-
};
|
|
1168
|
-
}
|
|
1169
|
-
function parseUrl(input) {
|
|
1170
|
-
if (isSchemeRelativeUrl(input)) {
|
|
1171
|
-
const url = parseAbsoluteUrl('http:' + input);
|
|
1172
|
-
url.scheme = '';
|
|
1173
|
-
url.type = 6 /* SchemeRelative */;
|
|
1174
|
-
return url;
|
|
1175
|
-
}
|
|
1176
|
-
if (isAbsolutePath(input)) {
|
|
1177
|
-
const url = parseAbsoluteUrl('http://foo.com' + input);
|
|
1178
|
-
url.scheme = '';
|
|
1179
|
-
url.host = '';
|
|
1180
|
-
url.type = 5 /* AbsolutePath */;
|
|
1181
|
-
return url;
|
|
1182
|
-
}
|
|
1183
|
-
if (isFileUrl(input))
|
|
1184
|
-
return parseFileUrl(input);
|
|
1185
|
-
if (isAbsoluteUrl(input))
|
|
1186
|
-
return parseAbsoluteUrl(input);
|
|
1187
|
-
const url = parseAbsoluteUrl('http://foo.com/' + input);
|
|
1188
|
-
url.scheme = '';
|
|
1189
|
-
url.host = '';
|
|
1190
|
-
url.type = input
|
|
1191
|
-
? input.startsWith('?')
|
|
1192
|
-
? 3 /* Query */
|
|
1193
|
-
: input.startsWith('#')
|
|
1194
|
-
? 2 /* Hash */
|
|
1195
|
-
: 4 /* RelativePath */
|
|
1196
|
-
: 1 /* Empty */;
|
|
1197
|
-
return url;
|
|
1198
|
-
}
|
|
1199
|
-
function stripPathFilename(path) {
|
|
1200
|
-
// If a path ends with a parent directory "..", then it's a relative path with excess parent
|
|
1201
|
-
// paths. It's not a file, so we can't strip it.
|
|
1202
|
-
if (path.endsWith('/..'))
|
|
1203
|
-
return path;
|
|
1204
|
-
const index = path.lastIndexOf('/');
|
|
1205
|
-
return path.slice(0, index + 1);
|
|
1206
|
-
}
|
|
1207
|
-
function mergePaths(url, base) {
|
|
1208
|
-
normalizePath$1(base, base.type);
|
|
1209
|
-
// If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
|
|
1210
|
-
// path).
|
|
1211
|
-
if (url.path === '/') {
|
|
1212
|
-
url.path = base.path;
|
|
1213
|
-
}
|
|
1214
|
-
else {
|
|
1215
|
-
// Resolution happens relative to the base path's directory, not the file.
|
|
1216
|
-
url.path = stripPathFilename(base.path) + url.path;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* The path can have empty directories "//", unneeded parents "foo/..", or current directory
|
|
1221
|
-
* "foo/.". We need to normalize to a standard representation.
|
|
1222
|
-
*/
|
|
1223
|
-
function normalizePath$1(url, type) {
|
|
1224
|
-
const rel = type <= 4 /* RelativePath */;
|
|
1225
|
-
const pieces = url.path.split('/');
|
|
1226
|
-
// We need to preserve the first piece always, so that we output a leading slash. The item at
|
|
1227
|
-
// pieces[0] is an empty string.
|
|
1228
|
-
let pointer = 1;
|
|
1229
|
-
// Positive is the number of real directories we've output, used for popping a parent directory.
|
|
1230
|
-
// Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
|
|
1231
|
-
let positive = 0;
|
|
1232
|
-
// We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
|
|
1233
|
-
// generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
|
|
1234
|
-
// real directory, we won't need to append, unless the other conditions happen again.
|
|
1235
|
-
let addTrailingSlash = false;
|
|
1236
|
-
for (let i = 1; i < pieces.length; i++) {
|
|
1237
|
-
const piece = pieces[i];
|
|
1238
|
-
// An empty directory, could be a trailing slash, or just a double "//" in the path.
|
|
1239
|
-
if (!piece) {
|
|
1240
|
-
addTrailingSlash = true;
|
|
1241
|
-
continue;
|
|
1242
|
-
}
|
|
1243
|
-
// If we encounter a real directory, then we don't need to append anymore.
|
|
1244
|
-
addTrailingSlash = false;
|
|
1245
|
-
// A current directory, which we can always drop.
|
|
1246
|
-
if (piece === '.')
|
|
1247
|
-
continue;
|
|
1248
|
-
// A parent directory, we need to see if there are any real directories we can pop. Else, we
|
|
1249
|
-
// have an excess of parents, and we'll need to keep the "..".
|
|
1250
|
-
if (piece === '..') {
|
|
1251
|
-
if (positive) {
|
|
1252
|
-
addTrailingSlash = true;
|
|
1253
|
-
positive--;
|
|
1254
|
-
pointer--;
|
|
1255
|
-
}
|
|
1256
|
-
else if (rel) {
|
|
1257
|
-
// If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
|
|
1258
|
-
// URL, protocol relative URL, or an absolute path, we don't need to keep excess.
|
|
1259
|
-
pieces[pointer++] = piece;
|
|
1260
|
-
}
|
|
1261
|
-
continue;
|
|
1262
|
-
}
|
|
1263
|
-
// We've encountered a real directory. Move it to the next insertion pointer, which accounts for
|
|
1264
|
-
// any popped or dropped directories.
|
|
1265
|
-
pieces[pointer++] = piece;
|
|
1266
|
-
positive++;
|
|
1267
|
-
}
|
|
1268
|
-
let path = '';
|
|
1269
|
-
for (let i = 1; i < pointer; i++) {
|
|
1270
|
-
path += '/' + pieces[i];
|
|
1271
|
-
}
|
|
1272
|
-
if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
|
|
1273
|
-
path += '/';
|
|
1274
|
-
}
|
|
1275
|
-
url.path = path;
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* Attempts to resolve `input` URL/path relative to `base`.
|
|
1279
|
-
*/
|
|
1280
|
-
function resolve(input, base) {
|
|
1281
|
-
if (!input && !base)
|
|
1282
|
-
return '';
|
|
1283
|
-
const url = parseUrl(input);
|
|
1284
|
-
let inputType = url.type;
|
|
1285
|
-
if (base && inputType !== 7 /* Absolute */) {
|
|
1286
|
-
const baseUrl = parseUrl(base);
|
|
1287
|
-
const baseType = baseUrl.type;
|
|
1288
|
-
switch (inputType) {
|
|
1289
|
-
case 1 /* Empty */:
|
|
1290
|
-
url.hash = baseUrl.hash;
|
|
1291
|
-
// fall through
|
|
1292
|
-
case 2 /* Hash */:
|
|
1293
|
-
url.query = baseUrl.query;
|
|
1294
|
-
// fall through
|
|
1295
|
-
case 3 /* Query */:
|
|
1296
|
-
case 4 /* RelativePath */:
|
|
1297
|
-
mergePaths(url, baseUrl);
|
|
1298
|
-
// fall through
|
|
1299
|
-
case 5 /* AbsolutePath */:
|
|
1300
|
-
// The host, user, and port are joined, you can't copy one without the others.
|
|
1301
|
-
url.user = baseUrl.user;
|
|
1302
|
-
url.host = baseUrl.host;
|
|
1303
|
-
url.port = baseUrl.port;
|
|
1304
|
-
// fall through
|
|
1305
|
-
case 6 /* SchemeRelative */:
|
|
1306
|
-
// The input doesn't have a schema at least, so we need to copy at least that over.
|
|
1307
|
-
url.scheme = baseUrl.scheme;
|
|
1308
|
-
}
|
|
1309
|
-
if (baseType > inputType)
|
|
1310
|
-
inputType = baseType;
|
|
1311
|
-
}
|
|
1312
|
-
normalizePath$1(url, inputType);
|
|
1313
|
-
const queryHash = url.query + url.hash;
|
|
1314
|
-
switch (inputType) {
|
|
1315
|
-
// This is impossible, because of the empty checks at the start of the function.
|
|
1316
|
-
// case UrlType.Empty:
|
|
1317
|
-
case 2 /* Hash */:
|
|
1318
|
-
case 3 /* Query */:
|
|
1319
|
-
return queryHash;
|
|
1320
|
-
case 4 /* RelativePath */: {
|
|
1321
|
-
// The first char is always a "/", and we need it to be relative.
|
|
1322
|
-
const path = url.path.slice(1);
|
|
1323
|
-
if (!path)
|
|
1324
|
-
return queryHash || '.';
|
|
1325
|
-
if (isRelative(base || input) && !isRelative(path)) {
|
|
1326
|
-
// If base started with a leading ".", or there is no base and input started with a ".",
|
|
1327
|
-
// then we need to ensure that the relative path starts with a ".". We don't know if
|
|
1328
|
-
// relative starts with a "..", though, so check before prepending.
|
|
1329
|
-
return './' + path + queryHash;
|
|
1330
|
-
}
|
|
1331
|
-
return path + queryHash;
|
|
1332
|
-
}
|
|
1333
|
-
case 5 /* AbsolutePath */:
|
|
1334
|
-
return url.path + queryHash;
|
|
1335
|
-
default:
|
|
1336
|
-
return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
// src/trace-mapping.ts
|
|
1341
|
-
|
|
1342
|
-
// src/strip-filename.ts
|
|
1343
|
-
function stripFilename(path) {
|
|
1344
|
-
if (!path) return "";
|
|
1345
|
-
const index = path.lastIndexOf("/");
|
|
1346
|
-
return path.slice(0, index + 1);
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
// src/resolve.ts
|
|
1350
|
-
function resolver(mapUrl, sourceRoot) {
|
|
1351
|
-
const from = stripFilename(mapUrl);
|
|
1352
|
-
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
1353
|
-
return (source) => resolve(prefix + (source || ""), from);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
// src/sourcemap-segment.ts
|
|
1357
|
-
var COLUMN$1 = 0;
|
|
1358
|
-
|
|
1359
|
-
// src/sort.ts
|
|
1360
|
-
function maybeSort(mappings, owned) {
|
|
1361
|
-
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
1362
|
-
if (unsortedIndex === mappings.length) return mappings;
|
|
1363
|
-
if (!owned) mappings = mappings.slice();
|
|
1364
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
1365
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
1366
|
-
}
|
|
1367
|
-
return mappings;
|
|
1368
|
-
}
|
|
1369
|
-
function nextUnsortedSegmentLine(mappings, start) {
|
|
1370
|
-
for (let i = start; i < mappings.length; i++) {
|
|
1371
|
-
if (!isSorted(mappings[i])) return i;
|
|
1372
|
-
}
|
|
1373
|
-
return mappings.length;
|
|
1374
|
-
}
|
|
1375
|
-
function isSorted(line) {
|
|
1376
|
-
for (let j = 1; j < line.length; j++) {
|
|
1377
|
-
if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) {
|
|
1378
|
-
return false;
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
return true;
|
|
1382
|
-
}
|
|
1383
|
-
function sortSegments(line, owned) {
|
|
1384
|
-
if (!owned) line = line.slice();
|
|
1385
|
-
return line.sort(sortComparator);
|
|
1386
|
-
}
|
|
1387
|
-
function sortComparator(a, b) {
|
|
1388
|
-
return a[COLUMN$1] - b[COLUMN$1];
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
// src/binary-search.ts
|
|
1392
|
-
var found = false;
|
|
1393
|
-
function binarySearch(haystack, needle, low, high) {
|
|
1394
|
-
while (low <= high) {
|
|
1395
|
-
const mid = low + (high - low >> 1);
|
|
1396
|
-
const cmp = haystack[mid][COLUMN$1] - needle;
|
|
1397
|
-
if (cmp === 0) {
|
|
1398
|
-
found = true;
|
|
1399
|
-
return mid;
|
|
1400
|
-
}
|
|
1401
|
-
if (cmp < 0) {
|
|
1402
|
-
low = mid + 1;
|
|
1403
|
-
} else {
|
|
1404
|
-
high = mid - 1;
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
found = false;
|
|
1408
|
-
return low - 1;
|
|
1409
|
-
}
|
|
1410
|
-
function lowerBound(haystack, needle, index) {
|
|
1411
|
-
for (let i = index - 1; i >= 0; index = i--) {
|
|
1412
|
-
if (haystack[i][COLUMN$1] !== needle) break;
|
|
1413
|
-
}
|
|
1414
|
-
return index;
|
|
1415
|
-
}
|
|
1416
|
-
function memoizedState() {
|
|
1417
|
-
return {
|
|
1418
|
-
lastKey: -1,
|
|
1419
|
-
lastNeedle: -1,
|
|
1420
|
-
lastIndex: -1
|
|
1421
|
-
};
|
|
1422
|
-
}
|
|
1423
|
-
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
1424
|
-
const { lastKey, lastNeedle, lastIndex } = state;
|
|
1425
|
-
let low = 0;
|
|
1426
|
-
let high = haystack.length - 1;
|
|
1427
|
-
if (key === lastKey) {
|
|
1428
|
-
if (needle === lastNeedle) {
|
|
1429
|
-
found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
|
|
1430
|
-
return lastIndex;
|
|
1431
|
-
}
|
|
1432
|
-
if (needle >= lastNeedle) {
|
|
1433
|
-
low = lastIndex === -1 ? 0 : lastIndex;
|
|
1434
|
-
} else {
|
|
1435
|
-
high = lastIndex;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
state.lastKey = key;
|
|
1439
|
-
state.lastNeedle = needle;
|
|
1440
|
-
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
// src/types.ts
|
|
1444
|
-
function parse(map) {
|
|
1445
|
-
return typeof map === "string" ? JSON.parse(map) : map;
|
|
1446
|
-
}
|
|
1447
|
-
var TraceMap = class {
|
|
1448
|
-
constructor(map, mapUrl) {
|
|
1449
|
-
const isString = typeof map === "string";
|
|
1450
|
-
if (!isString && map._decodedMemo) return map;
|
|
1451
|
-
const parsed = parse(map);
|
|
1452
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
1453
|
-
this.version = version;
|
|
1454
|
-
this.file = file;
|
|
1455
|
-
this.names = names || [];
|
|
1456
|
-
this.sourceRoot = sourceRoot;
|
|
1457
|
-
this.sources = sources;
|
|
1458
|
-
this.sourcesContent = sourcesContent;
|
|
1459
|
-
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
1460
|
-
const resolve = resolver(mapUrl, sourceRoot);
|
|
1461
|
-
this.resolvedSources = sources.map(resolve);
|
|
1462
|
-
const { mappings } = parsed;
|
|
1463
|
-
if (typeof mappings === "string") {
|
|
1464
|
-
this._encoded = mappings;
|
|
1465
|
-
this._decoded = void 0;
|
|
1466
|
-
} else if (Array.isArray(mappings)) {
|
|
1467
|
-
this._encoded = void 0;
|
|
1468
|
-
this._decoded = maybeSort(mappings, isString);
|
|
1469
|
-
} else if (parsed.sections) {
|
|
1470
|
-
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
1471
|
-
} else {
|
|
1472
|
-
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
1473
|
-
}
|
|
1474
|
-
this._decodedMemo = memoizedState();
|
|
1475
|
-
this._bySources = void 0;
|
|
1476
|
-
this._bySourceMemos = void 0;
|
|
1477
|
-
}
|
|
1478
|
-
};
|
|
1479
|
-
function cast$1(map) {
|
|
1480
|
-
return map;
|
|
1481
|
-
}
|
|
1482
|
-
function decodedMappings(map) {
|
|
1483
|
-
var _a;
|
|
1484
|
-
return (_a = cast$1(map))._decoded || (_a._decoded = decode(cast$1(map)._encoded));
|
|
1485
|
-
}
|
|
1486
|
-
function traceSegment(map, line, column) {
|
|
1487
|
-
const decoded = decodedMappings(map);
|
|
1488
|
-
if (line >= decoded.length) return null;
|
|
1489
|
-
const segments = decoded[line];
|
|
1490
|
-
const index = traceSegmentInternal(
|
|
1491
|
-
segments,
|
|
1492
|
-
cast$1(map)._decodedMemo,
|
|
1493
|
-
line,
|
|
1494
|
-
column);
|
|
1495
|
-
return index === -1 ? null : segments[index];
|
|
1496
|
-
}
|
|
1497
|
-
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
1498
|
-
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
1499
|
-
if (found) {
|
|
1500
|
-
index = (lowerBound)(segments, column, index);
|
|
1501
|
-
}
|
|
1502
|
-
if (index === -1 || index === segments.length) return -1;
|
|
1503
|
-
return index;
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
// src/set-array.ts
|
|
1507
|
-
var SetArray = class {
|
|
1508
|
-
constructor() {
|
|
1509
|
-
this._indexes = { __proto__: null };
|
|
1510
|
-
this.array = [];
|
|
1511
|
-
}
|
|
1512
|
-
};
|
|
1513
|
-
function cast(set) {
|
|
1514
|
-
return set;
|
|
1515
|
-
}
|
|
1516
|
-
function get(setarr, key) {
|
|
1517
|
-
return cast(setarr)._indexes[key];
|
|
1518
|
-
}
|
|
1519
|
-
function put(setarr, key) {
|
|
1520
|
-
const index = get(setarr, key);
|
|
1521
|
-
if (index !== void 0) return index;
|
|
1522
|
-
const { array, _indexes: indexes } = cast(setarr);
|
|
1523
|
-
const length = array.push(key);
|
|
1524
|
-
return indexes[key] = length - 1;
|
|
1525
|
-
}
|
|
1526
|
-
function remove(setarr, key) {
|
|
1527
|
-
const index = get(setarr, key);
|
|
1528
|
-
if (index === void 0) return;
|
|
1529
|
-
const { array, _indexes: indexes } = cast(setarr);
|
|
1530
|
-
for (let i = index + 1; i < array.length; i++) {
|
|
1531
|
-
const k = array[i];
|
|
1532
|
-
array[i - 1] = k;
|
|
1533
|
-
indexes[k]--;
|
|
1534
|
-
}
|
|
1535
|
-
indexes[key] = void 0;
|
|
1536
|
-
array.pop();
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
// src/sourcemap-segment.ts
|
|
1540
|
-
var COLUMN = 0;
|
|
1541
|
-
var SOURCES_INDEX = 1;
|
|
1542
|
-
var SOURCE_LINE = 2;
|
|
1543
|
-
var SOURCE_COLUMN = 3;
|
|
1544
|
-
var NAMES_INDEX = 4;
|
|
1545
|
-
|
|
1546
|
-
// src/gen-mapping.ts
|
|
1547
|
-
var NO_NAME = -1;
|
|
1548
|
-
var GenMapping = class {
|
|
1549
|
-
constructor({ file, sourceRoot } = {}) {
|
|
1550
|
-
this._names = new SetArray();
|
|
1551
|
-
this._sources = new SetArray();
|
|
1552
|
-
this._sourcesContent = [];
|
|
1553
|
-
this._mappings = [];
|
|
1554
|
-
this.file = file;
|
|
1555
|
-
this.sourceRoot = sourceRoot;
|
|
1556
|
-
this._ignoreList = new SetArray();
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
function cast2(map) {
|
|
1560
|
-
return map;
|
|
1561
|
-
}
|
|
1562
|
-
var maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
|
|
1563
|
-
return addSegmentInternal(
|
|
1564
|
-
true,
|
|
1565
|
-
map,
|
|
1566
|
-
genLine,
|
|
1567
|
-
genColumn,
|
|
1568
|
-
source,
|
|
1569
|
-
sourceLine,
|
|
1570
|
-
sourceColumn,
|
|
1571
|
-
name);
|
|
1572
|
-
};
|
|
1573
|
-
function setSourceContent(map, source, content) {
|
|
1574
|
-
const {
|
|
1575
|
-
_sources: sources,
|
|
1576
|
-
_sourcesContent: sourcesContent
|
|
1577
|
-
// _originalScopes: originalScopes,
|
|
1578
|
-
} = cast2(map);
|
|
1579
|
-
const index = put(sources, source);
|
|
1580
|
-
sourcesContent[index] = content;
|
|
1581
|
-
}
|
|
1582
|
-
function setIgnore(map, source, ignore = true) {
|
|
1583
|
-
const {
|
|
1584
|
-
_sources: sources,
|
|
1585
|
-
_sourcesContent: sourcesContent,
|
|
1586
|
-
_ignoreList: ignoreList
|
|
1587
|
-
// _originalScopes: originalScopes,
|
|
1588
|
-
} = cast2(map);
|
|
1589
|
-
const index = put(sources, source);
|
|
1590
|
-
if (index === sourcesContent.length) sourcesContent[index] = null;
|
|
1591
|
-
if (ignore) put(ignoreList, index);
|
|
1592
|
-
else remove(ignoreList, index);
|
|
1593
|
-
}
|
|
1594
|
-
function toDecodedMap(map) {
|
|
1595
|
-
const {
|
|
1596
|
-
_mappings: mappings,
|
|
1597
|
-
_sources: sources,
|
|
1598
|
-
_sourcesContent: sourcesContent,
|
|
1599
|
-
_names: names,
|
|
1600
|
-
_ignoreList: ignoreList
|
|
1601
|
-
// _originalScopes: originalScopes,
|
|
1602
|
-
// _generatedRanges: generatedRanges,
|
|
1603
|
-
} = cast2(map);
|
|
1604
|
-
removeEmptyFinalLines(mappings);
|
|
1605
|
-
return {
|
|
1606
|
-
version: 3,
|
|
1607
|
-
file: map.file || void 0,
|
|
1608
|
-
names: names.array,
|
|
1609
|
-
sourceRoot: map.sourceRoot || void 0,
|
|
1610
|
-
sources: sources.array,
|
|
1611
|
-
sourcesContent,
|
|
1612
|
-
mappings,
|
|
1613
|
-
// originalScopes,
|
|
1614
|
-
// generatedRanges,
|
|
1615
|
-
ignoreList: ignoreList.array
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
function toEncodedMap(map) {
|
|
1619
|
-
const decoded = toDecodedMap(map);
|
|
1620
|
-
return Object.assign({}, decoded, {
|
|
1621
|
-
// originalScopes: decoded.originalScopes.map((os) => encodeOriginalScopes(os)),
|
|
1622
|
-
// generatedRanges: encodeGeneratedRanges(decoded.generatedRanges as GeneratedRange[]),
|
|
1623
|
-
mappings: encode(decoded.mappings)
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|
1627
|
-
const {
|
|
1628
|
-
_mappings: mappings,
|
|
1629
|
-
_sources: sources,
|
|
1630
|
-
_sourcesContent: sourcesContent,
|
|
1631
|
-
_names: names
|
|
1632
|
-
// _originalScopes: originalScopes,
|
|
1633
|
-
} = cast2(map);
|
|
1634
|
-
const line = getIndex(mappings, genLine);
|
|
1635
|
-
const index = getColumnIndex(line, genColumn);
|
|
1636
|
-
if (!source) {
|
|
1637
|
-
if (skipSourceless(line, index)) return;
|
|
1638
|
-
return insert(line, index, [genColumn]);
|
|
1639
|
-
}
|
|
1640
|
-
const sourcesIndex = put(sources, source);
|
|
1641
|
-
const namesIndex = name ? put(names, name) : NO_NAME;
|
|
1642
|
-
if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = null;
|
|
1643
|
-
if (skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
return insert(
|
|
1647
|
-
line,
|
|
1648
|
-
index,
|
|
1649
|
-
name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]
|
|
1650
|
-
);
|
|
1651
|
-
}
|
|
1652
|
-
function getIndex(arr, index) {
|
|
1653
|
-
for (let i = arr.length; i <= index; i++) {
|
|
1654
|
-
arr[i] = [];
|
|
1655
|
-
}
|
|
1656
|
-
return arr[index];
|
|
1657
|
-
}
|
|
1658
|
-
function getColumnIndex(line, genColumn) {
|
|
1659
|
-
let index = line.length;
|
|
1660
|
-
for (let i = index - 1; i >= 0; index = i--) {
|
|
1661
|
-
const current = line[i];
|
|
1662
|
-
if (genColumn >= current[COLUMN]) break;
|
|
1663
|
-
}
|
|
1664
|
-
return index;
|
|
1665
|
-
}
|
|
1666
|
-
function insert(array, index, value) {
|
|
1667
|
-
for (let i = array.length; i > index; i--) {
|
|
1668
|
-
array[i] = array[i - 1];
|
|
1669
|
-
}
|
|
1670
|
-
array[index] = value;
|
|
1671
|
-
}
|
|
1672
|
-
function removeEmptyFinalLines(mappings) {
|
|
1673
|
-
const { length } = mappings;
|
|
1674
|
-
let len = length;
|
|
1675
|
-
for (let i = len - 1; i >= 0; len = i, i--) {
|
|
1676
|
-
if (mappings[i].length > 0) break;
|
|
1677
|
-
}
|
|
1678
|
-
if (len < length) mappings.length = len;
|
|
1679
|
-
}
|
|
1680
|
-
function skipSourceless(line, index) {
|
|
1681
|
-
if (index === 0) return true;
|
|
1682
|
-
const prev = line[index - 1];
|
|
1683
|
-
return prev.length === 1;
|
|
1684
|
-
}
|
|
1685
|
-
function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
|
|
1686
|
-
if (index === 0) return false;
|
|
1687
|
-
const prev = line[index - 1];
|
|
1688
|
-
if (prev.length === 1) return false;
|
|
1689
|
-
return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
// src/build-source-map-tree.ts
|
|
1693
|
-
var SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null, false);
|
|
1694
|
-
var EMPTY_SOURCES = [];
|
|
1695
|
-
function SegmentObject(source, line, column, name, content, ignore) {
|
|
1696
|
-
return { source, line, column, name, content, ignore };
|
|
1697
|
-
}
|
|
1698
|
-
function Source(map, sources, source, content, ignore) {
|
|
1699
|
-
return {
|
|
1700
|
-
map,
|
|
1701
|
-
sources,
|
|
1702
|
-
source,
|
|
1703
|
-
content,
|
|
1704
|
-
ignore
|
|
1705
|
-
};
|
|
1706
|
-
}
|
|
1707
|
-
function MapSource(map, sources) {
|
|
1708
|
-
return Source(map, sources, "", null, false);
|
|
1709
|
-
}
|
|
1710
|
-
function OriginalSource(source, content, ignore) {
|
|
1711
|
-
return Source(null, EMPTY_SOURCES, source, content, ignore);
|
|
1712
|
-
}
|
|
1713
|
-
function traceMappings(tree) {
|
|
1714
|
-
const gen = new GenMapping({ file: tree.map.file });
|
|
1715
|
-
const { sources: rootSources, map } = tree;
|
|
1716
|
-
const rootNames = map.names;
|
|
1717
|
-
const rootMappings = decodedMappings(map);
|
|
1718
|
-
for (let i = 0; i < rootMappings.length; i++) {
|
|
1719
|
-
const segments = rootMappings[i];
|
|
1720
|
-
for (let j = 0; j < segments.length; j++) {
|
|
1721
|
-
const segment = segments[j];
|
|
1722
|
-
const genCol = segment[0];
|
|
1723
|
-
let traced = SOURCELESS_MAPPING;
|
|
1724
|
-
if (segment.length !== 1) {
|
|
1725
|
-
const source2 = rootSources[segment[1]];
|
|
1726
|
-
traced = originalPositionFor(
|
|
1727
|
-
source2,
|
|
1728
|
-
segment[2],
|
|
1729
|
-
segment[3],
|
|
1730
|
-
segment.length === 5 ? rootNames[segment[4]] : ""
|
|
1731
|
-
);
|
|
1732
|
-
if (traced == null) continue;
|
|
1733
|
-
}
|
|
1734
|
-
const { column, line, name, content, source, ignore } = traced;
|
|
1735
|
-
maybeAddSegment(gen, i, genCol, source, line, column, name);
|
|
1736
|
-
if (source && content != null) setSourceContent(gen, source, content);
|
|
1737
|
-
if (ignore) setIgnore(gen, source, true);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
return gen;
|
|
1741
|
-
}
|
|
1742
|
-
function originalPositionFor(source, line, column, name) {
|
|
1743
|
-
if (!source.map) {
|
|
1744
|
-
return SegmentObject(source.source, line, column, name, source.content, source.ignore);
|
|
1745
|
-
}
|
|
1746
|
-
const segment = traceSegment(source.map, line, column);
|
|
1747
|
-
if (segment == null) return null;
|
|
1748
|
-
if (segment.length === 1) return SOURCELESS_MAPPING;
|
|
1749
|
-
return originalPositionFor(
|
|
1750
|
-
source.sources[segment[1]],
|
|
1751
|
-
segment[2],
|
|
1752
|
-
segment[3],
|
|
1753
|
-
segment.length === 5 ? source.map.names[segment[4]] : name
|
|
1754
|
-
);
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
// src/build-source-map-tree.ts
|
|
1758
|
-
function asArray(value) {
|
|
1759
|
-
if (Array.isArray(value)) return value;
|
|
1760
|
-
return [value];
|
|
1761
|
-
}
|
|
1762
|
-
function buildSourceMapTree(input, loader) {
|
|
1763
|
-
const maps = asArray(input).map((m) => new TraceMap(m, ""));
|
|
1764
|
-
const map = maps.pop();
|
|
1765
|
-
for (let i = 0; i < maps.length; i++) {
|
|
1766
|
-
if (maps[i].sources.length > 1) {
|
|
1767
|
-
throw new Error(
|
|
1768
|
-
`Transformation map ${i} must have exactly one source file.
|
|
1769
|
-
Did you specify these with the most recent transformation maps first?`
|
|
1770
|
-
);
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
let tree = build(map, loader, "", 0);
|
|
1774
|
-
for (let i = maps.length - 1; i >= 0; i--) {
|
|
1775
|
-
tree = MapSource(maps[i], [tree]);
|
|
1776
|
-
}
|
|
1777
|
-
return tree;
|
|
1778
|
-
}
|
|
1779
|
-
function build(map, loader, importer, importerDepth) {
|
|
1780
|
-
const { resolvedSources, sourcesContent, ignoreList } = map;
|
|
1781
|
-
const depth = importerDepth + 1;
|
|
1782
|
-
const children = resolvedSources.map((sourceFile, i) => {
|
|
1783
|
-
const ctx = {
|
|
1784
|
-
importer,
|
|
1785
|
-
depth,
|
|
1786
|
-
source: sourceFile || "",
|
|
1787
|
-
content: void 0,
|
|
1788
|
-
ignore: void 0
|
|
1789
|
-
};
|
|
1790
|
-
const sourceMap = loader(ctx.source, ctx);
|
|
1791
|
-
const { source} = ctx;
|
|
1792
|
-
if (sourceMap) return build(new TraceMap(sourceMap, source), loader, source, depth);
|
|
1793
|
-
const sourceContent = sourcesContent ? sourcesContent[i] : null;
|
|
1794
|
-
const ignored = ignoreList ? ignoreList.includes(i) : false;
|
|
1795
|
-
return OriginalSource(source, sourceContent, ignored);
|
|
1796
|
-
});
|
|
1797
|
-
return MapSource(map, children);
|
|
1798
|
-
}
|
|
1799
|
-
var SourceMap = class {
|
|
1800
|
-
constructor(map, options) {
|
|
1801
|
-
const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
|
|
1802
|
-
this.version = out.version;
|
|
1803
|
-
this.file = out.file;
|
|
1804
|
-
this.mappings = out.mappings;
|
|
1805
|
-
this.names = out.names;
|
|
1806
|
-
this.ignoreList = out.ignoreList;
|
|
1807
|
-
this.sourceRoot = out.sourceRoot;
|
|
1808
|
-
this.sources = out.sources;
|
|
1809
|
-
if (!options.excludeContent) {
|
|
1810
|
-
this.sourcesContent = out.sourcesContent;
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
toString() {
|
|
1814
|
-
return JSON.stringify(this);
|
|
1815
|
-
}
|
|
1816
|
-
};
|
|
1817
|
-
|
|
1818
|
-
// src/remapping.ts
|
|
1819
|
-
function remapping(input, loader, options) {
|
|
1820
|
-
const opts = { excludeContent: true, decodedMappings: false };
|
|
1821
|
-
const tree = buildSourceMapTree(input, loader);
|
|
1822
|
-
return new SourceMap(traceMappings(tree), opts);
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
var virtualStats = {};
|
|
1826
|
-
|
|
1827
|
-
var hasRequiredVirtualStats;
|
|
1828
|
-
|
|
1829
|
-
function requireVirtualStats () {
|
|
1830
|
-
if (hasRequiredVirtualStats) return virtualStats;
|
|
1831
|
-
hasRequiredVirtualStats = 1;
|
|
1832
|
-
var __importDefault = (virtualStats && virtualStats.__importDefault) || function (mod) {
|
|
1833
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
1834
|
-
};
|
|
1835
|
-
Object.defineProperty(virtualStats, "__esModule", { value: true });
|
|
1836
|
-
virtualStats.VirtualStats = void 0;
|
|
1837
|
-
const constants_1 = __importDefault(require$$0);
|
|
1838
|
-
class VirtualStats {
|
|
1839
|
-
constructor(config) {
|
|
1840
|
-
for (const key in config) {
|
|
1841
|
-
if (!Object.prototype.hasOwnProperty.call(config, key)) {
|
|
1842
|
-
continue;
|
|
1843
|
-
}
|
|
1844
|
-
this[key] = config[key];
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
_checkModeProperty(property) {
|
|
1848
|
-
return (this.mode & constants_1.default.S_IFMT) === property;
|
|
1849
|
-
}
|
|
1850
|
-
isDirectory() {
|
|
1851
|
-
return this._checkModeProperty(constants_1.default.S_IFDIR);
|
|
1852
|
-
}
|
|
1853
|
-
isFile() {
|
|
1854
|
-
return this._checkModeProperty(constants_1.default.S_IFREG);
|
|
1855
|
-
}
|
|
1856
|
-
isBlockDevice() {
|
|
1857
|
-
return this._checkModeProperty(constants_1.default.S_IFBLK);
|
|
1858
|
-
}
|
|
1859
|
-
isCharacterDevice() {
|
|
1860
|
-
return this._checkModeProperty(constants_1.default.S_IFCHR);
|
|
1861
|
-
}
|
|
1862
|
-
isSymbolicLink() {
|
|
1863
|
-
return this._checkModeProperty(constants_1.default.S_IFLNK);
|
|
1864
|
-
}
|
|
1865
|
-
isFIFO() {
|
|
1866
|
-
return this._checkModeProperty(constants_1.default.S_IFIFO);
|
|
1867
|
-
}
|
|
1868
|
-
isSocket() {
|
|
1869
|
-
return this._checkModeProperty(constants_1.default.S_IFSOCK);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
virtualStats.VirtualStats = VirtualStats;
|
|
1873
|
-
|
|
1874
|
-
return virtualStats;
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
var lib;
|
|
1878
|
-
var hasRequiredLib;
|
|
1879
|
-
|
|
1880
|
-
function requireLib () {
|
|
1881
|
-
if (hasRequiredLib) return lib;
|
|
1882
|
-
hasRequiredLib = 1;
|
|
1883
|
-
var __importDefault = (lib && lib.__importDefault) || function (mod) {
|
|
1884
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
1885
|
-
};
|
|
1886
|
-
const path_1 = __importDefault(sysPath__default);
|
|
1887
|
-
const virtual_stats_1 = requireVirtualStats();
|
|
1888
|
-
let inode = 45000000;
|
|
1889
|
-
const ALL = 'all';
|
|
1890
|
-
const STATIC = 'static';
|
|
1891
|
-
const DYNAMIC = 'dynamic';
|
|
1892
|
-
function checkActivation(instance) {
|
|
1893
|
-
if (!instance._compiler) {
|
|
1894
|
-
throw new Error('You must use this plugin only after creating webpack instance!');
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
function getModulePath(filePath, compiler) {
|
|
1898
|
-
return path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(compiler.context, filePath);
|
|
1899
|
-
}
|
|
1900
|
-
function createWebpackData(result) {
|
|
1901
|
-
return (backendOrStorage) => {
|
|
1902
|
-
if (backendOrStorage._data) {
|
|
1903
|
-
const curLevelIdx = backendOrStorage._currentLevel;
|
|
1904
|
-
const curLevel = backendOrStorage._levels[curLevelIdx];
|
|
1905
|
-
return {
|
|
1906
|
-
result,
|
|
1907
|
-
level: curLevel,
|
|
1908
|
-
};
|
|
1909
|
-
}
|
|
1910
|
-
return [null, result];
|
|
1911
|
-
};
|
|
1912
|
-
}
|
|
1913
|
-
function getData(storage, key) {
|
|
1914
|
-
if (storage._data instanceof Map) {
|
|
1915
|
-
return storage._data.get(key);
|
|
1916
|
-
}
|
|
1917
|
-
else if (storage._data) {
|
|
1918
|
-
return storage.data[key];
|
|
1919
|
-
}
|
|
1920
|
-
else if (storage.data instanceof Map) {
|
|
1921
|
-
return storage.data.get(key);
|
|
1922
|
-
}
|
|
1923
|
-
else {
|
|
1924
|
-
return storage.data[key];
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
function setData(backendOrStorage, key, valueFactory) {
|
|
1928
|
-
const value = valueFactory(backendOrStorage);
|
|
1929
|
-
if (backendOrStorage._data instanceof Map) {
|
|
1930
|
-
backendOrStorage._data.set(key, value);
|
|
1931
|
-
}
|
|
1932
|
-
else if (backendOrStorage._data) {
|
|
1933
|
-
backendOrStorage.data[key] = value;
|
|
1934
|
-
}
|
|
1935
|
-
else if (backendOrStorage.data instanceof Map) {
|
|
1936
|
-
backendOrStorage.data.set(key, value);
|
|
1937
|
-
}
|
|
1938
|
-
else {
|
|
1939
|
-
backendOrStorage.data[key] = value;
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
function getStatStorage(fileSystem) {
|
|
1943
|
-
if (fileSystem._statStorage) {
|
|
1944
|
-
return fileSystem._statStorage;
|
|
1945
|
-
}
|
|
1946
|
-
else if (fileSystem._statBackend) {
|
|
1947
|
-
return fileSystem._statBackend;
|
|
1948
|
-
}
|
|
1949
|
-
else {
|
|
1950
|
-
throw new Error("Couldn't find a stat storage");
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
function getFileStorage(fileSystem) {
|
|
1954
|
-
if (fileSystem._readFileStorage) {
|
|
1955
|
-
return fileSystem._readFileStorage;
|
|
1956
|
-
}
|
|
1957
|
-
else if (fileSystem._readFileBackend) {
|
|
1958
|
-
return fileSystem._readFileBackend;
|
|
1959
|
-
}
|
|
1960
|
-
else {
|
|
1961
|
-
throw new Error("Couldn't find a readFileStorage");
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
function getReadDirBackend(fileSystem) {
|
|
1965
|
-
if (fileSystem._readdirBackend) {
|
|
1966
|
-
return fileSystem._readdirBackend;
|
|
1967
|
-
}
|
|
1968
|
-
else if (fileSystem._readdirStorage) {
|
|
1969
|
-
return fileSystem._readdirStorage;
|
|
1970
|
-
}
|
|
1971
|
-
else {
|
|
1972
|
-
throw new Error("Couldn't find a readDirStorage from Webpack Internals");
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
function getRealpathBackend(fileSystem) {
|
|
1976
|
-
if (fileSystem._realpathBackend) {
|
|
1977
|
-
return fileSystem._realpathBackend;
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
class VirtualModulesPlugin {
|
|
1981
|
-
constructor(modules) {
|
|
1982
|
-
this._compiler = null;
|
|
1983
|
-
this._watcher = null;
|
|
1984
|
-
this._staticModules = modules || null;
|
|
1985
|
-
}
|
|
1986
|
-
getModuleList(filter = ALL) {
|
|
1987
|
-
var _a, _b;
|
|
1988
|
-
let modules = {};
|
|
1989
|
-
const shouldGetStaticModules = filter === ALL || filter === STATIC;
|
|
1990
|
-
const shouldGetDynamicModules = filter === ALL || filter === DYNAMIC;
|
|
1991
|
-
if (shouldGetStaticModules) {
|
|
1992
|
-
modules = Object.assign(Object.assign({}, modules), this._staticModules);
|
|
1993
|
-
}
|
|
1994
|
-
if (shouldGetDynamicModules) {
|
|
1995
|
-
const finalInputFileSystem = (_a = this._compiler) === null || _a === void 0 ? void 0 : _a.inputFileSystem;
|
|
1996
|
-
const virtualFiles = (_b = finalInputFileSystem === null || finalInputFileSystem === void 0 ? void 0 : finalInputFileSystem._virtualFiles) !== null && _b !== void 0 ? _b : {};
|
|
1997
|
-
const dynamicModules = {};
|
|
1998
|
-
Object.keys(virtualFiles).forEach((key) => {
|
|
1999
|
-
dynamicModules[key] = virtualFiles[key].contents;
|
|
2000
|
-
});
|
|
2001
|
-
modules = Object.assign(Object.assign({}, modules), dynamicModules);
|
|
2002
|
-
}
|
|
2003
|
-
return modules;
|
|
2004
|
-
}
|
|
2005
|
-
writeModule(filePath, contents) {
|
|
2006
|
-
if (!this._compiler) {
|
|
2007
|
-
throw new Error(`Plugin has not been initialized`);
|
|
2008
|
-
}
|
|
2009
|
-
checkActivation(this);
|
|
2010
|
-
const len = contents ? contents.length : 0;
|
|
2011
|
-
const time = Date.now();
|
|
2012
|
-
const date = new Date(time);
|
|
2013
|
-
const stats = new virtual_stats_1.VirtualStats({
|
|
2014
|
-
dev: 8675309,
|
|
2015
|
-
nlink: 0,
|
|
2016
|
-
uid: 1000,
|
|
2017
|
-
gid: 1000,
|
|
2018
|
-
rdev: 0,
|
|
2019
|
-
blksize: 4096,
|
|
2020
|
-
ino: inode++,
|
|
2021
|
-
mode: 33188,
|
|
2022
|
-
size: len,
|
|
2023
|
-
blocks: Math.floor(len / 4096),
|
|
2024
|
-
atime: date,
|
|
2025
|
-
mtime: date,
|
|
2026
|
-
ctime: date,
|
|
2027
|
-
birthtime: date,
|
|
2028
|
-
});
|
|
2029
|
-
const modulePath = getModulePath(filePath, this._compiler);
|
|
2030
|
-
if (process.env.WVM_DEBUG)
|
|
2031
|
-
console.log(this._compiler.name, 'Write virtual module:', modulePath, contents);
|
|
2032
|
-
let finalWatchFileSystem = this._watcher && this._watcher.watchFileSystem;
|
|
2033
|
-
while (finalWatchFileSystem && finalWatchFileSystem.wfs) {
|
|
2034
|
-
finalWatchFileSystem = finalWatchFileSystem.wfs;
|
|
2035
|
-
}
|
|
2036
|
-
let finalInputFileSystem = this._compiler.inputFileSystem;
|
|
2037
|
-
while (finalInputFileSystem && finalInputFileSystem._inputFileSystem) {
|
|
2038
|
-
finalInputFileSystem = finalInputFileSystem._inputFileSystem;
|
|
2039
|
-
}
|
|
2040
|
-
finalInputFileSystem._writeVirtualFile(modulePath, stats, contents);
|
|
2041
|
-
if (finalWatchFileSystem &&
|
|
2042
|
-
finalWatchFileSystem.watcher &&
|
|
2043
|
-
(finalWatchFileSystem.watcher.fileWatchers.size || finalWatchFileSystem.watcher.fileWatchers.length)) {
|
|
2044
|
-
const fileWatchers = finalWatchFileSystem.watcher.fileWatchers instanceof Map
|
|
2045
|
-
? Array.from(finalWatchFileSystem.watcher.fileWatchers.values())
|
|
2046
|
-
: finalWatchFileSystem.watcher.fileWatchers;
|
|
2047
|
-
for (let fileWatcher of fileWatchers) {
|
|
2048
|
-
if ('watcher' in fileWatcher) {
|
|
2049
|
-
fileWatcher = fileWatcher.watcher;
|
|
2050
|
-
}
|
|
2051
|
-
if (fileWatcher.path === modulePath) {
|
|
2052
|
-
if (process.env.DEBUG)
|
|
2053
|
-
console.log(this._compiler.name, 'Emit file change:', modulePath, time);
|
|
2054
|
-
delete fileWatcher.directoryWatcher._cachedTimeInfoEntries;
|
|
2055
|
-
fileWatcher.emit('change', time, null);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
apply(compiler) {
|
|
2061
|
-
this._compiler = compiler;
|
|
2062
|
-
const afterEnvironmentHook = () => {
|
|
2063
|
-
let finalInputFileSystem = compiler.inputFileSystem;
|
|
2064
|
-
while (finalInputFileSystem && finalInputFileSystem._inputFileSystem) {
|
|
2065
|
-
finalInputFileSystem = finalInputFileSystem._inputFileSystem;
|
|
2066
|
-
}
|
|
2067
|
-
if (!finalInputFileSystem._writeVirtualFile) {
|
|
2068
|
-
const originalPurge = finalInputFileSystem.purge;
|
|
2069
|
-
finalInputFileSystem.purge = () => {
|
|
2070
|
-
originalPurge.apply(finalInputFileSystem, []);
|
|
2071
|
-
if (finalInputFileSystem._virtualFiles) {
|
|
2072
|
-
Object.keys(finalInputFileSystem._virtualFiles).forEach((file) => {
|
|
2073
|
-
const data = finalInputFileSystem._virtualFiles[file];
|
|
2074
|
-
finalInputFileSystem._writeVirtualFile(file, data.stats, data.contents);
|
|
2075
|
-
});
|
|
2076
|
-
}
|
|
2077
|
-
};
|
|
2078
|
-
finalInputFileSystem._writeVirtualFile = (file, stats, contents) => {
|
|
2079
|
-
const statStorage = getStatStorage(finalInputFileSystem);
|
|
2080
|
-
const fileStorage = getFileStorage(finalInputFileSystem);
|
|
2081
|
-
const readDirStorage = getReadDirBackend(finalInputFileSystem);
|
|
2082
|
-
const realPathStorage = getRealpathBackend(finalInputFileSystem);
|
|
2083
|
-
finalInputFileSystem._virtualFiles = finalInputFileSystem._virtualFiles || {};
|
|
2084
|
-
finalInputFileSystem._virtualFiles[file] = { stats: stats, contents: contents };
|
|
2085
|
-
setData(statStorage, file, createWebpackData(stats));
|
|
2086
|
-
setData(fileStorage, file, createWebpackData(contents));
|
|
2087
|
-
const segments = file.split(/[\\/]/);
|
|
2088
|
-
let count = segments.length - 1;
|
|
2089
|
-
const minCount = segments[0] ? 1 : 0;
|
|
2090
|
-
while (count > minCount) {
|
|
2091
|
-
const dir = segments.slice(0, count).join(path_1.default.sep) || path_1.default.sep;
|
|
2092
|
-
try {
|
|
2093
|
-
finalInputFileSystem.readdirSync(dir);
|
|
2094
|
-
}
|
|
2095
|
-
catch (e) {
|
|
2096
|
-
const time = Date.now();
|
|
2097
|
-
const dirStats = new virtual_stats_1.VirtualStats({
|
|
2098
|
-
dev: 8675309,
|
|
2099
|
-
nlink: 0,
|
|
2100
|
-
uid: 1000,
|
|
2101
|
-
gid: 1000,
|
|
2102
|
-
rdev: 0,
|
|
2103
|
-
blksize: 4096,
|
|
2104
|
-
ino: inode++,
|
|
2105
|
-
mode: 16877,
|
|
2106
|
-
size: stats.size,
|
|
2107
|
-
blocks: Math.floor(stats.size / 4096),
|
|
2108
|
-
atime: time,
|
|
2109
|
-
mtime: time,
|
|
2110
|
-
ctime: time,
|
|
2111
|
-
birthtime: time,
|
|
2112
|
-
});
|
|
2113
|
-
setData(readDirStorage, dir, createWebpackData([]));
|
|
2114
|
-
if (realPathStorage) {
|
|
2115
|
-
setData(realPathStorage, dir, createWebpackData(dir));
|
|
2116
|
-
}
|
|
2117
|
-
setData(statStorage, dir, createWebpackData(dirStats));
|
|
2118
|
-
}
|
|
2119
|
-
let dirData = getData(getReadDirBackend(finalInputFileSystem), dir);
|
|
2120
|
-
dirData = dirData[1] || dirData.result;
|
|
2121
|
-
const filename = segments[count];
|
|
2122
|
-
if (dirData.indexOf(filename) < 0) {
|
|
2123
|
-
const files = dirData.concat([filename]).sort();
|
|
2124
|
-
setData(getReadDirBackend(finalInputFileSystem), dir, createWebpackData(files));
|
|
2125
|
-
}
|
|
2126
|
-
else {
|
|
2127
|
-
break;
|
|
2128
|
-
}
|
|
2129
|
-
count--;
|
|
2130
|
-
}
|
|
2131
|
-
};
|
|
2132
|
-
}
|
|
2133
|
-
};
|
|
2134
|
-
const afterResolversHook = () => {
|
|
2135
|
-
if (this._staticModules) {
|
|
2136
|
-
for (const [filePath, contents] of Object.entries(this._staticModules)) {
|
|
2137
|
-
this.writeModule(filePath, contents);
|
|
2138
|
-
}
|
|
2139
|
-
this._staticModules = null;
|
|
2140
|
-
}
|
|
2141
|
-
};
|
|
2142
|
-
const version = typeof compiler.webpack === 'undefined' ? 4 : 5;
|
|
2143
|
-
const watchRunHook = (watcher, callback) => {
|
|
2144
|
-
this._watcher = watcher.compiler || watcher;
|
|
2145
|
-
const virtualFiles = compiler.inputFileSystem._virtualFiles;
|
|
2146
|
-
const fts = compiler.fileTimestamps;
|
|
2147
|
-
if (virtualFiles && fts && typeof fts.set === 'function') {
|
|
2148
|
-
Object.keys(virtualFiles).forEach((file) => {
|
|
2149
|
-
const mtime = +virtualFiles[file].stats.mtime;
|
|
2150
|
-
fts.set(file, version === 4
|
|
2151
|
-
? mtime
|
|
2152
|
-
: {
|
|
2153
|
-
safeTime: mtime,
|
|
2154
|
-
timestamp: mtime,
|
|
2155
|
-
});
|
|
2156
|
-
});
|
|
2157
|
-
}
|
|
2158
|
-
callback();
|
|
2159
|
-
};
|
|
2160
|
-
if (compiler.hooks) {
|
|
2161
|
-
compiler.hooks.afterEnvironment.tap('VirtualModulesPlugin', afterEnvironmentHook);
|
|
2162
|
-
compiler.hooks.afterResolvers.tap('VirtualModulesPlugin', afterResolversHook);
|
|
2163
|
-
compiler.hooks.watchRun.tapAsync('VirtualModulesPlugin', watchRunHook);
|
|
2164
|
-
}
|
|
2165
|
-
else {
|
|
2166
|
-
compiler.plugin('after-environment', afterEnvironmentHook);
|
|
2167
|
-
compiler.plugin('after-resolvers', afterResolversHook);
|
|
2168
|
-
compiler.plugin('watch-run', watchRunHook);
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
lib = VirtualModulesPlugin;
|
|
2173
|
-
|
|
2174
|
-
return lib;
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
var libExports = requireLib();
|
|
2178
|
-
const VirtualModulesPlugin = /*@__PURE__*/getDefaultExportFromCjs(libExports);
|
|
2179
|
-
|
|
2180
|
-
//#region src/esbuild/utils.ts
|
|
2181
|
-
const ExtToLoader = {
|
|
2182
|
-
".js": "js",
|
|
2183
|
-
".mjs": "js",
|
|
2184
|
-
".cjs": "js",
|
|
2185
|
-
".jsx": "jsx",
|
|
2186
|
-
".ts": "ts",
|
|
2187
|
-
".cts": "ts",
|
|
2188
|
-
".mts": "ts",
|
|
2189
|
-
".tsx": "tsx",
|
|
2190
|
-
".css": "css",
|
|
2191
|
-
".less": "css",
|
|
2192
|
-
".stylus": "css",
|
|
2193
|
-
".scss": "css",
|
|
2194
|
-
".sass": "css",
|
|
2195
|
-
".json": "json",
|
|
2196
|
-
".txt": "text"
|
|
2197
|
-
};
|
|
2198
|
-
function guessLoader(code, id) {
|
|
2199
|
-
return ExtToLoader[path.extname(id).toLowerCase()] || "js";
|
|
2200
|
-
}
|
|
2201
|
-
function unwrapLoader(loader, code, id) {
|
|
2202
|
-
if (typeof loader === "function") return loader(code, id);
|
|
2203
|
-
return loader;
|
|
2204
|
-
}
|
|
2205
|
-
function fixSourceMap(map) {
|
|
2206
|
-
if (!Object.prototype.hasOwnProperty.call(map, "toString")) Object.defineProperty(map, "toString", {
|
|
2207
|
-
enumerable: false,
|
|
2208
|
-
value: function toString() {
|
|
2209
|
-
return JSON.stringify(this);
|
|
2210
|
-
}
|
|
2211
|
-
});
|
|
2212
|
-
if (!Object.prototype.hasOwnProperty.call(map, "toUrl")) Object.defineProperty(map, "toUrl", {
|
|
2213
|
-
enumerable: false,
|
|
2214
|
-
value: function toUrl() {
|
|
2215
|
-
return `data:application/json;charset=utf-8;base64,${Buffer$1.from(this.toString()).toString("base64")}`;
|
|
2216
|
-
}
|
|
2217
|
-
});
|
|
2218
|
-
return map;
|
|
2219
|
-
}
|
|
2220
|
-
const nullSourceMap = {
|
|
2221
|
-
names: [],
|
|
2222
|
-
sources: [],
|
|
2223
|
-
mappings: "",
|
|
2224
|
-
version: 3
|
|
2225
|
-
};
|
|
2226
|
-
function combineSourcemaps(filename, sourcemapList) {
|
|
2227
|
-
sourcemapList = sourcemapList.filter((m) => m.sources);
|
|
2228
|
-
if (sourcemapList.length === 0 || sourcemapList.every((m) => m.sources.length === 0)) return { ...nullSourceMap };
|
|
2229
|
-
let map;
|
|
2230
|
-
let mapIndex = 1;
|
|
2231
|
-
const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === void 0;
|
|
2232
|
-
if (useArrayInterface) map = remapping(sourcemapList, () => null);
|
|
2233
|
-
else map = remapping(sourcemapList[0], (sourcefile) => {
|
|
2234
|
-
if (sourcefile === filename && sourcemapList[mapIndex]) return sourcemapList[mapIndex++];
|
|
2235
|
-
else return { ...nullSourceMap };
|
|
2236
|
-
});
|
|
2237
|
-
if (!map.file) delete map.file;
|
|
2238
|
-
return map;
|
|
2239
|
-
}
|
|
2240
|
-
function createBuildContext$2(build) {
|
|
2241
|
-
const watchFiles = [];
|
|
2242
|
-
const { initialOptions } = build;
|
|
2243
|
-
return {
|
|
2244
|
-
parse: parse$1,
|
|
2245
|
-
addWatchFile() {
|
|
2246
|
-
throw new Error("unplugin/esbuild: addWatchFile outside supported hooks (resolveId, load, transform)");
|
|
2247
|
-
},
|
|
2248
|
-
emitFile(emittedFile) {
|
|
2249
|
-
const outFileName = emittedFile.fileName || emittedFile.name;
|
|
2250
|
-
if (initialOptions.outdir && emittedFile.source && outFileName) {
|
|
2251
|
-
const outPath = path.resolve(initialOptions.outdir, outFileName);
|
|
2252
|
-
const outDir = path.dirname(outPath);
|
|
2253
|
-
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
2254
|
-
fs.writeFileSync(outPath, emittedFile.source);
|
|
2255
|
-
}
|
|
2256
|
-
},
|
|
2257
|
-
getWatchFiles() {
|
|
2258
|
-
return watchFiles;
|
|
2259
|
-
},
|
|
2260
|
-
getNativeBuildContext() {
|
|
2261
|
-
return {
|
|
2262
|
-
framework: "esbuild",
|
|
2263
|
-
build
|
|
2264
|
-
};
|
|
2265
|
-
}
|
|
2266
|
-
};
|
|
2267
|
-
}
|
|
2268
|
-
function createPluginContext(context) {
|
|
2269
|
-
const errors = [];
|
|
2270
|
-
const warnings = [];
|
|
2271
|
-
const pluginContext = {
|
|
2272
|
-
error(message) {
|
|
2273
|
-
errors.push(normalizeMessage$2(message));
|
|
2274
|
-
},
|
|
2275
|
-
warn(message) {
|
|
2276
|
-
warnings.push(normalizeMessage$2(message));
|
|
2277
|
-
}
|
|
2278
|
-
};
|
|
2279
|
-
const mixedContext = {
|
|
2280
|
-
...context,
|
|
2281
|
-
...pluginContext,
|
|
2282
|
-
addWatchFile(id) {
|
|
2283
|
-
context.getWatchFiles().push(id);
|
|
2284
|
-
}
|
|
2285
|
-
};
|
|
2286
|
-
return {
|
|
2287
|
-
errors,
|
|
2288
|
-
warnings,
|
|
2289
|
-
mixedContext
|
|
2290
|
-
};
|
|
2291
|
-
}
|
|
2292
|
-
function normalizeMessage$2(message) {
|
|
2293
|
-
if (typeof message === "string") message = { message };
|
|
2294
|
-
return {
|
|
2295
|
-
id: message.id,
|
|
2296
|
-
pluginName: message.plugin,
|
|
2297
|
-
text: message.message,
|
|
2298
|
-
location: message.loc ? {
|
|
2299
|
-
file: message.loc.file,
|
|
2300
|
-
line: message.loc.line,
|
|
2301
|
-
column: message.loc.column
|
|
2302
|
-
} : null,
|
|
2303
|
-
detail: message.meta,
|
|
2304
|
-
notes: []
|
|
2305
|
-
};
|
|
2306
|
-
}
|
|
2307
|
-
function processCodeWithSourceMap(map, code) {
|
|
2308
|
-
if (map) {
|
|
2309
|
-
if (!map.sourcesContent || map.sourcesContent.length === 0) map.sourcesContent = [code];
|
|
2310
|
-
map = fixSourceMap(map);
|
|
2311
|
-
code += `\n//# sourceMappingURL=${map.toUrl()}`;
|
|
2312
|
-
}
|
|
2313
|
-
return code;
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
//#endregion
|
|
2317
|
-
//#region src/esbuild/index.ts
|
|
2318
|
-
function getEsbuildPlugin(factory) {
|
|
2319
|
-
return (userOptions) => {
|
|
2320
|
-
const meta = { framework: "esbuild" };
|
|
2321
|
-
const plugins = toArray$2(factory(userOptions, meta));
|
|
2322
|
-
const setupPlugins = async (build) => {
|
|
2323
|
-
const setup = buildSetup();
|
|
2324
|
-
const loaders = [];
|
|
2325
|
-
for (const plugin of plugins) {
|
|
2326
|
-
const loader = {};
|
|
2327
|
-
await setup(plugin)({
|
|
2328
|
-
...build,
|
|
2329
|
-
onLoad(_options, callback) {
|
|
2330
|
-
loader.options = _options;
|
|
2331
|
-
loader.onLoadCb = callback;
|
|
2332
|
-
},
|
|
2333
|
-
onTransform(_options, callback) {
|
|
2334
|
-
loader.options ||= _options;
|
|
2335
|
-
loader.onTransformCb = callback;
|
|
2336
|
-
}
|
|
2337
|
-
}, build);
|
|
2338
|
-
if (loader.onLoadCb || loader.onTransformCb) loaders.push(loader);
|
|
2339
|
-
}
|
|
2340
|
-
if (loaders.length) build.onLoad(loaders.length === 1 ? loaders[0].options : { filter: /.*/ }, async (args) => {
|
|
2341
|
-
function checkFilter(options) {
|
|
2342
|
-
return loaders.length === 1 || !options?.filter || options.filter.test(args.path);
|
|
2343
|
-
}
|
|
2344
|
-
let result;
|
|
2345
|
-
for (const { options, onLoadCb } of loaders) {
|
|
2346
|
-
if (!checkFilter(options)) continue;
|
|
2347
|
-
if (onLoadCb) result = await onLoadCb(args);
|
|
2348
|
-
if (result?.contents) break;
|
|
2349
|
-
}
|
|
2350
|
-
let fsContentsCache;
|
|
2351
|
-
for (const { options, onTransformCb } of loaders) {
|
|
2352
|
-
if (!checkFilter(options)) continue;
|
|
2353
|
-
if (onTransformCb) {
|
|
2354
|
-
const newArgs = {
|
|
2355
|
-
...result,
|
|
2356
|
-
...args,
|
|
2357
|
-
async getContents() {
|
|
2358
|
-
if (result?.contents) return result.contents;
|
|
2359
|
-
if (fsContentsCache) return fsContentsCache;
|
|
2360
|
-
return fsContentsCache = await fs.promises.readFile(args.path, "utf8");
|
|
2361
|
-
}
|
|
2362
|
-
};
|
|
2363
|
-
const _result = await onTransformCb(newArgs);
|
|
2364
|
-
if (_result?.contents) result = _result;
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
|
-
if (result?.contents) return result;
|
|
2368
|
-
});
|
|
2369
|
-
};
|
|
2370
|
-
return {
|
|
2371
|
-
name: (plugins.length === 1 ? plugins[0].name : meta.esbuildHostName) ?? `unplugin-host:${plugins.map((p) => p.name).join(":")}`,
|
|
2372
|
-
setup: setupPlugins
|
|
2373
|
-
};
|
|
2374
|
-
};
|
|
2375
|
-
}
|
|
2376
|
-
function buildSetup() {
|
|
2377
|
-
return (plugin) => {
|
|
2378
|
-
return (build, rawBuild) => {
|
|
2379
|
-
const context = createBuildContext$2(rawBuild);
|
|
2380
|
-
const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build;
|
|
2381
|
-
const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/;
|
|
2382
|
-
const onLoadFilter = plugin.esbuild?.onLoadFilter ?? /.*/;
|
|
2383
|
-
const loader = plugin.esbuild?.loader ?? guessLoader;
|
|
2384
|
-
plugin.esbuild?.config?.call(context, initialOptions);
|
|
2385
|
-
if (plugin.buildStart) onStart(() => plugin.buildStart.call(context));
|
|
2386
|
-
if (plugin.buildEnd || plugin.writeBundle) onEnd(async () => {
|
|
2387
|
-
if (plugin.buildEnd) await plugin.buildEnd.call(context);
|
|
2388
|
-
if (plugin.writeBundle) await plugin.writeBundle();
|
|
2389
|
-
});
|
|
2390
|
-
if (plugin.resolveId) onResolve({ filter: onResolveFilter }, async (args) => {
|
|
2391
|
-
const id = args.path;
|
|
2392
|
-
if (initialOptions.external?.includes(id)) return;
|
|
2393
|
-
const { handler, filter } = normalizeObjectHook("resolveId", plugin.resolveId);
|
|
2394
|
-
if (!filter(id)) return;
|
|
2395
|
-
const { errors, warnings, mixedContext } = createPluginContext(context);
|
|
2396
|
-
const isEntry = args.kind === "entry-point";
|
|
2397
|
-
const result = await handler.call(mixedContext, id, isEntry ? void 0 : args.importer, { isEntry });
|
|
2398
|
-
if (typeof result === "string") return {
|
|
2399
|
-
path: result,
|
|
2400
|
-
namespace: plugin.name,
|
|
2401
|
-
errors,
|
|
2402
|
-
warnings,
|
|
2403
|
-
watchFiles: mixedContext.getWatchFiles()
|
|
2404
|
-
};
|
|
2405
|
-
else if (typeof result === "object" && result !== null) return {
|
|
2406
|
-
path: result.id,
|
|
2407
|
-
external: result.external,
|
|
2408
|
-
namespace: plugin.name,
|
|
2409
|
-
errors,
|
|
2410
|
-
warnings,
|
|
2411
|
-
watchFiles: mixedContext.getWatchFiles()
|
|
2412
|
-
};
|
|
2413
|
-
});
|
|
2414
|
-
if (plugin.load) onLoad({ filter: onLoadFilter }, async (args) => {
|
|
2415
|
-
const { handler, filter } = normalizeObjectHook("load", plugin.load);
|
|
2416
|
-
const id = args.path + (args.suffix || "");
|
|
2417
|
-
if (plugin.loadInclude && !plugin.loadInclude(id)) return;
|
|
2418
|
-
if (!filter(id)) return;
|
|
2419
|
-
const { errors, warnings, mixedContext } = createPluginContext(context);
|
|
2420
|
-
let code;
|
|
2421
|
-
let map;
|
|
2422
|
-
const result = await handler.call(mixedContext, id);
|
|
2423
|
-
if (typeof result === "string") code = result;
|
|
2424
|
-
else if (typeof result === "object" && result !== null) {
|
|
2425
|
-
code = result.code;
|
|
2426
|
-
map = result.map;
|
|
2427
|
-
}
|
|
2428
|
-
if (code === void 0) return null;
|
|
2429
|
-
if (map) code = processCodeWithSourceMap(map, code);
|
|
2430
|
-
const resolveDir = path.dirname(args.path);
|
|
2431
|
-
return {
|
|
2432
|
-
contents: code,
|
|
2433
|
-
errors,
|
|
2434
|
-
warnings,
|
|
2435
|
-
watchFiles: mixedContext.getWatchFiles(),
|
|
2436
|
-
loader: unwrapLoader(loader, code, args.path),
|
|
2437
|
-
resolveDir
|
|
2438
|
-
};
|
|
2439
|
-
});
|
|
2440
|
-
if (plugin.transform) onTransform({ filter: onLoadFilter }, async (args) => {
|
|
2441
|
-
const { handler, filter } = normalizeObjectHook("transform", plugin.transform);
|
|
2442
|
-
const id = args.path + (args.suffix || "");
|
|
2443
|
-
if (plugin.transformInclude && !plugin.transformInclude(id)) return;
|
|
2444
|
-
let code = await args.getContents();
|
|
2445
|
-
if (!filter(id, code)) return;
|
|
2446
|
-
const { mixedContext, errors, warnings } = createPluginContext(context);
|
|
2447
|
-
const resolveDir = path.dirname(args.path);
|
|
2448
|
-
let map;
|
|
2449
|
-
const result = await handler.call(mixedContext, code, id);
|
|
2450
|
-
if (typeof result === "string") code = result;
|
|
2451
|
-
else if (typeof result === "object" && result !== null) {
|
|
2452
|
-
code = result.code;
|
|
2453
|
-
if (map && result.map) map = combineSourcemaps(args.path, [result.map === "string" ? JSON.parse(result.map) : result.map, map]);
|
|
2454
|
-
else if (typeof result.map === "string") map = JSON.parse(result.map);
|
|
2455
|
-
else map = result.map;
|
|
2456
|
-
}
|
|
2457
|
-
if (code) {
|
|
2458
|
-
if (map) code = processCodeWithSourceMap(map, code);
|
|
2459
|
-
return {
|
|
2460
|
-
contents: code,
|
|
2461
|
-
errors,
|
|
2462
|
-
warnings,
|
|
2463
|
-
watchFiles: mixedContext.getWatchFiles(),
|
|
2464
|
-
loader: unwrapLoader(loader, code, args.path),
|
|
2465
|
-
resolveDir
|
|
2466
|
-
};
|
|
2467
|
-
}
|
|
2468
|
-
});
|
|
2469
|
-
if (plugin.esbuild?.setup) return plugin.esbuild.setup(rawBuild);
|
|
2470
|
-
};
|
|
2471
|
-
};
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
//#endregion
|
|
2475
|
-
//#region src/farm/context.ts
|
|
2476
|
-
function createFarmContext(context, currentResolveId) {
|
|
2477
|
-
return {
|
|
2478
|
-
parse: parse$1,
|
|
2479
|
-
addWatchFile(id) {
|
|
2480
|
-
context.addWatchFile(id, currentResolveId || id);
|
|
2481
|
-
},
|
|
2482
|
-
emitFile(emittedFile) {
|
|
2483
|
-
const outFileName = emittedFile.fileName || emittedFile.name;
|
|
2484
|
-
if (emittedFile.source && outFileName) context.emitFile({
|
|
2485
|
-
resolvedPath: outFileName,
|
|
2486
|
-
name: outFileName,
|
|
2487
|
-
content: [...Buffer$1.from(emittedFile.source)],
|
|
2488
|
-
resourceType: extname(outFileName)
|
|
2489
|
-
});
|
|
2490
|
-
},
|
|
2491
|
-
getWatchFiles() {
|
|
2492
|
-
return context.getWatchFiles();
|
|
2493
|
-
},
|
|
2494
|
-
getNativeBuildContext() {
|
|
2495
|
-
return {
|
|
2496
|
-
framework: "farm",
|
|
2497
|
-
context
|
|
2498
|
-
};
|
|
2499
|
-
}
|
|
2500
|
-
};
|
|
2501
|
-
}
|
|
2502
|
-
function unpluginContext(context) {
|
|
2503
|
-
return {
|
|
2504
|
-
error: (error) => context.error(typeof error === "string" ? new Error(error) : error),
|
|
2505
|
-
warn: (error) => context.warn(typeof error === "string" ? new Error(error) : error)
|
|
2506
|
-
};
|
|
2507
|
-
}
|
|
2508
|
-
|
|
2509
|
-
//#endregion
|
|
2510
|
-
//#region src/farm/utils.ts
|
|
2511
|
-
function convertEnforceToPriority(value) {
|
|
2512
|
-
const defaultPriority = 100;
|
|
2513
|
-
const enforceToPriority = {
|
|
2514
|
-
pre: 102,
|
|
2515
|
-
post: 98
|
|
2516
|
-
};
|
|
2517
|
-
return enforceToPriority[value] !== void 0 ? enforceToPriority[value] : defaultPriority;
|
|
2518
|
-
}
|
|
2519
|
-
function convertWatchEventChange(value) {
|
|
2520
|
-
const watchEventChange = {
|
|
2521
|
-
Added: "create",
|
|
2522
|
-
Updated: "update",
|
|
2523
|
-
Removed: "delete"
|
|
2524
|
-
};
|
|
2525
|
-
return watchEventChange[value];
|
|
2526
|
-
}
|
|
2527
|
-
function isString(variable) {
|
|
2528
|
-
return typeof variable === "string";
|
|
2529
|
-
}
|
|
2530
|
-
function isObject(variable) {
|
|
2531
|
-
return typeof variable === "object" && variable !== null;
|
|
2532
|
-
}
|
|
2533
|
-
function customParseQueryString(url) {
|
|
2534
|
-
if (!url) return [];
|
|
2535
|
-
const queryString = url.split("?")[1];
|
|
2536
|
-
const parsedParams = querystring.parse(queryString);
|
|
2537
|
-
const paramsArray = [];
|
|
2538
|
-
for (const key in parsedParams) paramsArray.push([key, parsedParams[key]]);
|
|
2539
|
-
return paramsArray;
|
|
2540
|
-
}
|
|
2541
|
-
function encodeStr(str) {
|
|
2542
|
-
const len = str.length;
|
|
2543
|
-
if (len === 0) return str;
|
|
2544
|
-
const firstNullIndex = str.indexOf("\0");
|
|
2545
|
-
if (firstNullIndex === -1) return str;
|
|
2546
|
-
const result = Array.from({ length: len + countNulls(str, firstNullIndex) });
|
|
2547
|
-
let pos = 0;
|
|
2548
|
-
for (let i = 0; i < firstNullIndex; i++) result[pos++] = str[i];
|
|
2549
|
-
for (let i = firstNullIndex; i < len; i++) {
|
|
2550
|
-
const char = str[i];
|
|
2551
|
-
if (char === "\0") {
|
|
2552
|
-
result[pos++] = "\\";
|
|
2553
|
-
result[pos++] = "0";
|
|
2554
|
-
} else result[pos++] = char;
|
|
2555
|
-
}
|
|
2556
|
-
return path.posix.normalize(result.join(""));
|
|
2557
|
-
}
|
|
2558
|
-
function decodeStr(str) {
|
|
2559
|
-
const len = str.length;
|
|
2560
|
-
if (len === 0) return str;
|
|
2561
|
-
const firstIndex = str.indexOf("\\0");
|
|
2562
|
-
if (firstIndex === -1) return str;
|
|
2563
|
-
const result = Array.from({ length: len - countBackslashZeros(str, firstIndex) });
|
|
2564
|
-
let pos = 0;
|
|
2565
|
-
for (let i$1 = 0; i$1 < firstIndex; i$1++) result[pos++] = str[i$1];
|
|
2566
|
-
let i = firstIndex;
|
|
2567
|
-
while (i < len) if (str[i] === "\\" && str[i + 1] === "0") {
|
|
2568
|
-
result[pos++] = "\0";
|
|
2569
|
-
i += 2;
|
|
2570
|
-
} else result[pos++] = str[i++];
|
|
2571
|
-
return path.posix.normalize(result.join(""));
|
|
2572
|
-
}
|
|
2573
|
-
function getContentValue(content) {
|
|
2574
|
-
if (content === null || content === void 0) throw new Error("Content cannot be null or undefined");
|
|
2575
|
-
const strContent = typeof content === "string" ? content : content.code || "";
|
|
2576
|
-
return encodeStr(strContent);
|
|
2577
|
-
}
|
|
2578
|
-
function countNulls(str, startIndex) {
|
|
2579
|
-
let count = 0;
|
|
2580
|
-
const len = str.length;
|
|
2581
|
-
for (let i = startIndex; i < len; i++) if (str[i] === "\0") count++;
|
|
2582
|
-
return count;
|
|
2583
|
-
}
|
|
2584
|
-
function countBackslashZeros(str, startIndex) {
|
|
2585
|
-
let count = 0;
|
|
2586
|
-
const len = str.length;
|
|
2587
|
-
for (let i = startIndex; i < len - 1; i++) if (str[i] === "\\" && str[i + 1] === "0") {
|
|
2588
|
-
count++;
|
|
2589
|
-
i++;
|
|
2590
|
-
}
|
|
2591
|
-
return count;
|
|
2592
|
-
}
|
|
2593
|
-
function removeQuery(pathe) {
|
|
2594
|
-
const queryIndex = pathe.indexOf("?");
|
|
2595
|
-
if (queryIndex !== -1) return path.posix.normalize(pathe.slice(0, queryIndex));
|
|
2596
|
-
return path.posix.normalize(pathe);
|
|
2597
|
-
}
|
|
2598
|
-
function isStartsWithSlash(str) {
|
|
2599
|
-
return str?.startsWith("/");
|
|
2600
|
-
}
|
|
2601
|
-
function appendQuery(id, query) {
|
|
2602
|
-
if (!query.length) return id;
|
|
2603
|
-
return `${id}?${stringifyQuery(query)}`;
|
|
2604
|
-
}
|
|
2605
|
-
function stringifyQuery(query) {
|
|
2606
|
-
if (!query.length) return "";
|
|
2607
|
-
let queryStr = "";
|
|
2608
|
-
for (const [key, value] of query) queryStr += `${key}${value ? `=${value}` : ""}&`;
|
|
2609
|
-
return `${queryStr.slice(0, -1)}`;
|
|
2610
|
-
}
|
|
2611
|
-
const CSS_LANGS_RES = [
|
|
2612
|
-
[/\.(less)(?:$|\?)/, "less"],
|
|
2613
|
-
[/\.(scss|sass)(?:$|\?)/, "sass"],
|
|
2614
|
-
[/\.(styl|stylus)(?:$|\?)/, "stylus"],
|
|
2615
|
-
[/\.(css)(?:$|\?)/, "css"]
|
|
2616
|
-
];
|
|
2617
|
-
const JS_LANGS_RES = [
|
|
2618
|
-
[/\.(js|mjs|cjs)(?:$|\?)/, "js"],
|
|
2619
|
-
[/\.(jsx)(?:$|\?)/, "jsx"],
|
|
2620
|
-
[/\.(ts|cts|mts)(?:$|\?)/, "ts"],
|
|
2621
|
-
[/\.(tsx)(?:$|\?)/, "tsx"]
|
|
2622
|
-
];
|
|
2623
|
-
function getCssModuleType(id) {
|
|
2624
|
-
for (const [reg, lang] of CSS_LANGS_RES) if (reg.test(id)) return lang;
|
|
2625
|
-
return null;
|
|
2626
|
-
}
|
|
2627
|
-
function getJsModuleType(id) {
|
|
2628
|
-
for (const [reg, lang] of JS_LANGS_RES) if (reg.test(id)) return lang;
|
|
2629
|
-
return null;
|
|
2630
|
-
}
|
|
2631
|
-
function formatLoadModuleType(id) {
|
|
2632
|
-
const cssModuleType = getCssModuleType(id);
|
|
2633
|
-
if (cssModuleType) return cssModuleType;
|
|
2634
|
-
const jsModuleType = getJsModuleType(id);
|
|
2635
|
-
if (jsModuleType) return jsModuleType;
|
|
2636
|
-
return "js";
|
|
2637
|
-
}
|
|
2638
|
-
function formatTransformModuleType(id) {
|
|
2639
|
-
return formatLoadModuleType(id);
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
//#endregion
|
|
2643
|
-
//#region src/farm/index.ts
|
|
2644
|
-
function getFarmPlugin(factory) {
|
|
2645
|
-
return ((userOptions) => {
|
|
2646
|
-
const meta = { framework: "farm" };
|
|
2647
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
2648
|
-
const plugins = rawPlugins.map((rawPlugin) => {
|
|
2649
|
-
const plugin = toFarmPlugin(rawPlugin, userOptions);
|
|
2650
|
-
if (rawPlugin.farm) Object.assign(plugin, rawPlugin.farm);
|
|
2651
|
-
return plugin;
|
|
2652
|
-
});
|
|
2653
|
-
return plugins.length === 1 ? plugins[0] : plugins;
|
|
2654
|
-
});
|
|
2655
|
-
}
|
|
2656
|
-
function toFarmPlugin(plugin, options) {
|
|
2657
|
-
const farmPlugin = {
|
|
2658
|
-
name: plugin.name,
|
|
2659
|
-
priority: convertEnforceToPriority(plugin.enforce)
|
|
2660
|
-
};
|
|
2661
|
-
if (plugin.farm) Object.keys(plugin.farm).forEach((key) => {
|
|
2662
|
-
const value = plugin.farm[key];
|
|
2663
|
-
if (value) Reflect.set(farmPlugin, key, value);
|
|
2664
|
-
});
|
|
2665
|
-
if (plugin.buildStart) {
|
|
2666
|
-
const _buildStart = plugin.buildStart;
|
|
2667
|
-
farmPlugin.buildStart = { async executor(_, context) {
|
|
2668
|
-
await _buildStart.call(createFarmContext(context));
|
|
2669
|
-
} };
|
|
2670
|
-
}
|
|
2671
|
-
if (plugin.resolveId) {
|
|
2672
|
-
const _resolveId = plugin.resolveId;
|
|
2673
|
-
let filters = [];
|
|
2674
|
-
if (options) filters = options?.filters ?? [];
|
|
2675
|
-
farmPlugin.resolve = {
|
|
2676
|
-
filters: {
|
|
2677
|
-
sources: filters.length ? filters : [".*"],
|
|
2678
|
-
importers: [".*"]
|
|
2679
|
-
},
|
|
2680
|
-
async executor(params, context) {
|
|
2681
|
-
const resolvedIdPath = path.resolve(params.importer ?? "");
|
|
2682
|
-
const id = decodeStr(params.source);
|
|
2683
|
-
const { handler, filter } = normalizeObjectHook("resolveId", _resolveId);
|
|
2684
|
-
if (!filter(id)) return null;
|
|
2685
|
-
let isEntry = false;
|
|
2686
|
-
if (isObject(params.kind) && "entry" in params.kind) {
|
|
2687
|
-
const kindWithEntry = params.kind;
|
|
2688
|
-
isEntry = kindWithEntry.entry === "index";
|
|
2689
|
-
}
|
|
2690
|
-
const farmContext = createFarmContext(context, resolvedIdPath);
|
|
2691
|
-
const resolveIdResult = await handler.call(Object.assign(unpluginContext(context), farmContext), id, resolvedIdPath ?? null, { isEntry });
|
|
2692
|
-
if (isString(resolveIdResult)) return {
|
|
2693
|
-
resolvedPath: removeQuery(encodeStr(resolveIdResult)),
|
|
2694
|
-
query: customParseQueryString(resolveIdResult),
|
|
2695
|
-
sideEffects: true,
|
|
2696
|
-
external: false,
|
|
2697
|
-
meta: {}
|
|
2698
|
-
};
|
|
2699
|
-
if (isObject(resolveIdResult)) return {
|
|
2700
|
-
resolvedPath: removeQuery(encodeStr(resolveIdResult?.id)),
|
|
2701
|
-
query: customParseQueryString(resolveIdResult?.id),
|
|
2702
|
-
sideEffects: false,
|
|
2703
|
-
external: Boolean(resolveIdResult?.external),
|
|
2704
|
-
meta: {}
|
|
2705
|
-
};
|
|
2706
|
-
if (!isStartsWithSlash(params.source)) return null;
|
|
2707
|
-
}
|
|
2708
|
-
};
|
|
2709
|
-
}
|
|
2710
|
-
if (plugin.load) {
|
|
2711
|
-
const _load = plugin.load;
|
|
2712
|
-
farmPlugin.load = {
|
|
2713
|
-
filters: { resolvedPaths: [".*"] },
|
|
2714
|
-
async executor(params, context) {
|
|
2715
|
-
const resolvedPath = decodeStr(params.resolvedPath);
|
|
2716
|
-
const id = appendQuery(resolvedPath, params.query);
|
|
2717
|
-
const loader = formatTransformModuleType(id);
|
|
2718
|
-
if (plugin.loadInclude && !plugin.loadInclude?.(id)) return null;
|
|
2719
|
-
const { handler, filter } = normalizeObjectHook("load", _load);
|
|
2720
|
-
if (!filter(id)) return null;
|
|
2721
|
-
const farmContext = createFarmContext(context, id);
|
|
2722
|
-
const content = await handler.call(Object.assign(unpluginContext(context), farmContext), id);
|
|
2723
|
-
const loadFarmResult = {
|
|
2724
|
-
content: getContentValue(content),
|
|
2725
|
-
moduleType: loader
|
|
2726
|
-
};
|
|
2727
|
-
return loadFarmResult;
|
|
2728
|
-
}
|
|
2729
|
-
};
|
|
2730
|
-
}
|
|
2731
|
-
if (plugin.transform) {
|
|
2732
|
-
const _transform = plugin.transform;
|
|
2733
|
-
farmPlugin.transform = {
|
|
2734
|
-
filters: {
|
|
2735
|
-
resolvedPaths: [".*"],
|
|
2736
|
-
moduleTypes: [".*"]
|
|
2737
|
-
},
|
|
2738
|
-
async executor(params, context) {
|
|
2739
|
-
const resolvedPath = decodeStr(params.resolvedPath);
|
|
2740
|
-
const id = appendQuery(resolvedPath, params.query);
|
|
2741
|
-
const loader = formatTransformModuleType(id);
|
|
2742
|
-
if (plugin.transformInclude && !plugin.transformInclude(id)) return null;
|
|
2743
|
-
const { handler, filter } = normalizeObjectHook("transform", _transform);
|
|
2744
|
-
if (!filter(id, params.content)) return null;
|
|
2745
|
-
const farmContext = createFarmContext(context, id);
|
|
2746
|
-
const resource = await handler.call(Object.assign(unpluginContext(context), farmContext), params.content, id);
|
|
2747
|
-
if (resource && typeof resource !== "string") {
|
|
2748
|
-
const transformFarmResult = {
|
|
2749
|
-
content: getContentValue(resource),
|
|
2750
|
-
moduleType: loader,
|
|
2751
|
-
sourceMap: typeof resource.map === "object" && resource.map !== null ? JSON.stringify(resource.map) : void 0
|
|
2752
|
-
};
|
|
2753
|
-
return transformFarmResult;
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
};
|
|
2757
|
-
}
|
|
2758
|
-
if (plugin.watchChange) {
|
|
2759
|
-
const _watchChange = plugin.watchChange;
|
|
2760
|
-
farmPlugin.updateModules = { async executor(param, context) {
|
|
2761
|
-
const updatePathContent = param.paths[0];
|
|
2762
|
-
const ModifiedPath = updatePathContent[0];
|
|
2763
|
-
const eventChange = convertWatchEventChange(updatePathContent[1]);
|
|
2764
|
-
await _watchChange.call(createFarmContext(context), ModifiedPath, { event: eventChange });
|
|
2765
|
-
} };
|
|
2766
|
-
}
|
|
2767
|
-
if (plugin.buildEnd) {
|
|
2768
|
-
const _buildEnd = plugin.buildEnd;
|
|
2769
|
-
farmPlugin.buildEnd = { async executor(_, context) {
|
|
2770
|
-
await _buildEnd.call(createFarmContext(context));
|
|
2771
|
-
} };
|
|
2772
|
-
}
|
|
2773
|
-
if (plugin.writeBundle) {
|
|
2774
|
-
const _writeBundle = plugin.writeBundle;
|
|
2775
|
-
farmPlugin.finish = { async executor() {
|
|
2776
|
-
await _writeBundle();
|
|
2777
|
-
} };
|
|
2778
|
-
}
|
|
2779
|
-
return farmPlugin;
|
|
2780
|
-
}
|
|
2781
|
-
|
|
2782
|
-
//#endregion
|
|
2783
|
-
//#region src/rollup/index.ts
|
|
2784
|
-
function getRollupPlugin(factory) {
|
|
2785
|
-
return ((userOptions) => {
|
|
2786
|
-
const meta = { framework: "rollup" };
|
|
2787
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
2788
|
-
const plugins = rawPlugins.map((plugin) => toRollupPlugin(plugin, "rollup"));
|
|
2789
|
-
return plugins.length === 1 ? plugins[0] : plugins;
|
|
2790
|
-
});
|
|
2791
|
-
}
|
|
2792
|
-
function toRollupPlugin(plugin, key) {
|
|
2793
|
-
const nativeFilter = key === "rolldown";
|
|
2794
|
-
if (plugin.resolveId && !nativeFilter && typeof plugin.resolveId === "object" && plugin.resolveId.filter) {
|
|
2795
|
-
const resolveIdHook = plugin.resolveId;
|
|
2796
|
-
const { handler, filter } = normalizeObjectHook("load", resolveIdHook);
|
|
2797
|
-
replaceHookHandler("resolveId", resolveIdHook, function(...args) {
|
|
2798
|
-
const [id] = args;
|
|
2799
|
-
const supportFilter = supportNativeFilter(this, key);
|
|
2800
|
-
if (!supportFilter && !filter(id)) return;
|
|
2801
|
-
return handler.apply(this, args);
|
|
2802
|
-
});
|
|
2803
|
-
}
|
|
2804
|
-
if (plugin.load && (plugin.loadInclude || !nativeFilter && typeof plugin.load === "object" && plugin.load.filter)) {
|
|
2805
|
-
const loadHook = plugin.load;
|
|
2806
|
-
const { handler, filter } = normalizeObjectHook("load", loadHook);
|
|
2807
|
-
replaceHookHandler("load", loadHook, function(...args) {
|
|
2808
|
-
const [id] = args;
|
|
2809
|
-
if (plugin.loadInclude && !plugin.loadInclude(id)) return;
|
|
2810
|
-
const supportFilter = supportNativeFilter(this, key);
|
|
2811
|
-
if (!supportFilter && !filter(id)) return;
|
|
2812
|
-
return handler.apply(this, args);
|
|
2813
|
-
});
|
|
2814
|
-
}
|
|
2815
|
-
if (plugin.transform && (plugin.transformInclude || !nativeFilter && typeof plugin.transform === "object" && plugin.transform.filter)) {
|
|
2816
|
-
const transformHook = plugin.transform;
|
|
2817
|
-
const { handler, filter } = normalizeObjectHook("transform", transformHook);
|
|
2818
|
-
replaceHookHandler("transform", transformHook, function(...args) {
|
|
2819
|
-
const [code, id] = args;
|
|
2820
|
-
if (plugin.transformInclude && !plugin.transformInclude(id)) return;
|
|
2821
|
-
const supportFilter = supportNativeFilter(this, key);
|
|
2822
|
-
if (!supportFilter && !filter(id, code)) return;
|
|
2823
|
-
return handler.apply(this, args);
|
|
2824
|
-
});
|
|
2825
|
-
}
|
|
2826
|
-
if (plugin[key]) Object.assign(plugin, plugin[key]);
|
|
2827
|
-
return plugin;
|
|
2828
|
-
function replaceHookHandler(name, hook, handler) {
|
|
2829
|
-
if (typeof hook === "function") plugin[name] = handler;
|
|
2830
|
-
else hook.handler = handler;
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
function supportNativeFilter(context, framework) {
|
|
2834
|
-
if (framework === "unloader") return false;
|
|
2835
|
-
if (framework === "vite") return !!context?.meta?.viteVersion;
|
|
2836
|
-
if (framework === "rolldown") return true;
|
|
2837
|
-
const rollupVersion = context?.meta?.rollupVersion;
|
|
2838
|
-
if (!rollupVersion) return false;
|
|
2839
|
-
const [major, minor] = rollupVersion.split(".");
|
|
2840
|
-
return Number(major) > 4 || Number(major) === 4 && Number(minor) >= 40;
|
|
2841
|
-
}
|
|
2842
|
-
|
|
2843
|
-
//#endregion
|
|
2844
|
-
//#region src/rolldown/index.ts
|
|
2845
|
-
function getRolldownPlugin(factory) {
|
|
2846
|
-
return ((userOptions) => {
|
|
2847
|
-
const meta = { framework: "rolldown" };
|
|
2848
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
2849
|
-
const plugins = rawPlugins.map((rawPlugin) => {
|
|
2850
|
-
const plugin = toRollupPlugin(rawPlugin, "rolldown");
|
|
2851
|
-
return plugin;
|
|
2852
|
-
});
|
|
2853
|
-
return plugins.length === 1 ? plugins[0] : plugins;
|
|
2854
|
-
});
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
//#endregion
|
|
2858
|
-
//#region node_modules/.pnpm/tsdown@0.14.1_publint@0.3.5_typescript@5.9.2_unplugin-unused@0.5.2_vue-tsc@3.0.6_typescript@5.9.2_/node_modules/tsdown/esm-shims.js
|
|
2859
|
-
const getFilename = () => fileURLToPath(import.meta.url);
|
|
2860
|
-
const getDirname = () => path.dirname(getFilename());
|
|
2861
|
-
const __dirname = /* @__PURE__ */ getDirname();
|
|
2862
|
-
|
|
2863
|
-
//#endregion
|
|
2864
|
-
//#region src/rspack/index.ts
|
|
2865
|
-
const TRANSFORM_LOADER$1 = resolve$3(__dirname, "rspack/loaders/transform");
|
|
2866
|
-
const LOAD_LOADER$1 = resolve$3(__dirname, "rspack/loaders/load");
|
|
2867
|
-
function getRspackPlugin(factory) {
|
|
2868
|
-
return (userOptions) => {
|
|
2869
|
-
return { apply(compiler) {
|
|
2870
|
-
const VIRTUAL_MODULE_PREFIX = resolve$3(compiler.options.context ?? process.cwd(), "node_modules/.virtual", process.pid.toString());
|
|
2871
|
-
const meta = {
|
|
2872
|
-
framework: "rspack",
|
|
2873
|
-
rspack: { compiler }
|
|
2874
|
-
};
|
|
2875
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
2876
|
-
for (const rawPlugin of rawPlugins) {
|
|
2877
|
-
const plugin = Object.assign(rawPlugin, {
|
|
2878
|
-
__unpluginMeta: meta,
|
|
2879
|
-
__virtualModulePrefix: VIRTUAL_MODULE_PREFIX
|
|
2880
|
-
});
|
|
2881
|
-
const externalModules = /* @__PURE__ */ new Set();
|
|
2882
|
-
if (plugin.resolveId) {
|
|
2883
|
-
const createPlugin = (plugin$1) => {
|
|
2884
|
-
if (compiler.rspack.experiments.VirtualModulesPlugin) return new compiler.rspack.experiments.VirtualModulesPlugin();
|
|
2885
|
-
return new FakeVirtualModulesPlugin(plugin$1);
|
|
2886
|
-
};
|
|
2887
|
-
const vfs = createPlugin(plugin);
|
|
2888
|
-
vfs.apply(compiler);
|
|
2889
|
-
const vfsModules = /* @__PURE__ */ new Map();
|
|
2890
|
-
plugin.__vfsModules = vfsModules;
|
|
2891
|
-
plugin.__vfs = vfs;
|
|
2892
|
-
compiler.hooks.compilation.tap(plugin.name, (compilation, { normalModuleFactory }) => {
|
|
2893
|
-
normalModuleFactory.hooks.resolve.tapPromise(plugin.name, async (resolveData) => {
|
|
2894
|
-
const id = normalizeAbsolutePath(resolveData.request);
|
|
2895
|
-
const requestContext = resolveData.contextInfo;
|
|
2896
|
-
let importer = requestContext.issuer !== "" ? requestContext.issuer : void 0;
|
|
2897
|
-
const isEntry = requestContext.issuer === "";
|
|
2898
|
-
if (importer?.startsWith(plugin.__virtualModulePrefix)) importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
|
|
2899
|
-
const context = createBuildContext$1(compiler, compilation);
|
|
2900
|
-
let error;
|
|
2901
|
-
const pluginContext = {
|
|
2902
|
-
error(msg) {
|
|
2903
|
-
if (error == null) error = normalizeMessage$1(msg);
|
|
2904
|
-
else console.error(`unplugin/rspack: multiple errors returned from resolveId hook: ${msg}`);
|
|
2905
|
-
},
|
|
2906
|
-
warn(msg) {
|
|
2907
|
-
console.warn(`unplugin/rspack: warning from resolveId hook: ${msg}`);
|
|
2908
|
-
}
|
|
2909
|
-
};
|
|
2910
|
-
const { handler, filter } = normalizeObjectHook("resolveId", plugin.resolveId);
|
|
2911
|
-
if (!filter(id)) return;
|
|
2912
|
-
const resolveIdResult = await handler.call({
|
|
2913
|
-
...context,
|
|
2914
|
-
...pluginContext
|
|
2915
|
-
}, id, importer, { isEntry });
|
|
2916
|
-
if (error != null) throw error;
|
|
2917
|
-
if (resolveIdResult == null) return;
|
|
2918
|
-
let resolved = typeof resolveIdResult === "string" ? resolveIdResult : resolveIdResult.id;
|
|
2919
|
-
const isExternal = typeof resolveIdResult === "string" ? false : resolveIdResult.external === true;
|
|
2920
|
-
if (isExternal) externalModules.add(resolved);
|
|
2921
|
-
let isVirtual = true;
|
|
2922
|
-
try {
|
|
2923
|
-
(compiler.inputFileSystem?.statSync ?? fs.statSync)(resolved);
|
|
2924
|
-
isVirtual = false;
|
|
2925
|
-
} catch {
|
|
2926
|
-
isVirtual = !isVirtualModuleId(resolved, plugin);
|
|
2927
|
-
}
|
|
2928
|
-
if (isVirtual) {
|
|
2929
|
-
const encodedVirtualPath = encodeVirtualModuleId(resolved, plugin);
|
|
2930
|
-
if (!vfsModules.has(resolved)) {
|
|
2931
|
-
const fsPromise = Promise.resolve(vfs.writeModule(encodedVirtualPath, ""));
|
|
2932
|
-
vfsModules.set(resolved, fsPromise);
|
|
2933
|
-
await fsPromise;
|
|
2934
|
-
} else await vfsModules.get(resolved);
|
|
2935
|
-
resolved = encodedVirtualPath;
|
|
2936
|
-
}
|
|
2937
|
-
resolveData.request = resolved;
|
|
2938
|
-
});
|
|
2939
|
-
});
|
|
2940
|
-
}
|
|
2941
|
-
if (plugin.load) compiler.options.module.rules.unshift({
|
|
2942
|
-
enforce: plugin.enforce,
|
|
2943
|
-
include(id) {
|
|
2944
|
-
if (isVirtualModuleId(id, plugin)) id = decodeVirtualModuleId(id);
|
|
2945
|
-
if (plugin.loadInclude && !plugin.loadInclude(id)) return false;
|
|
2946
|
-
const { filter } = normalizeObjectHook("load", plugin.load);
|
|
2947
|
-
if (!filter(id)) return false;
|
|
2948
|
-
return !externalModules.has(id);
|
|
2949
|
-
},
|
|
2950
|
-
use: [{
|
|
2951
|
-
loader: LOAD_LOADER$1,
|
|
2952
|
-
options: { plugin }
|
|
2953
|
-
}],
|
|
2954
|
-
type: "javascript/auto"
|
|
2955
|
-
});
|
|
2956
|
-
if (plugin.transform) compiler.options.module.rules.unshift({
|
|
2957
|
-
enforce: plugin.enforce,
|
|
2958
|
-
use(data) {
|
|
2959
|
-
return transformUse(data, plugin, TRANSFORM_LOADER$1);
|
|
2960
|
-
}
|
|
2961
|
-
});
|
|
2962
|
-
if (plugin.rspack) plugin.rspack(compiler);
|
|
2963
|
-
if (plugin.watchChange || plugin.buildStart) compiler.hooks.make.tapPromise(plugin.name, async (compilation) => {
|
|
2964
|
-
const context = createBuildContext$1(compiler, compilation);
|
|
2965
|
-
if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) {
|
|
2966
|
-
const promises = [];
|
|
2967
|
-
if (compiler.modifiedFiles) compiler.modifiedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "update" }))));
|
|
2968
|
-
if (compiler.removedFiles) compiler.removedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "delete" }))));
|
|
2969
|
-
await Promise.all(promises);
|
|
2970
|
-
}
|
|
2971
|
-
if (plugin.buildStart) return await plugin.buildStart.call(context);
|
|
2972
|
-
});
|
|
2973
|
-
if (plugin.buildEnd) compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => {
|
|
2974
|
-
await plugin.buildEnd.call(createBuildContext$1(compiler, compilation));
|
|
2975
|
-
});
|
|
2976
|
-
if (plugin.writeBundle) compiler.hooks.afterEmit.tapPromise(plugin.name, async () => {
|
|
2977
|
-
await plugin.writeBundle();
|
|
2978
|
-
});
|
|
2979
|
-
}
|
|
2980
|
-
} };
|
|
2981
|
-
};
|
|
2982
|
-
}
|
|
2983
|
-
|
|
2984
|
-
//#endregion
|
|
2985
|
-
//#region src/unloader/index.ts
|
|
2986
|
-
function getUnloaderPlugin(factory) {
|
|
2987
|
-
return ((userOptions) => {
|
|
2988
|
-
const meta = { framework: "unloader" };
|
|
2989
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
2990
|
-
const plugins = rawPlugins.map((rawPlugin) => {
|
|
2991
|
-
const plugin = toRollupPlugin(rawPlugin, "unloader");
|
|
2992
|
-
return plugin;
|
|
2993
|
-
});
|
|
2994
|
-
return plugins.length === 1 ? plugins[0] : plugins;
|
|
2995
|
-
});
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
|
-
//#endregion
|
|
2999
|
-
//#region src/vite/index.ts
|
|
3000
|
-
function getVitePlugin(factory) {
|
|
3001
|
-
return ((userOptions) => {
|
|
3002
|
-
const meta = { framework: "vite" };
|
|
3003
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
3004
|
-
const plugins = rawPlugins.map((rawPlugin) => {
|
|
3005
|
-
const plugin = toRollupPlugin(rawPlugin, "vite");
|
|
3006
|
-
return plugin;
|
|
3007
|
-
});
|
|
3008
|
-
return plugins.length === 1 ? plugins[0] : plugins;
|
|
3009
|
-
});
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
//#endregion
|
|
3013
|
-
//#region src/webpack/index.ts
|
|
3014
|
-
const TRANSFORM_LOADER = resolve$3(__dirname, "webpack/loaders/transform");
|
|
3015
|
-
const LOAD_LOADER = resolve$3(__dirname, "webpack/loaders/load");
|
|
3016
|
-
function getWebpackPlugin(factory) {
|
|
3017
|
-
return (userOptions) => {
|
|
3018
|
-
return { apply(compiler) {
|
|
3019
|
-
const VIRTUAL_MODULE_PREFIX = resolve$3(compiler.options.context ?? process$1.cwd(), "_virtual_");
|
|
3020
|
-
const meta = {
|
|
3021
|
-
framework: "webpack",
|
|
3022
|
-
webpack: { compiler }
|
|
3023
|
-
};
|
|
3024
|
-
const rawPlugins = toArray$2(factory(userOptions, meta));
|
|
3025
|
-
for (const rawPlugin of rawPlugins) {
|
|
3026
|
-
const plugin = Object.assign(rawPlugin, {
|
|
3027
|
-
__unpluginMeta: meta,
|
|
3028
|
-
__virtualModulePrefix: VIRTUAL_MODULE_PREFIX
|
|
3029
|
-
});
|
|
3030
|
-
const externalModules = /* @__PURE__ */ new Set();
|
|
3031
|
-
if (plugin.resolveId) {
|
|
3032
|
-
let vfs = compiler.options.plugins.find((i) => i instanceof VirtualModulesPlugin);
|
|
3033
|
-
if (!vfs) {
|
|
3034
|
-
vfs = new VirtualModulesPlugin();
|
|
3035
|
-
compiler.options.plugins.push(vfs);
|
|
3036
|
-
}
|
|
3037
|
-
const vfsModules = /* @__PURE__ */ new Set();
|
|
3038
|
-
plugin.__vfsModules = vfsModules;
|
|
3039
|
-
plugin.__vfs = vfs;
|
|
3040
|
-
const resolverPlugin = { apply(resolver) {
|
|
3041
|
-
const target = resolver.ensureHook("resolve");
|
|
3042
|
-
resolver.getHook("resolve").tapAsync(plugin.name, async (request, resolveContext, callback) => {
|
|
3043
|
-
if (!request.request) return callback();
|
|
3044
|
-
if (normalizeAbsolutePath(request.request).startsWith(plugin.__virtualModulePrefix)) return callback();
|
|
3045
|
-
const id = normalizeAbsolutePath(request.request);
|
|
3046
|
-
const requestContext = request.context;
|
|
3047
|
-
let importer = requestContext.issuer !== "" ? requestContext.issuer : void 0;
|
|
3048
|
-
const isEntry = requestContext.issuer === "";
|
|
3049
|
-
if (importer?.startsWith(plugin.__virtualModulePrefix)) importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
|
|
3050
|
-
const fileDependencies = /* @__PURE__ */ new Set();
|
|
3051
|
-
const context = createBuildContext({
|
|
3052
|
-
addWatchFile(file) {
|
|
3053
|
-
fileDependencies.add(file);
|
|
3054
|
-
resolveContext.fileDependencies?.add(file);
|
|
3055
|
-
},
|
|
3056
|
-
getWatchFiles() {
|
|
3057
|
-
return Array.from(fileDependencies);
|
|
3058
|
-
}
|
|
3059
|
-
}, compiler);
|
|
3060
|
-
let error;
|
|
3061
|
-
const pluginContext = {
|
|
3062
|
-
error(msg) {
|
|
3063
|
-
if (error == null) error = normalizeMessage(msg);
|
|
3064
|
-
else console.error(`unplugin/webpack: multiple errors returned from resolveId hook: ${msg}`);
|
|
3065
|
-
},
|
|
3066
|
-
warn(msg) {
|
|
3067
|
-
console.warn(`unplugin/webpack: warning from resolveId hook: ${msg}`);
|
|
3068
|
-
}
|
|
3069
|
-
};
|
|
3070
|
-
const { handler, filter } = normalizeObjectHook("resolveId", plugin.resolveId);
|
|
3071
|
-
if (!filter(id)) return callback();
|
|
3072
|
-
const resolveIdResult = await handler.call({
|
|
3073
|
-
...context,
|
|
3074
|
-
...pluginContext
|
|
3075
|
-
}, id, importer, { isEntry });
|
|
3076
|
-
if (error != null) return callback(error);
|
|
3077
|
-
if (resolveIdResult == null) return callback();
|
|
3078
|
-
let resolved = typeof resolveIdResult === "string" ? resolveIdResult : resolveIdResult.id;
|
|
3079
|
-
const isExternal = typeof resolveIdResult === "string" ? false : resolveIdResult.external === true;
|
|
3080
|
-
if (isExternal) externalModules.add(resolved);
|
|
3081
|
-
if (!fs.existsSync(resolved)) {
|
|
3082
|
-
resolved = normalizeAbsolutePath(plugin.__virtualModulePrefix + encodeURIComponent(resolved));
|
|
3083
|
-
if (!vfsModules.has(resolved)) {
|
|
3084
|
-
plugin.__vfs.writeModule(resolved, "");
|
|
3085
|
-
vfsModules.add(resolved);
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
const newRequest = {
|
|
3089
|
-
...request,
|
|
3090
|
-
request: resolved
|
|
3091
|
-
};
|
|
3092
|
-
resolver.doResolve(target, newRequest, null, resolveContext, callback);
|
|
3093
|
-
});
|
|
3094
|
-
} };
|
|
3095
|
-
compiler.options.resolve.plugins = compiler.options.resolve.plugins || [];
|
|
3096
|
-
compiler.options.resolve.plugins.push(resolverPlugin);
|
|
3097
|
-
}
|
|
3098
|
-
if (plugin.load) compiler.options.module.rules.unshift({
|
|
3099
|
-
include(id) {
|
|
3100
|
-
return shouldLoad(id, plugin, externalModules);
|
|
3101
|
-
},
|
|
3102
|
-
enforce: plugin.enforce,
|
|
3103
|
-
use: [{
|
|
3104
|
-
loader: LOAD_LOADER,
|
|
3105
|
-
options: { plugin }
|
|
3106
|
-
}],
|
|
3107
|
-
type: "javascript/auto"
|
|
3108
|
-
});
|
|
3109
|
-
if (plugin.transform) compiler.options.module.rules.unshift({
|
|
3110
|
-
enforce: plugin.enforce,
|
|
3111
|
-
use(data) {
|
|
3112
|
-
return transformUse(data, plugin, TRANSFORM_LOADER);
|
|
3113
|
-
}
|
|
3114
|
-
});
|
|
3115
|
-
if (plugin.webpack) plugin.webpack(compiler);
|
|
3116
|
-
if (plugin.watchChange || plugin.buildStart) compiler.hooks.make.tapPromise(plugin.name, async (compilation) => {
|
|
3117
|
-
const context = createBuildContext(contextOptionsFromCompilation(compilation), compiler, compilation);
|
|
3118
|
-
if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) {
|
|
3119
|
-
const promises = [];
|
|
3120
|
-
if (compiler.modifiedFiles) compiler.modifiedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "update" }))));
|
|
3121
|
-
if (compiler.removedFiles) compiler.removedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "delete" }))));
|
|
3122
|
-
await Promise.all(promises);
|
|
3123
|
-
}
|
|
3124
|
-
if (plugin.buildStart) return await plugin.buildStart.call(context);
|
|
3125
|
-
});
|
|
3126
|
-
if (plugin.buildEnd) compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => {
|
|
3127
|
-
await plugin.buildEnd.call(createBuildContext(contextOptionsFromCompilation(compilation), compiler, compilation));
|
|
3128
|
-
});
|
|
3129
|
-
if (plugin.writeBundle) compiler.hooks.afterEmit.tapPromise(plugin.name, async () => {
|
|
3130
|
-
await plugin.writeBundle();
|
|
3131
|
-
});
|
|
3132
|
-
}
|
|
3133
|
-
} };
|
|
3134
|
-
};
|
|
3135
|
-
}
|
|
3136
|
-
function shouldLoad(id, plugin, externalModules) {
|
|
3137
|
-
if (id.startsWith(plugin.__virtualModulePrefix)) id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
|
|
3138
|
-
if (plugin.loadInclude && !plugin.loadInclude(id)) return false;
|
|
3139
|
-
const { filter } = normalizeObjectHook("load", plugin.load);
|
|
3140
|
-
if (!filter(id)) return false;
|
|
3141
|
-
return !externalModules.has(id);
|
|
3142
|
-
}
|
|
3143
|
-
|
|
3144
|
-
//#endregion
|
|
3145
|
-
//#region src/define.ts
|
|
3146
|
-
function createUnplugin(factory) {
|
|
3147
|
-
return {
|
|
3148
|
-
get esbuild() {
|
|
3149
|
-
return getEsbuildPlugin(factory);
|
|
3150
|
-
},
|
|
3151
|
-
get rollup() {
|
|
3152
|
-
return getRollupPlugin(factory);
|
|
3153
|
-
},
|
|
3154
|
-
get vite() {
|
|
3155
|
-
return getVitePlugin(factory);
|
|
3156
|
-
},
|
|
3157
|
-
get rolldown() {
|
|
3158
|
-
return getRolldownPlugin(factory);
|
|
3159
|
-
},
|
|
3160
|
-
get webpack() {
|
|
3161
|
-
return getWebpackPlugin(factory);
|
|
3162
|
-
},
|
|
3163
|
-
get rspack() {
|
|
3164
|
-
return getRspackPlugin(factory);
|
|
3165
|
-
},
|
|
3166
|
-
get farm() {
|
|
3167
|
-
return getFarmPlugin(factory);
|
|
3168
|
-
},
|
|
3169
|
-
get unloader() {
|
|
3170
|
-
return getUnloaderPlugin(factory);
|
|
3171
|
-
},
|
|
3172
|
-
get raw() {
|
|
3173
|
-
return factory;
|
|
3174
|
-
}
|
|
3175
|
-
};
|
|
3176
|
-
}
|
|
3177
|
-
|
|
3178
|
-
//#region src/path.ts
|
|
3179
|
-
/**
|
|
3180
|
-
* Converts path separators to forward slash.
|
|
3181
|
-
*/
|
|
3182
|
-
function normalizePath(filename) {
|
|
3183
|
-
return filename.replaceAll("\\", "/");
|
|
3184
|
-
}
|
|
3185
|
-
|
|
3186
|
-
//#endregion
|
|
3187
|
-
//#region src/utils.ts
|
|
3188
|
-
const isArray = Array.isArray;
|
|
3189
|
-
function toArray$1(thing) {
|
|
3190
|
-
if (isArray(thing)) return thing;
|
|
3191
|
-
if (thing == null) return [];
|
|
3192
|
-
return [thing];
|
|
3193
|
-
}
|
|
3194
|
-
|
|
3195
|
-
//#endregion
|
|
3196
|
-
//#region src/filter.ts
|
|
3197
|
-
const escapeMark = "[_#EsCaPe#_]";
|
|
3198
|
-
function getMatcherString(id, resolutionBase) {
|
|
3199
|
-
if (isAbsolute$3(id) || id.startsWith("**")) return normalizePath(id);
|
|
3200
|
-
const basePath = normalizePath(resolve$2("")).replaceAll(/[-^$*+?.()|[\]{}]/g, `${escapeMark}$&`);
|
|
3201
|
-
return join(basePath, normalizePath(id)).replaceAll(escapeMark, "\\");
|
|
3202
|
-
}
|
|
3203
|
-
/**
|
|
3204
|
-
* Constructs a filter function which can be used to determine whether or not
|
|
3205
|
-
* certain modules should be operated upon.
|
|
3206
|
-
* @param include If `include` is omitted or has zero length, filter will return `true` by default.
|
|
3207
|
-
* @param exclude ID must not match any of the `exclude` patterns.
|
|
3208
|
-
* @param options Additional options.
|
|
3209
|
-
* @param options.resolve Optionally resolves the patterns against a directory other than `process.cwd()`.
|
|
3210
|
-
* If a `string` is specified, then the value will be used as the base directory.
|
|
3211
|
-
* Relative paths will be resolved against `process.cwd()` first.
|
|
3212
|
-
* If `false`, then the patterns will not be resolved against any directory.
|
|
3213
|
-
* This can be useful if you want to create a filter for virtual module names.
|
|
3214
|
-
*/
|
|
3215
|
-
function createFilter(include, exclude, options) {
|
|
3216
|
-
const getMatcher = (id) => id instanceof RegExp ? id : { test: (what) => {
|
|
3217
|
-
const pattern = getMatcherString(id);
|
|
3218
|
-
return pm(pattern, { dot: true })(what);
|
|
3219
|
-
} };
|
|
3220
|
-
const includeMatchers = toArray$1(include).map(getMatcher);
|
|
3221
|
-
const excludeMatchers = toArray$1(exclude).map(getMatcher);
|
|
3222
|
-
if (!includeMatchers.length && !excludeMatchers.length) return (id) => typeof id === "string" && !id.includes("\0");
|
|
3223
|
-
return function result(id) {
|
|
3224
|
-
if (typeof id !== "string") return false;
|
|
3225
|
-
if (id.includes("\0")) return false;
|
|
3226
|
-
const pathId = normalizePath(id);
|
|
3227
|
-
for (const matcher of excludeMatchers) {
|
|
3228
|
-
if (matcher instanceof RegExp) matcher.lastIndex = 0;
|
|
3229
|
-
if (matcher.test(pathId)) return false;
|
|
3230
|
-
}
|
|
3231
|
-
for (const matcher of includeMatchers) {
|
|
3232
|
-
if (matcher instanceof RegExp) matcher.lastIndex = 0;
|
|
3233
|
-
if (matcher.test(pathId)) return true;
|
|
3234
|
-
}
|
|
3235
|
-
return !includeMatchers.length;
|
|
3236
|
-
};
|
|
3237
|
-
}
|
|
3238
|
-
|
|
3239
|
-
const defaultIncludes = [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/, /\.svelte$/];
|
|
3240
|
-
const defaultExcludes = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/];
|
|
3241
|
-
function toArray(x) {
|
|
3242
|
-
return x == null ? [] : Array.isArray(x) ? x : [x];
|
|
3243
|
-
}
|
|
3244
|
-
const unplugin$1 = createUnplugin((options = {}) => {
|
|
3245
|
-
const ctx = createUnimport(options);
|
|
3246
|
-
const filter = createFilter(
|
|
3247
|
-
toArray(options.include || []).length ? options.include : defaultIncludes,
|
|
3248
|
-
options.exclude || defaultExcludes
|
|
3249
|
-
);
|
|
3250
|
-
const dts = options.dts === true ? "unimport.d.ts" : options.dts;
|
|
3251
|
-
const {
|
|
3252
|
-
autoImport = true
|
|
3253
|
-
} = options;
|
|
3254
|
-
return {
|
|
3255
|
-
name: "unimport",
|
|
3256
|
-
enforce: "post",
|
|
3257
|
-
transformInclude(id) {
|
|
3258
|
-
return filter(id);
|
|
3259
|
-
},
|
|
3260
|
-
async transform(code, id) {
|
|
3261
|
-
const s = new MagicString(code);
|
|
3262
|
-
await ctx.injectImports(s, id, {
|
|
3263
|
-
autoImport
|
|
3264
|
-
});
|
|
3265
|
-
if (!s.hasChanged())
|
|
3266
|
-
return;
|
|
3267
|
-
return {
|
|
3268
|
-
code: s.toString(),
|
|
3269
|
-
map: s.generateMap()
|
|
3270
|
-
};
|
|
3271
|
-
},
|
|
3272
|
-
async buildStart() {
|
|
3273
|
-
await ctx.init();
|
|
3274
|
-
if (dts)
|
|
3275
|
-
return promises.writeFile(dts, await ctx.generateTypeDeclarations(), "utf-8");
|
|
3276
|
-
}
|
|
3277
|
-
};
|
|
3278
|
-
});
|
|
5
|
+
import { a as genSafeVariableName, b as genImport, c as genString, d as genObjectFromRaw } from './knitwork.mjs';
|
|
6
|
+
import { b as basename } from './pathe.mjs';
|
|
3279
7
|
|
|
3280
8
|
var __create = Object.create;
|
|
3281
9
|
var __defProp = Object.defineProperty;
|
|
@@ -9887,7 +6615,7 @@ async function getWasmImports(asset, _opts) {
|
|
|
9887
6615
|
resolved: true
|
|
9888
6616
|
};
|
|
9889
6617
|
}
|
|
9890
|
-
const { readPackageJSON } = await import('./
|
|
6618
|
+
const { readPackageJSON } = await import('./pkg-types.mjs').then(function (n) { return n.i; });
|
|
9891
6619
|
const pkgJSON = await readPackageJSON(asset.id);
|
|
9892
6620
|
let resolved = true;
|
|
9893
6621
|
const imports = [];
|
|
@@ -10165,7 +6893,7 @@ const unplugin = createUnplugin((opts) => {
|
|
|
10165
6893
|
}
|
|
10166
6894
|
const buff = Buffer.from(code, "binary");
|
|
10167
6895
|
const isModule = id.endsWith("?module");
|
|
10168
|
-
const name = `wasm/${basename
|
|
6896
|
+
const name = `wasm/${basename(id.split("?")[0], ".wasm")}-${sha1(buff)}.wasm`;
|
|
10169
6897
|
const parsed = isModule ? { imports: [], exports: ["default"] } : parse(name, buff);
|
|
10170
6898
|
const asset = assets[name] = {
|
|
10171
6899
|
name,
|
|
@@ -10228,930 +6956,4 @@ const unplugin = createUnplugin((opts) => {
|
|
|
10228
6956
|
});
|
|
10229
6957
|
const rollup = unplugin.rollup;
|
|
10230
6958
|
|
|
10231
|
-
|
|
10232
|
-
function virtual(modules, cache = {}) {
|
|
10233
|
-
const _modules = /* @__PURE__ */ new Map();
|
|
10234
|
-
for (const [id, mod] of Object.entries(modules)) {
|
|
10235
|
-
cache[id] = mod;
|
|
10236
|
-
_modules.set(id, mod);
|
|
10237
|
-
_modules.set(resolve$2(id), mod);
|
|
10238
|
-
}
|
|
10239
|
-
return {
|
|
10240
|
-
name: "virtual",
|
|
10241
|
-
resolveId(id, importer) {
|
|
10242
|
-
if (id in modules) {
|
|
10243
|
-
return PREFIX + id;
|
|
10244
|
-
}
|
|
10245
|
-
if (importer) {
|
|
10246
|
-
const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer;
|
|
10247
|
-
const resolved = resolve$2(dirname$1(importerNoPrefix), id);
|
|
10248
|
-
if (_modules.has(resolved)) {
|
|
10249
|
-
return PREFIX + resolved;
|
|
10250
|
-
}
|
|
10251
|
-
}
|
|
10252
|
-
return null;
|
|
10253
|
-
},
|
|
10254
|
-
async load(id) {
|
|
10255
|
-
if (!id.startsWith(PREFIX)) {
|
|
10256
|
-
return null;
|
|
10257
|
-
}
|
|
10258
|
-
const idNoPrefix = id.slice(PREFIX.length);
|
|
10259
|
-
if (!_modules.has(idNoPrefix)) {
|
|
10260
|
-
return null;
|
|
10261
|
-
}
|
|
10262
|
-
let m = _modules.get(idNoPrefix);
|
|
10263
|
-
if (typeof m === "function") {
|
|
10264
|
-
m = await m();
|
|
10265
|
-
}
|
|
10266
|
-
if (!m) {
|
|
10267
|
-
return null;
|
|
10268
|
-
}
|
|
10269
|
-
cache[id.replace(PREFIX, "")] = m;
|
|
10270
|
-
return {
|
|
10271
|
-
code: m,
|
|
10272
|
-
map: null
|
|
10273
|
-
};
|
|
10274
|
-
}
|
|
10275
|
-
};
|
|
10276
|
-
}
|
|
10277
|
-
|
|
10278
|
-
function database(nitro) {
|
|
10279
|
-
if (!nitro.options.experimental.database) {
|
|
10280
|
-
return virtual(
|
|
10281
|
-
{
|
|
10282
|
-
"#nitro-internal-virtual/database": () => {
|
|
10283
|
-
return (
|
|
10284
|
-
/* js */
|
|
10285
|
-
`export const connectionConfigs = {};`
|
|
10286
|
-
);
|
|
10287
|
-
}
|
|
10288
|
-
},
|
|
10289
|
-
nitro.vfs
|
|
10290
|
-
);
|
|
10291
|
-
}
|
|
10292
|
-
const dbConfigs = nitro.options.dev && nitro.options.devDatabase || nitro.options.database;
|
|
10293
|
-
const connectorsNames = [
|
|
10294
|
-
...new Set(
|
|
10295
|
-
Object.values(dbConfigs || {}).map((config) => config?.connector)
|
|
10296
|
-
)
|
|
10297
|
-
].filter(Boolean);
|
|
10298
|
-
for (const name of connectorsNames) {
|
|
10299
|
-
if (!connectors[name]) {
|
|
10300
|
-
throw new Error(`Database connector "${name}" is invalid.`);
|
|
10301
|
-
}
|
|
10302
|
-
}
|
|
10303
|
-
return virtual(
|
|
10304
|
-
{
|
|
10305
|
-
"#nitro-internal-virtual/database": () => {
|
|
10306
|
-
return `
|
|
10307
|
-
${connectorsNames.map(
|
|
10308
|
-
(name) => `import ${camelCase(name)}Connector from "${connectors[name]}";`
|
|
10309
|
-
).join("\n")}
|
|
10310
|
-
|
|
10311
|
-
export const connectionConfigs = {
|
|
10312
|
-
${Object.entries(dbConfigs || {}).map(
|
|
10313
|
-
([name, { connector, options }]) => `${name}: {
|
|
10314
|
-
connector: ${camelCase(connector)}Connector,
|
|
10315
|
-
options: ${JSON.stringify(options)}
|
|
10316
|
-
}`
|
|
10317
|
-
).join(",\n")}
|
|
10318
|
-
};
|
|
10319
|
-
`;
|
|
10320
|
-
}
|
|
10321
|
-
},
|
|
10322
|
-
nitro.vfs
|
|
10323
|
-
);
|
|
10324
|
-
}
|
|
10325
|
-
|
|
10326
|
-
const RuntimeRouteRules = [
|
|
10327
|
-
"headers",
|
|
10328
|
-
"redirect",
|
|
10329
|
-
"proxy",
|
|
10330
|
-
"cache"
|
|
10331
|
-
];
|
|
10332
|
-
function routing(nitro) {
|
|
10333
|
-
return virtual(
|
|
10334
|
-
{
|
|
10335
|
-
// --- routing (routes, routeRules and middleware) ---
|
|
10336
|
-
"#nitro-internal-virtual/routing": () => {
|
|
10337
|
-
const allHandlers = uniqueBy(
|
|
10338
|
-
[
|
|
10339
|
-
...Object.values(nitro.routing.routes.routes).map((h) => h.data),
|
|
10340
|
-
...Object.values(nitro.routing.routedMiddleware.routes).map(
|
|
10341
|
-
(h) => h.data
|
|
10342
|
-
),
|
|
10343
|
-
...nitro.routing.globalMiddleware
|
|
10344
|
-
],
|
|
10345
|
-
"_importHash"
|
|
10346
|
-
);
|
|
10347
|
-
const h3Imports = [
|
|
10348
|
-
(nitro.options.serverEntry || allHandlers.some((h) => !h.lazy)) && "toEventHandler",
|
|
10349
|
-
allHandlers.some((h) => h.lazy) && "defineLazyEventHandler"
|
|
10350
|
-
].filter(Boolean);
|
|
10351
|
-
return (
|
|
10352
|
-
/* js */
|
|
10353
|
-
`
|
|
10354
|
-
import * as __routeRules__ from "nitro/runtime/internal/route-rules";
|
|
10355
|
-
${nitro.options.serverEntry ? `import __serverEntry__ from ${JSON.stringify(nitro.options.serverEntry)};` : ""}
|
|
10356
|
-
import {${h3Imports.join(", ")}} from "h3";
|
|
10357
|
-
|
|
10358
|
-
export const findRouteRules = ${nitro.routing.routeRules.compileToString({ serialize: serializeRouteRule, matchAll: true })}
|
|
10359
|
-
|
|
10360
|
-
${allHandlers.filter((h) => !h.lazy).map((h) => (
|
|
10361
|
-
/* js */
|
|
10362
|
-
`import ${h._importHash} from "${h.handler}";`
|
|
10363
|
-
)).join("\n")}
|
|
10364
|
-
|
|
10365
|
-
${allHandlers.filter((h) => h.lazy).map(
|
|
10366
|
-
(h) => (
|
|
10367
|
-
/* js */
|
|
10368
|
-
`const ${h._importHash} = defineLazyEventHandler(() => import("${h.handler}"));`
|
|
10369
|
-
)
|
|
10370
|
-
).join("\n")}
|
|
10371
|
-
|
|
10372
|
-
export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
|
|
10373
|
-
|
|
10374
|
-
export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({ serialize: serializeHandler, matchAll: true })};
|
|
10375
|
-
|
|
10376
|
-
export const globalMiddleware = [${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `toEventHandler(${h._importHash})`).join(",")}];
|
|
10377
|
-
|
|
10378
|
-
${nitro.options.serverEntry && /* js */
|
|
10379
|
-
`const serverEntry = toEventHandler(__serverEntry__);
|
|
10380
|
-
if (serverEntry) { globalMiddleware.push(serverEntry) }`}
|
|
10381
|
-
`
|
|
10382
|
-
);
|
|
10383
|
-
},
|
|
10384
|
-
// --- routing-meta ---
|
|
10385
|
-
"#nitro-internal-virtual/routing-meta": () => {
|
|
10386
|
-
const routeHandlers = uniqueBy(
|
|
10387
|
-
Object.values(nitro.routing.routes.routes).map((h) => h.data),
|
|
10388
|
-
"_importHash"
|
|
10389
|
-
);
|
|
10390
|
-
return (
|
|
10391
|
-
/* js */
|
|
10392
|
-
`
|
|
10393
|
-
${routeHandlers.map(
|
|
10394
|
-
(h) => (
|
|
10395
|
-
/* js */
|
|
10396
|
-
`import ${h._importHash}Meta from "${h.handler}?meta";`
|
|
10397
|
-
)
|
|
10398
|
-
).join("\n")}
|
|
10399
|
-
export const handlersMeta = [
|
|
10400
|
-
${routeHandlers.map(
|
|
10401
|
-
(h) => (
|
|
10402
|
-
/* js */
|
|
10403
|
-
`{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(
|
|
10404
|
-
h.method?.toLowerCase()
|
|
10405
|
-
)}, meta: ${h._importHash}Meta }`
|
|
10406
|
-
)
|
|
10407
|
-
).join(",\n")}
|
|
10408
|
-
];
|
|
10409
|
-
`.trim()
|
|
10410
|
-
);
|
|
10411
|
-
}
|
|
10412
|
-
},
|
|
10413
|
-
nitro.vfs
|
|
10414
|
-
);
|
|
10415
|
-
}
|
|
10416
|
-
function uniqueBy(arr, key) {
|
|
10417
|
-
return [...new Map(arr.map((item) => [item[key], item])).values()];
|
|
10418
|
-
}
|
|
10419
|
-
function serializeHandler(h) {
|
|
10420
|
-
return `{${[
|
|
10421
|
-
`route:${JSON.stringify(h.route)}`,
|
|
10422
|
-
h.method && `method:${JSON.stringify(h.method)}`,
|
|
10423
|
-
h.meta && `meta:${JSON.stringify(h.meta)}`,
|
|
10424
|
-
`handler:${h.lazy ? h._importHash : `toEventHandler(${h._importHash})`}`
|
|
10425
|
-
].filter(Boolean).join(",")}}`;
|
|
10426
|
-
}
|
|
10427
|
-
function serializeRouteRule(h) {
|
|
10428
|
-
return `[${Object.entries(h).filter(([name, options]) => options !== void 0 && name[0] !== "_").map(([name, options]) => {
|
|
10429
|
-
return `{${[
|
|
10430
|
-
`name:${JSON.stringify(name)}`,
|
|
10431
|
-
`route:${JSON.stringify(h._route)}`,
|
|
10432
|
-
h._method && `method:${JSON.stringify(h._method)}`,
|
|
10433
|
-
RuntimeRouteRules.includes(name) && `handler:__routeRules__.${name}`,
|
|
10434
|
-
`options:${JSON.stringify(options)}`
|
|
10435
|
-
].filter(Boolean).join(",")}}`;
|
|
10436
|
-
}).join(",")}]`;
|
|
10437
|
-
}
|
|
10438
|
-
|
|
10439
|
-
const virtualPrefix = "\0nitro-handler-meta:";
|
|
10440
|
-
const esbuildLoaders = {
|
|
10441
|
-
".ts": "ts",
|
|
10442
|
-
".js": "js",
|
|
10443
|
-
".tsx": "tsx",
|
|
10444
|
-
".jsx": "jsx"
|
|
10445
|
-
};
|
|
10446
|
-
function routeMeta(nitro) {
|
|
10447
|
-
return {
|
|
10448
|
-
name: "nitro:route-meta",
|
|
10449
|
-
async resolveId(id, importer, resolveOpts) {
|
|
10450
|
-
if (id.startsWith("\0")) {
|
|
10451
|
-
return;
|
|
10452
|
-
}
|
|
10453
|
-
if (id.endsWith(`?meta`)) {
|
|
10454
|
-
const resolved = await this.resolve(
|
|
10455
|
-
id.replace(`?meta`, ``),
|
|
10456
|
-
importer,
|
|
10457
|
-
resolveOpts
|
|
10458
|
-
);
|
|
10459
|
-
if (!resolved) {
|
|
10460
|
-
return;
|
|
10461
|
-
}
|
|
10462
|
-
return virtualPrefix + resolved.id;
|
|
10463
|
-
}
|
|
10464
|
-
},
|
|
10465
|
-
load(id) {
|
|
10466
|
-
if (id.startsWith(virtualPrefix)) {
|
|
10467
|
-
const fullPath = id.slice(virtualPrefix.length);
|
|
10468
|
-
return readFile(fullPath, { encoding: "utf8" });
|
|
10469
|
-
}
|
|
10470
|
-
},
|
|
10471
|
-
async transform(code, id) {
|
|
10472
|
-
if (!id.startsWith(virtualPrefix)) {
|
|
10473
|
-
return;
|
|
10474
|
-
}
|
|
10475
|
-
let meta = null;
|
|
10476
|
-
try {
|
|
10477
|
-
const ext = extname$1(id);
|
|
10478
|
-
const jsCode = await transform(code, {
|
|
10479
|
-
loader: esbuildLoaders[ext]
|
|
10480
|
-
}).then((r) => r.code);
|
|
10481
|
-
const ast = this.parse(jsCode);
|
|
10482
|
-
for (const node of ast.body) {
|
|
10483
|
-
if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "defineRouteMeta" && node.expression.arguments.length === 1) {
|
|
10484
|
-
meta = astToObject(node.expression.arguments[0]);
|
|
10485
|
-
break;
|
|
10486
|
-
}
|
|
10487
|
-
}
|
|
10488
|
-
} catch (error) {
|
|
10489
|
-
nitro.logger.warn(
|
|
10490
|
-
`[handlers-meta] Cannot extra route meta for: ${id}: ${error}`
|
|
10491
|
-
);
|
|
10492
|
-
}
|
|
10493
|
-
return {
|
|
10494
|
-
code: `export default ${JSON.stringify(meta)};`,
|
|
10495
|
-
map: null
|
|
10496
|
-
};
|
|
10497
|
-
}
|
|
10498
|
-
};
|
|
10499
|
-
}
|
|
10500
|
-
function astToObject(node) {
|
|
10501
|
-
switch (node.type) {
|
|
10502
|
-
case "ObjectExpression": {
|
|
10503
|
-
const obj = {};
|
|
10504
|
-
for (const prop of node.properties) {
|
|
10505
|
-
if (prop.type === "Property") {
|
|
10506
|
-
const key = prop.key.name ?? prop.key.value;
|
|
10507
|
-
obj[key] = astToObject(prop.value);
|
|
10508
|
-
}
|
|
10509
|
-
}
|
|
10510
|
-
return obj;
|
|
10511
|
-
}
|
|
10512
|
-
case "ArrayExpression": {
|
|
10513
|
-
return node.elements.map((el) => astToObject(el)).filter(Boolean);
|
|
10514
|
-
}
|
|
10515
|
-
case "Literal": {
|
|
10516
|
-
return node.value;
|
|
10517
|
-
}
|
|
10518
|
-
}
|
|
10519
|
-
}
|
|
10520
|
-
|
|
10521
|
-
function serverMain(nitro) {
|
|
10522
|
-
return {
|
|
10523
|
-
name: "nitro:server-main",
|
|
10524
|
-
renderChunk(code, chunk) {
|
|
10525
|
-
if (chunk.isEntry) {
|
|
10526
|
-
return {
|
|
10527
|
-
code: `globalThis.__nitro_main__ = import.meta.url; ${code}`,
|
|
10528
|
-
map: null
|
|
10529
|
-
};
|
|
10530
|
-
}
|
|
10531
|
-
}
|
|
10532
|
-
};
|
|
10533
|
-
}
|
|
10534
|
-
|
|
10535
|
-
var etagExports = requireEtag();
|
|
10536
|
-
const createEtag = /*@__PURE__*/getDefaultExportFromCjs(etagExports);
|
|
10537
|
-
|
|
10538
|
-
const readAssetHandler = {
|
|
10539
|
-
true: "node",
|
|
10540
|
-
node: "node",
|
|
10541
|
-
false: "null",
|
|
10542
|
-
deno: "deno",
|
|
10543
|
-
inline: "inline"
|
|
10544
|
-
};
|
|
10545
|
-
function publicAssets(nitro) {
|
|
10546
|
-
return virtual(
|
|
10547
|
-
{
|
|
10548
|
-
// #nitro-internal-virtual/public-assets-data
|
|
10549
|
-
"#nitro-internal-virtual/public-assets-data": async () => {
|
|
10550
|
-
const assets = {};
|
|
10551
|
-
const files = await glob("**", {
|
|
10552
|
-
cwd: nitro.options.output.publicDir,
|
|
10553
|
-
absolute: false,
|
|
10554
|
-
dot: true
|
|
10555
|
-
});
|
|
10556
|
-
for (const id of files) {
|
|
10557
|
-
let mimeType = mime.getType(id.replace(/\.(gz|br)$/, "")) || "text/plain";
|
|
10558
|
-
if (mimeType.startsWith("text")) {
|
|
10559
|
-
mimeType += "; charset=utf-8";
|
|
10560
|
-
}
|
|
10561
|
-
const fullPath = resolve$2(nitro.options.output.publicDir, id);
|
|
10562
|
-
const assetData = await promises.readFile(fullPath);
|
|
10563
|
-
const etag = createEtag(assetData);
|
|
10564
|
-
const stat = await promises.stat(fullPath);
|
|
10565
|
-
const assetId = "/" + decodeURIComponent(id);
|
|
10566
|
-
let encoding;
|
|
10567
|
-
if (id.endsWith(".gz")) {
|
|
10568
|
-
encoding = "gzip";
|
|
10569
|
-
} else if (id.endsWith(".br")) {
|
|
10570
|
-
encoding = "br";
|
|
10571
|
-
}
|
|
10572
|
-
assets[assetId] = {
|
|
10573
|
-
type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType,
|
|
10574
|
-
encoding,
|
|
10575
|
-
etag,
|
|
10576
|
-
mtime: stat.mtime.toJSON(),
|
|
10577
|
-
size: stat.size,
|
|
10578
|
-
path: relative(nitro.options.output.serverDir, fullPath),
|
|
10579
|
-
data: nitro.options.serveStatic === "inline" ? assetData.toString("base64") : void 0
|
|
10580
|
-
};
|
|
10581
|
-
}
|
|
10582
|
-
return `export default ${JSON.stringify(assets, null, 2)};`;
|
|
10583
|
-
},
|
|
10584
|
-
// #nitro-internal-virtual/public-assets-node
|
|
10585
|
-
"#nitro-internal-virtual/public-assets-node": () => {
|
|
10586
|
-
return `
|
|
10587
|
-
import { promises as fsp } from 'node:fs'
|
|
10588
|
-
import { fileURLToPath } from 'node:url'
|
|
10589
|
-
import { resolve, dirname } from 'node:path'
|
|
10590
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
10591
|
-
export function readAsset (id) {
|
|
10592
|
-
const serverDir = dirname(fileURLToPath(globalThis.__nitro_main__))
|
|
10593
|
-
return fsp.readFile(resolve(serverDir, assets[id].path))
|
|
10594
|
-
}`;
|
|
10595
|
-
},
|
|
10596
|
-
// #nitro-internal-virtual/public-assets-deno
|
|
10597
|
-
"#nitro-internal-virtual/public-assets-deno": () => {
|
|
10598
|
-
return `
|
|
10599
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
10600
|
-
export function readAsset (id) {
|
|
10601
|
-
// https://deno.com/deploy/docs/serve-static-assets
|
|
10602
|
-
const path = '.' + decodeURIComponent(new URL(\`../public\${id}\`, 'file://').pathname)
|
|
10603
|
-
return Deno.readFile(path);
|
|
10604
|
-
}`;
|
|
10605
|
-
},
|
|
10606
|
-
// #nitro-internal-virtual/public-assets-null
|
|
10607
|
-
"#nitro-internal-virtual/public-assets-null": () => {
|
|
10608
|
-
return `
|
|
10609
|
-
export function readAsset (id) {
|
|
10610
|
-
return Promise.resolve(null);
|
|
10611
|
-
}`;
|
|
10612
|
-
},
|
|
10613
|
-
// #nitro-internal-virtual/public-assets-inline
|
|
10614
|
-
"#nitro-internal-virtual/public-assets-inline": () => {
|
|
10615
|
-
return `
|
|
10616
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
10617
|
-
export function readAsset (id) {
|
|
10618
|
-
if (!assets[id]) { return undefined }
|
|
10619
|
-
if (assets[id]._data) { return assets[id]._data }
|
|
10620
|
-
if (!assets[id].data) { return assets[id].data }
|
|
10621
|
-
assets[id]._data = Uint8Array.from(atob(assets[id].data), (c) => c.charCodeAt(0))
|
|
10622
|
-
return assets[id]._data
|
|
10623
|
-
}`;
|
|
10624
|
-
},
|
|
10625
|
-
// #nitro-internal-virtual/public-assets
|
|
10626
|
-
"#nitro-internal-virtual/public-assets": () => {
|
|
10627
|
-
const publicAssetBases = Object.fromEntries(
|
|
10628
|
-
nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [
|
|
10629
|
-
withTrailingSlash(dir.baseURL),
|
|
10630
|
-
{ maxAge: dir.maxAge }
|
|
10631
|
-
])
|
|
10632
|
-
);
|
|
10633
|
-
const handlerName = readAssetHandler[nitro.options.serveStatic] || "null";
|
|
10634
|
-
const readAssetImport = `#nitro-internal-virtual/public-assets-${handlerName}`;
|
|
10635
|
-
return `
|
|
10636
|
-
import assets from '#nitro-internal-virtual/public-assets-data'
|
|
10637
|
-
export { readAsset } from "${readAssetImport}"
|
|
10638
|
-
export const publicAssetBases = ${JSON.stringify(publicAssetBases)}
|
|
10639
|
-
|
|
10640
|
-
export function isPublicAssetURL(id = '') {
|
|
10641
|
-
if (assets[id]) {
|
|
10642
|
-
return true
|
|
10643
|
-
}
|
|
10644
|
-
for (const base in publicAssetBases) {
|
|
10645
|
-
if (id.startsWith(base)) { return true }
|
|
10646
|
-
}
|
|
10647
|
-
return false
|
|
10648
|
-
}
|
|
10649
|
-
|
|
10650
|
-
export function getPublicAssetMeta(id = '') {
|
|
10651
|
-
for (const base in publicAssetBases) {
|
|
10652
|
-
if (id.startsWith(base)) { return publicAssetBases[base] }
|
|
10653
|
-
}
|
|
10654
|
-
return {}
|
|
10655
|
-
}
|
|
10656
|
-
|
|
10657
|
-
export function getAsset (id) {
|
|
10658
|
-
return assets[id]
|
|
10659
|
-
}
|
|
10660
|
-
`;
|
|
10661
|
-
}
|
|
10662
|
-
},
|
|
10663
|
-
nitro.vfs
|
|
10664
|
-
);
|
|
10665
|
-
}
|
|
10666
|
-
|
|
10667
|
-
const HELPER_ID = "\0raw-helpers";
|
|
10668
|
-
function raw(opts = {}) {
|
|
10669
|
-
const extensions = /* @__PURE__ */ new Set([
|
|
10670
|
-
".md",
|
|
10671
|
-
".mdx",
|
|
10672
|
-
".txt",
|
|
10673
|
-
".css",
|
|
10674
|
-
".htm",
|
|
10675
|
-
".html",
|
|
10676
|
-
".sql",
|
|
10677
|
-
...opts.extensions || []
|
|
10678
|
-
]);
|
|
10679
|
-
return {
|
|
10680
|
-
name: "raw",
|
|
10681
|
-
async resolveId(id, importer, resolveOpts) {
|
|
10682
|
-
if (id === HELPER_ID) {
|
|
10683
|
-
return id;
|
|
10684
|
-
}
|
|
10685
|
-
if (id[0] === "\0") {
|
|
10686
|
-
return;
|
|
10687
|
-
}
|
|
10688
|
-
const withRawSpecifier = id.startsWith("raw:");
|
|
10689
|
-
if (withRawSpecifier) {
|
|
10690
|
-
id = id.slice(4);
|
|
10691
|
-
}
|
|
10692
|
-
if (!withRawSpecifier && !extensions.has(extname$1(id))) {
|
|
10693
|
-
return;
|
|
10694
|
-
}
|
|
10695
|
-
const resolvedId = (await this.resolve(id, importer, resolveOpts))?.id;
|
|
10696
|
-
if (!resolvedId || resolvedId.startsWith("\0")) {
|
|
10697
|
-
return resolvedId;
|
|
10698
|
-
}
|
|
10699
|
-
if (!withRawSpecifier && !extensions.has(extname$1(resolvedId))) {
|
|
10700
|
-
return;
|
|
10701
|
-
}
|
|
10702
|
-
return { id: "\0raw:" + resolvedId };
|
|
10703
|
-
},
|
|
10704
|
-
load(id) {
|
|
10705
|
-
if (id === HELPER_ID) {
|
|
10706
|
-
return getHelpers();
|
|
10707
|
-
}
|
|
10708
|
-
if (id.startsWith("\0raw:")) {
|
|
10709
|
-
return promises.readFile(id.slice(5), isBinary(id) ? "binary" : "utf8");
|
|
10710
|
-
}
|
|
10711
|
-
},
|
|
10712
|
-
transform(code, id) {
|
|
10713
|
-
if (!id.startsWith("\0raw:")) {
|
|
10714
|
-
return;
|
|
10715
|
-
}
|
|
10716
|
-
if (isBinary(id)) {
|
|
10717
|
-
const serialized = Buffer.from(code, "binary").toString("base64");
|
|
10718
|
-
return {
|
|
10719
|
-
code: `// ROLLUP_NO_REPLACE
|
|
10720
|
-
import {base64ToUint8Array } from "${HELPER_ID}"
|
|
10721
|
-
export default base64ToUint8Array("${serialized}")`,
|
|
10722
|
-
map: null
|
|
10723
|
-
};
|
|
10724
|
-
}
|
|
10725
|
-
return {
|
|
10726
|
-
code: `// ROLLUP_NO_REPLACE
|
|
10727
|
-
export default ${JSON.stringify(code)}`,
|
|
10728
|
-
map: null,
|
|
10729
|
-
moduleType: "js"
|
|
10730
|
-
};
|
|
10731
|
-
}
|
|
10732
|
-
};
|
|
10733
|
-
}
|
|
10734
|
-
function isBinary(id) {
|
|
10735
|
-
const idMime = mime.getType(id) || "";
|
|
10736
|
-
if (idMime.startsWith("text/")) {
|
|
10737
|
-
return false;
|
|
10738
|
-
}
|
|
10739
|
-
if (/application\/(json|sql|xml|yaml)/.test(idMime)) {
|
|
10740
|
-
return false;
|
|
10741
|
-
}
|
|
10742
|
-
return true;
|
|
10743
|
-
}
|
|
10744
|
-
function getHelpers() {
|
|
10745
|
-
const js = String.raw;
|
|
10746
|
-
return js`
|
|
10747
|
-
export function base64ToUint8Array(str) {
|
|
10748
|
-
const data = atob(str);
|
|
10749
|
-
const size = data.length;
|
|
10750
|
-
const bytes = new Uint8Array(size);
|
|
10751
|
-
for (let i = 0; i < size; i++) {
|
|
10752
|
-
bytes[i] = data.charCodeAt(i);
|
|
10753
|
-
}
|
|
10754
|
-
return bytes;
|
|
10755
|
-
}
|
|
10756
|
-
`;
|
|
10757
|
-
}
|
|
10758
|
-
|
|
10759
|
-
function serverAssets(nitro) {
|
|
10760
|
-
if (nitro.options.dev || nitro.options.preset === "nitro-prerender") {
|
|
10761
|
-
return virtual(
|
|
10762
|
-
{ "#nitro-internal-virtual/server-assets": getAssetsDev(nitro) },
|
|
10763
|
-
nitro.vfs
|
|
10764
|
-
);
|
|
10765
|
-
}
|
|
10766
|
-
return virtual(
|
|
10767
|
-
{
|
|
10768
|
-
"#nitro-internal-virtual/server-assets": async () => {
|
|
10769
|
-
const assets = {};
|
|
10770
|
-
for (const asset of nitro.options.serverAssets) {
|
|
10771
|
-
const files = await glob(asset.pattern || "**/*", {
|
|
10772
|
-
cwd: asset.dir,
|
|
10773
|
-
absolute: false,
|
|
10774
|
-
ignore: asset.ignore
|
|
10775
|
-
});
|
|
10776
|
-
for (const _id of files) {
|
|
10777
|
-
const fsPath = resolve$2(asset.dir, _id);
|
|
10778
|
-
const id = asset.baseName + "/" + _id;
|
|
10779
|
-
assets[id] = { fsPath, meta: {} };
|
|
10780
|
-
let type = mime.getType(id) || "text/plain";
|
|
10781
|
-
if (type.startsWith("text")) {
|
|
10782
|
-
type += "; charset=utf-8";
|
|
10783
|
-
}
|
|
10784
|
-
const etag = createEtag(await promises.readFile(fsPath));
|
|
10785
|
-
const mtime = await promises.stat(fsPath).then((s) => s.mtime.toJSON());
|
|
10786
|
-
assets[id].meta = { type, etag, mtime };
|
|
10787
|
-
}
|
|
10788
|
-
}
|
|
10789
|
-
return getAssetProd(assets);
|
|
10790
|
-
}
|
|
10791
|
-
},
|
|
10792
|
-
nitro.vfs
|
|
10793
|
-
);
|
|
10794
|
-
}
|
|
10795
|
-
function getAssetsDev(nitro) {
|
|
10796
|
-
return `
|
|
10797
|
-
import { createStorage } from 'unstorage'
|
|
10798
|
-
import fsDriver from 'unstorage/drivers/fs'
|
|
10799
|
-
|
|
10800
|
-
const serverAssets = ${JSON.stringify(nitro.options.serverAssets)}
|
|
10801
|
-
|
|
10802
|
-
export const assets = createStorage()
|
|
10803
|
-
|
|
10804
|
-
for (const asset of serverAssets) {
|
|
10805
|
-
assets.mount(asset.baseName, fsDriver({ base: asset.dir, ignore: (asset?.ignore || []) }))
|
|
10806
|
-
}`;
|
|
10807
|
-
}
|
|
10808
|
-
function getAssetProd(assets) {
|
|
10809
|
-
return `
|
|
10810
|
-
const _assets = {
|
|
10811
|
-
${Object.entries(assets).map(
|
|
10812
|
-
([id, asset]) => ` [${JSON.stringify(
|
|
10813
|
-
normalizeKey(id)
|
|
10814
|
-
)}]: {
|
|
10815
|
-
import: () => import(${JSON.stringify(
|
|
10816
|
-
"raw:" + asset.fsPath
|
|
10817
|
-
)}).then(r => r.default || r),
|
|
10818
|
-
meta: ${JSON.stringify(
|
|
10819
|
-
asset.meta
|
|
10820
|
-
)}
|
|
10821
|
-
}`
|
|
10822
|
-
).join(",\n")}
|
|
10823
|
-
}
|
|
10824
|
-
|
|
10825
|
-
const normalizeKey = ${normalizeKey.toString()}
|
|
10826
|
-
|
|
10827
|
-
export const assets = {
|
|
10828
|
-
getKeys() {
|
|
10829
|
-
return Promise.resolve(Object.keys(_assets))
|
|
10830
|
-
},
|
|
10831
|
-
hasItem (id) {
|
|
10832
|
-
id = normalizeKey(id)
|
|
10833
|
-
return Promise.resolve(id in _assets)
|
|
10834
|
-
},
|
|
10835
|
-
getItem (id) {
|
|
10836
|
-
id = normalizeKey(id)
|
|
10837
|
-
return Promise.resolve(_assets[id] ? _assets[id].import() : null)
|
|
10838
|
-
},
|
|
10839
|
-
getMeta (id) {
|
|
10840
|
-
id = normalizeKey(id)
|
|
10841
|
-
return Promise.resolve(_assets[id] ? _assets[id].meta : {})
|
|
10842
|
-
}
|
|
10843
|
-
}
|
|
10844
|
-
`;
|
|
10845
|
-
}
|
|
10846
|
-
|
|
10847
|
-
function storage(nitro) {
|
|
10848
|
-
const mounts = [];
|
|
10849
|
-
const isDevOrPrerender = nitro.options.dev || nitro.options.preset === "nitro-prerender";
|
|
10850
|
-
const storageMounts = isDevOrPrerender ? { ...nitro.options.storage, ...nitro.options.devStorage } : nitro.options.storage;
|
|
10851
|
-
for (const path in storageMounts) {
|
|
10852
|
-
const mount = storageMounts[path];
|
|
10853
|
-
mounts.push({
|
|
10854
|
-
path,
|
|
10855
|
-
driver: builtinDrivers[mount.driver] || mount.driver,
|
|
10856
|
-
opts: mount
|
|
10857
|
-
});
|
|
10858
|
-
}
|
|
10859
|
-
const driverImports = [...new Set(mounts.map((m) => m.driver))];
|
|
10860
|
-
const bundledStorageCode = `
|
|
10861
|
-
import { prefixStorage } from 'unstorage'
|
|
10862
|
-
import overlay from 'unstorage/drivers/overlay'
|
|
10863
|
-
import memory from 'unstorage/drivers/memory'
|
|
10864
|
-
|
|
10865
|
-
const bundledStorage = ${JSON.stringify(nitro.options.bundledStorage)}
|
|
10866
|
-
for (const base of bundledStorage) {
|
|
10867
|
-
storage.mount(base, overlay({
|
|
10868
|
-
layers: [
|
|
10869
|
-
memory(),
|
|
10870
|
-
// TODO
|
|
10871
|
-
// prefixStorage(storage, base),
|
|
10872
|
-
prefixStorage(storage, 'assets:nitro:bundled:' + base)
|
|
10873
|
-
]
|
|
10874
|
-
}))
|
|
10875
|
-
}`;
|
|
10876
|
-
return virtual(
|
|
10877
|
-
{
|
|
10878
|
-
"#nitro-internal-virtual/storage": (
|
|
10879
|
-
/* js */
|
|
10880
|
-
`
|
|
10881
|
-
import { createStorage } from 'unstorage'
|
|
10882
|
-
import { assets } from '#nitro-internal-virtual/server-assets'
|
|
10883
|
-
|
|
10884
|
-
${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
|
|
10885
|
-
|
|
10886
|
-
export function initStorage() {
|
|
10887
|
-
const storage = createStorage({})
|
|
10888
|
-
storage.mount('/assets', assets)
|
|
10889
|
-
${mounts.map(
|
|
10890
|
-
(m) => `storage.mount('${m.path}', ${genSafeVariableName(
|
|
10891
|
-
m.driver
|
|
10892
|
-
)}(${JSON.stringify(m.opts)}))`
|
|
10893
|
-
).join("\n")}
|
|
10894
|
-
|
|
10895
|
-
${!isDevOrPrerender && nitro.options.bundledStorage.length > 0 ? bundledStorageCode : ""}
|
|
10896
|
-
return storage
|
|
10897
|
-
}
|
|
10898
|
-
`
|
|
10899
|
-
)
|
|
10900
|
-
},
|
|
10901
|
-
nitro.vfs
|
|
10902
|
-
);
|
|
10903
|
-
}
|
|
10904
|
-
|
|
10905
|
-
function errorHandler(nitro) {
|
|
10906
|
-
return virtual(
|
|
10907
|
-
{
|
|
10908
|
-
"#nitro-internal-virtual/error-handler": () => {
|
|
10909
|
-
const errorHandlers = Array.isArray(nitro.options.errorHandler) ? nitro.options.errorHandler : [nitro.options.errorHandler];
|
|
10910
|
-
const builtinHandler = join(
|
|
10911
|
-
runtimeDir,
|
|
10912
|
-
`internal/error/${nitro.options.dev ? "dev" : "prod"}`
|
|
10913
|
-
);
|
|
10914
|
-
return (
|
|
10915
|
-
/* js */
|
|
10916
|
-
`
|
|
10917
|
-
${errorHandlers.map((h, i) => `import errorHandler$${i} from "${h}";`).join("\n")}
|
|
10918
|
-
|
|
10919
|
-
const errorHandlers = [${errorHandlers.map((_, i) => `errorHandler$${i}`).join(", ")}];
|
|
10920
|
-
|
|
10921
|
-
import { defaultHandler } from "${builtinHandler}";
|
|
10922
|
-
|
|
10923
|
-
export default async function(error, event) {
|
|
10924
|
-
for (const handler of errorHandlers) {
|
|
10925
|
-
try {
|
|
10926
|
-
const response = await handler(error, event, { defaultHandler });
|
|
10927
|
-
if (response) {
|
|
10928
|
-
return response;
|
|
10929
|
-
}
|
|
10930
|
-
} catch(error) {
|
|
10931
|
-
// Handler itself thrown, log and continue
|
|
10932
|
-
console.error(error);
|
|
10933
|
-
}
|
|
10934
|
-
}
|
|
10935
|
-
// H3 will handle fallback
|
|
10936
|
-
}
|
|
10937
|
-
`
|
|
10938
|
-
);
|
|
10939
|
-
}
|
|
10940
|
-
},
|
|
10941
|
-
nitro.vfs
|
|
10942
|
-
);
|
|
10943
|
-
}
|
|
10944
|
-
|
|
10945
|
-
function rendererTemplate(nitro) {
|
|
10946
|
-
return virtual(
|
|
10947
|
-
{
|
|
10948
|
-
"#nitro-internal-virtual/renderer-template": async () => {
|
|
10949
|
-
if (typeof nitro.options.renderer?.template !== "string") {
|
|
10950
|
-
return `export const rendererTemplate = () => '<!-- renderer.template is not set -->'; export const rendererTemplateFile = undefined;`;
|
|
10951
|
-
}
|
|
10952
|
-
if (nitro.options.dev) {
|
|
10953
|
-
return `import { readFile } from 'node:fs/promises';export const rendererTemplate = () => readFile(${JSON.stringify(nitro.options.renderer?.template)}, "utf8"); export const rendererTemplateFile = ${JSON.stringify(
|
|
10954
|
-
nitro.options.renderer?.template
|
|
10955
|
-
)};`;
|
|
10956
|
-
} else {
|
|
10957
|
-
const html = await readFile(nitro.options.renderer?.template, "utf8");
|
|
10958
|
-
if (hasTemplateSyntax(html)) {
|
|
10959
|
-
const template = compileTemplateToString(html, {
|
|
10960
|
-
contextKeys: [...RENDER_CONTEXT_KEYS]
|
|
10961
|
-
});
|
|
10962
|
-
return (
|
|
10963
|
-
/* js */
|
|
10964
|
-
`
|
|
10965
|
-
import { renderToResponse } from 'rendu'
|
|
10966
|
-
const template = ${template};
|
|
10967
|
-
export const rendererTemplate = (request) => renderToResponse(template, { request })
|
|
10968
|
-
`
|
|
10969
|
-
);
|
|
10970
|
-
} else {
|
|
10971
|
-
return (
|
|
10972
|
-
/* js */
|
|
10973
|
-
`
|
|
10974
|
-
import { HTTPResponse } from "h3";
|
|
10975
|
-
export const rendererTemplate = () => new HTTPResponse(${JSON.stringify(html)}, { headers: { "content-type": "text/html; charset=utf-8" } });
|
|
10976
|
-
`
|
|
10977
|
-
);
|
|
10978
|
-
}
|
|
10979
|
-
}
|
|
10980
|
-
}
|
|
10981
|
-
},
|
|
10982
|
-
nitro.vfs
|
|
10983
|
-
);
|
|
10984
|
-
}
|
|
10985
|
-
|
|
10986
|
-
function baseBuildPlugins(nitro, base) {
|
|
10987
|
-
const plugins = [];
|
|
10988
|
-
if (nitro.options.imports) {
|
|
10989
|
-
plugins.push(unplugin$1.rollup(nitro.options.imports));
|
|
10990
|
-
}
|
|
10991
|
-
plugins.push(raw());
|
|
10992
|
-
if (nitro.options.experimental.wasm) {
|
|
10993
|
-
plugins.push(rollup(nitro.options.wasm || {}));
|
|
10994
|
-
}
|
|
10995
|
-
plugins.push(serverMain());
|
|
10996
|
-
const nitroPlugins = [...new Set(nitro.options.plugins)];
|
|
10997
|
-
plugins.push(
|
|
10998
|
-
virtual(
|
|
10999
|
-
{
|
|
11000
|
-
"#nitro-internal-virtual/plugins": (
|
|
11001
|
-
/* js */
|
|
11002
|
-
`
|
|
11003
|
-
${nitroPlugins.map(
|
|
11004
|
-
(plugin) => `import _${hash(plugin).replace(/-/g, "")} from '${plugin}';`
|
|
11005
|
-
).join("\n")}
|
|
11006
|
-
|
|
11007
|
-
export const plugins = [
|
|
11008
|
-
${nitroPlugins.map((plugin) => `_${hash(plugin).replace(/-/g, "")}`).join(",\n")}
|
|
11009
|
-
]
|
|
11010
|
-
`
|
|
11011
|
-
)
|
|
11012
|
-
},
|
|
11013
|
-
nitro.vfs
|
|
11014
|
-
)
|
|
11015
|
-
);
|
|
11016
|
-
plugins.push(serverAssets(nitro));
|
|
11017
|
-
plugins.push(publicAssets(nitro));
|
|
11018
|
-
plugins.push(storage(nitro));
|
|
11019
|
-
plugins.push(database(nitro));
|
|
11020
|
-
plugins.push(routing(nitro));
|
|
11021
|
-
if (nitro.options.experimental.openAPI) {
|
|
11022
|
-
plugins.push(routeMeta(nitro));
|
|
11023
|
-
}
|
|
11024
|
-
plugins.push(errorHandler(nitro));
|
|
11025
|
-
plugins.push(
|
|
11026
|
-
virtual(
|
|
11027
|
-
{
|
|
11028
|
-
"#nitro-internal-pollyfills": base.env.polyfill.map((p) => (
|
|
11029
|
-
/* js */
|
|
11030
|
-
`import '${p}';`
|
|
11031
|
-
)).join("\n") || /* js */
|
|
11032
|
-
`/* No polyfills */`
|
|
11033
|
-
},
|
|
11034
|
-
nitro.vfs
|
|
11035
|
-
)
|
|
11036
|
-
);
|
|
11037
|
-
plugins.push(virtual(nitro.options.virtual, nitro.vfs));
|
|
11038
|
-
if (nitro.options.renderer?.template) {
|
|
11039
|
-
plugins.push(rendererTemplate(nitro));
|
|
11040
|
-
}
|
|
11041
|
-
if (nitro.options.noExternals) {
|
|
11042
|
-
plugins.push({
|
|
11043
|
-
name: "no-externals",
|
|
11044
|
-
async resolveId(id, importer, resolveOpts) {
|
|
11045
|
-
if (resolveOpts.custom?.skipNoExternals) {
|
|
11046
|
-
return;
|
|
11047
|
-
}
|
|
11048
|
-
id = base.aliases[id] || id;
|
|
11049
|
-
if (base.env.external.includes(id) || nitro.options.node && (id.startsWith("node:") || builtinModules.includes(id))) {
|
|
11050
|
-
return { id, external: true };
|
|
11051
|
-
}
|
|
11052
|
-
const resolved = await this.resolve(id, importer, resolveOpts);
|
|
11053
|
-
if (!resolved) {
|
|
11054
|
-
const _resolved = resolveModulePath(id, {
|
|
11055
|
-
try: true,
|
|
11056
|
-
from: importer && isAbsolute$3(importer) ? [pathToFileURL(importer), ...nitro.options.nodeModulesDirs] : nitro.options.nodeModulesDirs,
|
|
11057
|
-
suffixes: ["", "/index"],
|
|
11058
|
-
extensions: [".mjs", ".cjs", ".js", ".mts", ".cts", ".ts", ".json"],
|
|
11059
|
-
conditions: [
|
|
11060
|
-
"default",
|
|
11061
|
-
nitro.options.dev ? "development" : "production",
|
|
11062
|
-
"node",
|
|
11063
|
-
"import",
|
|
11064
|
-
"require"
|
|
11065
|
-
]
|
|
11066
|
-
});
|
|
11067
|
-
if (_resolved) {
|
|
11068
|
-
return { id: _resolved, external: false };
|
|
11069
|
-
}
|
|
11070
|
-
}
|
|
11071
|
-
if (!resolved || resolved.external && !id.endsWith(".wasm")) {
|
|
11072
|
-
throw new Error(
|
|
11073
|
-
`Cannot resolve ${JSON.stringify(id)} from ${JSON.stringify(
|
|
11074
|
-
importer
|
|
11075
|
-
)} and externals are not allowed!`
|
|
11076
|
-
);
|
|
11077
|
-
}
|
|
11078
|
-
}
|
|
11079
|
-
});
|
|
11080
|
-
} else {
|
|
11081
|
-
plugins.push(
|
|
11082
|
-
rollupNodeFileTrace(
|
|
11083
|
-
defu(nitro.options.externals, {
|
|
11084
|
-
outDir: nitro.options.output.serverDir,
|
|
11085
|
-
moduleDirectories: nitro.options.nodeModulesDirs,
|
|
11086
|
-
external: [
|
|
11087
|
-
...nitro.options.dev ? [nitro.options.buildDir] : [],
|
|
11088
|
-
...nitro.options.nodeModulesDirs
|
|
11089
|
-
],
|
|
11090
|
-
inline: [
|
|
11091
|
-
"#",
|
|
11092
|
-
"~",
|
|
11093
|
-
"@/",
|
|
11094
|
-
"~~",
|
|
11095
|
-
"@@/",
|
|
11096
|
-
"virtual:",
|
|
11097
|
-
"nitro/runtime",
|
|
11098
|
-
"nitro/runtime",
|
|
11099
|
-
dirname$1(nitro.options.entry),
|
|
11100
|
-
...nitro.options.experimental.wasm ? [(id) => id?.endsWith(".wasm")] : [],
|
|
11101
|
-
runtimeDir,
|
|
11102
|
-
nitro.options.srcDir,
|
|
11103
|
-
...nitro.options.handlers.map((m) => m.handler).filter((i) => typeof i === "string"),
|
|
11104
|
-
...nitro.options.dev || nitro.options.preset === "nitro-prerender" || nitro.options.experimental.bundleRuntimeDependencies === false ? [] : runtimeDependencies
|
|
11105
|
-
],
|
|
11106
|
-
traceOptions: {
|
|
11107
|
-
base: "/",
|
|
11108
|
-
processCwd: nitro.options.rootDir,
|
|
11109
|
-
exportsOnly: true
|
|
11110
|
-
},
|
|
11111
|
-
traceAlias: {
|
|
11112
|
-
"h3-nightly": "h3",
|
|
11113
|
-
...nitro.options.externals?.traceAlias
|
|
11114
|
-
},
|
|
11115
|
-
exportConditions: nitro.options.exportConditions,
|
|
11116
|
-
writePackageJson: true
|
|
11117
|
-
})
|
|
11118
|
-
)
|
|
11119
|
-
);
|
|
11120
|
-
}
|
|
11121
|
-
return plugins;
|
|
11122
|
-
}
|
|
11123
|
-
|
|
11124
|
-
const presetsWithConfig = ["awsAmplify", "awsLambda", "azure", "cloudflare", "firebase", "netlify", "vercel"];
|
|
11125
|
-
|
|
11126
|
-
async function writeBuildInfo(nitro) {
|
|
11127
|
-
const buildInfoPath = resolve$2(nitro.options.output.dir, "nitro.json");
|
|
11128
|
-
const buildInfo = {
|
|
11129
|
-
date: (/* @__PURE__ */ new Date()).toJSON(),
|
|
11130
|
-
preset: nitro.options.preset,
|
|
11131
|
-
framework: nitro.options.framework,
|
|
11132
|
-
versions: {
|
|
11133
|
-
nitro: version
|
|
11134
|
-
},
|
|
11135
|
-
commands: {
|
|
11136
|
-
preview: nitro.options.commands.preview,
|
|
11137
|
-
deploy: nitro.options.commands.deploy
|
|
11138
|
-
},
|
|
11139
|
-
config: {
|
|
11140
|
-
...Object.fromEntries(
|
|
11141
|
-
presetsWithConfig.map((key) => [key, nitro.options[key]])
|
|
11142
|
-
)
|
|
11143
|
-
}
|
|
11144
|
-
};
|
|
11145
|
-
await writeFile(buildInfoPath, JSON.stringify(buildInfo, null, 2), true);
|
|
11146
|
-
const lastBuild = resolve$2(
|
|
11147
|
-
nitro.options.rootDir,
|
|
11148
|
-
"node_modules/.nitro/last-build"
|
|
11149
|
-
);
|
|
11150
|
-
await mkdir(dirname(lastBuild), { recursive: true });
|
|
11151
|
-
await unlink(lastBuild).catch(() => {
|
|
11152
|
-
});
|
|
11153
|
-
await symlink(nitro.options.output.dir, lastBuild).catch(console.warn);
|
|
11154
|
-
return buildInfo;
|
|
11155
|
-
}
|
|
11156
|
-
|
|
11157
|
-
export { attachScopes as a, baseBuildConfig as b, createFilter$2 as c, baseBuildPlugins as d, writeBuildInfo as e, extractAssignedNames as f, dataToEsm as g, createFilter as h, makeLegalIdentifier as m, replace as r, walk as w };
|
|
6959
|
+
export { rollup as r };
|