@modern-js/core 2.0.0-beta.1 → 2.0.0-beta.3

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 (78) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/dist/bin.js +1 -4
  3. package/dist/config/createLoadedConfig.d.ts +6 -0
  4. package/dist/config/createLoadedConfig.js +35 -0
  5. package/dist/config/createResolvedConfig.d.ts +3 -0
  6. package/dist/config/createResolvedConfig.js +91 -0
  7. package/dist/config/index.d.ts +2 -17
  8. package/dist/config/index.js +2 -136
  9. package/dist/context.d.ts +5 -9
  10. package/dist/index.d.ts +8 -13
  11. package/dist/index.js +22 -59
  12. package/dist/loadPlugins.d.ts +2 -12
  13. package/dist/loadPlugins.js +12 -5
  14. package/dist/manager.d.ts +80 -64
  15. package/dist/manager.js +11 -5
  16. package/dist/runBin.d.ts +5 -0
  17. package/dist/runBin.js +50 -0
  18. package/dist/schema/patchSchema.d.ts +19 -0
  19. package/dist/{config/schema/index.js → schema/patchSchema.js} +8 -45
  20. package/dist/schema/source.d.ts +9 -0
  21. package/dist/schema/source.js +10 -0
  22. package/dist/schema/testing.d.ts +13 -0
  23. package/dist/schema/testing.js +11 -0
  24. package/dist/schema/traverseSchema.d.ts +2 -0
  25. package/dist/schema/traverseSchema.js +20 -0
  26. package/dist/types/config/index.d.ts +41 -0
  27. package/dist/{config/types → types/config}/index.js +0 -0
  28. package/dist/types/config/testing.d.ts +15 -0
  29. package/dist/{config/types/electron.js → types/config/testing.js} +0 -0
  30. package/dist/types/context.d.ts +26 -0
  31. package/dist/{config/types/less.js → types/context.js} +0 -0
  32. package/dist/types/hooks.d.ts +26 -0
  33. package/dist/{config/types/postcss.js → types/hooks.js} +0 -0
  34. package/dist/types/index.d.ts +10 -1
  35. package/dist/types/index.js +5 -1
  36. package/dist/types/plugin.d.ts +26 -0
  37. package/dist/{config/types/sass.js → types/plugin.js} +0 -0
  38. package/dist/types/pluginAPI.d.ts +18 -0
  39. package/dist/{config/types/ssg.js → types/pluginAPI.js} +0 -0
  40. package/dist/utils/mergeConfig.d.ts +2 -0
  41. package/dist/{config → utils}/mergeConfig.js +1 -8
  42. package/dist/utils/repeatKeyWarning.d.ts +2 -2
  43. package/dist/utils/repeatKeyWarning.js +2 -2
  44. package/package.json +24 -10
  45. package/compiled/v8-compile-cache/index.d.ts +0 -1
  46. package/compiled/v8-compile-cache/index.js +0 -1
  47. package/compiled/v8-compile-cache/license +0 -21
  48. package/compiled/v8-compile-cache/package.json +0 -1
  49. package/dist/config/defaults.d.ts +0 -29
  50. package/dist/config/defaults.js +0 -110
  51. package/dist/config/mergeConfig.d.ts +0 -32
  52. package/dist/config/schema/deploy.d.ts +0 -16
  53. package/dist/config/schema/deploy.js +0 -16
  54. package/dist/config/schema/index.d.ts +0 -499
  55. package/dist/config/schema/output.d.ts +0 -146
  56. package/dist/config/schema/output.js +0 -68
  57. package/dist/config/schema/server.d.ts +0 -194
  58. package/dist/config/schema/server.js +0 -111
  59. package/dist/config/schema/source.d.ts +0 -64
  60. package/dist/config/schema/source.js +0 -38
  61. package/dist/config/schema/tools.d.ts +0 -51
  62. package/dist/config/schema/tools.js +0 -24
  63. package/dist/config/types/electron.d.ts +0 -13
  64. package/dist/config/types/index.d.ts +0 -260
  65. package/dist/config/types/less.d.ts +0 -12
  66. package/dist/config/types/postcss.d.ts +0 -28
  67. package/dist/config/types/sass.d.ts +0 -10
  68. package/dist/config/types/ssg.d.ts +0 -15
  69. package/dist/config/types/test.d.ts +0 -14
  70. package/dist/config/types/test.js +0 -2
  71. package/dist/config/types/ts-loader.d.ts +0 -23
  72. package/dist/config/types/ts-loader.js +0 -2
  73. package/dist/initWatcher.d.ts +0 -3
  74. package/dist/initWatcher.js +0 -66
  75. package/dist/pluginAPI.d.ts +0 -13
  76. package/dist/pluginAPI.js +0 -16
  77. package/dist/types/cli.d.ts +0 -59
  78. package/dist/types/cli.js +0 -2
