@modern-js/app-tools 2.62.1 → 2.63.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.
Files changed (66) hide show
  1. package/bin/modern.js +2 -2
  2. package/dist/cjs/index.js +12 -144
  3. package/dist/cjs/new/compat/hooks.js +165 -0
  4. package/dist/cjs/new/compat/index.js +60 -0
  5. package/dist/cjs/new/compat/utils.js +95 -0
  6. package/dist/cjs/new/constants.js +37 -0
  7. package/dist/cjs/new/context.js +64 -0
  8. package/dist/cjs/new/getConfigFile.js +41 -0
  9. package/dist/cjs/new/index.js +79 -0
  10. package/dist/cjs/new/loadPlugins.js +57 -0
  11. package/dist/cjs/new/run.js +67 -0
  12. package/dist/cjs/new/utils/index.js +34 -0
  13. package/dist/cjs/old.js +179 -0
  14. package/dist/cjs/plugins/initialize/index.js +44 -50
  15. package/dist/cjs/types/new.js +16 -0
  16. package/dist/cjs/utils/restart.js +2 -2
  17. package/dist/esm/index.js +7 -249
  18. package/dist/esm/new/compat/hooks.js +452 -0
  19. package/dist/esm/new/compat/index.js +41 -0
  20. package/dist/esm/new/compat/utils.js +69 -0
  21. package/dist/esm/new/constants.js +10 -0
  22. package/dist/esm/new/context.js +31 -0
  23. package/dist/esm/new/getConfigFile.js +11 -0
  24. package/dist/esm/new/index.js +55 -0
  25. package/dist/esm/new/loadPlugins.js +94 -0
  26. package/dist/esm/new/run.js +80 -0
  27. package/dist/esm/new/utils/index.js +33 -0
  28. package/dist/esm/old.js +258 -0
  29. package/dist/esm/plugins/initialize/index.js +61 -64
  30. package/dist/esm/types/new.js +0 -0
  31. package/dist/esm/utils/restart.js +1 -1
  32. package/dist/esm-node/index.js +7 -131
  33. package/dist/esm-node/new/compat/hooks.js +140 -0
  34. package/dist/esm-node/new/compat/index.js +36 -0
  35. package/dist/esm-node/new/compat/utils.js +69 -0
  36. package/dist/esm-node/new/constants.js +10 -0
  37. package/dist/esm-node/new/context.js +30 -0
  38. package/dist/esm-node/new/getConfigFile.js +7 -0
  39. package/dist/esm-node/new/index.js +52 -0
  40. package/dist/esm-node/new/loadPlugins.js +33 -0
  41. package/dist/esm-node/new/run.js +43 -0
  42. package/dist/esm-node/new/utils/index.js +10 -0
  43. package/dist/esm-node/old.js +140 -0
  44. package/dist/esm-node/plugins/initialize/index.js +44 -50
  45. package/dist/esm-node/types/new.js +0 -0
  46. package/dist/esm-node/utils/restart.js +1 -1
  47. package/dist/types/config/default.d.ts +4 -3
  48. package/dist/types/index.d.ts +6 -16
  49. package/dist/types/new/compat/hooks.d.ts +7 -0
  50. package/dist/types/new/compat/index.d.ts +2 -0
  51. package/dist/types/new/compat/utils.d.ts +6 -0
  52. package/dist/types/new/constants.d.ts +4 -0
  53. package/dist/types/new/context.d.ts +33 -0
  54. package/dist/types/new/getConfigFile.d.ts +1 -0
  55. package/dist/types/new/index.d.ts +6 -0
  56. package/dist/types/new/loadPlugins.d.ts +9 -0
  57. package/dist/types/new/run.d.ts +13 -0
  58. package/dist/types/new/utils/index.d.ts +1 -0
  59. package/dist/types/old.d.ts +13 -0
  60. package/dist/types/plugins/initialize/index.d.ts +2 -2
  61. package/dist/types/types/index.d.ts +12 -3
  62. package/dist/types/types/new.d.ts +145 -0
  63. package/dist/types/utils/env.d.ts +2 -2
  64. package/dist/types/utils/restart.d.ts +1 -1
  65. package/lib/types.d.ts +82 -61
  66. package/package.json +27 -18
@@ -0,0 +1,41 @@
1
+ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
2
+ import { createCollectAsyncHook } from "@modern-js/plugin-v2";
3
+ import { getHookRunners } from "./hooks";
4
+ var compatPlugin = function() {
5
+ return {
6
+ name: "@modern-js/app-tools-compat",
7
+ _registryApi: function(getAppContext, updateAppContext) {
8
+ var getInternalContext = function() {
9
+ return getAppContext()._internalContext;
10
+ };
11
+ return {
12
+ useAppContext: function() {
13
+ var _getAppContext = getAppContext(), _internalContext = _getAppContext._internalContext, appContext = _object_without_properties(_getAppContext, [
14
+ "_internalContext"
15
+ ]);
16
+ return appContext;
17
+ },
18
+ setAppContext: function(context) {
19
+ return updateAppContext(context);
20
+ },
21
+ useConfigContext: function() {
22
+ return getInternalContext().config;
23
+ },
24
+ useResolvedConfigContext: function() {
25
+ return getInternalContext().normalizedConfig;
26
+ },
27
+ useHookRunners: function() {
28
+ return getHookRunners(getInternalContext());
29
+ }
30
+ };
31
+ },
32
+ registryHooks: {
33
+ appendEntryCode: createCollectAsyncHook()
34
+ },
35
+ setup: function(_api) {
36
+ }
37
+ };
38
+ };
39
+ export {
40
+ compatPlugin
41
+ };
@@ -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
+ var PACKAGE_JSON_CONFIG_NAME = "modernConfig";
2
+ var DEFAULT_CONFIG_FILE = "modern.config";
3
+ var DEFAULT_SERVER_CONFIG_FILE = "modern.server-runtime.config";
4
+ var 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,31 @@
1
+ import path from "path";
2
+ import { fs, address } from "@modern-js/utils";
3
+ var initAppContext = function(param) {
4
+ var appDirectory = param.appDirectory, runtimeConfigFile = param.runtimeConfigFile, options = param.options, serverConfigFile = param.serverConfigFile, tempDir = param.tempDir;
5
+ var _ref = options || {}, _ref_metaName = _ref.metaName, metaName = _ref_metaName === void 0 ? "modern-js" : _ref_metaName, _ref_apiDir = _ref.apiDir, apiDir = _ref_apiDir === void 0 ? "api" : _ref_apiDir, _ref_distDir = _ref.distDir, distDir = _ref_distDir === void 0 ? "" : _ref_distDir, _ref_sharedDir = _ref.sharedDir, sharedDir = _ref_sharedDir === void 0 ? "shared" : _ref_sharedDir;
6
+ var pkgPath = path.resolve(appDirectory, "./package.json");
7
+ return {
8
+ metaName,
9
+ runtimeConfigFile,
10
+ serverConfigFile,
11
+ ip: address.ip(),
12
+ port: 0,
13
+ moduleType: fs.existsSync(pkgPath) ? require(pkgPath).type || "commonjs" : "commonjs",
14
+ apiDirectory: path.resolve(appDirectory, apiDir),
15
+ lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
16
+ sharedDirectory: path.resolve(appDirectory, sharedDir),
17
+ distDirectory: distDir,
18
+ serverPlugins: [],
19
+ internalDirectory: path.resolve(appDirectory, tempDir || "./node_modules/.".concat(metaName)),
20
+ htmlTemplates: {},
21
+ serverRoutes: [],
22
+ entrypoints: [],
23
+ checkedEntries: [],
24
+ apiOnly: false,
25
+ internalDirAlias: "@_".concat(metaName.replace(/-/g, "_"), "_internal"),
26
+ internalSrcAlias: "@_".concat(metaName.replace(/-/g, "_"), "_src")
27
+ };
28
+ };
29
+ export {
30
+ initAppContext
31
+ };
@@ -0,0 +1,11 @@
1
+ import path from "path";
2
+ import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
3
+ import { DEFAULT_CONFIG_FILE } from "./constants";
4
+ var getConfigFile = function(configFile) {
5
+ return findExists(CONFIG_FILE_EXTENSIONS.map(function(extension) {
6
+ return path.resolve(process.cwd(), "".concat(configFile || DEFAULT_CONFIG_FILE).concat(extension));
7
+ }));
8
+ };
9
+ export {
10
+ getConfigFile
11
+ };
@@ -0,0 +1,55 @@
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
+ var appTools = function() {
8
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
9
+ // default webpack to be compatible with original projects
10
+ bundler: "webpack"
11
+ };
12
+ return {
13
+ name: "@modern-js/app-tools",
14
+ usePlugins: [
15
+ compatPlugin(),
16
+ oldAppTools(options)
17
+ ],
18
+ post: [
19
+ "@modern-js/app-tools-old"
20
+ ],
21
+ registryHooks: {
22
+ onBeforeConfig: createAsyncHook(),
23
+ onAfterPrepare: createAsyncHook(),
24
+ deploy: createAsyncHook(),
25
+ _internalRuntimePlugins: createAsyncHook(),
26
+ _internalServerPlugins: createAsyncHook(),
27
+ checkEntryPoint: createAsyncHook(),
28
+ modifyEntrypoints: createAsyncHook(),
29
+ modifyFileSystemRoutes: createAsyncHook(),
30
+ modifyServerRoutes: createAsyncHook(),
31
+ generateEntryCode: createAsyncHook(),
32
+ onBeforeGenerateRoutes: createAsyncHook(),
33
+ onBeforePrintInstructions: createAsyncHook(),
34
+ registerDev: createAsyncHook(),
35
+ registerBuildPlatform: createAsyncHook(),
36
+ addRuntimeExports: createAsyncHook()
37
+ },
38
+ setup: function(api) {
39
+ var _userConfig_output;
40
+ var context = api.getAppContext();
41
+ var userConfig = api.getConfig();
42
+ api.updateAppContext(initAppContext({
43
+ appDirectory: context.appDirectory,
44
+ options: {},
45
+ serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
46
+ runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
47
+ tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
48
+ }));
49
+ }
50
+ };
51
+ };
52
+ export {
53
+ appTools,
54
+ initAppContext
55
+ };
@@ -0,0 +1,94 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
5
+ var debug = createDebugger("load-plugins");
6
+ var resolveCliPlugin = function() {
7
+ var _ref = _async_to_generator(function(p, appDirectory) {
8
+ var pkg, pluginOptions, path, module, e, ref, result;
9
+ return _ts_generator(this, function(_state) {
10
+ switch (_state.label) {
11
+ case 0:
12
+ pkg = typeof p === "string" ? p : p[0];
13
+ pluginOptions = typeof p === "string" ? void 0 : p[1];
14
+ path = tryResolve(pkg, appDirectory);
15
+ _state.label = 1;
16
+ case 1:
17
+ _state.trys.push([
18
+ 1,
19
+ 3,
20
+ ,
21
+ 5
22
+ ]);
23
+ return [
24
+ 4,
25
+ compatibleRequire(path)
26
+ ];
27
+ case 2:
28
+ module = _state.sent();
29
+ return [
30
+ 3,
31
+ 5
32
+ ];
33
+ case 3:
34
+ e = _state.sent();
35
+ return [
36
+ 4,
37
+ dynamicImport(path)
38
+ ];
39
+ case 4:
40
+ ref = _state.sent(), module = ref.default, ref;
41
+ return [
42
+ 3,
43
+ 5
44
+ ];
45
+ case 5:
46
+ if (typeof module === "function") {
47
+ result = module(pluginOptions);
48
+ return [
49
+ 2,
50
+ result
51
+ ];
52
+ }
53
+ return [
54
+ 2,
55
+ module
56
+ ];
57
+ }
58
+ });
59
+ });
60
+ return function resolveCliPlugin2(p, appDirectory) {
61
+ return _ref.apply(this, arguments);
62
+ };
63
+ }();
64
+ var loadInternalPlugins = function() {
65
+ var _ref = _async_to_generator(function(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
66
+ var plugins, loadedPlugins;
67
+ return _ts_generator(this, function(_state) {
68
+ switch (_state.label) {
69
+ case 0:
70
+ plugins = _to_consumable_array(autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : []).concat(_to_consumable_array(autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []));
71
+ return [
72
+ 4,
73
+ Promise.all(plugins.map(function(plugin) {
74
+ var loadedPlugin = resolveCliPlugin(plugin, appDirectory);
75
+ debug("resolve plugin %s: %s", plugin, loadedPlugin);
76
+ return loadedPlugin;
77
+ }))
78
+ ];
79
+ case 1:
80
+ loadedPlugins = _state.sent();
81
+ return [
82
+ 2,
83
+ loadedPlugins
84
+ ];
85
+ }
86
+ });
87
+ });
88
+ return function loadInternalPlugins2(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
89
+ return _ref.apply(this, arguments);
90
+ };
91
+ }();
92
+ export {
93
+ loadInternalPlugins
94
+ };
@@ -0,0 +1,80 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { initAppDir } from "@modern-js/plugin-v2/cli";
4
+ import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
5
+ import { minimist } from "@modern-js/utils";
6
+ import { handleSetupResult } from "./compat/hooks";
7
+ import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
8
+ import { getConfigFile } from "./getConfigFile";
9
+ import { loadInternalPlugins } from "./loadPlugins";
10
+ import { getIsAutoLoadPlugins } from "./utils";
11
+ function run(_) {
12
+ return _run.apply(this, arguments);
13
+ }
14
+ function _run() {
15
+ _run = _async_to_generator(function(param) {
16
+ var cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile, command, cliParams, SUPPORT_CONFIG_PARAM_COMMANDS, customConfigFile, appDirectory, finalConfigFile, autoLoadPlugins, plugins;
17
+ return _ts_generator(this, function(_state) {
18
+ switch (_state.label) {
19
+ case 0:
20
+ cwd = param.cwd, initialLog = param.initialLog, version = param.version, internalPlugins = param.internalPlugins, packageJsonConfig = param.packageJsonConfig, configFile = param.configFile;
21
+ command = process.argv[2];
22
+ cliParams = minimist(process.argv.slice(2));
23
+ SUPPORT_CONFIG_PARAM_COMMANDS = [
24
+ "dev",
25
+ "build",
26
+ "deploy",
27
+ "start",
28
+ "serve",
29
+ "inspect",
30
+ "upgrade"
31
+ ];
32
+ if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command)) {
33
+ customConfigFile = cliParams.config || cliParams.c;
34
+ }
35
+ if (command === "new") {
36
+ customConfigFile = cliParams["config-file"];
37
+ }
38
+ return [
39
+ 4,
40
+ initAppDir(cwd)
41
+ ];
42
+ case 1:
43
+ appDirectory = _state.sent();
44
+ finalConfigFile = customConfigFile || getConfigFile(configFile);
45
+ return [
46
+ 4,
47
+ getIsAutoLoadPlugins(appDirectory, finalConfigFile)
48
+ ];
49
+ case 2:
50
+ autoLoadPlugins = _state.sent();
51
+ return [
52
+ 4,
53
+ loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins)
54
+ ];
55
+ case 3:
56
+ plugins = _state.sent();
57
+ return [
58
+ 4,
59
+ CLIPluginRun({
60
+ cwd,
61
+ initialLog: initialLog || "Modern.js Framework v".concat(version),
62
+ configFile: finalConfigFile,
63
+ packageJsonConfig: packageJsonConfig || PACKAGE_JSON_CONFIG_NAME,
64
+ internalPlugins: plugins,
65
+ handleSetupResult
66
+ })
67
+ ];
68
+ case 4:
69
+ _state.sent();
70
+ return [
71
+ 2
72
+ ];
73
+ }
74
+ });
75
+ });
76
+ return _run.apply(this, arguments);
77
+ }
78
+ export {
79
+ run
80
+ };
@@ -0,0 +1,33 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
4
+ function getIsAutoLoadPlugins(appDirectory) {
5
+ return _getIsAutoLoadPlugins.apply(this, arguments);
6
+ }
7
+ function _getIsAutoLoadPlugins() {
8
+ _getIsAutoLoadPlugins = _async_to_generator(function(appDirectory) {
9
+ var configFile, packageJsonConfig, _loaded_config, loaded, autoLoadPlugins;
10
+ var _arguments = arguments;
11
+ return _ts_generator(this, function(_state) {
12
+ switch (_state.label) {
13
+ case 0:
14
+ configFile = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern.config.ts", packageJsonConfig = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : "ModernConfig";
15
+ return [
16
+ 4,
17
+ createLoadedConfig(appDirectory, configFile, packageJsonConfig)
18
+ ];
19
+ case 1:
20
+ loaded = _state.sent();
21
+ autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
22
+ return [
23
+ 2,
24
+ autoLoadPlugins || false
25
+ ];
26
+ }
27
+ });
28
+ });
29
+ return _getIsAutoLoadPlugins.apply(this, arguments);
30
+ }
31
+ export {
32
+ getIsAutoLoadPlugins
33
+ };
@@ -0,0 +1,258 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
+ import path from "path";
7
+ import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
8
+ import { castArray } from "@modern-js/uni-builder";
9
+ import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
10
+ import { hooks } from "./hooks";
11
+ import { i18n } from "./locale";
12
+ import analyzePlugin from "./plugins/analyze";
13
+ import deployPlugin from "./plugins/deploy";
14
+ import initializePlugin from "./plugins/initialize";
15
+ import serverBuildPlugin from "./plugins/serverBuild";
16
+ import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
17
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
18
+ import { restart } from "./utils/restart";
19
+ import { dev } from "./commands/dev";
20
+ import { mergeConfig } from "@modern-js/core";
21
+ export * from "./defineConfig";
22
+ export * from "./types";
23
+ var appTools = function() {
24
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
25
+ // default webpack to be compatible with original projects
26
+ bundler: "webpack"
27
+ };
28
+ return {
29
+ name: "@modern-js/app-tools-old",
30
+ post: [
31
+ "@modern-js/plugin-initialize",
32
+ "@modern-js/plugin-analyze",
33
+ "@modern-js/plugin-ssr",
34
+ "@modern-js/plugin-document",
35
+ "@modern-js/plugin-state",
36
+ "@modern-js/plugin-router",
37
+ "@modern-js/plugin-router-v5",
38
+ "@modern-js/plugin-polyfill"
39
+ ],
40
+ registerHook: hooks,
41
+ usePlugins: [
42
+ initializePlugin({
43
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
44
+ "rspack",
45
+ "experimental-rspack"
46
+ ].includes(options.bundler) ? "rspack" : "webpack"
47
+ }),
48
+ analyzePlugin({
49
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
50
+ "rspack",
51
+ "experimental-rspack"
52
+ ].includes(options.bundler) ? "rspack" : "webpack"
53
+ }),
54
+ serverBuildPlugin(),
55
+ deployPlugin()
56
+ ],
57
+ setup: function(api) {
58
+ var appContext = api.useAppContext();
59
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
60
+ toolsType: "app-tools"
61
+ }));
62
+ var locale = getLocaleLanguage();
63
+ i18n.changeLanguage({
64
+ locale
65
+ });
66
+ return {
67
+ beforeConfig: function beforeConfig() {
68
+ return _async_to_generator(function() {
69
+ var _userConfig_output, userConfig, appContext2;
70
+ return _ts_generator(this, function(_state) {
71
+ userConfig = api.useConfigContext();
72
+ appContext2 = api.useAppContext();
73
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
74
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext2), {
75
+ internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
76
+ }));
77
+ }
78
+ return [
79
+ 2
80
+ ];
81
+ });
82
+ })();
83
+ },
84
+ commands: function commands(param) {
85
+ var program = param.program;
86
+ return _async_to_generator(function() {
87
+ return _ts_generator(this, function(_state) {
88
+ switch (_state.label) {
89
+ case 0:
90
+ return [
91
+ 4,
92
+ devCommand(program, api)
93
+ ];
94
+ case 1:
95
+ _state.sent();
96
+ return [
97
+ 4,
98
+ buildCommand(program, api)
99
+ ];
100
+ case 2:
101
+ _state.sent();
102
+ serverCommand(program, api);
103
+ deployCommand(program, api);
104
+ newCommand(program, locale);
105
+ inspectCommand(program, api);
106
+ upgradeCommand(program);
107
+ deprecatedCommands(program);
108
+ return [
109
+ 2
110
+ ];
111
+ }
112
+ });
113
+ })();
114
+ },
115
+ prepare: function prepare() {
116
+ return _async_to_generator(function() {
117
+ var command, isSkipBuild, resolvedConfig, appContext2;
118
+ return _ts_generator(this, function(_state) {
119
+ switch (_state.label) {
120
+ case 0:
121
+ command = getCommand();
122
+ if (command === "deploy") {
123
+ isSkipBuild = [
124
+ "-s",
125
+ "--skip-build"
126
+ ].some(function(tag) {
127
+ return getArgv().includes(tag);
128
+ });
129
+ if (isSkipBuild) {
130
+ return [
131
+ 2
132
+ ];
133
+ }
134
+ }
135
+ if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
136
+ return [
137
+ 3,
138
+ 2
139
+ ];
140
+ resolvedConfig = api.useResolvedConfigContext();
141
+ if (!resolvedConfig.output.cleanDistPath)
142
+ return [
143
+ 3,
144
+ 2
145
+ ];
146
+ appContext2 = api.useAppContext();
147
+ return [
148
+ 4,
149
+ emptyDir(appContext2.distDirectory)
150
+ ];
151
+ case 1:
152
+ _state.sent();
153
+ _state.label = 2;
154
+ case 2:
155
+ return [
156
+ 2
157
+ ];
158
+ }
159
+ });
160
+ })();
161
+ },
162
+ watchFiles: function watchFiles() {
163
+ return _async_to_generator(function() {
164
+ var appContext2, config, files, watchFiles2;
165
+ return _ts_generator(this, function(_state) {
166
+ switch (_state.label) {
167
+ case 0:
168
+ appContext2 = api.useAppContext();
169
+ config = api.useResolvedConfigContext();
170
+ return [
171
+ 4,
172
+ generateWatchFiles(appContext2, config.source.configDir)
173
+ ];
174
+ case 1:
175
+ files = _state.sent();
176
+ watchFiles2 = castArray(config.dev.watchFiles);
177
+ watchFiles2.forEach(function(param) {
178
+ var type = param.type, paths = param.paths;
179
+ if (type === "reload-server") {
180
+ var _files;
181
+ (_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
182
+ paths
183
+ ]));
184
+ }
185
+ });
186
+ return [
187
+ 2,
188
+ files
189
+ ];
190
+ }
191
+ });
192
+ })();
193
+ },
194
+ fileChange: (
195
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
196
+ function fileChange(e) {
197
+ return _async_to_generator(function() {
198
+ var filename, eventType, isPrivate, closeServer;
199
+ return _ts_generator(this, function(_state) {
200
+ switch (_state.label) {
201
+ case 0:
202
+ filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
203
+ if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
204
+ return [
205
+ 3,
206
+ 4
207
+ ];
208
+ return [
209
+ 4,
210
+ import("./utils/createServer.js")
211
+ ];
212
+ case 1:
213
+ closeServer = _state.sent().closeServer;
214
+ return [
215
+ 4,
216
+ closeServer()
217
+ ];
218
+ case 2:
219
+ _state.sent();
220
+ return [
221
+ 4,
222
+ restart(api.useHookRunners(), filename)
223
+ ];
224
+ case 3:
225
+ _state.sent();
226
+ _state.label = 4;
227
+ case 4:
228
+ return [
229
+ 2
230
+ ];
231
+ }
232
+ });
233
+ })();
234
+ }
235
+ ),
236
+ beforeRestart: function beforeRestart() {
237
+ return _async_to_generator(function() {
238
+ return _ts_generator(this, function(_state) {
239
+ cleanRequireCache([
240
+ require.resolve("./plugins/analyze")
241
+ ]);
242
+ return [
243
+ 2
244
+ ];
245
+ });
246
+ })();
247
+ }
248
+ };
249
+ }
250
+ };
251
+ };
252
+ var old_default = appTools;
253
+ export {
254
+ appTools,
255
+ old_default as default,
256
+ dev,
257
+ mergeConfig
258
+ };