@modern-js/core 1.11.1 → 1.12.1

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
+ ## 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
+
18
+ ## 1.12.0
19
+
20
+ ### Minor Changes
21
+
22
+ - 8e1cedd8a: feat(webpack): support addIncludes and addExcludes in tools.tsLoader
23
+
24
+ ### Patch Changes
25
+
26
+ - 9377d2d9d: feat: support addPlugins util in tools.postcss
27
+ - b7a1cea52: feat: support utils in tools.babel
28
+ - 3dfee700c: feat: support addExcludes in tools.less and tools.sass
29
+ - Updated dependencies [9377d2d9d]
30
+ - Updated dependencies [8c9ad1749]
31
+ - Updated dependencies [1ac68424f]
32
+ - @modern-js/utils@1.7.7
33
+ - @modern-js/plugin@1.3.7
34
+
35
+ ## 1.11.2
36
+
37
+ ### Patch Changes
38
+
39
+ - 8d508c6ed: feat(devServer): support disable hmr or live reload
40
+ - 0eff2473c: ignore devServer config fn merge
41
+ - f25d6a62e: fix: change bffConfig type define to interface
42
+ - a18926bbd: fix(app-tools): dev --config not working
43
+ - 8f7c0f898: feat(app-tools): support specify config file in build and deploy command
44
+ - Updated dependencies [a1198d509]
45
+ - Updated dependencies [a18926bbd]
46
+ - @modern-js/load-config@1.3.4
47
+ - @modern-js/plugin@1.3.6
48
+
3
49
  ## 1.11.1
4
50
 
5
51
  ### Patch Changes
package/dist/bin.js CHANGED
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ /* eslint-disable-next-line eslint-comments/disable-enable-pair */
4
+ /* eslint-disable import/first */
3
5
  Object.defineProperty(exports, "__esModule", { value: true });
4
6
  require('../compiled/v8-compile-cache');
5
- // eslint-disable-next-line import/first
7
+ const utils_1 = require("@modern-js/utils");
6
8
  const _1 = require(".");
9
+ const command = process.argv[2];
7
10
  if (!process.env.NODE_ENV) {
8
- const command = process.argv[2];
9
11
  if (['build', 'start', 'deploy'].includes(command)) {
10
12
  process.env.NODE_ENV = 'production';
11
13
  }
@@ -17,4 +19,11 @@ if (!process.env.NODE_ENV) {
17
19
  }
18
20
  }
19
21
  const { version } = require('../package.json');
20
- _1.cli.run(process.argv.slice(2), { version });
22
+ const cliParams = (0, utils_1.minimist)(process.argv.slice(2));
23
+ const runOptions = {
24
+ version,
25
+ };
26
+ if (['dev', 'build', 'deploy'].includes(command) && cliParams.config) {
27
+ runOptions.configFile = cliParams.config;
28
+ }
29
+ _1.cli.run(process.argv.slice(2), runOptions);
@@ -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
+ /**
12
+ * Assign the pkg config into the user config.
13
+ */
14
+ export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
11
15
  export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => 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>;
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.resolveConfig = exports.loadUserConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.mergeConfig = exports.defaultsConfig = void 0;
16
+ exports.resolveConfig = exports.loadUserConfig = exports.assignPkgConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.mergeConfig = exports.defaultsConfig = void 0;
17
17
  const load_config_1 = require("@modern-js/load-config");
18
18
  const utils_1 = require("@modern-js/utils");
19
19
  const lodash_1 = require("@modern-js/utils/lodash");
@@ -37,6 +37,19 @@ const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFil
37
37
  exports.addServerConfigToDeps = addServerConfigToDeps;
38
38
  const defineConfig = (config) => config;
39
39
  exports.defineConfig = defineConfig;
40
+ /**
41
+ * Assign the pkg config into the user config.
42
+ */
43
+ const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
44
+ // mergeWith can not merge object with symbol, but plugins object contains symbol,
45
+ // so we need to handle it manually.
46
+ if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
47
+ return { ...srcValue };
48
+ }
49
+ // return undefined to use the default behavior of mergeWith
50
+ return undefined;
51
+ });
52
+ exports.assignPkgConfig = assignPkgConfig;
40
53
  const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
41
54
  const loaded = await (0, load_config_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
42
55
  const config = !loaded
@@ -45,7 +58,7 @@ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
45
58
  ? loaded.config(0)
46
59
  : loaded.config);