package/dist/index.js CHANGED
@@ -21,14 +21,13 @@ exports.initAppContext = exports.initAppDir = exports.cli = exports.mergeOptions
21
21
  const path_1 = __importDefault(require("path"));
22
22
  const utils_1 = require("@modern-js/utils");
23
23
  const commander_1 = require("./utils/commander");
24
- const config_1 = require("./config");
25
24
  const loadPlugins_1 = require("./loadPlugins");
26
25
  const context_1 = require("./context");
27
26
  Object.defineProperty(exports, "initAppContext", { enumerable: true, get: function () { return context_1.initAppContext; } });
28
- const initWatcher_1 = require("./initWatcher");
29
27
  const loadEnv_1 = require("./loadEnv");
30
28
  const manager_1 = require("./manager");
31
- __exportStar(require("./config"), exports);
29
+ const config_1 = require("./config");
30
+ __exportStar(require("./types"), exports);
32
31
  __exportStar(require("@modern-js/plugin"), exports);
33
32
  // TODO: remove export after refactor all plugins
34
33
  var manager_2 = require("./manager");
@@ -36,14 +35,13 @@ Object.defineProperty(exports, "manager", { enumerable: true, get: function () {
36
35
  Object.defineProperty(exports, "mountHook", { enumerable: true, get: function () { return manager_2.mountHook; } });
37
36
  Object.defineProperty(exports, "createPlugin", { enumerable: true, get: function () { return manager_2.createPlugin; } });
38
37
  Object.defineProperty(exports, "registerHook", { enumerable: true, get: function () { return manager_2.registerHook; } });
39
- // TODO: remove export after refactor all plugins
40
- var pluginAPI_1 = require("./pluginAPI");
41
- Object.defineProperty(exports, "AppContext", { enumerable: true, get: function () { return pluginAPI_1.AppContext; } });
42
- Object.defineProperty(exports, "ConfigContext", { enumerable: true, get: function () { return pluginAPI_1.ConfigContext; } });
43
- Object.defineProperty(exports, "ResolvedConfigContext", { enumerable: true, get: function () { return pluginAPI_1.ResolvedConfigContext; } });
44
- Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return pluginAPI_1.useAppContext; } });
45
- Object.defineProperty(exports, "useConfigContext", { enumerable: true, get: function () { return pluginAPI_1.useConfigContext; } });
46
- Object.defineProperty(exports, "useResolvedConfigContext", { enumerable: true, get: function () { return pluginAPI_1.useResolvedConfigContext; } });
38
+ var context_2 = require("./context");
39
+ Object.defineProperty(exports, "AppContext", { enumerable: true, get: function () { return context_2.AppContext; } });
40
+ Object.defineProperty(exports, "ConfigContext", { enumerable: true, get: function () { return context_2.ConfigContext; } });
41
+ Object.defineProperty(exports, "ResolvedConfigContext", { enumerable: true, get: function () { return context_2.ResolvedConfigContext; } });
42
+ Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return context_2.useAppContext; } });
43
+ Object.defineProperty(exports, "useConfigContext", { enumerable: true, get: function () { return context_2.useConfigContext; } });
44
+ Object.defineProperty(exports, "useResolvedConfigContext", { enumerable: true, get: function () { return context_2.useResolvedConfigContext; } });
47
45
  const initAppDir = async (cwd) => {
48
46
  if (!cwd) {
49
47
  // eslint-disable-next-line no-param-reassign
@@ -71,21 +69,19 @@ const setProgramVersion = (version = 'unknown') => {
71
69
  };
72
70
  const createCli = () => {
73
71
  let hooksRunner;
74
- let isRestart = false;
75
- let restartWithExistingPort = 0;
76
- let restartOptions;
77
- const init = async (argv = [], options) => {
72
+ let initOptions;
73
+ const init = async (options) => {
78
74
  var _a, _b, _c, _d;
79
75
  manager_1.manager.clear();
80
76
  const mergedOptions = (0, exports.mergeOptions)(options);
81
- restartOptions = mergedOptions;
77
+ initOptions = mergedOptions;
82
78
  const appDirectory = await initAppDir(options === null || options === void 0 ? void 0 : options.cwd);
83
79
  (0, commander_1.initCommandsMap)();
84
80
  setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
85
81
  const metaName = (_b = (_a = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options) === null || _a === void 0 ? void 0 : _a.metaName) !== null && _b !== void 0 ? _b : 'MODERN';
86
82
  (0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
87
- const loaded = await (0, config_1.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
88
- const plugins = (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
83
+ const loaded = await (0, config_1.createLoadedConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
84
+ const plugins = await (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
89
85
  internalPlugins: (_c = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _c === void 0 ? void 0 : _c.cli,
90
86
  transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin,
91
87
  });
@@ -98,8 +94,6 @@ const createCli = () => {
98
94
  serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile,
99
95
  serverInternalPlugins: ((_d = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _d === void 0 ? void 0 : _d.server) || utils_1.INTERNAL_SERVER_PLUGINS,
100
96
  });
101
- // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
102
- (0, config_1.addServerConfigToDeps)(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
103
97
  context_1.ConfigContext.set(loaded.config);
104
98
  context_1.AppContext.set(appContext);
105
99
  hooksRunner = await manager_1.manager.init();
@@ -117,68 +111,37 @@ const createCli = () => {
117
111
  });
118
112
  const extraConfigs = await hooksRunner.config();
119
113
  const extraSchemas = await hooksRunner.validateSchema();
120
- const config = await (0, config_1.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
114
+ const normalizedConfig = await (0, config_1.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
121
115
  const { resolved } = await hooksRunner.resolvedConfig({
122
- resolved: config,
116
+ resolved: normalizedConfig,
123
117
  });
124
118
  // update context value
125
119
  context_1.ConfigContext.set(loaded.config);
126
120
  context_1.ResolvedConfigContext.set(resolved);
127
- context_1.AppContext.set({
128
- ...appContext,
129
- port: resolved.server.port,
130
- distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path),
131
- });
121
+ await hooksRunner.addRuntimeExports();
132
122
  await hooksRunner.prepare();
133
123
  return {
134
- loadedConfig: loaded,
135
- // appContext may be updated in `prepare` hook, should return latest value
136
- appContext: (0, context_1.useAppContext)(),
137
124
  resolved,
125
+ appContext: (0, context_1.useAppContext)(),
138
126
  };
139
127
  };
140
- async function run(argv, options) {
141
- const { loadedConfig, appContext, resolved } = await init(argv, options);
128
+ async function run(options) {
129
+ await init(options);
142
130
  await hooksRunner.commands({ program: utils_1.program });
143
- (0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
144
131
  utils_1.program.parse(process.argv);
145
132
  }
146
- async function restart() {
147
- var _a, _b;
148
- isRestart = true;
149
- restartWithExistingPort = isRestart ? (_b = (_a = context_1.AppContext.use().value) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 0 : 0;
150
- utils_1.logger.info('Restart...\n');
151
- let hasGetError = false;
152
- const runner = manager_1.manager.useRunner();
153
- await runner.beforeRestart();
154
- try {
155
- await init(process.argv.slice(2), restartOptions);
156
- }
157
- catch (err) {
158
- console.error(err);
159
- hasGetError = true;
160
- }
161
- finally {
162
- if (!hasGetError) {
163
- utils_1.program.parse(process.argv);
164
- }
165
- }
166
- }
167
133
  async function test(argv, options) {
168
134
  const newProgram = new utils_1.Command();
169
135
  const { coreOptions } = options !== null && options !== void 0 ? options : {};
170
- const { loadedConfig, appContext, resolved } = await init(argv, coreOptions);
136
+ await init(coreOptions);
171
137
  await hooksRunner.commands({ program: newProgram });
172
- if (!(options === null || options === void 0 ? void 0 : options.disableWatcher)) {
173
- (0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
174
- }
175
138
  await newProgram.parseAsync(argv);
176
139
  }
177
140
  return {
178
141
  init,
179
142
  run,
180
- restart,
181
143
  test,
144
+ getPrevInitOptions: () => initOptions,
182
145
  };
183
146
  };
184
147
  exports.cli = createCli();
@@ -1,15 +1,6 @@
1
1
  import { InternalPlugins } from '@modern-js/types';
2
- import type { UserConfig } from './config';
3
- import { CliPlugin } from './manager';
4
- declare type PluginItem = string | [string, any];
2
+ import type { CliPlugin, UserConfig, OldPluginConfig, PluginConfig } from './types';
5
3
  export declare type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
6
- /**
7
- * @deprecated
8
- * Using NewPluginConfig instead.
9
- */
10
- declare type OldPluginConfig = Array<PluginItem>;
11
- export declare type NewPluginConfig<T = {}> = CliPlugin<T>[];
12
- export declare type PluginConfig = OldPluginConfig | NewPluginConfig;
13
4
  export declare const isOldPluginConfig: (config?: PluginConfig) => config is OldPluginConfig;
14
5
  /**
15
6
  * Load internal plugins which in @modern-js scope and user's custom plugins.
@@ -22,5 +13,4 @@ export declare const isOldPluginConfig: (config?: PluginConfig) => config is Old
22
13
  export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
23
14
  internalPlugins?: InternalPlugins;
24
15
  transformPlugin?: TransformPlugin;
25
- }) => CliPlugin<{}>[];
26
- export {};
16
+ }) => Promise<CliPlugin<{}, {}, {}, {}>[]>;
@@ -4,11 +4,18 @@ exports.loadPlugins = exports.isOldPluginConfig = void 0;
4
4
  const utils_1 = require("@modern-js/utils");
5
5
  const manager_1 = require("./manager");
6
6
  const debug = (0, utils_1.createDebugger)('load-plugins');
7
- const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
7
+ const resolveCliPlugin = async (p, userConfig, appDirectory, transformPlugin) => {
8
8
  const pkg = typeof p === 'string' ? p : p[0];
9
9
  const pluginOptions = typeof p === 'string' ? undefined : p[1];
10
10
  const path = (0, utils_1.tryResolve)(pkg, appDirectory);
11
- let module = (0, utils_1.compatRequire)(path);
11
+ let module;
12
+ try {
13
+ module = (0, utils_1.compatRequire)(path);
14
+ }
15
+ catch (e) {
16
+ // load esm module
17
+ ({ default: module } = await (0, utils_1.dynamicImport)(path));
18
+ }
12
19
  if (transformPlugin) {
13
20
  module = transformPlugin(module, userConfig, pluginOptions);
14
21
  }
@@ -31,18 +38,18 @@ exports.isOldPluginConfig = isOldPluginConfig;
31
38
  * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
32
39
  * @returns Plugin Objects has been required.
33
40
  */
34
- const loadPlugins = (appDirectory, userConfig, options = {}) => {
41
+ const loadPlugins = async (appDirectory, userConfig, options = {}) => {
35
42
  const pluginConfig = userConfig.plugins;
36
43
  const plugins = [
37
44
  ...(0, utils_1.getInternalPlugins)(appDirectory, options.internalPlugins),
38
45
  ...((0, exports.isOldPluginConfig)(pluginConfig) ? pluginConfig : []),
39
46
  ];
40
- const loadedPlugins = plugins.map(plugin => {
47
+ const loadedPlugins = await Promise.all(plugins.map(plugin => {
41
48
  const loadedPlugin = resolveCliPlugin(plugin, userConfig, appDirectory, options.transformPlugin);
42
49
  // server plugins don't support to accept params
43
50
  debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
44
51
  return loadedPlugin;
45
- });
52
+ }));
46
53
  if (!(0, exports.isOldPluginConfig)(pluginConfig)) {
47
54
  if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.length) {
48
55
  loadedPlugins.push(...pluginConfig.map(item => (0, manager_1.createPlugin)(item.setup, item)));
package/dist/manager.d.ts CHANGED
@@ -1,71 +1,87 @@
1
- import { ToThreads, ToRunners, AsyncSetup, PluginOptions, AsyncWorkflow, AsyncWaterfall, ParallelWorkflow } from '@modern-js/plugin';
2
- import type { Hooks } from './types';
3
- import type { Command } from './utils/commander';
4
- import type { NormalizedConfig } from './config/mergeConfig';
5
- import type { UserConfig } from './config';
6
- import { pluginAPI } from './pluginAPI';
7
- export declare type HooksRunner = ToRunners<{
8
- config: ParallelWorkflow<void, UserConfig>;
9
- resolvedConfig: AsyncWaterfall<{
10
- resolved: NormalizedConfig;
1
+ import { BasePluginAPI } from './types';
2
+ export declare const manager: import("@modern-js/plugin").AsyncManager<{
3
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
4
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
5
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
11
6
  }>;
12
- validateSchema: ParallelWorkflow<void>;
13
- prepare: AsyncWorkflow<void, void>;
14
- commands: AsyncWorkflow<{
15
- program: Command;
7
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
8
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
9
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
10
+ program: import("@modern-js/utils").Command;
16
11
  }, void>;
17
- watchFiles: ParallelWorkflow<void>;
18
- fileChange: AsyncWorkflow<{
19
- filename: string;
20
- eventType: 'add' | 'change' | 'unlink';
12
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
13
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
14
+ }, BasePluginAPI<{}, {}, {}, {}>>;
15
+ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSetup<{
16
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
17
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
18
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
19
+ }>;
20
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
21
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
22
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
23
+ program: import("@modern-js/utils").Command;
21
24
  }, void>;
22
- beforeExit: AsyncWorkflow<void, void>;
23
- beforeRestart: AsyncWorkflow<void, void>;
24
- }>;
25
- declare const baseHooks: {
26
- config: ParallelWorkflow<void, UserConfig>;
27
- resolvedConfig: AsyncWaterfall<{
28
- resolved: NormalizedConfig;
25
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
26
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
27
+ }, BasePluginAPI<{}, {}, {}, {}>> | undefined, options?: import("@modern-js/plugin").PluginOptions<{
28
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
29
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
30
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
29
31
  }>;
30
- validateSchema: ParallelWorkflow<void, unknown>;
31
- prepare: AsyncWorkflow<void, void>;
32
- commands: AsyncWorkflow<{
33
- program: Command;
32
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
33
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
34
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
35
+ program: import("@modern-js/utils").Command;
34
36
  }, void>;
35
- watchFiles: ParallelWorkflow<void, unknown>;
36
- fileChange: AsyncWorkflow<{
37
- filename: string;
38
- eventType: 'add' | 'change' | 'unlink';
37
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
38
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
39
+ }, import("@modern-js/plugin").AsyncSetup<{
40
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
41
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
42
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
43
+ }>;
44
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
45
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
46
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
47
+ program: import("@modern-js/utils").Command;
48
+ }, void>;
49
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
50
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
51
+ }, BasePluginAPI<{}, {}, {}, {}>>, Record<string, unknown>, any, any> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
52
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
53
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
54
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
55
+ }>;
56
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
57
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
58
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
59
+ program: import("@modern-js/utils").Command;
60
+ }, void>;
61
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
62
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
63
+ }, BasePluginAPI<{}, {}, {}, {}>>, registerHook: (newHooks: Partial<{
64
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
65
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
66
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
67
+ }>;
68
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
69
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
70
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
71
+ program: import("@modern-js/utils").Command;
72
+ }, void>;
73
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
74
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
75
+ }>) => void, mountHook: () => import("@modern-js/plugin").ToRunners<{
76
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
77
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
78
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
79
+ }>;
80
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
81
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
82
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
83
+ program: import("@modern-js/utils").Command;
39
84
  }, void>;
40
- beforeExit: AsyncWorkflow<void, void>;
41
- beforeRestart: AsyncWorkflow<void, void>;
42
- };
43
- /** All hooks of cli plugin. */
44
- export declare type CliHooks = typeof baseHooks & Hooks;
45
- /** All hook callbacks of cli plugin. */
46
- export declare type CliHookCallbacks = ToThreads<CliHooks>;
47
- export declare const manager: import("@modern-js/plugin").AsyncManager<CliHooks, {
48
- setAppContext: (value: import("@modern-js/types/cli").IAppContext) => void;
49
- useAppContext: () => import("@modern-js/types/cli").IAppContext;
50
- useConfigContext: () => UserConfig;
51
- useResolvedConfigContext: () => NormalizedConfig;
85
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
86
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
52
87
  }>;
53
- /** Plugin options of a cli plugin. */
54
- export declare type CliPlugin<ExtendHooks = {}> = PluginOptions<CliHooks, AsyncSetup<CliHooks & ExtendHooks, typeof pluginAPI>, ExtendHooks>;
55
- export declare const createPlugin: (setup?: AsyncSetup<CliHooks, {
56
- setAppContext: (value: import("@modern-js/types/cli").IAppContext) => void;
57
- useAppContext: () => import("@modern-js/types/cli").IAppContext;
58
- useConfigContext: () => UserConfig;
59
- useResolvedConfigContext: () => NormalizedConfig;
60
- }> | undefined, options?: PluginOptions<CliHooks, AsyncSetup<CliHooks, {
61
- setAppContext: (value: import("@modern-js/types/cli").IAppContext) => void;
62
- useAppContext: () => import("@modern-js/types/cli").IAppContext;
63
- useConfigContext: () => UserConfig;
64
- useResolvedConfigContext: () => NormalizedConfig;
65
- }>, Record<string, unknown>> | undefined) => import("@modern-js/plugin").AsyncPlugin<CliHooks, {
66
- setAppContext: (value: import("@modern-js/types/cli").IAppContext) => void;
67
- useAppContext: () => import("@modern-js/types/cli").IAppContext;
68
- useConfigContext: () => UserConfig;
69
- useResolvedConfigContext: () => NormalizedConfig;
70
- }>, registerHook: (newHooks: Partial<CliHooks>) => void, mountHook: () => ToRunners<CliHooks>;
71
- export {};
package/dist/manager.js CHANGED
@@ -2,17 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mountHook = exports.registerHook = exports.createPlugin = exports.manager = void 0;
4
4
  const plugin_1 = require("@modern-js/plugin");
5
- const pluginAPI_1 = require("./pluginAPI");
5
+ const context_1 = require("./context");
6
+ // eslint-disable-next-line @typescript-eslint/ban-types
6
7
  const baseHooks = {
7
8
  config: (0, plugin_1.createParallelWorkflow)(),
8
9
  resolvedConfig: (0, plugin_1.createAsyncWaterfall)(),
9
10
  validateSchema: (0, plugin_1.createParallelWorkflow)(),
10
11
  prepare: (0, plugin_1.createAsyncWorkflow)(),
11
12
  commands: (0, plugin_1.createAsyncWorkflow)(),
12
- watchFiles: (0, plugin_1.createParallelWorkflow)(),
13
- fileChange: (0, plugin_1.createAsyncWorkflow)(),
14
13
  beforeExit: (0, plugin_1.createAsyncWorkflow)(),
15
- beforeRestart: (0, plugin_1.createAsyncWorkflow)(),
14
+ addRuntimeExports: (0, plugin_1.createAsyncWaterfall)(),
16
15
  };
17
- exports.manager = (0, plugin_1.createAsyncManager)(baseHooks, pluginAPI_1.pluginAPI);
16
+ // eslint-disable-next-line @typescript-eslint/ban-types
17
+ const pluginAPI = {
18
+ setAppContext: context_1.setAppContext,
19
+ useAppContext: context_1.useAppContext,
20
+ useConfigContext: context_1.useConfigContext,
21
+ useResolvedConfigContext: context_1.useResolvedConfigContext,
22
+ };
23
+ exports.manager = (0, plugin_1.createAsyncManager)(baseHooks, pluginAPI);
18
24
  exports.createPlugin = exports.manager.createPlugin, exports.registerHook = exports.manager.registerHook, exports.mountHook = exports.manager.useRunner;
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { CoreOptions } from '.';
3
+ export declare const run: (otherCoreOptions?: CoreOptions, options?: {
4
+ override?: boolean | ((coreOptions: CoreOptions) => Promise<CoreOptions> | CoreOptions) | undefined;
5
+ }) => Promise<void>;
package/dist/runBin.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.run = void 0;
5
+ const utils_1 = require("@modern-js/utils");
6
+ const _1 = require(".");
7
+ const run = async (otherCoreOptions = {}, options = {}) => {
8
+ const command = process.argv[2];
9
+ if (!process.env.NODE_ENV) {
10
+ if (['build', 'start', 'deploy', 'release'].includes(command)) {
11
+ process.env.NODE_ENV = 'production';
12
+ }
13
+ else if (command === 'test') {
14
+ process.env.NODE_ENV = 'test';
15
+ }
16
+ else {
17
+ process.env.NODE_ENV = 'development';
18
+ }
19
+ }
20
+ const { version } = require('../package.json');
21
+ const cliParams = (0, utils_1.minimist)(process.argv.slice(2));
22
+ const runOptions = {
23
+ version,
24
+ };
25
+ /**
26
+ * Commands that support specify config files
27
+ * Some commands can't support this feature, such as `new`
28
+ */
29
+ const SUPPORT_CONFIG_PARAM_COMMANDS = [
30
+ 'dev',
31
+ 'build',
32
+ 'deploy',
33
+ 'start',
34
+ 'inspect',
35
+ ];
36
+ const customConfigFile = cliParams.config || cliParams.c;
37
+ if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command) && customConfigFile) {
38
+ runOptions.configFile = customConfigFile;
39
+ }
40
+ if (typeof options.override === 'boolean' && options.override) {
41
+ await _1.cli.run(otherCoreOptions);
42
+ }
43
+ else if (typeof (options === null || options === void 0 ? void 0 : options.override) === 'function') {
44
+ await _1.cli.run(await options.override(runOptions));
45
+ }
46
+ else {
47
+ await _1.cli.run(utils_1.lodash.merge({}, runOptions, otherCoreOptions));
48
+ }
49
+ };
50
+ exports.run = run;
@@ -0,0 +1,19 @@
1
+ import { PluginValidateSchema } from '../types';
2
+ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | PluginValidateSchema[]>) => {
3
+ type: string;
4
+ properties: {
5
+ testing: {
6
+ type: string;
7
+ additionalProperties: boolean;
8
+ properties: {
9
+ transformer: {
10
+ type: string;
11
+ enum: string[];
12
+ };
13
+ jest: {
14
+ typeof: string[];
15
+ };
16
+ };
17
+ };
18
+ };
19
+ };
@@ -1,45 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseSchema = exports.patchSchema = void 0;
3
+ exports.patchSchema = void 0;
4
4
  const utils_1 = require("@modern-js/utils");
5
5
  const lodash_1 = require("@modern-js/utils/lodash");
6
- const source_1 = require("./source");
7
- const output_1 = require("./output");
8
- const server_1 = require("./server");
9
- const deploy_1 = require("./deploy");
10
- const tools_1 = require("./tools");
6
+ const testing_1 = require("./testing");
11
7
  const debug = (0, utils_1.createDebugger)('validate-schema');
12
- const plugins = {
13
- type: 'array',
14
- additionalProperties: false,
15
- };
16
- const dev = {
17
- type: 'object',
18
- properties: {
19
- assetPrefix: { type: ['boolean', 'string'] },
20
- https: {
21
- type: 'boolean',
22
- },
23
- },
24
- additionalProperties: false,
25
- };
26
8
  const patchSchema = (pluginSchemas) => {
27
9
  const finalSchema = (0, lodash_1.cloneDeep)({
28
10
  type: 'object',
29
- additionalProperties: false,
30
11
  properties: {
31
- source: source_1.source,
32
- output: output_1.output,
33
- server: server_1.server,
34
- deploy: deploy_1.deploy,
35
- plugins,
36
- dev,
37
- tools: tools_1.tools,
12
+ testing: testing_1.testing,
38
13
  },
39
14
  });
40
15
  const findTargetNode = (props) => {
41
16
  let node = finalSchema.properties;
42
17
  for (const prop of props) {
18
+ if (!node[prop]) {
19
+ node[prop] = {
20
+ type: 'object',
21
+ };
22
+ }
43
23
  node = node[prop];
44
24
  if (!node || !(0, utils_1.isObject)(node)) {
45
25
  throw new Error(`add schema ${props.join('.')} error`);
@@ -75,20 +55,3 @@ const patchSchema = (pluginSchemas) => {
75
55
  return finalSchema;
76
56
  };
77
57
  exports.patchSchema = patchSchema;
78
- const traverseSchema = (schema) => {
79
- const keys = [];
80
- const traverse = ({ properties }, old = []) => {
81
- for (const key of Object.keys(properties)) {
82
- const current = [...old, key];
83
- if (properties[key].type === 'object' && properties[key].properties) {
84
- traverse(properties[key], current);
85
- }
86
- else {
87
- keys.push(current.join('.'));
88
- }
89
- }
90
- };
91
- traverse(schema);
92
- return keys;
93
- };
94
- exports.traverseSchema = traverseSchema;
@@ -0,0 +1,9 @@
1
+ export declare const source: {
2
+ type: string;
3
+ additionalProperties: boolean;
4
+ properties: {
5
+ designSystem: {
6
+ type: string;
7
+ };
8
+ };
9
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.source = void 0;
4
+ exports.source = {
5
+ type: 'object',
6
+ additionalProperties: false,
7
+ properties: {
8
+ designSystem: { type: 'object' },
9
+ },
10
+ };
@@ -0,0 +1,13 @@
1
+ export declare const testing: {
2
+ type: string;
3
+ additionalProperties: boolean;
4
+ properties: {
5
+ transformer: {
6
+ type: string;
7
+ enum: string[];
8
+ };
9
+ jest: {
10
+ typeof: string[];
11
+ };
12
+ };
13
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testing = void 0;
4
+ exports.testing = {
5
+ type: 'object',
6
+ additionalProperties: false,
7
+ properties: {
8
+ transformer: { type: 'string', enum: ['babel-jest', 'ts-jest'] },
9
+ jest: { typeof: ['object', 'function'] },
10
+ },
11
+ };
@@ -0,0 +1,2 @@
1
+ import { patchSchema } from './patchSchema';
2
+ export declare const traverseSchema: (schema: ReturnType<typeof patchSchema>) => string[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traverseSchema = void 0;
4
+ const traverseSchema = (schema) => {
5
+ const keys = [];
6
+ const traverse = ({ properties }, old = []) => {
7
+ for (const key of Object.keys(properties)) {
8
+ const current = [...old, key];
9
+ if (properties[key].type === 'object' && properties[key].properties) {
10
+ traverse(properties[key], current);
11
+ }
12
+ else {
13
+ keys.push(current.join('.'));
14
+ }
15
+ }
16
+ };
17
+ traverse(schema);
18
+ return keys;
19
+ };
20
+ exports.traverseSchema = traverseSchema;