@umijs/plugins 4.0.0-beta.8 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/README.md +4 -1
- package/dist/access.d.ts +1 -1
- package/dist/access.js +194 -4
- package/dist/{sass.d.ts → analytics.d.ts} +1 -1
- package/dist/analytics.js +118 -0
- package/dist/antd.d.ts +1 -1
- package/dist/antd.js +345 -157
- package/dist/{icons.d.ts → confetti.d.ts} +1 -1
- package/dist/confetti.js +64 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +30 -0
- package/dist/dva.d.ts +4 -1
- package/dist/dva.js +302 -8
- package/dist/initial-state.d.ts +1 -1
- package/dist/initial-state.js +147 -4
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +754 -4
- package/dist/locale.d.ts +2 -1
- package/dist/locale.js +257 -4
- package/dist/mf.d.ts +2 -0
- package/dist/mf.js +358 -0
- package/dist/model.d.ts +1 -1
- package/dist/model.js +109 -4
- package/dist/moment2dayjs.d.ts +3 -0
- package/dist/moment2dayjs.js +125 -0
- package/dist/qiankun/constants.d.ts +5 -0
- package/dist/qiankun/constants.js +41 -0
- package/dist/qiankun/master.d.ts +6 -0
- package/dist/qiankun/master.js +236 -0
- package/dist/qiankun/slave.d.ts +3 -0
- package/dist/qiankun/slave.js +345 -0
- package/dist/qiankun.d.ts +1 -1
- package/dist/qiankun.js +51 -4
- package/dist/react-query.d.ts +3 -0
- package/dist/react-query.js +193 -0
- package/dist/request.d.ts +1 -1
- package/dist/request.js +384 -4
- package/dist/styled-components.d.ts +3 -0
- package/dist/styled-components.js +150 -0
- package/dist/tailwindcss.d.ts +3 -0
- package/dist/tailwindcss.js +106 -0
- package/dist/unocss.d.ts +3 -0
- package/dist/unocss.js +71 -0
- package/dist/utils/astUtils.d.ts +3 -0
- package/dist/utils/astUtils.js +49 -0
- package/dist/utils/localeUtils.d.ts +33 -0
- package/dist/utils/localeUtils.js +139 -0
- package/dist/utils/mfUtils.d.ts +14 -0
- package/dist/utils/mfUtils.js +56 -0
- package/dist/utils/modelUtils.d.ts +40 -0
- package/dist/utils/modelUtils.js +286 -0
- package/dist/utils/resolveProjectDep.d.ts +5 -0
- package/dist/utils/resolveProjectDep.js +40 -0
- package/dist/utils/withTmpPath.d.ts +6 -0
- package/dist/utils/withTmpPath.js +39 -0
- package/dist/valtio.d.ts +3 -0
- package/dist/valtio.js +81 -0
- package/libs/dva.tsx +45 -0
- package/libs/model.tsx +180 -0
- package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
- package/libs/qiankun/master/AntdLoader.tsx +15 -0
- package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
- package/libs/qiankun/master/MicroApp.tsx +327 -0
- package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
- package/libs/qiankun/master/common.ts +172 -0
- package/libs/qiankun/master/constants.ts +19 -0
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
- package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
- package/libs/qiankun/master/routeUtils.ts +26 -0
- package/libs/qiankun/master/types.ts +54 -0
- package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
- package/libs/qiankun/slave/connectMaster.tsx +14 -0
- package/libs/qiankun/slave/constants.ts +5 -0
- package/libs/qiankun/slave/lifecycles.ts +164 -0
- package/libs/qiankun/slave/qiankunModel.ts +18 -0
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
- package/package.json +54 -24
- package/templates/antd/runtime.ts.tpl +170 -0
- package/templates/antd/types.d.ts.tpl +17 -0
- package/templates/locale/SelectLang.tpl +502 -0
- package/templates/locale/locale.tpl +82 -0
- package/templates/locale/localeExports.tpl +307 -0
- package/templates/locale/runtime.tpl +34 -0
- package/templates/mf/runtime.ts.tpl +149 -0
- package/dist/access.d.ts.map +0 -1
- package/dist/antd.d.ts.map +0 -1
- package/dist/dva.d.ts.map +0 -1
- package/dist/icons.d.ts.map +0 -1
- package/dist/icons.js +0 -5
- package/dist/initial-state.d.ts.map +0 -1
- package/dist/layout.d.ts.map +0 -1
- package/dist/locale.d.ts.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/qiankun.d.ts.map +0 -1
- package/dist/request.d.ts.map +0 -1
- package/dist/sass.d.ts.map +0 -1
- package/dist/sass.js +0 -5
package/dist/request.js
CHANGED
|
@@ -1,5 +1,385 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/request.ts
|
|
30
|
+
var request_exports = {};
|
|
31
|
+
__export(request_exports, {
|
|
32
|
+
default: () => request_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(request_exports);
|
|
35
|
+
var import_path = require("path");
|
|
36
|
+
var import_umi = require("umi");
|
|
37
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
38
|
+
var request_default = (api) => {
|
|
39
|
+
api.describe({
|
|
40
|
+
key: "request",
|
|
41
|
+
config: {
|
|
42
|
+
schema: ({ zod }) => {
|
|
43
|
+
return zod.object({
|
|
44
|
+
// TODO: '' | string 没有找到对应的写法
|
|
45
|
+
dataField: zod.string()
|
|
46
|
+
}).partial();
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
enableBy: api.EnableBy.config
|
|
50
|
+
});
|
|
51
|
+
api.addRuntimePluginKey(() => ["request"]);
|
|
52
|
+
const requestTpl = `
|
|
53
|
+
import axios, {
|
|
54
|
+
type AxiosInstance,
|
|
55
|
+
type AxiosRequestConfig,
|
|
56
|
+
type AxiosResponse,
|
|
57
|
+
type AxiosError,
|
|
58
|
+
} from '{{{axiosPath}}}';
|
|
59
|
+
import useUmiRequest, { UseRequestProvider } from '{{{umiRequestPath}}}';
|
|
60
|
+
import { ApplyPluginsType } from 'umi';
|
|
61
|
+
import { getPluginManager } from '../core/plugin';
|
|
62
|
+
|
|
63
|
+
import {
|
|
64
|
+
BaseOptions,
|
|
65
|
+
BasePaginatedOptions,
|
|
66
|
+
BaseResult,
|
|
67
|
+
CombineService,
|
|
68
|
+
LoadMoreFormatReturn,
|
|
69
|
+
LoadMoreOptions,
|
|
70
|
+
LoadMoreOptionsWithFormat,
|
|
71
|
+
LoadMoreParams,
|
|
72
|
+
LoadMoreResult,
|
|
73
|
+
OptionsWithFormat,
|
|
74
|
+
PaginatedFormatReturn,
|
|
75
|
+
PaginatedOptionsWithFormat,
|
|
76
|
+
PaginatedParams,
|
|
77
|
+
PaginatedResult,
|
|
78
|
+
} from '{{{umiRequestPath}}}/es/types';
|
|
79
|
+
|
|
80
|
+
type ResultWithData< T = any > = { {{resultDataType}} [key: string]: any };
|
|
81
|
+
|
|
82
|
+
function useRequest<
|
|
83
|
+
R = any,
|
|
84
|
+
P extends any[] = any,
|
|
85
|
+
U = any,
|
|
86
|
+
UU extends U = any,
|
|
87
|
+
>(
|
|
88
|
+
service: CombineService<R, P>,
|
|
89
|
+
options: OptionsWithFormat<R, P, U, UU>,
|
|
90
|
+
): BaseResult<U, P>;
|
|
91
|
+
function useRequest<R extends ResultWithData = any, P extends any[] = any>(
|
|
92
|
+
service: CombineService<R, P>,
|
|
93
|
+
options?: BaseOptions<R{{{resultDataField}}}, P>,
|
|
94
|
+
): BaseResult<R{{{resultDataField}}}, P>;
|
|
95
|
+
function useRequest<R extends LoadMoreFormatReturn = any, RR = any>(
|
|
96
|
+
service: CombineService<RR, LoadMoreParams<R>>,
|
|
97
|
+
options: LoadMoreOptionsWithFormat<R, RR>,
|
|
98
|
+
): LoadMoreResult<R>;
|
|
99
|
+
function useRequest<
|
|
100
|
+
R extends ResultWithData<LoadMoreFormatReturn | any> = any,
|
|
101
|
+
RR extends R = any,
|
|
102
|
+
>(
|
|
103
|
+
service: CombineService<R, LoadMoreParams<R{{{resultDataField}}}>>,
|
|
104
|
+
options: LoadMoreOptions<RR{{{resultDataField}}}>,
|
|
105
|
+
): LoadMoreResult<R{{{resultDataField}}}>;
|
|
106
|
+
|
|
107
|
+
function useRequest<R = any, Item = any, U extends Item = any>(
|
|
108
|
+
service: CombineService<R, PaginatedParams>,
|
|
109
|
+
options: PaginatedOptionsWithFormat<R, Item, U>,
|
|
110
|
+
): PaginatedResult<Item>;
|
|
111
|
+
function useRequest<Item = any, U extends Item = any>(
|
|
112
|
+
service: CombineService<
|
|
113
|
+
ResultWithData<PaginatedFormatReturn<Item>>,
|
|
114
|
+
PaginatedParams
|
|
115
|
+
>,
|
|
116
|
+
options: BasePaginatedOptions<U>,
|
|
117
|
+
): PaginatedResult<Item>;
|
|
118
|
+
function useRequest(service: any, options: any = {}) {
|
|
119
|
+
return useUmiRequest(service, {
|
|
120
|
+
formatResult: {{{formatResult}}},
|
|
121
|
+
requestMethod: (requestOptions: any) => {
|
|
122
|
+
if (typeof requestOptions === 'string') {
|
|
123
|
+
return request(requestOptions);
|
|
124
|
+
}
|
|
125
|
+
if (typeof requestOptions === 'object') {
|
|
126
|
+
const { url, ...rest } = requestOptions;
|
|
127
|
+
return request(url, rest);
|
|
128
|
+
}
|
|
129
|
+
throw new Error('request options error');
|
|
130
|
+
},
|
|
131
|
+
...options,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// request 方法 opts 参数的接口
|
|
136
|
+
interface IRequestOptions extends AxiosRequestConfig {
|
|
137
|
+
skipErrorHandler?: boolean;
|
|
138
|
+
requestInterceptors?: IRequestInterceptorTuple[];
|
|
139
|
+
responseInterceptors?: IResponseInterceptorTuple[];
|
|
140
|
+
[key: string]: any;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface IRequestOptionsWithResponse extends IRequestOptions {
|
|
144
|
+
getResponse: true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface IRequestOptionsWithoutResponse extends IRequestOptions{
|
|
148
|
+
getResponse: false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface IRequest{
|
|
152
|
+
<T = any>(url: string, opts: IRequestOptionsWithResponse): Promise<AxiosResponse<T>>;
|
|
153
|
+
<T = any>(url: string, opts: IRequestOptionsWithoutResponse): Promise<T>;
|
|
154
|
+
<T = any>(url: string, opts: IRequestOptions): Promise<T>; // getResponse 默认是 false, 因此不提供该参数时,只返回 data
|
|
155
|
+
<T = any>(url: string): Promise<T>; // 不提供 opts 时,默认使用 'GET' method,并且默认返回 data
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type RequestError = AxiosError | Error
|
|
159
|
+
|
|
160
|
+
interface IErrorHandler {
|
|
161
|
+
(error: RequestError, opts: IRequestOptions): void;
|
|
162
|
+
}
|
|
163
|
+
type WithPromise<T> = T | Promise<T>;
|
|
164
|
+
type IRequestInterceptorAxios = (config: IRequestOptions) => WithPromise<IRequestOptions>;
|
|
165
|
+
type IRequestInterceptorUmiRequest = (url: string, config : IRequestOptions) => WithPromise<{ url: string, options: IRequestOptions }>;
|
|
166
|
+
type IRequestInterceptor = IRequestInterceptorAxios | IRequestInterceptorUmiRequest;
|
|
167
|
+
type IErrorInterceptor = (error: Error) => Promise<Error>;
|
|
168
|
+
type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => WithPromise<AxiosResponse<T>> ;
|
|
169
|
+
type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [IRequestInterceptor] | IRequestInterceptor
|
|
170
|
+
type IResponseInterceptorTuple = [IResponseInterceptor, IErrorInterceptor] | [IResponseInterceptor] | IResponseInterceptor
|
|
171
|
+
|
|
172
|
+
export interface RequestConfig<T = any> extends AxiosRequestConfig {
|
|
173
|
+
errorConfig?: {
|
|
174
|
+
errorHandler?: IErrorHandler;
|
|
175
|
+
errorThrower?: ( res: T ) => void
|
|
176
|
+
};
|
|
177
|
+
requestInterceptors?: IRequestInterceptorTuple[];
|
|
178
|
+
responseInterceptors?: IResponseInterceptorTuple[];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let requestInstance: AxiosInstance;
|
|
182
|
+
let config: RequestConfig;
|
|
183
|
+
const getConfig = (): RequestConfig => {
|
|
184
|
+
if (config) return config;
|
|
185
|
+
config = getPluginManager().applyPlugins({
|
|
186
|
+
key: 'request',
|
|
187
|
+
type: ApplyPluginsType.modify,
|
|
188
|
+
initialValue: {},
|
|
189
|
+
});
|
|
190
|
+
return config;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const getRequestInstance = (): AxiosInstance => {
|
|
194
|
+
if (requestInstance) return requestInstance;
|
|
195
|
+
const config = getConfig();
|
|
196
|
+
requestInstance = axios.create(config);
|
|
197
|
+
|
|
198
|
+
config?.requestInterceptors?.forEach((interceptor) => {
|
|
199
|
+
if(interceptor instanceof Array){
|
|
200
|
+
requestInstance.interceptors.request.use(async (config) => {
|
|
201
|
+
const { url } = config;
|
|
202
|
+
if(interceptor[0].length === 2){
|
|
203
|
+
const { url: newUrl, options } = await interceptor[0](url, config);
|
|
204
|
+
return { ...options, url: newUrl };
|
|
205
|
+
}
|
|
206
|
+
return interceptor[0](config);
|
|
207
|
+
}, interceptor[1]);
|
|
208
|
+
} else {
|
|
209
|
+
requestInstance.interceptors.request.use(async (config) => {
|
|
210
|
+
const { url } = config;
|
|
211
|
+
if(interceptor.length === 2){
|
|
212
|
+
const { url: newUrl, options } = await interceptor(url, config);
|
|
213
|
+
return { ...options, url: newUrl };
|
|
214
|
+
}
|
|
215
|
+
return interceptor(config);
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
config?.responseInterceptors?.forEach((interceptor) => {
|
|
221
|
+
interceptor instanceof Array ?
|
|
222
|
+
requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
|
|
223
|
+
requestInstance.interceptors.response.use(interceptor);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// 当响应的数据 success 是 false 的时候,抛出 error 以供 errorHandler 处理。
|
|
227
|
+
requestInstance.interceptors.response.use((response) => {
|
|
228
|
+
const { data } = response;
|
|
229
|
+
if(data?.success === false && config?.errorConfig?.errorThrower){
|
|
230
|
+
config.errorConfig.errorThrower(data);
|
|
231
|
+
}
|
|
232
|
+
return response;
|
|
233
|
+
})
|
|
234
|
+
return requestInstance;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
|
|
238
|
+
const requestInstance = getRequestInstance();
|
|
239
|
+
const config = getConfig();
|
|
240
|
+
const { getResponse = false, requestInterceptors, responseInterceptors } = opts;
|
|
241
|
+
const requestInterceptorsToEject = requestInterceptors?.map((interceptor) => {
|
|
242
|
+
if(interceptor instanceof Array){
|
|
243
|
+
return requestInstance.interceptors.request.use(async (config) => {
|
|
244
|
+
const { url } = config;
|
|
245
|
+
if(interceptor[0].length === 2){
|
|
246
|
+
const { url: newUrl, options } = await interceptor[0](url, config);
|
|
247
|
+
return { ...options, url: newUrl };
|
|
248
|
+
}
|
|
249
|
+
return interceptor[0](config);
|
|
250
|
+
}, interceptor[1]);
|
|
251
|
+
} else {
|
|
252
|
+
return requestInstance.interceptors.request.use(async (config) => {
|
|
253
|
+
const { url } = config;
|
|
254
|
+
if(interceptor.length === 2){
|
|
255
|
+
const { url: newUrl, options } = await interceptor(url, config);
|
|
256
|
+
return { ...options, url: newUrl };
|
|
257
|
+
}
|
|
258
|
+
return interceptor(config);
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
const responseInterceptorsToEject = responseInterceptors?.map((interceptor) => {
|
|
263
|
+
return interceptor instanceof Array ?
|
|
264
|
+
requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
|
|
265
|
+
requestInstance.interceptors.response.use(interceptor);
|
|
266
|
+
});
|
|
267
|
+
return new Promise((resolve, reject)=>{
|
|
268
|
+
requestInstance
|
|
269
|
+
.request({...opts, url})
|
|
270
|
+
.then((res)=>{
|
|
271
|
+
requestInterceptorsToEject?.forEach((interceptor) => {
|
|
272
|
+
requestInstance.interceptors.request.eject(interceptor);
|
|
273
|
+
});
|
|
274
|
+
responseInterceptorsToEject?.forEach((interceptor) => {
|
|
275
|
+
requestInstance.interceptors.response.eject(interceptor);
|
|
276
|
+
});
|
|
277
|
+
resolve(getResponse ? res : res.data);
|
|
278
|
+
})
|
|
279
|
+
.catch((error)=>{
|
|
280
|
+
requestInterceptorsToEject?.forEach((interceptor) => {
|
|
281
|
+
requestInstance.interceptors.request.eject(interceptor);
|
|
282
|
+
});
|
|
283
|
+
responseInterceptorsToEject?.forEach((interceptor) => {
|
|
284
|
+
requestInstance.interceptors.response.eject(interceptor);
|
|
285
|
+
});
|
|
286
|
+
try {
|
|
287
|
+
const handler =
|
|
288
|
+
config?.errorConfig?.errorHandler;
|
|
289
|
+
if(handler)
|
|
290
|
+
handler(error, opts, config);
|
|
291
|
+
} catch (e) {
|
|
292
|
+
reject(e);
|
|
293
|
+
}
|
|
294
|
+
reject(error);
|
|
295
|
+
})
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export {
|
|
300
|
+
useRequest,
|
|
301
|
+
UseRequestProvider,
|
|
302
|
+
request,
|
|
303
|
+
getRequestInstance,
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export type {
|
|
307
|
+
AxiosInstance,
|
|
308
|
+
AxiosRequestConfig,
|
|
309
|
+
AxiosResponse,
|
|
310
|
+
AxiosError,
|
|
311
|
+
RequestError,
|
|
312
|
+
IRequestInterceptorAxios as RequestInterceptorAxios,
|
|
313
|
+
IRequestInterceptorUmiRequest as RequestInterceptorUmiRequest,
|
|
314
|
+
IRequestInterceptor as RequestInterceptor,
|
|
315
|
+
IErrorInterceptor as ErrorInterceptor,
|
|
316
|
+
IResponseInterceptor as ResponseInterceptor,
|
|
317
|
+
IRequestOptions as RequestOptions,
|
|
318
|
+
IRequest as Request,
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
`;
|
|
322
|
+
api.onGenerateFiles(() => {
|
|
323
|
+
var _a;
|
|
324
|
+
const umiRequestPath = (0, import_plugin_utils.winPath)(
|
|
325
|
+
(0, import_path.dirname)(require.resolve("@ahooksjs/use-request/package.json"))
|
|
326
|
+
);
|
|
327
|
+
const axiosPath = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("axios/package.json")));
|
|
328
|
+
let dataField = (_a = api.config.request) == null ? void 0 : _a.dataField;
|
|
329
|
+
if (dataField === void 0)
|
|
330
|
+
dataField = "data";
|
|
331
|
+
const isEmpty = dataField === "";
|
|
332
|
+
const formatResult = isEmpty ? `result => result` : `result => result?.${dataField}`;
|
|
333
|
+
const resultDataType = isEmpty ? dataField : `${dataField}?: T;`;
|
|
334
|
+
const resultDataField = isEmpty ? dataField : `['${dataField}']`;
|
|
335
|
+
api.writeTmpFile({
|
|
336
|
+
path: "request.ts",
|
|
337
|
+
content: import_plugin_utils.Mustache.render(requestTpl, {
|
|
338
|
+
umiRequestPath,
|
|
339
|
+
axiosPath,
|
|
340
|
+
formatResult,
|
|
341
|
+
resultDataType,
|
|
342
|
+
resultDataField
|
|
343
|
+
})
|
|
344
|
+
});
|
|
345
|
+
api.writeTmpFile({
|
|
346
|
+
path: "types.d.ts",
|
|
347
|
+
content: `
|
|
348
|
+
export type {
|
|
349
|
+
RequestConfig,
|
|
350
|
+
AxiosInstance,
|
|
351
|
+
AxiosRequestConfig,
|
|
352
|
+
AxiosResponse,
|
|
353
|
+
AxiosError,
|
|
354
|
+
RequestError,
|
|
355
|
+
RequestInterceptorAxios,
|
|
356
|
+
RequestInterceptorUmiRequest,
|
|
357
|
+
RequestInterceptor,
|
|
358
|
+
ErrorInterceptor,
|
|
359
|
+
ResponseInterceptor,
|
|
360
|
+
RequestOptions,
|
|
361
|
+
Request } from './request';
|
|
362
|
+
`
|
|
363
|
+
});
|
|
364
|
+
api.writeTmpFile({
|
|
365
|
+
path: "index.ts",
|
|
366
|
+
content: `
|
|
367
|
+
export {
|
|
368
|
+
useRequest,
|
|
369
|
+
UseRequestProvider,
|
|
370
|
+
request,
|
|
371
|
+
getRequestInstance,
|
|
372
|
+
} from './request';
|
|
373
|
+
`
|
|
374
|
+
});
|
|
375
|
+
api.writeTmpFile({
|
|
376
|
+
path: import_umi.RUNTIME_TYPE_FILE_NAME,
|
|
377
|
+
content: `
|
|
378
|
+
import type { RequestConfig } from './types.d'
|
|
379
|
+
export type IRuntimeConfig = {
|
|
380
|
+
request?: RequestConfig
|
|
381
|
+
};
|
|
382
|
+
`
|
|
383
|
+
});
|
|
384
|
+
});
|
|
5
385
|
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/styled-components.ts
|
|
30
|
+
var styled_components_exports = {};
|
|
31
|
+
__export(styled_components_exports, {
|
|
32
|
+
default: () => styled_components_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(styled_components_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_resolveProjectDep = require("./utils/resolveProjectDep");
|
|
38
|
+
var import_withTmpPath = require("./utils/withTmpPath");
|
|
39
|
+
var styled_components_default = (api) => {
|
|
40
|
+
api.describe({
|
|
41
|
+
key: "styledComponents",
|
|
42
|
+
config: {
|
|
43
|
+
schema({ zod }) {
|
|
44
|
+
return zod.object({
|
|
45
|
+
babelPlugin: zod.record(zod.any()).optional()
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
enableBy: api.EnableBy.config
|
|
50
|
+
});
|
|
51
|
+
api.modifyConfig((memo) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (api.userConfig.mako || process.env.OKAM) {
|
|
54
|
+
return memo;
|
|
55
|
+
}
|
|
56
|
+
const isProd = api.env === "production";
|
|
57
|
+
const pluginConfig = {
|
|
58
|
+
// https://github.com/styled-components/babel-plugin-styled-components/blob/f8e9fb480d1645be8be797d73e49686bdf98975b/src/utils/options.js#L11
|
|
59
|
+
topLevelImportPaths: [
|
|
60
|
+
"@umijs/max",
|
|
61
|
+
"@alipay/bigfish",
|
|
62
|
+
"umi",
|
|
63
|
+
"alita",
|
|
64
|
+
"@kmi/kmi"
|
|
65
|
+
],
|
|
66
|
+
...isProd ? {
|
|
67
|
+
displayName: false
|
|
68
|
+
} : {},
|
|
69
|
+
...((_a = api.config.styledComponents) == null ? void 0 : _a.babelPlugin) || {},
|
|
70
|
+
...((_b = api.userConfig.styledComponents) == null ? void 0 : _b.babelPlugin) || {}
|
|
71
|
+
};
|
|
72
|
+
memo.extraBabelPlugins = [
|
|
73
|
+
...memo.extraBabelPlugins || [],
|
|
74
|
+
[require.resolve("babel-plugin-styled-components"), pluginConfig]
|
|
75
|
+
];
|
|
76
|
+
return memo;
|
|
77
|
+
});
|
|
78
|
+
api.addRuntimePlugin(() => {
|
|
79
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
|
|
80
|
+
});
|
|
81
|
+
api.addRuntimePluginKey(() => {
|
|
82
|
+
return ["styledComponents"];
|
|
83
|
+
});
|
|
84
|
+
const SC_NAME = `styled-components`;
|
|
85
|
+
let libPath;
|
|
86
|
+
try {
|
|
87
|
+
libPath = (0, import_resolveProjectDep.resolveProjectDep)({
|
|
88
|
+
pkg: api.pkg,
|
|
89
|
+
cwd: api.cwd,
|
|
90
|
+
dep: SC_NAME
|
|
91
|
+
}) || (0, import_path.dirname)(require.resolve(`${SC_NAME}/package.json`));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
}
|
|
94
|
+
api.modifyConfig((memo) => {
|
|
95
|
+
memo.alias[SC_NAME] = libPath;
|
|
96
|
+
return memo;
|
|
97
|
+
});
|
|
98
|
+
api.onGenerateFiles(() => {
|
|
99
|
+
var _a, _b, _c;
|
|
100
|
+
api.writeTmpFile({
|
|
101
|
+
path: "index.tsx",
|
|
102
|
+
content: `
|
|
103
|
+
import styled, { ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme } from '${(0, import_utils.winPath)(
|
|
104
|
+
libPath
|
|
105
|
+
)}';
|
|
106
|
+
export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme };
|
|
107
|
+
`
|
|
108
|
+
});
|
|
109
|
+
const styledComponentsRuntimeCode = ((_a = api.appData.appJS) == null ? void 0 : _a.exports.includes(
|
|
110
|
+
"styledComponents"
|
|
111
|
+
)) ? `import { styledComponents as styledComponentsConfig } from '@/app';` : `const styledComponentsConfig = {};`;
|
|
112
|
+
const isLegacy = !import_utils.lodash.isEmpty((_b = api.config.targets) == null ? void 0 : _b.ie) || api.config.legacy;
|
|
113
|
+
const disableCSSOM = !!((_c = api.config.qiankun) == null ? void 0 : _c.slave);
|
|
114
|
+
const providerOptions = {
|
|
115
|
+
// https://styled-components.com/docs/faqs#vendor-prefixes-are-omitted-by-default
|
|
116
|
+
...isLegacy ? { enableVendorPrefixes: true } : {},
|
|
117
|
+
...disableCSSOM ? { disableCSSOMInjection: true } : {}
|
|
118
|
+
};
|
|
119
|
+
const hasProvider = !import_utils.lodash.isEmpty(providerOptions);
|
|
120
|
+
api.writeTmpFile({
|
|
121
|
+
path: "runtime.tsx",
|
|
122
|
+
content: `
|
|
123
|
+
import React from 'react';
|
|
124
|
+
${hasProvider ? `import { StyleSheetManager } from '${(0, import_utils.winPath)(libPath)}';` : ``}
|
|
125
|
+
|
|
126
|
+
${styledComponentsRuntimeCode}
|
|
127
|
+
export function rootContainer(container) {
|
|
128
|
+
const scConfig =
|
|
129
|
+
typeof styledComponentsConfig === 'function'
|
|
130
|
+
? styledComponentsConfig()
|
|
131
|
+
: styledComponentsConfig;
|
|
132
|
+
const globalStyle = scConfig.GlobalStyle ? <scConfig.GlobalStyle /> : null;
|
|
133
|
+
const inner = (
|
|
134
|
+
<>
|
|
135
|
+
{globalStyle}
|
|
136
|
+
{container}
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
${hasProvider ? `
|
|
140
|
+
return (
|
|
141
|
+
<StyleSheetManager {...${JSON.stringify(providerOptions)}}>
|
|
142
|
+
{inner}
|
|
143
|
+
</StyleSheetManager>
|
|
144
|
+
);
|
|
145
|
+
` : "return inner;"}
|
|
146
|
+
}
|
|
147
|
+
`
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
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/tailwindcss.ts
|
|
20
|
+
var tailwindcss_exports = {};
|
|
21
|
+
__export(tailwindcss_exports, {
|
|
22
|
+
default: () => tailwindcss_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(tailwindcss_exports);
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
28
|
+
var CHECK_INTERVAL = 300;
|
|
29
|
+
var CHECK_TIMEOUT_UNIT_SECOND = 5;
|
|
30
|
+
var tailwindcss_default = (api) => {
|
|
31
|
+
api.describe({
|
|
32
|
+
key: "tailwindcss",
|
|
33
|
+
config: {
|
|
34
|
+
schema({ zod }) {
|
|
35
|
+
return zod.record(zod.any());
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
enableBy: api.EnableBy.config
|
|
39
|
+
});
|
|
40
|
+
let tailwind = null;
|
|
41
|
+
const outputPath = "plugin-tailwindcss/tailwind.css";
|
|
42
|
+
api.onBeforeCompiler(() => {
|
|
43
|
+
const inputPath = (0, import_path.join)(api.cwd, "tailwind.css");
|
|
44
|
+
const generatedPath = (0, import_path.join)(api.paths.absTmpPath, outputPath);
|
|
45
|
+
const binPath = getTailwindBinPath({ cwd: api.cwd });
|
|
46
|
+
const configPath = (0, import_path.join)(api.cwd, "tailwind.config.js");
|
|
47
|
+
if (process.env.IS_UMI_BUILD_WORKER) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
tailwind = (0, import_plugin_utils.crossSpawn)(
|
|
52
|
+
`${binPath}`,
|
|
53
|
+
[
|
|
54
|
+
"-c",
|
|
55
|
+
configPath,
|
|
56
|
+
"-i",
|
|
57
|
+
inputPath,
|
|
58
|
+
"-o",
|
|
59
|
+
generatedPath,
|
|
60
|
+
api.env === "development" ? "--watch" : ""
|
|
61
|
+
],
|
|
62
|
+
{
|
|
63
|
+
stdio: "inherit",
|
|
64
|
+
cwd: process.env.APP_ROOT || api.cwd
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
tailwind.on("error", (m) => {
|
|
68
|
+
api.logger.error("tailwindcss service encounter an error: " + m);
|
|
69
|
+
});
|
|
70
|
+
if (api.env === "production") {
|
|
71
|
+
tailwind.on("exit", () => {
|
|
72
|
+
api.logger.info("tailwindcss service exited");
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
api.logger.info("tailwindcss service started");
|
|
77
|
+
const interval = setInterval(() => {
|
|
78
|
+
if ((0, import_fs.existsSync)(generatedPath)) {
|
|
79
|
+
clearInterval(interval);
|
|
80
|
+
resolve();
|
|
81
|
+
}
|
|
82
|
+
}, CHECK_INTERVAL);
|
|
83
|
+
const timer = setTimeout(() => {
|
|
84
|
+
if (!(0, import_fs.existsSync)(generatedPath)) {
|
|
85
|
+
clearInterval(timer);
|
|
86
|
+
api.logger.error(
|
|
87
|
+
`tailwindcss generate failed after ${CHECK_TIMEOUT_UNIT_SECOND} seconds, please check your tailwind.css and tailwind.config.js`
|
|
88
|
+
);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}, CHECK_TIMEOUT_UNIT_SECOND * 1e3);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
api.addEntryImports(() => {
|
|
96
|
+
const generatedPath = (0, import_plugin_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, outputPath));
|
|
97
|
+
return [{ source: generatedPath }];
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
function getTailwindBinPath(opts) {
|
|
101
|
+
const pkgPath = require.resolve("tailwindcss/package.json", {
|
|
102
|
+
paths: [opts.cwd]
|
|
103
|
+
});
|
|
104
|
+
const tailwindPath = require(pkgPath).bin["tailwind"];
|
|
105
|
+
return (0, import_path.join)((0, import_path.dirname)(pkgPath), tailwindPath);
|
|
106
|
+
}
|
package/dist/unocss.d.ts
ADDED