@modern-js/plugin-v2 2.63.8-alpha.2 → 2.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/run/create.js +14 -23
- package/dist/cjs/runtime/api.js +15 -2
- package/dist/esm/cli/run/create.js +33 -42
- package/dist/esm/runtime/api.js +15 -2
- package/dist/esm-node/cli/run/create.js +14 -23
- package/dist/esm-node/runtime/api.js +15 -2
- package/dist/types/cli/hooks.d.ts +4 -4
- package/dist/types/cli/run/create.d.ts +1 -2
- package/dist/types/cli/run/index.d.ts +4 -4
- package/dist/types/types/cli/api.d.ts +10 -5
- package/dist/types/types/cli/context.d.ts +1 -1
- package/dist/types/types/cli/hooks.d.ts +5 -4
- package/dist/types/types/cli/plugin.d.ts +1 -2
- package/dist/types/types/runtime/api.d.ts +7 -2
- package/package.json +10 -9
|
@@ -37,23 +37,6 @@ const debug = (0, import_utils.createDebugger)("plugin-v2");
|
|
|
37
37
|
const createCli = () => {
|
|
38
38
|
let initOptions;
|
|
39
39
|
const pluginManager = (0, import_manager.createPluginManager)();
|
|
40
|
-
const existListenerMap = /* @__PURE__ */ new Map();
|
|
41
|
-
function createExistListener(event, context) {
|
|
42
|
-
return async function(err) {
|
|
43
|
-
await context.hooks.onBeforeExit.call();
|
|
44
|
-
let hasError = false;
|
|
45
|
-
if (err instanceof Error) {
|
|
46
|
-
import_utils.logger.error(err.stack);
|
|
47
|
-
hasError = true;
|
|
48
|
-
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
49
|
-
console.trace("Unknown Error", err);
|
|
50
|
-
hasError = true;
|
|
51
|
-
}
|
|
52
|
-
process.nextTick(() => {
|
|
53
|
-
process.exit(hasError ? 1 : 0);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
40
|
async function init(options) {
|
|
58
41
|
var _context_hooks_onAfterPrepare, _context_hooks;
|
|
59
42
|
pluginManager.clear();
|
|
@@ -101,12 +84,20 @@ const createCli = () => {
|
|
|
101
84
|
"unhandledRejection",
|
|
102
85
|
"uncaughtException"
|
|
103
86
|
].forEach((event) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
87
|
+
process.on(event, async (err) => {
|
|
88
|
+
await context.hooks.onBeforeExit.call();
|
|
89
|
+
let hasError = false;
|
|
90
|
+
if (err instanceof Error) {
|
|
91
|
+
import_utils.logger.error(err.stack);
|
|
92
|
+
hasError = true;
|
|
93
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
94
|
+
console.trace("Unknown Error", err);
|
|
95
|
+
hasError = true;
|
|
96
|
+
}
|
|
97
|
+
process.nextTick(() => {
|
|
98
|
+
process.exit(hasError ? 1 : 0);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
110
101
|
});
|
|
111
102
|
const extraConfigs = await context.hooks.config.call();
|
|
112
103
|
const normalizedConfig = await (0, import_createResolvedConfig.createResolveConfig)(loaded, extraConfigs);
|
package/dist/cjs/runtime/api.js
CHANGED
|
@@ -26,7 +26,7 @@ function initPluginAPI({ context, plugins }) {
|
|
|
26
26
|
const { hooks, extendsHooks } = context;
|
|
27
27
|
function getRuntimeContext() {
|
|
28
28
|
if (context) {
|
|
29
|
-
const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI, ...runtimeContext } = context;
|
|
29
|
+
const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI: pluginAPI2, ...runtimeContext } = context;
|
|
30
30
|
runtimeContext._internalContext = context;
|
|
31
31
|
return runtimeContext;
|
|
32
32
|
}
|
|
@@ -62,7 +62,7 @@ function initPluginAPI({ context, plugins }) {
|
|
|
62
62
|
extendsPluginApi[hookName] = extendsHooks[hookName].tap;
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
const pluginAPI = {
|
|
66
66
|
updateRuntimeContext,
|
|
67
67
|
getHooks,
|
|
68
68
|
getRuntimeConfig,
|
|
@@ -72,6 +72,19 @@ function initPluginAPI({ context, plugins }) {
|
|
|
72
72
|
pickContext: hooks.pickContext.tap,
|
|
73
73
|
...extendsPluginApi
|
|
74
74
|
};
|
|
75
|
+
return new Proxy(pluginAPI, {
|
|
76
|
+
get(target, prop) {
|
|
77
|
+
if (prop === "then") {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
if (prop in target) {
|
|
81
|
+
return target[prop];
|
|
82
|
+
}
|
|
83
|
+
return () => {
|
|
84
|
+
console.warn(`api.${prop.toString()} not exist`);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
75
88
|
}
|
|
76
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
77
90
|
0 && (module.exports = {
|
|
@@ -16,41 +16,6 @@ import { initAppDir } from "./utils/initAppDir";
|
|
|
16
16
|
import { loadEnv } from "./utils/loadEnv";
|
|
17
17
|
var debug = createDebugger("plugin-v2");
|
|
18
18
|
var createCli = function() {
|
|
19
|
-
var createExistListener = function createExistListener2(event, context) {
|
|
20
|
-
return function() {
|
|
21
|
-
var _ref = _async_to_generator(function(err) {
|
|
22
|
-
var hasError;
|
|
23
|
-
return _ts_generator(this, function(_state) {
|
|
24
|
-
switch (_state.label) {
|
|
25
|
-
case 0:
|
|
26
|
-
return [
|
|
27
|
-
4,
|
|
28
|
-
context.hooks.onBeforeExit.call()
|
|
29
|
-
];
|
|
30
|
-
case 1:
|
|
31
|
-
_state.sent();
|
|
32
|
-
hasError = false;
|
|
33
|
-
if (_instanceof(err, Error)) {
|
|
34
|
-
logger.error(err.stack);
|
|
35
|
-
hasError = true;
|
|
36
|
-
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
37
|
-
console.trace("Unknown Error", err);
|
|
38
|
-
hasError = true;
|
|
39
|
-
}
|
|
40
|
-
process.nextTick(function() {
|
|
41
|
-
process.exit(hasError ? 1 : 0);
|
|
42
|
-
});
|
|
43
|
-
return [
|
|
44
|
-
2
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
return function(err) {
|
|
50
|
-
return _ref.apply(this, arguments);
|
|
51
|
-
};
|
|
52
|
-
}();
|
|
53
|
-
};
|
|
54
19
|
var init = function init2(options) {
|
|
55
20
|
return _init.apply(this, arguments);
|
|
56
21
|
};
|
|
@@ -59,7 +24,6 @@ var createCli = function() {
|
|
|
59
24
|
};
|
|
60
25
|
var initOptions;
|
|
61
26
|
var pluginManager = createPluginManager();
|
|
62
|
-
var existListenerMap = /* @__PURE__ */ new Map();
|
|
63
27
|
function _init() {
|
|
64
28
|
_init = _async_to_generator(function(options) {
|
|
65
29
|
var _context_hooks_onAfterPrepare, _context_hooks, _options_metaName, metaName, configFile, config, command, version, packageJsonConfig, internalPlugins, handleSetupResult, appDirectory, loaded, allPlugins, plugins, context, pluginAPI, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _plugin_setup, setupResult, err, extraConfigs, normalizedConfig, resolved;
|
|
@@ -194,12 +158,39 @@ var createCli = function() {
|
|
|
194
158
|
"unhandledRejection",
|
|
195
159
|
"uncaughtException"
|
|
196
160
|
].forEach(function(event) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
161
|
+
process.on(event, function() {
|
|
162
|
+
var _ref = _async_to_generator(function(err2) {
|
|
163
|
+
var hasError;
|
|
164
|
+
return _ts_generator(this, function(_state2) {
|
|
165
|
+
switch (_state2.label) {
|
|
166
|
+
case 0:
|
|
167
|
+
return [
|
|
168
|
+
4,
|
|
169
|
+
context.hooks.onBeforeExit.call()
|
|
170
|
+
];
|
|
171
|
+
case 1:
|
|
172
|
+
_state2.sent();
|
|
173
|
+
hasError = false;
|
|
174
|
+
if (_instanceof(err2, Error)) {
|
|
175
|
+
logger.error(err2.stack);
|
|
176
|
+
hasError = true;
|
|
177
|
+
} else if (err2 && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
178
|
+
console.trace("Unknown Error", err2);
|
|
179
|
+
hasError = true;
|
|
180
|
+
}
|
|
181
|
+
process.nextTick(function() {
|
|
182
|
+
process.exit(hasError ? 1 : 0);
|
|
183
|
+
});
|
|
184
|
+
return [
|
|
185
|
+
2
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
return function(err2) {
|
|
191
|
+
return _ref.apply(this, arguments);
|
|
192
|
+
};
|
|
193
|
+
}());
|
|
203
194
|
});
|
|
204
195
|
return [
|
|
205
196
|
4,
|
package/dist/esm/runtime/api.js
CHANGED
|
@@ -6,7 +6,7 @@ function initPluginAPI(param) {
|
|
|
6
6
|
var hooks = context.hooks, extendsHooks = context.extendsHooks;
|
|
7
7
|
function getRuntimeContext() {
|
|
8
8
|
if (context) {
|
|
9
|
-
var hooks2 = context.hooks, extendsHooks2 = context.extendsHooks, config = context.config,
|
|
9
|
+
var hooks2 = context.hooks, extendsHooks2 = context.extendsHooks, config = context.config, pluginAPI2 = context.pluginAPI, runtimeContext = _object_without_properties(context, [
|
|
10
10
|
"hooks",
|
|
11
11
|
"extendsHooks",
|
|
12
12
|
"config",
|
|
@@ -44,7 +44,7 @@ function initPluginAPI(param) {
|
|
|
44
44
|
extendsPluginApi[hookName] = extendsHooks[hookName].tap;
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
var pluginAPI = _object_spread({
|
|
48
48
|
updateRuntimeContext,
|
|
49
49
|
getHooks,
|
|
50
50
|
getRuntimeConfig,
|
|
@@ -53,6 +53,19 @@ function initPluginAPI(param) {
|
|
|
53
53
|
wrapRoot: hooks.wrapRoot.tap,
|
|
54
54
|
pickContext: hooks.pickContext.tap
|
|
55
55
|
}, extendsPluginApi);
|
|
56
|
+
return new Proxy(pluginAPI, {
|
|
57
|
+
get: function get(target, prop) {
|
|
58
|
+
if (prop === "then") {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
if (prop in target) {
|
|
62
|
+
return target[prop];
|
|
63
|
+
}
|
|
64
|
+
return function() {
|
|
65
|
+
console.warn("api.".concat(prop.toString(), " not exist"));
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
56
69
|
}
|
|
57
70
|
export {
|
|
58
71
|
initPluginAPI
|
|
@@ -14,23 +14,6 @@ const debug = createDebugger("plugin-v2");
|
|
|
14
14
|
const createCli = () => {
|
|
15
15
|
let initOptions;
|
|
16
16
|
const pluginManager = createPluginManager();
|
|
17
|
-
const existListenerMap = /* @__PURE__ */ new Map();
|
|
18
|
-
function createExistListener(event, context) {
|
|
19
|
-
return async function(err) {
|
|
20
|
-
await context.hooks.onBeforeExit.call();
|
|
21
|
-
let hasError = false;
|
|
22
|
-
if (err instanceof Error) {
|
|
23
|
-
logger.error(err.stack);
|
|
24
|
-
hasError = true;
|
|
25
|
-
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
26
|
-
console.trace("Unknown Error", err);
|
|
27
|
-
hasError = true;
|
|
28
|
-
}
|
|
29
|
-
process.nextTick(() => {
|
|
30
|
-
process.exit(hasError ? 1 : 0);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
17
|
async function init(options) {
|
|
35
18
|
var _context_hooks_onAfterPrepare, _context_hooks;
|
|
36
19
|
pluginManager.clear();
|
|
@@ -78,12 +61,20 @@ const createCli = () => {
|
|
|
78
61
|
"unhandledRejection",
|
|
79
62
|
"uncaughtException"
|
|
80
63
|
].forEach((event) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
64
|
+
process.on(event, async (err) => {
|
|
65
|
+
await context.hooks.onBeforeExit.call();
|
|
66
|
+
let hasError = false;
|
|
67
|
+
if (err instanceof Error) {
|
|
68
|
+
logger.error(err.stack);
|
|
69
|
+
hasError = true;
|
|
70
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
71
|
+
console.trace("Unknown Error", err);
|
|
72
|
+
hasError = true;
|
|
73
|
+
}
|
|
74
|
+
process.nextTick(() => {
|
|
75
|
+
process.exit(hasError ? 1 : 0);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
87
78
|
});
|
|
88
79
|
const extraConfigs = await context.hooks.config.call();
|
|
89
80
|
const normalizedConfig = await createResolveConfig(loaded, extraConfigs);
|
|
@@ -3,7 +3,7 @@ function initPluginAPI({ context, plugins }) {
|
|
|
3
3
|
const { hooks, extendsHooks } = context;
|
|
4
4
|
function getRuntimeContext() {
|
|
5
5
|
if (context) {
|
|
6
|
-
const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI, ...runtimeContext } = context;
|
|
6
|
+
const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI: pluginAPI2, ...runtimeContext } = context;
|
|
7
7
|
runtimeContext._internalContext = context;
|
|
8
8
|
return runtimeContext;
|
|
9
9
|
}
|
|
@@ -39,7 +39,7 @@ function initPluginAPI({ context, plugins }) {
|
|
|
39
39
|
extendsPluginApi[hookName] = extendsHooks[hookName].tap;
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
const pluginAPI = {
|
|
43
43
|
updateRuntimeContext,
|
|
44
44
|
getHooks,
|
|
45
45
|
getRuntimeConfig,
|
|
@@ -49,6 +49,19 @@ function initPluginAPI({ context, plugins }) {
|
|
|
49
49
|
pickContext: hooks.pickContext.tap,
|
|
50
50
|
...extendsPluginApi
|
|
51
51
|
};
|
|
52
|
+
return new Proxy(pluginAPI, {
|
|
53
|
+
get(target, prop) {
|
|
54
|
+
if (prop === "then") {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
if (prop in target) {
|
|
58
|
+
return target[prop];
|
|
59
|
+
}
|
|
60
|
+
return () => {
|
|
61
|
+
console.warn(`api.${prop.toString()} not exist`);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
52
65
|
}
|
|
53
66
|
export {
|
|
54
67
|
initPluginAPI
|
|
@@ -2,7 +2,7 @@ import type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBefore
|
|
|
2
2
|
import type { AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn } from '../types/cli/hooks';
|
|
3
3
|
import type { DeepPartial } from '../types/utils';
|
|
4
4
|
export type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnBeforeDeployFn, OnBeforeDevFn, OnAfterDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn, };
|
|
5
|
-
export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils
|
|
5
|
+
export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>(): {
|
|
6
6
|
/**
|
|
7
7
|
* add config for this cli plugin
|
|
8
8
|
*/
|
|
@@ -11,11 +11,11 @@ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils, Ex
|
|
|
11
11
|
* @private
|
|
12
12
|
* modify config for this cli plugin
|
|
13
13
|
*/
|
|
14
|
-
modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config
|
|
14
|
+
modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config>>;
|
|
15
15
|
/**
|
|
16
16
|
* modify final config
|
|
17
17
|
*/
|
|
18
|
-
modifyResolvedConfig: import("..").AsyncHook<ModifyResolvedConfigFn<NormalizedConfig
|
|
18
|
+
modifyResolvedConfig: import("..").AsyncHook<ModifyResolvedConfigFn<NormalizedConfig>>;
|
|
19
19
|
modifyRsbuildConfig: import("..").AsyncHook<ModifyRsbuildConfigFn<ExtendBuildUtils>>;
|
|
20
20
|
modifyBundlerChain: import("..").AsyncHook<ModifyBundlerChainFn<ExtendBuildUtils>>;
|
|
21
21
|
modifyRspackConfig: import("..").AsyncHook<ModifyRspackConfigFn<ExtendBuildUtils>>;
|
|
@@ -38,4 +38,4 @@ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils, Ex
|
|
|
38
38
|
onAfterDeploy: import("..").AsyncHook<OnAfterDeployFn>;
|
|
39
39
|
onBeforeExit: import("..").AsyncHook<OnBeforeExitFn>;
|
|
40
40
|
};
|
|
41
|
-
export type Hooks<Config, NormalizedConfig, ExtendBuildUtils
|
|
41
|
+
export type Hooks<Config, NormalizedConfig, ExtendBuildUtils> = ReturnType<typeof initHooks<Config, NormalizedConfig, ExtendBuildUtils>>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { InternalContext } from '../../types/cli/context';
|
|
2
1
|
import type { CLIPluginExtends } from '../../types/cli/plugin';
|
|
3
2
|
import type { CLIRunOptions } from './types';
|
|
4
3
|
export declare const createCli: <Extends extends CLIPluginExtends>() => {
|
|
5
4
|
init: (options: CLIRunOptions<Extends>) => Promise<{
|
|
6
|
-
appContext: InternalContext<Extends>;
|
|
5
|
+
appContext: import("../..").InternalContext<Extends>;
|
|
7
6
|
}>;
|
|
8
7
|
run: (options: CLIRunOptions<Extends>) => Promise<void>;
|
|
9
8
|
getPrevInitOptions: () => CLIRunOptions<Extends>;
|
|
@@ -3,9 +3,9 @@ export { createLoadedConfig } from './config/createLoadedConfig';
|
|
|
3
3
|
export { initAppDir } from './utils/initAppDir';
|
|
4
4
|
export { createCli };
|
|
5
5
|
export declare const cli: {
|
|
6
|
-
init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}
|
|
7
|
-
appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}
|
|
6
|
+
init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<{
|
|
7
|
+
appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
|
|
8
8
|
}>;
|
|
9
|
-
run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}
|
|
10
|
-
getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}
|
|
9
|
+
run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<void>;
|
|
10
|
+
getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
|
|
11
11
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn } from '@rsbuild/core';
|
|
2
2
|
import type { Hooks } from '../../cli/hooks';
|
|
3
|
-
import type { PluginHookTap } from '../hooks';
|
|
3
|
+
import type { PluginHook, PluginHookTap } from '../hooks';
|
|
4
4
|
import type { DeepPartial } from '../utils';
|
|
5
5
|
import type { AppContext } from './context';
|
|
6
6
|
import type { AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn } from './hooks';
|
|
@@ -13,11 +13,11 @@ export type CLIPluginAPI<Extends extends CLIPluginExtends> = Readonly<{
|
|
|
13
13
|
getAppContext: () => Readonly<AppContext<Extends> & Extends['extendContext']>;
|
|
14
14
|
getConfig: () => Readonly<Extends['config']>;
|
|
15
15
|
getNormalizedConfig: () => Readonly<Extends['normalizedConfig']>;
|
|
16
|
-
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']
|
|
16
|
+
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']> & Extends['extendHooks']>;
|
|
17
17
|
updateAppContext: (appContext: DeepPartial<AppContext<Extends> & Extends['extendContext']>) => void;
|
|
18
18
|
config: PluginHookTap<ConfigFn<DeepPartial<Extends['config']>>>;
|
|
19
|
-
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config']
|
|
20
|
-
modifyResolvedConfig: PluginHookTap<ModifyResolvedConfigFn<Extends['normalizedConfig']
|
|
19
|
+
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config']>>;
|
|
20
|
+
modifyResolvedConfig: PluginHookTap<ModifyResolvedConfigFn<Extends['normalizedConfig']>>;
|
|
21
21
|
modifyRsbuildConfig: PluginHookTap<ModifyRsbuildConfigFn<Extends['extendBuildUtils']>>;
|
|
22
22
|
modifyBundlerChain: PluginHookTap<ModifyBundlerChainFn<Extends['extendBuildUtils']>>;
|
|
23
23
|
/** Only works when bundler is Rspack */
|
|
@@ -42,4 +42,9 @@ export type CLIPluginAPI<Extends extends CLIPluginExtends> = Readonly<{
|
|
|
42
42
|
onBeforeDeploy: PluginHookTap<OnBeforeDeployFn>;
|
|
43
43
|
onAfterDeploy: PluginHookTap<OnAfterDeployFn>;
|
|
44
44
|
onBeforeExit: PluginHookTap<OnBeforeExitFn>;
|
|
45
|
-
}
|
|
45
|
+
} & CLIPluginExtendsAPI<Extends>>;
|
|
46
|
+
export type CLIPluginExtendsAPI<Extends extends CLIPluginExtends> = {
|
|
47
|
+
[K in keyof Extends['extendHooks']]: PluginHookTap<Extends['extendHooks'][K] extends PluginHook<infer Args> ? Args extends (...args: any[]) => any ? Args : (...args: any[]) => any : (...args: any[]) => any>;
|
|
48
|
+
} & Extends['extendApi'];
|
|
49
|
+
export type AllKeysForCLIPluginExtendsAPI<Extends extends CLIPluginExtends> = keyof CLIPluginExtendsAPI<Extends>;
|
|
50
|
+
export type AllValueForCLIPluginExtendsAPI<Extends extends CLIPluginExtends> = CLIPluginExtendsAPI<Extends>[AllKeysForCLIPluginExtendsAPI<Extends>];
|
|
@@ -28,7 +28,7 @@ export type AppContext<Extends extends CLIPluginExtends> = {
|
|
|
28
28
|
/** The inner context. */
|
|
29
29
|
export type InternalContext<Extends extends CLIPluginExtends> = AppContext<Extends> & {
|
|
30
30
|
/** All hooks. */
|
|
31
|
-
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']
|
|
31
|
+
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']> & Extends['extendHooks'];
|
|
32
32
|
/** All plugin registry hooks */
|
|
33
33
|
extendsHooks: Extends['extendHooks'];
|
|
34
34
|
/** Current App config. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { WebpackConfig } from '@modern-js/uni-builder';
|
|
2
2
|
import type { Command } from '@modern-js/utils/commander';
|
|
3
3
|
import type { ModifyBundlerChainUtils, ModifyRspackConfigUtils, ModifyWebpackChainUtils, ModifyWebpackConfigUtils, RsbuildConfig, Rspack, RspackChain } from '@rsbuild/core';
|
|
4
|
+
import type { TransformFunction } from '../plugin';
|
|
4
5
|
import type { MaybePromise } from '../utils';
|
|
5
6
|
import type { Entrypoint } from './context';
|
|
6
7
|
declare module '@modern-js/utils/commander' {
|
|
@@ -9,8 +10,8 @@ declare module '@modern-js/utils/commander' {
|
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
export type ConfigFn<Config> = () => Config;
|
|
12
|
-
export type ModifyConfigFn<Config
|
|
13
|
-
export type ModifyResolvedConfigFn<NormalizedConfig
|
|
13
|
+
export type ModifyConfigFn<Config> = TransformFunction<Config>;
|
|
14
|
+
export type ModifyResolvedConfigFn<NormalizedConfig> = TransformFunction<NormalizedConfig>;
|
|
14
15
|
type IPartialMethod = (...script: string[]) => void;
|
|
15
16
|
export interface PartialMethod {
|
|
16
17
|
append: IPartialMethod;
|
|
@@ -43,8 +44,8 @@ export type OnBeforeDevFn = () => Promise<void> | void;
|
|
|
43
44
|
export type OnAfterDevFn = (params: {
|
|
44
45
|
port: number;
|
|
45
46
|
}) => Promise<void> | void;
|
|
46
|
-
export type OnBeforeDeployFn = (options
|
|
47
|
-
export type OnAfterDeployFn = (options
|
|
47
|
+
export type OnBeforeDeployFn = (options: Record<string, any>) => Promise<void> | void;
|
|
48
|
+
export type OnAfterDeployFn = (options: Record<string, any>) => Promise<void> | void;
|
|
48
49
|
export type OnBeforeExitFn = () => void;
|
|
49
50
|
export type ModifyBundlerChainFn<ExtendsUtils> = (chain: RspackChain, utils: ModifyBundlerChainUtils & ExtendsUtils) => MaybePromise<void>;
|
|
50
51
|
export type ModifyRsbuildConfigUtils = {
|
|
@@ -2,14 +2,13 @@ import type { PluginHook } from '../hooks';
|
|
|
2
2
|
import type { Plugin } from '../plugin';
|
|
3
3
|
import type { CLIPluginAPI } from './api';
|
|
4
4
|
import type { AppContext } from './context';
|
|
5
|
-
export interface CLIPluginExtends<Config extends Record<string, any> = {}, NormalizedConfig extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}, ExtendBuildUtils extends Record<string, any> = {}
|
|
5
|
+
export interface CLIPluginExtends<Config extends Record<string, any> = {}, NormalizedConfig extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}, ExtendBuildUtils extends Record<string, any> = {}> {
|
|
6
6
|
config?: Config;
|
|
7
7
|
normalizedConfig?: NormalizedConfig;
|
|
8
8
|
extendContext?: ExtendContext;
|
|
9
9
|
extendApi?: ExtendAPI;
|
|
10
10
|
extendHooks?: ExtendHook;
|
|
11
11
|
extendBuildUtils?: ExtendBuildUtils;
|
|
12
|
-
extendConfigUtils?: ExtendConfigUtils;
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* The type of the CLI plugin object.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PluginHookTap } from '../hooks';
|
|
1
|
+
import type { PluginHook, PluginHookTap } from '../hooks';
|
|
2
2
|
import type { DeepPartial } from '../utils';
|
|
3
3
|
import type { RuntimeContext } from './context';
|
|
4
4
|
import type { Hooks } from './hooks';
|
|
@@ -12,4 +12,9 @@ export type RuntimePluginAPI<Extends extends RuntimePluginExtends> = Readonly<{
|
|
|
12
12
|
wrapRoot: PluginHookTap<WrapRootFn>;
|
|
13
13
|
pickContext: PluginHookTap<PickContextFn<RuntimeContext>>;
|
|
14
14
|
modifyRuntimeConfig: PluginHookTap<ModifyRuntimeConfigFn<Extends['config']>>;
|
|
15
|
-
}
|
|
15
|
+
} & RuntimePluginExtendsAPI<Extends>>;
|
|
16
|
+
export type RuntimePluginExtendsAPI<Extends extends RuntimePluginExtends> = {
|
|
17
|
+
[K in keyof Extends['extendHooks']]: PluginHookTap<Extends['extendHooks'][K] extends PluginHook<infer Args> ? Args extends (...args: any[]) => any ? Args : (...args: any[]) => any : (...args: any[]) => any>;
|
|
18
|
+
} & Extends['extendApi'];
|
|
19
|
+
export type AllKeysForRuntimePluginExtendsAPI<Extends extends RuntimePluginExtends> = keyof RuntimePluginExtendsAPI<Extends>;
|
|
20
|
+
export type AllValueForRuntimePluginExtendsAPI<Extends extends RuntimePluginExtends> = RuntimePluginExtendsAPI<Extends>[AllKeysForRuntimePluginExtendsAPI<Extends>];
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.64.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@swc/helpers": "0.5.13",
|
|
67
|
-
"@modern-js/node-bundle-require": "2.
|
|
68
|
-
"@modern-js/utils": "2.
|
|
69
|
-
"@modern-js/runtime-utils": "2.
|
|
67
|
+
"@modern-js/node-bundle-require": "2.64.0",
|
|
68
|
+
"@modern-js/utils": "2.64.0",
|
|
69
|
+
"@modern-js/runtime-utils": "2.64.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@rsbuild/core": "1.1.13",
|
|
@@ -75,15 +75,16 @@
|
|
|
75
75
|
"@types/node": "^14",
|
|
76
76
|
"jest": "^29",
|
|
77
77
|
"typescript": "^5",
|
|
78
|
-
"@modern-js/
|
|
79
|
-
"@modern-js/
|
|
80
|
-
"@scripts/build": "2.
|
|
81
|
-
"@scripts/jest-config": "2.
|
|
78
|
+
"@modern-js/types": "2.64.0",
|
|
79
|
+
"@modern-js/uni-builder": "2.64.0",
|
|
80
|
+
"@scripts/build": "2.64.0",
|
|
81
|
+
"@scripts/jest-config": "2.64.0"
|
|
82
82
|
},
|
|
83
83
|
"sideEffects": false,
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"registry": "https://registry.npmjs.org/",
|
|
86
|
-
"access": "public"
|
|
86
|
+
"access": "public",
|
|
87
|
+
"provenance": true
|
|
87
88
|
},
|
|
88
89
|
"scripts": {
|
|
89
90
|
"new": "modern-lib new",
|