@modern-js/app-tools 2.62.0 → 2.62.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/bin/modern.js +2 -2
  2. package/dist/cjs/index.js +4 -142
  3. package/dist/cjs/new/compat/hooks.js +160 -0
  4. package/dist/cjs/new/compat/index.js +52 -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 +63 -0
  8. package/dist/cjs/new/getConfigFile.js +41 -0
  9. package/dist/cjs/new/index.js +76 -0
  10. package/dist/cjs/new/loadPlugins.js +57 -0
  11. package/dist/cjs/new/run.js +66 -0
  12. package/dist/cjs/new/types/index.js +16 -0
  13. package/dist/cjs/new/utils/index.js +34 -0
  14. package/dist/cjs/old.js +179 -0
  15. package/dist/esm/index.js +2 -248
  16. package/dist/esm/new/compat/hooks.js +418 -0
  17. package/dist/esm/new/compat/index.js +30 -0
  18. package/dist/esm/new/compat/utils.js +69 -0
  19. package/dist/esm/new/constants.js +10 -0
  20. package/dist/esm/new/context.js +30 -0
  21. package/dist/esm/new/getConfigFile.js +11 -0
  22. package/dist/esm/new/index.js +52 -0
  23. package/dist/esm/new/loadPlugins.js +94 -0
  24. package/dist/esm/new/run.js +79 -0
  25. package/dist/esm/new/types/index.js +0 -0
  26. package/dist/esm/new/utils/index.js +33 -0
  27. package/dist/esm/old.js +258 -0
  28. package/dist/esm-node/index.js +2 -130
  29. package/dist/esm-node/new/compat/hooks.js +135 -0
  30. package/dist/esm-node/new/compat/index.js +28 -0
  31. package/dist/esm-node/new/compat/utils.js +69 -0
  32. package/dist/esm-node/new/constants.js +10 -0
  33. package/dist/esm-node/new/context.js +29 -0
  34. package/dist/esm-node/new/getConfigFile.js +7 -0
  35. package/dist/esm-node/new/index.js +49 -0
  36. package/dist/esm-node/new/loadPlugins.js +33 -0
  37. package/dist/esm-node/new/run.js +42 -0
  38. package/dist/esm-node/new/types/index.js +0 -0
  39. package/dist/esm-node/new/utils/index.js +10 -0
  40. package/dist/esm-node/old.js +140 -0
  41. package/dist/types/index.d.ts +2 -6
  42. package/dist/types/new/compat/hooks.d.ts +8 -0
  43. package/dist/types/new/compat/index.d.ts +4 -0
  44. package/dist/types/new/compat/utils.d.ts +6 -0
  45. package/dist/types/new/constants.d.ts +4 -0
  46. package/dist/types/new/context.d.ts +32 -0
  47. package/dist/types/new/getConfigFile.d.ts +1 -0
  48. package/dist/types/new/index.d.ts +15 -0
  49. package/dist/types/new/loadPlugins.d.ts +9 -0
  50. package/dist/types/new/run.d.ts +14 -0
  51. package/dist/types/new/types/index.d.ts +89 -0
  52. package/dist/types/new/utils/index.d.ts +1 -0
  53. package/dist/types/old.d.ts +20 -0
  54. package/package.json +16 -8
@@ -0,0 +1,140 @@
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,5 +1,5 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- import type { AppTools } from './types';
1
+ import { appTools } from './new/index';
2
+ export * from './new/index';
3
3
  export { dev } from './commands/dev';
4
4
  export type { DevOptions } from './utils/types';
5
5
  export { mergeConfig } from '@modern-js/core';
@@ -13,8 +13,4 @@ export type AppToolsOptions = {
13
13
  * */
14
14
  bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
15
15
  };
16
- /**
17
- * The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
18
- */
19
- export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
20
16
  export default appTools;
