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

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 (76) hide show
  1. package/CHANGELOG.md +64 -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 +92 -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 +6 -14
  11. package/dist/index.js +23 -62
  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/schema/patchSchema.d.ts +19 -0
  17. package/dist/{config/schema/index.js → schema/patchSchema.js} +8 -45
  18. package/dist/schema/source.d.ts +9 -0
  19. package/dist/schema/source.js +10 -0
  20. package/dist/schema/testing.d.ts +13 -0
  21. package/dist/schema/testing.js +11 -0
  22. package/dist/schema/traverseSchema.d.ts +2 -0
  23. package/dist/schema/traverseSchema.js +20 -0
  24. package/dist/types/config/index.d.ts +41 -0
  25. package/dist/{config/types → types/config}/index.js +0 -0
  26. package/dist/types/config/testing.d.ts +15 -0
  27. package/dist/{config/types/electron.js → types/config/testing.js} +0 -0
  28. package/dist/types/context.d.ts +26 -0
  29. package/dist/{config/types/less.js → types/context.js} +0 -0
  30. package/dist/types/hooks.d.ts +26 -0
  31. package/dist/{config/types/postcss.js → types/hooks.js} +0 -0
  32. package/dist/types/index.d.ts +10 -1
  33. package/dist/types/index.js +5 -1
  34. package/dist/types/plugin.d.ts +26 -0
  35. package/dist/{config/types/sass.js → types/plugin.js} +0 -0
  36. package/dist/types/pluginAPI.d.ts +18 -0
  37. package/dist/{config/types/ssg.js → types/pluginAPI.js} +0 -0
  38. package/dist/utils/mergeConfig.d.ts +2 -0
  39. package/dist/{config → utils}/mergeConfig.js +1 -8
  40. package/dist/utils/repeatKeyWarning.d.ts +2 -2
  41. package/dist/utils/repeatKeyWarning.js +2 -2
  42. package/package.json +16 -9
  43. package/compiled/v8-compile-cache/index.d.ts +0 -1
  44. package/compiled/v8-compile-cache/index.js +0 -1
  45. package/compiled/v8-compile-cache/license +0 -21
  46. package/compiled/v8-compile-cache/package.json +0 -1
  47. package/dist/config/defaults.d.ts +0 -29
  48. package/dist/config/defaults.js +0 -110
  49. package/dist/config/mergeConfig.d.ts +0 -32
  50. package/dist/config/schema/deploy.d.ts +0 -16
  51. package/dist/config/schema/deploy.js +0 -16
  52. package/dist/config/schema/index.d.ts +0 -499
  53. package/dist/config/schema/output.d.ts +0 -146
  54. package/dist/config/schema/output.js +0 -68
  55. package/dist/config/schema/server.d.ts +0 -194
  56. package/dist/config/schema/server.js +0 -111
  57. package/dist/config/schema/source.d.ts +0 -64
  58. package/dist/config/schema/source.js +0 -38
  59. package/dist/config/schema/tools.d.ts +0 -51
  60. package/dist/config/schema/tools.js +0 -24
  61. package/dist/config/types/electron.d.ts +0 -13
  62. package/dist/config/types/index.d.ts +0 -260
  63. package/dist/config/types/less.d.ts +0 -12
  64. package/dist/config/types/postcss.d.ts +0 -28
  65. package/dist/config/types/sass.d.ts +0 -10
  66. package/dist/config/types/ssg.d.ts +0 -15
  67. package/dist/config/types/test.d.ts +0 -14
  68. package/dist/config/types/test.js +0 -2
  69. package/dist/config/types/ts-loader.d.ts +0 -23
  70. package/dist/config/types/ts-loader.js +0 -2
  71. package/dist/initWatcher.d.ts +0 -3
  72. package/dist/initWatcher.js +0 -66
  73. package/dist/pluginAPI.d.ts +0 -13
  74. package/dist/pluginAPI.js +0 -16
  75. package/dist/types/cli.d.ts +0 -59
  76. package/dist/types/cli.js +0 -2
