@modern-js/app-tools 2.62.2-alpha.0 → 2.63.1-alpha.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/bin/modern.js +1 -1
- package/dist/cjs/commands/build.js +19 -13
- package/dist/cjs/commands/deploy.js +5 -5
- package/dist/cjs/commands/dev.js +11 -11
- package/dist/cjs/commands/index.js +6 -6
- package/dist/cjs/commands/inspect.js +1 -1
- package/dist/cjs/commands/serve.js +4 -4
- package/dist/cjs/{new/compat → compat}/hooks.js +20 -8
- package/dist/cjs/{new/compat → compat}/index.js +10 -2
- package/dist/cjs/{new/compat → compat}/utils.js +10 -1
- package/dist/cjs/index.js +156 -7
- package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
- package/dist/cjs/plugins/analyze/index.js +128 -130
- package/dist/cjs/plugins/deploy/index.js +12 -14
- package/dist/cjs/plugins/initialize/index.js +44 -50
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new/types/index.js → types/new.js} +2 -2
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +5 -5
- package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/cjs/utils/loadPlugins.js +35 -4
- package/dist/cjs/utils/printInstructions.js +2 -2
- package/dist/cjs/utils/restart.js +4 -3
- package/dist/esm/commands/build.js +18 -12
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +10 -10
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +5 -5
- package/dist/esm/{new/compat → compat}/hooks.js +65 -41
- package/dist/esm/{new/compat → compat}/index.js +13 -2
- package/dist/{esm-node/new → esm}/compat/utils.js +10 -1
- package/dist/esm/index.js +248 -5
- package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
- package/dist/esm/plugins/analyze/index.js +328 -331
- package/dist/esm/plugins/deploy/index.js +84 -88
- package/dist/esm/plugins/initialize/index.js +61 -64
- package/dist/esm/plugins/serverBuild.js +52 -56
- package/dist/esm/{new/run.js → run/index.js} +6 -6
- package/dist/esm/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm/{new/context.js → utils/initAppContext.js} +3 -3
- package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/esm/utils/loadPlugins.js +95 -7
- package/dist/esm/utils/printInstructions.js +3 -3
- package/dist/esm/utils/restart.js +5 -4
- package/dist/esm-node/commands/build.js +19 -13
- package/dist/esm-node/commands/deploy.js +5 -5
- package/dist/esm-node/commands/dev.js +11 -11
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/commands/inspect.js +1 -1
- package/dist/esm-node/commands/serve.js +4 -4
- package/dist/esm-node/{new/compat → compat}/hooks.js +20 -8
- package/dist/esm-node/{new/compat → compat}/index.js +10 -2
- package/dist/{esm/new → esm-node}/compat/utils.js +10 -1
- package/dist/esm-node/index.js +143 -5
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
- package/dist/esm-node/plugins/analyze/index.js +128 -130
- package/dist/esm-node/plugins/deploy/index.js +12 -14
- package/dist/esm-node/plugins/initialize/index.js +44 -50
- package/dist/esm-node/plugins/serverBuild.js +30 -32
- package/dist/esm-node/{new/run.js → run/index.js} +6 -6
- package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm-node/{new/context.js → utils/initAppContext.js} +3 -3
- package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
- package/dist/esm-node/utils/loadPlugins.js +34 -4
- package/dist/esm-node/utils/printInstructions.js +2 -2
- package/dist/esm-node/utils/restart.js +4 -3
- package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
- package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
- package/dist/types/builder/shared/types.d.ts +3 -2
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/index.d.ts +6 -6
- package/dist/types/commands/inspect.d.ts +2 -2
- package/dist/types/commands/serve.d.ts +2 -2
- package/dist/types/compat/hooks.d.ts +7 -0
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/config/default.d.ts +4 -3
- package/dist/types/config/initialize/index.d.ts +3 -2
- package/dist/types/config/initialize/inits.d.ts +4 -3
- package/dist/types/index.d.ts +8 -5
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
- package/dist/types/plugins/analyze/index.d.ts +2 -3
- package/dist/types/plugins/deploy/index.d.ts +2 -3
- package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
- package/dist/types/plugins/deploy/utils.d.ts +2 -2
- package/dist/types/plugins/initialize/index.d.ts +2 -2
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/index.d.ts +7 -3
- package/dist/types/types/new.d.ts +157 -0
- package/dist/types/utils/env.d.ts +2 -2
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
- package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
- package/dist/types/utils/loadPlugins.d.ts +13 -3
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +2 -3
- package/dist/types/utils/routes.d.ts +2 -1
- package/lib/types.d.ts +82 -61
- package/package.json +24 -24
- package/dist/cjs/hooks.js +0 -60
- package/dist/cjs/new/index.js +0 -79
- package/dist/cjs/new/loadPlugins.js +0 -57
- package/dist/cjs/old.js +0 -179
- package/dist/esm/hooks.js +0 -36
- package/dist/esm/new/index.js +0 -55
- package/dist/esm/new/loadPlugins.js +0 -94
- package/dist/esm/old.js +0 -258
- package/dist/esm-node/hooks.js +0 -36
- package/dist/esm-node/new/index.js +0 -52
- package/dist/esm-node/new/loadPlugins.js +0 -33
- package/dist/esm-node/old.js +0 -140
- package/dist/types/hooks.d.ts +0 -2
- package/dist/types/new/compat/hooks.d.ts +0 -8
- package/dist/types/new/compat/index.d.ts +0 -4
- package/dist/types/new/index.d.ts +0 -9
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/types/index.d.ts +0 -90
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -13
- /package/dist/cjs/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/types/index.js → types/new.js} +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/types/index.js → types/new.js} +0 -0
- /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
- /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
- /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
|
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { logger, prettyInstructions } from "@modern-js/utils";
|
|
4
4
|
var printInstructions = function() {
|
|
5
|
-
var _ref = _async_to_generator(function(
|
|
5
|
+
var _ref = _async_to_generator(function(hooks, appContext, config) {
|
|
6
6
|
var message, instructions;
|
|
7
7
|
return _ts_generator(this, function(_state) {
|
|
8
8
|
switch (_state.label) {
|
|
@@ -10,7 +10,7 @@ var printInstructions = function() {
|
|
|
10
10
|
message = prettyInstructions(appContext, config);
|
|
11
11
|
return [
|
|
12
12
|
4,
|
|
13
|
-
|
|
13
|
+
hooks.onBeforePrintInstructions.call({
|
|
14
14
|
instructions: message
|
|
15
15
|
})
|
|
16
16
|
];
|
|
@@ -23,7 +23,7 @@ var printInstructions = function() {
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
-
return function printInstructions2(
|
|
26
|
+
return function printInstructions2(hooks, appContext, config) {
|
|
27
27
|
return _ref.apply(this, arguments);
|
|
28
28
|
};
|
|
29
29
|
}();
|
|
@@ -1,12 +1,13 @@
|
|
|
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
3
|
import { cli } from "@modern-js/plugin-v2/cli";
|
|
4
|
-
import { chalk, clearConsole, getFullArgv, logger
|
|
5
|
-
|
|
4
|
+
import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
|
|
5
|
+
import { program } from "@modern-js/utils/commander";
|
|
6
|
+
function restart(hooks, filename) {
|
|
6
7
|
return _restart.apply(this, arguments);
|
|
7
8
|
}
|
|
8
9
|
function _restart() {
|
|
9
|
-
_restart = _async_to_generator(function(
|
|
10
|
+
_restart = _async_to_generator(function(hooks, filename) {
|
|
10
11
|
var hasGetError, err;
|
|
11
12
|
return _ts_generator(this, function(_state) {
|
|
12
13
|
switch (_state.label) {
|
|
@@ -16,7 +17,7 @@ function _restart() {
|
|
|
16
17
|
hasGetError = false;
|
|
17
18
|
return [
|
|
18
19
|
4,
|
|
19
|
-
|
|
20
|
+
hooks.onBeforeRestart.call()
|
|
20
21
|
];
|
|
21
22
|
case 1:
|
|
22
23
|
_state.sent();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ResolvedConfigContext } from "@modern-js/core";
|
|
2
1
|
import { logger } from "@modern-js/utils";
|
|
3
2
|
import { buildServerConfig } from "../utils/config";
|
|
4
3
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
@@ -9,9 +8,9 @@ const build = async (api, options) => {
|
|
|
9
8
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
|
10
9
|
process.env.BUNDLE_ANALYZE = "true";
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
const appContext = api.
|
|
14
|
-
const
|
|
11
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
12
|
+
const appContext = api.getAppContext();
|
|
13
|
+
const hooks = api.getHooks();
|
|
15
14
|
await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
|
|
16
15
|
if (appContext.moduleType && appContext.moduleType === "module") {
|
|
17
16
|
var _resolvedConfig_source1;
|
|
@@ -26,9 +25,12 @@ const build = async (api, options) => {
|
|
|
26
25
|
const { apiOnly } = appContext;
|
|
27
26
|
if (apiOnly) {
|
|
28
27
|
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
|
29
|
-
await
|
|
28
|
+
await hooks.onBeforeBuild.call({
|
|
29
|
+
environments: {},
|
|
30
30
|
// "null" bundlerConfigs
|
|
31
|
-
bundlerConfigs: void 0
|
|
31
|
+
bundlerConfigs: void 0,
|
|
32
|
+
isFirstCompile: false,
|
|
33
|
+
isWatch: false
|
|
32
34
|
});
|
|
33
35
|
await buildServerConfig({
|
|
34
36
|
appDirectory: appDirectory2,
|
|
@@ -36,17 +38,21 @@ const build = async (api, options) => {
|
|
|
36
38
|
configFile: serverConfigFile2
|
|
37
39
|
});
|
|
38
40
|
await generateRoutes(appContext);
|
|
39
|
-
await
|
|
41
|
+
await hooks.onAfterBuild.call({
|
|
42
|
+
environments: {},
|
|
40
43
|
// "null" stats
|
|
41
|
-
stats: void 0
|
|
44
|
+
stats: void 0,
|
|
45
|
+
isFirstCompile: false,
|
|
46
|
+
isWatch: false
|
|
42
47
|
});
|
|
43
48
|
return;
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
api.modifyResolvedConfig((config) => {
|
|
51
|
+
return {
|
|
52
|
+
...config,
|
|
53
|
+
cliOptions: options
|
|
54
|
+
};
|
|
55
|
+
});
|
|
50
56
|
const { distDirectory, appDirectory, serverConfigFile } = appContext;
|
|
51
57
|
await buildServerConfig({
|
|
52
58
|
appDirectory,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getServerPlugins } from "../utils/loadPlugins";
|
|
2
2
|
const deploy = async (api, options) => {
|
|
3
|
-
const
|
|
4
|
-
const { metaName } = api.
|
|
3
|
+
const hooks = api.getHooks();
|
|
4
|
+
const { metaName } = api.getAppContext();
|
|
5
5
|
await getServerPlugins(api, metaName);
|
|
6
|
-
await
|
|
7
|
-
await
|
|
8
|
-
await
|
|
6
|
+
await hooks.onBeforeDeploy.call(options);
|
|
7
|
+
await hooks.deploy.call();
|
|
8
|
+
await hooks.onAfterDeploy.call(options);
|
|
9
9
|
};
|
|
10
10
|
export {
|
|
11
11
|
deploy
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { ResolvedConfigContext } from "@modern-js/core";
|
|
3
2
|
import { applyPlugins } from "@modern-js/prod-server";
|
|
4
3
|
import { createDevServer } from "@modern-js/server";
|
|
5
4
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
|
@@ -14,9 +13,9 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
14
13
|
if (options.analyze) {
|
|
15
14
|
process.env.BUNDLE_ANALYZE = "true";
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
const appContext = api.
|
|
19
|
-
const
|
|
16
|
+
const normalizedConfig = api.getNormalizedConfig();
|
|
17
|
+
const appContext = api.getAppContext();
|
|
18
|
+
const hooks = api.getHooks();
|
|
20
19
|
if (appContext.moduleType && appContext.moduleType === "module") {
|
|
21
20
|
var _normalizedConfig_source1;
|
|
22
21
|
const { registerEsm } = await import("../esm/register-esm.mjs");
|
|
@@ -27,11 +26,12 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
28
|
await registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
api.modifyResolvedConfig((config) => {
|
|
30
|
+
return {
|
|
31
|
+
...config,
|
|
32
|
+
cliOptions: options
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
35
|
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
|
|
36
36
|
await buildServerConfig({
|
|
37
37
|
appDirectory,
|
|
@@ -41,7 +41,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
41
41
|
});
|
|
42
42
|
const meta = getMeta(metaName);
|
|
43
43
|
const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
44
|
-
await
|
|
44
|
+
await hooks.onBeforeDev.call();
|
|
45
45
|
if (!appContext.builder && !apiOnly) {
|
|
46
46
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
47
47
|
}
|
|
@@ -80,7 +80,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
80
80
|
port,
|
|
81
81
|
host
|
|
82
82
|
}, () => {
|
|
83
|
-
printInstructions(
|
|
83
|
+
printInstructions(hooks, appContext, normalizedConfig);
|
|
84
84
|
});
|
|
85
85
|
} else {
|
|
86
86
|
const { server, afterListen } = await createDevServer({
|
|
@@ -2,8 +2,8 @@ import { castArray } from "@modern-js/uni-builder";
|
|
|
2
2
|
import { newAction, upgradeAction } from "@modern-js/utils";
|
|
3
3
|
import { i18n, localeKeys } from "../locale";
|
|
4
4
|
const devCommand = async (program, api) => {
|
|
5
|
-
const
|
|
6
|
-
const devToolMetas = await
|
|
5
|
+
const hooks = api.getHooks();
|
|
6
|
+
const devToolMetas = await hooks.registerDev.call();
|
|
7
7
|
const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
8
8
|
const { dev } = await import("./dev.js");
|
|
9
9
|
await dev(api, options);
|
|
@@ -14,7 +14,7 @@ const devCommand = async (program, api) => {
|
|
|
14
14
|
}
|
|
15
15
|
for (const subCmd of meta.subCommands) {
|
|
16
16
|
devProgram.command(subCmd).action(async (options = {}) => {
|
|
17
|
-
const { appDirectory } = api.
|
|
17
|
+
const { appDirectory } = api.getAppContext();
|
|
18
18
|
const { isTypescript } = await import("@modern-js/utils");
|
|
19
19
|
await meta.action(options, {
|
|
20
20
|
isTsProject: isTypescript(appDirectory)
|
|
@@ -24,8 +24,8 @@ const devCommand = async (program, api) => {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
const buildCommand = async (program, api) => {
|
|
27
|
-
const
|
|
28
|
-
const platformBuilders = await
|
|
27
|
+
const hooks = api.getHooks();
|
|
28
|
+
const platformBuilders = await hooks.registerBuildPlatform.call();
|
|
29
29
|
const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
|
|
30
30
|
const { build } = await import("./build.js");
|
|
31
31
|
await build(api, options);
|
|
@@ -34,7 +34,7 @@ const buildCommand = async (program, api) => {
|
|
|
34
34
|
const platforms = castArray(platformBuilder.platform);
|
|
35
35
|
for (const platform of platforms) {
|
|
36
36
|
buildProgram.command(platform).action(async () => {
|
|
37
|
-
const { appDirectory } = api.
|
|
37
|
+
const { appDirectory } = api.getAppContext();
|
|
38
38
|
const { isTypescript } = await import("@modern-js/utils");
|
|
39
39
|
await platformBuilder.build(platform, {
|
|
40
40
|
isTsProject: isTypescript(appDirectory)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const inspect = async (api, options) => {
|
|
2
|
-
const appContext = api.
|
|
2
|
+
const appContext = api.getAppContext();
|
|
3
3
|
if (!appContext.builder) {
|
|
4
4
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
5
5
|
}
|
|
@@ -5,9 +5,9 @@ import { loadServerPlugins } from "../utils/loadPlugins";
|
|
|
5
5
|
import { printInstructions } from "../utils/printInstructions";
|
|
6
6
|
const start = async (api) => {
|
|
7
7
|
var _userConfig_source, _userConfig_output_distPath;
|
|
8
|
-
const appContext = api.
|
|
9
|
-
const userConfig = api.
|
|
10
|
-
const
|
|
8
|
+
const appContext = api.getAppContext();
|
|
9
|
+
const userConfig = api.getNormalizedConfig();
|
|
10
|
+
const hooks = api.getHooks();
|
|
11
11
|
const { distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
|
|
12
12
|
logger.info(`Starting production server...`);
|
|
13
13
|
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
|
@@ -44,7 +44,7 @@ const start = async (api) => {
|
|
|
44
44
|
runMode
|
|
45
45
|
});
|
|
46
46
|
app.listen(port, async () => {
|
|
47
|
-
await printInstructions(
|
|
47
|
+
await printInstructions(hooks, appContext, userConfig);
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
50
|
export {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
|
|
1
2
|
import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
|
|
2
3
|
function getHookRunners(context) {
|
|
3
4
|
const { hooks } = context;
|
|
@@ -41,6 +42,11 @@ function getHookRunners(context) {
|
|
|
41
42
|
beforePrintInstructions: async (params) => {
|
|
42
43
|
return hooks.onBeforePrintInstructions.call(params);
|
|
43
44
|
},
|
|
45
|
+
// garfish plugin hooks
|
|
46
|
+
appendEntryCode: async (params) => {
|
|
47
|
+
const result = await (hooks === null || hooks === void 0 ? void 0 : hooks.appendEntryCode.call(params));
|
|
48
|
+
return result;
|
|
49
|
+
},
|
|
44
50
|
/**
|
|
45
51
|
* common hooks
|
|
46
52
|
*/
|
|
@@ -51,7 +57,13 @@ function getHookRunners(context) {
|
|
|
51
57
|
return hooks.modifyResolvedConfig.call(params);
|
|
52
58
|
},
|
|
53
59
|
htmlPartials: async (params) => {
|
|
54
|
-
|
|
60
|
+
await hooks.modifyHtmlPartials.call({
|
|
61
|
+
entrypoint: params.entrypoint,
|
|
62
|
+
partials: getModifyHtmlPartials(params.partials)
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
partials: params.partials
|
|
66
|
+
};
|
|
55
67
|
},
|
|
56
68
|
commands: async (params) => {
|
|
57
69
|
return hooks.addCommand.call(params);
|
|
@@ -62,7 +74,7 @@ function getHookRunners(context) {
|
|
|
62
74
|
prepare: async () => {
|
|
63
75
|
return hooks.onPrepare.call();
|
|
64
76
|
},
|
|
65
|
-
|
|
77
|
+
fileChange: async (params) => {
|
|
66
78
|
return hooks.onFileChanged.call(params);
|
|
67
79
|
},
|
|
68
80
|
beforeCreateCompiler: async (params) => {
|
|
@@ -98,20 +110,20 @@ function getHookRunners(context) {
|
|
|
98
110
|
/**
|
|
99
111
|
* @deprecated
|
|
100
112
|
*/
|
|
101
|
-
registerDev: async (
|
|
102
|
-
return hooks.registerDev.call(
|
|
113
|
+
registerDev: async () => {
|
|
114
|
+
return hooks.registerDev.call();
|
|
103
115
|
},
|
|
104
116
|
/**
|
|
105
117
|
* @deprecated
|
|
106
118
|
*/
|
|
107
|
-
registerBuildPlatform: async (
|
|
108
|
-
return hooks.registerBuildPlatform.call(
|
|
119
|
+
registerBuildPlatform: async () => {
|
|
120
|
+
return hooks.registerBuildPlatform.call();
|
|
109
121
|
},
|
|
110
122
|
/**
|
|
111
123
|
* @deprecated
|
|
112
124
|
*/
|
|
113
|
-
addRuntimeExports: async (
|
|
114
|
-
return hooks.addRuntimeExports.call(
|
|
125
|
+
addRuntimeExports: async () => {
|
|
126
|
+
return hooks.addRuntimeExports.call();
|
|
115
127
|
}
|
|
116
128
|
};
|
|
117
129
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCollectAsyncHook } from "@modern-js/plugin-v2";
|
|
1
2
|
import { getHookRunners } from "./hooks";
|
|
2
3
|
const compatPlugin = () => ({
|
|
3
4
|
name: "@modern-js/app-tools-compat",
|
|
@@ -7,7 +8,8 @@ const compatPlugin = () => ({
|
|
|
7
8
|
};
|
|
8
9
|
return {
|
|
9
10
|
useAppContext: () => {
|
|
10
|
-
|
|
11
|
+
const { _internalContext, ...appContext } = getAppContext();
|
|
12
|
+
return appContext;
|
|
11
13
|
},
|
|
12
14
|
setAppContext: (context) => {
|
|
13
15
|
return updateAppContext(context);
|
|
@@ -23,7 +25,13 @@ const compatPlugin = () => ({
|
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
27
|
},
|
|
26
|
-
|
|
28
|
+
registryHooks: {
|
|
29
|
+
appendEntryCode: createCollectAsyncHook()
|
|
30
|
+
},
|
|
31
|
+
setup: (api) => {
|
|
32
|
+
api.updateAppContext({
|
|
33
|
+
toolsType: "app-tools"
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
36
|
});
|
|
29
37
|
export {
|
|
@@ -16,7 +16,7 @@ function transformHookRunner(hookRunnerName) {
|
|
|
16
16
|
return "addCommand";
|
|
17
17
|
case "watchFiles":
|
|
18
18
|
return "addWatchFiles";
|
|
19
|
-
case "
|
|
19
|
+
case "fileChange":
|
|
20
20
|
return "onFileChanged";
|
|
21
21
|
case "beforeCreateCompiler":
|
|
22
22
|
return "onBeforeCreateCompiler";
|
|
@@ -50,6 +50,15 @@ function transformHookParams(hookRunnerName, params) {
|
|
|
50
50
|
return {
|
|
51
51
|
resolved: params
|
|
52
52
|
};
|
|
53
|
+
case "htmlPartials":
|
|
54
|
+
return {
|
|
55
|
+
partials: {
|
|
56
|
+
top: params.partials.top.current,
|
|
57
|
+
head: params.partials.head.current,
|
|
58
|
+
body: params.partials.body.current
|
|
59
|
+
},
|
|
60
|
+
entrypoint: params.entrypoint
|
|
61
|
+
};
|
|
53
62
|
default:
|
|
54
63
|
return params;
|
|
55
64
|
}
|
package/dist/esm-node/index.js
CHANGED
|
@@ -1,12 +1,150 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
|
2
|
+
import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
|
|
3
|
+
import { castArray } from "@modern-js/uni-builder";
|
|
4
|
+
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
5
|
+
import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
|
|
6
|
+
import { compatPlugin } from "./compat";
|
|
7
|
+
import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
|
|
8
|
+
import { i18n } from "./locale";
|
|
9
|
+
import analyzePlugin from "./plugins/analyze";
|
|
10
|
+
import deployPlugin from "./plugins/deploy";
|
|
11
|
+
import initializePlugin from "./plugins/initialize";
|
|
12
|
+
import serverBuildPlugin from "./plugins/serverBuild";
|
|
13
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
14
|
+
import { initAppContext } from "./utils/initAppContext";
|
|
15
|
+
import { restart } from "./utils/restart";
|
|
16
|
+
export * from "./defineConfig";
|
|
17
|
+
const appTools = (options = {
|
|
18
|
+
// default webpack to be compatible with original projects
|
|
19
|
+
bundler: "webpack"
|
|
20
|
+
}) => ({
|
|
21
|
+
name: "@modern-js/app-tools",
|
|
22
|
+
usePlugins: [
|
|
23
|
+
compatPlugin(),
|
|
24
|
+
initializePlugin({
|
|
25
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
|
26
|
+
"rspack",
|
|
27
|
+
"experimental-rspack"
|
|
28
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
|
29
|
+
}),
|
|
30
|
+
analyzePlugin({
|
|
31
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
|
32
|
+
"rspack",
|
|
33
|
+
"experimental-rspack"
|
|
34
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
|
35
|
+
}),
|
|
36
|
+
serverBuildPlugin(),
|
|
37
|
+
deployPlugin()
|
|
38
|
+
],
|
|
39
|
+
post: [
|
|
40
|
+
"@modern-js/plugin-initialize",
|
|
41
|
+
"@modern-js/plugin-analyze",
|
|
42
|
+
"@modern-js/plugin-ssr",
|
|
43
|
+
"@modern-js/plugin-document",
|
|
44
|
+
"@modern-js/plugin-state",
|
|
45
|
+
"@modern-js/plugin-router",
|
|
46
|
+
"@modern-js/plugin-router-v5",
|
|
47
|
+
"@modern-js/plugin-polyfill"
|
|
48
|
+
],
|
|
49
|
+
registryHooks: {
|
|
50
|
+
onBeforeConfig: createAsyncHook(),
|
|
51
|
+
onAfterPrepare: createAsyncHook(),
|
|
52
|
+
deploy: createAsyncHook(),
|
|
53
|
+
_internalRuntimePlugins: createAsyncHook(),
|
|
54
|
+
_internalServerPlugins: createAsyncHook(),
|
|
55
|
+
checkEntryPoint: createAsyncHook(),
|
|
56
|
+
modifyEntrypoints: createAsyncHook(),
|
|
57
|
+
modifyFileSystemRoutes: createAsyncHook(),
|
|
58
|
+
modifyServerRoutes: createAsyncHook(),
|
|
59
|
+
generateEntryCode: createAsyncHook(),
|
|
60
|
+
onBeforeGenerateRoutes: createAsyncHook(),
|
|
61
|
+
onBeforePrintInstructions: createAsyncHook(),
|
|
62
|
+
registerDev: createCollectAsyncHook(),
|
|
63
|
+
registerBuildPlatform: createCollectAsyncHook(),
|
|
64
|
+
addRuntimeExports: createAsyncHook()
|
|
65
|
+
},
|
|
66
|
+
setup: (api) => {
|
|
67
|
+
var _userConfig_output;
|
|
68
|
+
const context = api.getAppContext();
|
|
69
|
+
const userConfig = api.getConfig();
|
|
70
|
+
const locale = getLocaleLanguage();
|
|
71
|
+
i18n.changeLanguage({
|
|
72
|
+
locale
|
|
73
|
+
});
|
|
74
|
+
api.updateAppContext(initAppContext({
|
|
75
|
+
appDirectory: context.appDirectory,
|
|
76
|
+
options: {},
|
|
77
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
|
|
78
|
+
runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
|
|
79
|
+
tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
|
|
80
|
+
}));
|
|
81
|
+
api.addCommand(async ({ program }) => {
|
|
82
|
+
await devCommand(program, api);
|
|
83
|
+
await buildCommand(program, api);
|
|
84
|
+
serverCommand(program, api);
|
|
85
|
+
deployCommand(program, api);
|
|
86
|
+
newCommand(program, locale);
|
|
87
|
+
inspectCommand(program, api);
|
|
88
|
+
upgradeCommand(program);
|
|
89
|
+
deprecatedCommands(program);
|
|
90
|
+
});
|
|
91
|
+
api.onPrepare(async () => {
|
|
92
|
+
const command = getCommand();
|
|
93
|
+
if (command === "deploy") {
|
|
94
|
+
const isSkipBuild = [
|
|
95
|
+
"-s",
|
|
96
|
+
"--skip-build"
|
|
97
|
+
].some((tag) => {
|
|
98
|
+
return getArgv().includes(tag);
|
|
99
|
+
});
|
|
100
|
+
if (isSkipBuild) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
|
105
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
106
|
+
if (resolvedConfig.output.cleanDistPath) {
|
|
107
|
+
const appContext = api.getAppContext();
|
|
108
|
+
await emptyDir(appContext.distDirectory);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
api.addWatchFiles(async () => {
|
|
113
|
+
const appContext = api.getAppContext();
|
|
114
|
+
const config = api.getNormalizedConfig();
|
|
115
|
+
const files = await generateWatchFiles(appContext, config.source.configDir);
|
|
116
|
+
const watchFiles = castArray(config.dev.watchFiles);
|
|
117
|
+
watchFiles.forEach(({ type, paths }) => {
|
|
118
|
+
if (type === "reload-server") {
|
|
119
|
+
files.push(...Array.isArray(paths) ? paths : [
|
|
120
|
+
paths
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return files;
|
|
125
|
+
});
|
|
126
|
+
api.onFileChanged(async (e) => {
|
|
127
|
+
const { filename, eventType, isPrivate } = e;
|
|
128
|
+
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
|
129
|
+
const { closeServer } = await import("./utils/createServer.js");
|
|
130
|
+
await closeServer();
|
|
131
|
+
await restart(api.getHooks(), filename);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
api.onBeforeRestart(() => {
|
|
135
|
+
cleanRequireCache([
|
|
136
|
+
require.resolve("./plugins/analyze")
|
|
137
|
+
]);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
5
141
|
import { defineConfig, defineLegacyConfig } from "./defineConfig";
|
|
142
|
+
import { mergeConfig } from "@modern-js/core";
|
|
143
|
+
import { dev } from "./commands/dev";
|
|
6
144
|
export * from "./types";
|
|
7
145
|
var src_default = appTools;
|
|
8
146
|
export {
|
|
9
|
-
|
|
147
|
+
appTools,
|
|
10
148
|
src_default as default,
|
|
11
149
|
defineConfig,
|
|
12
150
|
defineLegacyConfig,
|
|
@@ -22,10 +22,10 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
|
|
|
22
22
|
}
|
|
23
23
|
return false;
|
|
24
24
|
});
|
|
25
|
-
const getBundleEntry = async (
|
|
25
|
+
const getBundleEntry = async (hooks, appContext, config) => {
|
|
26
26
|
const { appDirectory, packageName } = appContext;
|
|
27
27
|
const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
|
|
28
|
-
const defaults = disableDefaultEntries ? [] : await getFileSystemEntry(
|
|
28
|
+
const defaults = disableDefaultEntries ? [] : await getFileSystemEntry(hooks, appContext, config);
|
|
29
29
|
if (entries) {
|
|
30
30
|
Object.keys(entries).forEach((name) => {
|
|
31
31
|
const value = entries[name];
|
|
@@ -6,8 +6,8 @@ import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
|
|
6
6
|
const hasIndex = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
|
|
7
7
|
const hasEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}${ext}`)));
|
|
8
8
|
const hasServerEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}.server${ext}`)));
|
|
9
|
-
const isBundleEntry = async (
|
|
10
|
-
const { entry } = await
|
|
9
|
+
const isBundleEntry = async (hooks, dir, enableCustomEntry) => {
|
|
10
|
+
const { entry } = await hooks.checkEntryPoint.call({
|
|
11
11
|
path: dir,
|
|
12
12
|
entry: false
|
|
13
13
|
});
|
|
@@ -20,7 +20,7 @@ const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
|
|
|
20
20
|
}
|
|
21
21
|
return hasIndex(dir);
|
|
22
22
|
};
|
|
23
|
-
const scanDir = async (
|
|
23
|
+
const scanDir = async (hooks, dirs, enableCustomEntry) => {
|
|
24
24
|
const entries = await Promise.all(dirs.map(async (dir) => {
|
|
25
25
|
const indexFile = hasIndex(dir);
|
|
26
26
|
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
|
@@ -37,7 +37,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
|
|
37
37
|
customBootstrap
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
const entryFile = (await
|
|
40
|
+
const entryFile = (await hooks.checkEntryPoint.call({
|
|
41
41
|
path: dir,
|
|
42
42
|
entry: false
|
|
43
43
|
})).entry;
|
|
@@ -71,7 +71,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
|
|
71
71
|
}
|
|
72
72
|
return entries;
|
|
73
73
|
};
|
|
74
|
-
const getFileSystemEntry = async (
|
|
74
|
+
const getFileSystemEntry = async (hooks, appContext, config) => {
|
|
75
75
|
const { appDirectory } = appContext;
|
|
76
76
|
const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
|
|
77
77
|
let disabledDirs = [];
|
|
@@ -81,19 +81,19 @@ const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
|
|
81
81
|
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
|
82
82
|
if (fs.existsSync(src)) {
|
|
83
83
|
if (fs.statSync(src).isDirectory()) {
|
|
84
|
-
if (await isBundleEntry(
|
|
85
|
-
return scanDir(
|
|
84
|
+
if (await isBundleEntry(hooks, src, enableCustomEntry)) {
|
|
85
|
+
return scanDir(hooks, [
|
|
86
86
|
src
|
|
87
87
|
], enableCustomEntry);
|
|
88
88
|
}
|
|
89
89
|
const dirs = [];
|
|
90
90
|
await Promise.all(fs.readdirSync(src).map(async (filename) => {
|
|
91
91
|
const file = path.join(src, filename);
|
|
92
|
-
if (fs.statSync(file).isDirectory() && await isBundleEntry(
|
|
92
|
+
if (fs.statSync(file).isDirectory() && await isBundleEntry(hooks, file, enableCustomEntry) && !disabledDirs.includes(file)) {
|
|
93
93
|
dirs.push(file);
|
|
94
94
|
}
|
|
95
95
|
}));
|
|
96
|
-
return scanDir(
|
|
96
|
+
return scanDir(hooks, dirs, enableCustomEntry);
|
|
97
97
|
} else {
|
|
98
98
|
throw Error(`source.entriesDir accept a directory.`);
|
|
99
99
|
}
|