@modern-js/app-tools 2.63.0 → 2.63.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
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,36 +0,0 @@
1
- import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
- const 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,52 +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
- 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
- };
@@ -1,33 +0,0 @@
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
- };
@@ -1,140 +0,0 @@
1
- import path from "path";
2
- import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
3
- import { castArray } from "@modern-js/uni-builder";
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";
15
- import { mergeConfig } from "@modern-js/core";
16
- export * from "./defineConfig";
17
- 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-old",
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
- var old_default = appTools;
135
- export {
136
- appTools,
137
- old_default as default,
138
- dev,
139
- mergeConfig
140
- };
@@ -1,2 +0,0 @@
1
- import type { AppToolsHooks } from './types/hooks';
2
- export declare const hooks: AppToolsHooks;
@@ -1,2 +0,0 @@
1
- import type { AppTools, CliPluginFuture } from '../../types';
2
- export declare const compatPlugin: () => CliPluginFuture<AppTools>;
@@ -1,6 +0,0 @@
1
- import { type AppToolsOptions } from '../old';
2
- import type { AppTools, CliPluginFuture } from '../types';
3
- import { initAppContext } from './context';
4
- export * from '../defineConfig';
5
- export { initAppContext };
6
- export declare const appTools: (options?: AppToolsOptions) => CliPluginFuture<AppTools<'shared'>>;
@@ -1,9 +0,0 @@
1
- import type { Plugin } from '@modern-js/plugin-v2';
2
- import type { InternalPlugins } from '@modern-js/types';
3
- /**
4
- * Load internal plugins which in @modern-js scope and user's custom plugins.
5
- * @param appDirectory - Application root directory.
6
- * @param internalPlugins - Internal plugins.
7
- * @returns Plugin Objects has been required.
8
- */
9
- export declare const loadInternalPlugins: (appDirectory: string, internalPlugins?: InternalPlugins, autoLoad?: InternalPlugins, autoLoadPlugins?: boolean) => Promise<Plugin[]>;
@@ -1 +0,0 @@
1
- export declare function getIsAutoLoadPlugins(appDirectory: string, configFile?: string, packageJsonConfig?: string): Promise<boolean>;
@@ -1,13 +0,0 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- import type { AppTools, AppToolsOptions } from './types';
3
- export { dev } from './commands/dev';
4
- export type { DevOptions } from './utils/types';
5
- export { mergeConfig } from '@modern-js/core';
6
- export * from './defineConfig';
7
- export * from './types';
8
- export type { RuntimeUserConfig } from './types/config';
9
- /**
10
- * The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
11
- */
12
- export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
13
- export default appTools;
File without changes
File without changes
File without changes
File without changes
File without changes