@@ -0,0 +1,8 @@
1
+ import type { InternalContext } from '@modern-js/plugin-v2';
2
+ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from '../../types';
3
+ import type { AppToolsExtendAPIName } from '../types';
4
+ /**
5
+ * old plugin useHookRunners function result
6
+ */
7
+ export declare function getHookRunners(context: InternalContext<AppToolsUserConfig<'shared'>, AppToolsNormalizedConfig, AppToolsExtendAPIName<'shared'>>): Record<string, any>;
8
+ export declare function handleSetupResult(setupResult: Record<string, (...args: any) => any>, api: Record<string, any>): void;
@@ -0,0 +1,4 @@
1
+ import type { InternalContext, Plugin } from '@modern-js/plugin-v2';
2
+ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from '../../types/config';
3
+ import type { AppTools, AppToolsExtendAPIName } from '../types';
4
+ export declare const compatPlugin: () => Plugin<AppTools<'shared'>, InternalContext<AppToolsUserConfig<'shared'>, AppToolsNormalizedConfig, AppToolsExtendAPIName<'shared'>>>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Maps old plugin hook function names to new plugin API names
3
+ */
4
+ export declare function transformHookRunner(hookRunnerName: string): string;
5
+ export declare function transformHookParams(hookRunnerName: string, params: any): any;
6
+ export declare function transformHookResult(hookRunnerName: string, result: any): any;
@@ -0,0 +1,4 @@
1
+ export declare const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
2
+ export declare const DEFAULT_CONFIG_FILE = "modern.config";
3
+ export declare const DEFAULT_SERVER_CONFIG_FILE = "modern.server-runtime.config";
4
+ export declare const DEFAULT_RUNTIME_CONFIG_FILE = "modern.runtime";
@@ -0,0 +1,32 @@
1
+ export declare const initAppContext: ({ appDirectory, runtimeConfigFile, options, serverConfigFile, }: {
2
+ appDirectory: string;
3
+ runtimeConfigFile: string | false;
4
+ options?: {
5
+ metaName?: string | undefined;
6
+ srcDir?: string | undefined;
7
+ apiDir?: string | undefined;
8
+ distDir?: string | undefined;
9
+ sharedDir?: string | undefined;
10
+ } | undefined;
11
+ serverConfigFile: string;
12
+ }) => {
13
+ metaName: string;
14
+ runtimeConfigFile: string | false;
15
+ serverConfigFile: string;
16
+ ip: any;
17
+ port: number;
18
+ moduleType: any;
19
+ apiDirectory: string;
20
+ lambdaDirectory: string;
21
+ sharedDirectory: string;
22
+ distDirectory: string;
23
+ serverPlugins: never[];
24
+ internalDirectory: string;
25
+ htmlTemplates: {};
26
+ serverRoutes: never[];
27
+ entrypoints: never[];
28
+ checkedEntries: never[];
29
+ apiOnly: boolean;
30
+ internalDirAlias: string;
31
+ internalSrcAlias: string;
32
+ };
@@ -0,0 +1 @@
1
+ export declare const getConfigFile: (configFile?: string) => string | false;
@@ -0,0 +1,15 @@
1
+ import type { InternalContext, Plugin } from '@modern-js/plugin-v2';
2
+ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from '../types';
3
+ import { initAppContext } from './context';
4
+ import type { AppTools, AppToolsExtendAPIName } from './types';
5
+ export * from '../defineConfig';
6
+ export { initAppContext };
7
+ export type AppToolsOptions = {
8
+ /**
9
+ * Specify which bundler to use for the build.
10
+ * @default `webpack`
11
+ * */
12
+ bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
13
+ };
14
+ export type AppToolsPlugin = Plugin<AppTools<'shared'>, InternalContext<AppToolsUserConfig<'shared'>, AppToolsNormalizedConfig, AppToolsExtendAPIName<'shared'>>>;
15
+ export declare const appTools: (options?: AppToolsOptions) => AppToolsPlugin;
@@ -0,0 +1,9 @@
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, forceAutoLoadPlugins?: boolean) => Promise<Plugin[]>;
@@ -0,0 +1,14 @@
1
+ import type { InternalPlugins } from '@modern-js/types';
2
+ export interface RunOptions {
3
+ cwd?: string;
4
+ configFile?: string;
5
+ packageJsonConfig?: string;
6
+ internalPlugins?: {
7
+ cli?: InternalPlugins;
8
+ autoLoad?: InternalPlugins;
9
+ };
10
+ forceAutoLoadPlugins?: boolean;
11
+ initialLog?: string;
12
+ version: string;
13
+ }
14
+ export declare function run({ cwd, initialLog, version, internalPlugins, forceAutoLoadPlugins, packageJsonConfig, configFile, }: RunOptions): Promise<void>;
@@ -0,0 +1,89 @@
1
+ import type { DevToolData, RegisterBuildPlatformResult } from '@modern-js/core';
2
+ import type { CLIPluginAPI, PluginHookTap, TransformFunction } from '@modern-js/plugin-v2';
3
+ import type { AppContext } from '@modern-js/plugin-v2/dist/types';
4
+ import type { Entrypoint, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
5
+ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from '../../types/config';
6
+ import type { RuntimePlugin } from '../../types/hooks';
7
+ import type { Bundler } from '../../types/utils';
8
+ import type { getHookRunners } from '../compat/hooks';
9
+ export type BeforeConfigFn = () => Promise<void> | void;
10
+ export type AfterPrepareFn = () => Promise<void> | void;
11
+ export type InternalRuntimePluginsFn = TransformFunction<{
12
+ entrypoint: Entrypoint;
13
+ plugins: RuntimePlugin[];
14
+ }>;
15
+ export type InternalServerPluginsFn = TransformFunction<{
16
+ plugins: ServerPlugin[];
17
+ }>;
18
+ export type CheckEntryPointFn = TransformFunction<{
19
+ path: string;
20
+ entry: false | string;
21
+ }>;
22
+ export type ModifyEntrypointsFn = TransformFunction<Entrypoint[]>;
23
+ export type ModifyFileSystemRoutesFn = TransformFunction<{
24
+ entrypoint: Entrypoint;
25
+ routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
26
+ }>;
27
+ export type ModifyServerRoutesFn = TransformFunction<{
28
+ routes: ServerRoute[];
29
+ }>;
30
+ export type DeplpoyFn = () => Promise<void> | void;
31
+ export type GenerateEntryCodeFn = (entrypoints: Entrypoint[]) => Promise<void> | void;
32
+ export type BeforeGenerateRoutesFn = TransformFunction<{
33
+ entrypoint: Entrypoint;
34
+ code: string;
35
+ }>;
36
+ export type BeforePrintInstructionsFn = TransformFunction<{
37
+ instructions: string;
38
+ }>;
39
+ export type RegisterDevFn = () => Promise<DevToolData> | DevToolData;
40
+ export type RegisterBuildPlatformFn = () => Promise<RegisterBuildPlatformResult> | RegisterBuildPlatformResult;
41
+ export type AddRuntimeExportsFn = () => Promise<void> | void;
42
+ export interface AppToolsExtendAPI<B extends Bundler> {
43
+ onBeforeConfig: PluginHookTap<BeforeConfigFn>;
44
+ onAfterPrepare: PluginHookTap<AfterPrepareFn>;
45
+ deploy: PluginHookTap<DeplpoyFn>;
46
+ _internalRuntimePlugins: PluginHookTap<InternalRuntimePluginsFn>;
47
+ _internalServerPlugins: PluginHookTap<InternalServerPluginsFn>;
48
+ checkEntryPoint: PluginHookTap<CheckEntryPointFn>;
49
+ modifyEntrypoints: PluginHookTap<ModifyEntrypointsFn>;
50
+ modifyFileSystemRoutes: PluginHookTap<ModifyFileSystemRoutesFn>;
51
+ modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
52
+ generateEntryCode: PluginHookTap<GenerateEntryCodeFn>;
53
+ onBeforeGenerateRoutes: PluginHookTap<BeforeGenerateRoutesFn>;
54
+ /**
55
+ * @deprecated
56
+ */
57
+ onBeforePrintInstructions: PluginHookTap<BeforePrintInstructionsFn>;
58
+ /**
59
+ * @deprecated
60
+ */
61
+ registerDev: PluginHookTap<RegisterDevFn>;
62
+ /**
63
+ * @deprecated
64
+ */
65
+ registerBuildPlatform: PluginHookTap<RegisterBuildPlatformFn>;
66
+ /**
67
+ * @deprecated
68
+ */
69
+ addRuntimeExports: PluginHookTap<AddRuntimeExportsFn>;
70
+ /**
71
+ * @deprecated use getAppContext instead
72
+ */
73
+ useAppContext: () => AppContext<AppToolsUserConfig<B>, AppToolsNormalizedConfig<AppToolsUserConfig<B>>>;
74
+ /**
75
+ * @deprecated use getConfig instead
76
+ */
77
+ useConfigContext: () => AppToolsUserConfig<B>;
78
+ /**
79
+ * @deprecated use getNormalizedConfig instead
80
+ */
81
+ useResolvedConfigContext: () => AppToolsNormalizedConfig<AppToolsUserConfig<B>>;
82
+ /**
83
+ * @deprecated use api.xx instead
84
+ */
85
+ useHookRunners: () => ReturnType<typeof getHookRunners>;
86
+ }
87
+ export interface AppTools<B extends Bundler> extends CLIPluginAPI<AppToolsUserConfig<B>, AppToolsNormalizedConfig<AppToolsUserConfig<B>>>, AppToolsExtendAPI<B> {
88
+ }
89
+ export type AppToolsExtendAPIName<B extends Bundler> = keyof AppToolsExtendAPI<B> & string;
@@ -0,0 +1 @@
1
+ export declare function getIsAutoLoadPlugins(appDirectory: string, configFile?: string, packageJsonConfig?: string): Promise<boolean>;
@@ -0,0 +1,20 @@
1
+ import type { CliPlugin } from '@modern-js/core';
2
+ import type { AppTools } 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
+ export type AppToolsOptions = {
10
+ /**
11
+ * Specify which bundler to use for the build.
12
+ * @default `webpack`
13
+ * */
14
+ bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
15
+ };
16
+ /**
17
+ * The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
18
+ */
19
+ export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
20
+ export default appTools;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.62.0",
18
+ "version": "2.62.1-alpha.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -34,6 +34,11 @@
34
34
  "jsnext:source": "./src/index.ts",
35
35
  "default": "./dist/cjs/index.js"
36
36
  },
