umi 4.0.5 → 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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ // requireHook.ts
2
+ var import_path = require("path");
3
+ var hookPropertyMap = /* @__PURE__ */ new Map([
4
+ ["umi", (0, import_path.join)(__dirname, "../index.js")],
5
+ ["umi/plugin-utils", (0, import_path.join)(__dirname, "../../plugin-utils.js")]
6
+ ]);
7
+ var mod = require("module");
8
+ var resolveFilename = mod._resolveFilename;
9
+ mod._resolveFilename = function(request, parent, isMain, options) {
10
+ const hookResolved = hookPropertyMap.get(request);
11
+ if (hookResolved)
12
+ request = hookResolved;
13
+ return resolveFilename.call(mod, request, parent, isMain, options);
14
+ };
@@ -1,39 +1,80 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Service = void 0;
4
- const core_1 = require("@umijs/core");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- const constants_1 = require("../constants");
8
- const cwd_1 = require("./cwd");
9
- class Service extends core_1.Service {
10
- constructor(opts) {
11
- process.env.UMI_DIR = (0, path_1.dirname)(require.resolve('../../package'));
12
- const cwd = (0, cwd_1.getCwd)();
13
- super({
14
- ...opts,
15
- env: process.env.NODE_ENV,
16
- cwd,
17
- defaultConfigFiles: constants_1.DEFAULT_CONFIG_FILES,
18
- frameworkName: constants_1.FRAMEWORK_NAME,
19
- presets: [require.resolve('@umijs/preset-umi'), ...((opts === null || opts === void 0 ? void 0 : opts.presets) || [])],
20
- plugins: [
21
- (0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.ts')) && (0, path_1.join)(cwd, 'plugin.ts'),
22
- (0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.js')) && (0, path_1.join)(cwd, 'plugin.js'),
23
- ].filter(Boolean),
24
- });
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
25
20
  }
26
- async run2(opts) {
27
- let name = opts.name;
28
- if ((opts === null || opts === void 0 ? void 0 : opts.args.version) || name === 'v') {
29
- name = 'version';
30
- }
31
- else if ((opts === null || opts === void 0 ? void 0 : opts.args.help) || !name || name === 'h') {
32
- name = 'help';
33
- }
34
- // TODO
35
- // initWebpack
36
- return await this.run({ ...opts, name });
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ 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));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // service.ts
40
+ var service_exports = {};
41
+ __export(service_exports, {
42
+ Service: () => Service
43
+ });
44
+ module.exports = __toCommonJS(service_exports);
45
+ var import_core = require("@umijs/core");
46
+ var import_fs = require("fs");
47
+ var import_path = require("path");
48
+ var import_constants = require("../constants");
49
+ var import_cwd = require("./cwd");
50
+ var Service = class extends import_core.Service {
51
+ constructor(opts) {
52
+ process.env.UMI_DIR = (0, import_path.dirname)(require.resolve("../../package"));
53
+ const cwd = (0, import_cwd.getCwd)();
54
+ require("./requireHook");
55
+ super(__spreadProps(__spreadValues({}, opts), {
56
+ env: process.env.NODE_ENV,
57
+ cwd,
58
+ defaultConfigFiles: import_constants.DEFAULT_CONFIG_FILES,
59
+ frameworkName: import_constants.FRAMEWORK_NAME,
60
+ presets: [require.resolve("@umijs/preset-umi"), ...(opts == null ? void 0 : opts.presets) || []],
61
+ plugins: [
62
+ (0, import_fs.existsSync)((0, import_path.join)(cwd, "plugin.ts")) && (0, import_path.join)(cwd, "plugin.ts"),
63
+ (0, import_fs.existsSync)((0, import_path.join)(cwd, "plugin.js")) && (0, import_path.join)(cwd, "plugin.js")
64
+ ].filter(Boolean)
65
+ }));
66
+ }
67
+ async run2(opts) {
68
+ let name = opts.name;
69
+ if ((opts == null ? void 0 : opts.args.version) || name === "v") {
70
+ name = "version";
71
+ } else if ((opts == null ? void 0 : opts.args.help) || !name || name === "h") {
72
+ name = "help";
37
73
  }
38
- }
39
- exports.Service = Service;
74
+ return await this.run(__spreadProps(__spreadValues({}, opts), { name }));
75
+ }
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ Service
80
+ });
package/dist/test.js CHANGED
@@ -1,67 +1,77 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
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;
15
16
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.configUmiAlias = exports.getUmiAlias = exports.getAliasPathWithKey = void 0;
18
- const fs_1 = require("fs");
19
- const service_1 = require("./service/service");
20
- __exportStar(require("@umijs/test"), exports);
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // test.ts
21
+ var test_exports = {};
22
+ __export(test_exports, {
23
+ configUmiAlias: () => configUmiAlias,
24
+ getAliasPathWithKey: () => getAliasPathWithKey,
25
+ getUmiAlias: () => getUmiAlias
26
+ });
27
+ module.exports = __toCommonJS(test_exports);
28
+ var import_fs = require("fs");
29
+ var import_service = require("./service/service");
30
+ __reExport(test_exports, require("@umijs/test"), module.exports);
21
31
  function getAliasPathWithKey(alias, key) {
22
- if (alias[key]) {
23
- return getAliasPathWithKey(alias, alias[key]);
24
- }
25
- const aliasKeys = Object.keys(alias);
26
- const keyStartedWith = aliasKeys.find((k) => !k.endsWith('$') && key.startsWith(`${k}/`));
27
- if (keyStartedWith) {
28
- const realPath = alias[keyStartedWith];
29
- const newKey = realPath + key.slice(keyStartedWith.length);
30
- return getAliasPathWithKey(alias, newKey);
31
- }
32
- else {
33
- return key;
34
- }
32
+ if (alias[key]) {
33
+ return getAliasPathWithKey(alias, alias[key]);
34
+ }
35
+ const aliasKeys = Object.keys(alias);
36
+ const keyStartedWith = aliasKeys.find((k) => !k.endsWith("$") && key.startsWith(`${k}/`));
37
+ if (keyStartedWith) {
38
+ const realPath = alias[keyStartedWith];
39
+ const newKey = realPath + key.slice(keyStartedWith.length);
40
+ return getAliasPathWithKey(alias, newKey);
41
+ } else {
42
+ return key;
43
+ }
35
44
  }
