@shijiu/jsview 2.3.151-test.0 → 3.0.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dom/bin/jsview-dom-browser-engine-core.min.js +1 -1
- package/dom/bin/jsview-dom-browser-engine-modules.min.js +1 -1
- package/dom/bin/{jsview-dom-browser-forge.1493.9a36.wasm → jsview-dom-browser-forge.1760.0e35.wasm} +0 -0
- package/dom/bin/jsview-dom-browser-forge.min.js +1 -1
- package/dom/bin/jsview-dom-browser-forge.worker.min.js +1 -1
- package/dom/bin/jsview-dom-browser.min.js +1 -1
- package/dom/bin/jsview-dom-native.min.js +1 -1
- package/dom/bin/jsview-engine-js-native.min.js +1 -1
- package/dom/target_core_revision.mjs +2 -2
- package/loader/jsv-core-api/jsview-core-api-glue.js +10 -1
- package/loader/jsv-core-api/wasm/core-api.js +87 -2
- package/loader/jsv-core-api/wasm/wasm-extension.js +5 -0
- package/loader/jsview-loader.js +7 -0
- package/loader/jsview-main.mjs +2 -1
- package/loader/jsview.config.default.js +4 -0
- package/package.json +7 -5
- package/patches/@vitejs+plugin-vue+4.0.0.patch +51 -0
- package/patches/@vitejs+plugin-vue+6.0.6.patch +54 -0
- package/patches/@vue+compiler-dom+3.2.45.patch +22 -0
- package/patches/@vue+compiler-dom+3.6.0-beta.10.patch +22 -0
- package/patches/@vue+compiler-sfc+3.2.45.patch +1986 -0
- package/patches/@vue+compiler-sfc+3.6.0-beta.10.patch +69 -0
- package/patches/@vue+runtime-core+3.2.45.patch +353 -0
- package/patches/@vue+runtime-core+3.6.0-beta.10.patch +198 -0
- package/patches/@vue+runtime-dom+3.2.45.patch +81 -0
- package/patches/@vue+runtime-dom+3.6.0-beta.10.patch +47 -0
- package/patches/postcss-js+5.1.0.patch +20 -0
- package/patches/vite+4.0.0.patch +117 -0
- package/patches/vite+8.0.9.patch +77 -0
- package/patches/vue-router+4.1.6.patch +17 -0
- package/patches/vue-router+5.0.6.patch +0 -0
- package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js → thirdparty/@vue/compiler-sfc/jsview-css-to-js.cjs} +15 -10
- package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-checker.js → thirdparty/@vue/compiler-sfc/jsview-style-checker.cjs} +6 -1
- package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-formator.cjs.js → thirdparty/@vue/compiler-sfc/jsview-style-formator.cjs} +3 -0
- package/thirdparty/@vue/runtime-core/jsview-render-break.mjs +201 -0
- package/thirdparty/vite/jsview-vite-extension.mjs +336 -0
- package/tools/jsview-build-zip.mjs +7 -2
- package/tools/jsview-common.mjs +17 -4
- package/tools/{jsview-logger.js → jsview-logger.cjs} +1 -1
- package/tools/jsview-post-build.mjs +55 -0
- package/tools/jsview-post-install.mjs +98 -110
- package/tools/jsview-run-tool.mjs +3 -6
- package/tools/jsview-vue-devtools.mjs +1 -1
- package/loader/jsview-react-main.js +0 -37
- package/loader/jsview-react-script-loader.js +0 -134
- package/patches/node_modules/@vitejs/plugin-react/dist/index.cjs +0 -520
- package/patches/node_modules/@vitejs/plugin-react/package.json +0 -55
- package/patches/node_modules/@vitejs/plugin-vue/dist/index.mjs +0 -2756
- package/patches/node_modules/@vitejs/plugin-vue/package.json +0 -51
- package/patches/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js +0 -3152
- package/patches/node_modules/@vue/compiler-dom/package.json +0 -43
- package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -17730
- package/patches/node_modules/@vue/compiler-sfc/package.json +0 -59
- package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +0 -8154
- package/patches/node_modules/@vue/runtime-core/package.json +0 -38
- package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.d.ts +0 -1531
- package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1740
- package/patches/node_modules/@vue/runtime-dom/package.json +0 -42
- package/patches/node_modules/postcss-js/objectifier.js +0 -94
- package/patches/node_modules/postcss-js/package.json +0 -42
- package/patches/node_modules/react-dev-utils/WebpackDevServerUtils.js +0 -450
- package/patches/node_modules/react-dev-utils/package.json +0 -88
- package/patches/node_modules/react-dom/cjs/react-dom.development.js +0 -29868
- package/patches/node_modules/react-dom/cjs/react-dom.production.min.js +0 -323
- package/patches/node_modules/react-dom/package.json +0 -62
- package/patches/node_modules/react-scripts/config/paths.js +0 -179
- package/patches/node_modules/react-scripts/config/webpack.config.js +0 -858
- package/patches/node_modules/react-scripts/package.json +0 -108
- package/patches/node_modules/vite/dist/node/chunks/dep-ed9cb113.js +0 -63182
- package/patches/node_modules/vite/dist/node/constants.js +0 -125
- package/patches/node_modules/vite/dist/node/jsview-vite-extension.js +0 -245
- package/patches/node_modules/vite/package.json +0 -153
- package/patches/node_modules/vue-router/dist/vue-router.mjs +0 -3613
- package/patches/node_modules/vue-router/package.json +0 -114
- package/patches/node_modules/webpack-dev-server/client/utils/reloadApp.js +0 -76
- package/patches/node_modules/webpack-dev-server/client/utils/sendMessage.js +0 -21
- package/patches/node_modules/webpack-dev-server/package.json +0 -141
- /package/patches/{node_modules/@originjs/vite-plugin-federation/1.3.4/@originjs+vite-plugin-federation+1.3.4.patch → @originjs+vite-plugin-federation+1.3.4.patch} +0 -0
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('node:path');
|
|
4
|
-
const babel = require('@babel/core');
|
|
5
|
-
const vite = require('vite');
|
|
6
|
-
const MagicString = require('magic-string');
|
|
7
|
-
const fs = require('node:fs');
|
|
8
|
-
const node_module = require('node:module');
|
|
9
|
-
|
|
10
|
-
function _interopNamespaceDefault(e) {
|
|
11
|
-
const n = Object.create(null);
|
|
12
|
-
if (e) {
|
|
13
|
-
for (const k in e) {
|
|
14
|
-
n[k] = e[k];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
n.default = e;
|
|
18
|
-
return n;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const babel__namespace = /*#__PURE__*/_interopNamespaceDefault(babel);
|
|
22
|
-
|
|
23
|
-
const runtimePublicPath = "/@react-refresh";
|
|
24
|
-
const _require = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
25
|
-
const reactRefreshDir = path.dirname(
|
|
26
|
-
_require.resolve("react-refresh/package.json")
|
|
27
|
-
);
|
|
28
|
-
const runtimeFilePath = path.join(
|
|
29
|
-
reactRefreshDir,
|
|
30
|
-
"cjs/react-refresh-runtime.development.js"
|
|
31
|
-
);
|
|
32
|
-
const runtimeCode = `
|
|
33
|
-
const exports = {}
|
|
34
|
-
${fs.readFileSync(runtimeFilePath, "utf-8")}
|
|
35
|
-
function debounce(fn, delay) {
|
|
36
|
-
let handle
|
|
37
|
-
return () => {
|
|
38
|
-
clearTimeout(handle)
|
|
39
|
-
handle = setTimeout(fn, delay)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.performReactRefresh = debounce(exports.performReactRefresh, 16)
|
|
43
|
-
export default exports
|
|
44
|
-
`;
|
|
45
|
-
const preambleCode = `
|
|
46
|
-
import RefreshRuntime from "__BASE__${runtimePublicPath.slice(1)}"
|
|
47
|
-
RefreshRuntime.injectIntoGlobalHook(window)
|
|
48
|
-
window.$RefreshReg$ = () => {}
|
|
49
|
-
window.$RefreshSig$ = () => (type) => type
|
|
50
|
-
window.__vite_plugin_react_preamble_installed__ = true
|
|
51
|
-
`;
|
|
52
|
-
const header = `
|
|
53
|
-
import RefreshRuntime from "${runtimePublicPath}";
|
|
54
|
-
|
|
55
|
-
let prevRefreshReg;
|
|
56
|
-
let prevRefreshSig;
|
|
57
|
-
|
|
58
|
-
if (import.meta.hot) {
|
|
59
|
-
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
"@vitejs/plugin-react can't detect preamble. Something is wrong. " +
|
|
62
|
-
"See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201"
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
prevRefreshReg = window.$RefreshReg$;
|
|
67
|
-
prevRefreshSig = window.$RefreshSig$;
|
|
68
|
-
window.$RefreshReg$ = (type, id) => {
|
|
69
|
-
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
70
|
-
};
|
|
71
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
72
|
-
}`.replace(/[\n]+/gm, "");
|
|
73
|
-
const timeout = `
|
|
74
|
-
if (!window.__vite_plugin_react_timeout) {
|
|
75
|
-
window.__vite_plugin_react_timeout = setTimeout(() => {
|
|
76
|
-
window.__vite_plugin_react_timeout = 0;
|
|
77
|
-
RefreshRuntime.performReactRefresh();
|
|
78
|
-
}, 30);
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
81
|
-
const footer = `
|
|
82
|
-
if (import.meta.hot) {
|
|
83
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
84
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
85
|
-
|
|
86
|
-
__ACCEPT__
|
|
87
|
-
}`;
|
|
88
|
-
const checkAndAccept = `
|
|
89
|
-
function isReactRefreshBoundary(mod) {
|
|
90
|
-
if (mod == null || typeof mod !== 'object') {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
let hasExports = false;
|
|
94
|
-
let areAllExportsComponents = true;
|
|
95
|
-
for (const exportName in mod) {
|
|
96
|
-
hasExports = true;
|
|
97
|
-
if (exportName === '__esModule') {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
const desc = Object.getOwnPropertyDescriptor(mod, exportName);
|
|
101
|
-
if (desc && desc.get) {
|
|
102
|
-
// Don't invoke getters as they may have side effects.
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
const exportValue = mod[exportName];
|
|
106
|
-
if (!RefreshRuntime.isLikelyComponentType(exportValue)) {
|
|
107
|
-
areAllExportsComponents = false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return hasExports && areAllExportsComponents;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
import.meta.hot.accept(mod => {
|
|
114
|
-
if (isReactRefreshBoundary(mod)) {
|
|
115
|
-
${timeout}
|
|
116
|
-
} else {
|
|
117
|
-
import.meta.hot.invalidate();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
`;
|
|
121
|
-
function addRefreshWrapper(code, id, accept) {
|
|
122
|
-
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer.replace("__ACCEPT__", accept ? checkAndAccept : timeout);
|
|
123
|
-
}
|
|
124
|
-
function isRefreshBoundary(ast) {
|
|
125
|
-
return ast.program.body.every((node) => {
|
|
126
|
-
if (node.type !== "ExportNamedDeclaration") {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
const { declaration, specifiers } = node;
|
|
130
|
-
if (declaration) {
|
|
131
|
-
if (declaration.type === "ClassDeclaration")
|
|
132
|
-
return false;
|
|
133
|
-
if (declaration.type === "VariableDeclaration") {
|
|
134
|
-
return declaration.declarations.every(
|
|
135
|
-
(variable) => isComponentLikeIdentifier(variable.id)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
if (declaration.type === "FunctionDeclaration") {
|
|
139
|
-
return !!declaration.id && isComponentLikeIdentifier(declaration.id);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return specifiers.every((spec) => {
|
|
143
|
-
return isComponentLikeIdentifier(spec.exported);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function isComponentLikeIdentifier(node) {
|
|
148
|
-
return node.type === "Identifier" && isComponentLikeName(node.name);
|
|
149
|
-
}
|
|
150
|
-
function isComponentLikeName(name) {
|
|
151
|
-
return typeof name === "string" && name[0] >= "A" && name[0] <= "Z";
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function babelImportToRequire({ types: t }) {
|
|
155
|
-
return {
|
|
156
|
-
visitor: {
|
|
157
|
-
ImportDeclaration(path) {
|
|
158
|
-
const decl = path.node;
|
|
159
|
-
const spec = decl.specifiers[0];
|
|
160
|
-
path.replaceWith(
|
|
161
|
-
t.variableDeclaration("var", [
|
|
162
|
-
t.variableDeclarator(
|
|
163
|
-
spec.local,
|
|
164
|
-
t.memberExpression(
|
|
165
|
-
t.callExpression(t.identifier("require"), [decl.source]),
|
|
166
|
-
spec.imported
|
|
167
|
-
)
|
|
168
|
-
)
|
|
169
|
-
])
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let babelRestoreJSX;
|
|
177
|
-
const jsxNotFound = [null, false];
|
|
178
|
-
async function getBabelRestoreJSX() {
|
|
179
|
-
if (!babelRestoreJSX)
|
|
180
|
-
babelRestoreJSX = import('./chunks/babel-restore-jsx.cjs').then((r) => {
|
|
181
|
-
const fn = r.default;
|
|
182
|
-
if ("default" in fn)
|
|
183
|
-
return fn.default;
|
|
184
|
-
return fn;
|
|
185
|
-
});
|
|
186
|
-
return babelRestoreJSX;
|
|
187
|
-
}
|
|
188
|
-
async function restoreJSX(babel, code, filename) {
|
|
189
|
-
const [reactAlias, isCommonJS] = parseReactAlias(code);
|
|
190
|
-
if (!reactAlias) {
|
|
191
|
-
return jsxNotFound;
|
|
192
|
-
}
|
|
193
|
-
const reactJsxRE = new RegExp(
|
|
194
|
-
`\\b${reactAlias}\\.(createElement|Fragment)\\b`,
|
|
195
|
-
"g"
|
|
196
|
-
);
|
|
197
|
-
if (!reactJsxRE.test(code)) {
|
|
198
|
-
return jsxNotFound;
|
|
199
|
-
}
|
|
200
|
-
const result = await babel.transformAsync(code, {
|
|
201
|
-
babelrc: false,
|
|
202
|
-
configFile: false,
|
|
203
|
-
ast: true,
|
|
204
|
-
code: false,
|
|
205
|
-
filename,
|
|
206
|
-
parserOpts: {
|
|
207
|
-
plugins: ["jsx"]
|
|
208
|
-
},
|
|
209
|
-
plugins: [[await getBabelRestoreJSX(), { reactAlias }]]
|
|
210
|
-
});
|
|
211
|
-
return [result?.ast, isCommonJS];
|
|
212
|
-
}
|
|
213
|
-
function parseReactAlias(code) {
|
|
214
|
-
let match = code.match(
|
|
215
|
-
/\b(var|let|const)\s+([^=\{\s]+)\s*=\s*require\(["']react["']\)/
|
|
216
|
-
);
|
|
217
|
-
if (match) {
|
|
218
|
-
return [match[2], true];
|
|
219
|
-
}
|
|
220
|
-
match = code.match(/^import\s+(?:\*\s+as\s+)?(\w+).+?\bfrom\s*["']react["']/m);
|
|
221
|
-
if (match) {
|
|
222
|
-
return [match[1], false];
|
|
223
|
-
}
|
|
224
|
-
return [void 0, false];
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const prependReactImportCode = "import React from 'react'; ";
|
|
228
|
-
function viteReact(opts = {}) {
|
|
229
|
-
let devBase = "/";
|
|
230
|
-
let resolvedCacheDir;
|
|
231
|
-
let filter = vite.createFilter(opts.include, opts.exclude);
|
|
232
|
-
let needHiresSourcemap = false;
|
|
233
|
-
let isProduction = true;
|
|
234
|
-
let projectRoot = process.cwd();
|
|
235
|
-
// JsView Modified >>>
|
|
236
|
-
// 防止react注入module到html
|
|
237
|
-
// let skipFastRefresh = opts.fastRefresh === false;
|
|
238
|
-
let skipFastRefresh = true;
|
|
239
|
-
// JsView Modified <<<
|
|
240
|
-
let skipReactImport = false;
|
|
241
|
-
let runPluginOverrides = (options, context) => false;
|
|
242
|
-
let staticBabelOptions;
|
|
243
|
-
const useAutomaticRuntime = opts.jsxRuntime !== "classic";
|
|
244
|
-
const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
|
|
245
|
-
const fileExtensionRE = /\.[^\/\s\?]+$/;
|
|
246
|
-
const viteBabel = {
|
|
247
|
-
name: "vite:react-babel",
|
|
248
|
-
enforce: "pre",
|
|
249
|
-
config() {
|
|
250
|
-
if (opts.jsxRuntime === "classic") {
|
|
251
|
-
return {
|
|
252
|
-
esbuild: {
|
|
253
|
-
logOverride: {
|
|
254
|
-
"this-is-undefined-in-esm": "silent"
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
configResolved(config) {
|
|
261
|
-
devBase = config.base;
|
|
262
|
-
projectRoot = config.root;
|
|
263
|
-
resolvedCacheDir = vite.normalizePath(path.resolve(config.cacheDir));
|
|
264
|
-
filter = vite.createFilter(opts.include, opts.exclude, {
|
|
265
|
-
resolve: projectRoot
|
|
266
|
-
});
|
|
267
|
-
needHiresSourcemap = config.command === "build" && !!config.build.sourcemap;
|
|
268
|
-
isProduction = config.isProduction;
|
|
269
|
-
skipFastRefresh || (skipFastRefresh = isProduction || config.command === "build");
|
|
270
|
-
const jsxInject = config.esbuild && config.esbuild.jsxInject;
|
|
271
|
-
if (jsxInject && importReactRE.test(jsxInject)) {
|
|
272
|
-
skipReactImport = true;
|
|
273
|
-
config.logger.warn(
|
|
274
|
-
"[@vitejs/plugin-react] This plugin imports React for you automatically, so you can stop using `esbuild.jsxInject` for that purpose."
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
config.plugins.forEach((plugin) => {
|
|
278
|
-
const hasConflict = plugin.name === "react-refresh" || plugin !== viteReactJsx && plugin.name === "vite:react-jsx";
|
|
279
|
-
if (hasConflict)
|
|
280
|
-
return config.logger.warn(
|
|
281
|
-
`[@vitejs/plugin-react] You should stop using "${plugin.name}" since this plugin conflicts with it.`
|
|
282
|
-
);
|
|
283
|
-
});
|
|
284
|
-
runPluginOverrides = (babelOptions, context) => {
|
|
285
|
-
const hooks = config.plugins.map((plugin) => plugin.api?.reactBabel).filter(Boolean);
|
|
286
|
-
if (hooks.length > 0) {
|
|
287
|
-
return (runPluginOverrides = (babelOptions2, context2) => {
|
|
288
|
-
hooks.forEach((hook) => hook(babelOptions2, context2, config));
|
|
289
|
-
return true;
|
|
290
|
-
})(babelOptions, context);
|
|
291
|
-
}
|
|
292
|
-
runPluginOverrides = () => false;
|
|
293
|
-
return false;
|
|
294
|
-
};
|
|
295
|
-
},
|
|
296
|
-
async transform(code, id, options) {
|
|
297
|
-
const ssr = options?.ssr === true;
|
|
298
|
-
const [filepath, querystring = ""] = id.split("?");
|
|
299
|
-
const [extension = ""] = querystring.match(fileExtensionRE) || filepath.match(fileExtensionRE) || [];
|
|
300
|
-
if (/\.(mjs|[tj]sx?)$/.test(extension)) {
|
|
301
|
-
const isJSX = extension.endsWith("x");
|
|
302
|
-
const isNodeModules = id.includes("/node_modules/");
|
|
303
|
-
const isProjectFile = !isNodeModules && (id[0] === "\0" || id.startsWith(projectRoot + "/"));
|
|
304
|
-
let babelOptions = staticBabelOptions;
|
|
305
|
-
if (typeof opts.babel === "function") {
|
|
306
|
-
const rawOptions = opts.babel(id, { ssr });
|
|
307
|
-
babelOptions = createBabelOptions(rawOptions);
|
|
308
|
-
runPluginOverrides(babelOptions, { ssr, id });
|
|
309
|
-
} else if (!babelOptions) {
|
|
310
|
-
babelOptions = createBabelOptions(opts.babel);
|
|
311
|
-
if (!runPluginOverrides(babelOptions, { ssr, id })) {
|
|
312
|
-
staticBabelOptions = babelOptions;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
const plugins = isProjectFile ? [...babelOptions.plugins] : [];
|
|
316
|
-
let useFastRefresh = false;
|
|
317
|
-
if (!skipFastRefresh && !ssr && !isNodeModules) {
|
|
318
|
-
const isReactModule = isJSX || importReactRE.test(code);
|
|
319
|
-
if (isReactModule && filter(id)) {
|
|
320
|
-
useFastRefresh = true;
|
|
321
|
-
plugins.push([
|
|
322
|
-
await loadPlugin("react-refresh/babel"),
|
|
323
|
-
{ skipEnvCheck: true }
|
|
324
|
-
]);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
let ast;
|
|
328
|
-
let prependReactImport = false;
|
|
329
|
-
if (!isProjectFile || isJSX) {
|
|
330
|
-
if (useAutomaticRuntime) {
|
|
331
|
-
const isOptimizedReactDom = id.startsWith(resolvedCacheDir) && id.includes("/react-dom.js");
|
|
332
|
-
const [restoredAst, isCommonJS] = !isProjectFile && !isJSX && !isOptimizedReactDom ? await restoreJSX(babel__namespace, code, id) : [null, false];
|
|
333
|
-
if (isJSX || (ast = restoredAst)) {
|
|
334
|
-
plugins.push([
|
|
335
|
-
await loadPlugin(
|
|
336
|
-
"@babel/plugin-transform-react-jsx" + (isProduction ? "" : "-development")
|
|
337
|
-
),
|
|
338
|
-
{
|
|
339
|
-
runtime: "automatic",
|
|
340
|
-
importSource: opts.jsxImportSource,
|
|
341
|
-
pure: opts.jsxPure !== false,
|
|
342
|
-
throwIfNamespace: opts.jsxThrowIfNamespace
|
|
343
|
-
}
|
|
344
|
-
]);
|
|
345
|
-
if (isCommonJS) {
|
|
346
|
-
plugins.push(babelImportToRequire);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
} else if (isProjectFile) {
|
|
350
|
-
if (!isProduction) {
|
|
351
|
-
plugins.push(
|
|
352
|
-
await loadPlugin("@babel/plugin-transform-react-jsx-self"),
|
|
353
|
-
await loadPlugin("@babel/plugin-transform-react-jsx-source")
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
if (!skipReactImport && !importReactRE.test(code)) {
|
|
357
|
-
prependReactImport = true;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
let inputMap;
|
|
362
|
-
if (prependReactImport) {
|
|
363
|
-
if (needHiresSourcemap) {
|
|
364
|
-
const s = new MagicString(code);
|
|
365
|
-
s.prepend(prependReactImportCode);
|
|
366
|
-
code = s.toString();
|
|
367
|
-
inputMap = s.generateMap({ hires: true, source: id });
|
|
368
|
-
} else {
|
|
369
|
-
code = prependReactImportCode + code;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
const shouldSkip = !plugins.length && !babelOptions.configFile && !(isProjectFile && babelOptions.babelrc);
|
|
373
|
-
if (shouldSkip) {
|
|
374
|
-
return {
|
|
375
|
-
code,
|
|
376
|
-
map: inputMap ?? null
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
const parserPlugins = [
|
|
380
|
-
...babelOptions.parserOpts.plugins,
|
|
381
|
-
"importMeta",
|
|
382
|
-
"topLevelAwait",
|
|
383
|
-
"classProperties",
|
|
384
|
-
"classPrivateProperties",
|
|
385
|
-
"classPrivateMethods"
|
|
386
|
-
];
|
|
387
|
-
if (!extension.endsWith(".ts")) {
|
|
388
|
-
parserPlugins.push("jsx");
|
|
389
|
-
}
|
|
390
|
-
if (/\.tsx?$/.test(extension)) {
|
|
391
|
-
parserPlugins.push("typescript");
|
|
392
|
-
}
|
|
393
|
-
const transformAsync = ast ? babel__namespace.transformFromAstAsync.bind(babel__namespace, ast, code) : babel__namespace.transformAsync.bind(babel__namespace, code);
|
|
394
|
-
const isReasonReact = extension.endsWith(".bs.js");
|
|
395
|
-
const result = await transformAsync({
|
|
396
|
-
...babelOptions,
|
|
397
|
-
ast: !isReasonReact,
|
|
398
|
-
root: projectRoot,
|
|
399
|
-
filename: id,
|
|
400
|
-
sourceFileName: filepath,
|
|
401
|
-
parserOpts: {
|
|
402
|
-
...babelOptions.parserOpts,
|
|
403
|
-
sourceType: "module",
|
|
404
|
-
allowAwaitOutsideFunction: true,
|
|
405
|
-
plugins: parserPlugins
|
|
406
|
-
},
|
|
407
|
-
generatorOpts: {
|
|
408
|
-
...babelOptions.generatorOpts,
|
|
409
|
-
decoratorsBeforeExport: true
|
|
410
|
-
},
|
|
411
|
-
plugins,
|
|
412
|
-
sourceMaps: true,
|
|
413
|
-
inputSourceMap: inputMap ?? false
|
|
414
|
-
});
|
|
415
|
-
if (result) {
|
|
416
|
-
let code2 = result.code;
|
|
417
|
-
if (useFastRefresh && /\$RefreshReg\$\(/.test(code2)) {
|
|
418
|
-
const accept = isReasonReact || isRefreshBoundary(result.ast);
|
|
419
|
-
code2 = addRefreshWrapper(code2, id, accept);
|
|
420
|
-
}
|
|
421
|
-
return {
|
|
422
|
-
code: code2,
|
|
423
|
-
map: result.map
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
const viteReactRefresh = {
|
|
430
|
-
name: "vite:react-refresh",
|
|
431
|
-
enforce: "pre",
|
|
432
|
-
config: () => ({
|
|
433
|
-
resolve: {
|
|
434
|
-
dedupe: ["react", "react-dom"]
|
|
435
|
-
}
|
|
436
|
-
}),
|
|
437
|
-
resolveId(id) {
|
|
438
|
-
if (id === runtimePublicPath) {
|
|
439
|
-
return id;
|
|
440
|
-
}
|
|
441
|
-
},
|
|
442
|
-
load(id) {
|
|
443
|
-
if (id === runtimePublicPath) {
|
|
444
|
-
return runtimeCode;
|
|
445
|
-
}
|
|
446
|
-
},
|
|
447
|
-
transformIndexHtml() {
|
|
448
|
-
if (!skipFastRefresh)
|
|
449
|
-
return [
|
|
450
|
-
{
|
|
451
|
-
tag: "script",
|
|
452
|
-
attrs: { type: "module" },
|
|
453
|
-
children: preambleCode.replace(`__BASE__`, devBase)
|
|
454
|
-
}
|
|
455
|
-
];
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
const reactJsxRuntimeId = "react/jsx-runtime";
|
|
459
|
-
const reactJsxDevRuntimeId = "react/jsx-dev-runtime";
|
|
460
|
-
const virtualReactJsxRuntimeId = "\0" + reactJsxRuntimeId;
|
|
461
|
-
const virtualReactJsxDevRuntimeId = "\0" + reactJsxDevRuntimeId;
|
|
462
|
-
const viteReactJsx = {
|
|
463
|
-
name: "vite:react-jsx",
|
|
464
|
-
enforce: "pre",
|
|
465
|
-
config() {
|
|
466
|
-
return {
|
|
467
|
-
optimizeDeps: {
|
|
468
|
-
include: [reactJsxRuntimeId, reactJsxDevRuntimeId, "react"]
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
},
|
|
472
|
-
resolveId(id, importer) {
|
|
473
|
-
if (id === reactJsxRuntimeId && importer !== virtualReactJsxRuntimeId) {
|
|
474
|
-
return virtualReactJsxRuntimeId;
|
|
475
|
-
}
|
|
476
|
-
if (id === reactJsxDevRuntimeId && importer !== virtualReactJsxDevRuntimeId) {
|
|
477
|
-
return virtualReactJsxDevRuntimeId;
|
|
478
|
-
}
|
|
479
|
-
},
|
|
480
|
-
load(id) {
|
|
481
|
-
if (id === virtualReactJsxRuntimeId) {
|
|
482
|
-
return [
|
|
483
|
-
`import * as jsxRuntime from ${JSON.stringify(reactJsxRuntimeId)}`,
|
|
484
|
-
`export const Fragment = jsxRuntime.Fragment`,
|
|
485
|
-
`export const jsx = jsxRuntime.jsx`,
|
|
486
|
-
`export const jsxs = jsxRuntime.jsxs`
|
|
487
|
-
].join("\n");
|
|
488
|
-
}
|
|
489
|
-
if (id === virtualReactJsxDevRuntimeId) {
|
|
490
|
-
return [
|
|
491
|
-
`import * as jsxRuntime from ${JSON.stringify(reactJsxDevRuntimeId)}`,
|
|
492
|
-
`export const Fragment = jsxRuntime.Fragment`,
|
|
493
|
-
`export const jsxDEV = jsxRuntime.jsxDEV`
|
|
494
|
-
].join("\n");
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
return [viteBabel, viteReactRefresh, useAutomaticRuntime && viteReactJsx];
|
|
499
|
-
}
|
|
500
|
-
viteReact.preambleCode = preambleCode;
|
|
501
|
-
function loadPlugin(path2) {
|
|
502
|
-
return import(path2).then((module) => module.default || module);
|
|
503
|
-
}
|
|
504
|
-
function createBabelOptions(rawOptions) {
|
|
505
|
-
var _a;
|
|
506
|
-
const babelOptions = {
|
|
507
|
-
babelrc: false,
|
|
508
|
-
configFile: false,
|
|
509
|
-
...rawOptions
|
|
510
|
-
};
|
|
511
|
-
babelOptions.plugins || (babelOptions.plugins = []);
|
|
512
|
-
babelOptions.presets || (babelOptions.presets = []);
|
|
513
|
-
babelOptions.overrides || (babelOptions.overrides = []);
|
|
514
|
-
babelOptions.parserOpts || (babelOptions.parserOpts = {});
|
|
515
|
-
(_a = babelOptions.parserOpts).plugins || (_a.plugins = []);
|
|
516
|
-
return babelOptions;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
module.exports = viteReact;
|
|
520
|
-
module.exports.default = viteReact;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vitejs/plugin-react",
|
|
3
|
-
"version": "2.2.0",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"author": "Evan You",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Alec Larson"
|
|
8
|
-
],
|
|
9
|
-
"files": [
|
|
10
|
-
"dist"
|
|
11
|
-
],
|
|
12
|
-
"main": "./dist/index.cjs",
|
|
13
|
-
"module": "./dist/index.mjs",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"import": "./dist/index.mjs",
|
|
19
|
-
"require": "./dist/index.cjs"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"dev": "unbuild --stub",
|
|
24
|
-
"build": "unbuild && pnpm run patch-cjs",
|
|
25
|
-
"patch-cjs": "tsx ../../scripts/patchCJS.ts",
|
|
26
|
-
"prepublishOnly": "npm run build"
|
|
27
|
-
},
|
|
28
|
-
"engines": {
|
|
29
|
-
"node": "^14.18.0 || >=16.0.0"
|
|
30
|
-
},
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/vitejs/vite.git",
|
|
34
|
-
"directory": "packages/plugin-react"
|
|
35
|
-
},
|
|
36
|
-
"bugs": {
|
|
37
|
-
"url": "https://github.com/vitejs/vite/issues"
|
|
38
|
-
},
|
|
39
|
-
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react#readme",
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@babel/core": "^7.19.6",
|
|
42
|
-
"@babel/plugin-transform-react-jsx": "^7.19.0",
|
|
43
|
-
"@babel/plugin-transform-react-jsx-development": "^7.18.6",
|
|
44
|
-
"@babel/plugin-transform-react-jsx-self": "^7.18.6",
|
|
45
|
-
"@babel/plugin-transform-react-jsx-source": "^7.19.6",
|
|
46
|
-
"magic-string": "^0.26.7",
|
|
47
|
-
"react-refresh": "^0.14.0"
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"vite": "^3.0.0"
|
|
51
|
-
},
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"vite": "workspace:*"
|
|
54
|
-
}
|
|
55
|
-
}
|