@modern-js/core 2.8.0 → 2.10.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 2.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a16b9b0: feat: warning when user registe plugin duplication
8
+ feat: 当用户重复注册插件时进行 warning 提示
9
+
10
+ ### Patch Changes
11
+
12
+ - 0da32d0: chore: upgrade jest and puppeteer
13
+ chore: 升级 jest 和 puppeteer 到 latest
14
+ - d3f0642: feat(core): throw warnings when config file is not found
15
+
16
+ feat(core): 找不到配置文件时抛出 warning
17
+
18
+ - 0d9962b: fix: add types field in package.json
19
+ fix: 添加 package.json 中的 types 字段
20
+ - fbefa7e: chore(deps): bump webpack from 5.75.0 to 5.76.2
21
+
22
+ chore(deps): 将 webpack 从 5.75.0 升级至 5.76.2
23
+
24
+ - Updated dependencies [0da32d0]
25
+ - Updated dependencies [0d9962b]
26
+ - Updated dependencies [fbefa7e]
27
+ - Updated dependencies [4d54233]
28
+ - Updated dependencies [6db4864]
29
+ - @modern-js/node-bundle-require@2.10.0
30
+ - @modern-js/plugin@2.10.0
31
+ - @modern-js/utils@2.10.0
32
+
33
+ ## 2.9.0
34
+
35
+ ### Patch Changes
36
+
37
+ - 88328d914b: chore(core): remove legacy transformPlugin option
38
+
39
+ chore(core): 移除不再使用的 transformPlugin 选项
40
+
41
+ - dd56401486: chore: fix some TODO comments
42
+
43
+ chore: 处理一些标记 TODO 的问题
44
+
45
+ - @modern-js/node-bundle-require@2.9.0
46
+ - @modern-js/plugin@2.9.0
47
+ - @modern-js/utils@2.9.0
48
+
3
49
  ## 2.8.0
4
50
 
5
51
  ### Patch Changes
