@umijs/core 4.0.0-rc.1 → 4.0.0-rc.10
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/compiled/dotenv/index.js +1 -1
- package/compiled/dotenv/lib/main.d.ts +73 -0
- package/compiled/dotenv/package.json +1 -1
- package/compiled/just-diff/index.js +1 -1
- package/dist/index.js +5 -1
- package/dist/route/defineRoutes.js +6 -3
- package/dist/route/route.js +5 -1
- package/dist/route/routesConfig.js +10 -0
- package/dist/service/generatePlugin.js +3 -6
- package/dist/service/generator.d.ts +2 -13
- package/dist/service/path.d.ts +1 -0
- package/dist/service/path.js +2 -0
- package/dist/service/plugin.d.ts +4 -0
- package/dist/service/plugin.js +5 -4
- package/dist/service/pluginAPI.d.ts +1 -1
- package/dist/service/pluginAPI.js +13 -4
- package/dist/service/service.d.ts +4 -0
- package/dist/service/service.js +53 -21
- package/dist/types.d.ts +1 -0
- package/package.json +8 -7
package/compiled/dotenv/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var e={
|
|
1
|
+
(function(){var e={875:function(e,r,n){const o=n(147);const t=n(17);const s=n(37);const i=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;function parse(e){const r={};let n=e.toString();n=n.replace(/\r\n?/gm,"\n");let o;while((o=i.exec(n))!=null){const e=o[1];let n=o[2]||"";n=n.trim();const t=n[0];n=n.replace(/^(['"`])([\s\S]*)\1$/gm,"$2");if(t==='"'){n=n.replace(/\\n/g,"\n");n=n.replace(/\\r/g,"\r")}r[e]=n}return r}function _log(e){console.log(`[dotenv][DEBUG] ${e}`)}function _resolveHome(e){return e[0]==="~"?t.join(s.homedir(),e.slice(1)):e}function config(e){let r=t.resolve(process.cwd(),".env");let n="utf8";const s=Boolean(e&&e.debug);const i=Boolean(e&&e.override);if(e){if(e.path!=null){r=_resolveHome(e.path)}if(e.encoding!=null){n=e.encoding}}try{const e=c.parse(o.readFileSync(r,{encoding:n}));Object.keys(e).forEach((function(r){if(!Object.prototype.hasOwnProperty.call(process.env,r)){process.env[r]=e[r]}else{if(i===true){process.env[r]=e[r]}if(s){if(i===true){_log(`"${r}" is already defined in \`process.env\` and WAS overwritten`)}else{_log(`"${r}" is already defined in \`process.env\` and was NOT overwritten`)}}}}));return{parsed:e}}catch(e){if(s){_log(`Failed to load ${r} ${e.message}`)}return{error:e}}}const c={config:config,parse:parse};e.exports.config=c.config;e.exports.parse=c.parse;e.exports=c},147:function(e){"use strict";e.exports=require("fs")},37:function(e){"use strict";e.exports=require("os")},17:function(e){"use strict";e.exports=require("path")}};var r={};function __nccwpck_require__(n){var o=r[n];if(o!==undefined){return o.exports}var t=r[n]={exports:{}};var s=true;try{e[n](t,t.exports,__nccwpck_require__);s=false}finally{if(s)delete r[n]}return t.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n=__nccwpck_require__(875);module.exports=n})();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// TypeScript Version: 3.0
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
|
|
4
|
+
export interface DotenvParseOutput {
|
|
5
|
+
[name: string]: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parses a string or buffer in the .env file format into an object.
|
|
10
|
+
*
|
|
11
|
+
* See https://docs.dotenv.org
|
|
12
|
+
*
|
|
13
|
+
* @param src - contents to be parsed. example: `'DB_HOST=localhost'`
|
|
14
|
+
* @param options - additional options. example: `{ debug: true }`
|
|
15
|
+
* @returns an object with keys and values based on `src`. example: `{ DB_HOST : 'localhost' }`
|
|
16
|
+
*/
|
|
17
|
+
export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
|
|
18
|
+
src: string | Buffer
|
|
19
|
+
): T;
|
|
20
|
+
|
|
21
|
+
export interface DotenvConfigOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Default: `path.resolve(process.cwd(), '.env')`
|
|
24
|
+
*
|
|
25
|
+
* Specify a custom path if your file containing environment variables is located elsewhere.
|
|
26
|
+
*
|
|
27
|
+
* example: `require('dotenv').config({ path: '/custom/path/to/.env' })`
|
|
28
|
+
*/
|
|
29
|
+
path?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Default: `utf8`
|
|
33
|
+
*
|
|
34
|
+
* Specify the encoding of your file containing environment variables.
|
|
35
|
+
*
|
|
36
|
+
* example: `require('dotenv').config({ encoding: 'latin1' })`
|
|
37
|
+
*/
|
|
38
|
+
encoding?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Default: `false`
|
|
42
|
+
*
|
|
43
|
+
* Turn on logging to help debug why certain keys or values are not being set as you expect.
|
|
44
|
+
*
|
|
45
|
+
* example: `require('dotenv').config({ debug: process.env.DEBUG })`
|
|
46
|
+
*/
|
|
47
|
+
debug?: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Default: `false`
|
|
51
|
+
*
|
|
52
|
+
* Override any environment variables that have already been set on your machine with values from your .env file.
|
|
53
|
+
*
|
|
54
|
+
* example: `require('dotenv').config({ override: true })`
|
|
55
|
+
*/
|
|
56
|
+
override?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DotenvConfigOutput {
|
|
60
|
+
error?: Error;
|
|
61
|
+
parsed?: DotenvParseOutput;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Loads `.env` file contents into process.env.
|
|
66
|
+
*
|
|
67
|
+
* See https://docs.dotenv.org
|
|
68
|
+
*
|
|
69
|
+
* @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
|
|
70
|
+
* @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"dotenv","license":"BSD-2-Clause","types":"
|
|
1
|
+
{"name":"dotenv","license":"BSD-2-Clause","types":"lib/main.d.ts"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var e={
|
|
1
|
+
(function(){var e={277:function(e){e.exports={diff:diff,jsonPatchPathConverter:jsonPatchPathConverter};function diff(e,r,t){if(!e||typeof e!="object"||!r||typeof r!="object"){throw new Error("both arguments must be objects or arrays")}t||(t=function(e){return e});function getDiff(e,r,a,n){var o=Object.keys(e);var c=o.length;var i=Object.keys(r);var f=i.length;var u;for(var p=0;p<c;p++){var s=Array.isArray(e)?Number(o[p]):o[p];if(!(s in r)){u=a.concat(s);n.remove.push({op:"remove",path:t(u)})}}for(var p=0;p<f;p++){var s=Array.isArray(r)?Number(i[p]):i[p];var v=e[s];var _=r[s];if(!(s in e)){u=a.concat(s);var h=r[s];n.add.push({op:"add",path:t(u),value:h})}else if(v!==_){if(Object(v)!==v||Object(_)!==_){u=pushReplace(u,a,s,n,t,r)}else{if(!Object.keys(v).length&&!Object.keys(_).length&&String(v)!=String(_)){u=pushReplace(u,a,s,n,t,r)}else{getDiff(e[s],r[s],a.concat(s),n)}}}}return n.remove.reverse().concat(n.replace).concat(n.add)}return getDiff(e,r,[],{remove:[],replace:[],add:[]})}function pushReplace(e,r,t,a,n,o){e=r.concat(t);a.replace.push({op:"replace",path:n(e),value:o[t]});return e}function jsonPatchPathConverter(e){return[""].concat(e).join("/")}}};var r={};function __nccwpck_require__(t){var a=r[t];if(a!==undefined){return a.exports}var n=r[t]={exports:{}};var o=true;try{e[t](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(277);module.exports=t})();
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -7,13 +7,16 @@ function defineRoutes(callback) {
|
|
|
7
7
|
const parentRoutes = [];
|
|
8
8
|
const defineRoute = (opts) => {
|
|
9
9
|
opts.options = opts.options || {};
|
|
10
|
+
const parentRoute = parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1] : null;
|
|
11
|
+
const parentId = parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.id;
|
|
12
|
+
const parentAbsPath = parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.absPath;
|
|
13
|
+
const absPath = [parentAbsPath, opts.path].join('/');
|
|
10
14
|
const route = {
|
|
11
15
|
path: opts.path || '/',
|
|
12
16
|
id: (0, utils_1.createRouteId)(opts.file),
|
|
13
|
-
parentId
|
|
14
|
-
? parentRoutes[parentRoutes.length - 1].id
|
|
15
|
-
: undefined,
|
|
17
|
+
parentId,
|
|
16
18
|
file: opts.file,
|
|
19
|
+
absPath,
|
|
17
20
|
};
|
|
18
21
|
routes[route.id] = route;
|
|
19
22
|
if (opts.children) {
|
package/dist/route/route.js
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
// programming route
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
9
13
|
}) : (function(o, m, k, k2) {
|
|
10
14
|
if (k2 === undefined) k2 = k;
|
|
11
15
|
o[k2] = m[k];
|
|
@@ -31,7 +31,17 @@ function transformRoute(opts) {
|
|
|
31
31
|
(0, assert_1.default)(!opts.route.children, 'children is not allowed in route props, use routes instead.');
|
|
32
32
|
const id = String(opts.memo.id++);
|
|
33
33
|
const _a = opts.route, { routes, component } = _a, routeProps = __rest(_a, ["routes", "component"]);
|
|
34
|
+
let absPath = opts.route.path;
|
|
35
|
+
if ((absPath === null || absPath === void 0 ? void 0 : absPath.charAt(0)) !== '/') {
|
|
36
|
+
const parentAbsPath = opts.parentId
|
|
37
|
+
? opts.memo.ret[opts.parentId].absPath.replace(/\/*$/, '/') // to remove '/'s on the tail
|
|
38
|
+
: '/';
|
|
39
|
+
absPath = parentAbsPath + absPath;
|
|
40
|
+
}
|
|
34
41
|
opts.memo.ret[id] = Object.assign(Object.assign(Object.assign(Object.assign({}, routeProps), { path: opts.route.path }), (component ? { file: component } : {})), { parentId: opts.parentId, id });
|
|
42
|
+
if (absPath) {
|
|
43
|
+
opts.memo.ret[id].absPath = absPath;
|
|
44
|
+
}
|
|
35
45
|
if (opts.route.routes) {
|
|
36
46
|
transformRoutes({
|
|
37
47
|
routes: opts.route.routes,
|
|
@@ -25,7 +25,6 @@ umi generate
|
|
|
25
25
|
const [type] = args._;
|
|
26
26
|
const runGenerator = (generator) => __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
yield (generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
28
|
-
api,
|
|
29
28
|
args,
|
|
30
29
|
generateFile: utils_1.generateFile,
|
|
31
30
|
installDeps: utils_1.installDeps,
|
|
@@ -39,7 +38,6 @@ umi generate
|
|
|
39
38
|
}
|
|
40
39
|
if (generator.type === generator_1.GeneratorType.enable) {
|
|
41
40
|
const enable = yield ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
|
|
42
|
-
api,
|
|
43
41
|
args,
|
|
44
42
|
}));
|
|
45
43
|
if (!enable) {
|
|
@@ -50,9 +48,9 @@ umi generate
|
|
|
50
48
|
}
|
|
51
49
|
else {
|
|
52
50
|
const getEnableGenerators = (generators) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
var _b, _c;
|
|
53
52
|
const questions = [];
|
|
54
|
-
Object.keys(generators)
|
|
55
|
-
var _b, _c;
|
|
53
|
+
for (const key of Object.keys(generators)) {
|
|
56
54
|
if (generators[key].type === generator_1.GeneratorType.generate) {
|
|
57
55
|
questions.push({
|
|
58
56
|
title: `${generators[key].name} -- ${generators[key].description}` ||
|
|
@@ -62,7 +60,6 @@ umi generate
|
|
|
62
60
|
}
|
|
63
61
|
else {
|
|
64
62
|
const enable = yield ((_c = (_b = generators[key]) === null || _b === void 0 ? void 0 : _b.checkEnable) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
65
|
-
api,
|
|
66
63
|
args,
|
|
67
64
|
}));
|
|
68
65
|
if (enable) {
|
|
@@ -73,7 +70,7 @@ umi generate
|
|
|
73
70
|
});
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
|
-
}
|
|
73
|
+
}
|
|
77
74
|
return questions;
|
|
78
75
|
});
|
|
79
76
|
const questions = yield getEnableGenerators(api.service.generators);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateFile } from '@umijs/utils';
|
|
2
2
|
import { Plugin } from './plugin';
|
|
3
|
-
import { PluginAPI } from './pluginAPI';
|
|
4
|
-
import { IServicePluginAPI } from './service';
|
|
5
3
|
export declare enum GeneratorType {
|
|
6
4
|
generate = "generate",
|
|
7
5
|
enable = "enable"
|
|
@@ -14,21 +12,12 @@ export interface IGeneratorOpts {
|
|
|
14
12
|
checkEnable?: {
|
|
15
13
|
(opts: {
|
|
16
14
|
args: any;
|
|
17
|
-
api: PluginAPI & IServicePluginAPI;
|
|
18
15
|
}): boolean;
|
|
19
16
|
};
|
|
20
17
|
fn: {
|
|
21
18
|
(opts: {
|
|
22
19
|
args: any;
|
|
23
|
-
|
|
24
|
-
generateFile: {
|
|
25
|
-
(opts: {
|
|
26
|
-
path: string;
|
|
27
|
-
target: string;
|
|
28
|
-
data?: any;
|
|
29
|
-
questions?: prompts.PromptObject[];
|
|
30
|
-
}): void;
|
|
31
|
-
};
|
|
20
|
+
generateFile: typeof generateFile;
|
|
32
21
|
updatePackageJSON: {
|
|
33
22
|
(opts: {
|
|
34
23
|
opts: object;
|
package/dist/service/path.d.ts
CHANGED
package/dist/service/path.js
CHANGED
|
@@ -13,6 +13,7 @@ function getPaths(opts) {
|
|
|
13
13
|
const src = winJoin(cwd, 'src');
|
|
14
14
|
const absSrcPath = (0, fs_1.existsSync)(src) && (0, fs_1.statSync)(src).isDirectory() ? src : cwd;
|
|
15
15
|
const absPagesPath = winJoin(absSrcPath, 'pages');
|
|
16
|
+
const absApiRoutesPath = winJoin(absSrcPath, 'api');
|
|
16
17
|
const tmp = opts.env === types_1.Env.development
|
|
17
18
|
? `.${opts.prefix}`
|
|
18
19
|
: `.${opts.prefix}-${opts.env}`;
|
|
@@ -23,6 +24,7 @@ function getPaths(opts) {
|
|
|
23
24
|
cwd,
|
|
24
25
|
absSrcPath,
|
|
25
26
|
absPagesPath,
|
|
27
|
+
absApiRoutesPath,
|
|
26
28
|
absTmpPath,
|
|
27
29
|
absNodeModulesPath,
|
|
28
30
|
absOutputPath,
|
package/dist/service/plugin.d.ts
CHANGED
package/dist/service/plugin.js
CHANGED
|
@@ -17,6 +17,7 @@ const RE = {
|
|
|
17
17
|
class Plugin {
|
|
18
18
|
constructor(opts) {
|
|
19
19
|
this.config = {};
|
|
20
|
+
this.time = { hooks: {} };
|
|
20
21
|
this.enableBy = types_1.EnableBy.register;
|
|
21
22
|
this.type = opts.type;
|
|
22
23
|
this.path = (0, utils_1.winPath)(opts.path);
|
|
@@ -25,7 +26,7 @@ class Plugin {
|
|
|
25
26
|
let pkg = null;
|
|
26
27
|
// path is the package entry
|
|
27
28
|
let isPkgEntry = false;
|
|
28
|
-
const pkgJSONPath = utils_1.pkgUp.
|
|
29
|
+
const pkgJSONPath = utils_1.pkgUp.pkgUpSync({ cwd: this.path });
|
|
29
30
|
if (pkgJSONPath) {
|
|
30
31
|
pkg = require(pkgJSONPath);
|
|
31
32
|
isPkgEntry =
|
|
@@ -37,6 +38,7 @@ class Plugin {
|
|
|
37
38
|
this.apply = () => {
|
|
38
39
|
utils_1.register.register({
|
|
39
40
|
implementor: esbuild_1.default,
|
|
41
|
+
exts: ['.ts', '.mjs'],
|
|
40
42
|
});
|
|
41
43
|
utils_1.register.clearFiles();
|
|
42
44
|
let ret;
|
|
@@ -46,10 +48,9 @@ class Plugin {
|
|
|
46
48
|
catch (e) {
|
|
47
49
|
throw new Error(`Register ${this.type} ${this.path} failed, since ${e.message}`);
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
finally {
|
|
52
|
+
utils_1.register.restore();
|
|
51
53
|
}
|
|
52
|
-
utils_1.register.restore();
|
|
53
54
|
// use the default member for es modules
|
|
54
55
|
return ret.__esModule ? ret.default : ret;
|
|
55
56
|
};
|
|
@@ -33,7 +33,7 @@ export declare class PluginAPI {
|
|
|
33
33
|
}): void;
|
|
34
34
|
registerPresets(source: Plugin[], presets: any[]): void;
|
|
35
35
|
registerPlugins(source: Plugin[], plugins: any[]): void;
|
|
36
|
-
skipPlugins(
|
|
36
|
+
skipPlugins(keys: string[]): void;
|
|
37
37
|
static proxyPluginAPI(opts: {
|
|
38
38
|
pluginAPI: PluginAPI;
|
|
39
39
|
service: Service;
|
|
@@ -36,6 +36,11 @@ class PluginAPI {
|
|
|
36
36
|
}, {});
|
|
37
37
|
}
|
|
38
38
|
describe(opts) {
|
|
39
|
+
var _a;
|
|
40
|
+
// default 值 + 配置开启冲突,会导致就算用户没有配 key,插件也会生效
|
|
41
|
+
if (opts.enableBy === types_1.EnableBy.config && ((_a = opts.config) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
42
|
+
throw new Error(`[plugin: ${this.plugin.id}] The config.default is not allowed when enableBy is EnableBy.config.`);
|
|
43
|
+
}
|
|
39
44
|
this.plugin.merge(opts);
|
|
40
45
|
}
|
|
41
46
|
registerCommand(opts) {
|
|
@@ -63,6 +68,7 @@ class PluginAPI {
|
|
|
63
68
|
}
|
|
64
69
|
register(opts) {
|
|
65
70
|
var _a, _b;
|
|
71
|
+
(0, assert_1.default)(this.service.stage <= types_1.ServiceStage.initPlugins, 'api.register() should not be called after plugin register stage.');
|
|
66
72
|
(_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
67
73
|
this.service.hooks[opts.key].push(new hook_1.Hook(Object.assign(Object.assign({}, opts), { plugin: this.plugin })));
|
|
68
74
|
}
|
|
@@ -85,7 +91,7 @@ class PluginAPI {
|
|
|
85
91
|
return new plugin_1.Plugin({
|
|
86
92
|
path: preset,
|
|
87
93
|
cwd: this.service.cwd,
|
|
88
|
-
type: types_1.PluginType.
|
|
94
|
+
type: types_1.PluginType.preset,
|
|
89
95
|
});
|
|
90
96
|
}));
|
|
91
97
|
}
|
|
@@ -99,6 +105,7 @@ class PluginAPI {
|
|
|
99
105
|
plugin.enableBy = plugin.enableBy || types_1.EnableBy.register;
|
|
100
106
|
plugin.apply = plugin.apply || (() => () => { });
|
|
101
107
|
plugin.config = plugin.config || {};
|
|
108
|
+
plugin.time = { hooks: {} };
|
|
102
109
|
return plugin;
|
|
103
110
|
}
|
|
104
111
|
else {
|
|
@@ -116,9 +123,11 @@ class PluginAPI {
|
|
|
116
123
|
source.splice(0, 0, ...mappedPlugins);
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
|
-
skipPlugins(
|
|
120
|
-
|
|
121
|
-
this.
|
|
126
|
+
skipPlugins(keys) {
|
|
127
|
+
keys.forEach((key) => {
|
|
128
|
+
(0, assert_1.default)(!(this.plugin.key === key), `plugin ${key} can't skip itself!`);
|
|
129
|
+
(0, assert_1.default)(this.service.keyToPluginMap[key], `key: ${key} is not be registered by any plugin. You can't skip it!`);
|
|
130
|
+
this.service.skipPluginIds.add(this.service.keyToPluginMap[key].id);
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
133
|
static proxyPluginAPI(opts) {
|
|
@@ -20,6 +20,7 @@ export declare class Service {
|
|
|
20
20
|
version: string;
|
|
21
21
|
matches: string[];
|
|
22
22
|
subpaths: string[];
|
|
23
|
+
external?: boolean;
|
|
23
24
|
}>;
|
|
24
25
|
[key: string]: any;
|
|
25
26
|
};
|
|
@@ -38,6 +39,7 @@ export declare class Service {
|
|
|
38
39
|
cwd?: string;
|
|
39
40
|
absSrcPath?: string;
|
|
40
41
|
absPagesPath?: string;
|
|
42
|
+
absApiRoutesPath?: string;
|
|
41
43
|
absTmpPath?: string;
|
|
42
44
|
absNodeModulesPath?: string;
|
|
43
45
|
absOutputPath?: string;
|
|
@@ -71,6 +73,7 @@ export declare class Service {
|
|
|
71
73
|
name: string;
|
|
72
74
|
args?: any;
|
|
73
75
|
}): Promise<void>;
|
|
76
|
+
_baconPlugins(): void;
|
|
74
77
|
initPreset(opts: {
|
|
75
78
|
preset: Plugin;
|
|
76
79
|
presets: Plugin[];
|
|
@@ -109,6 +112,7 @@ export interface IServicePluginAPI {
|
|
|
109
112
|
ConfigChangeType: typeof ConfigChangeType;
|
|
110
113
|
EnableBy: typeof EnableBy;
|
|
111
114
|
ServiceStage: typeof ServiceStage;
|
|
115
|
+
registerPresets: (presets: any[]) => void;
|
|
112
116
|
registerPlugins: (plugins: (Plugin | {})[]) => void;
|
|
113
117
|
}
|
|
114
118
|
export {};
|
package/dist/service/service.js
CHANGED
|
@@ -25,7 +25,6 @@ const env_1 = require("./env");
|
|
|
25
25
|
const path_2 = require("./path");
|
|
26
26
|
const plugin_1 = require("./plugin");
|
|
27
27
|
const pluginAPI_1 = require("./pluginAPI");
|
|
28
|
-
const utils_2 = require("./utils");
|
|
29
28
|
class Service {
|
|
30
29
|
constructor(opts) {
|
|
31
30
|
this.appData = {};
|
|
@@ -81,11 +80,15 @@ class Service {
|
|
|
81
80
|
if (!this.isPluginEnable(hook))
|
|
82
81
|
continue;
|
|
83
82
|
tAdd.tapPromise({
|
|
84
|
-
name: hook.plugin.
|
|
83
|
+
name: hook.plugin.key,
|
|
85
84
|
stage: hook.stage,
|
|
86
85
|
before: hook.before,
|
|
87
86
|
}, (memo) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const dateStart = new Date();
|
|
88
89
|
const items = yield hook.fn(opts.args);
|
|
90
|
+
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
91
|
+
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
89
92
|
return memo.concat(items);
|
|
90
93
|
}));
|
|
91
94
|
}
|
|
@@ -96,11 +99,16 @@ class Service {
|
|
|
96
99
|
if (!this.isPluginEnable(hook))
|
|
97
100
|
continue;
|
|
98
101
|
tModify.tapPromise({
|
|
99
|
-
name: hook.plugin.
|
|
102
|
+
name: hook.plugin.key,
|
|
100
103
|
stage: hook.stage,
|
|
101
104
|
before: hook.before,
|
|
102
105
|
}, (memo) => __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
106
|
+
var _c, _d;
|
|
107
|
+
const dateStart = new Date();
|
|
108
|
+
const ret = yield hook.fn(memo, opts.args);
|
|
109
|
+
(_c = hook.plugin.time.hooks)[_d = opts.key] || (_c[_d] = []);
|
|
110
|
+
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
111
|
+
return ret;
|
|
104
112
|
}));
|
|
105
113
|
}
|
|
106
114
|
return (yield tModify.promise(opts.initialValue));
|
|
@@ -110,11 +118,15 @@ class Service {
|
|
|
110
118
|
if (!this.isPluginEnable(hook))
|
|
111
119
|
continue;
|
|
112
120
|
tEvent.tapPromise({
|
|
113
|
-
name: hook.plugin.
|
|
121
|
+
name: hook.plugin.key,
|
|
114
122
|
stage: hook.stage || 0,
|
|
115
123
|
before: hook.before,
|
|
116
124
|
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _f, _g;
|
|
126
|
+
const dateStart = new Date();
|
|
117
127
|
yield hook.fn(opts.args);
|
|
128
|
+
(_f = hook.plugin.time.hooks)[_g = opts.key] || (_f[_g] = []);
|
|
129
|
+
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
118
130
|
}));
|
|
119
131
|
}
|
|
120
132
|
return (yield tEvent.promise(1));
|
|
@@ -153,12 +165,14 @@ class Service {
|
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
this.pkg = pkg;
|
|
156
|
-
this.pkgPath = pkgPath;
|
|
168
|
+
this.pkgPath = pkgPath || (0, path_1.join)(this.cwd, 'package.json');
|
|
169
|
+
const prefix = this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME;
|
|
157
170
|
// get user config
|
|
158
171
|
const configManager = new config_1.Config({
|
|
159
172
|
cwd: this.cwd,
|
|
160
173
|
env: this.env,
|
|
161
174
|
defaultConfigFiles: this.opts.defaultConfigFiles,
|
|
175
|
+
specifiedEnv: process.env[`${prefix}_ENV`.toUpperCase()],
|
|
162
176
|
});
|
|
163
177
|
this.configManager = configManager;
|
|
164
178
|
this.userConfig = configManager.getUserConfig().config;
|
|
@@ -170,7 +184,7 @@ class Service {
|
|
|
170
184
|
plugins: [require.resolve('./generatePlugin')].concat(this.opts.plugins || []),
|
|
171
185
|
presets: [require.resolve('./servicePlugin')].concat(this.opts.presets || []),
|
|
172
186
|
userConfig: this.userConfig,
|
|
173
|
-
prefix
|
|
187
|
+
prefix,
|
|
174
188
|
});
|
|
175
189
|
// register presets and plugins
|
|
176
190
|
this.stage = types_1.ServiceStage.initPresets;
|
|
@@ -187,10 +201,6 @@ class Service {
|
|
|
187
201
|
while (plugins.length) {
|
|
188
202
|
yield this.initPlugin({ plugin: plugins.shift(), plugins });
|
|
189
203
|
}
|
|
190
|
-
// keyToPluginMap
|
|
191
|
-
for (const id of Object.keys(this.plugins)) {
|
|
192
|
-
this.keyToPluginMap[this.plugins[id].key] = this.plugins[id];
|
|
193
|
-
}
|
|
194
204
|
// collect configSchemas and configDefaults
|
|
195
205
|
for (const id of Object.keys(this.plugins)) {
|
|
196
206
|
const { config, key } = this.plugins[id];
|
|
@@ -207,9 +217,6 @@ class Service {
|
|
|
207
217
|
env: this.env,
|
|
208
218
|
prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
|
|
209
219
|
});
|
|
210
|
-
if (this.config.outputPath) {
|
|
211
|
-
paths.absOutputPath = (0, path_1.join)(this.cwd, this.config.outputPath);
|
|
212
|
-
}
|
|
213
220
|
this.stage = types_1.ServiceStage.resolveConfig;
|
|
214
221
|
const config = yield this.applyPlugins({
|
|
215
222
|
key: 'modifyConfig',
|
|
@@ -226,6 +233,9 @@ class Service {
|
|
|
226
233
|
initialValue: this.configDefaults,
|
|
227
234
|
});
|
|
228
235
|
this.config = utils_1.lodash.merge(defaultConfig, config);
|
|
236
|
+
if (this.config.outputPath) {
|
|
237
|
+
paths.absOutputPath = (0, path_1.join)(this.cwd, this.config.outputPath);
|
|
238
|
+
}
|
|
229
239
|
this.paths = yield this.applyPlugins({
|
|
230
240
|
key: 'modifyPaths',
|
|
231
241
|
initialValue: paths,
|
|
@@ -276,9 +286,21 @@ class Service {
|
|
|
276
286
|
this.stage = types_1.ServiceStage.runCommand;
|
|
277
287
|
const command = this.commands[name];
|
|
278
288
|
(0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
|
|
279
|
-
|
|
289
|
+
let ret = yield command.fn({ args });
|
|
290
|
+
this._baconPlugins();
|
|
291
|
+
return ret;
|
|
280
292
|
});
|
|
281
293
|
}
|
|
294
|
+
_baconPlugins() {
|
|
295
|
+
// TODO: prettier
|
|
296
|
+
if (this.args.baconPlugins) {
|
|
297
|
+
console.log();
|
|
298
|
+
for (const id of Object.keys(this.plugins)) {
|
|
299
|
+
const plugin = this.plugins[id];
|
|
300
|
+
console.log(utils_1.chalk.green('plugin'), plugin.id, plugin.time);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
282
304
|
initPreset(opts) {
|
|
283
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
284
306
|
const { presets, plugins } = yield this.initPlugin({
|
|
@@ -291,7 +313,7 @@ class Service {
|
|
|
291
313
|
});
|
|
292
314
|
}
|
|
293
315
|
initPlugin(opts) {
|
|
294
|
-
var _a;
|
|
316
|
+
var _a, _b;
|
|
295
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
296
318
|
// register to this.plugins
|
|
297
319
|
(0, assert_1.default)(!this.plugins[opts.plugin.id], `${opts.plugin.type} ${opts.plugin.id} is already registered by ${(_a = this.plugins[opts.plugin.id]) === null || _a === void 0 ? void 0 : _a.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
|
|
@@ -328,13 +350,15 @@ class Service {
|
|
|
328
350
|
service: this,
|
|
329
351
|
},
|
|
330
352
|
});
|
|
331
|
-
let
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
353
|
+
let dateStart = new Date();
|
|
354
|
+
let ret = yield opts.plugin.apply()(proxyPluginAPI);
|
|
355
|
+
opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
|
|
335
356
|
if (opts.plugin.type === 'plugin') {
|
|
336
357
|
(0, assert_1.default)(!ret, `plugin should return nothing`);
|
|
337
358
|
}
|
|
359
|
+
// key should be unique
|
|
360
|
+
(0, assert_1.default)(!this.keyToPluginMap[opts.plugin.key], `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) === null || _b === void 0 ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
|
|
361
|
+
this.keyToPluginMap[opts.plugin.key] = opts.plugin;
|
|
338
362
|
if (ret === null || ret === void 0 ? void 0 : ret.presets) {
|
|
339
363
|
ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
|
|
340
364
|
path: preset,
|
|
@@ -369,7 +393,15 @@ class Service {
|
|
|
369
393
|
return false;
|
|
370
394
|
if (enableBy === types_1.EnableBy.config) {
|
|
371
395
|
// TODO: 提供单独的命令用于启用插件
|
|
372
|
-
|
|
396
|
+
// this.userConfig 中如果存在,启用
|
|
397
|
+
// this.config 好了之后如果存在,启用
|
|
398
|
+
// this.config 在 modifyConfig 和 modifyDefaultConfig 之后才会 ready
|
|
399
|
+
// 这意味着 modifyConfig 和 modifyDefaultConfig 只能判断 api.userConfig
|
|
400
|
+
// 举个具体场景:
|
|
401
|
+
// - p1 enableBy config, p2 modifyDefaultConfig p1 = {}
|
|
402
|
+
// - p1 里 modifyConfig 和 modifyDefaultConfig 仅 userConfig 里有 p1 有效,其他 p2 开启时即有效
|
|
403
|
+
// - p2 里因为用了 modifyDefaultConfig,如果 p2 是 enableBy config,需要 userConfig 里配 p2,p2 和 p1 才有效
|
|
404
|
+
return key in this.userConfig || (this.config && key in this.config);
|
|
373
405
|
}
|
|
374
406
|
if (typeof enableBy === 'function')
|
|
375
407
|
return enableBy({
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/core",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.10",
|
|
4
4
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
|
|
5
5
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
6
6
|
"repository": {
|
|
@@ -17,17 +17,18 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "pnpm tsc",
|
|
19
19
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
20
|
-
"dev": "pnpm build -- --watch"
|
|
20
|
+
"dev": "pnpm build -- --watch",
|
|
21
|
+
"test": "jest -c ../../jest.turbo.config.ts"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
24
|
-
"@umijs/utils": "4.0.0-rc.
|
|
24
|
+
"@umijs/bundler-utils": "4.0.0-rc.10",
|
|
25
|
+
"@umijs/utils": "4.0.0-rc.10"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@hapi/joi": "17.1.1",
|
|
28
|
-
"@types/hapi__joi": "17.1.
|
|
29
|
-
"dotenv": "
|
|
30
|
-
"just-diff": "
|
|
29
|
+
"@types/hapi__joi": "17.1.8",
|
|
30
|
+
"dotenv": "16.0.0",
|
|
31
|
+
"just-diff": "5.0.1",
|
|
31
32
|
"tapable": "2.2.1"
|
|
32
33
|
},
|
|
33
34
|
"publishConfig": {
|