36
- exports.getAliasPathWithKey = getAliasPathWithKey;
37
- let service;
45
+ var service;
38
46
  async function getUmiAlias() {
39
- if (!service) {
40
- service = new service_1.Service();
41
- await service.run2({
42
- name: 'setup',
43
- args: { quiet: true },
44
- });
45
- }
46
- return service.config.alias;
47
+ if (!service) {
48
+ service = new import_service.Service();
49
+ await service.run2({
50
+ name: "setup",
51
+ args: { quiet: true }
52
+ });
53
+ }
54
+ return service.config.alias;
47
55
  }
48
- exports.getUmiAlias = getUmiAlias;
49
56
  async function configUmiAlias(config) {
50
- config.moduleNameMapper || (config.moduleNameMapper = {});
51
- const alias = await getUmiAlias();
52
- for (const key of Object.keys(alias)) {
53
- const aliasPath = getAliasPathWithKey(alias, key);
54
- if (key.endsWith('$')) {
55
- config.moduleNameMapper[`^${key}`] = aliasPath;
56
- }
57
- else if ((0, fs_1.existsSync)(aliasPath) && (0, fs_1.statSync)(aliasPath).isDirectory()) {
58
- config.moduleNameMapper[`^${key}/(.*)$`] = `${aliasPath}/$1`;
59
- config.moduleNameMapper[`^${key}$`] = aliasPath;
60
- }
61
- else {
62
- config.moduleNameMapper[`^${key}$`] = aliasPath;
63
- }
57
+ config.moduleNameMapper || (config.moduleNameMapper = {});
58
+ const alias = await getUmiAlias();
59
+ for (const key of Object.keys(alias)) {
60
+ const aliasPath = getAliasPathWithKey(alias, key);
61
+ if (key.endsWith("$")) {
62
+ config.moduleNameMapper[`^${key}`] = aliasPath;
63
+ } else if ((0, import_fs.existsSync)(aliasPath) && (0, import_fs.statSync)(aliasPath).isDirectory()) {
64
+ config.moduleNameMapper[`^${key}/(.*)$`] = `${aliasPath}/$1`;
65
+ config.moduleNameMapper[`^${key}$`] = aliasPath;
66
+ } else {
67
+ config.moduleNameMapper[`^${key}$`] = aliasPath;
64
68
  }
65
- return config;
69
+ }
70
+ return config;
66
71
  }
67
- exports.configUmiAlias = configUmiAlias;
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ configUmiAlias,
75
+ getAliasPathWithKey,
76
+ getUmiAlias
77
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umi",
3
- "version": "4.0.5",
3
+ "version": "4.0.8",
4
4
  "description": "umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -30,23 +30,22 @@
30
30
  "stylelint.js"
31
31
  ],