@@ -56,6 +56,10 @@ async function loadLocalConfig(appDirectory, configFile) {
56
56
  async function createLoadedConfig(appDirectory, filePath, packageJsonConfig) {
57
57
  const configFile = (0, loadConfig_1.getConfigFilePath)(appDirectory, filePath);
58
58
  const loaded = await (0, loadConfig_1.loadConfig)(appDirectory, configFile, packageJsonConfig);
59
+ if (!loaded.config && !loaded.pkgConfig) {
60
+ utils_1.logger.warn(`Can not find any config file in the current project, please check if you have a correct config file.`);
61
+ utils_1.logger.warn(`Current project path: ${utils_1.chalk.yellow(appDirectory)}`);
62
+ }
59
63
  const config = await getConfigObject(loaded.config);
60
64
  let mergedConfig = config;
61
65
  if (loaded.pkgConfig) {
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type { ErrorObject } from '@modern-js/utils/ajv';
2
2
  import { InternalPlugins } from '@modern-js/types';
3
- import { TransformPlugin } from './loadPlugins';
4
3
  import { initAppContext } from './context';
5
4
  import type { ToolsType } from './types';
6
5
  export * from './types';
7
6
  export * from '@modern-js/plugin';
8
- export { manager, mountHook, createPlugin, registerHook } from './manager';
7
+ export { manager, createPlugin, registerHook } from './manager';
9
8
  export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './context';
10
9
  declare const initAppDir: (cwd?: string) => Promise<string>;
11
10
  export interface CoreOptions {
@@ -19,7 +18,6 @@ export interface CoreOptions {
19
18
  server?: InternalPlugins;
20
19
  autoLoad?: InternalPlugins;
21
20
  };
22
- transformPlugin?: TransformPlugin;
23
21
  onSchemaError?: (error: ErrorObject) => void;
24
22
  options?: {
25
23
  metaName?: string;
@@ -42,7 +40,6 @@ export declare const mergeOptions: (options?: CoreOptions) => {
42
40
  server?: InternalPlugins | undefined;
43
41
  autoLoad?: InternalPlugins | undefined;
44
42
  } | undefined;
45
- transformPlugin?: TransformPlugin | undefined;
46
43
  onSchemaError?: ((error: ErrorObject) => void) | undefined;
47
44
  options?: {
48
45
  metaName?: string | undefined;
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.initAppContext = exports.initAppDir = exports.cli = exports.mergeOptions = exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = exports.registerHook = exports.createPlugin = exports.mountHook = exports.manager = void 0;
20
+ exports.initAppContext = exports.initAppDir = exports.cli = exports.mergeOptions = exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = exports.registerHook = exports.createPlugin = exports.manager = void 0;
21
21
  const path_1 = __importDefault(require("path"));
22
22
  const utils_1 = require("@modern-js/utils");
23
23
  const utils_2 = require("./utils");
@@ -27,12 +27,11 @@ Object.defineProperty(exports, "initAppContext", { enumerable: true, get: functi
27
27
  const loadEnv_1 = require("./loadEnv");
28
28
  const manager_1 = require("./manager");
29
29
  const config_1 = require("./config");
30
+ const checkIsDuplicationPlugin_1 = require("./utils/checkIsDuplicationPlugin");
30
31
  __exportStar(require("./types"), exports);
31
32
  __exportStar(require("@modern-js/plugin"), exports);
32
- // TODO: remove export after refactor all plugins
33
33
  var manager_2 = require("./manager");
34
34
  Object.defineProperty(exports, "manager", { enumerable: true, get: function () { return manager_2.manager; } });
35
- Object.defineProperty(exports, "mountHook", { enumerable: true, get: function () { return manager_2.mountHook; } });
36
35
  Object.defineProperty(exports, "createPlugin", { enumerable: true, get: function () { return manager_2.createPlugin; } });
37
36
  Object.defineProperty(exports, "registerHook", { enumerable: true, get: function () { return manager_2.registerHook; } });
38
37
  var context_2 = require("./context");
@@ -83,10 +82,10 @@ const createCli = () => {
83
82
  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
83
  const plugins = await (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
85
84
  internalPlugins: (_c = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _c === void 0 ? void 0 : _c.cli,
86
- transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin,
87
85
  autoLoad: (_d = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _d === void 0 ? void 0 : _d.autoLoad,
88
86
  forceAutoLoadPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.forceAutoLoadPlugins,
89
87
  });
88
+ (0, checkIsDuplicationPlugin_1.checkIsDuplicationPlugin)(plugins.map(plugin => plugin.name), loaded.config.autoLoadPlugins);
90
89
  plugins.forEach(plugin => plugin && manager_1.manager.usePlugin(plugin));
91
90
  const appContext = (0, context_1.initAppContext)({
92
91
  toolsType: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.toolsType,
@@ -134,6 +133,9 @@ const createCli = () => {
134
133
  await hooksRunner.commands({ program: utils_1.program });
135
134
  await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
136
135
  utils_1.program.parse(process.argv);
136
+ if (!utils_1.program.commands || !utils_1.program.commands.length) {
137
+ utils_1.logger.warn('No command found, please make sure you have registered plugins correctly.');
138
+ }
137
139
  }
138
140
  async function test(argv, options) {
139
141
  const newProgram = new utils_1.Command();
@@ -1,18 +1,15 @@
1
1
  import { InternalPlugins } from '@modern-js/types';
2
2
  import type { CliPlugin, UserConfig, OldPluginConfig, PluginConfig } from './types';
3
- export type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
4
3
  export declare const isOldPluginConfig: (config?: PluginConfig) => config is OldPluginConfig;
5
4
  /**
6
5
  * Load internal plugins which in @modern-js scope and user's custom plugins.
7
6
  * @param appDirectory - Application root directory.
8
7
  * @param userConfig - Resolved user config.
9
8
  * @param options.internalPlugins - Internal plugins.
10
- * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
11
9
  * @returns Plugin Objects has been required.
12
10
  */
13
11
  export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
14
12
  internalPlugins?: InternalPlugins;
15
13
  autoLoad?: InternalPlugins;
16
- transformPlugin?: TransformPlugin;
17
14
  forceAutoLoadPlugins?: boolean;
18
15
  }) => Promise<CliPlugin<{}, {}, {}, {}>[]>;
@@ -4,7 +4,7 @@ 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 = async (p, userConfig, appDirectory, transformPlugin) => {
7
+ const resolveCliPlugin = async (p, appDirectory) => {
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);
@@ -16,9 +16,6 @@ const resolveCliPlugin = async (p, userConfig, appDirectory, transformPlugin) =>
16
16
  // load esm module
17
17
  ({ default: module } = await (0, utils_1.dynamicImport)(path));
18
18
  }
19
- if (transformPlugin) {
20
- module = transformPlugin(module, userConfig, pluginOptions);
21
- }
22
19
  if (typeof module === 'function') {
23
20
  const result = module(pluginOptions);
24
21
  return (0, manager_1.createPlugin)(result.setup, result);
@@ -35,7 +32,6 @@ exports.isOldPluginConfig = isOldPluginConfig;
35
32
  * @param appDirectory - Application root directory.
36
33
  * @param userConfig - Resolved user config.
37
34
  * @param options.internalPlugins - Internal plugins.
38
- * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
39
35
  * @returns Plugin Objects has been required.
40
36
  */
41
37
  const loadPlugins = async (appDirectory, userConfig, options = {}) => {
@@ -50,8 +46,7 @@ const loadPlugins = async (appDirectory, userConfig, options = {}) => {
50
46
  : []),
51
47
  ];
52
48
  const loadedPlugins = await Promise.all(plugins.map(plugin => {
53
- const loadedPlugin = resolveCliPlugin(plugin, userConfig, appDirectory, options.transformPlugin);
54
- // server plugins don't support to accept params
49
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
55
50
  debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
56
51
  return loadedPlugin;
57
52
  }));
package/dist/manager.d.ts CHANGED
@@ -108,22 +108,4 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
108
108
  }, void>;
109
109
  beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
110
110
  addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
111
- }>) => void, mountHook: () => import("@modern-js/plugin").ToRunners<{
112
- config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
113
- resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
114
- resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
115
- }>;
116
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
117
- prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
118
- afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
119
- watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, any>;
120
- fileChange: import("@modern-js/plugin").AsyncWorkflow<{
121
- filename: string;
122
- eventType: "add" | "unlink" | "change";
123
- }, void>;
124
- commands: import("@modern-js/plugin").AsyncWorkflow<{
125
- program: import("@modern-js/utils").Command;
126
- }, void>;
127
- beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
128
- addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
129
- }>;
111
+ }>) => void;
package/dist/manager.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mountHook = exports.registerHook = exports.createPlugin = exports.manager = void 0;
3
+ exports.registerHook = exports.createPlugin = exports.manager = void 0;
4
4
  const plugin_1 = require("@modern-js/plugin");
5
5
  const context_1 = require("./context");
6
6
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -24,4 +24,4 @@ const pluginAPI = {
24
24
  useResolvedConfigContext: context_1.useResolvedConfigContext,
25
25
  };
26
26
  exports.manager = (0, plugin_1.createAsyncManager)(baseHooks, pluginAPI);
27
- exports.createPlugin = exports.manager.createPlugin, exports.registerHook = exports.manager.registerHook, exports.mountHook = exports.manager.useRunner;
27
+ exports.createPlugin = exports.manager.createPlugin, exports.registerHook = exports.manager.registerHook;
@@ -0,0 +1 @@
1
+ export declare function checkIsDuplicationPlugin(plugins: (string | undefined)[], autoLoadPlugin?: boolean): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIsDuplicationPlugin = void 0;
4
+ const utils_1 = require("@modern-js/utils");
5
+ function checkIsDuplicationPlugin(plugins, autoLoadPlugin = false) {
6
+ const set = new Set();
7
+ const duplicationPlugins = [];
8
+ plugins
9
+ .filter(plugin => typeof plugin === 'string')
10
+ .forEach(plugin => {
11
+ if (set.has(plugin)) {
12
+ duplicationPlugins.push(plugin);
13
+ }
14
+ else {
15
+ set.add(plugin);
16
+ }
17
+ });
18
+ if (duplicationPlugins.length > 0) {
19
+ utils_1.logger.warn(`Duplicate registration plugins: ${duplicationPlugins.join(',')}.`);
20
+ if (autoLoadPlugin) {
21
+ utils_1.logger.warn('This is probably because you enabled `autoLoadPlugin` configuration and also registered these plugins manually');
22
+ }
23
+ }
24
+ }
25
+ exports.checkIsDuplicationPlugin = checkIsDuplicationPlugin;
@@ -2,3 +2,4 @@ export * from './commander';
2
2
  export * from './createFileWatcher';
3
3
  export * from './mergeConfig';
4
4
  export * from './repeatKeyWarning';
5
+ export * from './checkIsDuplicationPlugin';
@@ -18,3 +18,4 @@ __exportStar(require("./commander"), exports);
18
18
  __exportStar(require("./createFileWatcher"), exports);
19
19
  __exportStar(require("./mergeConfig"), exports);
20
20
  __exportStar(require("./repeatKeyWarning"), exports);
21
+ __exportStar(require("./checkIsDuplicationPlugin"), exports);
@@ -6,7 +6,6 @@ const lodash_1 = require("@modern-js/utils/lodash");
6
6
  const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target, source, key) => {
7
7
  // Do not use the following merge logic for source.designSystem and tools.tailwind(css)
8
8
  if (key === 'designSystem' ||
9
- (key === 'tailwind' && typeof source === 'object') ||
10
9
  (key === 'tailwindcss' && typeof source === 'object') ||
11
10
  key === 'devServer') {
12
11
  return (0, lodash_1.mergeWith)({}, target !== null && target !== void 0 ? target : {}, source !== null && source !== void 0 ? source : {});
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "modern",
11
11
  "modern.js"
12
12
  ],
13
- "version": "2.8.0",
13
+ "version": "2.10.0",
14
14
  "jsnext:source": "./src/index.ts",
15
15
  "types": "./dist/index.d.ts",
16
16
  "main": "./dist/index.js",
@@ -28,11 +28,18 @@
28
28
  "jsnext:source": "./src/bin.ts",
29
29
  "default": "./dist/bin.js"
30
30
  },
31
+ "./config": {
32
+ "jsnext:source": "./src/config.ts",
33
+ "types": "./dist/config/types/index.d.ts",
34
+ "default": "./dist/config/index.js"
35
+ },
31
36
  "./runBin": {
32
37
  "jsnext:source": "./src/runBin.ts",
38
+ "types": "./dist/runBin.d.ts",
33
39
  "default": "./dist/runBin.js"
34
40
  },
35
41
  "./types": {
42
+ "types": "./dist/types/index.d.ts",
36
43
  "default": "./dist/types/index.js"
37
44
  }
38
45
  },
@@ -50,31 +57,30 @@
50
57
  }
51
58
  },
52
59
  "dependencies": {
53
- "@modern-js/node-bundle-require": "2.8.0",
54
- "@modern-js/plugin": "2.8.0",
55
- "@modern-js/utils": "2.8.0"
60
+ "@modern-js/node-bundle-require": "2.10.0",
61
+ "@modern-js/plugin": "2.10.0",
62
+ "@modern-js/utils": "2.10.0"
56
63
  },
57
64
  "devDependencies": {
58
- "@jest/types": "^27.0.6",
59
65
  "@types/babel__code-frame": "^7.0.3",
60
66
  "@types/babel__core": "^7.1.16",
61
- "@types/jest": "^27",
67
+ "@types/jest": "^29",
62
68
  "@types/less": "^3.0.3",
63
69
  "@types/node": "^14",
64
70
  "autoprefixer": "10.4.13",
65
71
  "btsm": "2.2.2",
66
72
  "html-webpack-plugin": "5.5.0",
67
- "jest": "^27",
73
+ "jest": "^29",
68
74
  "postcss": "8.4.21",
69
75
  "sass": "^1.45.0",
70
76
  "terser-webpack-plugin": "^5.1.4",
71
77
  "typescript": "^4",
72
- "webpack": "^5.75.0",
73
- "@modern-js/builder-shared": "2.8.0",
74
- "@modern-js/babel-preset-app": "2.8.0",
75
- "@modern-js/types": "2.8.0",
76
- "@scripts/jest-config": "2.8.0",
77
- "@scripts/build": "2.8.0"
78
+ "webpack": "^5.76.2",
79
+ "@modern-js/builder-shared": "2.10.0",
80
+ "@modern-js/babel-preset-app": "2.10.0",
81
+ "@modern-js/types": "2.10.0",
82
+ "@scripts/build": "2.10.0",
83
+ "@scripts/jest-config": "2.10.0"
78
84
  },
79
85
  "sideEffects": false,
80
86
  "publishConfig": {