47
60
  return {
48
- config: (0, lodash_1.mergeWith)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
61
+ config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
49
62
  jsConfig: config || {},
50
63
  pkgConfig: ((loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
51
64
  filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
@@ -11,7 +11,10 @@ const utils_1 = require("@modern-js/utils");
11
11
  */
12
12
  const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target, source, key) => {
13
13
  // Do not use the following merge logic for source.designSystem and tools.tailwind(css)
14
- if (key === 'designSystem' || key === 'tailwind' || key === 'tailwindcss') {
14
+ if (key === 'designSystem' ||
15
+ key === 'tailwind' ||
16
+ key === 'tailwindcss' ||
17
+ key === 'devServer') {
15
18
  return (0, lodash_1.mergeWith)({}, target !== null && target !== void 0 ? target : {}, source !== null && source !== void 0 ? source : {});
16
19
  }
17
20
  if (Array.isArray(target)) {
@@ -2,12 +2,13 @@
2
2
  import type { IncomingMessage, ServerResponse } from 'http';
3
3
  import type { NextFunction, BffProxyOptions } from '@modern-js/types';
4
4
  import type { MetaOptions, ChainIdentifier } from '@modern-js/utils';
5
- import type { TransformOptions } from '@babel/core';
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';
11
+ import type { AcceptedPlugin as PostCSSPlugin } from 'postcss';
11
12
  import type { PluginConfig } from '../../loadPlugins';
12
13
  import type { TestConfig, JestConfig } from './test';
13
14
  import type { SassConfig, SassLoaderOptions } from './sass';
@@ -16,8 +17,11 @@ import type { UnbundleConfig } from './unbundle';
16
17
  import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
17
18
  import type { ElectronConfig } from './electron';
18
19
  import type { PostCSSLoaderOptions } from './postcss';
20
+ import type { TsLoaderOptions } from './ts-loader';
19
21
  declare type AutoprefixerOptions = autoprefixer.Options;
20
- declare type TerserOptions = BasePluginOptions & RawTerserOptions;
22
+ declare type TerserOptions = BasePluginOptions & {
23
+ terserOptions?: Partial<RawTerserOptions>;
24
+ };
21
25
  export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions, };
22
26
  export interface SourceConfig {
23
27
  entries?: Record<string, string | {
@@ -142,33 +146,53 @@ export interface DeployConfig {
142
146
  declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>, utils?: any) => Record<string, unknown> | void);
143
147
  export declare type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
144
148
  export declare type DevServerConfig = {
149
+ hot?: boolean;
150
+ liveReload?: boolean;
145
151
  proxy?: BffProxyOptions;
146
152
  headers?: Record<string, string>;
147
153
  before?: RequestHandler[];
148
154
  after?: RequestHandler[];
149
155
  [propsName: string]: any;
150
156
  };
151
- export declare type PostCSSConfig = PostCSSLoaderOptions | ((options: PostCSSLoaderOptions) => PostCSSLoaderOptions | void);
152
- export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils: {
157
+ export declare type PostCSSConfigUtils = {
158
+ addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
159
+ };
160
+ export declare type PostCSSConfig = PostCSSLoaderOptions | ((options: PostCSSLoaderOptions, utils: PostCSSConfigUtils) => PostCSSLoaderOptions | void);
161
+ export declare type WebpackConfigUtils = {
153
162
  env: string;
154
163
  name: string;
155
164
  webpack: typeof webpack;
156
- addRules: (rules: RuleSetRule[]) => void;
157
- prependPlugins: (plugins: WebpackConfiguration['plugins']) => void;
158
- appendPlugins: (plugins: WebpackConfiguration['plugins']) => void;
165
+ addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
166
+ prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
167
+ appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
159
168
  removePlugin: (pluginName: string) => void;
160
169
  /**
161
170
  * @deprecated please use `tools.webpackChain` instead.
162
171
  */
163
172
  chain: WebpackChain;
164
- }) => WebpackConfiguration | void);
165
- export declare type WebpackChainConfig = (chain: WebpackChain, utils: {
173
+ };
174
+ export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils: WebpackConfigUtils) => WebpackConfiguration | void);
175
+ export declare type WebpackChainConfigUtils = {
166
176
  env: string;
167
177
  name: string;
168
178
  webpack: typeof webpack;
169
179
  CHAIN_ID: ChainIdentifier;
170
- }) => void;
171
- export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils?: any) => TransformOptions | void);
180
+ };
181
+ export declare type WebpackChainConfig = (chain: WebpackChain, utils: WebpackChainConfigUtils) => void;
182
+ export declare type TsLoaderConfigUtils = {
183
+ addIncludes: (includes: string | RegExp | (string | RegExp)[]) => void;
184
+ addExcludes: (excludes: string | RegExp | (string | RegExp)[]) => void;
185
+ };
186
+ export declare type TsLoaderConfig = TsLoaderOptions | ((config: TsLoaderOptions, utils: TsLoaderConfigUtils) => TsLoaderOptions | void);
187
+ export declare type BabelConfigUtils = {
188
+ addPlugins: (plugins: BabelPlugin[]) => void;
189
+ addPresets: (presets: BabelPlugin[]) => void;
190
+ addIncludes: (includes: string | RegExp | (string | RegExp)[]) => void;
191
+ addExcludes: (excludes: string | RegExp | (string | RegExp)[]) => void;
192
+ removePlugins: (plugins: string | string[]) => void;
193
+ removePresets: (presets: string | string[]) => void;
194
+ };
195
+ export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils: BabelConfigUtils) => TransformOptions | void);
172
196
  export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
