@umijs/plugins 4.0.0-canary.20240511.1 → 4.0.0-canary.20240513.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.
@@ -65,7 +65,7 @@ export default function InitialStateProvider(props: any) {
65
65
  appLoaded.current = true;
66
66
  }
67
67
  }, [loading]);
68
- if (loading && !appLoaded.current) {
68
+ if (loading && !appLoaded.current && typeof window !== 'undefined') {
69
69
  return <Loading />;
70
70
  }
71
71
  return props.children;
package/dist/layout.js CHANGED
@@ -36,7 +36,6 @@ var import_fs = require("fs");
36
36
  var import_path = require("path");
37
37
  var import_umi = require("umi");
38
38
  var import_plugin_utils = require("umi/plugin-utils");
39
- var import_npmClient = require("./utils/npmClient");
40
39
  var import_resolveProjectDep = require("./utils/resolveProjectDep");
41
40
  var import_withTmpPath = require("./utils/withTmpPath");
42
41
  var antIconsPath = (0, import_plugin_utils.winPath)(
@@ -119,7 +118,14 @@ var layout_default = (api) => {
119
118
  return memo;
120
119
  });
121
120
  api.onGenerateFiles(() => {
122
- const isFlattedDepsDir = (0, import_npmClient.isFlattedNodeModulesDir)(api);
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
+ }
126
+ const isFlattedDepsDir = [import_plugin_utils.NpmClientEnum.npm, import_plugin_utils.NpmClientEnum.yarn].includes(
127
+ realNpmClient
128
+ );
123
129
  const PKG_TYPE_REFERENCE = `
124
130
  /// <reference types="${isFlattedDepsDir ? ANT_PRO_COMPONENT : resolvedPkgPath}" />
125
131
  ${isFlattedDepsDir ? '/// <reference types="antd" />' : ""}
@@ -219,6 +219,16 @@ export { MicroAppWithMemoHistory } from './MicroAppWithMemoHistory';
219
219
  `
220
220
  });
221
221
  });
222
+ api.chainWebpack((config, { ssr }) => {
223
+ if (ssr) {
224
+ const originalExternals = config.get("externals");
225
+ config.externals({
226
+ ...originalExternals,
227
+ qiankun: "fs"
228
+ });
229
+ }
230
+ return config;
231
+ });
222
232
  };
223
233
  // Annotate the CommonJS export names for ESM import in node:
