@umijs/plugins 4.1.4 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/layout.js CHANGED
@@ -118,8 +118,13 @@ var layout_default = (api) => {
118
118
  return memo;
119
119
  });
120
120
  api.onGenerateFiles(() => {
121
+ var _a;
122
+ let realNpmClient = api.appData.npmClient;
123
+ if (api.appData.npmClient === import_plugin_utils.NpmClientEnum.tnpm && ((_a = api.pkg.tnpm) == null ? void 0 : _a.mode) && [import_plugin_utils.NpmClientEnum.npm, import_plugin_utils.NpmClientEnum.yarn].includes(api.pkg.tnpm.mode)) {
124
+ realNpmClient = api.pkg.tnpm.mode;
125
+ }
121
126
  const isFlattedDepsDir = [import_plugin_utils.NpmClientEnum.npm, import_plugin_utils.NpmClientEnum.yarn].includes(
122
- api.appData.npmClient
127
+ realNpmClient
123
128
  );
124
129
  const PKG_TYPE_REFERENCE = `
125
130
  /// <reference types="${isFlattedDepsDir ? ANT_PRO_COMPONENT : resolvedPkgPath}" />
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/react-query.ts
@@ -50,25 +40,51 @@ var react_query_default = (api) => {
50
40
  enableBy: api.EnableBy.config
51
41
  });
52
42
  let pkgPath;
43
+ let devtoolsPkgPath;
44
+ const REACT_QUERY_DEP_NAME = "@tanstack/react-query";
45
+ const REACT_QUERY_DEVTOOLS_DEP_NAME = "@tanstack/react-query-devtools";
53
46
  const defaultPkgPath = (0, import_utils.winPath)(
54
- (0, import_path.dirname)(require.resolve("@tanstack/react-query/package.json"))
47
+ (0, import_path.dirname)(require.resolve(`${REACT_QUERY_DEP_NAME}/package.json`))
55
48
  );
56
- const devtoolPkgPath = (0, import_utils.winPath)(
57
- (0, import_path.dirname)(require.resolve("@tanstack/react-query-devtools/package.json"))
49
+ const defaultDevtoolPkgPath = (0, import_utils.winPath)(
50
+ (0, import_path.dirname)(require.resolve(`${REACT_QUERY_DEVTOOLS_DEP_NAME}/package.json`))
58
51
  );
59
52
  try {
60
53
  const localQueryPath = (0, import_resolveProjectDep.resolveProjectDep)({
61
54
  pkg: api.pkg,
62
55
  cwd: api.cwd,
63
- dep: "@tanstack/react-query"
56
+ dep: REACT_QUERY_DEP_NAME
64
57
  });
65
58
  pkgPath = localQueryPath ? (0, import_utils.winPath)(localQueryPath) : defaultPkgPath;
66
59
  } catch (e) {
67
- throw new Error(`[reactQuery] package resolve failed, ${e.message}`);
60
+ throw new Error(
61
+ `[reactQuery] package '${REACT_QUERY_DEP_NAME}' resolve failed, ${e.message}`
62
+ );
68
63
  }
64
+ try {
65
+ const localDevtoolsPkgPath = (0, import_resolveProjectDep.resolveProjectDep)({
66
+ pkg: api.pkg,
67
+ cwd: api.cwd,
68
+ dep: REACT_QUERY_DEVTOOLS_DEP_NAME
69
+ });
70
+ devtoolsPkgPath = localDevtoolsPkgPath ? (0, import_utils.winPath)(localDevtoolsPkgPath) : defaultDevtoolPkgPath;
71
+ } catch (e) {
72
+ throw new Error(
73
+ `[reactQuery] package '${REACT_QUERY_DEVTOOLS_DEP_NAME}' resolve failed, ${e.message}`
74
+ );
75
+ }
76
+ const pkg = require((0, import_path.join)(pkgPath, "package.json"));
77
+ const devtoolsPkg = require((0, import_path.join)(devtoolsPkgPath, "package.json"));
78
+ const pkgVersion = pkg.version;
79
+ const devtoolsVersion = devtoolsPkg.version;
80
+ const useV4 = pkgVersion.startsWith("4");
81
+ const useV4Devtools = devtoolsVersion.startsWith("4");
82
+ const useV5 = pkgVersion.startsWith("5");
83
+ const useV5Devtools = devtoolsVersion.startsWith("5");
84
+ const canUseDevtools = useV4 && useV4Devtools || useV5 && useV5Devtools;
69
85
  api.onStart(() => {
70
- if (pkgPath !== defaultPkgPath) {
71
- api.logger.info(`[reactQuery] use local package ${pkgPath}`);
86
+ if (pkgPath !== defaultPkgPath && !process.env.IS_UMI_BUILD_WORKER) {
87
+ api.logger.info(`[reactQuery] use local package, version: ${pkgVersion}`);
72
88
  }
73
89
  });
74
90
  api.addRuntimePlugin(() => {
@@ -77,9 +93,16 @@ var react_query_default = (api) => {
77
93
  api.addRuntimePluginKey(() => {
78
94
  return ["reactQuery"];
79
95
  });
96
+ api.modifyConfig((memo) => {
97
+ memo.alias[REACT_QUERY_DEP_NAME] = pkgPath;
98
+ if (canUseDevtools) {
99
+ memo.alias[REACT_QUERY_DEVTOOLS_DEP_NAME] = devtoolsPkgPath;
100
+ }
101
+ return memo;
102
+ });
80
103
  api.onGenerateFiles(() => {
81
104
  var _a;
82
- const enableDevTools = api.config.reactQuery.devtool !== false;
105
+ const enableDevTools = api.config.reactQuery.devtool !== false && canUseDevtools;
83
106
  const enableQueryClient = api.config.reactQuery.queryClient !== false;
84
107
  const reactQueryRuntimeCode = ((_a = api.appData.appJS) == null ? void 0 : _a.exports.includes(
85
108
  "reactQuery"
@@ -88,15 +111,26 @@ var react_query_default = (api) => {
88
111
  path: "runtime.tsx",
89
112
  content: enableQueryClient ? `
90
113
  import React from 'react';
91
- import { defaultContext, QueryClient, QueryClientProvider } from '${pkgPath}';
92
- import { ReactQueryDevtools } from '${devtoolPkgPath}';
114
+ import {
115
+ ${useV4 ? "defaultContext," : ""}
116
+ QueryClient,
117
+ QueryClientProvider
118
+ } from '${pkgPath}';
119
+ ${enableDevTools ? `import { ReactQueryDevtools } from '${devtoolsPkgPath}';` : ""}
93
120
  ${reactQueryRuntimeCode}
94
121
  const client = new QueryClient(reactQueryConfig.queryClient || {});
95
122
  export function rootContainer(container) {
96
123
  return (
97
- <QueryClientProvider client={client} context={defaultContext}>
124
+ <QueryClientProvider
125
+ client={client}
126
+ ${useV4 ? "context={defaultContext}" : ""}
127
+ >
98
128
  {container}
99
- ${enableDevTools ? "<ReactQueryDevtools context={defaultContext} initialIsOpen={false} {...(reactQueryConfig.devtool || {})} />" : ""}
129
+ ${enableDevTools ? `<ReactQueryDevtools
130
+ ${useV4 ? "context={defaultContext}" : ""}
131
+ initialIsOpen={false}
132
+ {...(reactQueryConfig.devtool || {})}
133
+ />` : ""}
100
134
  </QueryClientProvider>
101
135
  );
102
136
  }
@@ -127,6 +161,7 @@ export {
127
161
  useQueryClient,
128
162
  QueryErrorResetBoundary,
129
163
  useQueryErrorResetBoundary,
164
+ ${useV5 ? "queryOptions," : ""}
130
165
  } from '${pkgPath}';
131
166
  `
132
167
  });
@@ -141,7 +176,7 @@ export type {
141
176
  QueriesOptions,
142
177
  QueryErrorResetBoundaryProps,
143
178
  QueryClientProviderProps,
144
- ContextOptions as QueryContextOptions,
179
+ ${useV4 ? "ContextOptions as QueryContextOptions," : ""}
145
180
  UseQueryOptions,
146
181
  UseBaseQueryOptions,
147
182
  UseQueryResult,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -45,12 +45,12 @@
45
45
  "styled-components": "6.1.1",
46
46
  "tslib": "^2",
47
47
  "warning": "^4.0.3",
48
- "@umijs/bundler-utils": "4.1.4",
48
+ "@umijs/bundler-utils": "4.1.5",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.1.4"
53
+ "umi": "4.1.5"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"