32
32
  "scripts": {
33
- "build": "pnpm tsc",
34
- "build:client": "pnpm tsc --project ./tsconfig.client.json",
33
+ "build": "pnpm father build",
35
34
  "build:deps": "umi-scripts bundleDeps",
36
- "dev": "pnpm build --watch",
37
- "dev:client": "pnpm build:client -- --watch",
35
+ "dev": "pnpm father dev",
38
36
  "test": "umi-scripts jest-turbo"
39
37
  },
40
38
  "dependencies": {
41
- "@umijs/bundler-utils": "4.0.5",
42
- "@umijs/bundler-webpack": "4.0.5",
43
- "@umijs/core": "4.0.5",
44
- "@umijs/lint": "4.0.5",
45
- "@umijs/preset-umi": "4.0.5",
46
- "@umijs/renderer-react": "4.0.5",
47
- "@umijs/server": "4.0.5",
48
- "@umijs/test": "4.0.5",
49
- "@umijs/utils": "4.0.5",
39
+ "@babel/runtime": "7.17.9",
40
+ "@umijs/bundler-utils": "4.0.8",
41
+ "@umijs/bundler-webpack": "4.0.8",
42
+ "@umijs/core": "4.0.8",
43
+ "@umijs/lint": "4.0.8",
44
+ "@umijs/preset-umi": "4.0.8",
45
+ "@umijs/renderer-react": "4.0.8",
46
+ "@umijs/server": "4.0.8",
47
+ "@umijs/test": "4.0.8",
48
+ "@umijs/utils": "4.0.8",
50
49
  "prettier-plugin-organize-imports": "^2.3.4",
51
50
  "prettier-plugin-packagejson": "^2.2.17"
52
51
  },
