@modern-js/core 1.12.0 → 1.12.2-beta.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,20 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b255072f2: fix(core): failed to load user plugins in modern.config.js
8
+ - 7975bfa68: fix(core): incorrect type of tools.terser
9
+ - b7302f781: Export some required types
10
+ - Updated dependencies [63c354ad5]
11
+ - Updated dependencies [073e9ad78]
12
+ - Updated dependencies [b7302f781]
13
+ - Updated dependencies [f4a7d49e1]
14
+ - Updated dependencies [e0e708f83]
15
+ - @modern-js/utils@1.7.8
16
+ - @modern-js/plugin@1.3.8
17
+
3
18
  ## 1.12.0
4
19
 
5
20
  ### Minor Changes
@@ -8,5 +8,9 @@ export { mergeConfig };
8
8
  export * from './types';
9
9
  export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
10
10
  export declare const defineConfig: (config: ConfigParam) => ConfigParam;
11
- export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
11
+ /**
12
+ * Assign the pkg config into the user config.
13
+ */
14
+ export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
15
+ export declare const loadUserConfig: (appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<LoadedConfig>;
12
16
  export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -13,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
18
  };
15
19
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.resolveConfig = exports.loadUserConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.mergeConfig = exports.defaultsConfig = void 0;
20
+ exports.resolveConfig = exports.loadUserConfig = exports.assignPkgConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.mergeConfig = exports.defaultsConfig = void 0;
17
21
  const load_config_1 = require("@modern-js/load-config");
18
22
  const utils_1 = require("@modern-js/utils");
19
23
  const lodash_1 = require("@modern-js/utils/lodash");
@@ -37,6 +41,19 @@ const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFil
37
41
  exports.addServerConfigToDeps = addServerConfigToDeps;
38
42
  const defineConfig = (config) => config;
39
43
  exports.defineConfig = defineConfig;
44
+ /**
45
+ * Assign the pkg config into the user config.
46
+ */
47
+ const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
48
+ // mergeWith can not merge object with symbol, but plugins object contains symbol,
49
+ // so we need to handle it manually.
50
+ if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
51
+ return { ...srcValue };
52
+ }
53
+ // return undefined to use the default behavior of mergeWith
54
+ return undefined;
55
+ });
56
+ exports.assignPkgConfig = assignPkgConfig;
40
57
  const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
41
58
  const loaded = await (0, load_config_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
42
59
  const config = !loaded
@@ -45,7 +62,7 @@ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
45
62
  ? loaded.config(0)
46
63
  : loaded.config);
47
64
  return {
48
- config: (0, lodash_1.mergeWith)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
65
+ config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
49
66
  jsConfig: config || {},
50
67
  pkgConfig: ((loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
51
68
  filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
@@ -391,6 +391,9 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
391
391
  enableMicroFrontendDebug: {
392
392
  type: string;
393
393
  };
394
+ watchOptions: {
395
+ type: string;
396
+ };
394
397
  };
395
398
  };
396
399
  deploy: {
@@ -178,5 +178,8 @@ export declare const server: {
178
178
  enableMicroFrontendDebug: {
179
179
  type: string;
180
180
  };
181
+ watchOptions: {
182
+ type: string;
183
+ };
181
184
  };
182
185
  };
@@ -103,5 +103,6 @@ exports.server = {
103
103
  metrics: { type: ['object', 'boolean'] },
104
104
  proxy: { type: 'object' },
105
105
  enableMicroFrontendDebug: { type: 'boolean' },
106
+ watchOptions: { type: 'object' },
106
107
  },
107
108
  };
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import type { IncomingMessage, ServerResponse } from 'http';
3
3
  import type { NextFunction, BffProxyOptions } from '@modern-js/types';
4
- import type { MetaOptions, ChainIdentifier } from '@modern-js/utils';
4
+ import type { MetaOptions, ChainIdentifier, WatchOptions } from '@modern-js/utils';
5
5
  import type { TransformOptions, PluginItem as BabelPlugin } from '@babel/core';
6
6
  import type webpack from 'webpack';
7
- import type { RuleSetRule, Configuration as WebpackConfiguration } from 'webpack';
7
+ import type { RuleSetRule, Configuration as WebpackConfiguration, WebpackPluginInstance } from 'webpack';
8
8
  import type WebpackChain from '@modern-js/utils/webpack-chain';
9
9
  import type autoprefixer from 'autoprefixer';
10
10
  import type { BasePluginOptions, TerserOptions as RawTerserOptions } from 'terser-webpack-plugin';
@@ -19,7 +19,9 @@ import type { ElectronConfig } from './electron';
19
19
  import type { PostCSSLoaderOptions } from './postcss';
20
20
  import type { TsLoaderOptions } from './ts-loader';
21
21
  declare type AutoprefixerOptions = autoprefixer.Options;