224
234
  0 && (module.exports = {
@@ -171,7 +171,10 @@ export interface IRuntimeConfig {
171
171
  `window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
172
172
  ];
173
173
  });
174
- api.chainWebpack((config) => {
174
+ api.chainWebpack((config, { ssr }) => {
175
+ if (ssr) {
176
+ return;
177
+ }
175
178
  (0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
176
179
  const {
177
180
  shouldNotAddLibraryChunkName = api.env === "production" || !Boolean(api.config.mfsu)
@@ -201,11 +204,14 @@ export interface IRuntimeConfig {
201
204
  });
202
205
  api.addEntryCode(() => [
203
206
  `
204
- export const bootstrap = qiankun_genBootstrap(render);
205
- export const mount = qiankun_genMount('${api.config.mountElementId}');
206
- export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
207
- export const update = qiankun_genUpdate();
208
- if (!window.__POWERED_BY_QIANKUN__) {
207
+ const qiankun_noop = () => new Error('qiankun lifecycle is not available for server runtime!');
208
+ const isServer = typeof window === 'undefined';
209
+ export const bootstrap = isServer ? qiankun_noop: qiankun_genBootstrap(render);
210
+ export const mount = isServer ? qiankun_noop : qiankun_genMount('${api.config.mountElementId}');
211
+ export const unmount = isServer ? qiankun_noop : qiankun_genUnmount('${api.config.mountElementId}');
212
+ export const update = isServer ? qiankun_noop : qiankun_genUpdate();
213
+ // 增加 ssr 的判断
214
+ if (!isServer && !window.__POWERED_BY_QIANKUN__) {
209
215
  bootstrap().then(mount);
210
216
  }
211
217
  `
@@ -24,7 +24,6 @@ __export(react_query_exports, {
24
24
  module.exports = __toCommonJS(react_query_exports);
25
25
  var import_utils = require("@umijs/utils");
26
26
  var import_path = require("path");
27
- var import_npmClient = require("./utils/npmClient");
28
27
  var import_resolveProjectDep = require("./utils/resolveProjectDep");
29
28
  var import_withTmpPath = require("./utils/withTmpPath");
30
29
  var react_query_default = (api) => {
@@ -135,117 +134,60 @@ export function rootContainer(container) {
135
134
  </QueryClientProvider>
136
135
  );
137
136
  }
138
- ` : "export {}"
137
+ ` : ""
139
138
  });
140
- const exportMembers = [
141
- // from @tanstack/query-core
142
- "QueryClient",
143
- "QueryCache",
144
- "MutationCache",
145
- "QueryObserver",
146
- "InfiniteQueryObserver",
147
- "QueriesObserver",
148
- "MutationObserver",
149
- // from @tanstack/react-query
150
- "useQuery",
151
- "useQueries",
152
- "useInfiniteQuery",
153
- "useMutation",
154
- "useIsFetching",
155
- "useIsMutating",
156
- ...useV5 ? [
157
- "useMutationState",
158
- "useSuspenseQuery",
159
- "useSuspenseInfiniteQuery",
160
- "useSuspenseQueries",
161
- "queryOptions",
162
- "infiniteQueryOptions"
163
- ] : [],
164
- "QueryClientProvider",
165
- "useQueryClient",
166
- "QueryErrorResetBoundary",
167
- "useQueryErrorResetBoundary",
168
- "useIsRestoring",
169
- "IsRestoringProvider"
170
- ].filter(Boolean);
171
139
  api.writeTmpFile({
172
140
  path: "index.tsx",
173
141
  content: `
174
142
  export {
175
- ${exportMembers.join(",\n ")}
143
+ // from @tanstack/query-core
144
+ QueryClient,
145
+ MutationObserver,
146
+ MutationCache,
147
+ InfiniteQueryObserver,
148
+ QueriesObserver,
149
+ QueryObserver,
150
+ QueryCache,
151
+ // from @tanstack/react-query
152
+ useIsRestoring,
153
+ IsRestoringProvider,
154
+ useInfiniteQuery,
155
+ useIsMutating,
156
+ useIsFetching,
157
+ useMutation,
158
+ useQueries,
159
+ useQuery,
160
+ QueryClientProvider,
161
+ useQueryClient,
162
+ QueryErrorResetBoundary,
163
+ useQueryErrorResetBoundary,
164
+ ${useV5 ? "queryOptions," : ""}
176
165
  } from '${pkgPath}';
177
166
  `
178
167
  });
179
- const exportTypes = [
180
- // from @tanstack/query-core
181
- "Query",
182
- "QueryState",
183
- "Mutation",
184
- // from @tanstack/react-query
185
- "QueriesResults",
186
- "QueriesOptions",
187
- "QueryErrorResetBoundaryProps",
188
- "QueryClientProviderProps",
189
- useV4 && "ContextOptions as QueryContextOptions,",
190
- "UseQueryOptions",
191
- "UseBaseQueryOptions",
192
- "UseQueryResult",
193
- "UseBaseQueryResult",
194
- "UseInfiniteQueryOptions",
195
- "UseMutationResult",
196
- "UseMutateFunction",
197
- "UseMutateAsyncFunction",
198
- "UseBaseMutationResult"
199
- ].filter(Boolean);
200
168
  api.writeTmpFile({
201
169
  path: "types.d.ts",
202
170
  content: `
203
171
  export type {
204
- ${exportTypes.join(",\n ")}
172
+ // from @tanstack/query-core
173
+ Query, QueryState, Mutation,
174
+ // from @tanstack/react-query
175
+ QueriesResults,
176
+ QueriesOptions,
177
+ QueryErrorResetBoundaryProps,
178
+ QueryClientProviderProps,
179
+ ${useV4 ? "ContextOptions as QueryContextOptions," : ""}
180
+ UseQueryOptions,
181
+ UseBaseQueryOptions,
182
+ UseQueryResult,
183
+ UseBaseQueryResult,
184
+ UseInfiniteQueryOptions,
185
+ UseMutationResult,
186
+ UseMutateFunction,
187
+ UseMutateAsyncFunction,
188
+ UseBaseMutationResult,
205
189
  } from '${pkgPath}';
206
190
  `
207
191
  });
208
- api.writeTmpFile({
209
- path: "types.d.ts",
210
- content: enableQueryClient ? `
211
- import React from 'react';
212
- import { QueryClientConfig } from '${pkgPath}';
213
- ${enableDevTools ? `
214
- import { ReactQueryDevtools } from '${devtoolsPkgPath}';
215
- ` : ""}
216
-
217
- export type RuntimeReactQueryType = {
218
- ${enableDevTools ? `
219
- devtool?: React.ComponentProps<typeof ReactQueryDevtools>
220
- ` : ""}
221
- queryClient?: QueryClientConfig
222
- }` : "export type RuntimeReactQueryType = {}"
223
- });
224
192
  });
225
- const isFlattedDepsDir = (0, import_npmClient.isFlattedNodeModulesDir)(api);
226
- if (useV5 && !isFlattedDepsDir) {
227
- let corePath;
228
- const REACT_QUERY_CORE_DEP_NAME = "@tanstack/query-core";
229
- try {
230
- corePath = (0, import_utils.winPath)(
231
- (0, import_path.dirname)(
232
- require.resolve(`${REACT_QUERY_CORE_DEP_NAME}/package.json`, {
233
- paths: [pkgPath]
234
- })
235
- )
236
- );
237
- } catch (e) {
238
- throw new Error(
239
- `[reactQuery] package '${REACT_QUERY_CORE_DEP_NAME}' resolve failed, ${e.message}`
240
- );
241
- }
242
- api.modifyTSConfig((config) => {
243
- import_utils.lodash.set(
244
- config,
245
- `compilerOptions.paths["${REACT_QUERY_CORE_DEP_NAME}"]`,
246
- [corePath]
247
- );
248
- return config;
249
- });
250
- }
251
193
  };
@@ -167,13 +167,6 @@ export const MicroApp = forwardRef(
167
167
  props: { settings: settingsFromConfig = {}, ...propsFromConfig } = {},
168
168
  } = appConfig || {};
169
169
 
170
- const __globalRoutesInfo = {
171
- appNameKeyAlias,
172
- masterHistoryType,
173
- base: globalSettings.base,
174
- microAppRoutes: globalSettings.microAppRoutes,
175
- };
176
-
177
170
  useEffect(() => {
178
171
  setComponentError(null);
179
172
  setLoading(true);
@@ -192,7 +185,12 @@ export const MicroApp = forwardRef(
192
185
  ...propsFromConfig,
193
186
  ...stateForSlave,
194
187
  ...propsFromParams,
195
- __globalRoutesInfo,
188
+ __globalRoutesInfo: {
189
+ appNameKeyAlias,
190
+ masterHistoryType,
191
+ base: globalSettings.base,
192
+ microAppRoutes: globalSettings.microAppRoutes,
193
+ },
196
194
  setLoading,
197
195
  },
198
196
  },
@@ -265,7 +263,6 @@ export const MicroApp = forwardRef(
265
263
  ...propsFromConfig,
266
264
  ...stateForSlave,
267
265
  ...propsFromParams,
268
- __globalRoutesInfo,
269
266
  setLoading,
270
267
  };
271
268
 
@@ -77,6 +77,10 @@ function patchMicroAppRouteComponent(routes: any[]) {
77
77
  }
78
78
 
79
79
  export async function render(oldRender: typeof noop) {
80
+ // 在 ssr 的场景下,直接返回旧的 render
81
+ if (typeof window === 'undefined') {
82
+ return oldRender();
83
+ }
80
84
  const runtimeOptions = await getMasterRuntime();
81
85
  let masterOptions: MasterOptions = {
82
86
  ...getMasterOptions(),
@@ -138,6 +142,10 @@ export async function render(oldRender: typeof noop) {
138
142
  }
139
143
 
140
144
  export function patchClientRoutes({ routes }: { routes: any[] }) {
145
+ // 在 ssr 的场景下,不执行主应用的 patchClientRoutes
146
+ if (typeof window === 'undefined') {
147
+ return;
148
+ }
141
149
  const microAppRoutes = [].concat(
142
150
  deepFilterLeafRoutes(routes),
143
151
  deepFilterLeafRoutes(microAppRuntimeRoutes),
@@ -3,6 +3,10 @@ import { createHistory } from '@@/core/history';
3
3
  import qiankunRender, { contextOptsStack } from './lifecycles';
4
4
 
5
5
  export function render(oldRender: any) {
6
+ // 在 ssr 的场景下,直接返回旧的 render
7
+ if (typeof window === 'undefined') {
8
+ return oldRender();
9
+ }
6
10
  return qiankunRender().then(oldRender);
7
11
  }
8
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-canary.20240511.1",
3
+ "version": "4.0.0-canary.20240513.1",
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.0.0-canary.20240511.1",
48
+ "@umijs/bundler-utils": "4.0.0-canary.20240513.1",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.0.0-canary.20240511.1"
53
+ "umi": "4.0.0-canary.20240513.1"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -1,2 +0,0 @@
1
- import type { IApi } from 'umi';
2
- export declare const isFlattedNodeModulesDir: (api: IApi) => boolean;
@@ -1,45 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/npmClient.ts
20
- var npmClient_exports = {};
21
- __export(npmClient_exports, {
22
- isFlattedNodeModulesDir: () => isFlattedNodeModulesDir
23
- });
24
- module.exports = __toCommonJS(npmClient_exports);
25
- var import_plugin_utils = require("umi/plugin-utils");
26
- var FLATTED_NPM_CLIENT = [
27
- import_plugin_utils.NpmClientEnum.npm,
28
- import_plugin_utils.NpmClientEnum.yarn
29
- ];
30
- var isFlattedNodeModulesDir = (api) => {
31
- var _a;
32
- let currentNpmClient = api.appData.npmClient;
33
- const tnpmCompatMode = api.appData.npmClient === import_plugin_utils.NpmClientEnum.tnpm && ((_a = api.pkg.tnpm) == null ? void 0 : _a.mode);
34
- if (tnpmCompatMode) {
35
- if (FLATTED_NPM_CLIENT.includes(api.pkg.tnpm.mode)) {
36
- return true;
37
- }
38
- }
39
- const isFlattedDir = FLATTED_NPM_CLIENT.includes(currentNpmClient);
40
- return isFlattedDir;
41
- };
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- isFlattedNodeModulesDir
45
- });