@umijs/plugins 4.0.7 → 4.0.8

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/access.js CHANGED
@@ -1,41 +1,57 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const path_1 = require("path");
8
- const withTmpPath_1 = require("./utils/withTmpPath");
9
- exports.default = (api) => {
10
- api.describe({
11
- config: {
12
- schema(joi) {
13
- return joi.object();
14
- },
15
- },
16
- enableBy: api.EnableBy.config,
17
- });
18
- api.onGenerateFiles(async () => {
19
- // allow enable access without access file
20
- const hasAccessFile = ['js', 'jsx', 'ts', 'tsx'].some((ext) => fs_1.default.existsSync((0, path_1.join)(api.paths.absSrcPath, `access.${ext}`)));
21
- // runtime.tsx
22
- api.writeTmpFile({
23
- path: 'runtime.tsx',
24
- content: `
25
- import React from 'react';${hasAccessFile
26
- ? `
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // access.ts
23
+ var access_exports = {};
24
+ __export(access_exports, {
25
+ default: () => access_default
26
+ });
27
+ module.exports = __toCommonJS(access_exports);
28
+ var import_fs = __toESM(require("fs"));
29
+ var import_path = require("path");
30
+ var import_withTmpPath = require("./utils/withTmpPath");
31
+ var access_default = (api) => {
32
+ api.describe({
33
+ config: {
34
+ schema(joi) {
35
+ return joi.object();
36
+ }
37
+ },
38
+ enableBy: api.EnableBy.config
39
+ });
40
+ api.onGenerateFiles(async () => {
41
+ const hasAccessFile = ["js", "jsx", "ts", "tsx"].some((ext) => import_fs.default.existsSync((0, import_path.join)(api.paths.absSrcPath, `access.${ext}`)));
42
+ api.writeTmpFile({
43
+ path: "runtime.tsx",
44
+ content: `
45
+ import React from 'react';${hasAccessFile ? `
27
46
  import accessFactory from '@/access'
28
47
  import { useModel } from '@@/plugin-model';
29
- `
30
- : ''}
48
+ ` : ""}
31
49
  import { AccessContext } from './context';
32
50
 
33
- function Provider(props) {${hasAccessFile
34
- ? `
51
+ function Provider(props) {${hasAccessFile ? `
35
52
  const { initialState } = useModel('@@initialState');
36
53
  const access = React.useMemo(() => accessFactory(initialState), [initialState]);
37
- `
38
- : `
54
+ ` : `
39
55
  const access = {};
40
56
  `}
41
57
  return (
@@ -48,12 +64,11 @@ function Provider(props) {${hasAccessFile
48
64
  export function accessProvider(container) {
49
65
  return <Provider>{ container }</Provider>;
50
66
  }
51
- `,
52
- });
53
- // index.tsx
54
- api.writeTmpFile({
55
- path: 'index.tsx',
56
- content: `
67
+ `
68
+ });
69
+ api.writeTmpFile({
70
+ path: "index.tsx",
71
+ content: `
57
72
  import React, { PropsWithChildren } from 'react';
58
73
  import { AccessContext } from './context';
59
74
  import type { IRoute } from 'umi';
@@ -81,7 +96,7 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
81
96
  const accessCode = route.access || parentAccessCode;
82
97
 
83
98
  // set default status
84
- route.unaccessible = ${api.config.access.strictMode ? 'true' : 'false'};
99
+ route.unaccessible = ${api.config.access.strictMode ? "true" : "false"};
85
100
 
86
101
  // check access code
87
102
  if (typeof accessCode === 'string') {
@@ -118,22 +133,23 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
118
133
 
119
134
  return markdedRoutes;
120
135
  }
121
- `,
122
- });
123
- // context.ts
124
- api.writeTmpFile({
125
- path: 'context.ts',
126
- content: `
136
+ `
137
+ });
138
+ api.writeTmpFile({
139
+ path: "context.ts",
140
+ content: `
127
141
  import React from 'react';
128
142
  export const AccessContext = React.createContext<any>(null);
129
- `,
130
- });
131
- });
132
- api.addRuntimePlugin(() => {
133
- return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
143
+ `
134
144
  });
135
- api.addTmpGenerateWatcherPaths(() => [
136
- (0, path_1.join)(api.paths.absSrcPath, 'access.ts'),
137
- (0, path_1.join)(api.paths.absSrcPath, 'access.js'),
138
- ]);
145
+ });
146
+ api.addRuntimePlugin(() => {
147
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
148
+ });
149
+ api.addTmpGenerateWatcherPaths(() => [
150
+ (0, import_path.join)(api.paths.absSrcPath, "access.ts"),
151
+ (0, import_path.join)(api.paths.absSrcPath, "access.js")
152
+ ]);
139
153
  };
154
+ // Annotate the CommonJS export names for ESM import in node:
155
+ 0 && (module.exports = {});
package/dist/analytics.js CHANGED
@@ -1,23 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (api) => {
4
- const GA_KEY = process.env.GA_KEY;
5
- const enableBy = (opts) => {
6
- return opts.config.analytics || GA_KEY;
7
- };
8
- api.describe({
9
- key: 'analytics',
10
- config: {
11
- schema(joi) {
12
- return joi.object();
13
- },
14
- onChange: api.ConfigChangeType.reload,
15
- },
16
- enableBy,
17
- });
18
- // https://tongji.baidu.com/web/help/article?id=174&type=0
19
- const baiduTpl = (code) => {
20
- return `
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
+ // analytics.ts
20
+ var analytics_exports = {};
21
+ __export(analytics_exports, {
22
+ default: () => analytics_default
23
+ });
24
+ module.exports = __toCommonJS(analytics_exports);
25
+ var analytics_default = (api) => {
26
+ const GA_KEY = process.env.GA_KEY;
27
+ const enableBy = (opts) => {
28
+ return opts.config.analytics || GA_KEY;
29
+ };
30
+ api.describe({
31
+ key: "analytics",
32
+ config: {
33
+ schema(joi) {
34
+ return joi.object();
35
+ },
36
+ onChange: api.ConfigChangeType.reload
37
+ },
38
+ enableBy
39
+ });
40
+ const baiduTpl = (code) => {
41
+ return `
21
42
  (function() {
22
43
  var hm = document.createElement('script');
23
44
  hm.src = '//hm.baidu.com/hm.js?${code}';
@@ -25,9 +46,9 @@ exports.default = (api) => {
25
46
  s.parentNode.insertBefore(hm, s);
26
47
  })();
27
48
  `;
28
- };
29
- const gaTpl = (code) => {
30
- return `
49
+ };
50
+ const gaTpl = (code) => {
51
+ return `
31
52
  (function(){
32
53
  if (!location.port) {
33
54
  (function (i, s, o, g, r, a, m) {
@@ -46,22 +67,22 @@ exports.default = (api) => {
46
67
  }
47
68
  })();
48
69
  `;
49
- };
50
- api.addHTMLHeadScripts(() => {
51
- const { analytics = {} } = api.config;
52
- const { ga = GA_KEY, baidu } = analytics;
53
- return [
54
- baidu && {
55
- content: 'var _hmt = _hmt || [];',
56
- },
57
- api.env !== 'development' &&
58
- baidu && {
59
- content: baiduTpl(baidu),
60
- },
61
- api.env !== 'development' &&
62
- ga && {
63
- content: gaTpl(ga),
64
- },
65
- ].filter(Boolean);
66
- });
70
+ };
71
+ api.addHTMLHeadScripts(() => {
72
+ const { analytics = {} } = api.config;
73
+ const { ga = GA_KEY, baidu } = analytics;
74
+ return [
75
+ baidu && {
76
+ content: "var _hmt = _hmt || [];"
77
+ },
78
+ api.env !== "development" && baidu && {
79
+ content: baiduTpl(baidu)
80
+ },
81
+ api.env !== "development" && ga && {
82
+ content: gaTpl(ga)
83
+ }
84
+ ].filter(Boolean);
85
+ });
67
86
  };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {});
package/dist/antd.js CHANGED
@@ -1,109 +1,128 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const plugin_utils_1 = require("umi/plugin-utils");
5
- const resolveProjectDep_1 = require("./utils/resolveProjectDep");
6
- const withTmpPath_1 = require("./utils/withTmpPath");
7
- exports.default = (api) => {
8
- let pkgPath;
9
- try {
10
- pkgPath =
11
- (0, resolveProjectDep_1.resolveProjectDep)({
12
- pkg: api.pkg,
13
- cwd: api.cwd,
14
- dep: 'antd',
15
- }) || (0, path_1.dirname)(require.resolve('antd/package.json'));
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
16
18
  }
17
- catch (e) { }
18
- api.describe({
19
- config: {
20
- schema(Joi) {
21
- return Joi.object({
22
- configProvider: Joi.object(),
23
- // themes
24
- dark: Joi.boolean(),
25
- compact: Joi.boolean(),
26
- // babel-plugin-import
27
- import: Joi.boolean(),
28
- // less or css, default less
29
- style: Joi.string().allow('less', 'css'),
30
- });
31
- },
32
- },
33
- enableBy({ userConfig }) {
34
- // 由于本插件有 api.modifyConfig 的调用,以及 Umi 框架的限制
35
- // 在其他插件中通过 api.modifyDefaultConfig 设置 antd 并不能让 api.modifyConfig 生效
36
- // 所以这里通过环境变量来判断是否启用
37
- return process.env.UMI_PLUGIN_ANTD_ENABLE || userConfig.antd;
38
- },
39
- });
40
- function checkPkgPath() {
41
- if (!pkgPath) {
42
- throw new Error(`Can't find antd package. Please install antd first.`);
43
- }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // antd.ts
37
+ var antd_exports = {};
38
+ __export(antd_exports, {
39
+ default: () => antd_default
40
+ });
41
+ module.exports = __toCommonJS(antd_exports);
42
+ var import_path = require("path");
43
+ var import_plugin_utils = require("umi/plugin-utils");
44
+ var import_resolveProjectDep = require("./utils/resolveProjectDep");
45
+ var import_withTmpPath = require("./utils/withTmpPath");
46
+ var antd_default = (api) => {
47
+ let pkgPath;
48
+ try {
49
+ pkgPath = (0, import_resolveProjectDep.resolveProjectDep)({
50
+ pkg: api.pkg,
51
+ cwd: api.cwd,
52
+ dep: "antd"
53
+ }) || (0, import_path.dirname)(require.resolve("antd/package.json"));
54
+ } catch (e) {
55
+ }
56
+ api.describe({
57
+ config: {
58
+ schema(Joi) {
59
+ return Joi.object({
60
+ configProvider: Joi.object(),
61
+ dark: Joi.boolean(),
62
+ compact: Joi.boolean(),
63
+ import: Joi.boolean(),
64
+ style: Joi.string().allow("less", "css")
65
+ });
66
+ }
67
+ },
68
+ enableBy({ userConfig }) {
69
+ return process.env.UMI_PLUGIN_ANTD_ENABLE || userConfig.antd;
44
70
  }
45
- api.modifyAppData((memo) => {
46
- checkPkgPath();
47
- const version = require(`${pkgPath}/package.json`).version;
48
- memo.antd = {
49
- pkgPath,
50
- version,
51
- };
52
- return memo;
53
- });
54
- api.modifyConfig((memo) => {
55
- checkPkgPath();
56
- const antd = memo.antd || {};
57
- // defaultConfig 的取值在 config 之后,所以改用环境变量传默认值
58
- if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
59
- const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
60
- Object.assign(antd, defaultConfig);
61
- }
62
- // antd import
63
- memo.alias.antd = pkgPath;
64
- // moment > dayjs
65
- if (antd.dayjs) {
66
- memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
67
- }
68
- // dark mode & compact mode
69
- if (antd.dark || antd.compact) {
70
- const { getThemeVariables } = require('antd/dist/theme');
71
- memo.theme = {
72
- ...getThemeVariables(antd),
73
- ...memo.theme,
74
- };
75
- }
76
- // antd theme
77
- memo.theme = {
78
- 'root-entry-name': 'default',
79
- ...memo.theme,
80
- };
81
- return memo;
82
- });
83
- // babel-plugin-import
84
- api.addExtraBabelPlugins(() => {
85
- const style = api.config.antd.style || 'less';
86
- return api.config.antd.import && !api.appData.vite
87
- ? [
88
- [
89
- require.resolve('babel-plugin-import'),
90
- {
91
- libraryName: 'antd',
92
- libraryDirectory: 'es',
93
- style: style === 'less' ? true : 'css',
94
- },
95
- 'antd',
96
- ],
97
- ]
98
- : [];
99
- });
100
- // antd config provider
101
- api.onGenerateFiles(() => {
102
- if (!api.config.antd.configProvider)
103
- return;
104
- api.writeTmpFile({
105
- path: `runtime.tsx`,
106
- content: plugin_utils_1.Mustache.render(`
71
+ });
72
+ function checkPkgPath() {
73
+ if (!pkgPath) {
74
+ throw new Error(`Can't find antd package. Please install antd first.`);
75
+ }
76
+ }
77
+ api.modifyAppData((memo) => {
78
+ checkPkgPath();
79
+ const version = require(`${pkgPath}/package.json`).version;
80
+ memo.antd = {
81
+ pkgPath,
82
+ version
83
+ };
84
+ return memo;
85
+ });
86
+ api.modifyConfig((memo) => {
87
+ checkPkgPath();
88
+ const antd = memo.antd || {};
89
+ if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
90
+ const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
91
+ Object.assign(antd, defaultConfig);
92
+ }
93
+ memo.alias.antd = pkgPath;
94
+ if (antd.dayjs) {
95
+ memo.alias.moment = (0, import_path.dirname)(require.resolve("dayjs/package.json"));
96
+ }
97
+ if (antd.dark || antd.compact) {
98
+ const { getThemeVariables } = require("antd/dist/theme");
99
+ memo.theme = __spreadValues(__spreadValues({}, getThemeVariables(antd)), memo.theme);
100
+ }
101
+ memo.theme = __spreadValues({
102
+ "root-entry-name": "default"
103
+ }, memo.theme);
104
+ return memo;
105
+ });
106
+ api.addExtraBabelPlugins(() => {
107
+ const style = api.config.antd.style || "less";
108
+ return api.config.antd.import && !api.appData.vite ? [
109
+ [
110
+ require.resolve("babel-plugin-import"),
111
+ {
112
+ libraryName: "antd",
113
+ libraryDirectory: "es",
114
+ style: style === "less" ? true : "css"
115
+ },
116
+ "antd"
117
+ ]
118
+ ] : [];
119
+ });
120
+ api.onGenerateFiles(() => {
121
+ if (!api.config.antd.configProvider)
122
+ return;
123
+ api.writeTmpFile({
124
+ path: `runtime.tsx`,
125
+ content: import_plugin_utils.Mustache.render(`
107
126
  import React from 'react';
108
127
  import { ConfigProvider, Modal, message, notification } from 'antd';
109
128
 
@@ -123,24 +142,21 @@ export function rootContainer(container) {
123
142
  return <ConfigProvider {...finalConfig}>{container}</ConfigProvider>;
124
143
  }
125
144
  `.trim(), {
126
- config: JSON.stringify(api.config.antd.configProvider),
127
- }),
128
- });
129
- });
130
- api.addRuntimePlugin(() => {
131
- return api.config.antd.configProvider
132
- ? [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]
133
- : [];
134
- });
135
- // import antd style if antd.import is not configured
136
- api.addEntryImportsAhead(() => {
137
- const style = api.config.antd.style || 'less';
138
- return api.config.antd.import && !api.appData.vite
139
- ? []
140
- : [
141
- {
142
- source: style === 'less' ? 'antd/dist/antd.less' : 'antd/dist/antd.css',
143
- },
144
- ];
145
+ config: JSON.stringify(api.config.antd.configProvider)
146
+ })
145
147
  });
148
+ });
149
+ api.addRuntimePlugin(() => {
150
+ return api.config.antd.configProvider ? [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })] : [];
151
+ });
152
+ api.addEntryImportsAhead(() => {
153
+ const style = api.config.antd.style || "less";
154
+ return api.config.antd.import && !api.appData.vite ? [] : [
155
+ {
156
+ source: style === "less" ? "antd/dist/antd.less" : "antd/dist/antd.css"
157
+ }
158
+ ];
159
+ });
146
160
  };
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {});