@modern-js/app-tools 2.63.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.
Files changed (135) hide show
  1. package/bin/modern.js +1 -1
  2. package/dist/cjs/commands/build.js +19 -13
  3. package/dist/cjs/commands/deploy.js +5 -5
  4. package/dist/cjs/commands/dev.js +11 -11
  5. package/dist/cjs/commands/index.js +6 -6
  6. package/dist/cjs/commands/inspect.js +1 -1
  7. package/dist/cjs/commands/serve.js +4 -4
  8. package/dist/cjs/{new/compat → compat}/hooks.js +15 -8
  9. package/dist/cjs/{new/compat → compat}/index.js +4 -1
  10. package/dist/cjs/{new/compat → compat}/utils.js +10 -1
  11. package/dist/cjs/index.js +154 -5
  12. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
  13. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
  14. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
  15. package/dist/cjs/plugins/analyze/index.js +128 -130
  16. package/dist/cjs/plugins/deploy/index.js +12 -14
  17. package/dist/cjs/plugins/initialize/index.js +1 -1
  18. package/dist/cjs/plugins/serverBuild.js +30 -32
  19. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  20. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  21. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -4
  22. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  23. package/dist/cjs/utils/loadPlugins.js +35 -4
  24. package/dist/cjs/utils/printInstructions.js +2 -2
  25. package/dist/cjs/utils/restart.js +4 -3
  26. package/dist/esm/commands/build.js +18 -12
  27. package/dist/esm/commands/deploy.js +6 -6
  28. package/dist/esm/commands/dev.js +10 -10
  29. package/dist/esm/commands/index.js +8 -8
  30. package/dist/esm/commands/inspect.js +1 -1
  31. package/dist/esm/commands/serve.js +5 -5
  32. package/dist/esm/{new/compat → compat}/hooks.js +41 -41
  33. package/dist/esm/{new/compat → compat}/index.js +4 -1
  34. package/dist/esm/{new/compat → compat}/utils.js +10 -1
  35. package/dist/esm/index.js +245 -2
  36. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  37. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  38. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  39. package/dist/esm/plugins/analyze/index.js +328 -331
  40. package/dist/esm/plugins/deploy/index.js +84 -88
  41. package/dist/esm/plugins/initialize/index.js +1 -1
  42. package/dist/esm/plugins/serverBuild.js +52 -56
  43. package/dist/esm/{new/run.js → run/index.js} +6 -6
  44. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  45. package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -1
  46. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  47. package/dist/esm/utils/loadPlugins.js +95 -7
  48. package/dist/esm/utils/printInstructions.js +3 -3
  49. package/dist/esm/utils/restart.js +5 -4
  50. package/dist/esm-node/commands/build.js +19 -13
  51. package/dist/esm-node/commands/deploy.js +5 -5
  52. package/dist/esm-node/commands/dev.js +11 -11
  53. package/dist/esm-node/commands/index.js +6 -6
  54. package/dist/esm-node/commands/inspect.js +1 -1
  55. package/dist/esm-node/commands/serve.js +4 -4
  56. package/dist/esm-node/{new/compat → compat}/hooks.js +15 -8
  57. package/dist/esm-node/{new/compat → compat}/index.js +4 -1
  58. package/dist/esm-node/{new/compat → compat}/utils.js +10 -1
  59. package/dist/esm-node/index.js +140 -2
  60. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  61. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  62. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  63. package/dist/esm-node/plugins/analyze/index.js +128 -130
  64. package/dist/esm-node/plugins/deploy/index.js +12 -14
  65. package/dist/esm-node/plugins/initialize/index.js +1 -1
  66. package/dist/esm-node/plugins/serverBuild.js +30 -32
  67. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  68. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  69. package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -1
  70. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  71. package/dist/esm-node/utils/loadPlugins.js +34 -4
  72. package/dist/esm-node/utils/printInstructions.js +2 -2
  73. package/dist/esm-node/utils/restart.js +4 -3
  74. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  75. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  76. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  77. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  78. package/dist/types/builder/index.d.ts +1 -1
  79. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  80. package/dist/types/builder/shared/types.d.ts +3 -2
  81. package/dist/types/commands/build.d.ts +2 -2
  82. package/dist/types/commands/deploy.d.ts +2 -2
  83. package/dist/types/commands/dev.d.ts +2 -2
  84. package/dist/types/commands/index.d.ts +6 -6
  85. package/dist/types/commands/inspect.d.ts +2 -2
  86. package/dist/types/commands/serve.d.ts +2 -2
  87. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  88. package/dist/types/compat/index.d.ts +2 -0
  89. package/dist/types/config/initialize/index.d.ts +3 -2
  90. package/dist/types/config/initialize/inits.d.ts +4 -3
  91. package/dist/types/index.d.ts +5 -3
  92. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  93. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  94. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  95. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  96. package/dist/types/plugins/analyze/index.d.ts +2 -3
  97. package/dist/types/plugins/deploy/index.d.ts +2 -3
  98. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  99. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  100. package/dist/types/plugins/serverBuild.d.ts +2 -2
  101. package/dist/types/types/index.d.ts +2 -0
  102. package/dist/types/types/new.d.ts +46 -34
  103. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  104. package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
  105. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  106. package/dist/types/utils/loadPlugins.d.ts +13 -3
  107. package/dist/types/utils/printInstructions.d.ts +3 -3
  108. package/dist/types/utils/restart.d.ts +2 -3
  109. package/dist/types/utils/routes.d.ts +2 -1
  110. package/package.json +14 -15
  111. package/dist/cjs/hooks.js +0 -60
  112. package/dist/cjs/new/index.js +0 -79
  113. package/dist/cjs/new/loadPlugins.js +0 -57
  114. package/dist/cjs/old.js +0 -179
  115. package/dist/esm/hooks.js +0 -36
  116. package/dist/esm/new/index.js +0 -55
  117. package/dist/esm/new/loadPlugins.js +0 -94
  118. package/dist/esm/old.js +0 -258
  119. package/dist/esm-node/hooks.js +0 -36
  120. package/dist/esm-node/new/index.js +0 -52
  121. package/dist/esm-node/new/loadPlugins.js +0 -33
  122. package/dist/esm-node/old.js +0 -140
  123. package/dist/types/hooks.d.ts +0 -2
  124. package/dist/types/new/compat/index.d.ts +0 -2
  125. package/dist/types/new/index.d.ts +0 -6
  126. package/dist/types/new/loadPlugins.d.ts +0 -9
  127. package/dist/types/new/utils/index.d.ts +0 -1
  128. package/dist/types/old.d.ts +0 -13
  129. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  130. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  131. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  132. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  133. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  134. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  135. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var loadPlugins_exports = {};
20
- __export(loadPlugins_exports, {
21
- loadInternalPlugins: () => loadInternalPlugins
22
- });
23
- module.exports = __toCommonJS(loadPlugins_exports);
24
- var import_utils = require("@modern-js/utils");
25
- const debug = (0, import_utils.createDebugger)("load-plugins");
26
- const resolveCliPlugin = async (p, appDirectory) => {
27
- const pkg = typeof p === "string" ? p : p[0];
28
- const pluginOptions = typeof p === "string" ? void 0 : p[1];
29
- const path = (0, import_utils.tryResolve)(pkg, appDirectory);
30
- let module2;
31
- try {
32
- module2 = await (0, import_utils.compatibleRequire)(path);
33
- } catch (e) {
34
- ({ default: module2 } = await (0, import_utils.dynamicImport)(path));
35
- }
36
- if (typeof module2 === "function") {
37
- const result = module2(pluginOptions);
38
- return result;
39
- }
40
- return module2;
41
- };
42
- const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
43
- const plugins = [
44
- ...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
45
- ...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
46
- ];
47
- const loadedPlugins = await Promise.all(plugins.map((plugin) => {
48
- const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
49
- debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
50
- return loadedPlugin;
51
- }));
52
- return loadedPlugins;
53
- };
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
56
- loadInternalPlugins
57
- });
package/dist/cjs/old.js DELETED
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var old_exports = {};
31
- __export(old_exports, {
32
- appTools: () => appTools,
33
- default: () => old_default,
34
- dev: () => import_dev.dev,
35
- mergeConfig: () => import_core.mergeConfig
36
- });
37
- module.exports = __toCommonJS(old_exports);
38
- var import_path = __toESM(require("path"));
39
- var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
40
- var import_uni_builder = require("@modern-js/uni-builder");
41
- var import_utils = require("@modern-js/utils");
42
- var import_hooks = require("./hooks");
43
- var import_locale = require("./locale");
44
- var import_analyze = __toESM(require("./plugins/analyze"));
45
- var import_deploy = __toESM(require("./plugins/deploy"));
46
- var import_initialize = __toESM(require("./plugins/initialize"));
47
- var import_serverBuild = __toESM(require("./plugins/serverBuild"));
48
- var import_commands = require("./commands");
49
- var import_generateWatchFiles = require("./utils/generateWatchFiles");
50
- var import_restart = require("./utils/restart");
51
- var import_dev = require("./commands/dev");
52
- var import_core = require("@modern-js/core");
53
- __reExport(old_exports, require("./defineConfig"), module.exports);
54
- __reExport(old_exports, require("./types"), module.exports);
55
- const appTools = (options = {
56
- // default webpack to be compatible with original projects
57
- bundler: "webpack"
58
- }) => ({
59
- name: "@modern-js/app-tools-old",
60
- post: [
61
- "@modern-js/plugin-initialize",
62
- "@modern-js/plugin-analyze",
63
- "@modern-js/plugin-ssr",
64
- "@modern-js/plugin-document",
65
- "@modern-js/plugin-state",
66
- "@modern-js/plugin-router",
67
- "@modern-js/plugin-router-v5",
68
- "@modern-js/plugin-polyfill"
69
- ],
70
- registerHook: import_hooks.hooks,
71
- usePlugins: [
72
- (0, import_initialize.default)({
73
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
74
- "rspack",
75
- "experimental-rspack"
76
- ].includes(options.bundler) ? "rspack" : "webpack"
77
- }),
78
- (0, import_analyze.default)({
79
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
80
- "rspack",
81
- "experimental-rspack"
82
- ].includes(options.bundler) ? "rspack" : "webpack"
83
- }),
84
- (0, import_serverBuild.default)(),
85
- (0, import_deploy.default)()
86
- ],
87
- setup: (api) => {
88
- const appContext = api.useAppContext();
89
- api.setAppContext({
90
- ...appContext,
91
- toolsType: "app-tools"
92
- });
93
- const locale = (0, import_language_detector.getLocaleLanguage)();
94
- import_locale.i18n.changeLanguage({
95
- locale
96
- });
97
- return {
98
- async beforeConfig() {
99
- var _userConfig_output;
100
- const userConfig = api.useConfigContext();
101
- const appContext2 = api.useAppContext();
102
- if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
103
- api.setAppContext({
104
- ...appContext2,
105
- internalDirectory: import_path.default.resolve(appContext2.appDirectory, userConfig.output.tempDir)
106
- });
107
- }
108
- },
109
- async commands({ program }) {
110
- await (0, import_commands.devCommand)(program, api);
111
- await (0, import_commands.buildCommand)(program, api);
112
- (0, import_commands.serverCommand)(program, api);
113
- (0, import_commands.deployCommand)(program, api);
114
- (0, import_commands.newCommand)(program, locale);
115
- (0, import_commands.inspectCommand)(program, api);
116
- (0, import_commands.upgradeCommand)(program);
117
- (0, import_utils.deprecatedCommands)(program);
118
- },
119
- async prepare() {
120
- const command = (0, import_utils.getCommand)();
121
- if (command === "deploy") {
122
- const isSkipBuild = [
123
- "-s",
124
- "--skip-build"
125
- ].some((tag) => {
126
- return (0, import_utils.getArgv)().includes(tag);
127
- });
128
- if (isSkipBuild) {
129
- return;
130
- }
131
- }
132
- if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
133
- const resolvedConfig = api.useResolvedConfigContext();
134
- if (resolvedConfig.output.cleanDistPath) {
135
- const appContext2 = api.useAppContext();
136
- await (0, import_utils.emptyDir)(appContext2.distDirectory);
137
- }
138
- }
139
- },
140
- async watchFiles() {
141
- const appContext2 = api.useAppContext();
142
- const config = api.useResolvedConfigContext();
143
- const files = await (0, import_generateWatchFiles.generateWatchFiles)(appContext2, config.source.configDir);
144
- const watchFiles = (0, import_uni_builder.castArray)(config.dev.watchFiles);
145
- watchFiles.forEach(({ type, paths }) => {
146
- if (type === "reload-server") {
147
- files.push(...Array.isArray(paths) ? paths : [
148
- paths
149
- ]);
150
- }
151
- });
152
- return files;
153
- },
154
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
155
- async fileChange(e) {
156
- const { filename, eventType, isPrivate } = e;
157
- if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
158
- const { closeServer } = await import("./utils/createServer.js");
159
- await closeServer();
160
- await (0, import_restart.restart)(api.useHookRunners(), filename);
161
- }
162
- },
163
- async beforeRestart() {
164
- (0, import_utils.cleanRequireCache)([
165
- require.resolve("./plugins/analyze")
166
- ]);
167
- }
168
- };
169
- }
170
- });
171
- var old_default = appTools;
172
- // Annotate the CommonJS export names for ESM import in node:
173
- 0 && (module.exports = {
174
- appTools,
175
- dev,
176
- mergeConfig,
177
- ...require("./defineConfig"),
178
- ...require("./types")
179
- });
package/dist/esm/hooks.js DELETED
@@ -1,36 +0,0 @@
1
- import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
- var hooks = {
3
- _internalRuntimePlugins: createAsyncWaterfall(),
4
- modifyFileSystemRoutes: createAsyncWaterfall(),
5
- modifyServerRoutes: createAsyncWaterfall(),
6
- /** add entry point info to entrypoints array */
7
- modifyEntrypoints: createAsyncWaterfall(),
8
- /** add entry type */
9
- checkEntryPoint: createAsyncWaterfall(),
10
- generateEntryCode: createAsyncWorkflow(),
11
- htmlPartials: createAsyncWaterfall(),
12
- beforeGenerateRoutes: createAsyncWaterfall(),
13
- _internalServerPlugins: createAsyncWaterfall(),
14
- beforeDev: createAsyncWorkflow(),
15
- afterDev: createAsyncWorkflow(),
16
- beforeCreateCompiler: createAsyncWorkflow(),
17
- afterCreateCompiler: createAsyncWorkflow(),
18
- beforePrintInstructions: createAsyncWaterfall(),
19
- beforeBuild: createAsyncWorkflow(),
20
- afterBuild: createAsyncWorkflow(),
21
- beforeDeploy: createAsyncWorkflow(),
22
- deploy: createAsyncWorkflow(),
23
- afterDeploy: createAsyncWorkflow(),
24
- beforeRestart: createAsyncWorkflow(),
25
- /**
26
- * @deprecated
27
- */
28
- registerDev: createParallelWorkflow(),
29
- /**
30
- * @deprecated
31
- */
32
- registerBuildPlatform: createParallelWorkflow()
33
- };
34
- export {
35
- hooks
36
- };
@@ -1,55 +0,0 @@
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
- };
@@ -1,94 +0,0 @@
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
- };
package/dist/esm/old.js DELETED
@@ -1,258 +0,0 @@
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
- };