@umijs/core 4.0.0-rc.12 → 4.0.0-rc.15

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.
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -30,18 +19,39 @@ function transformRoutes(opts) {
30
19
  function transformRoute(opts) {
31
20
  (0, assert_1.default)(!opts.route.children, 'children is not allowed in route props, use routes instead.');
32
21
  const id = String(opts.memo.id++);
33
- const _a = opts.route, { routes, component } = _a, routeProps = __rest(_a, ["routes", "component"]);
22
+ const { routes, component, wrappers, ...routeProps } = opts.route;
34
23
  let absPath = opts.route.path;
35
24
  if ((absPath === null || absPath === void 0 ? void 0 : absPath.charAt(0)) !== '/') {
36
25
  const parentAbsPath = opts.parentId
37
- ? opts.memo.ret[opts.parentId].absPath.replace(/\/*$/, '/') // to remove '/'s on the tail
26
+ ? opts.memo.ret[opts.parentId].absPath.replace(/\/+$/, '/') // to remove '/'s on the tail
38
27
  : '/';
39
28
  absPath = parentAbsPath + absPath;
40
29
  }
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 });
30
+ opts.memo.ret[id] = {
31
+ ...routeProps,
32
+ path: opts.route.path,
33
+ ...(component ? { file: component } : {}),
34
+ parentId: opts.parentId,
35
+ id,
36
+ };
42
37
  if (absPath) {
43
38
  opts.memo.ret[id].absPath = absPath;
44
39
  }
40
+ if (wrappers === null || wrappers === void 0 ? void 0 : wrappers.length) {
41
+ let parentId = opts.parentId;
42
+ let path = opts.route.path;
43
+ wrappers.forEach((wrapper) => {
44
+ const { id } = transformRoute({
45
+ route: { path, component: wrapper },
46
+ parentId,
47
+ memo: opts.memo,
48
+ });
49
+ parentId = id;
50
+ path = '';
51
+ });
52
+ opts.memo.ret[id].parentId = parentId;
53
+ opts.memo.ret[id].path = path;
54
+ }
45
55
  if (opts.route.routes) {
46
56
  transformRoutes({
47
57
  routes: opts.route.routes,
@@ -49,4 +59,5 @@ function transformRoute(opts) {
49
59
  memo: opts.memo,
50
60
  });
51
61
  }
62
+ return { id };
52
63
  }
@@ -44,10 +44,10 @@ function visitFiles(opts) {
44
44
  let file = (0, path_1.resolve)(opts.dir, filename);
45
45
  let stat = (0, fs_1.lstatSync)(file);
46
46
  if (stat.isDirectory()) {
47
- visitFiles(Object.assign(Object.assign({}, opts), { dir: file }));
47
+ visitFiles({ ...opts, dir: file });
48
48
  }
49
49
  else if (stat.isFile() &&
50
- ['.tsx', '.ts', '.js', '.jsx', '.md', '.mdx'].includes((0, path_1.extname)(file))) {
50
+ ['.tsx', '.ts', '.js', '.jsx', '.md', '.mdx', '.vue'].includes((0, path_1.extname)(file))) {
51
51
  opts.visitor((0, path_1.relative)(opts.baseDir, file));
52
52
  }
53
53
  }
@@ -19,7 +19,7 @@ function findParentRouteId(routeIds, childRouteId) {
19
19
  return routeIds.find((id) => childRouteId.startsWith(`${id}/`));
20
20
  }
21
21
  exports.findParentRouteId = findParentRouteId;
22
- const routeModuleExts = ['.js', '.jsx', '.ts', '.tsx', '.md', '.mdx'];
22
+ const routeModuleExts = ['.js', '.jsx', '.ts', '.tsx', '.md', '.mdx', '.vue'];
23
23
  function isRouteModuleFile(opts) {
24
24
  // TODO: add cache strategy
25
25
  for (const excludeRegExp of opts.exclude || []) {
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const utils_1 = require("@umijs/utils");
13
4
  const generator_1 = require("./generator");
@@ -19,70 +10,68 @@ exports.default = (api) => {
19
10
  umi generate
20
11
  `,
21
12
  description: 'generate code snippets quickly',
22
- fn({ args }) {
13
+ async fn({ args }) {
23
14
  var _a;
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const [type] = args._;
26
- const runGenerator = (generator) => __awaiter(this, void 0, void 0, function* () {
27
- yield (generator === null || generator === void 0 ? void 0 : generator.fn({
15
+ const [type] = args._;
16
+ const runGenerator = async (generator) => {
17
+ await (generator === null || generator === void 0 ? void 0 : generator.fn({
18
+ args,
19
+ generateFile: utils_1.generateFile,
20
+ installDeps: utils_1.installDeps,
21
+ updatePackageJSON: utils_1.updatePackageJSON,
22
+ }));
23
+ };
24
+ if (type) {
25
+ const generator = api.service.generators[type];
26
+ if (!generator) {
27
+ throw new Error(`Generator ${type} not found.`);
28
+ }
29
+ if (generator.type === generator_1.GeneratorType.enable) {
30
+ const enable = await ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
28
31
  args,
29
- generateFile: utils_1.generateFile,
30
- installDeps: utils_1.installDeps,
31
- updatePackageJSON: utils_1.updatePackageJSON,
32
32
  }));
33
- });
34
- if (type) {
35
- const generator = api.service.generators[type];
36
- if (!generator) {
37
- throw new Error(`Generator ${type} not found.`);
38
- }
39
- if (generator.type === generator_1.GeneratorType.enable) {
40
- const enable = yield ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
41
- args,
42
- }));
43
- if (!enable) {
44
- throw new Error(`Generator ${type} is unable.The corresponding function has been turned on or is not available.`);
45
- }
33
+ if (!enable) {
34
+ throw new Error(`Generator ${type} is unable.The corresponding function has been turned on or is not available.`);
46
35
  }
47
- yield runGenerator(generator);
48
36
  }
49
- else {
50
- const getEnableGenerators = (generators) => __awaiter(this, void 0, void 0, function* () {
51
- var _b, _c;
52
- const questions = [];
53
- for (const key of Object.keys(generators)) {
54
- if (generators[key].type === generator_1.GeneratorType.generate) {
37
+ await runGenerator(generator);
38
+ }
39
+ else {
40
+ const getEnableGenerators = async (generators) => {
41
+ var _a, _b;
42
+ const questions = [];
43
+ for (const key of Object.keys(generators)) {
44
+ if (generators[key].type === generator_1.GeneratorType.generate) {
45
+ questions.push({
46
+ title: `${generators[key].name} -- ${generators[key].description}` ||
47
+ '',
48
+ value: generators[key].key,
49
+ });
50
+ }
51
+ else {
52
+ const enable = await ((_b = (_a = generators[key]) === null || _a === void 0 ? void 0 : _a.checkEnable) === null || _b === void 0 ? void 0 : _b.call(_a, {
53
+ args,
54
+ }));
55
+ if (enable) {
55
56
  questions.push({
56
57
  title: `${generators[key].name} -- ${generators[key].description}` ||
57
58
  '',
58
59
  value: generators[key].key,
59
60
  });
60
61
  }
61
- else {
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, {
63
- args,
64
- }));
65
- if (enable) {
66
- questions.push({
67
- title: `${generators[key].name} -- ${generators[key].description}` ||
68
- '',
69
- value: generators[key].key,
70
- });
71
- }
72
- }
73
62
  }
74
- return questions;
75
- });
76
- const questions = yield getEnableGenerators(api.service.generators);
77
- const { gType } = yield (0, utils_1.prompts)({
78
- type: 'select',
79
- name: 'gType',
80
- message: 'Pick generator type',
81
- choices: questions,
82
- });
83
- yield runGenerator(api.service.generators[gType]);
84
- }
85
- });
63
+ }
64
+ return questions;
65
+ };
66
+ const questions = await getEnableGenerators(api.service.generators);
67
+ const { gType } = await (0, utils_1.prompts)({
68
+ type: 'select',
69
+ name: 'gType',
70
+ message: 'Pick generator type',
71
+ choices: questions,
72
+ });
73
+ await runGenerator(api.service.generators[gType]);
74
+ }
86
75
  },
87
76
  });
88
77
  };
@@ -50,13 +50,16 @@ class PluginAPI {
50
50
  var _a;
51
51
  const { name } = commandOpts;
52
52
  (0, assert_1.default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
53
- this.service.commands[name] = new command_1.Command(Object.assign(Object.assign({}, commandOpts), { plugin: this.plugin }));
53
+ this.service.commands[name] = new command_1.Command({
54
+ ...commandOpts,
55
+ plugin: this.plugin,
56
+ });
54
57
  };
55
58
  registerCommand(opts);
56
59
  if (alias) {
57
60
  const aliases = (0, utils_2.makeArray)(alias);
58
61
  aliases.forEach((alias) => {
59
- registerCommand(Object.assign(Object.assign({}, opts), { name: alias }));
62
+ registerCommand({ ...opts, name: alias });
60
63
  });
61
64
  }
62
65
  }
@@ -64,13 +67,16 @@ class PluginAPI {
64
67
  var _a;
65
68
  const { key } = opts;
66
69
  (0, assert_1.default)(!this.service.generators[key], `api.registerGenerator() failed, the generator ${key} is exists from ${(_a = this.service.generators[key]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
67
- this.service.generators[key] = new generator_1.Generator(Object.assign(Object.assign({}, opts), { plugin: this.plugin }));
70
+ this.service.generators[key] = new generator_1.Generator({
71
+ ...opts,
72
+ plugin: this.plugin,
73
+ });
68
74
  }
69
75
  register(opts) {
70
76
  var _a, _b;
71
77
  (0, assert_1.default)(this.service.stage <= types_1.ServiceStage.initPlugins, 'api.register() should not be called after plugin register stage.');
72
78
  (_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
73
- this.service.hooks[opts.key].push(new hook_1.Hook(Object.assign(Object.assign({}, opts), { plugin: this.plugin })));
79
+ this.service.hooks[opts.key].push(new hook_1.Hook({ ...opts, plugin: this.plugin }));
74
80
  }
75
81
  registerMethod(opts) {
76
82
  (0, assert_1.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
@@ -81,7 +87,10 @@ class PluginAPI {
81
87
  // 否则 pluginId 会不会,导致不能正确 skip plugin
82
88
  function (fn) {
83
89
  // @ts-ignore
84
- this.register(Object.assign({ key: opts.name }, (utils_1.lodash.isPlainObject(fn) ? fn : { fn })));
90
+ this.register({
91
+ key: opts.name,
92
+ ...(utils_1.lodash.isPlainObject(fn) ? fn : { fn }),
93
+ });
85
94
  },
86
95
  };
87
96
  }
@@ -63,6 +63,13 @@ export declare class Service {
63
63
  };
64
64
  pkgPath: string;
65
65
  constructor(opts: IOpts);
66
+ applyPlugins<T>(opts: {
67
+ key: string;
68
+ type?: ApplyPluginsType.event;
69
+ initialValue?: any;
70
+ args?: any;
71
+ sync: true;
72
+ }): typeof opts.initialValue | T;
66
73
  applyPlugins<T>(opts: {
67
74
  key: string;
68
75
  type?: ApplyPluginsType;
@@ -73,6 +80,11 @@ export declare class Service {
73
80
  name: string;
74
81
  args?: any;
75
82
  }): Promise<void>;
83
+ generateFinalConfig(): Promise<{
84
+ config: any;
85
+ defaultConfig: any;
86
+ finalConfig: Record<string, any>;
87
+ }>;
76
88
  _baconPlugins(): void;
77
89
  initPreset(opts: {
78
90
  preset: Plugin;
@@ -1,23 +1,14 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.Service = void 0;
7
+ const tapable_1 = require("@umijs/bundler-utils/compiled/tapable");
16
8
  const utils_1 = require("@umijs/utils");
17
9
  const assert_1 = __importDefault(require("assert"));
18
10
  const fs_1 = require("fs");
19
11
  const path_1 = require("path");
20
- const tapable_1 = require("../../compiled/tapable");
21
12
  const config_1 = require("../config/config");
22
13
  const constants_1 = require("../constants");
23
14
  const types_1 = require("../types");
@@ -54,242 +45,271 @@ class Service {
54
45
  (0, assert_1.default)((0, fs_1.existsSync)(this.cwd), `Invalid cwd ${this.cwd}, it's not found.`);
55
46
  }
56
47
  applyPlugins(opts) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const hooks = this.hooks[opts.key] || [];
59
- let type = opts.type;
60
- // guess type from key
61
- if (!type) {
62
- if (opts.key.startsWith('on')) {
63
- type = types_1.ApplyPluginsType.event;
48
+ const hooks = this.hooks[opts.key] || [];
49
+ let type = opts.type;
50
+ // guess type from key
51
+ if (!type) {
52
+ if (opts.key.startsWith('on')) {
53
+ type = types_1.ApplyPluginsType.event;
54
+ }
55
+ else if (opts.key.startsWith('modify')) {
56
+ type = types_1.ApplyPluginsType.modify;
57
+ }
58
+ else if (opts.key.startsWith('add')) {
59
+ type = types_1.ApplyPluginsType.add;
60
+ }
61
+ else {
62
+ throw new Error(`Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`);
63
+ }
64
+ }
65
+ switch (type) {
66
+ case types_1.ApplyPluginsType.add:
67
+ (0, assert_1.default)(!('initialValue' in opts) || Array.isArray(opts.initialValue), `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`);
68
+ const tAdd = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
69
+ for (const hook of hooks) {
70
+ if (!this.isPluginEnable(hook))
71
+ continue;
72
+ tAdd.tapPromise({
73
+ name: hook.plugin.key,
74
+ stage: hook.stage,
75
+ before: hook.before,
76
+ }, async (memo) => {
77
+ var _a, _b;
78
+ const dateStart = new Date();
79
+ const items = await hook.fn(opts.args);
80
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
81
+ hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
82
+ return memo.concat(items);
83
+ });
64
84
  }
65
- else if (opts.key.startsWith('modify')) {
66
- type = types_1.ApplyPluginsType.modify;
85
+ return tAdd.promise(opts.initialValue || []);
86
+ case types_1.ApplyPluginsType.modify:
87
+ const tModify = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
88
+ for (const hook of hooks) {
89
+ if (!this.isPluginEnable(hook))
90
+ continue;
91
+ tModify.tapPromise({
92
+ name: hook.plugin.key,
93
+ stage: hook.stage,
94
+ before: hook.before,
95
+ }, async (memo) => {
96
+ var _a, _b;
97
+ const dateStart = new Date();
98
+ const ret = await hook.fn(memo, opts.args);
99
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
100
+ hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
101
+ return ret;
102
+ });
67
103
  }
68
- else if (opts.key.startsWith('add')) {
69
- type = types_1.ApplyPluginsType.add;
104
+ return tModify.promise(opts.initialValue);
105
+ case types_1.ApplyPluginsType.event:
106
+ if (opts.sync) {
107
+ const tEvent = new tapable_1.SyncWaterfallHook(['_']);
108
+ hooks.forEach((hook) => {
109
+ if (this.isPluginEnable(hook)) {
110
+ tEvent.tap({
111
+ name: hook.plugin.key,
112
+ stage: hook.stage || 0,
113
+ before: hook.before,
114
+ }, () => {
115
+ var _a, _b;
116
+ const dateStart = new Date();
117
+ hook.fn(opts.args);
118
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
119
+ hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
120
+ });
121
+ }
122
+ });
123
+ return tEvent.call(1);
70
124
  }
71
- else {
72
- throw new Error(`Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`);
125
+ const tEvent = new tapable_1.AsyncSeriesWaterfallHook(['_']);
126
+ for (const hook of hooks) {
127
+ if (!this.isPluginEnable(hook))
128
+ continue;
129
+ tEvent.tapPromise({
130
+ name: hook.plugin.key,
131
+ stage: hook.stage || 0,
132
+ before: hook.before,
133
+ }, async () => {
134
+ var _a, _b;
135
+ const dateStart = new Date();
136
+ await hook.fn(opts.args);
137
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
138
+ hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
139
+ });
73
140
  }
74
- }
75
- switch (type) {
76
- case types_1.ApplyPluginsType.add:
77
- (0, assert_1.default)(!('initialValue' in opts) || Array.isArray(opts.initialValue), `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`);
78
- const tAdd = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
79
- for (const hook of hooks) {
80
- if (!this.isPluginEnable(hook))
81
- continue;
82
- tAdd.tapPromise({
83
- name: hook.plugin.key,
84
- stage: hook.stage,
85
- before: hook.before,
86
- }, (memo) => __awaiter(this, void 0, void 0, function* () {
87
- var _a, _b;
88
- const dateStart = new Date();
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());
92
- return memo.concat(items);
93
- }));
94
- }
95
- return (yield tAdd.promise(opts.initialValue || []));
96
- case types_1.ApplyPluginsType.modify:
97
- const tModify = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
98
- for (const hook of hooks) {
99
- if (!this.isPluginEnable(hook))
100
- continue;
101
- tModify.tapPromise({
102
- name: hook.plugin.key,
103
- stage: hook.stage,
104
- before: hook.before,
105
- }, (memo) => __awaiter(this, void 0, void 0, function* () {
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;
112
- }));
113
- }
114
- return (yield tModify.promise(opts.initialValue));
115
- case types_1.ApplyPluginsType.event:
116
- const tEvent = new tapable_1.AsyncSeriesWaterfallHook(['_']);
117
- for (const hook of hooks) {
118
- if (!this.isPluginEnable(hook))
119
- continue;
120
- tEvent.tapPromise({
121
- name: hook.plugin.key,
122
- stage: hook.stage || 0,
123
- before: hook.before,
124
- }, () => __awaiter(this, void 0, void 0, function* () {
125
- var _f, _g;
126
- const dateStart = new Date();
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());
130
- }));
131
- }
132
- return (yield tEvent.promise(1));
133
- default:
134
- throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
135
- }
136
- });
141
+ return tEvent.promise(1);
142
+ default:
143
+ throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
144
+ }
137
145
  }
138
- run(opts) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- const { name, args = {} } = opts;
141
- args._ = args._ || [];
142
- // shift the command itself
143
- if (args._[0] === name)
144
- args._.shift();
145
- this.args = args;
146
- this.name = name;
147
- // loadEnv
148
- this.stage = types_1.ServiceStage.init;
149
- (0, env_1.loadEnv)({ cwd: this.cwd, envFile: '.env' });
150
- // get pkg from package.json
151
- let pkg = {};
152
- let pkgPath = '';
153
- try {
154
- pkg = require((0, path_1.join)(this.cwd, 'package.json'));
155
- pkgPath = (0, path_1.join)(this.cwd, 'package.json');
156
- }
157
- catch (_e) {
158
- // APP_ROOT
159
- if (this.cwd !== process.cwd()) {
160
- try {
161
- pkg = require((0, path_1.join)(process.cwd(), 'package.json'));
162
- pkgPath = (0, path_1.join)(process.cwd(), 'package.json');
163
- }
164
- catch (_e) { }
146
+ async run(opts) {
147
+ const { name, args = {} } = opts;
148
+ args._ = args._ || [];
149
+ // shift the command itself
150
+ if (args._[0] === name)
151
+ args._.shift();
152
+ this.args = args;
153
+ this.name = name;
154
+ // loadEnv
155
+ this.stage = types_1.ServiceStage.init;
156
+ (0, env_1.loadEnv)({ cwd: this.cwd, envFile: '.env' });
157
+ // get pkg from package.json
158
+ let pkg = {};
159
+ let pkgPath = '';
160
+ try {
161
+ pkg = require((0, path_1.join)(this.cwd, 'package.json'));
162
+ pkgPath = (0, path_1.join)(this.cwd, 'package.json');
163
+ }
164
+ catch (_e) {
165
+ // APP_ROOT
166
+ if (this.cwd !== process.cwd()) {
167
+ try {
168
+ pkg = require((0, path_1.join)(process.cwd(), 'package.json'));
169
+ pkgPath = (0, path_1.join)(process.cwd(), 'package.json');
165
170
  }
171
+ catch (_e) { }
166
172
  }
167
- this.pkg = pkg;
168
- this.pkgPath = pkgPath || (0, path_1.join)(this.cwd, 'package.json');
169
- const prefix = this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME;
170
- // get user config
171
- const configManager = new config_1.Config({
172
- cwd: this.cwd,
173
- env: this.env,
174
- defaultConfigFiles: this.opts.defaultConfigFiles,
175
- specifiedEnv: process.env[`${prefix}_ENV`.toUpperCase()],
173
+ }
174
+ this.pkg = pkg;
175
+ this.pkgPath = pkgPath || (0, path_1.join)(this.cwd, 'package.json');
176
+ const prefix = this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME;
177
+ // get user config
178
+ const configManager = new config_1.Config({
179
+ cwd: this.cwd,
180
+ env: this.env,
181
+ defaultConfigFiles: this.opts.defaultConfigFiles,
182
+ specifiedEnv: process.env[`${prefix}_ENV`.toUpperCase()],
183
+ });
184
+ this.configManager = configManager;
185
+ this.userConfig = configManager.getUserConfig().config;
186
+ // get paths
187
+ const paths = (0, path_2.getPaths)({
188
+ cwd: this.cwd,
189
+ env: this.env,
190
+ prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
191
+ });
192
+ // temporary paths for use by function generateFinalConfig.
193
+ // the value of paths may be updated by plugins later
194
+ this.paths = paths;
195
+ // resolve initial presets and plugins
196
+ const { plugins, presets } = plugin_1.Plugin.getPluginsAndPresets({
197
+ cwd: this.cwd,
198
+ pkg,
199
+ plugins: [require.resolve('./generatePlugin')].concat(this.opts.plugins || []),
200
+ presets: [require.resolve('./servicePlugin')].concat(this.opts.presets || []),
201
+ userConfig: this.userConfig,
202
+ prefix,
203
+ });
204
+ // register presets and plugins
205
+ this.stage = types_1.ServiceStage.initPresets;
206
+ const presetPlugins = [];
207
+ while (presets.length) {
208
+ await this.initPreset({
209
+ preset: presets.shift(),
210
+ presets,
211
+ plugins: presetPlugins,
176
212
  });
177
- this.configManager = configManager;
178
- this.userConfig = configManager.getUserConfig().config;
179
- // get paths (move after?)
180
- // resolve initial presets and plugins
181
- const { plugins, presets } = plugin_1.Plugin.getPluginsAndPresets({
213
+ }
214
+ plugins.unshift(...presetPlugins);
215
+ this.stage = types_1.ServiceStage.initPlugins;
216
+ while (plugins.length) {
217
+ await this.initPlugin({ plugin: plugins.shift(), plugins });
218
+ }
219
+ // collect configSchemas and configDefaults
220
+ for (const id of Object.keys(this.plugins)) {
221
+ const { config, key } = this.plugins[id];
222
+ if (config.schema)
223
+ this.configSchemas[key] = config.schema;
224
+ if (config.default !== undefined) {
225
+ this.configDefaults[key] = config.default;
226
+ }
227
+ this.configOnChanges[key] = config.onChange || types_1.ConfigChangeType.reload;
228
+ }
229
+ // setup api.config from modifyConfig and modifyDefaultConfig
230
+ this.stage = types_1.ServiceStage.resolveConfig;
231
+ const { config, defaultConfig } = await this.generateFinalConfig();
232
+ if (this.config.outputPath) {
233
+ paths.absOutputPath = (0, path_1.isAbsolute)(this.config.outputPath)
234
+ ? this.config.outputPath
235
+ : (0, path_1.join)(this.cwd, this.config.outputPath);
236
+ }
237
+ this.paths = await this.applyPlugins({
238
+ key: 'modifyPaths',
239
+ initialValue: paths,
240
+ });
241
+ // applyPlugin collect app data
242
+ // TODO: some data is mutable
243
+ this.stage = types_1.ServiceStage.collectAppData;
244
+ this.appData = await this.applyPlugins({
245
+ key: 'modifyAppData',
246
+ initialValue: {
247
+ // base
182
248
  cwd: this.cwd,
183
249
  pkg,
184
- plugins: [require.resolve('./generatePlugin')].concat(this.opts.plugins || []),
185
- presets: [require.resolve('./servicePlugin')].concat(this.opts.presets || []),
250
+ pkgPath,
251
+ plugins,
252
+ presets,
253
+ name,
254
+ args,
255
+ // config
186
256
  userConfig: this.userConfig,
187
- prefix,
188
- });
189
- // register presets and plugins
190
- this.stage = types_1.ServiceStage.initPresets;
191
- const presetPlugins = [];
192
- while (presets.length) {
193
- yield this.initPreset({
194
- preset: presets.shift(),
195
- presets,
196
- plugins: presetPlugins,
197
- });
198
- }
199
- plugins.unshift(...presetPlugins);
200
- this.stage = types_1.ServiceStage.initPlugins;
201
- while (plugins.length) {
202
- yield this.initPlugin({ plugin: plugins.shift(), plugins });
203
- }
204
- // collect configSchemas and configDefaults
205
- for (const id of Object.keys(this.plugins)) {
206
- const { config, key } = this.plugins[id];
207
- if (config.schema)
208
- this.configSchemas[key] = config.schema;
209
- if (config.default !== undefined) {
210
- this.configDefaults[key] = config.default;
211
- }
212
- this.configOnChanges[key] = config.onChange || types_1.ConfigChangeType.reload;
213
- }
214
- // setup api.config from modifyConfig and modifyDefaultConfig
215
- const paths = (0, path_2.getPaths)({
216
- cwd: this.cwd,
217
- env: this.env,
218
- prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
219
- });
220
- this.stage = types_1.ServiceStage.resolveConfig;
221
- const config = yield this.applyPlugins({
222
- key: 'modifyConfig',
223
- // why clone deep?
224
- // user may change the config in modifyConfig
225
- // e.g. memo.alias = xxx
226
- initialValue: utils_1.lodash.cloneDeep(configManager.getConfig({
227
- schemas: this.configSchemas,
228
- }).config),
229
- args: { paths },
230
- });
231
- const defaultConfig = yield this.applyPlugins({
232
- key: 'modifyDefaultConfig',
233
- initialValue: this.configDefaults,
234
- });
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
- }
239
- this.paths = yield this.applyPlugins({
240
- key: 'modifyPaths',
241
- initialValue: paths,
242
- });
243
- // applyPlugin collect app data
244
- // TODO: some data is mutable
245
- this.stage = types_1.ServiceStage.collectAppData;
246
- this.appData = yield this.applyPlugins({
247
- key: 'modifyAppData',
248
- initialValue: {
249
- // base
250
- cwd: this.cwd,
251
- pkg,
252
- pkgPath,
253
- plugins,
254
- presets,
255
- name,
256
- args,
257
- // config
258
- userConfig: this.userConfig,
259
- mainConfigFile: configManager.mainConfigFile,
260
- config,
261
- defaultConfig: defaultConfig,
262
- // TODO
263
- // moduleGraph,
264
- // routes,
265
- // npmClient,
266
- // nodeVersion,
267
- // gitInfo,
268
- // gitBranch,
269
- // debugger info,
270
- // devPort,
271
- // devHost,
272
- // env
273
- },
274
- });
275
- // applyPlugin onCheck
276
- this.stage = types_1.ServiceStage.onCheck;
277
- yield this.applyPlugins({
278
- key: 'onCheck',
279
- });
280
- // applyPlugin onStart
281
- this.stage = types_1.ServiceStage.onStart;
282
- yield this.applyPlugins({
283
- key: 'onStart',
284
- });
285
- // run command
286
- this.stage = types_1.ServiceStage.runCommand;
287
- const command = this.commands[name];
288
- (0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
289
- let ret = yield command.fn({ args });
290
- this._baconPlugins();
291
- return ret;
257
+ mainConfigFile: configManager.mainConfigFile,
258
+ config,
259
+ defaultConfig: defaultConfig,
260
+ // TODO
261
+ // moduleGraph,
262
+ // routes,
263
+ // npmClient,
264
+ // nodeVersion,
265
+ // gitInfo,
266
+ // gitBranch,
267
+ // debugger info,
268
+ // devPort,
269
+ // devHost,
270
+ // env
271
+ },
272
+ });
273
+ // applyPlugin onCheck
274
+ this.stage = types_1.ServiceStage.onCheck;
275
+ await this.applyPlugins({
276
+ key: 'onCheck',
292
277
  });
278
+ // applyPlugin onStart
279
+ this.stage = types_1.ServiceStage.onStart;
280
+ await this.applyPlugins({
281
+ key: 'onStart',
282
+ });
283
+ // run command
284
+ this.stage = types_1.ServiceStage.runCommand;
285
+ const command = this.commands[name];
286
+ (0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
287
+ let ret = await command.fn({ args });
288
+ this._baconPlugins();
289
+ return ret;
290
+ }
291
+ // generate config and defaultConfig, and assign values to this.config
292
+ async generateFinalConfig() {
293
+ var _a;
294
+ // configManager and paths are not available until the init stage
295
+ (0, assert_1.default)(this.stage > types_1.ServiceStage.init, `Can't generate final config before init stage`);
296
+ const config = await this.applyPlugins({
297
+ key: 'modifyConfig',
298
+ // why clone deep?
299
+ // user may change the config in modifyConfig
300
+ // e.g. memo.alias = xxx
301
+ initialValue: utils_1.lodash.cloneDeep((_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getConfig({
302
+ schemas: this.configSchemas,
303
+ }).config),
304
+ args: { paths: this.paths },
305
+ });
306
+ const defaultConfig = await this.applyPlugins({
307
+ key: 'modifyDefaultConfig',
308
+ initialValue: this.configDefaults,
309
+ });
310
+ const finalConfig = utils_1.lodash.merge(defaultConfig, config);
311
+ this.config = finalConfig;
312
+ return { config, defaultConfig, finalConfig };
293
313
  }
294
314
  _baconPlugins() {
295
315
  // TODO: prettier
@@ -301,80 +321,76 @@ class Service {
301
321
  }
302
322
  }
303
323
  }
304
- initPreset(opts) {
305
- return __awaiter(this, void 0, void 0, function* () {
306
- const { presets, plugins } = yield this.initPlugin({
307
- plugin: opts.preset,
308
- presets: opts.presets,
309
- plugins: opts.plugins,
310
- });
311
- opts.presets.unshift(...(presets || []));
312
- opts.plugins.push(...(plugins || []));
324
+ async initPreset(opts) {
325
+ const { presets, plugins } = await this.initPlugin({
326
+ plugin: opts.preset,
327
+ presets: opts.presets,
328
+ plugins: opts.plugins,
313
329
  });
330
+ opts.presets.unshift(...(presets || []));
331
+ opts.plugins.push(...(plugins || []));
314
332
  }
315
- initPlugin(opts) {
333
+ async initPlugin(opts) {
316
334
  var _a, _b;
317
- return __awaiter(this, void 0, void 0, function* () {
318
- // register to this.plugins
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.`);
320
- this.plugins[opts.plugin.id] = opts.plugin;
321
- // apply with PluginAPI
322
- const pluginAPI = new pluginAPI_1.PluginAPI({
323
- plugin: opts.plugin,
324
- service: this,
325
- });
326
- pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
327
- pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
328
- const proxyPluginAPI = pluginAPI_1.PluginAPI.proxyPluginAPI({
335
+ // register to this.plugins
336
+ (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.`);
337
+ this.plugins[opts.plugin.id] = opts.plugin;
338
+ // apply with PluginAPI
339
+ const pluginAPI = new pluginAPI_1.PluginAPI({
340
+ plugin: opts.plugin,
341
+ service: this,
342
+ });
343
+ pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
344
+ pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
345
+ const proxyPluginAPI = pluginAPI_1.PluginAPI.proxyPluginAPI({
346
+ service: this,
347
+ pluginAPI,
348
+ serviceProps: [
349
+ 'appData',
350
+ 'applyPlugins',
351
+ 'args',
352
+ 'config',
353
+ 'cwd',
354
+ 'pkg',
355
+ 'pkgPath',
356
+ 'name',
357
+ 'paths',
358
+ 'userConfig',
359
+ 'env',
360
+ 'isPluginEnable',
361
+ ],
362
+ staticProps: {
363
+ ApplyPluginsType: types_1.ApplyPluginsType,
364
+ ConfigChangeType: types_1.ConfigChangeType,
365
+ EnableBy: types_1.EnableBy,
366
+ ServiceStage: types_1.ServiceStage,
329
367
  service: this,
330
- pluginAPI,
331
- serviceProps: [
332
- 'appData',
333
- 'applyPlugins',
334
- 'args',
335
- 'config',
336
- 'cwd',
337
- 'pkg',
338
- 'pkgPath',
339
- 'name',
340
- 'paths',
341
- 'userConfig',
342
- 'env',
343
- 'isPluginEnable',
344
- ],
345
- staticProps: {
346
- ApplyPluginsType: types_1.ApplyPluginsType,
347
- ConfigChangeType: types_1.ConfigChangeType,
348
- EnableBy: types_1.EnableBy,
349
- ServiceStage: types_1.ServiceStage,
350
- service: this,
351
- },
352
- });
353
- let dateStart = new Date();
354
- let ret = yield opts.plugin.apply()(proxyPluginAPI);
355
- opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
356
- if (opts.plugin.type === 'plugin') {
357
- (0, assert_1.default)(!ret, `plugin should return nothing`);
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;
362
- if (ret === null || ret === void 0 ? void 0 : ret.presets) {
363
- ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
364
- path: preset,
365
- type: types_1.PluginType.preset,
366
- cwd: this.cwd,
367
- }));
368
- }
369
- if (ret === null || ret === void 0 ? void 0 : ret.plugins) {
370
- ret.plugins = ret.plugins.map((plugin) => new plugin_1.Plugin({
371
- path: plugin,
372
- type: types_1.PluginType.plugin,
373
- cwd: this.cwd,
374
- }));
375
- }
376
- return ret || {};
368
+ },
377
369
  });
370
+ let dateStart = new Date();
371
+ let ret = await opts.plugin.apply()(proxyPluginAPI);
372
+ opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
373
+ if (opts.plugin.type === 'plugin') {
374
+ (0, assert_1.default)(!ret, `plugin should return nothing`);
375
+ }
376
+ // key should be unique
377
+ (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.`);
378
+ this.keyToPluginMap[opts.plugin.key] = opts.plugin;
379
+ if (ret === null || ret === void 0 ? void 0 : ret.presets) {
380
+ ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
381
+ path: preset,
382
+ type: types_1.PluginType.preset,
383
+ cwd: this.cwd,
384
+ }));
385
+ }
386
+ if (ret === null || ret === void 0 ? void 0 : ret.plugins) {
387
+ ret.plugins = ret.plugins.map((plugin) => new plugin_1.Plugin({
388
+ path: plugin,
389
+ type: types_1.PluginType.plugin,
390
+ cwd: this.cwd,
391
+ }));
392
+ }
393
+ return ret || {};
378
394
  }
379
395
  isPluginEnable(hook) {
380
396
  let plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "4.0.0-rc.12",
3
+ "version": "4.0.0-rc.15",
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": {
@@ -16,20 +16,19 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "pnpm tsc",
19
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
19
+ "build:deps": "umi-scripts bundleDeps",
20
20
  "dev": "pnpm build -- --watch",
21
- "test": "jest -c ../../jest.turbo.config.ts"
21
+ "test": "umi-scripts jest-turbo"
22
22
  },
23
23
  "dependencies": {
24
- "@umijs/bundler-utils": "4.0.0-rc.12",
25
- "@umijs/utils": "4.0.0-rc.12"
24
+ "@umijs/bundler-utils": "4.0.0-rc.15",
25
+ "@umijs/utils": "4.0.0-rc.15"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@hapi/joi": "17.1.1",
29
29
  "@types/hapi__joi": "17.1.8",
30
30
  "dotenv": "16.0.0",
31
- "just-diff": "5.0.1",
32
- "tapable": "2.2.1"
31
+ "just-diff": "5.0.1"
33
32
  },
34
33
  "publishConfig": {
35
34
  "access": "public"
@@ -41,14 +40,13 @@
41
40
  "deps": [
42
41
  "@hapi/joi",
43
42
  "dotenv",
44
- "just-diff",
45
- "tapable"
43
+ "just-diff"
46
44
  ],
47
45
  "externals": {
48
46
  "@hapi/joi": "$$LOCAL",
49
47
  "dotenv": "$$LOCAL",
50
48
  "just-diff": "$$LOCAL",
51
- "tapable": "$$LOCAL"
49
+ "tapable": "@umijs/bundler-utils/compiled/tapable"
52
50
  }
53
51
  }
54
52
  }
@@ -1,21 +0,0 @@
1
- The MIT License
2
-
3
- Copyright JS Foundation and other contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1 +0,0 @@
1
- (function(){"use strict";var e={131:function(e,t,n){const o=n(246);const r=n(431);class AsyncParallelBailHookCodeFactory extends r{content({onError:e,onResult:t,onDone:n}){let o="";o+=`var _results = new Array(${this.options.taps.length});\n`;o+="var _checkDone = function() {\n";o+="for(var i = 0; i < _results.length; i++) {\n";o+="var item = _results[i];\n";o+="if(item === undefined) return false;\n";o+="if(item.result !== undefined) {\n";o+=t("item.result");o+="return true;\n";o+="}\n";o+="if(item.error) {\n";o+=e("item.error");o+="return true;\n";o+="}\n";o+="}\n";o+="return false;\n";o+="}\n";o+=this.callTapsParallel({onError:(e,t,n,o)=>{let r="";r+=`if(${e} < _results.length && ((_results.length = ${e+1}), (_results[${e}] = { error: ${t} }), _checkDone())) {\n`;r+=o(true);r+="} else {\n";r+=n();r+="}\n";return r},onResult:(e,t,n,o)=>{let r="";r+=`if(${e} < _results.length && (${t} !== undefined && (_results.length = ${e+1}), (_results[${e}] = { result: ${t} }), _checkDone())) {\n`;r+=o(true);r+="} else {\n";r+=n();r+="}\n";return r},onTap:(e,t,n,o)=>{let r="";if(e>0){r+=`if(${e} >= _results.length) {\n`;r+=n();r+="} else {\n"}r+=t();if(e>0)r+="}\n";return r},onDone:n});return o}}const s=new AsyncParallelBailHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncParallelBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncParallelBailHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncParallelBailHook.prototype=null;e.exports=AsyncParallelBailHook},834:function(e,t,n){const o=n(246);const r=n(431);class AsyncParallelHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsParallel({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncParallelHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncParallelHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncParallelHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncParallelHook.prototype=null;e.exports=AsyncParallelHook},179:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesBailHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,onDone:o}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onResult:(e,n,o)=>`if(${n} !== undefined) {\n${t(n)}\n} else {\n${o()}}\n`,resultReturns:n,onDone:o})}}const s=new AsyncSeriesBailHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesBailHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesBailHook.prototype=null;e.exports=AsyncSeriesBailHook},1:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncSeriesHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesHook.prototype=null;e.exports=AsyncSeriesHook},843:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesLoopHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsLooping({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncSeriesLoopHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesLoopHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesLoopHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesLoopHook.prototype=null;e.exports=AsyncSeriesLoopHook},371:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesWaterfallHookCodeFactory extends r{content({onError:e,onResult:t,onDone:n}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onResult:(e,t,n)=>{let o="";o+=`if(${t} !== undefined) {\n`;o+=`${this._args[0]} = ${t};\n`;o+=`}\n`;o+=n();return o},onDone:()=>t(this._args[0])})}}const s=new AsyncSeriesWaterfallHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesWaterfallHook(e=[],t=undefined){if(e.length<1)throw new Error("Waterfall hooks must have at least one argument");const n=new o(e,t);n.constructor=AsyncSeriesWaterfallHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesWaterfallHook.prototype=null;e.exports=AsyncSeriesWaterfallHook},246:function(e,t,n){const o=n(669);const r=o.deprecate((()=>{}),"Hook.context is deprecated and will be removed");const CALL_DELEGATE=function(...e){this.call=this._createCall("sync");return this.call(...e)};const CALL_ASYNC_DELEGATE=function(...e){this.callAsync=this._createCall("async");return this.callAsync(...e)};const PROMISE_DELEGATE=function(...e){this.promise=this._createCall("promise");return this.promise(...e)};class Hook{constructor(e=[],t=undefined){this._args=e;this.name=t;this.taps=[];this.interceptors=[];this._call=CALL_DELEGATE;this.call=CALL_DELEGATE;this._callAsync=CALL_ASYNC_DELEGATE;this.callAsync=CALL_ASYNC_DELEGATE;this._promise=PROMISE_DELEGATE;this.promise=PROMISE_DELEGATE;this._x=undefined;this.compile=this.compile;this.tap=this.tap;this.tapAsync=this.tapAsync;this.tapPromise=this.tapPromise}compile(e){throw new Error("Abstract: should be overridden")}_createCall(e){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:e})}_tap(e,t,n){if(typeof t==="string"){t={name:t.trim()}}else if(typeof t!=="object"||t===null){throw new Error("Invalid tap options")}if(typeof t.name!=="string"||t.name===""){throw new Error("Missing name for tap")}if(typeof t.context!=="undefined"){r()}t=Object.assign({type:e,fn:n},t);t=this._runRegisterInterceptors(t);this._insert(t)}tap(e,t){this._tap("sync",e,t)}tapAsync(e,t){this._tap("async",e,t)}tapPromise(e,t){this._tap("promise",e,t)}_runRegisterInterceptors(e){for(const t of this.interceptors){if(t.register){const n=t.register(e);if(n!==undefined){e=n}}}return e}withOptions(e){const mergeOptions=t=>Object.assign({},e,typeof t==="string"?{name:t}:t);return{name:this.name,tap:(e,t)=>this.tap(mergeOptions(e),t),tapAsync:(e,t)=>this.tapAsync(mergeOptions(e),t),tapPromise:(e,t)=>this.tapPromise(mergeOptions(e),t),intercept:e=>this.intercept(e),isUsed:()=>this.isUsed(),withOptions:e=>this.withOptions(mergeOptions(e))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(e){this._resetCompilation();this.interceptors.push(Object.assign({},e));if(e.register){for(let t=0;t<this.taps.length;t++){this.taps[t]=e.register(this.taps[t])}}}_resetCompilation(){this.call=this._call;this.callAsync=this._callAsync;this.promise=this._promise}_insert(e){this._resetCompilation();let t;if(typeof e.before==="string"){t=new Set([e.before])}else if(Array.isArray(e.before)){t=new Set(e.before)}let n=0;if(typeof e.stage==="number"){n=e.stage}let o=this.taps.length;while(o>0){o--;const e=this.taps[o];this.taps[o+1]=e;const r=e.stage||0;if(t){if(t.has(e.name)){t.delete(e.name);continue}if(t.size>0){continue}}if(r>n){continue}o++;break}this.taps[o]=e}}Object.setPrototypeOf(Hook.prototype,null);e.exports=Hook},431:function(e){class HookCodeFactory{constructor(e){this.config=e;this.options=undefined;this._args=undefined}create(e){this.init(e);let t;switch(this.options.type){case"sync":t=new Function(this.args(),'"use strict";\n'+this.header()+this.contentWithInterceptors({onError:e=>`throw ${e};\n`,onResult:e=>`return ${e};\n`,resultReturns:true,onDone:()=>"",rethrowIfPossible:true}));break;case"async":t=new Function(this.args({after:"_callback"}),'"use strict";\n'+this.header()+this.contentWithInterceptors({onError:e=>`_callback(${e});\n`,onResult:e=>`_callback(null, ${e});\n`,onDone:()=>"_callback();\n"}));break;case"promise":let e=false;const n=this.contentWithInterceptors({onError:t=>{e=true;return`_error(${t});\n`},onResult:e=>`_resolve(${e});\n`,onDone:()=>"_resolve();\n"});let o="";o+='"use strict";\n';o+=this.header();o+="return new Promise((function(_resolve, _reject) {\n";if(e){o+="var _sync = true;\n";o+="function _error(_err) {\n";o+="if(_sync)\n";o+="_resolve(Promise.resolve().then((function() { throw _err; })));\n";o+="else\n";o+="_reject(_err);\n";o+="};\n"}o+=n;if(e){o+="_sync = false;\n"}o+="}));\n";t=new Function(this.args(),o);break}this.deinit();return t}setup(e,t){e._x=t.taps.map((e=>e.fn))}init(e){this.options=e;this._args=e.args.slice()}deinit(){this.options=undefined;this._args=undefined}contentWithInterceptors(e){if(this.options.interceptors.length>0){const t=e.onError;const n=e.onResult;const o=e.onDone;let r="";for(let e=0;e<this.options.interceptors.length;e++){const t=this.options.interceptors[e];if(t.call){r+=`${this.getInterceptor(e)}.call(${this.args({before:t.context?"_context":undefined})});\n`}}r+=this.content(Object.assign(e,{onError:t&&(e=>{let n="";for(let t=0;t<this.options.interceptors.length;t++){const o=this.options.interceptors[t];if(o.error){n+=`${this.getInterceptor(t)}.error(${e});\n`}}n+=t(e);return n}),onResult:n&&(e=>{let t="";for(let n=0;n<this.options.interceptors.length;n++){const o=this.options.interceptors[n];if(o.result){t+=`${this.getInterceptor(n)}.result(${e});\n`}}t+=n(e);return t}),onDone:o&&(()=>{let e="";for(let t=0;t<this.options.interceptors.length;t++){const n=this.options.interceptors[t];if(n.done){e+=`${this.getInterceptor(t)}.done();\n`}}e+=o();return e})}));return r}else{return this.content(e)}}header(){let e="";if(this.needContext()){e+="var _context = {};\n"}else{e+="var _context;\n"}e+="var _x = this._x;\n";if(this.options.interceptors.length>0){e+="var _taps = this.taps;\n";e+="var _interceptors = this.interceptors;\n"}return e}needContext(){for(const e of this.options.taps)if(e.context)return true;return false}callTap(e,{onError:t,onResult:n,onDone:o,rethrowIfPossible:r}){let s="";let i=false;for(let t=0;t<this.options.interceptors.length;t++){const n=this.options.interceptors[t];if(n.tap){if(!i){s+=`var _tap${e} = ${this.getTap(e)};\n`;i=true}s+=`${this.getInterceptor(t)}.tap(${n.context?"_context, ":""}_tap${e});\n`}}s+=`var _fn${e} = ${this.getTapFn(e)};\n`;const c=this.options.taps[e];switch(c.type){case"sync":if(!r){s+=`var _hasError${e} = false;\n`;s+="try {\n"}if(n){s+=`var _result${e} = _fn${e}(${this.args({before:c.context?"_context":undefined})});\n`}else{s+=`_fn${e}(${this.args({before:c.context?"_context":undefined})});\n`}if(!r){s+="} catch(_err) {\n";s+=`_hasError${e} = true;\n`;s+=t("_err");s+="}\n";s+=`if(!_hasError${e}) {\n`}if(n){s+=n(`_result${e}`)}if(o){s+=o()}if(!r){s+="}\n"}break;case"async":let i="";if(n)i+=`(function(_err${e}, _result${e}) {\n`;else i+=`(function(_err${e}) {\n`;i+=`if(_err${e}) {\n`;i+=t(`_err${e}`);i+="} else {\n";if(n){i+=n(`_result${e}`)}if(o){i+=o()}i+="}\n";i+="})";s+=`_fn${e}(${this.args({before:c.context?"_context":undefined,after:i})});\n`;break;case"promise":s+=`var _hasResult${e} = false;\n`;s+=`var _promise${e} = _fn${e}(${this.args({before:c.context?"_context":undefined})});\n`;s+=`if (!_promise${e} || !_promise${e}.then)\n`;s+=` throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise${e} + ')');\n`;s+=`_promise${e}.then((function(_result${e}) {\n`;s+=`_hasResult${e} = true;\n`;if(n){s+=n(`_result${e}`)}if(o){s+=o()}s+=`}), function(_err${e}) {\n`;s+=`if(_hasResult${e}) throw _err${e};\n`;s+=t(`_err${e}`);s+="});\n";break}return s}callTapsSeries({onError:e,onResult:t,resultReturns:n,onDone:o,doneReturns:r,rethrowIfPossible:s}){if(this.options.taps.length===0)return o();const i=this.options.taps.findIndex((e=>e.type!=="sync"));const c=n||r;let a="";let l=o;let p=0;for(let n=this.options.taps.length-1;n>=0;n--){const r=n;const u=l!==o&&(this.options.taps[r].type!=="sync"||p++>20);if(u){p=0;a+=`function _next${r}() {\n`;a+=l();a+=`}\n`;l=()=>`${c?"return ":""}_next${r}();\n`}const f=l;const doneBreak=e=>{if(e)return"";return o()};const h=this.callTap(r,{onError:t=>e(r,t,f,doneBreak),onResult:t&&(e=>t(r,e,f,doneBreak)),onDone:!t&&f,rethrowIfPossible:s&&(i<0||r<i)});l=()=>h}a+=l();return a}callTapsLooping({onError:e,onDone:t,rethrowIfPossible:n}){if(this.options.taps.length===0)return t();const o=this.options.taps.every((e=>e.type==="sync"));let r="";if(!o){r+="var _looper = (function() {\n";r+="var _loopAsync = false;\n"}r+="var _loop;\n";r+="do {\n";r+="_loop = false;\n";for(let e=0;e<this.options.interceptors.length;e++){const t=this.options.interceptors[e];if(t.loop){r+=`${this.getInterceptor(e)}.loop(${this.args({before:t.context?"_context":undefined})});\n`}}r+=this.callTapsSeries({onError:e,onResult:(e,t,n,r)=>{let s="";s+=`if(${t} !== undefined) {\n`;s+="_loop = true;\n";if(!o)s+="if(_loopAsync) _looper();\n";s+=r(true);s+=`} else {\n`;s+=n();s+=`}\n`;return s},onDone:t&&(()=>{let e="";e+="if(!_loop) {\n";e+=t();e+="}\n";return e}),rethrowIfPossible:n&&o});r+="} while(_loop);\n";if(!o){r+="_loopAsync = true;\n";r+="});\n";r+="_looper();\n"}return r}callTapsParallel({onError:e,onResult:t,onDone:n,rethrowIfPossible:o,onTap:r=((e,t)=>t())}){if(this.options.taps.length<=1){return this.callTapsSeries({onError:e,onResult:t,onDone:n,rethrowIfPossible:o})}let s="";s+="do {\n";s+=`var _counter = ${this.options.taps.length};\n`;if(n){s+="var _done = (function() {\n";s+=n();s+="});\n"}for(let i=0;i<this.options.taps.length;i++){const done=()=>{if(n)return"if(--_counter === 0) _done();\n";else return"--_counter;"};const doneBreak=e=>{if(e||!n)return"_counter = 0;\n";else return"_counter = 0;\n_done();\n"};s+="if(_counter <= 0) break;\n";s+=r(i,(()=>this.callTap(i,{onError:t=>{let n="";n+="if(_counter > 0) {\n";n+=e(i,t,done,doneBreak);n+="}\n";return n},onResult:t&&(e=>{let n="";n+="if(_counter > 0) {\n";n+=t(i,e,done,doneBreak);n+="}\n";return n}),onDone:!t&&(()=>done()),rethrowIfPossible:o})),done,doneBreak)}s+="} while(false);\n";return s}args({before:e,after:t}={}){let n=this._args;if(e)n=[e].concat(n);if(t)n=n.concat(t);if(n.length===0){return""}else{return n.join(", ")}}getTapFn(e){return`_x[${e}]`}getTap(e){return`_taps[${e}]`}getInterceptor(e){return`_interceptors[${e}]`}}e.exports=HookCodeFactory},278:function(e,t,n){const o=n(669);const defaultFactory=(e,t)=>t;class HookMap{constructor(e,t=undefined){this._map=new Map;this.name=t;this._factory=e;this._interceptors=[]}get(e){return this._map.get(e)}for(e){const t=this.get(e);if(t!==undefined){return t}let n=this._factory(e);const o=this._interceptors;for(let t=0;t<o.length;t++){n=o[t].factory(e,n)}this._map.set(e,n);return n}intercept(e){this._interceptors.push(Object.assign({factory:defaultFactory},e))}}HookMap.prototype.tap=o.deprecate((function(e,t,n){return this.for(e).tap(t,n)}),"HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead.");HookMap.prototype.tapAsync=o.deprecate((function(e,t,n){return this.for(e).tapAsync(t,n)}),"HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead.");HookMap.prototype.tapPromise=o.deprecate((function(e,t,n){return this.for(e).tapPromise(t,n)}),"HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead.");e.exports=HookMap},310:function(e,t,n){const o=n(246);class MultiHook{constructor(e,t=undefined){this.hooks=e;this.name=t}tap(e,t){for(const n of this.hooks){n.tap(e,t)}}tapAsync(e,t){for(const n of this.hooks){n.tapAsync(e,t)}}tapPromise(e,t){for(const n of this.hooks){n.tapPromise(e,t)}}isUsed(){for(const e of this.hooks){if(e.isUsed())return true}return false}intercept(e){for(const t of this.hooks){t.intercept(e)}}withOptions(e){return new MultiHook(this.hooks.map((t=>t.withOptions(e))),this.name)}}e.exports=MultiHook},487:function(e,t,n){const o=n(246);const r=n(431);class SyncBailHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,onDone:o,rethrowIfPossible:r}){return this.callTapsSeries({onError:(t,n)=>e(n),onResult:(e,n,o)=>`if(${n} !== undefined) {\n${t(n)};\n} else {\n${o()}}\n`,resultReturns:n,onDone:o,rethrowIfPossible:r})}}const s=new SyncBailHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncBailHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncBailHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncBailHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncBailHook.prototype=null;e.exports=SyncBailHook},75:function(e,t,n){const o=n(246);const r=n(431);class SyncHookCodeFactory extends r{content({onError:e,onDone:t,rethrowIfPossible:n}){return this.callTapsSeries({onError:(t,n)=>e(n),onDone:t,rethrowIfPossible:n})}}const s=new SyncHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncHook.prototype=null;e.exports=SyncHook},667:function(e,t,n){const o=n(246);const r=n(431);class SyncLoopHookCodeFactory extends r{content({onError:e,onDone:t,rethrowIfPossible:n}){return this.callTapsLooping({onError:(t,n)=>e(n),onDone:t,rethrowIfPossible:n})}}const s=new SyncLoopHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncLoopHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncLoopHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncLoopHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncLoopHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncLoopHook.prototype=null;e.exports=SyncLoopHook},303:function(e,t,n){const o=n(246);const r=n(431);class SyncWaterfallHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,rethrowIfPossible:o}){return this.callTapsSeries({onError:(t,n)=>e(n),onResult:(e,t,n)=>{let o="";o+=`if(${t} !== undefined) {\n`;o+=`${this._args[0]} = ${t};\n`;o+=`}\n`;o+=n();return o},onDone:()=>t(this._args[0]),doneReturns:n,rethrowIfPossible:o})}}const s=new SyncWaterfallHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncWaterfallHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncWaterfallHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncWaterfallHook(e=[],t=undefined){if(e.length<1)throw new Error("Waterfall hooks must have at least one argument");const n=new o(e,t);n.constructor=SyncWaterfallHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncWaterfallHook.prototype=null;e.exports=SyncWaterfallHook},669:function(e){e.exports=require("util")}};var t={};function __nccwpck_require__(n){var o=t[n];if(o!==undefined){return o.exports}var r=t[n]={exports:{}};var s=true;try{e[n](r,r.exports,__nccwpck_require__);s=false}finally{if(s)delete t[n]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n={};!function(){var e=n;e.__esModule=true;e.SyncHook=__nccwpck_require__(75);e.SyncBailHook=__nccwpck_require__(487);e.SyncWaterfallHook=__nccwpck_require__(303);e.SyncLoopHook=__nccwpck_require__(667);e.AsyncParallelHook=__nccwpck_require__(834);e.AsyncParallelBailHook=__nccwpck_require__(131);e.AsyncSeriesHook=__nccwpck_require__(1);e.AsyncSeriesBailHook=__nccwpck_require__(179);e.AsyncSeriesLoopHook=__nccwpck_require__(843);e.AsyncSeriesWaterfallHook=__nccwpck_require__(371);e.HookMap=__nccwpck_require__(278);e.MultiHook=__nccwpck_require__(310)}();module.exports=n})();
@@ -1 +0,0 @@
1
- {"name":"tapable","author":"Tobias Koppers @sokra","license":"MIT","types":"./tapable.d.ts"}
@@ -1,116 +0,0 @@
1
- type FixedSizeArray<T extends number, U> = T extends 0
2
- ? void[]
3
- : ReadonlyArray<U> & {
4
- 0: U;
5
- length: T;
6
- };
7
- type Measure<T extends number> = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
8
- ? T
9
- : never;
10
- type Append<T extends any[], U> = {
11
- 0: [U];
12
- 1: [T[0], U];
13
- 2: [T[0], T[1], U];
14
- 3: [T[0], T[1], T[2], U];
15
- 4: [T[0], T[1], T[2], T[3], U];
16
- 5: [T[0], T[1], T[2], T[3], T[4], U];
17
- 6: [T[0], T[1], T[2], T[3], T[4], T[5], U];
18
- 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U];
19
- 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U];
20
- }[Measure<T["length"]>];
21
- type AsArray<T> = T extends any[] ? T : [T];
22
-
23
- declare class UnsetAdditionalOptions {
24
- _UnsetAdditionalOptions: true
25
- }
26
- type IfSet<X> = X extends UnsetAdditionalOptions ? {} : X;
27
-
28
- type Callback<E, T> = (error: E | null, result?: T) => void;
29
- type InnerCallback<E, T> = (error?: E | null | false, result?: T) => void;
30
-
31
- type FullTap = Tap & {
32
- type: "sync" | "async" | "promise",
33
- fn: Function
34
- }
35
-
36
- type Tap = TapOptions & {
37
- name: string;
38
- };
39
-
40
- type TapOptions = {
41
- before?: string;
42
- stage?: number;
43
- };
44
-
45
- interface HookInterceptor<T, R, AdditionalOptions = UnsetAdditionalOptions> {
46
- name?: string;
47
- tap?: (tap: FullTap & IfSet<AdditionalOptions>) => void;
48
- call?: (...args: any[]) => void;
49
- loop?: (...args: any[]) => void;
50
- error?: (err: Error) => void;
51
- result?: (result: R) => void;
52
- done?: () => void;
53
- register?: (tap: FullTap & IfSet<AdditionalOptions>) => FullTap & IfSet<AdditionalOptions>;
54
- }
55
-
56
- type ArgumentNames<T extends any[]> = FixedSizeArray<T["length"], string>;
57
-
58
- declare class Hook<T, R, AdditionalOptions = UnsetAdditionalOptions> {
59
- constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
60
- name: string | undefined;
61
- taps: FullTap[];
62
- intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void;
63
- isUsed(): boolean;
64
- callAsync(...args: Append<AsArray<T>, Callback<Error, R>>): void;
65
- promise(...args: AsArray<T>): Promise<R>;
66
- tap(options: string | Tap & IfSet<AdditionalOptions>, fn: (...args: AsArray<T>) => R): void;
67
- withOptions(options: TapOptions & IfSet<AdditionalOptions>): Omit<this, "call" | "callAsync" | "promise">;
68
- }
69
-
70
- export class SyncHook<T, R = void, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
71
- call(...args: AsArray<T>): R;
72
- }
73
-
74
- export class SyncBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, R, AdditionalOptions> {}
75
- export class SyncLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, void, AdditionalOptions> {}
76
- export class SyncWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, AsArray<T>[0], AdditionalOptions> {}
77
-
78
- declare class AsyncHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
79
- tapAsync(
80
- options: string | Tap & IfSet<AdditionalOptions>,
81
- fn: (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void
82
- ): void;
83
- tapPromise(
84
- options: string | Tap & IfSet<AdditionalOptions>,
85
- fn: (...args: AsArray<T>) => Promise<R>
86
- ): void;
87
- }
88
-
89
- export class AsyncParallelHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
90
- export class AsyncParallelBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {}
91
- export class AsyncSeriesHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
92
- export class AsyncSeriesBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {}
93
- export class AsyncSeriesLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
94
- export class AsyncSeriesWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, AsArray<T>[0], AdditionalOptions> {}
95
-
96
- type HookFactory<H> = (key: any, hook?: H) => H;
97
-
98
- interface HookMapInterceptor<H> {
99
- factory?: HookFactory<H>;
100
- }
101
-
102
- export class HookMap<H> {
103
- constructor(factory: HookFactory<H>, name?: string);
104
- name: string | undefined;
105
- get(key: any): H | undefined;
106
- for(key: any): H;
107
- intercept(interceptor: HookMapInterceptor<H>): void;
108
- }
109
-
110
- export class MultiHook<H> {
111
- constructor(hooks: H[], name?: string);
112
- name: string | undefined;
113
- tap(options: string | Tap, fn?: Function): void;
114
- tapAsync(options: string | Tap, fn?: Function): void;
115
- tapPromise(options: string | Tap, fn?: Function): void;
116
- }