37
+ "./cli/run": {
38
+ "types": "./dist/types/new/run.d.ts",
39
+ "jsnext:source": "./src/new/run.ts",
40
+ "default": "./dist/cjs/new/run.js"
41
+ },
37
42
  "./types": {
38
43
  "types": "./lib/types.d.ts",
39
44
  "jsnext:source": "./lib/types.d.ts",
@@ -58,6 +63,9 @@
58
63
  ".": [
59
64
  "./dist/types/index.d.ts"
60
65
  ],
66
+ "cli/run": [
67
+ "./dist/types/new/run.d.ts"
68
+ ],
61
69
  "types": [
62
70
  "./lib/types.d.ts"
63
71
  ],
@@ -88,19 +96,20 @@
88
96
  "mlly": "^1.6.1",
89
97
  "pkg-types": "^1.1.0",
90
98
  "std-env": "^3.7.0",
91
- "@modern-js/core": "2.62.0",
92
- "@modern-js/node-bundle-require": "2.62.0",
93
99
  "@modern-js/plugin": "2.62.0",
100
+ "@modern-js/plugin-v2": "2.60.6",
94
101
  "@modern-js/plugin-i18n": "2.62.0",
95
102
  "@modern-js/plugin-data-loader": "2.62.0",
96
103
  "@modern-js/prod-server": "2.62.0",
97
- "@modern-js/rsbuild-plugin-esbuild": "2.62.0",
104
+ "@modern-js/core": "2.62.0",
98
105
  "@modern-js/server": "2.62.0",
99
- "@modern-js/server-utils": "2.62.0",
106
+ "@modern-js/node-bundle-require": "2.62.0",
107
+ "@modern-js/rsbuild-plugin-esbuild": "2.62.0",
100
108
  "@modern-js/server-core": "2.62.0",
101
109
  "@modern-js/types": "2.62.0",
110
+ "@modern-js/utils": "2.62.0",
102
111
  "@modern-js/uni-builder": "2.62.0",
103
- "@modern-js/utils": "2.62.0"
112
+ "@modern-js/server-utils": "2.62.0"
104
113
  },
105
114
  "devDependencies": {
106
115
  "@rsbuild/plugin-webpack-swc": "~1.0.3",
@@ -130,8 +139,7 @@
130
139
  "sideEffects": false,
131
140
  "publishConfig": {
132
141
  "registry": "https://registry.npmjs.org/",
133
- "access": "public",
134
- "provenance": true
142
+ "access": "public"
135
143
  },
136
144
  "scripts": {
137
145
  "new": "modern-lib new",