@modern-js/app-tools 2.62.1-alpha.1 → 2.62.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 +142 -4
  3. package/dist/esm/index.js +248 -2
  4. package/dist/esm-node/index.js +130 -2
  5. package/dist/types/index.d.ts +6 -2
  6. package/package.json +18 -26
  7. package/dist/cjs/new/compat/hooks.js +0 -160
  8. package/dist/cjs/new/compat/index.js +0 -52
  9. package/dist/cjs/new/compat/utils.js +0 -95
  10. package/dist/cjs/new/constants.js +0 -37
  11. package/dist/cjs/new/context.js +0 -63
  12. package/dist/cjs/new/getConfigFile.js +0 -41
  13. package/dist/cjs/new/index.js +0 -76
  14. package/dist/cjs/new/loadPlugins.js +0 -57
  15. package/dist/cjs/new/run.js +0 -66
  16. package/dist/cjs/new/types/index.js +0 -16
  17. package/dist/cjs/new/utils/index.js +0 -34
  18. package/dist/cjs/old.js +0 -179
  19. package/dist/esm/new/compat/hooks.js +0 -418
  20. package/dist/esm/new/compat/index.js +0 -30
  21. package/dist/esm/new/compat/utils.js +0 -69
  22. package/dist/esm/new/constants.js +0 -10
  23. package/dist/esm/new/context.js +0 -30
  24. package/dist/esm/new/getConfigFile.js +0 -11
  25. package/dist/esm/new/index.js +0 -52
  26. package/dist/esm/new/loadPlugins.js +0 -94
  27. package/dist/esm/new/run.js +0 -79
  28. package/dist/esm/new/types/index.js +0 -0
  29. package/dist/esm/new/utils/index.js +0 -33
  30. package/dist/esm/old.js +0 -258
  31. package/dist/esm-node/new/compat/hooks.js +0 -135
  32. package/dist/esm-node/new/compat/index.js +0 -28
  33. package/dist/esm-node/new/compat/utils.js +0 -69
  34. package/dist/esm-node/new/constants.js +0 -10
  35. package/dist/esm-node/new/context.js +0 -29
  36. package/dist/esm-node/new/getConfigFile.js +0 -7
  37. package/dist/esm-node/new/index.js +0 -49
  38. package/dist/esm-node/new/loadPlugins.js +0 -33
  39. package/dist/esm-node/new/run.js +0 -42
  40. package/dist/esm-node/new/types/index.js +0 -0
  41. package/dist/esm-node/new/utils/index.js +0 -10
  42. package/dist/esm-node/old.js +0 -140
  43. package/dist/types/new/compat/hooks.d.ts +0 -8
  44. package/dist/types/new/compat/index.d.ts +0 -4
  45. package/dist/types/new/compat/utils.d.ts +0 -6
  46. package/dist/types/new/constants.d.ts +0 -4
  47. package/dist/types/new/context.d.ts +0 -32
  48. package/dist/types/new/getConfigFile.d.ts +0 -1
  49. package/dist/types/new/index.d.ts +0 -15
  50. package/dist/types/new/loadPlugins.d.ts +0 -9
  51. package/dist/types/new/run.d.ts +0 -14
  52. package/dist/types/new/types/index.d.ts +0 -89
  53. package/dist/types/new/utils/index.d.ts +0 -1
  54. package/dist/types/old.d.ts +0 -20
@@ -1,66 +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 run_exports = {};
20
- __export(run_exports, {
21
- run: () => run
22
- });
23
- module.exports = __toCommonJS(run_exports);
24
- var import_cli = require("@modern-js/plugin-v2/cli");
25
- var import_run = require("@modern-js/plugin-v2/run");
26
- var import_utils = require("@modern-js/utils");
27
- var import_hooks = require("./compat/hooks");
28
- var import_constants = require("./constants");
29
- var import_getConfigFile = require("./getConfigFile");
30
- var import_loadPlugins = require("./loadPlugins");
31
- var import_utils2 = require("./utils");
32
- async function run({ cwd, initialLog, version, internalPlugins, forceAutoLoadPlugins, packageJsonConfig, configFile }) {
33
- const command = process.argv[2];
34
- const cliParams = (0, import_utils.minimist)(process.argv.slice(2));
35
- const SUPPORT_CONFIG_PARAM_COMMANDS = [
36
- "dev",
37
- "build",
38
- "deploy",
39
- "start",
40
- "serve",
41
- "inspect",
42
- "upgrade"
43
- ];
44
- let customConfigFile;
45
- if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command)) {
46
- customConfigFile = cliParams.config || cliParams.c;
47
- }
48
- if (command === "new") {
49
- customConfigFile = cliParams["config-file"];
50
- }
51
- const appDirectory = await (0, import_cli.initAppDir)(cwd);
52
- const autoLoadPlugins = await (0, import_utils2.getIsAutoLoadPlugins)(appDirectory, customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile));
53
- const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins, forceAutoLoadPlugins);
54
- await (0, import_run.run)({
55
- cwd,
56
- initialLog: initialLog || `Modern.js Framework v${version}`,
57
- configFile: customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile),
58
- packageJsonConfig: packageJsonConfig || import_constants.PACKAGE_JSON_CONFIG_NAME,
59
- internalPlugins: plugins,
60
- handleSetupResult: import_hooks.handleSetupResult
61
- });
62
- }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- run
66
- });
@@ -1,16 +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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
@@ -1,34 +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 utils_exports = {};
20
- __export(utils_exports, {
21
- getIsAutoLoadPlugins: () => getIsAutoLoadPlugins
22
- });
23
- module.exports = __toCommonJS(utils_exports);
24
- var import_cli = require("@modern-js/plugin-v2/cli");
25
- async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
26
- var _loaded_config;
27
- const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
28
- const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
29
- return autoLoadPlugins || false;
30
- }
31
- // Annotate the CommonJS export names for ESM import in node:
32
- 0 && (module.exports = {
33
- getIsAutoLoadPlugins
34
- });
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
- });