@@ -1 +0,0 @@
1
- export declare function printHelp(): void;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printHelp = void 0;
4
- const utils_1 = require("@umijs/utils");
5
- function printHelp() {
6
- utils_1.logger.fatal('A complete log of this run can be found in:');
7
- utils_1.logger.fatal(utils_1.logger.getLatestLogFilePath());
8
- utils_1.logger.fatal('Consider reporting a GitHub issue on https://github.com/umijs/umi/issues');
9
- }
10
- exports.printHelp = printHelp;
@@ -1,34 +0,0 @@
1
- export declare enum ApplyPluginsType {
2
- compose = "compose",
3
- modify = "modify",
4
- event = "event"
5
- }
6
- interface IPlugin {
7
- path?: string;
8
- apply: Record<string, any>;
9
- }
10
- export declare class PluginManager {
11
- opts: {
12
- validKeys: string[];
13
- };
14
- hooks: {
15
- [key: string]: any;
16
- };
17
- constructor(opts: {
18
- validKeys: string[];
19
- });
20
- register(plugin: IPlugin): void;
21
- getHooks(keyWithDot: string): any;
22
- applyPlugins({ key, type, initialValue, args, async, }: {
23
- key: string;
24
- type: ApplyPluginsType;
25
- initialValue?: any;
26
- args?: object;
27
- async?: boolean;
28
- }): any;
29
- static create(opts: {
30
- validKeys: string[];
31
- plugins: IPlugin[];
32
- }): PluginManager;
33
- }
34
- export {};
@@ -1,124 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginManager = exports.ApplyPluginsType = void 0;
4
- const utils_1 = require("./utils");
5
- var ApplyPluginsType;
6
- (function (ApplyPluginsType) {
7
- ApplyPluginsType["compose"] = "compose";
8
- ApplyPluginsType["modify"] = "modify";
9
- ApplyPluginsType["event"] = "event";
10
- })(ApplyPluginsType = exports.ApplyPluginsType || (exports.ApplyPluginsType = {}));
11
- class PluginManager {
12
- constructor(opts) {
13
- this.hooks = {};
14
- this.opts = opts;
15
- }
16
- register(plugin) {
17
- (0, utils_1.assert)(plugin.apply, `plugin register failed, apply must supplied`);
18
- Object.keys(plugin.apply).forEach((key) => {
19
- (0, utils_1.assert)(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} ${plugin.path ? `from plugin ${plugin.path}` : ''}.`);
20
- this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
21
- });
22
- }
23
- getHooks(keyWithDot) {
24
- const [key, ...memberKeys] = keyWithDot.split('.');
25
- let hooks = this.hooks[key] || [];
26
- if (memberKeys.length) {
27
- hooks = hooks
28
- .map((hook) => {
29
- try {
30
- let ret = hook;
31
- for (const memberKey of memberKeys) {
32
- ret = ret[memberKey];
33
- }
34
- return ret;
35
- }
36
- catch (e) {
37
- return null;
38
- }
39
- })
40
- .filter(Boolean);
41
- }
42
- return hooks;
43
- }
44
- applyPlugins({ key, type, initialValue, args, async, }) {
45
- const hooks = this.getHooks(key) || [];
46
- if (args) {
47
- (0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
48
- }
49
- if (async) {
50
- (0, utils_1.assert)(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
51
- }
52
- switch (type) {
53
- case ApplyPluginsType.modify:
54
- if (async) {
55
- return hooks.reduce(async (memo, hook) => {
56
- (0, utils_1.assert)(typeof hook === 'function' ||
57
- typeof hook === 'object' ||
58
- (0, utils_1.isPromiseLike)(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
59
- if ((0, utils_1.isPromiseLike)(memo)) {
60
- memo = await memo;
61
- }
62
- if (typeof hook === 'function') {
63
- const ret = hook(memo, args);
64
- if ((0, utils_1.isPromiseLike)(ret)) {
65
- return await ret;
66
- }
67
- else {
68
- return ret;
69
- }
70
- }
71
- else {
72
- if ((0, utils_1.isPromiseLike)(hook)) {
73
- hook = await hook;
74
- }
75
- return { ...memo, ...hook };
76
- }
77
- }, (0, utils_1.isPromiseLike)(initialValue)
78
- ? initialValue
79
- : Promise.resolve(initialValue));
80
- }
81
- else {
82
- return hooks.reduce((memo, hook) => {
83
- (0, utils_1.assert)(typeof hook === 'function' || typeof hook === 'object', `applyPlugins failed, all hooks for key ${key} must be function or plain object.`);
84
- if (typeof hook === 'function') {
85
- return hook(memo, args);
86
- }
87
- else {
88
- // TODO: deepmerge?
89
- return { ...memo, ...hook };
90
- }
91
- }, initialValue);
92
- }
93
- case ApplyPluginsType.event:
94
- return (async () => {
95
- for (const hook of hooks) {
96
- (0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
97
- const ret = hook(args);
98
- if (async && (0, utils_1.isPromiseLike)(ret)) {
99
- await ret;
100
- }
101
- }
102
- })();
103
- case ApplyPluginsType.compose:
104
- return () => {
105
- return (0, utils_1.compose)({
106
- fns: hooks.concat(initialValue),
107
- args,
108
- })();
109
- };
110
- }
111
- }
112
- static create(opts) {
113
- const pluginManager = new PluginManager({
114
- validKeys: opts.validKeys,
115
- });
116
- opts.plugins.forEach((plugin) => {
117
- pluginManager.register(plugin);
118
- });
119
- return pluginManager;
120
- }
121
- }
122
- exports.PluginManager = PluginManager;
123
- // plugins meta info (in tmp file)
124
- // hooks api: usePlugin
@@ -1,6 +0,0 @@
1
- export declare function assert(value: unknown, message: string): void;
2
- export declare function compose({ fns, args, }: {
3
- fns: (Function | any)[];
4
- args?: object;
5
- }): any;
6
- export declare function isPromiseLike(obj: any): boolean;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPromiseLike = exports.compose = exports.assert = void 0;
4
- function assert(value, message) {
5
- if (!value)
6
- throw new Error(message);
7
- }
8
- exports.assert = assert;
9
- function compose({ fns, args, }) {
10
- if (fns.length === 1) {
11
- return fns[0];
12
- }
13
- const last = fns.pop();
14
- return fns.reduce((a, b) => () => b(a, args), last);
15
- }
16
- exports.compose = compose;
17
- function isPromiseLike(obj) {
18
- return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
19
- }
20
- exports.isPromiseLike = isPromiseLike;