22
- declare type TerserOptions = BasePluginOptions & RawTerserOptions;
22
+ declare type TerserOptions = BasePluginOptions & {
23
+ terserOptions?: Partial<RawTerserOptions>;
24
+ };
23
25
  export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions, };
24
26
  export interface SourceConfig {
25
27
  entries?: Record<string, string | {
@@ -113,6 +115,7 @@ export interface ServerConfig {
113
115
  logger?: boolean | Record<string, any>;
114
116
  metrics?: boolean | Record<string, any>;
115
117
  enableMicroFrontendDebug?: boolean;
118
+ watchOptions?: WatchOptions;
116
119
  }
117
120
  export declare type DevProxyOptions = string | Record<string, string>;
118
121
  export interface DevConfig {
@@ -160,9 +163,9 @@ export declare type WebpackConfigUtils = {
160
163
  env: string;
161
164
  name: string;
162
165
  webpack: typeof webpack;
163
- addRules: (rules: RuleSetRule[]) => void;
164
- prependPlugins: (plugins: WebpackConfiguration['plugins']) => void;
165
- appendPlugins: (plugins: WebpackConfiguration['plugins']) => void;
166
+ addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
167
+ prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
168
+ appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
166
169
  removePlugin: (pluginName: string) => void;
167
170
  /**
168
171
  * @deprecated please use `tools.webpackChain` instead.
package/dist/index.d.ts CHANGED
@@ -7,13 +7,12 @@ import type { NormalizedConfig } from './config/mergeConfig';
7
7
  export type { Hooks };
8
8
  export * from './config';
9
9
  export * from '@modern-js/plugin';
10
- export * from '@modern-js/plugin/node';
11
10
  export { manager, mountHook, usePlugins, createPlugin, registerHook, } from './manager';
12
11
  export type { CliHooks, CliPlugin, CliHookCallbacks } from './manager';
13
12
  export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './pluginAPI';
14
13
  export type { PluginAPI } from './pluginAPI';
15
14
  export type { NormalizedConfig, IAppContext };
16
- declare const initAppDir: (cwd?: string | undefined) => Promise<string>;
15
+ declare const initAppDir: (cwd?: string) => Promise<string>;
17
16
  export interface CoreOptions {
18
17
  version?: string;
19
18
  configFile?: string;
@@ -29,7 +28,7 @@ export interface CoreOptions {
29
28
  sharedDir?: string;
30
29
  };
31
30
  }
32
- export declare const mergeOptions: (options?: CoreOptions | undefined) => {
31
+ export declare const mergeOptions: (options?: CoreOptions) => {
33
32
  version?: string | undefined;
34
33
  configFile?: string | undefined;
35
34
  serverConfigFile: string;
@@ -50,12 +49,12 @@ export declare const mergeOptions: (options?: CoreOptions | undefined) => {
50
49
  } | undefined;
51
50
  };
52
51
  export declare const cli: {
53
- init: (argv?: string[], options?: CoreOptions | undefined) => Promise<{
52
+ init: (argv?: string[], options?: CoreOptions) => Promise<{
54
53
  loadedConfig: import("./config").LoadedConfig;
55
54
  appContext: IAppContext;
56
55
  resolved: NormalizedConfig;
57
56
  }>;
58
- run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
57
+ run: (argv: string[], options?: CoreOptions) => Promise<void>;
59
58
  restart: () => Promise<void>;
60
59
  };
61
60
  export { initAppDir, initAppContext };
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -16,7 +20,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
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.usePlugins = exports.mountHook = exports.manager = void 0;
17
21
  const path_1 = __importDefault(require("path"));
18
22
  const utils_1 = require("@modern-js/utils");
19
- const node_1 = require("@modern-js/plugin/node");
20
23
  const commander_1 = require("./utils/commander");
21
24
  const config_1 = require("./config");
22
25
  const loadPlugins_1 = require("./loadPlugins");
@@ -27,7 +30,6 @@ const loadEnv_1 = require("./loadEnv");
27
30
  const manager_1 = require("./manager");
28
31
  __exportStar(require("./config"), exports);
29
32
  __exportStar(require("@modern-js/plugin"), exports);
30
- __exportStar(require("@modern-js/plugin/node"), exports);
31
33
  // TODO: remove export after refactor all plugins
32
34
  var manager_2 = require("./manager");
33
35
  Object.defineProperty(exports, "manager", { enumerable: true, get: function () { return manager_2.manager; } });
@@ -75,7 +77,6 @@ const createCli = () => {
75
77
  let restartOptions;
76
78
  const init = async (argv = [], options) => {
77
79
  var _a, _b;
78
- (0, node_1.enable)();
79
80
  manager_1.manager.clear();
80
81
  const mergedOptions = (0, exports.mergeOptions)(options);
81
82
  restartOptions = mergedOptions;
@@ -99,10 +100,8 @@ const createCli = () => {
99
100
  });
100
101
  // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
101
102
  (0, config_1.addServerConfigToDeps)(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
102
- manager_1.manager.run(() => {
103
- context_1.ConfigContext.set(loaded.config);
104
- context_1.AppContext.set(appContext);
105
- });
103
+ context_1.ConfigContext.set(loaded.config);
104
+ context_1.AppContext.set(appContext);
106
105
  hooksRunner = await manager_1.manager.init();
107
106
  ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
108
107
  process.on(event, async (err) => {
@@ -123,14 +122,12 @@ const createCli = () => {
123
122
  resolved: config,
124
123
  });
125
124
  // update context value
126
- manager_1.manager.run(() => {
127
- context_1.ConfigContext.set(loaded.config);
128
- context_1.ResolvedConfigContext.set(resolved);
129
- context_1.AppContext.set({
130
- ...appContext,
131
- port: resolved.server.port,
132
- distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path),
133
- });
125
+ context_1.ConfigContext.set(loaded.config);
126
+ 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),
134
131
  });
135
132
  await hooksRunner.prepare();
136
133
  return {
@@ -144,7 +141,7 @@ const createCli = () => {
144
141
  const { loadedConfig, appContext, resolved } = await init(argv, options);
145
142
  await hooksRunner.commands({ program: utils_1.program });
146
143
  (0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
147
- manager_1.manager.run(() => utils_1.program.parse(process.argv));
144
+ utils_1.program.parse(process.argv);
148
145
  }
149
146
  async function restart() {
150
147
  var _a, _b;
@@ -163,7 +160,7 @@ const createCli = () => {
163
160
  }
164
161
  finally {
165
162
  if (!hasGetError) {
166
- manager_1.manager.run(() => utils_1.program.parse(process.argv));
163
+ utils_1.program.parse(process.argv);
167
164
  }
168
165
  }
169
166
  }
@@ -4,26 +4,6 @@ exports.loadPlugins = exports.getAppPlugins = 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
- /**
8
- * Try to resolve plugin entry file path.
9
- * @param name - Plugin name.
10
- * @param appDirectory - Application root directory.
11
- * @returns Resolved file path.
12
- */
13
- const tryResolve = (name, appDirectory) => {
14
- let filePath = '';
15
- try {
16
- filePath = require.resolve(name, { paths: [appDirectory] });
17
- delete require.cache[filePath];
18
- }
19
- catch (err) {
20
- if (err.code === 'MODULE_NOT_FOUND') {
21
- throw new Error(`Can not find plugin ${name}.`);
22
- }
23
- throw err;
24
- }
25
- return filePath;
26
- };
27
7
  function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
28
8
  const allPlugins = internalPlugins || utils_1.INTERNAL_PLUGINS;
29
9
  const appPlugins = [
@@ -44,7 +24,7 @@ exports.getAppPlugins = getAppPlugins;
44
24
  const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
45
25
  const pkg = typeof p === 'string' ? p : p[0];
46
26
  const pluginOptions = typeof p === 'string' ? undefined : p[1];
47
- const path = tryResolve(pkg, appDirectory);
27
+ const path = (0, utils_1.tryResolve)(pkg, appDirectory);
48
28
  let module = (0, utils_1.compatRequire)(path);
49
29
  if (transformPlugin) {
50
30
  module = transformPlugin(module, userConfig, pluginOptions);
@@ -2,11 +2,12 @@ import type { CommonAPI } from '@modern-js/plugin';
2
2
  import type { CliHooks } from './manager';
3
3
  import { AppContext, ConfigContext, useAppContext, useConfigContext, ResolvedConfigContext, useResolvedConfigContext } from './context';
4
4
  export declare const pluginAPI: {
5
- setAppContext: (value: import("@modern-js/types/cli").IAppContext) => void;
6
- useAppContext: () => import("@modern-js/types/cli").IAppContext;
5
+ setAppContext: (value: import("@modern-js/types").IAppContext) => void;
6
+ useAppContext: () => import("@modern-js/types").IAppContext;
7
7
  useConfigContext: () => import("./config").UserConfig;
8
8
  useResolvedConfigContext: () => import(".").NormalizedConfig;
9
9
  };
10
+ export type { IAppContext } from '@modern-js/types';
10
11
  /** all apis for cli plugin */
11
12
  export declare type PluginAPI = typeof pluginAPI & CommonAPI<CliHooks>;
12
13
  export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.12.0",
14
+ "version": "1.12.2-beta.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@modern-js/load-config": "^1.3.4",
43
- "@modern-js/plugin": "^1.3.7",
44
- "@modern-js/utils": "^1.7.7"
43
+ "@modern-js/plugin": "^1.3.8",
44
+ "@modern-js/utils": "^1.7.8"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@jest/types": "^27.0.6",
@@ -68,7 +68,8 @@
68
68
  "sideEffects": false,
69
69
  "publishConfig": {
70
70
  "registry": "https://registry.npmjs.org/",
71
- "access": "public"
71
+ "access": "public",
72
+ "types": "./dist/index.d.ts"
72
73
  },
73
74
  "wireit": {
74
75
  "build": {