@modern-js/app-tools 2.62.1 → 2.63.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +2 -2
- package/dist/cjs/index.js +12 -144
- package/dist/cjs/new/compat/hooks.js +165 -0
- package/dist/cjs/new/compat/index.js +60 -0
- package/dist/cjs/new/compat/utils.js +95 -0
- package/dist/cjs/new/constants.js +37 -0
- package/dist/cjs/new/context.js +64 -0
- package/dist/cjs/new/getConfigFile.js +41 -0
- package/dist/cjs/new/index.js +79 -0
- package/dist/cjs/new/loadPlugins.js +57 -0
- package/dist/cjs/new/run.js +67 -0
- package/dist/cjs/new/utils/index.js +34 -0
- package/dist/cjs/old.js +179 -0
- package/dist/cjs/plugins/initialize/index.js +44 -50
- package/dist/cjs/types/new.js +16 -0
- package/dist/cjs/utils/restart.js +2 -2
- package/dist/esm/index.js +7 -249
- package/dist/esm/new/compat/hooks.js +452 -0
- package/dist/esm/new/compat/index.js +41 -0
- package/dist/esm/new/compat/utils.js +69 -0
- package/dist/esm/new/constants.js +10 -0
- package/dist/esm/new/context.js +31 -0
- package/dist/esm/new/getConfigFile.js +11 -0
- package/dist/esm/new/index.js +55 -0
- package/dist/esm/new/loadPlugins.js +94 -0
- package/dist/esm/new/run.js +80 -0
- package/dist/esm/new/utils/index.js +33 -0
- package/dist/esm/old.js +258 -0
- package/dist/esm/plugins/initialize/index.js +61 -64
- package/dist/esm/types/new.js +0 -0
- package/dist/esm/utils/restart.js +1 -1
- package/dist/esm-node/index.js +7 -131
- package/dist/esm-node/new/compat/hooks.js +140 -0
- package/dist/esm-node/new/compat/index.js +36 -0
- package/dist/esm-node/new/compat/utils.js +69 -0
- package/dist/esm-node/new/constants.js +10 -0
- package/dist/esm-node/new/context.js +30 -0
- package/dist/esm-node/new/getConfigFile.js +7 -0
- package/dist/esm-node/new/index.js +52 -0
- package/dist/esm-node/new/loadPlugins.js +33 -0
- package/dist/esm-node/new/run.js +43 -0
- package/dist/esm-node/new/utils/index.js +10 -0
- package/dist/esm-node/old.js +140 -0
- package/dist/esm-node/plugins/initialize/index.js +44 -50
- package/dist/esm-node/types/new.js +0 -0
- package/dist/esm-node/utils/restart.js +1 -1
- package/dist/types/config/default.d.ts +4 -3
- package/dist/types/index.d.ts +6 -16
- package/dist/types/new/compat/hooks.d.ts +7 -0
- package/dist/types/new/compat/index.d.ts +2 -0
- package/dist/types/new/compat/utils.d.ts +6 -0
- package/dist/types/new/constants.d.ts +4 -0
- package/dist/types/new/context.d.ts +33 -0
- package/dist/types/new/getConfigFile.d.ts +1 -0
- package/dist/types/new/index.d.ts +6 -0
- package/dist/types/new/loadPlugins.d.ts +9 -0
- package/dist/types/new/run.d.ts +13 -0
- package/dist/types/new/utils/index.d.ts +1 -0
- package/dist/types/old.d.ts +13 -0
- package/dist/types/plugins/initialize/index.d.ts +2 -2
- package/dist/types/types/index.d.ts +12 -3
- package/dist/types/types/new.d.ts +145 -0
- package/dist/types/utils/env.d.ts +2 -2
- package/dist/types/utils/restart.d.ts +1 -1
- package/lib/types.d.ts +82 -61
- package/package.json +27 -18
@@ -17,72 +17,69 @@ function initialize_default(param) {
|
|
17
17
|
"@modern-js/plugin-polyfill"
|
18
18
|
],
|
19
19
|
setup: function setup(api) {
|
20
|
-
|
21
|
-
var appContext = api.
|
22
|
-
var userConfig = api.
|
23
|
-
api.
|
20
|
+
api.config(function() {
|
21
|
+
var appContext = api.getAppContext();
|
22
|
+
var userConfig = api.getConfig();
|
23
|
+
api.updateAppContext({
|
24
24
|
bundlerType: bundler
|
25
|
-
})
|
25
|
+
});
|
26
26
|
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
|
27
|
-
};
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
})();
|
84
|
-
}
|
85
|
-
};
|
27
|
+
});
|
28
|
+
api.modifyResolvedConfig(function() {
|
29
|
+
var _ref = _async_to_generator(function(resolved) {
|
30
|
+
var _resolved_output_distPath, appContext, userConfig, port, normalizedConfig, _normalizedConfig_autoLoadPlugins;
|
31
|
+
return _ts_generator(this, function(_state) {
|
32
|
+
switch (_state.label) {
|
33
|
+
case 0:
|
34
|
+
appContext = api.getAppContext();
|
35
|
+
userConfig = api.getConfig();
|
36
|
+
return [
|
37
|
+
4,
|
38
|
+
getServerPort(resolved)
|
39
|
+
];
|
40
|
+
case 1:
|
41
|
+
port = _state.sent();
|
42
|
+
appContext = _object_spread_props(_object_spread({}, appContext), {
|
43
|
+
port,
|
44
|
+
distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
45
|
+
});
|
46
|
+
api.updateAppContext(appContext);
|
47
|
+
normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
48
|
+
resolved._raw = userConfig;
|
49
|
+
resolved.server = _object_spread_props(_object_spread({}, normalizedConfig.server || {}), {
|
50
|
+
port
|
51
|
+
});
|
52
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
53
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
54
|
+
"source",
|
55
|
+
"bff",
|
56
|
+
"dev",
|
57
|
+
"html",
|
58
|
+
"output",
|
59
|
+
"tools",
|
60
|
+
"testing",
|
61
|
+
"plugins",
|
62
|
+
"builderPlugins",
|
63
|
+
"runtime",
|
64
|
+
"runtimeByEntries",
|
65
|
+
"deploy",
|
66
|
+
"performance"
|
67
|
+
]);
|
68
|
+
if (bundler === "webpack") {
|
69
|
+
resolved.security = normalizedConfig.security || {};
|
70
|
+
resolved.experiments = normalizedConfig.experiments;
|
71
|
+
}
|
72
|
+
return [
|
73
|
+
2,
|
74
|
+
resolved
|
75
|
+
];
|
76
|
+
}
|
77
|
+
});
|
78
|
+
});
|
79
|
+
return function(resolved) {
|
80
|
+
return _ref.apply(this, arguments);
|
81
|
+
};
|
82
|
+
}());
|
86
83
|
}
|
87
84
|
};
|
88
85
|
}
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
-
import { cli } from "@modern-js/
|
3
|
+
import { cli } from "@modern-js/plugin-v2/cli";
|
4
4
|
import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
|
5
5
|
function restart(hooksRunner, filename) {
|
6
6
|
return _restart.apply(this, arguments);
|
package/dist/esm-node/index.js
CHANGED
@@ -1,140 +1,16 @@
|
|
1
|
-
import
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
5
|
-
import { hooks } from "./hooks";
|
6
|
-
import { i18n } from "./locale";
|
7
|
-
import analyzePlugin from "./plugins/analyze";
|
8
|
-
import deployPlugin from "./plugins/deploy";
|
9
|
-
import initializePlugin from "./plugins/initialize";
|
10
|
-
import serverBuildPlugin from "./plugins/serverBuild";
|
11
|
-
import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
|
12
|
-
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
13
|
-
import { restart } from "./utils/restart";
|
14
|
-
import { dev } from "./commands/dev";
|
1
|
+
import { appTools } from "./new/index";
|
2
|
+
import { initAppContext } from "./new/index";
|
3
|
+
import { defineConfig, defineLegacyConfig } from "./defineConfig";
|
15
4
|
import { mergeConfig } from "@modern-js/core";
|
16
|
-
|
5
|
+
import { dev } from "./commands/dev";
|
17
6
|
export * from "./types";
|
18
|
-
const appTools = (options = {
|
19
|
-
// default webpack to be compatible with original projects
|
20
|
-
bundler: "webpack"
|
21
|
-
}) => ({
|
22
|
-
name: "@modern-js/app-tools",
|
23
|
-
post: [
|
24
|
-
"@modern-js/plugin-initialize",
|
25
|
-
"@modern-js/plugin-analyze",
|
26
|
-
"@modern-js/plugin-ssr",
|
27
|
-
"@modern-js/plugin-document",
|
28
|
-
"@modern-js/plugin-state",
|
29
|
-
"@modern-js/plugin-router",
|
30
|
-
"@modern-js/plugin-router-v5",
|
31
|
-
"@modern-js/plugin-polyfill"
|
32
|
-
],
|
33
|
-
registerHook: hooks,
|
34
|
-
usePlugins: [
|
35
|
-
initializePlugin({
|
36
|
-
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
37
|
-
"rspack",
|
38
|
-
"experimental-rspack"
|
39
|
-
].includes(options.bundler) ? "rspack" : "webpack"
|
40
|
-
}),
|
41
|
-
analyzePlugin({
|
42
|
-
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
43
|
-
"rspack",
|
44
|
-
"experimental-rspack"
|
45
|
-
].includes(options.bundler) ? "rspack" : "webpack"
|
46
|
-
}),
|
47
|
-
serverBuildPlugin(),
|
48
|
-
deployPlugin()
|
49
|
-
],
|
50
|
-
setup: (api) => {
|
51
|
-
const appContext = api.useAppContext();
|
52
|
-
api.setAppContext({
|
53
|
-
...appContext,
|
54
|
-
toolsType: "app-tools"
|
55
|
-
});
|
56
|
-
const locale = getLocaleLanguage();
|
57
|
-
i18n.changeLanguage({
|
58
|
-
locale
|
59
|
-
});
|
60
|
-
return {
|
61
|
-
async beforeConfig() {
|
62
|
-
var _userConfig_output;
|
63
|
-
const userConfig = api.useConfigContext();
|
64
|
-
const appContext2 = api.useAppContext();
|
65
|
-
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
66
|
-
api.setAppContext({
|
67
|
-
...appContext2,
|
68
|
-
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
69
|
-
});
|
70
|
-
}
|
71
|
-
},
|
72
|
-
async commands({ program }) {
|
73
|
-
await devCommand(program, api);
|
74
|
-
await buildCommand(program, api);
|
75
|
-
serverCommand(program, api);
|
76
|
-
deployCommand(program, api);
|
77
|
-
newCommand(program, locale);
|
78
|
-
inspectCommand(program, api);
|
79
|
-
upgradeCommand(program);
|
80
|
-
deprecatedCommands(program);
|
81
|
-
},
|
82
|
-
async prepare() {
|
83
|
-
const command = getCommand();
|
84
|
-
if (command === "deploy") {
|
85
|
-
const isSkipBuild = [
|
86
|
-
"-s",
|
87
|
-
"--skip-build"
|
88
|
-
].some((tag) => {
|
89
|
-
return getArgv().includes(tag);
|
90
|
-
});
|
91
|
-
if (isSkipBuild) {
|
92
|
-
return;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
96
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
97
|
-
if (resolvedConfig.output.cleanDistPath) {
|
98
|
-
const appContext2 = api.useAppContext();
|
99
|
-
await emptyDir(appContext2.distDirectory);
|
100
|
-
}
|
101
|
-
}
|
102
|
-
},
|
103
|
-
async watchFiles() {
|
104
|
-
const appContext2 = api.useAppContext();
|
105
|
-
const config = api.useResolvedConfigContext();
|
106
|
-
const files = await generateWatchFiles(appContext2, config.source.configDir);
|
107
|
-
const watchFiles = castArray(config.dev.watchFiles);
|
108
|
-
watchFiles.forEach(({ type, paths }) => {
|
109
|
-
if (type === "reload-server") {
|
110
|
-
files.push(...Array.isArray(paths) ? paths : [
|
111
|
-
paths
|
112
|
-
]);
|
113
|
-
}
|
114
|
-
});
|
115
|
-
return files;
|
116
|
-
},
|
117
|
-
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
118
|
-
async fileChange(e) {
|
119
|
-
const { filename, eventType, isPrivate } = e;
|
120
|
-
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
121
|
-
const { closeServer } = await import("./utils/createServer.js");
|
122
|
-
await closeServer();
|
123
|
-
await restart(api.useHookRunners(), filename);
|
124
|
-
}
|
125
|
-
},
|
126
|
-
async beforeRestart() {
|
127
|
-
cleanRequireCache([
|
128
|
-
require.resolve("./plugins/analyze")
|
129
|
-
]);
|
130
|
-
}
|
131
|
-
};
|
132
|
-
}
|
133
|
-
});
|
134
7
|
var src_default = appTools;
|
135
8
|
export {
|
136
9
|
appTools,
|
137
10
|
src_default as default,
|
11
|
+
defineConfig,
|
12
|
+
defineLegacyConfig,
|
138
13
|
dev,
|
14
|
+
initAppContext,
|
139
15
|
mergeConfig
|
140
16
|
};
|
@@ -0,0 +1,140 @@
|
|
1
|
+
import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
|
2
|
+
function getHookRunners(context) {
|
3
|
+
const { hooks } = context;
|
4
|
+
return {
|
5
|
+
/**
|
6
|
+
* app tools hooks
|
7
|
+
*/
|
8
|
+
beforeConfig: async () => {
|
9
|
+
return hooks.onBeforeConfig.call();
|
10
|
+
},
|
11
|
+
afterPrepare: async () => {
|
12
|
+
return hooks.onAfterPrepare.call();
|
13
|
+
},
|
14
|
+
deploy: async () => {
|
15
|
+
return hooks.deploy.call();
|
16
|
+
},
|
17
|
+
_internalRuntimePlugins: async (params) => {
|
18
|
+
return hooks._internalRuntimePlugins.call(params);
|
19
|
+
},
|
20
|
+
_internalServerPlugins: async (params) => {
|
21
|
+
return hooks._internalServerPlugins.call(params);
|
22
|
+
},
|
23
|
+
checkEntryPoint: async (params) => {
|
24
|
+
return hooks.checkEntryPoint.call(params);
|
25
|
+
},
|
26
|
+
modifyEntrypoints: async (params) => {
|
27
|
+
return hooks.modifyEntrypoints.call(params);
|
28
|
+
},
|
29
|
+
modifyFileSystemRoutes: async (params) => {
|
30
|
+
return hooks.modifyFileSystemRoutes.call(params);
|
31
|
+
},
|
32
|
+
modifyServerRoutes: async (params) => {
|
33
|
+
return hooks.modifyServerRoutes.call(params);
|
34
|
+
},
|
35
|
+
generateEntryCode: async (params) => {
|
36
|
+
return hooks.generateEntryCode.call(params);
|
37
|
+
},
|
38
|
+
beforeGenerateRoutes: async (params) => {
|
39
|
+
return hooks.onBeforeGenerateRoutes.call(params);
|
40
|
+
},
|
41
|
+
beforePrintInstructions: async (params) => {
|
42
|
+
return hooks.onBeforePrintInstructions.call(params);
|
43
|
+
},
|
44
|
+
// garfish plugin hooks
|
45
|
+
appendEntryCode: async (params) => {
|
46
|
+
const result = await (hooks === null || hooks === void 0 ? void 0 : hooks.appendEntryCode.call(params));
|
47
|
+
return result;
|
48
|
+
},
|
49
|
+
/**
|
50
|
+
* common hooks
|
51
|
+
*/
|
52
|
+
config: async () => {
|
53
|
+
return hooks.config.call();
|
54
|
+
},
|
55
|
+
resolvedConfig: (params) => {
|
56
|
+
return hooks.modifyResolvedConfig.call(params);
|
57
|
+
},
|
58
|
+
htmlPartials: async (params) => {
|
59
|
+
return hooks.modifyHtmlPartials.call(params);
|
60
|
+
},
|
61
|
+
commands: async (params) => {
|
62
|
+
return hooks.addCommand.call(params);
|
63
|
+
},
|
64
|
+
watchFiles: async () => {
|
65
|
+
return hooks.addWatchFiles.call();
|
66
|
+
},
|
67
|
+
prepare: async () => {
|
68
|
+
return hooks.onPrepare.call();
|
69
|
+
},
|
70
|
+
filedChange: async (params) => {
|
71
|
+
return hooks.onFileChanged.call(params);
|
72
|
+
},
|
73
|
+
beforeCreateCompiler: async (params) => {
|
74
|
+
return hooks.onBeforeCreateCompiler.call(params);
|
75
|
+
},
|
76
|
+
afterCreateCompiler: async (params) => {
|
77
|
+
return hooks.onAfterCreateCompiler.call(params);
|
78
|
+
},
|
79
|
+
beforeBuild: async (params) => {
|
80
|
+
return hooks.onBeforeBuild.call(params);
|
81
|
+
},
|
82
|
+
afterBuild: async (params) => {
|
83
|
+
return hooks.onAfterBuild.call(params);
|
84
|
+
},
|
85
|
+
beforeDev: async () => {
|
86
|
+
return hooks.onBeforeDev.call();
|
87
|
+
},
|
88
|
+
afterDev: async (params) => {
|
89
|
+
return hooks.onAfterDev.call(params);
|
90
|
+
},
|
91
|
+
beforeDeploy: async (options) => {
|
92
|
+
return hooks.onBeforeDeploy.call(options);
|
93
|
+
},
|
94
|
+
afterDeploy: async (options) => {
|
95
|
+
return hooks.onAfterDeploy.call(options);
|
96
|
+
},
|
97
|
+
beforeExit: async () => {
|
98
|
+
return hooks.onBeforeExit.call();
|
99
|
+
},
|
100
|
+
beforeRestart: async () => {
|
101
|
+
return hooks.onBeforeRestart.call();
|
102
|
+
},
|
103
|
+
/**
|
104
|
+
* @deprecated
|
105
|
+
*/
|
106
|
+
registerDev: async (params) => {
|
107
|
+
return hooks.registerDev.call(params);
|
108
|
+
},
|
109
|
+
/**
|
110
|
+
* @deprecated
|
111
|
+
*/
|
112
|
+
registerBuildPlatform: async (params) => {
|
113
|
+
return hooks.registerBuildPlatform.call(params);
|
114
|
+
},
|
115
|
+
/**
|
116
|
+
* @deprecated
|
117
|
+
*/
|
118
|
+
addRuntimeExports: async (params) => {
|
119
|
+
return hooks.addRuntimeExports.call(params);
|
120
|
+
}
|
121
|
+
};
|
122
|
+
}
|
123
|
+
function handleSetupResult(setupResult, api) {
|
124
|
+
if (!setupResult) {
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
Object.keys(setupResult).forEach((key) => {
|
128
|
+
const fn = setupResult[key];
|
129
|
+
if (typeof fn === "function") {
|
130
|
+
const newAPI = transformHookRunner(key);
|
131
|
+
if (api[newAPI]) {
|
132
|
+
api[newAPI](async (params) => transformHookResult(key, await fn(transformHookParams(key, params))));
|
133
|
+
}
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
export {
|
138
|
+
getHookRunners,
|
139
|
+
handleSetupResult
|
140
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { createCollectAsyncHook } from "@modern-js/plugin-v2";
|
2
|
+
import { getHookRunners } from "./hooks";
|
3
|
+
const compatPlugin = () => ({
|
4
|
+
name: "@modern-js/app-tools-compat",
|
5
|
+
_registryApi: (getAppContext, updateAppContext) => {
|
6
|
+
const getInternalContext = () => {
|
7
|
+
return getAppContext()._internalContext;
|
8
|
+
};
|
9
|
+
return {
|
10
|
+
useAppContext: () => {
|
11
|
+
const { _internalContext, ...appContext } = getAppContext();
|
12
|
+
return appContext;
|
13
|
+
},
|
14
|
+
setAppContext: (context) => {
|
15
|
+
return updateAppContext(context);
|
16
|
+
},
|
17
|
+
useConfigContext: () => {
|
18
|
+
return getInternalContext().config;
|
19
|
+
},
|
20
|
+
useResolvedConfigContext: () => {
|
21
|
+
return getInternalContext().normalizedConfig;
|
22
|
+
},
|
23
|
+
useHookRunners: () => {
|
24
|
+
return getHookRunners(getInternalContext());
|
25
|
+
}
|
26
|
+
};
|
27
|
+
},
|
28
|
+
registryHooks: {
|
29
|
+
appendEntryCode: createCollectAsyncHook()
|
30
|
+
},
|
31
|
+
setup: (_api) => {
|
32
|
+
}
|
33
|
+
});
|
34
|
+
export {
|
35
|
+
compatPlugin
|
36
|
+
};
|
@@ -0,0 +1,69 @@
|
|
1
|
+
function transformHookRunner(hookRunnerName) {
|
2
|
+
switch (hookRunnerName) {
|
3
|
+
case "beforeConfig":
|
4
|
+
return "onBeforeConfig";
|
5
|
+
case "prepare":
|
6
|
+
return "onPrepare";
|
7
|
+
case "afterPrepare":
|
8
|
+
return "onAfterPrepare";
|
9
|
+
case "beforeGenerateRoutes":
|
10
|
+
return "onBeforeGenerateRoutes";
|
11
|
+
case "beforePrintInstructions":
|
12
|
+
return "onBeforePrintInstructions";
|
13
|
+
case "resolvedConfig":
|
14
|
+
return "modifyResolvedConfig";
|
15
|
+
case "commands":
|
16
|
+
return "addCommand";
|
17
|
+
case "watchFiles":
|
18
|
+
return "addWatchFiles";
|
19
|
+
case "filedChange":
|
20
|
+
return "onFileChanged";
|
21
|
+
case "beforeCreateCompiler":
|
22
|
+
return "onBeforeCreateCompiler";
|
23
|
+
case "afterCreateCompiler":
|
24
|
+
return "onAfterCreateCompiler";
|
25
|
+
case "beforeBuild":
|
26
|
+
return "onBeforeBuild";
|
27
|
+
case "afterBuild":
|
28
|
+
return "onAfterBuild";
|
29
|
+
case "beforeDev":
|
30
|
+
return "onBeforeDev";
|
31
|
+
case "afterDev":
|
32
|
+
return "onAfterDev";
|
33
|
+
case "beforeDeploy":
|
34
|
+
return "onBeforeDeploy";
|
35
|
+
case "afterDeploy":
|
36
|
+
return "onAfterDeploy";
|
37
|
+
case "beforeExit":
|
38
|
+
return "onBeforeExit";
|
39
|
+
case "beforeRestart":
|
40
|
+
return "onBeforeRestart";
|
41
|
+
case "htmlPartials":
|
42
|
+
return "modifyHtmlPartials";
|
43
|
+
default:
|
44
|
+
return hookRunnerName;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
function transformHookParams(hookRunnerName, params) {
|
48
|
+
switch (hookRunnerName) {
|
49
|
+
case "resolvedConfig":
|
50
|
+
return {
|
51
|
+
resolved: params
|
52
|
+
};
|
53
|
+
default:
|
54
|
+
return params;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
function transformHookResult(hookRunnerName, result) {
|
58
|
+
switch (hookRunnerName) {
|
59
|
+
case "resolvedConfig":
|
60
|
+
return result.resolved;
|
61
|
+
default:
|
62
|
+
return result;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
export {
|
66
|
+
transformHookParams,
|
67
|
+
transformHookResult,
|
68
|
+
transformHookRunner
|
69
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
2
|
+
const DEFAULT_CONFIG_FILE = "modern.config";
|
3
|
+
const DEFAULT_SERVER_CONFIG_FILE = "modern.server-runtime.config";
|
4
|
+
const DEFAULT_RUNTIME_CONFIG_FILE = "modern.runtime";
|
5
|
+
export {
|
6
|
+
DEFAULT_CONFIG_FILE,
|
7
|
+
DEFAULT_RUNTIME_CONFIG_FILE,
|
8
|
+
DEFAULT_SERVER_CONFIG_FILE,
|
9
|
+
PACKAGE_JSON_CONFIG_NAME
|
10
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { fs, address } from "@modern-js/utils";
|
3
|
+
const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir }) => {
|
4
|
+
const { metaName = "modern-js", apiDir = "api", distDir = "", sharedDir = "shared" } = options || {};
|
5
|
+
const pkgPath = path.resolve(appDirectory, "./package.json");
|
6
|
+
return {
|
7
|
+
metaName,
|
8
|
+
runtimeConfigFile,
|
9
|
+
serverConfigFile,
|
10
|
+
ip: address.ip(),
|
11
|
+
port: 0,
|
12
|
+
moduleType: fs.existsSync(pkgPath) ? require(pkgPath).type || "commonjs" : "commonjs",
|
13
|
+
apiDirectory: path.resolve(appDirectory, apiDir),
|
14
|
+
lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
|
15
|
+
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
16
|
+
distDirectory: distDir,
|
17
|
+
serverPlugins: [],
|
18
|
+
internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
|
19
|
+
htmlTemplates: {},
|
20
|
+
serverRoutes: [],
|
21
|
+
entrypoints: [],
|
22
|
+
checkedEntries: [],
|
23
|
+
apiOnly: false,
|
24
|
+
internalDirAlias: `@_${metaName.replace(/-/g, "_")}_internal`,
|
25
|
+
internalSrcAlias: `@_${metaName.replace(/-/g, "_")}_src`
|
26
|
+
};
|
27
|
+
};
|
28
|
+
export {
|
29
|
+
initAppContext
|
30
|
+
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
|
3
|
+
import { DEFAULT_CONFIG_FILE } from "./constants";
|
4
|
+
const getConfigFile = (configFile) => findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
|
5
|
+
export {
|
6
|
+
getConfigFile
|
7
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { createAsyncHook } from "@modern-js/plugin-v2";
|
2
|
+
import { appTools as oldAppTools } from "../old";
|
3
|
+
import { compatPlugin } from "./compat";
|
4
|
+
import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
|
5
|
+
import { initAppContext } from "./context";
|
6
|
+
export * from "../defineConfig";
|
7
|
+
const appTools = (options = {
|
8
|
+
// default webpack to be compatible with original projects
|
9
|
+
bundler: "webpack"
|
10
|
+
}) => ({
|
11
|
+
name: "@modern-js/app-tools",
|
12
|
+
usePlugins: [
|
13
|
+
compatPlugin(),
|
14
|
+
oldAppTools(options)
|
15
|
+
],
|
16
|
+
post: [
|
17
|
+
"@modern-js/app-tools-old"
|
18
|
+
],
|
19
|
+
registryHooks: {
|
20
|
+
onBeforeConfig: createAsyncHook(),
|
21
|
+
onAfterPrepare: createAsyncHook(),
|
22
|
+
deploy: createAsyncHook(),
|
23
|
+
_internalRuntimePlugins: createAsyncHook(),
|
24
|
+
_internalServerPlugins: createAsyncHook(),
|
25
|
+
checkEntryPoint: createAsyncHook(),
|
26
|
+
modifyEntrypoints: createAsyncHook(),
|
27
|
+
modifyFileSystemRoutes: createAsyncHook(),
|
28
|
+
modifyServerRoutes: createAsyncHook(),
|
29
|
+
generateEntryCode: createAsyncHook(),
|
30
|
+
onBeforeGenerateRoutes: createAsyncHook(),
|
31
|
+
onBeforePrintInstructions: createAsyncHook(),
|
32
|
+
registerDev: createAsyncHook(),
|
33
|
+
registerBuildPlatform: createAsyncHook(),
|
34
|
+
addRuntimeExports: createAsyncHook()
|
35
|
+
},
|
36
|
+
setup: (api) => {
|
37
|
+
var _userConfig_output;
|
38
|
+
const context = api.getAppContext();
|
39
|
+
const userConfig = api.getConfig();
|
40
|
+
api.updateAppContext(initAppContext({
|
41
|
+
appDirectory: context.appDirectory,
|
42
|
+
options: {},
|
43
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
|
44
|
+
runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
|
45
|
+
tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
|
46
|
+
}));
|
47
|
+
}
|
48
|
+
});
|
49
|
+
export {
|
50
|
+
appTools,
|
51
|
+
initAppContext
|
52
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
|
2
|
+
const debug = createDebugger("load-plugins");
|
3
|
+
const resolveCliPlugin = async (p, appDirectory) => {
|
4
|
+
const pkg = typeof p === "string" ? p : p[0];
|
5
|
+
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
6
|
+
const path = tryResolve(pkg, appDirectory);
|
7
|
+
let module;
|
8
|
+
try {
|
9
|
+
module = await compatibleRequire(path);
|
10
|
+
} catch (e) {
|
11
|
+
({ default: module } = await dynamicImport(path));
|
12
|
+
}
|
13
|
+
if (typeof module === "function") {
|
14
|
+
const result = module(pluginOptions);
|
15
|
+
return result;
|
16
|
+
}
|
17
|
+
return module;
|
18
|
+
};
|
19
|
+
const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
|
20
|
+
const plugins = [
|
21
|
+
...autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : [],
|
22
|
+
...autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []
|
23
|
+
];
|
24
|
+
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
25
|
+
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
26
|
+
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
27
|
+
return loadedPlugin;
|
28
|
+
}));
|
29
|
+
return loadedPlugins;
|
30
|
+
};
|
31
|
+
export {
|
32
|
+
loadInternalPlugins
|
33
|
+
};
|