@@ -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,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;
@@ -0,0 +1,41 @@
1
+ import { PluginConfig } from '../plugin';
2
+ import type { BaseTestingNormalizedConfig, BaseTestingUserConfig } from './testing';
3
+ export type { Jest as JestConfig, BaseTestingUserConfig as TestConfig, } from './testing';
4
+ declare type DropUndefined<T> = T extends undefined ? never : T;
5
+ export declare type UserConfig<Extends extends {
6
+ hooks?: ExtendHooks;
7
+ userConfig?: ExtendUserConfig;
8
+ normalizedConfig?: ExtendNormalizedConfig;
9
+ } = {}, ExtendHooks extends Record<string, any> = {}, ExtendUserConfig extends {
10
+ source?: Record<string, any>;
11
+ tools?: Record<string, any>;
12
+ testing?: Record<string, any>;
13
+ [property: string]: any;
14
+ } = {}, ExtendNormalizedConfig extends Record<string, any> = {}> = {
15
+ testing?: BaseTestingUserConfig<DropUndefined<Extends['userConfig']>['testing']>;
16
+ plugins?: PluginConfig<Extends>;
17
+ } & Omit<Extends['userConfig'], 'plugins' | 'testing'>;
18
+ export declare type NormalizedConfig<Extends extends {
19
+ hooks?: ExtendHooks;
20
+ userConfig?: ExtendUserConfig;
21
+ normalizedConfig?: ExtendNormalizedConfig;
22
+ } = {}, ExtendHooks extends Record<string, any> = {}, ExtendUserConfig extends Record<string, any> = {}, ExtendNormalizedConfig extends {
23
+ source?: Record<string, any>;
24
+ tools?: Record<string, any>;
25
+ testing?: Record<string, any>;
26
+ [property: string]: any;
27
+ } = {}> = {
28
+ plugins: PluginConfig<Extends>;
29
+ testing: BaseTestingNormalizedConfig<DropUndefined<Extends['normalizedConfig']>['testing']>;
30
+ } & Omit<Extends['normalizedConfig'], 'plugins' | 'testing'>;
31
+ export declare type LoadedConfig<Extends extends {
32
+ hooks?: ExtendHooks;
33
+ userConfig?: ExtendUserConfig;
34
+ } = {}, ExtendHooks extends {} = {}, ExtendUserConfig extends Record<string, any> = {}> = {
35
+ config: UserConfig<Extends>;
36
+ filePath: string | false;
37
+ dependencies: string[];
38
+ pkgConfig: UserConfig<Extends>;
39
+ jsConfig: UserConfig<Extends>;
40
+ };
41
+ export declare type ConfigParams = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
File without changes
@@ -0,0 +1,15 @@
1
+ import type { JestConfigTypes, Merge } from '@modern-js/types';
2
+ export declare type Jest = JestConfigTypes.InitialOptions;
3
+ export declare type BaseTestingUserConfig<ExtendTestingUserConfig = {}> = Merge<{
4
+ /**
5
+ * Decide which transformer will be used to compile file
6
+ * Default: babel-jest
7
+ */
8
+ transformer?: 'babel-jest' | 'ts-jest';
9
+ /**
10
+ * Original jest config
11
+ * Doc: https://jestjs.io/docs/configuration
12
+ */
13
+ jest?: Jest | ((jestConfig: Jest) => Jest);
14
+ }, ExtendTestingUserConfig>;
15
+ export declare type BaseTestingNormalizedConfig<ExtendTestingNormailzedConfig = {}> = BaseTestingUserConfig<ExtendTestingNormailzedConfig>;
@@ -0,0 +1,26 @@
1
+ import { Entrypoint, InternalPlugins, ServerRoute, HtmlTemplates } from '@modern-js/types';
2
+ import { BuilderInstance } from '@modern-js/builder-shared';
3
+ export interface IAppContext {
4
+ metaName: string;
5
+ appDirectory: string;
6
+ configFile: string | false;
7
+ serverConfigFile: string;
8
+ serverInternalPlugins: InternalPlugins;
9
+ ip?: string;
10
+ port?: number;
11
+ distDirectory: string;
12
+ packageName: string;
13
+ srcDirectory: string;
14
+ sharedDirectory: string;
15
+ nodeModulesDirectory: string;
16
+ internalDirectory: string;
17
+ plugins: any[];
18
+ entrypoints: Entrypoint[];
19
+ checkedEntries: string[];
20
+ serverRoutes: ServerRoute[];
21
+ htmlTemplates: HtmlTemplates;
22
+ apiOnly: boolean;
23
+ internalDirAlias: string;
24
+ internalSrcAlias: string;
25
+ builder?: BuilderInstance;
26
+ }
File without changes
@@ -0,0 +1,26 @@
1
+ import { ParallelWorkflow, AsyncWaterfall, AsyncWorkflow, ToRunners, ToThreads } from '@modern-js/plugin';
2
+ import type { Command } from '@modern-js/utils';
3
+ import type { UserConfig, NormalizedConfig } from './config';
4
+ export declare type BaseHooks<Extends extends {
5
+ hooks?: ExtendHooks;
6
+ userConfig?: ExtendUserConfig;
7
+ normalizedConfig?: ExtendNormalizedConfig;
8
+ }, ExtendHooks extends {} = {}, ExtendUserConfig extends Record<string, any> = {}, ExtendNormalizedConfig extends Record<string, any> = {}> = {
9
+ config: ParallelWorkflow<void, UserConfig<Extends>>;
10
+ resolvedConfig: AsyncWaterfall<{
11
+ resolved: NormalizedConfig<Extends>;
12
+ }>;
13
+ validateSchema: ParallelWorkflow<void>;
14
+ prepare: AsyncWorkflow<void, void>;
15
+ commands: AsyncWorkflow<{
16
+ program: Command;
17
+ }, void>;
18
+ beforeExit: AsyncWorkflow<void, void>;
19
+ addRuntimeExports: AsyncWaterfall<void>;
20
+ };
21
+ export declare type CliHooksRunner<Extends extends {
22
+ hooks?: ExtendHooks;
23
+ userConfig?: ExtendUserConfig;
24
+ normalizedConfig?: ExtendNormalizedConfig;
25
+ } = {}, ExtendHooks extends {} = {}, ExtendUserConfig extends Record<string, any> = {}, ExtendNormalizedConfig extends Record<string, any> = {}> = ToRunners<BaseHooks<Extends> & Extends['hooks']>;
26
+ export declare type CliHookCallbacks = ToThreads<BaseHooks<{}>>;
File without changes
@@ -1 +1,10 @@
1
- export * from './cli';
1
+ import type { JSONSchemaType } from '@modern-js/utils/ajv/json-schema';
2
+ export * from './plugin';
3
+ export * from './config';
4
+ export * from './pluginAPI';
5
+ export * from './hooks';
6
+ export * from './context';
7
+ export interface PluginValidateSchema {
8
+ target: string;
9
+ schema: JSONSchemaType<any>;
10
+ }
@@ -14,4 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cli"), exports);
17
+ __exportStar(require("./plugin"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./pluginAPI"), exports);
20
+ __exportStar(require("./hooks"), exports);
21
+ __exportStar(require("./context"), exports);
@@ -0,0 +1,26 @@
1
+ import { AsyncSetup, PluginOptions } from '@modern-js/plugin';
2
+ import { BaseHooks } from './hooks';
3
+ import { BasePluginAPI } from './pluginAPI';
4
+ export type { InternalPlugins } from '@modern-js/types';
5
+ /** Plugin options of a cli plugin. */
6
+ export declare type CliPlugin<Extends extends {
7
+ hooks?: ExtendHooks;
8
+ userConfig?: ExtendUserConfig;
9
+ normalizedConfig?: ExtendNormalizedConfig;
10
+ } = {}, ExtendHooks extends Record<string, any> = {}, ExtendUserConfig extends Record<string, any> = {}, ExtendNormalizedConfig extends Record<string, any> = {}> = PluginOptions<BaseHooks<Extends>, AsyncSetup<BaseHooks<Extends> & Extends['hooks'], BasePluginAPI<Extends>>, Extends['hooks'], BaseHooks<Extends> | BaseHooks<{}>, AsyncSetup<BaseHooks<Extends> & Extends['hooks'], BasePluginAPI<Extends>> | AsyncSetup<BaseHooks<{}>, BasePluginAPI<{}>>>;
11
+ export declare type PluginItem = string | [string, any];
12
+ /**
13
+ * @deprecated
14
+ * Using NewPluginConfig instead.
15
+ */
16
+ export declare type OldPluginConfig = Array<PluginItem>;
17
+ export declare type NewPluginConfig<PluginTypes extends {
18
+ hooks?: Record<string, any>;
19
+ userConfig?: Record<string, any>;
20
+ normalizedConfig?: Record<string, any>;
21
+ }> = CliPlugin<PluginTypes>[];
22
+ export declare type PluginConfig<PluginTypes extends {
23
+ hooks?: Record<string, any>;
24
+ userConfig?: Record<string, any>;
25
+ normalizedConfig?: Record<string, any>;
26
+ } = {}> = OldPluginConfig | NewPluginConfig<PluginTypes>;
File without changes
@@ -0,0 +1,18 @@
1
+ import { CommonAPI } from '@modern-js/plugin';
2
+ import type { setAppContext, useAppContext, useResolvedConfigContext, useConfigContext } from '../context';
3
+ import { BaseHooks } from './hooks';
4
+ export declare type BasePluginAPI<Extends extends {
5
+ hooks?: ExtendHooks;
6
+ userConfig?: ExtendUserConfig;
7
+ normalizedConfig?: ExtendNormalizedConfig;
8
+ }, ExtendHooks extends {} = {}, ExtendUserConfig extends Record<string, any> = {}, ExtendNormalizedConfig extends Record<string, any> = {}> = {
9
+ setAppContext: typeof setAppContext;
10
+ useAppContext: typeof useAppContext;
11
+ useConfigContext: typeof useConfigContext<Extends>;
12
+ useResolvedConfigContext: typeof useResolvedConfigContext<Extends>;
13
+ };
14
+ /** all apis for cli plugin */
15
+ export declare type PluginAPI<Extends extends {
16
+ hooks?: ExtendHooks;
17
+ userConfig?: ExtendUserConfig;
18
+ } = {}, ExtendHooks extends {} = {}, ExtendUserConfig extends Record<string, any> = {}> = BasePluginAPI<Extends> & CommonAPI<BaseHooks<Extends> & Extends['hooks']>;
File without changes
@@ -0,0 +1,2 @@
1
+ import { UserConfig, NormalizedConfig } from '../types';
2
+ export declare const mergeConfig: <ExtendConfig extends Record<string, any>>(configs: (UserConfig<ExtendConfig, {}, {}, {}> | NormalizedConfig<ExtendConfig, {}, {}, {}>)[]) => NormalizedConfig<ExtendConfig, {}, {}, {}>;
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeConfig = void 0;
4
4
  const lodash_1 = require("@modern-js/utils/lodash");
5
- const utils_1 = require("@modern-js/utils");
6
- /**
7
- * merge configuration from modern.config.js and plugins.
8
- *
9
- * @param configs - Configuration from modern.config.ts or plugin's config hook.
10
- * @returns - normalized user config.
11
- */
12
5
  const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target, source, key) => {
13
6
  // Do not use the following merge logic for source.designSystem and tools.tailwind(css)
14
7
  if (key === 'designSystem' ||
@@ -25,7 +18,7 @@ const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target
25
18
  return source !== undefined ? [...target, source] : target;
26
19
  }
27
20
  }
28
- else if ((0, utils_1.isFunction)(target) || (0, utils_1.isFunction)(source)) {
21
+ else if ((0, lodash_1.isFunction)(target) || (0, lodash_1.isFunction)(source)) {
29
22
  if (source === undefined) {
30
23
  return target;
31
24
  }
@@ -1,3 +1,3 @@
1
- import { UserConfig } from '../config';
1
+ import { UserConfig } from '../types';
2
2
  export declare const deepGet: (obj: any, key: string) => any;
3
- export declare const repeatKeyWarning: (schema: any, jsConfig: UserConfig, pkgConfig: UserConfig) => void;
3
+ export declare const repeatKeyWarning: <E extends Record<string, any>>(schema: any, jsConfig: UserConfig<E, {}, {}, {}>, pkgConfig: UserConfig<E, {}, {}, {}>) => void;