@gravity-ui/data-source 0.9.0 → 0.9.1-alpha.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/build/cjs/core/types/DataSource.d.ts +8 -8
- package/build/cjs/core/types/DataSource.js.map +1 -1
- package/build/cjs/react/components/AsyncBoundary/AsyncBoundary.d.ts +3 -0
- package/build/cjs/react/components/AsyncBoundary/AsyncBoundary.js +35 -0
- package/build/cjs/react/components/AsyncBoundary/AsyncBoundary.js.map +1 -0
- package/build/cjs/react/components/AsyncBoundary/index.d.ts +3 -0
- package/build/cjs/react/components/AsyncBoundary/index.js +20 -0
- package/build/cjs/react/components/AsyncBoundary/index.js.map +1 -0
- package/build/cjs/react/components/AsyncBoundary/types.d.ts +13 -0
- package/build/cjs/react/components/AsyncBoundary/types.js +6 -0
- package/build/cjs/react/components/AsyncBoundary/types.js.map +1 -0
- package/build/cjs/react/components/AsyncBoundary/withAsyncBoundary.d.ts +3 -0
- package/build/cjs/react/components/AsyncBoundary/withAsyncBoundary.js +26 -0
- package/build/cjs/react/components/AsyncBoundary/withAsyncBoundary.js.map +1 -0
- package/build/cjs/react/components/EmptyView/EmptyView.d.ts +2 -0
- package/build/cjs/react/components/EmptyView/EmptyView.js +10 -0
- package/build/cjs/react/components/EmptyView/EmptyView.js.map +1 -0
- package/build/cjs/react/components/EmptyView/index.d.ts +1 -0
- package/build/cjs/react/components/EmptyView/index.js +13 -0
- package/build/cjs/react/components/EmptyView/index.js.map +1 -0
- package/build/cjs/react/components/types.d.ts +1 -1
- package/build/cjs/react/components/types.js.map +1 -1
- package/build/cjs/react/index.d.ts +5 -3
- package/build/cjs/react/index.js +27 -3
- package/build/cjs/react/index.js.map +1 -1
- package/build/cjs/react-query/components/QueryAsyncBoundary/QueryAsyncBoundary.d.ts +3 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/QueryAsyncBoundary.js +23 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/QueryAsyncBoundary.js.map +1 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/index.d.ts +3 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/index.js +20 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/index.js.map +1 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/types.d.ts +8 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/types.js +6 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/types.js.map +1 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.d.ts +3 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js +26 -0
- package/build/cjs/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js.map +1 -0
- package/build/cjs/react-query/hooks/useSuspenseQueryData.d.ts +9 -0
- package/build/cjs/react-query/hooks/useSuspenseQueryData.js +22 -0
- package/build/cjs/react-query/hooks/useSuspenseQueryData.js.map +1 -0
- package/build/cjs/react-query/index.d.ts +2 -0
- package/build/cjs/react-query/index.js +35 -0
- package/build/cjs/react-query/index.js.map +1 -1
- package/build/esm/core/types/DataSource.d.ts +8 -8
- package/build/esm/core/types/DataSource.js.map +1 -1
- package/build/esm/react/components/AsyncBoundary/AsyncBoundary.d.ts +3 -0
- package/build/esm/react/components/AsyncBoundary/AsyncBoundary.js +28 -0
- package/build/esm/react/components/AsyncBoundary/AsyncBoundary.js.map +1 -0
- package/build/esm/react/components/AsyncBoundary/index.d.ts +3 -0
- package/build/esm/react/components/AsyncBoundary/index.js +3 -0
- package/build/esm/react/components/AsyncBoundary/index.js.map +1 -0
- package/build/esm/react/components/AsyncBoundary/types.d.ts +13 -0
- package/build/esm/react/components/AsyncBoundary/types.js +2 -0
- package/build/esm/react/components/AsyncBoundary/types.js.map +1 -0
- package/build/esm/react/components/AsyncBoundary/withAsyncBoundary.d.ts +3 -0
- package/build/esm/react/components/AsyncBoundary/withAsyncBoundary.js +19 -0
- package/build/esm/react/components/AsyncBoundary/withAsyncBoundary.js.map +1 -0
- package/build/esm/react/components/EmptyView/EmptyView.d.ts +2 -0
- package/build/esm/react/components/EmptyView/EmptyView.js +4 -0
- package/build/esm/react/components/EmptyView/EmptyView.js.map +1 -0
- package/build/esm/react/components/EmptyView/index.d.ts +1 -0
- package/build/esm/react/components/EmptyView/index.js +2 -0
- package/build/esm/react/components/EmptyView/index.js.map +1 -0
- package/build/esm/react/components/types.d.ts +1 -1
- package/build/esm/react/components/types.js.map +1 -1
- package/build/esm/react/index.d.ts +5 -3
- package/build/esm/react/index.js +4 -2
- package/build/esm/react/index.js.map +1 -1
- package/build/esm/react-query/components/QueryAsyncBoundary/QueryAsyncBoundary.d.ts +3 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/QueryAsyncBoundary.js +16 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/QueryAsyncBoundary.js.map +1 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/index.d.ts +3 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/index.js +3 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/index.js.map +1 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/types.d.ts +8 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/types.js +2 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/types.js.map +1 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.d.ts +3 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js +19 -0
- package/build/esm/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js.map +1 -0
- package/build/esm/react-query/hooks/useSuspenseQueryData.d.ts +9 -0
- package/build/esm/react-query/hooks/useSuspenseQueryData.js +15 -0
- package/build/esm/react-query/hooks/useSuspenseQueryData.js.map +1 -0
- package/build/esm/react-query/index.d.ts +2 -0
- package/build/esm/react-query/index.js +2 -0
- package/build/esm/react-query/index.js.map +1 -1
- package/build/plugin/esbuild.d.mts +7 -0
- package/build/plugin/esbuild.mjs +6 -0
- package/build/plugin/factory-2tSt4Rte.mjs +513 -0
- package/build/plugin/index-mY40Sgl5.d.mts +24 -0
- package/build/plugin/index.d.mts +7 -0
- package/build/plugin/index.mjs +6 -0
- package/build/plugin/rollup.d.mts +6 -0
- package/build/plugin/rollup.mjs +6 -0
- package/build/plugin/rspack.d.mts +7 -0
- package/build/plugin/rspack.mjs +6 -0
- package/build/plugin/typings/client.d.ts +11 -0
- package/build/plugin/vite.d.mts +6 -0
- package/build/plugin/vite.mjs +6 -0
- package/build/plugin/webpack.d.mts +7 -0
- package/build/plugin/webpack.mjs +6 -0
- package/package.json +54 -5
- package/build/cjs/core/utils/__tests__/composeFullKey.test.js +0 -34
- package/build/cjs/core/utils/__tests__/composeFullKey.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/composeKey.test.js +0 -32
- package/build/cjs/core/utils/__tests__/composeKey.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/getError.test.js +0 -31
- package/build/cjs/core/utils/__tests__/getError.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/getStatus.test.js +0 -49
- package/build/cjs/core/utils/__tests__/getStatus.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/hasTag.test.js +0 -31
- package/build/cjs/core/utils/__tests__/hasTag.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/mergeStatuses.test.js +0 -25
- package/build/cjs/core/utils/__tests__/mergeStatuses.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/skipContext.test.js +0 -70
- package/build/cjs/core/utils/__tests__/skipContext.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/withCancellation.test.js +0 -106
- package/build/cjs/core/utils/__tests__/withCancellation.test.js.map +0 -1
- package/build/cjs/core/utils/__tests__/withCatch.test.js +0 -208
- package/build/cjs/core/utils/__tests__/withCatch.test.js.map +0 -1
- package/build/cjs/react/__tests__/DataManagerContext.test.js +0 -47
- package/build/cjs/react/__tests__/DataManagerContext.test.js.map +0 -1
- package/build/cjs/react/__tests__/withDataManager.test.js +0 -61
- package/build/cjs/react/__tests__/withDataManager.test.js.map +0 -1
- package/build/cjs/react/components/DataInfiniteLoader/__tests__/DataInfiniteLoader.test.js +0 -187
- package/build/cjs/react/components/DataInfiniteLoader/__tests__/DataInfiniteLoader.test.js.map +0 -1
- package/build/cjs/react/components/DataLoader/__tests__/DataLoader.test.js +0 -119
- package/build/cjs/react/components/DataLoader/__tests__/DataLoader.test.js.map +0 -1
- package/build/cjs/react-query/__tests__/createQueryNormalizer.test.js +0 -177
- package/build/cjs/react-query/__tests__/createQueryNormalizer.test.js.map +0 -1
- package/build/cjs/react-query/__tests__/normalizationEdgeCases.test.js +0 -100
- package/build/cjs/react-query/__tests__/normalizationEdgeCases.test.js.map +0 -1
- package/build/cjs/react-query/__tests__/subscriptions.test.js +0 -1180
- package/build/cjs/react-query/__tests__/subscriptions.test.js.map +0 -1
- package/build/cjs/react-query/__tests__/threeLevelIntegration.test.js +0 -659
- package/build/cjs/react-query/__tests__/threeLevelIntegration.test.js.map +0 -1
- package/build/cjs/react-query/__tests__/updateQueriesFromMutationData.test.js +0 -229
- package/build/cjs/react-query/__tests__/updateQueriesFromMutationData.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useQueryContext.test.js +0 -55
- package/build/cjs/react-query/hooks/__tests__/useQueryContext.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useQueryData.refetch.test.js +0 -230
- package/build/cjs/react-query/hooks/__tests__/useQueryData.refetch.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useQueryData.test.js +0 -97
- package/build/cjs/react-query/hooks/__tests__/useQueryData.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useQueryResponses.test.js +0 -77
- package/build/cjs/react-query/hooks/__tests__/useQueryResponses.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useRefetchAll.test.js +0 -79
- package/build/cjs/react-query/hooks/__tests__/useRefetchAll.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useRefetchErrored.test.js +0 -117
- package/build/cjs/react-query/hooks/__tests__/useRefetchErrored.test.js.map +0 -1
- package/build/cjs/react-query/hooks/__tests__/useRefetchInterval.test.js +0 -156
- package/build/cjs/react-query/hooks/__tests__/useRefetchInterval.test.js.map +0 -1
- package/build/cjs/react-query/utils/__tests__/checkMutationObjectsKeys.test.js +0 -295
- package/build/cjs/react-query/utils/__tests__/checkMutationObjectsKeys.test.js.map +0 -1
- package/build/cjs/react-query/utils/__tests__/formatNullableValue.test.js +0 -27
- package/build/cjs/react-query/utils/__tests__/formatNullableValue.test.js.map +0 -1
- package/build/cjs/react-query/utils/__tests__/getProgressiveRefetch.test.js +0 -76
- package/build/cjs/react-query/utils/__tests__/getProgressiveRefetch.test.js.map +0 -1
- package/build/cjs/react-query/utils/__tests__/normalizeStatus.test.js +0 -30
- package/build/cjs/react-query/utils/__tests__/normalizeStatus.test.js.map +0 -1
- package/build/cjs/react-query/utils/__tests__/notReachable.test.js +0 -35
- package/build/cjs/react-query/utils/__tests__/notReachable.test.js.map +0 -1
- package/build/cjs/react-query/utils/__tests__/parseNullableValue.test.js +0 -27
- package/build/cjs/react-query/utils/__tests__/parseNullableValue.test.js.map +0 -1
- package/build/cjs/setupTests.d.ts +0 -1
- package/build/cjs/setupTests.js +0 -4
- package/build/cjs/setupTests.js.map +0 -1
- package/build/esm/core/utils/__tests__/composeFullKey.test.js +0 -32
- package/build/esm/core/utils/__tests__/composeFullKey.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/composeKey.test.js +0 -30
- package/build/esm/core/utils/__tests__/composeKey.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/getError.test.js +0 -29
- package/build/esm/core/utils/__tests__/getError.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/getStatus.test.js +0 -47
- package/build/esm/core/utils/__tests__/getStatus.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/hasTag.test.js +0 -29
- package/build/esm/core/utils/__tests__/hasTag.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/mergeStatuses.test.js +0 -23
- package/build/esm/core/utils/__tests__/mergeStatuses.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/skipContext.test.js +0 -67
- package/build/esm/core/utils/__tests__/skipContext.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/withCancellation.test.js +0 -104
- package/build/esm/core/utils/__tests__/withCancellation.test.js.map +0 -1
- package/build/esm/core/utils/__tests__/withCatch.test.js +0 -205
- package/build/esm/core/utils/__tests__/withCatch.test.js.map +0 -1
- package/build/esm/react/__tests__/DataManagerContext.test.js +0 -44
- package/build/esm/react/__tests__/DataManagerContext.test.js.map +0 -1
- package/build/esm/react/__tests__/withDataManager.test.js +0 -58
- package/build/esm/react/__tests__/withDataManager.test.js.map +0 -1
- package/build/esm/react/components/DataInfiniteLoader/__tests__/DataInfiniteLoader.test.js +0 -184
- package/build/esm/react/components/DataInfiniteLoader/__tests__/DataInfiniteLoader.test.js.map +0 -1
- package/build/esm/react/components/DataLoader/__tests__/DataLoader.test.js +0 -116
- package/build/esm/react/components/DataLoader/__tests__/DataLoader.test.js.map +0 -1
- package/build/esm/react-query/__tests__/createQueryNormalizer.test.js +0 -174
- package/build/esm/react-query/__tests__/createQueryNormalizer.test.js.map +0 -1
- package/build/esm/react-query/__tests__/normalizationEdgeCases.test.js +0 -98
- package/build/esm/react-query/__tests__/normalizationEdgeCases.test.js.map +0 -1
- package/build/esm/react-query/__tests__/subscriptions.test.js +0 -1176
- package/build/esm/react-query/__tests__/subscriptions.test.js.map +0 -1
- package/build/esm/react-query/__tests__/threeLevelIntegration.test.js +0 -656
- package/build/esm/react-query/__tests__/threeLevelIntegration.test.js.map +0 -1
- package/build/esm/react-query/__tests__/updateQueriesFromMutationData.test.js +0 -227
- package/build/esm/react-query/__tests__/updateQueriesFromMutationData.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useQueryContext.test.js +0 -52
- package/build/esm/react-query/hooks/__tests__/useQueryContext.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useQueryData.refetch.test.js +0 -227
- package/build/esm/react-query/hooks/__tests__/useQueryData.refetch.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useQueryData.test.js +0 -95
- package/build/esm/react-query/hooks/__tests__/useQueryData.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useQueryResponses.test.js +0 -74
- package/build/esm/react-query/hooks/__tests__/useQueryResponses.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useRefetchAll.test.js +0 -77
- package/build/esm/react-query/hooks/__tests__/useRefetchAll.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useRefetchErrored.test.js +0 -115
- package/build/esm/react-query/hooks/__tests__/useRefetchErrored.test.js.map +0 -1
- package/build/esm/react-query/hooks/__tests__/useRefetchInterval.test.js +0 -154
- package/build/esm/react-query/hooks/__tests__/useRefetchInterval.test.js.map +0 -1
- package/build/esm/react-query/utils/__tests__/checkMutationObjectsKeys.test.js +0 -292
- package/build/esm/react-query/utils/__tests__/checkMutationObjectsKeys.test.js.map +0 -1
- package/build/esm/react-query/utils/__tests__/formatNullableValue.test.js +0 -25
- package/build/esm/react-query/utils/__tests__/formatNullableValue.test.js.map +0 -1
- package/build/esm/react-query/utils/__tests__/getProgressiveRefetch.test.js +0 -74
- package/build/esm/react-query/utils/__tests__/getProgressiveRefetch.test.js.map +0 -1
- package/build/esm/react-query/utils/__tests__/normalizeStatus.test.js +0 -28
- package/build/esm/react-query/utils/__tests__/normalizeStatus.test.js.map +0 -1
- package/build/esm/react-query/utils/__tests__/notReachable.test.js +0 -33
- package/build/esm/react-query/utils/__tests__/notReachable.test.js.map +0 -1
- package/build/esm/react-query/utils/__tests__/parseNullableValue.test.js +0 -25
- package/build/esm/react-query/utils/__tests__/parseNullableValue.test.js.map +0 -1
- package/build/esm/setupTests.d.ts +0 -1
- package/build/esm/setupTests.js +0 -2
- package/build/esm/setupTests.js.map +0 -1
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import { Visitor, parseSync } from "oxc-parser";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { transformSync } from "oxc-transform";
|
|
6
|
+
//#region src/plugin/core/utils.ts
|
|
7
|
+
const VIRTUAL_PREFIX = "\0dsl-plugin";
|
|
8
|
+
const COMPANION_TYPES = {
|
|
9
|
+
loading: "Loading",
|
|
10
|
+
error: "Error",
|
|
11
|
+
lazy: "Lazy"
|
|
12
|
+
};
|
|
13
|
+
const COMPANION_TYPE_BY_SUFFIX = {
|
|
14
|
+
Loading: "loading",
|
|
15
|
+
Error: "error",
|
|
16
|
+
Lazy: "lazy"
|
|
17
|
+
};
|
|
18
|
+
const COMPANION_TYPES_SET = new Set(Object.keys(COMPANION_TYPES));
|
|
19
|
+
const COMPANION_SUFFIXES_SET = new Set(Object.values(COMPANION_TYPES));
|
|
20
|
+
function isCompanionType(type) {
|
|
21
|
+
return COMPANION_TYPES_SET.has(type);
|
|
22
|
+
}
|
|
23
|
+
function isCompanionSuffix(suffix) {
|
|
24
|
+
return COMPANION_SUFFIXES_SET.has(suffix);
|
|
25
|
+
}
|
|
26
|
+
function makeVirtualId(type, sourceFile) {
|
|
27
|
+
return `${VIRTUAL_PREFIX}:${type}:${sourceFile}`;
|
|
28
|
+
}
|
|
29
|
+
function parseVirtualId(id) {
|
|
30
|
+
if (id.indexOf("\0dsl-plugin") !== 0) return null;
|
|
31
|
+
const rest = id.slice(12);
|
|
32
|
+
const colonIndex = rest.indexOf(":");
|
|
33
|
+
if (colonIndex === -1) return null;
|
|
34
|
+
const type = rest.slice(0, colonIndex);
|
|
35
|
+
if (!isCompanionType(type)) return null;
|
|
36
|
+
return {
|
|
37
|
+
type,
|
|
38
|
+
sourceFile: rest.slice(colonIndex + 1)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function makeCompanionId(type, sourceFile) {
|
|
42
|
+
const suffix = COMPANION_TYPES[type];
|
|
43
|
+
const ext = path.extname(sourceFile);
|
|
44
|
+
return `${ext ? sourceFile.slice(0, -ext.length) : sourceFile}.${suffix}${ext}`;
|
|
45
|
+
}
|
|
46
|
+
function parseCompanionId(id) {
|
|
47
|
+
const suffixIndex = id.lastIndexOf(".");
|
|
48
|
+
if (suffixIndex === -1) return null;
|
|
49
|
+
const suffix = id.slice(suffixIndex + 1);
|
|
50
|
+
if (!isCompanionSuffix(suffix)) return null;
|
|
51
|
+
return {
|
|
52
|
+
type: COMPANION_TYPE_BY_SUFFIX[suffix],
|
|
53
|
+
sourceFile: id.slice(0, suffixIndex)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function isRelativeId(id) {
|
|
57
|
+
return id[0] === ".";
|
|
58
|
+
}
|
|
59
|
+
function stripQuery(id) {
|
|
60
|
+
const queryIndex = id.indexOf("?");
|
|
61
|
+
return queryIndex === -1 ? id : id.slice(0, queryIndex);
|
|
62
|
+
}
|
|
63
|
+
function getHocString(from, name) {
|
|
64
|
+
return `${from}/${name}`;
|
|
65
|
+
}
|
|
66
|
+
function assertNever(value) {
|
|
67
|
+
throw new Error(`Unexpected value: ${value}`);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/plugin/core/extract.ts
|
|
71
|
+
function extractHocInfo(hocsSet, filename, source) {
|
|
72
|
+
const program = parseProgram(filename, source);
|
|
73
|
+
if (!program) return null;
|
|
74
|
+
const importDecls = [];
|
|
75
|
+
const trackedHocs = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const node of program.body) {
|
|
77
|
+
if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
|
|
78
|
+
importDecls.push(node);
|
|
79
|
+
for (const spec of node.specifiers) {
|
|
80
|
+
let importedName;
|
|
81
|
+
if (spec.type === "ImportSpecifier") {
|
|
82
|
+
if (spec.importKind === "type") continue;
|
|
83
|
+
importedName = spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name;
|
|
84
|
+
} else if (spec.type === "ImportDefaultSpecifier") importedName = "default";
|
|
85
|
+
else continue;
|
|
86
|
+
if (hocsSet.has(getHocString(node.source.value, importedName))) trackedHocs.set(spec.local.name, {
|
|
87
|
+
from: node.source.value,
|
|
88
|
+
name: importedName
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (trackedHocs.size === 0) return null;
|
|
93
|
+
for (const node of program.body) {
|
|
94
|
+
if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type" || node.declaration?.type !== "VariableDeclaration") continue;
|
|
95
|
+
for (const decl of node.declaration.declarations) {
|
|
96
|
+
if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length !== 3) continue;
|
|
97
|
+
const hocEntry = trackedHocs.get(decl.init.callee.name);
|
|
98
|
+
if (!hocEntry) continue;
|
|
99
|
+
const [contentArg, loadingArg, errorArg] = decl.init.arguments;
|
|
100
|
+
const contentInfo = contentArg.type === "Identifier" ? {
|
|
101
|
+
kind: "identifier",
|
|
102
|
+
name: contentArg.name
|
|
103
|
+
} : {
|
|
104
|
+
kind: "inline",
|
|
105
|
+
argSource: source.slice(contentArg.start, contentArg.end),
|
|
106
|
+
argStart: contentArg.start,
|
|
107
|
+
argEnd: contentArg.end
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
hocImportSource: hocEntry.from,
|
|
111
|
+
hocImportedName: hocEntry.name,
|
|
112
|
+
hocLocalName: decl.init.callee.name,
|
|
113
|
+
exportedName: decl.id.name,
|
|
114
|
+
hocExportStart: node.start,
|
|
115
|
+
content: contentInfo,
|
|
116
|
+
loading: {
|
|
117
|
+
argSource: source.slice(loadingArg.start, loadingArg.end),
|
|
118
|
+
argStart: loadingArg.start,
|
|
119
|
+
argEnd: loadingArg.end,
|
|
120
|
+
imports: filterNeededImports(importDecls, collectIdentifiers(loadingArg))
|
|
121
|
+
},
|
|
122
|
+
error: {
|
|
123
|
+
argSource: source.slice(errorArg.start, errorArg.end),
|
|
124
|
+
argStart: errorArg.start,
|
|
125
|
+
argEnd: errorArg.end,
|
|
126
|
+
imports: filterNeededImports(importDecls, collectIdentifiers(errorArg))
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const COMPANION_PROPS_RE = new RegExp(`\\.(${Object.values(COMPANION_TYPES).join("|")})\\b`);
|
|
134
|
+
function extractUsages(filename, source) {
|
|
135
|
+
const result = [];
|
|
136
|
+
if (!COMPANION_PROPS_RE.test(source)) return result;
|
|
137
|
+
const program = parseProgram(filename, source);
|
|
138
|
+
if (!program) return result;
|
|
139
|
+
const trackedImports = /* @__PURE__ */ new Map();
|
|
140
|
+
const importLocalStarts = /* @__PURE__ */ new Set();
|
|
141
|
+
for (const node of program.body) {
|
|
142
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
143
|
+
const declMeta = {
|
|
144
|
+
source: node.source.value,
|
|
145
|
+
namedSpecifiers: [],
|
|
146
|
+
start: node.start,
|
|
147
|
+
end: node.end
|
|
148
|
+
};
|
|
149
|
+
for (const spec of node.specifiers) {
|
|
150
|
+
if (spec.type !== "ImportSpecifier") continue;
|
|
151
|
+
const specMeta = {
|
|
152
|
+
localName: spec.local.name,
|
|
153
|
+
importedName: spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name,
|
|
154
|
+
start: spec.start,
|
|
155
|
+
end: spec.end
|
|
156
|
+
};
|
|
157
|
+
declMeta.namedSpecifiers.push(specMeta);
|
|
158
|
+
trackedImports.set(spec.local.name, {
|
|
159
|
+
decl: declMeta,
|
|
160
|
+
spec: specMeta
|
|
161
|
+
});
|
|
162
|
+
importLocalStarts.add(spec.local.start);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (trackedImports.size === 0) return result;
|
|
166
|
+
const usages = /* @__PURE__ */ new Map();
|
|
167
|
+
function ensureUsage(name) {
|
|
168
|
+
let usage = usages.get(name);
|
|
169
|
+
if (!usage) usages.set(name, usage = {
|
|
170
|
+
totalStarts: /* @__PURE__ */ new Set(),
|
|
171
|
+
accesses: []
|
|
172
|
+
});
|
|
173
|
+
return usage;
|
|
174
|
+
}
|
|
175
|
+
function trackIdentifier(name, start) {
|
|
176
|
+
if (trackedImports.has(name) && !importLocalStarts.has(start)) ensureUsage(name).totalStarts.add(start);
|
|
177
|
+
}
|
|
178
|
+
function trackCompanionAccess(localName, prop, exprStart, exprEnd) {
|
|
179
|
+
ensureUsage(localName).accesses.push({
|
|
180
|
+
prop,
|
|
181
|
+
start: exprStart,
|
|
182
|
+
end: exprEnd
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
new Visitor({
|
|
186
|
+
Identifier(node) {
|
|
187
|
+
trackIdentifier(node.name, node.start);
|
|
188
|
+
},
|
|
189
|
+
JSXIdentifier(node) {
|
|
190
|
+
trackIdentifier(node.name, node.start);
|
|
191
|
+
},
|
|
192
|
+
MemberExpression(node) {
|
|
193
|
+
if (!node.computed && node.object.type === "Identifier" && trackedImports.has(node.object.name) && node.property.type === "Identifier" && isCompanionSuffix(node.property.name)) trackCompanionAccess(node.object.name, node.property.name, node.start, node.end);
|
|
194
|
+
},
|
|
195
|
+
JSXMemberExpression(node) {
|
|
196
|
+
if (node.object.type === "JSXIdentifier" && trackedImports.has(node.object.name) && isCompanionSuffix(node.property.name)) trackCompanionAccess(node.object.name, node.property.name, node.start, node.end);
|
|
197
|
+
}
|
|
198
|
+
}).visit(program);
|
|
199
|
+
for (const [localName, { accesses, totalStarts }] of usages) {
|
|
200
|
+
if (accesses.length === 0) continue;
|
|
201
|
+
const { decl, spec } = trackedImports.get(localName);
|
|
202
|
+
const hasOtherUsages = totalStarts.size > accesses.length;
|
|
203
|
+
result.push({
|
|
204
|
+
decl,
|
|
205
|
+
spec,
|
|
206
|
+
accesses,
|
|
207
|
+
hasOtherUsages
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
function collectIdentifiers(node) {
|
|
213
|
+
const result = /* @__PURE__ */ new Set();
|
|
214
|
+
walk(node, (current) => {
|
|
215
|
+
if (isOwnIdentifier(current) || isJSXIdentifier(current)) result.add(current.name);
|
|
216
|
+
});
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
function filterNeededImports(importDecls, identifiers) {
|
|
220
|
+
const result = [];
|
|
221
|
+
for (const decl of importDecls) {
|
|
222
|
+
if (decl.specifiers.length === 0) {
|
|
223
|
+
result.push(decl);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const specifiers = decl.specifiers.filter((spec) => identifiers.has(spec.local.name));
|
|
227
|
+
if (specifiers.length > 0) result.push({
|
|
228
|
+
...decl,
|
|
229
|
+
specifiers
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
function isOwnNode(node) {
|
|
235
|
+
return typeof node === "object" && node !== null && "type" in node && typeof node.type === "string";
|
|
236
|
+
}
|
|
237
|
+
function isOwnIdentifier(node) {
|
|
238
|
+
return node.type === "Identifier";
|
|
239
|
+
}
|
|
240
|
+
function isJSXIdentifier(node) {
|
|
241
|
+
return node.type === "JSXIdentifier";
|
|
242
|
+
}
|
|
243
|
+
function walk(node, visitor) {
|
|
244
|
+
if (!isOwnNode(node)) return;
|
|
245
|
+
visitor(node);
|
|
246
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) for (const item of value) walk(item, visitor);
|
|
247
|
+
else walk(value, visitor);
|
|
248
|
+
}
|
|
249
|
+
function parseProgram(filename, source) {
|
|
250
|
+
const parsed = parseSync(filename, source, {
|
|
251
|
+
sourceType: "module",
|
|
252
|
+
range: true
|
|
253
|
+
});
|
|
254
|
+
if (parsed.errors.some((error) => error.severity === "Error")) return null;
|
|
255
|
+
return parsed.program;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/plugin/core/generate.ts
|
|
259
|
+
function generateAuxModule(sourceFile, info, type, options = {}) {
|
|
260
|
+
const auxInfo = info[type];
|
|
261
|
+
const name = info.exportedName;
|
|
262
|
+
const suffix = COMPANION_TYPES[type];
|
|
263
|
+
const cleanSourceFile = stripQuery(sourceFile);
|
|
264
|
+
const code = [
|
|
265
|
+
renderImports(auxInfo.imports),
|
|
266
|
+
"",
|
|
267
|
+
`export const ${name}${suffix} = ${auxInfo.argSource};`,
|
|
268
|
+
""
|
|
269
|
+
].join("\n").trimStart();
|
|
270
|
+
return transformJsx(makeCompanionId(type, cleanSourceFile), code, options);
|
|
271
|
+
}
|
|
272
|
+
function generateLazyModule(sourceFile, info, options = {}) {
|
|
273
|
+
const importSource = options.jsx?.importSource ?? "react";
|
|
274
|
+
const name = info.exportedName;
|
|
275
|
+
const cleanSourceFile = stripQuery(sourceFile);
|
|
276
|
+
const base = `./${path.basename(cleanSourceFile, path.extname(cleanSourceFile))}`;
|
|
277
|
+
const code = [
|
|
278
|
+
`import {lazy} from '${importSource}';`,
|
|
279
|
+
"",
|
|
280
|
+
info.hocImportedName === "default" ? `import ${info.hocLocalName} from '${info.hocImportSource}';` : `import {${info.hocImportedName}} from '${info.hocImportSource}';`,
|
|
281
|
+
"",
|
|
282
|
+
`import {${name}Loading} from '${base}.Loading';`,
|
|
283
|
+
`import {${name}Error} from '${base}.Error';`,
|
|
284
|
+
``,
|
|
285
|
+
`export const ${name}Lazy = ${info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName}(`,
|
|
286
|
+
` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`,
|
|
287
|
+
` ${name}Loading,`,
|
|
288
|
+
` ${name}Error,`,
|
|
289
|
+
`);`,
|
|
290
|
+
``
|
|
291
|
+
].join("\n");
|
|
292
|
+
const filename = makeCompanionId("lazy", cleanSourceFile);
|
|
293
|
+
return {
|
|
294
|
+
code,
|
|
295
|
+
map: new MagicString(code).generateMap({
|
|
296
|
+
source: filename,
|
|
297
|
+
includeContent: true,
|
|
298
|
+
hires: false
|
|
299
|
+
}).toString()
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function transformJsx(filename, code, options) {
|
|
303
|
+
const result = transformSync(filename, code, {
|
|
304
|
+
lang: "tsx",
|
|
305
|
+
jsx: options.jsx,
|
|
306
|
+
target: options.target,
|
|
307
|
+
sourcemap: true
|
|
308
|
+
});
|
|
309
|
+
if (result.errors.length > 0) {
|
|
310
|
+
const error = result.errors[0];
|
|
311
|
+
throw new Error(error.codeframe ?? error.message);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
code: result.code,
|
|
315
|
+
map: JSON.stringify(result.map)
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function renderImport(decl) {
|
|
319
|
+
const parts = [];
|
|
320
|
+
const named = [];
|
|
321
|
+
for (const spec of decl.specifiers) if (spec.type === "ImportDefaultSpecifier") parts.push(spec.local.name);
|
|
322
|
+
else if (spec.type === "ImportNamespaceSpecifier") parts.push(`* as ${spec.local.name}`);
|
|
323
|
+
else {
|
|
324
|
+
const imported = spec.imported.type === "Literal" ? JSON.stringify(spec.imported.value) : spec.imported.name;
|
|
325
|
+
const renderedSpec = imported === spec.local.name ? spec.local.name : `${imported} as ${spec.local.name}`;
|
|
326
|
+
named.push(spec.importKind === "type" ? `type ${renderedSpec}` : renderedSpec);
|
|
327
|
+
}
|
|
328
|
+
if (named.length > 0) parts.push(`{${named.join(", ")}}`);
|
|
329
|
+
return `import ${decl.importKind === "type" ? "type " : ""}${parts.join(", ")} from '${decl.source.value}';`;
|
|
330
|
+
}
|
|
331
|
+
function renderImports(imports) {
|
|
332
|
+
return imports.map(renderImport).join("\n");
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/plugin/core/resolve.ts
|
|
336
|
+
async function resolveSourceFile(ctx, sourceFile, importer) {
|
|
337
|
+
const nativeCtx = ctx.getNativeBuildContext?.();
|
|
338
|
+
const directory = path.dirname(importer);
|
|
339
|
+
if (nativeCtx?.framework === "webpack" || nativeCtx?.framework === "rspack") return resolveWithCompiler(nativeCtx.compiler, directory, sourceFile);
|
|
340
|
+
if (nativeCtx?.framework === "esbuild") {
|
|
341
|
+
const result = await nativeCtx.build.resolve(sourceFile, {
|
|
342
|
+
kind: "import-statement",
|
|
343
|
+
importer,
|
|
344
|
+
resolveDir: directory
|
|
345
|
+
});
|
|
346
|
+
return result.errors.length === 0 && result.path ? result.path : null;
|
|
347
|
+
}
|
|
348
|
+
if ("resolve" in ctx && typeof ctx.resolve === "function") {
|
|
349
|
+
const resolved = await ctx.resolve(sourceFile, importer, { skipSelf: true });
|
|
350
|
+
if (!resolved || resolved.external) return null;
|
|
351
|
+
return resolved.id;
|
|
352
|
+
}
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
function resolveWithCompiler(compiler, directory, request) {
|
|
356
|
+
return new Promise((resolve) => {
|
|
357
|
+
try {
|
|
358
|
+
compiler.resolverFactory.get("normal").resolve({}, directory, request, {}, (error, result) => {
|
|
359
|
+
resolve(!error && typeof result === "string" ? result : null);
|
|
360
|
+
});
|
|
361
|
+
} catch {
|
|
362
|
+
resolve(null);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/plugin/core/transform.ts
|
|
368
|
+
function transformDefinitionModule(s, filename, info) {
|
|
369
|
+
const name = info.exportedName;
|
|
370
|
+
const cleanFilename = stripQuery(filename);
|
|
371
|
+
const localSource = `./${path.basename(cleanFilename, path.extname(cleanFilename))}`;
|
|
372
|
+
s.prepend(`${renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))}\n${renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource))}\n`);
|
|
373
|
+
s.overwrite(info.loading.argStart, info.loading.argEnd, `${name}Loading`);
|
|
374
|
+
s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
|
|
375
|
+
if (info.content.kind === "identifier") s.append(`\nexport {${info.content.name} as ${name}Content};\n`);
|
|
376
|
+
else {
|
|
377
|
+
s.appendLeft(info.hocExportStart, `const ${name}Content = ${info.content.argSource};\n\n`);
|
|
378
|
+
s.overwrite(info.content.argStart, info.content.argEnd, `${name}Content`);
|
|
379
|
+
s.append(`\nexport {${name}Content};\n`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function transformUsages(s, usages) {
|
|
383
|
+
for (const { spec, accesses } of usages) for (const access of accesses) s.overwrite(access.start, access.end, `${spec.localName}${access.prop}`);
|
|
384
|
+
const newImports = [];
|
|
385
|
+
for (const { decl, spec, accesses } of usages) {
|
|
386
|
+
const propsUsed = new Set(accesses.map((access) => access.prop));
|
|
387
|
+
for (const prop of propsUsed) newImports.push(renderNamedImport(`${spec.localName}${prop}`, `${spec.importedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], decl.source)));
|
|
388
|
+
}
|
|
389
|
+
if (newImports.length > 0) s.prepend(newImports.join("\n") + "\n");
|
|
390
|
+
const localsByDecl = /* @__PURE__ */ new Map();
|
|
391
|
+
for (const usage of usages) {
|
|
392
|
+
if (usage.hasOtherUsages) continue;
|
|
393
|
+
let locals = localsByDecl.get(usage.decl);
|
|
394
|
+
if (!locals) localsByDecl.set(usage.decl, locals = /* @__PURE__ */ new Set());
|
|
395
|
+
locals.add(usage.spec.localName);
|
|
396
|
+
}
|
|
397
|
+
for (const [decl, locals] of localsByDecl) removeImportSpecifiers(s, decl, locals);
|
|
398
|
+
}
|
|
399
|
+
function removeImportSpecifiers(s, decl, localsToRemove) {
|
|
400
|
+
const kept = decl.namedSpecifiers.filter((spec) => !localsToRemove.has(spec.localName));
|
|
401
|
+
if (kept.length === 0) {
|
|
402
|
+
s.remove(decl.start, s.original[decl.end] === "\n" ? decl.end + 1 : decl.end);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const firstSpec = decl.namedSpecifiers[0];
|
|
406
|
+
const lastSpec = decl.namedSpecifiers[decl.namedSpecifiers.length - 1];
|
|
407
|
+
const braceOpen = s.original.lastIndexOf("{", firstSpec.start);
|
|
408
|
+
const braceClose = s.original.indexOf("}", lastSpec.end);
|
|
409
|
+
if (braceOpen === -1 || braceClose === -1) return;
|
|
410
|
+
const keptText = kept.map((spec) => s.original.slice(spec.start, spec.end)).join(", ");
|
|
411
|
+
s.overwrite(braceOpen + 1, braceClose, keptText);
|
|
412
|
+
}
|
|
413
|
+
function renderNamedImport(local, imported, source) {
|
|
414
|
+
return `import {${local === imported ? imported : `${imported} as ${local}`}} from '${source}';`;
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/plugin/core/factory.ts
|
|
418
|
+
const DEFAULT_HOCS = [{
|
|
419
|
+
from: "@gravity-ui/data-source",
|
|
420
|
+
name: "withAsyncBoundary"
|
|
421
|
+
}, {
|
|
422
|
+
from: "@gravity-ui/data-source",
|
|
423
|
+
name: "withQueryAsyncBoundary"
|
|
424
|
+
}];
|
|
425
|
+
const DEFAULT_INCLUDE = /\.(tsx?|jsx?)$/;
|
|
426
|
+
const VIRTUAL_EXCLUDE = new RegExp(`${VIRTUAL_PREFIX}|${encodeURIComponent(VIRTUAL_PREFIX)}`);
|
|
427
|
+
const dataSourceLazyUnpluginFactory = (options = {}) => {
|
|
428
|
+
const hocPatterns = options.hocs ?? DEFAULT_HOCS;
|
|
429
|
+
const include = options.include ?? DEFAULT_INCLUDE;
|
|
430
|
+
const exclude = [VIRTUAL_EXCLUDE];
|
|
431
|
+
if (Array.isArray(options.exclude)) exclude.push(...options.exclude);
|
|
432
|
+
else if (options.exclude) exclude.push(options.exclude);
|
|
433
|
+
const hocsSet = new Set(hocPatterns.map((pattern) => getHocString(pattern.from, pattern.name)));
|
|
434
|
+
const hocsRegexp = new RegExp(Array.from(new Set(hocPatterns.map((pattern) => pattern.name))).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
|
|
435
|
+
const hocInfoCache = /* @__PURE__ */ new Map();
|
|
436
|
+
const getHocInfo = (sourceFile, source) => {
|
|
437
|
+
const key = stripQuery(sourceFile);
|
|
438
|
+
const cachedInfo = hocInfoCache.get(key);
|
|
439
|
+
if (cachedInfo !== void 0) return cachedInfo;
|
|
440
|
+
const resolvedSource = source ?? fs.readFileSync(key, "utf-8");
|
|
441
|
+
const info = hocsRegexp.test(resolvedSource) ? extractHocInfo(hocsSet, key, resolvedSource) : null;
|
|
442
|
+
hocInfoCache.set(key, info);
|
|
443
|
+
return info;
|
|
444
|
+
};
|
|
445
|
+
return {
|
|
446
|
+
name: "data-source-lazy",
|
|
447
|
+
enforce: "pre",
|
|
448
|
+
async resolveId(id, importer) {
|
|
449
|
+
if (!importer) return null;
|
|
450
|
+
const companion = parseCompanionId(id);
|
|
451
|
+
const parsedImporter = parseVirtualId(importer);
|
|
452
|
+
const normalizedImporter = parsedImporter?.sourceFile ?? importer;
|
|
453
|
+
if (companion) {
|
|
454
|
+
if (await resolveSourceFile(this, id, normalizedImporter)) return null;
|
|
455
|
+
const resolvedSourceFile = await resolveSourceFile(this, companion.sourceFile, normalizedImporter);
|
|
456
|
+
return resolvedSourceFile && makeVirtualId(companion.type, resolvedSourceFile);
|
|
457
|
+
}
|
|
458
|
+
if (parsedImporter && isRelativeId(id)) return resolveSourceFile(this, id, parsedImporter.sourceFile);
|
|
459
|
+
return null;
|
|
460
|
+
},
|
|
461
|
+
load: {
|
|
462
|
+
filter: { id: new RegExp(VIRTUAL_PREFIX) },
|
|
463
|
+
handler(id) {
|
|
464
|
+
const parsedId = parseVirtualId(id);
|
|
465
|
+
if (!parsedId) return null;
|
|
466
|
+
this.addWatchFile(parsedId.sourceFile);
|
|
467
|
+
const info = getHocInfo(parsedId.sourceFile);
|
|
468
|
+
if (!info) return null;
|
|
469
|
+
switch (parsedId.type) {
|
|
470
|
+
case "loading":
|
|
471
|
+
case "error": return generateAuxModule(parsedId.sourceFile, info, parsedId.type, options.generateOptions);
|
|
472
|
+
case "lazy": return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
|
|
473
|
+
default: return assertNever(parsedId.type);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
transform: {
|
|
478
|
+
filter: { id: {
|
|
479
|
+
include,
|
|
480
|
+
exclude
|
|
481
|
+
} },
|
|
482
|
+
async handler(code, id) {
|
|
483
|
+
const info = getHocInfo(id, code);
|
|
484
|
+
const usages = extractUsages(id, code);
|
|
485
|
+
if (!info && usages.length === 0) return null;
|
|
486
|
+
const verifiedUsages = (await Promise.all(usages.map(async (usage) => {
|
|
487
|
+
const resolvedSourceFile = await resolveSourceFile(this, usage.decl.source, id);
|
|
488
|
+
if (!resolvedSourceFile) return null;
|
|
489
|
+
const usageInfo = getHocInfo(resolvedSourceFile);
|
|
490
|
+
if (!usageInfo || usageInfo.exportedName !== usage.spec.importedName) return null;
|
|
491
|
+
return usage;
|
|
492
|
+
}))).filter((usage) => usage !== null);
|
|
493
|
+
if (!info && verifiedUsages.length === 0) return null;
|
|
494
|
+
const s = new MagicString(code);
|
|
495
|
+
if (info) transformDefinitionModule(s, id, info);
|
|
496
|
+
if (verifiedUsages.length > 0) transformUsages(s, verifiedUsages);
|
|
497
|
+
if (!s.hasChanged()) return null;
|
|
498
|
+
return {
|
|
499
|
+
code: s.toString(),
|
|
500
|
+
map: s.generateMap({
|
|
501
|
+
source: id,
|
|
502
|
+
hires: true
|
|
503
|
+
}).toString()
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
watchChange(id) {
|
|
508
|
+
hocInfoCache.delete(stripQuery(id));
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
//#endregion
|
|
513
|
+
export { dataSourceLazyUnpluginFactory as n, DEFAULT_HOCS as t };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UnpluginFactory } from "unplugin";
|
|
2
|
+
import { JsxOptions } from "oxc-transform";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/core/generate.d.ts
|
|
5
|
+
interface GenerateOptions {
|
|
6
|
+
jsx?: JsxOptions;
|
|
7
|
+
target?: string | string[];
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/plugin/core/factory.d.ts
|
|
11
|
+
interface DataSourceLazyHocPattern {
|
|
12
|
+
from: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
interface DataSourceLazyPluginOptions {
|
|
16
|
+
hocs?: DataSourceLazyHocPattern[];
|
|
17
|
+
include?: RegExp | RegExp[];
|
|
18
|
+
exclude?: RegExp | RegExp[];
|
|
19
|
+
generateOptions?: GenerateOptions;
|
|
20
|
+
}
|
|
21
|
+
declare const DEFAULT_HOCS: DataSourceLazyPluginOptions['hocs'];
|
|
22
|
+
declare const dataSourceLazyUnpluginFactory: UnpluginFactory<DataSourceLazyPluginOptions | undefined>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { dataSourceLazyUnpluginFactory as i, DataSourceLazyHocPattern as n, DataSourceLazyPluginOptions as r, DEFAULT_HOCS as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { i as dataSourceLazyUnpluginFactory, n as DataSourceLazyHocPattern, r as DataSourceLazyPluginOptions, t as DEFAULT_HOCS } from "./index-mY40Sgl5.mjs";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/index.d.ts
|
|
5
|
+
declare const DataSourceLazyPlugin: _$unplugin.UnpluginInstance<DataSourceLazyPluginOptions | undefined, boolean>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { DEFAULT_HOCS, DataSourceLazyHocPattern, DataSourceLazyPlugin, DataSourceLazyPlugin as default, DataSourceLazyPluginOptions, dataSourceLazyUnpluginFactory };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { n as dataSourceLazyUnpluginFactory, t as DEFAULT_HOCS } from "./factory-2tSt4Rte.mjs";
|
|
2
|
+
import { createUnplugin } from "unplugin";
|
|
3
|
+
//#region src/plugin/index.ts
|
|
4
|
+
const DataSourceLazyPlugin = /* @__PURE__ */ createUnplugin(dataSourceLazyUnpluginFactory);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { DEFAULT_HOCS, DataSourceLazyPlugin, DataSourceLazyPlugin as default, dataSourceLazyUnpluginFactory };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { n as dataSourceLazyUnpluginFactory } from "./factory-2tSt4Rte.mjs";
|
|
2
|
+
import { createRollupPlugin } from "unplugin";
|
|
3
|
+
//#region src/plugin/rollup.ts
|
|
4
|
+
var rollup_default = createRollupPlugin(dataSourceLazyUnpluginFactory);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { rollup_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { r as DataSourceLazyPluginOptions } from "./index-mY40Sgl5.mjs";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/rspack.d.ts
|
|
5
|
+
declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => _$unplugin.RspackPluginInstance;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { n as dataSourceLazyUnpluginFactory } from "./factory-2tSt4Rte.mjs";
|
|
2
|
+
import { createRspackPlugin } from "unplugin";
|
|
3
|
+
//#region src/plugin/rspack.ts
|
|
4
|
+
var rspack_default = createRspackPlugin(dataSourceLazyUnpluginFactory);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { rspack_default as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {ComponentType} from 'react';
|
|
2
|
+
|
|
3
|
+
declare module '@gravity-ui/data-source' {
|
|
4
|
+
interface AsyncBoundaryComponent<TProps extends object> {
|
|
5
|
+
Lazy: ComponentType<TProps>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface QueryAsyncBoundaryComponent<TProps extends object> {
|
|
9
|
+
Lazy: ComponentType<TProps>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { n as dataSourceLazyUnpluginFactory } from "./factory-2tSt4Rte.mjs";
|
|
2
|
+
import { createVitePlugin } from "unplugin";
|
|
3
|
+
//#region src/plugin/vite.ts
|
|
4
|
+
var vite_default = createVitePlugin(dataSourceLazyUnpluginFactory);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { vite_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { r as DataSourceLazyPluginOptions } from "./index-mY40Sgl5.mjs";
|
|
2
|
+
import * as _$webpack from "webpack";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/webpack.d.ts
|
|
5
|
+
declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => _$webpack.WebpackPluginInstance;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { n as dataSourceLazyUnpluginFactory } from "./factory-2tSt4Rte.mjs";
|
|
2
|
+
import { createWebpackPlugin } from "unplugin";
|
|
3
|
+
//#region src/plugin/webpack.ts
|
|
4
|
+
var webpack_default = createWebpackPlugin(dataSourceLazyUnpluginFactory);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { webpack_default as default };
|