@shopify/ui-extensions-server-kit 5.3.1 → 5.4.1
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/CHANGELOG.md +12 -0
- package/README.md +3 -2
- package/dist/ExtensionServerClient/ExtensionServerClient.d.ts +3 -5
- package/dist/ExtensionServerClient/server-types.d.ts +31 -7
- package/dist/_virtual/jsx-runtime.cjs.js +1 -0
- package/dist/_virtual/jsx-runtime.cjs2.js +1 -0
- package/dist/_virtual/jsx-runtime.es.js +5 -0
- package/dist/_virtual/jsx-runtime.es2.js +4 -0
- package/dist/_virtual/react-jsx-runtime.development.cjs.js +1 -0
- package/dist/_virtual/react-jsx-runtime.development.es.js +4 -0
- package/dist/_virtual/react-jsx-runtime.production.min.cjs.js +1 -0
- package/dist/_virtual/react-jsx-runtime.production.min.es.js +4 -0
- package/dist/context/ExtensionServerProvider.d.ts +2 -1
- package/dist/i18n.d.ts +2 -8
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.es.js +18 -18
- package/dist/index.es2.js +3 -3
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.cjs.js +22 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.es.js +604 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.cjs.js +9 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.es.js +28 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.cjs.js +1 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.es.js +10 -0
- package/dist/packages/ui-extensions-server-kit/src/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -0
- package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/ExtensionServerClient.es.js +21 -18
- package/dist/packages/ui-extensions-server-kit/src/context/ExtensionServerProvider.cjs.js +1 -0
- package/dist/packages/ui-extensions-server-kit/src/context/ExtensionServerProvider.es.js +30 -0
- package/dist/{context → packages/ui-extensions-server-kit/src/context}/constants.cjs.js +1 -1
- package/dist/packages/ui-extensions-server-kit/src/hooks/useExtensionServerContext.cjs.js +1 -0
- package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerContext.es.js +3 -2
- package/dist/packages/ui-extensions-server-kit/src/testing/MockExtensionServerProvider.cjs.js +1 -0
- package/dist/packages/ui-extensions-server-kit/src/testing/MockExtensionServerProvider.es.js +25 -0
- package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/extensions.cjs.js +1 -1
- package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/extensions.es.js +3 -2
- package/dist/packages/ui-extensions-server-kit/src/utilities/isUIExtension.cjs.js +1 -0
- package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/isUIExtension.es.js +3 -2
- package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/isValidSurface.cjs.js +1 -1
- package/dist/packages/ui-extensions-server-kit/src/utilities/isValidSurface.es.js +7 -0
- package/dist/testing/MockExtensionServerProvider.d.ts +2 -1
- package/dist/types.d.ts +14 -7
- package/dist/utilities/isUIExtension.d.ts +1 -1
- package/dist/utilities/isValidSurface.d.ts +1 -1
- package/dist/utilities/set.d.ts +1 -1
- package/node_modules/{@shopify/react-testing/LICENSE.md → @testing-library/react/LICENSE} +2 -3
- package/node_modules/@testing-library/react/README.md +692 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.cjs.js +537 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.esm.js +497 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.cjs.js +501 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.esm.js +461 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.js +502 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.min.js +2 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.min.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.js +538 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.min.js +2 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.min.js.map +1 -0
- package/node_modules/@testing-library/react/dist/act-compat.js +80 -0
- package/node_modules/@testing-library/react/dist/config.js +33 -0
- package/node_modules/@testing-library/react/dist/fire-event.js +70 -0
- package/node_modules/@testing-library/react/dist/index.js +52 -0
- package/node_modules/@testing-library/react/dist/pure.js +356 -0
- package/node_modules/@testing-library/react/dont-cleanup-after-each.js +1 -0
- package/node_modules/@testing-library/react/package.json +116 -0
- package/node_modules/@testing-library/react/pure.d.ts +1 -0
- package/node_modules/@testing-library/react/pure.js +2 -0
- package/node_modules/@testing-library/react/types/index.d.ts +287 -0
- package/node_modules/@testing-library/react/types/pure.d.ts +1 -0
- package/node_modules/@types/react/README.md +4 -5
- package/node_modules/@types/react/canary.d.ts +166 -0
- package/node_modules/@types/react/experimental.d.ts +21 -86
- package/node_modules/@types/react/global.d.ts +146 -137
- package/node_modules/@types/react/index.d.ts +2738 -1370
- package/node_modules/@types/react/jsx-dev-runtime.d.ts +45 -2
- package/node_modules/@types/react/jsx-runtime.d.ts +36 -2
- package/node_modules/@types/react/package.json +111 -54
- package/node_modules/@types/react/ts5.0/canary.d.ts +166 -0
- package/node_modules/@types/react/ts5.0/experimental.d.ts +127 -0
- package/node_modules/@types/react/ts5.0/global.d.ts +160 -0
- package/node_modules/@types/react/ts5.0/index.d.ts +4530 -0
- package/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +44 -0
- package/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +35 -0
- package/node_modules/@vitejs/plugin-react/README.md +159 -0
- package/node_modules/@vitejs/plugin-react/dist/index.d.ts +75 -0
- package/node_modules/@vitejs/plugin-react/dist/index.js +401 -0
- package/node_modules/@vitejs/plugin-react/dist/refresh-runtime.js +663 -0
- package/node_modules/@vitejs/plugin-react/package.json +77 -0
- package/node_modules/@vitejs/plugin-react/types/preamble.d.ts +1 -0
- package/package.json +9 -10
- package/project.json +1 -1
- package/src/ExtensionServerClient/ExtensionServerClient.test.ts +6 -5
- package/src/ExtensionServerClient/ExtensionServerClient.ts +27 -19
- package/src/ExtensionServerClient/server-types.ts +17 -7
- package/src/ExtensionServerClient/types.ts +0 -2
- package/src/context/ExtensionServerProvider.test.tsx +55 -73
- package/src/context/ExtensionServerProvider.tsx +1 -0
- package/src/i18n.ts +2 -5
- package/src/state/reducers/extensionServerReducer.test.ts +2 -2
- package/src/testing/extensions.ts +1 -0
- package/src/types.ts +15 -5
- package/src/utilities/assetToString.ts +0 -1
- package/src/utilities/isUIExtension.ts +5 -4
- package/src/utilities/isValidSurface.ts +2 -3
- package/src/utilities/replaceUpdated.ts +0 -2
- package/src/utilities/set.ts +10 -5
- package/tests/setup.ts +1 -4
- package/vite.config.mts +57 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +0 -1
- package/dist/context/ExtensionServerProvider.cjs.js +0 -1
- package/dist/context/ExtensionServerProvider.es.js +0 -29
- package/dist/hooks/useExtensionServerContext.cjs.js +0 -1
- package/dist/testing/MockExtensionServerProvider.cjs.js +0 -1
- package/dist/testing/MockExtensionServerProvider.es.js +0 -24
- package/dist/utilities/isUIExtension.cjs.js +0 -1
- package/dist/utilities/isValidSurface.es.js +0 -7
- package/node_modules/@shopify/react-testing/README.md +0 -711
- package/node_modules/@shopify/react-testing/build/cjs/TestWrapper.js +0 -52
- package/node_modules/@shopify/react-testing/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -47
- package/node_modules/@shopify/react-testing/build/cjs/compat.js +0 -14
- package/node_modules/@shopify/react-testing/build/cjs/destroy.js +0 -13
- package/node_modules/@shopify/react-testing/build/cjs/element.js +0 -225
- package/node_modules/@shopify/react-testing/build/cjs/index.js +0 -21
- package/node_modules/@shopify/react-testing/build/cjs/matchers/components.js +0 -46
- package/node_modules/@shopify/react-testing/build/cjs/matchers/context.js +0 -25
- package/node_modules/@shopify/react-testing/build/cjs/matchers/index.js +0 -16
- package/node_modules/@shopify/react-testing/build/cjs/matchers/props.js +0 -38
- package/node_modules/@shopify/react-testing/build/cjs/matchers/strings.js +0 -42
- package/node_modules/@shopify/react-testing/build/cjs/matchers/utilities.js +0 -110
- package/node_modules/@shopify/react-testing/build/cjs/mount.js +0 -76
- package/node_modules/@shopify/react-testing/build/cjs/root.js +0 -284
- package/node_modules/@shopify/react-testing/build/cjs/toReactString.js +0 -86
- package/node_modules/@shopify/react-testing/build/cjs/types.js +0 -28
- package/node_modules/@shopify/react-testing/build/esm/TestWrapper.mjs +0 -44
- package/node_modules/@shopify/react-testing/build/esm/_virtual/_rollupPluginBabelHelpers.mjs +0 -42
- package/node_modules/@shopify/react-testing/build/esm/compat.mjs +0 -10
- package/node_modules/@shopify/react-testing/build/esm/destroy.mjs +0 -9
- package/node_modules/@shopify/react-testing/build/esm/element.mjs +0 -221
- package/node_modules/@shopify/react-testing/build/esm/index.mjs +0 -5
- package/node_modules/@shopify/react-testing/build/esm/matchers/components.mjs +0 -41
- package/node_modules/@shopify/react-testing/build/esm/matchers/context.mjs +0 -21
- package/node_modules/@shopify/react-testing/build/esm/matchers/index.mjs +0 -14
- package/node_modules/@shopify/react-testing/build/esm/matchers/props.mjs +0 -33
- package/node_modules/@shopify/react-testing/build/esm/matchers/strings.mjs +0 -37
- package/node_modules/@shopify/react-testing/build/esm/matchers/utilities.mjs +0 -101
- package/node_modules/@shopify/react-testing/build/esm/mount.mjs +0 -70
- package/node_modules/@shopify/react-testing/build/esm/root.mjs +0 -275
- package/node_modules/@shopify/react-testing/build/esm/toReactString.mjs +0 -80
- package/node_modules/@shopify/react-testing/build/esm/types.mjs +0 -26
- package/node_modules/@shopify/react-testing/build/esnext/TestWrapper.esnext +0 -44
- package/node_modules/@shopify/react-testing/build/esnext/compat.esnext +0 -10
- package/node_modules/@shopify/react-testing/build/esnext/destroy.esnext +0 -9
- package/node_modules/@shopify/react-testing/build/esnext/element.esnext +0 -221
- package/node_modules/@shopify/react-testing/build/esnext/index.esnext +0 -5
- package/node_modules/@shopify/react-testing/build/esnext/matchers/components.esnext +0 -41
- package/node_modules/@shopify/react-testing/build/esnext/matchers/context.esnext +0 -21
- package/node_modules/@shopify/react-testing/build/esnext/matchers/index.esnext +0 -14
- package/node_modules/@shopify/react-testing/build/esnext/matchers/props.esnext +0 -33
- package/node_modules/@shopify/react-testing/build/esnext/matchers/strings.esnext +0 -37
- package/node_modules/@shopify/react-testing/build/esnext/matchers/utilities.esnext +0 -99
- package/node_modules/@shopify/react-testing/build/esnext/mount.esnext +0 -71
- package/node_modules/@shopify/react-testing/build/esnext/root.esnext +0 -275
- package/node_modules/@shopify/react-testing/build/esnext/toReactString.esnext +0 -80
- package/node_modules/@shopify/react-testing/build/esnext/types.esnext +0 -26
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts +0 -17
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts +0 -3
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts +0 -2
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts +0 -42
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts +0 -7
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts +0 -12
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts +0 -8
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts +0 -20
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts +0 -10
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts +0 -11
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts +0 -17
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts +0 -39
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts +0 -55
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts +0 -5
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts +0 -89
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/index.esnext +0 -1
- package/node_modules/@shopify/react-testing/index.js +0 -1
- package/node_modules/@shopify/react-testing/index.mjs +0 -1
- package/node_modules/@shopify/react-testing/matchers.esnext +0 -1
- package/node_modules/@shopify/react-testing/matchers.js +0 -1
- package/node_modules/@shopify/react-testing/matchers.mjs +0 -1
- package/node_modules/@shopify/react-testing/package.json +0 -69
- package/node_modules/@shopify/ui-extensions-test-utils/CHANGELOG.md +0 -66
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.d.ts +0 -3
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.js +0 -3
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.d.ts +0 -2
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.js +0 -5
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.d.ts +0 -17
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.js +0 -20
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.d.ts +0 -9
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +0 -7
- package/node_modules/@shopify/ui-extensions-test-utils/package.json +0 -40
- package/node_modules/@shopify/ui-extensions-test-utils/project.json +0 -39
- package/node_modules/@vitejs/plugin-react-refresh/README.md +0 -73
- package/node_modules/@vitejs/plugin-react-refresh/index.d.ts +0 -14
- package/node_modules/@vitejs/plugin-react-refresh/index.js +0 -239
- package/node_modules/@vitejs/plugin-react-refresh/package.json +0 -35
- /package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/types.cjs.js +0 -0
- /package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/types.es.js +0 -0
- /package/dist/{context → packages/ui-extensions-server-kit/src/context}/constants.es.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerState.cjs.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerState.es.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useIsomorphicLayoutEffect.cjs.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useIsomorphicLayoutEffect.es.js +0 -0
- /package/dist/{i18n.cjs.js → packages/ui-extensions-server-kit/src/i18n.cjs.js} +0 -0
- /package/dist/{i18n.es.js → packages/ui-extensions-server-kit/src/i18n.es.js} +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/actions/actions.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/actions/actions.es.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/constants.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/constants.es.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/extensionServerReducer.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/extensionServerReducer.es.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/app.cjs.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/app.es.js +0 -0
- /package/dist/{types.cjs.js → packages/ui-extensions-server-kit/src/types.cjs.js} +0 -0
- /package/dist/{types.es.js → packages/ui-extensions-server-kit/src/types.es.js} +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/assetToString.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/assetToString.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/noop.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/noop.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/replaceUpdated.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/replaceUpdated.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/set.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/set.es.js +0 -0
- /package/node_modules/@vitejs/{plugin-react-refresh → plugin-react}/LICENSE +0 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { exactRegex, makeIdFiltersToMatchWithQuery } from "@rolldown/pluginutils";
|
|
5
|
+
import * as vite from "vite";
|
|
6
|
+
import { createFilter } from "vite";
|
|
7
|
+
|
|
8
|
+
//#region ../common/refresh-utils.ts
|
|
9
|
+
const runtimePublicPath = "/@react-refresh";
|
|
10
|
+
const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
|
11
|
+
const refreshContentRE = /\$RefreshReg\$\(/;
|
|
12
|
+
const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
|
|
13
|
+
injectIntoGlobalHook(window);
|
|
14
|
+
window.$RefreshReg$ = () => {};
|
|
15
|
+
window.$RefreshSig$ = () => (type) => type;`;
|
|
16
|
+
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
|
17
|
+
function addRefreshWrapper(code, pluginName, id, reactRefreshHost = "") {
|
|
18
|
+
const hasRefresh = refreshContentRE.test(code);
|
|
19
|
+
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
|
20
|
+
if (!hasRefresh && !onlyReactComp) return void 0;
|
|
21
|
+
let newCode = code;
|
|
22
|
+
newCode += `
|
|
23
|
+
|
|
24
|
+
import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
|
25
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
26
|
+
if (import.meta.hot && !inWebWorker) {
|
|
27
|
+
if (!window.$RefreshReg$) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"${pluginName} can't detect preamble. Something is wrong."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
34
|
+
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
|
35
|
+
import.meta.hot.accept((nextExports) => {
|
|
36
|
+
if (!nextExports) return;
|
|
37
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
|
|
38
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
if (hasRefresh) newCode += `function $RefreshReg$(type, id) { return RefreshRuntime.register(type, ${JSON.stringify(id)} + ' ' + id) }
|
|
44
|
+
function $RefreshSig$() { return RefreshRuntime.createSignatureFunctionForTransform(); }
|
|
45
|
+
`;
|
|
46
|
+
return newCode;
|
|
47
|
+
}
|
|
48
|
+
function virtualPreamblePlugin({ name, isEnabled }) {
|
|
49
|
+
return {
|
|
50
|
+
name: "vite:react-virtual-preamble",
|
|
51
|
+
resolveId: {
|
|
52
|
+
order: "pre",
|
|
53
|
+
filter: { id: exactRegex(name) },
|
|
54
|
+
handler(source) {
|
|
55
|
+
if (source === name) return "\0" + source;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
load: {
|
|
59
|
+
filter: { id: exactRegex("\0" + name) },
|
|
60
|
+
handler(id) {
|
|
61
|
+
if (id === "\0" + name) {
|
|
62
|
+
if (isEnabled()) return preambleCode.replace("__BASE__", "/");
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../common/warning.ts
|
|
72
|
+
const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
|
|
73
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
|
|
74
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
|
|
75
|
+
if (userConfig.build?.rollupOptions?.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
76
|
+
else defaultHandler(warning);
|
|
77
|
+
} } });
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/index.ts
|
|
81
|
+
const refreshRuntimePath = join(dirname(fileURLToPath(import.meta.url)), "refresh-runtime.js");
|
|
82
|
+
let babel;
|
|
83
|
+
async function loadBabel() {
|
|
84
|
+
if (!babel) babel = await import("@babel/core");
|
|
85
|
+
return babel;
|
|
86
|
+
}
|
|
87
|
+
const defaultIncludeRE = /\.[tj]sx?$/;
|
|
88
|
+
const defaultExcludeRE = /\/node_modules\//;
|
|
89
|
+
const tsRE = /\.tsx?$/;
|
|
90
|
+
const compilerAnnotationRE = /['"]use memo['"]/;
|
|
91
|
+
function viteReact(opts = {}) {
|
|
92
|
+
const include = opts.include ?? defaultIncludeRE;
|
|
93
|
+
const exclude = opts.exclude ?? defaultExcludeRE;
|
|
94
|
+
const filter = createFilter(include, exclude);
|
|
95
|
+
const jsxImportSource = opts.jsxImportSource ?? "react";
|
|
96
|
+
const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
|
|
97
|
+
const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
|
|
98
|
+
const isRolldownVite = "rolldownVersion" in vite;
|
|
99
|
+
let runningInVite = false;
|
|
100
|
+
let isProduction = true;
|
|
101
|
+
let projectRoot = process.cwd();
|
|
102
|
+
let skipFastRefresh = true;
|
|
103
|
+
let base;
|
|
104
|
+
let isBundledDev = false;
|
|
105
|
+
let runPluginOverrides;
|
|
106
|
+
let staticBabelOptions;
|
|
107
|
+
const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
|
|
108
|
+
const viteBabel = {
|
|
109
|
+
name: "vite:react-babel",
|
|
110
|
+
enforce: "pre",
|
|
111
|
+
config(_userConfig, { command }) {
|
|
112
|
+
if ("rolldownVersion" in vite) if (opts.jsxRuntime === "classic") return { oxc: {
|
|
113
|
+
jsx: {
|
|
114
|
+
runtime: "classic",
|
|
115
|
+
refresh: command === "serve",
|
|
116
|
+
development: false
|
|
117
|
+
},
|
|
118
|
+
jsxRefreshInclude: makeIdFiltersToMatchWithQuery(include),
|
|
119
|
+
jsxRefreshExclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
120
|
+
} };
|
|
121
|
+
else return {
|
|
122
|
+
oxc: {
|
|
123
|
+
jsx: {
|
|
124
|
+
runtime: "automatic",
|
|
125
|
+
importSource: opts.jsxImportSource,
|
|
126
|
+
refresh: command === "serve"
|
|
127
|
+
},
|
|
128
|
+
jsxRefreshInclude: makeIdFiltersToMatchWithQuery(include),
|
|
129
|
+
jsxRefreshExclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
130
|
+
},
|
|
131
|
+
optimizeDeps: { rolldownOptions: { transform: { jsx: { runtime: "automatic" } } } }
|
|
132
|
+
};
|
|
133
|
+
if (opts.jsxRuntime === "classic") return { esbuild: { jsx: "transform" } };
|
|
134
|
+
else return {
|
|
135
|
+
esbuild: {
|
|
136
|
+
jsx: "automatic",
|
|
137
|
+
jsxImportSource: opts.jsxImportSource
|
|
138
|
+
},
|
|
139
|
+
optimizeDeps: { esbuildOptions: { jsx: "automatic" } }
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
configResolved(config) {
|
|
143
|
+
runningInVite = true;
|
|
144
|
+
base = config.base;
|
|
145
|
+
if (config.experimental.bundledDev) isBundledDev = true;
|
|
146
|
+
projectRoot = config.root;
|
|
147
|
+
isProduction = config.isProduction;
|
|
148
|
+
skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
|
|
149
|
+
const hooks = config.plugins.map((plugin) => plugin.api?.reactBabel).filter(defined);
|
|
150
|
+
if (hooks.length > 0) runPluginOverrides = (babelOptions, context) => {
|
|
151
|
+
hooks.forEach((hook) => hook(babelOptions, context, config));
|
|
152
|
+
};
|
|
153
|
+
else if (typeof opts.babel !== "function") {
|
|
154
|
+
staticBabelOptions = createBabelOptions(opts.babel);
|
|
155
|
+
if ((isRolldownVite || skipFastRefresh) && canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && (opts.jsxRuntime === "classic" ? isProduction : true)) delete viteBabel.transform;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
options(options) {
|
|
159
|
+
if (!runningInVite) {
|
|
160
|
+
options.transform ??= {};
|
|
161
|
+
options.transform.jsx = {
|
|
162
|
+
runtime: opts.jsxRuntime,
|
|
163
|
+
importSource: opts.jsxImportSource
|
|
164
|
+
};
|
|
165
|
+
return options;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
transform: {
|
|
169
|
+
filter: { id: {
|
|
170
|
+
include: makeIdFiltersToMatchWithQuery(include),
|
|
171
|
+
exclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
172
|
+
} },
|
|
173
|
+
async handler(code, id, options) {
|
|
174
|
+
const [filepath] = id.split("?");
|
|
175
|
+
if (!filter(filepath)) return;
|
|
176
|
+
const ssr = options?.ssr === true;
|
|
177
|
+
const babelOptions = (() => {
|
|
178
|
+
if (staticBabelOptions) return staticBabelOptions;
|
|
179
|
+
const newBabelOptions = createBabelOptions(typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel);
|
|
180
|
+
runPluginOverrides?.(newBabelOptions, {
|
|
181
|
+
id,
|
|
182
|
+
ssr
|
|
183
|
+
});
|
|
184
|
+
return newBabelOptions;
|
|
185
|
+
})();
|
|
186
|
+
const plugins = [...babelOptions.plugins];
|
|
187
|
+
let reactCompilerPlugin = getReactCompilerPlugin(plugins);
|
|
188
|
+
if (reactCompilerPlugin && ssr) {
|
|
189
|
+
plugins.splice(plugins.indexOf(reactCompilerPlugin), 1);
|
|
190
|
+
reactCompilerPlugin = void 0;
|
|
191
|
+
}
|
|
192
|
+
if (Array.isArray(reactCompilerPlugin) && reactCompilerPlugin[1]?.compilationMode === "annotation" && !compilerAnnotationRE.test(code)) {
|
|
193
|
+
plugins.splice(plugins.indexOf(reactCompilerPlugin), 1);
|
|
194
|
+
reactCompilerPlugin = void 0;
|
|
195
|
+
}
|
|
196
|
+
const isJSX = filepath.endsWith("x");
|
|
197
|
+
const useFastRefresh = !(isRolldownVite || skipFastRefresh) && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
|
|
198
|
+
if (useFastRefresh) plugins.push([await loadPlugin("react-refresh/babel"), { skipEnvCheck: true }]);
|
|
199
|
+
if (opts.jsxRuntime === "classic" && isJSX) {
|
|
200
|
+
if (!isProduction) plugins.push(await loadPlugin("@babel/plugin-transform-react-jsx-self"), await loadPlugin("@babel/plugin-transform-react-jsx-source"));
|
|
201
|
+
}
|
|
202
|
+
if (canSkipBabel(plugins, babelOptions)) return;
|
|
203
|
+
const parserPlugins = [...babelOptions.parserOpts.plugins];
|
|
204
|
+
if (!filepath.endsWith(".ts")) parserPlugins.push("jsx");
|
|
205
|
+
if (tsRE.test(filepath)) parserPlugins.push("typescript");
|
|
206
|
+
const result = await (await loadBabel()).transformAsync(code, {
|
|
207
|
+
...babelOptions,
|
|
208
|
+
root: projectRoot,
|
|
209
|
+
filename: id,
|
|
210
|
+
sourceFileName: filepath,
|
|
211
|
+
retainLines: reactCompilerPlugin ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
|
|
212
|
+
parserOpts: {
|
|
213
|
+
...babelOptions.parserOpts,
|
|
214
|
+
sourceType: "module",
|
|
215
|
+
allowAwaitOutsideFunction: true,
|
|
216
|
+
plugins: parserPlugins
|
|
217
|
+
},
|
|
218
|
+
generatorOpts: {
|
|
219
|
+
...babelOptions.generatorOpts,
|
|
220
|
+
importAttributesKeyword: "with",
|
|
221
|
+
decoratorsBeforeExport: true
|
|
222
|
+
},
|
|
223
|
+
plugins,
|
|
224
|
+
sourceMaps: true
|
|
225
|
+
});
|
|
226
|
+
if (result) {
|
|
227
|
+
if (!useFastRefresh) return {
|
|
228
|
+
code: result.code,
|
|
229
|
+
map: result.map
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
code: addRefreshWrapper(result.code, "@vitejs/plugin-react", id, opts.reactRefreshHost) ?? result.code,
|
|
233
|
+
map: result.map
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const viteRefreshWrapper = {
|
|
240
|
+
name: "vite:react:refresh-wrapper",
|
|
241
|
+
apply: "serve",
|
|
242
|
+
async applyToEnvironment(env) {
|
|
243
|
+
if (env.config.consumer !== "client" || skipFastRefresh) return false;
|
|
244
|
+
let nativePlugin;
|
|
245
|
+
try {
|
|
246
|
+
nativePlugin = (await import("vite/internal")).reactRefreshWrapperPlugin;
|
|
247
|
+
} catch {}
|
|
248
|
+
if (!nativePlugin || [
|
|
249
|
+
"7.1.10",
|
|
250
|
+
"7.1.11",
|
|
251
|
+
"7.1.12"
|
|
252
|
+
].includes(vite.version)) return true;
|
|
253
|
+
delete viteRefreshWrapper.transform;
|
|
254
|
+
return nativePlugin({
|
|
255
|
+
cwd: process.cwd(),
|
|
256
|
+
include: makeIdFiltersToMatchWithQuery(include),
|
|
257
|
+
exclude: makeIdFiltersToMatchWithQuery(exclude),
|
|
258
|
+
jsxImportSource,
|
|
259
|
+
reactRefreshHost: opts.reactRefreshHost ?? ""
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
transform: {
|
|
263
|
+
filter: { id: {
|
|
264
|
+
include: makeIdFiltersToMatchWithQuery(include),
|
|
265
|
+
exclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
266
|
+
} },
|
|
267
|
+
handler(code, id, options) {
|
|
268
|
+
const ssr = options?.ssr === true;
|
|
269
|
+
const [filepath] = id.split("?");
|
|
270
|
+
const isJSX = filepath.endsWith("x");
|
|
271
|
+
if (!(!skipFastRefresh && !ssr && (isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)))) return;
|
|
272
|
+
const newCode = addRefreshWrapper(code, "@vitejs/plugin-react", id, opts.reactRefreshHost);
|
|
273
|
+
return newCode ? {
|
|
274
|
+
code: newCode,
|
|
275
|
+
map: null
|
|
276
|
+
} : void 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const viteConfigPost = {
|
|
281
|
+
name: "vite:react:config-post",
|
|
282
|
+
enforce: "post",
|
|
283
|
+
config(userConfig) {
|
|
284
|
+
if (userConfig.server?.hmr === false) return { oxc: { jsx: { refresh: false } } };
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const viteReactRefreshBundledDevMode = {
|
|
288
|
+
name: "vite:react-refresh-fbm",
|
|
289
|
+
enforce: "pre",
|
|
290
|
+
transformIndexHtml: {
|
|
291
|
+
handler() {
|
|
292
|
+
if (!skipFastRefresh && isBundledDev) return [{
|
|
293
|
+
tag: "script",
|
|
294
|
+
attrs: { type: "module" },
|
|
295
|
+
children: getPreambleCode(base)
|
|
296
|
+
}];
|
|
297
|
+
},
|
|
298
|
+
order: "pre"
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const dependencies = [
|
|
302
|
+
"react",
|
|
303
|
+
"react-dom",
|
|
304
|
+
jsxImportDevRuntime,
|
|
305
|
+
jsxImportRuntime
|
|
306
|
+
];
|
|
307
|
+
const reactCompilerPlugin = getReactCompilerPlugin(typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : []);
|
|
308
|
+
if (reactCompilerPlugin != null) {
|
|
309
|
+
const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
|
|
310
|
+
dependencies.push(reactCompilerRuntimeModule);
|
|
311
|
+
}
|
|
312
|
+
const viteReactRefresh = {
|
|
313
|
+
name: "vite:react-refresh",
|
|
314
|
+
enforce: "pre",
|
|
315
|
+
config: (userConfig) => ({
|
|
316
|
+
build: silenceUseClientWarning(userConfig),
|
|
317
|
+
optimizeDeps: { include: dependencies }
|
|
318
|
+
}),
|
|
319
|
+
resolveId: {
|
|
320
|
+
filter: { id: exactRegex(runtimePublicPath) },
|
|
321
|
+
handler(id) {
|
|
322
|
+
if (id === runtimePublicPath) return id;
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
load: {
|
|
326
|
+
filter: { id: exactRegex(runtimePublicPath) },
|
|
327
|
+
handler(id) {
|
|
328
|
+
if (id === runtimePublicPath) return readFileSync(refreshRuntimePath, "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react");
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
transformIndexHtml() {
|
|
332
|
+
if (!skipFastRefresh && !isBundledDev) return [{
|
|
333
|
+
tag: "script",
|
|
334
|
+
attrs: { type: "module" },
|
|
335
|
+
children: getPreambleCode(base)
|
|
336
|
+
}];
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
return [
|
|
340
|
+
viteBabel,
|
|
341
|
+
...isRolldownVite ? [
|
|
342
|
+
viteRefreshWrapper,
|
|
343
|
+
viteConfigPost,
|
|
344
|
+
viteReactRefreshBundledDevMode
|
|
345
|
+
] : [],
|
|
346
|
+
viteReactRefresh,
|
|
347
|
+
virtualPreamblePlugin({
|
|
348
|
+
name: "@vitejs/plugin-react/preamble",
|
|
349
|
+
isEnabled: () => !skipFastRefresh && !isBundledDev
|
|
350
|
+
})
|
|
351
|
+
];
|
|
352
|
+
}
|
|
353
|
+
viteReact.preambleCode = preambleCode;
|
|
354
|
+
function viteReactForCjs(options) {
|
|
355
|
+
return viteReact.call(this, options);
|
|
356
|
+
}
|
|
357
|
+
Object.assign(viteReactForCjs, { default: viteReactForCjs });
|
|
358
|
+
function canSkipBabel(plugins, babelOptions) {
|
|
359
|
+
return !(plugins.length || babelOptions.presets.length || babelOptions.overrides.length || babelOptions.configFile || babelOptions.babelrc);
|
|
360
|
+
}
|
|
361
|
+
const loadedPlugin = /* @__PURE__ */ new Map();
|
|
362
|
+
function loadPlugin(path) {
|
|
363
|
+
const cached = loadedPlugin.get(path);
|
|
364
|
+
if (cached) return cached;
|
|
365
|
+
const promise = import(path).then((module) => {
|
|
366
|
+
const value = module.default || module;
|
|
367
|
+
loadedPlugin.set(path, value);
|
|
368
|
+
return value;
|
|
369
|
+
});
|
|
370
|
+
loadedPlugin.set(path, promise);
|
|
371
|
+
return promise;
|
|
372
|
+
}
|
|
373
|
+
function createBabelOptions(rawOptions) {
|
|
374
|
+
const babelOptions = {
|
|
375
|
+
babelrc: false,
|
|
376
|
+
configFile: false,
|
|
377
|
+
...rawOptions
|
|
378
|
+
};
|
|
379
|
+
babelOptions.plugins ||= [];
|
|
380
|
+
babelOptions.presets ||= [];
|
|
381
|
+
babelOptions.overrides ||= [];
|
|
382
|
+
babelOptions.parserOpts ||= {};
|
|
383
|
+
babelOptions.parserOpts.plugins ||= [];
|
|
384
|
+
return babelOptions;
|
|
385
|
+
}
|
|
386
|
+
function defined(value) {
|
|
387
|
+
return value !== void 0;
|
|
388
|
+
}
|
|
389
|
+
function getReactCompilerPlugin(plugins) {
|
|
390
|
+
return plugins.find((p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler");
|
|
391
|
+
}
|
|
392
|
+
function getReactCompilerRuntimeModule(plugin) {
|
|
393
|
+
let moduleName = "react/compiler-runtime";
|
|
394
|
+
if (Array.isArray(plugin)) {
|
|
395
|
+
if (plugin[1]?.target === "17" || plugin[1]?.target === "18") moduleName = "react-compiler-runtime";
|
|
396
|
+
}
|
|
397
|
+
return moduleName;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
//#endregion
|
|
401
|
+
export { viteReact as default, viteReactForCjs as "module.exports" };
|