173
197
  export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
174
198
  export interface ToolsConfig {
@@ -180,7 +204,7 @@ export interface ToolsConfig {
180
204
  styledComponents?: ConfigFunction;
181
205
  lodash?: ConfigFunction;
182
206
  devServer?: DevServerConfig;
183
- tsLoader?: ConfigFunction;
207
+ tsLoader?: TsLoaderConfig;
184
208
  terser?: TerserConfig;
185
209
  minifyCss?: ConfigFunction;
186
210
  esbuild?: Record<string, unknown>;
@@ -215,12 +239,12 @@ export interface RuntimeConfig {
215
239
  export interface RuntimeByEntriesConfig {
216
240
  [name: string]: RuntimeConfig;
217
241
  }
218
- export declare type BffConfig = Partial<{
219
- prefix: string;
220
- requestCreator: string;
221
- fetcher: string;
222
- proxy: Record<string, any>;
223
- }>;
242
+ export interface BffConfig {
243
+ prefix?: string;
244
+ requestCreator?: string;
245
+ fetcher?: string;
246
+ proxy?: Record<string, any>;
247
+ }
224
248
  export interface UserConfig {
225
249
  source?: SourceConfig;
226
250
  output?: OutputConfig;
@@ -7,4 +7,6 @@ export declare type LessLoaderOptions = {
7
7
  webpackImporter?: boolean;
8
8
  implementation?: boolean;
9
9
  };
10
- export declare type LessConfig = LessLoaderOptions | ((options: LessLoaderOptions, utils?: any) => LessLoaderOptions | void);
10
+ export declare type LessConfig = LessLoaderOptions | ((options: LessLoaderOptions, utils: {
11
+ addExcludes: (excludes: RegExp | RegExp[]) => void;
12
+ }) => LessLoaderOptions | void);
@@ -5,4 +5,6 @@ export interface SassLoaderOptions {
5
5
  implementation?: string;
6
6
  additionalData?: string | ((content: string, filename: string) => string);
7
7
  }
8
- export declare type SassConfig = SassLoaderOptions | ((options: SassLoaderOptions, utils?: any) => SassLoaderOptions | void);
8
+ export declare type SassConfig = SassLoaderOptions | ((options: SassLoaderOptions, utils: {
9
+ addExcludes: (excludes: RegExp | RegExp[]) => void;
10
+ }) => SassLoaderOptions | void);
@@ -0,0 +1,23 @@
1
+ export declare type TsLoaderOptions = {
2
+ colors?: boolean;
3
+ silent?: boolean;
4
+ context?: string;
5
+ instance?: string;
6
+ logLevel?: string;
7
+ compiler?: string;
8
+ configFile?: string;
9
+ reportFiles?: string[];
10
+ transpileOnly?: boolean;
11
+ happyPackMode?: boolean;
12
+ errorFormatter?: (message: Record<string, unknown>, colors: boolean) => string;
13
+ logInfoToStdOut?: boolean;
14
+ compilerOptions?: Record<string, unknown>;
15
+ appendTsSuffixTo?: (RegExp | string)[];
16
+ appendTsxSuffixTo?: (RegExp | string)[];
17
+ projectReferences?: boolean;
18
+ ignoreDiagnostics?: number[];
19
+ allowTsInNodeModules?: boolean;
20
+ experimentalFileCaching?: boolean;
21
+ onlyCompileBundledFiles?: boolean;
22
+ useCaseSensitiveFileNames?: boolean;
23
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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.11.1",
14
+ "version": "1.12.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -39,9 +39,9 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@modern-js/load-config": "^1.3.3",
43
- "@modern-js/plugin": "^1.3.5",
44
- "@modern-js/utils": "^1.7.6"
42
+ "@modern-js/load-config": "^1.3.4",
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",
@@ -58,7 +58,7 @@
58
58
  "autoprefixer": "^10.3.1",
59
59
  "btsm": "2.2.2",
60
60
  "jest": "^27",
61
- "postcss": "^8",
61
+ "postcss": "^8.4.14",
62
62
  "sass": "^1.45.0",
63
63
  "electron-builder": "22.7.0",
64
64
  "terser-webpack-plugin": "^5.1.4",