@modern-js/core 1.11.0 → 1.12.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,50 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8e1cedd8a: feat(webpack): support addIncludes and addExcludes in tools.tsLoader
8
+
9
+ ### Patch Changes
10
+
11
+ - 9377d2d9d: feat: support addPlugins util in tools.postcss
12
+ - b7a1cea52: feat: support utils in tools.babel
13
+ - 3dfee700c: feat: support addExcludes in tools.less and tools.sass
14
+ - Updated dependencies [9377d2d9d]
15
+ - Updated dependencies [8c9ad1749]
16
+ - Updated dependencies [1ac68424f]
17
+ - @modern-js/utils@1.7.7
18
+ - @modern-js/plugin@1.3.7
19
+
20
+ ## 1.11.2
21
+
22
+ ### Patch Changes
23
+
24
+ - 8d508c6ed: feat(devServer): support disable hmr or live reload
25
+ - 0eff2473c: ignore devServer config fn merge
26
+ - f25d6a62e: fix: change bffConfig type define to interface
27
+ - a18926bbd: fix(app-tools): dev --config not working
28
+ - 8f7c0f898: feat(app-tools): support specify config file in build and deploy command
29
+ - Updated dependencies [a1198d509]
30
+ - Updated dependencies [a18926bbd]
31
+ - @modern-js/load-config@1.3.4
32
+ - @modern-js/plugin@1.3.6
33
+
34
+ ## 1.11.1
35
+
36
+ ### Patch Changes
37
+
38
+ - f730081c: feat: modify `RuntimeConfig` type to make it extensible
39
+ - d1ab1f05: fix(core): should not register the `core` command
40
+ - 2ec8181a: fix(core): modern --version get incorrect value
41
+ - 6451a098: fix: cyclic dependencies of @modern-js/core and @moden-js/webpack
42
+ - 7fcfd6cc: fix(core): fix tools.postcss typing
43
+ - Updated dependencies [6451a098]
44
+ - Updated dependencies [d5a2cfd8]
45
+ - Updated dependencies [437367c6]
46
+ - @modern-js/utils@1.7.6
47
+
3
48
  ## 1.11.0
4
49
 
5
50
  ### Minor Changes
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /* eslint-disable-next-line eslint-comments/disable-enable-pair */
4
+ /* eslint-disable import/first */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ require('../compiled/v8-compile-cache');
7
+ const utils_1 = require("@modern-js/utils");
8
+ const _1 = require(".");
9
+ const command = process.argv[2];
10
+ if (!process.env.NODE_ENV) {
11
+ if (['build', 'start', 'deploy'].includes(command)) {
12
+ process.env.NODE_ENV = 'production';
13
+ }
14
+ else if (command === 'test') {
15
+ process.env.NODE_ENV = 'test';
16
+ }
17
+ else {
18
+ process.env.NODE_ENV = 'development';
19
+ }
20
+ }
21
+ const { version } = require('../package.json');
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);
@@ -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)) {
@@ -1,20 +1,23 @@
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 } from '@modern-js/utils';
5
- import type { TransformOptions } from '@babel/core';
4
+ import type { MetaOptions, ChainIdentifier } from '@modern-js/utils';
5
+ import type { TransformOptions, PluginItem as BabelPlugin } from '@babel/core';
6
6
  import type webpack from 'webpack';
7
- import type { Configuration as WebpackConfiguration } from 'webpack';
8
- import type { ChainIdentifier, WebpackChain } from '@modern-js/webpack';
7
+ import type { RuleSetRule, Configuration as WebpackConfiguration } from 'webpack';
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';
14
15
  import type { LessConfig, LessLoaderOptions } from './less';
15
16
  import type { UnbundleConfig } from './unbundle';
16
17
  import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
17
- import { ElectronConfig } from './electron';
18
+ import type { ElectronConfig } from './electron';
19
+ import type { PostCSSLoaderOptions } from './postcss';
20
+ import type { TsLoaderOptions } from './ts-loader';
18
21
  declare type AutoprefixerOptions = autoprefixer.Options;
19
22
  declare type TerserOptions = BasePluginOptions & RawTerserOptions;
20
23
  export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions, };
@@ -141,29 +144,53 @@ export interface DeployConfig {
141
144
  declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>, utils?: any) => Record<string, unknown> | void);
142
145
  export declare type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
143
146
  export declare type DevServerConfig = {
147
+ hot?: boolean;
148
+ liveReload?: boolean;
144
149
  proxy?: BffProxyOptions;
145
150
  headers?: Record<string, string>;
146
151
  before?: RequestHandler[];
147
152
  after?: RequestHandler[];
148
153
  [propsName: string]: any;
149
154
  };
150
- export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils: {
155
+ export declare type PostCSSConfigUtils = {
156
+ addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
157
+ };
158
+ export declare type PostCSSConfig = PostCSSLoaderOptions | ((options: PostCSSLoaderOptions, utils: PostCSSConfigUtils) => PostCSSLoaderOptions | void);
159
+ export declare type WebpackConfigUtils = {
151
160
  env: string;
152
161
  name: string;
153
162
  webpack: typeof webpack;
163
+ addRules: (rules: RuleSetRule[]) => void;
164
+ prependPlugins: (plugins: WebpackConfiguration['plugins']) => void;
165
+ appendPlugins: (plugins: WebpackConfiguration['plugins']) => void;
166
+ removePlugin: (pluginName: string) => void;
154
167
  /**
155
168
  * @deprecated please use `tools.webpackChain` instead.
156
169
  */
157
170
  chain: WebpackChain;
158
- [key: string]: any;
159
- }) => WebpackConfiguration | void);
160
- export declare type WebpackChainConfig = (chain: WebpackChain, utils: {
171
+ };
172
+ export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils: WebpackConfigUtils) => WebpackConfiguration | void);
173
+ export declare type WebpackChainConfigUtils = {
161
174
  env: string;
162
175
  name: string;
163
176
  webpack: typeof webpack;
164
177
  CHAIN_ID: ChainIdentifier;
165
- }) => void;
166
- export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils?: any) => TransformOptions | void);
178
+ };
179
+ export declare type WebpackChainConfig = (chain: WebpackChain, utils: WebpackChainConfigUtils) => void;
180
+ export declare type TsLoaderConfigUtils = {
181
+ addIncludes: (includes: string | RegExp | (string | RegExp)[]) => void;
182
+ addExcludes: (excludes: string | RegExp | (string | RegExp)[]) => void;
183
+ };
184
+ export declare type TsLoaderConfig = TsLoaderOptions | ((config: TsLoaderOptions, utils: TsLoaderConfigUtils) => TsLoaderOptions | void);
185
+ export declare type BabelConfigUtils = {
186
+ addPlugins: (plugins: BabelPlugin[]) => void;
187
+ addPresets: (presets: BabelPlugin[]) => void;
188
+ addIncludes: (includes: string | RegExp | (string | RegExp)[]) => void;
189
+ addExcludes: (excludes: string | RegExp | (string | RegExp)[]) => void;
190
+ removePlugins: (plugins: string | string[]) => void;
191
+ removePresets: (presets: string | string[]) => void;
192
+ };
193
+ export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils: BabelConfigUtils) => TransformOptions | void);
167
194
  export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
168
195
  export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
169
196
  export interface ToolsConfig {
@@ -171,11 +198,11 @@ export interface ToolsConfig {
171
198
  webpackChain?: WebpackChainConfig;
172
199
  babel?: BabelConfig;
173
200
  autoprefixer?: AutoprefixerConfig;
174
- postcss?: ConfigFunction;
201
+ postcss?: PostCSSConfig;
175
202
  styledComponents?: ConfigFunction;
176
203
  lodash?: ConfigFunction;
177
204
  devServer?: DevServerConfig;
178
- tsLoader?: ConfigFunction;
205
+ tsLoader?: TsLoaderConfig;
179
206
  terser?: TerserConfig;
180
207
  minifyCss?: ConfigFunction;
181
208
  esbuild?: Record<string, unknown>;
@@ -204,16 +231,18 @@ export interface ToolsConfig {
204
231
  */
205
232
  less?: LessConfig;
206
233
  }
207
- export declare type RuntimeConfig = Record<string, any>;
234
+ export interface RuntimeConfig {
235
+ [name: string]: any;
236
+ }
208
237
  export interface RuntimeByEntriesConfig {
209
238
  [name: string]: RuntimeConfig;
210
239
  }
211
- export declare type BffConfig = Partial<{
212
- prefix: string;
213
- requestCreator: string;
214
- fetcher: string;
215
- proxy: Record<string, any>;
216
- }>;
240
+ export interface BffConfig {
241
+ prefix?: string;
242
+ requestCreator?: string;
243
+ fetcher?: string;
244
+ proxy?: Record<string, any>;
245
+ }
217
246
  export interface UserConfig {
218
247
  source?: SourceConfig;
219
248
  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);
@@ -0,0 +1,28 @@
1
+ import type { Syntax, Parser, Stringifier, AcceptedPlugin, SourceMapOptions } from 'postcss';
2
+ export declare type PostCSSOptions = {
3
+ to?: string;
4
+ from?: string;
5
+ map?: boolean | SourceMapOptions;
6
+ syntax?: Syntax;
7
+ parser?: string | object | (() => Parser);
8
+ plugins?: AcceptedPlugin[];
9
+ stringifier?: Stringifier | Syntax;
10
+ };
11
+ export declare type PostCSSLoaderOptions = {
12
+ /**
13
+ * Enable PostCSS Parser support in CSS-in-JS. If you use JS styles the postcss-js parser, add the execute option.
14
+ */
15
+ execute?: boolean;
16
+ /**
17
+ * By default generation of source maps depends on the devtool option. All values enable source map generation except eval and false value.
18
+ */
19
+ sourceMap?: boolean;
20
+ /**
21
+ * The special implementation option determines which implementation of PostCSS to use.
22
+ */
23
+ implementation?: unknown;
24
+ /**
25
+ * Allows to set PostCSS options and plugins.
26
+ */
27
+ postcssOptions?: PostCSSOptions;
28
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 });
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export type { PluginAPI } from './pluginAPI';
15
15
  export type { NormalizedConfig, IAppContext };
16
16
  declare const initAppDir: (cwd?: string | undefined) => Promise<string>;
17
17
  export interface CoreOptions {
18
+ version?: string;
18
19
  configFile?: string;
19
20
  serverConfigFile?: string;
20
21
  packageJsonConfig?: string;
@@ -29,6 +30,7 @@ export interface CoreOptions {
29
30
  };
30
31
  }
31
32
  export declare const mergeOptions: (options?: CoreOptions | undefined) => {
33
+ version?: string | undefined;
32
34
  configFile?: string | undefined;
33
35
  serverConfigFile: string;
34
36
  packageJsonConfig?: string | undefined;
package/dist/index.js CHANGED
@@ -43,10 +43,6 @@ Object.defineProperty(exports, "ResolvedConfigContext", { enumerable: true, get:
43
43
  Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return pluginAPI_1.useAppContext; } });
44
44
  Object.defineProperty(exports, "useConfigContext", { enumerable: true, get: function () { return pluginAPI_1.useConfigContext; } });
45
45
  Object.defineProperty(exports, "useResolvedConfigContext", { enumerable: true, get: function () { return pluginAPI_1.useResolvedConfigContext; } });
46
- utils_1.program
47
- .name('modern')
48
- .usage('<command> [options]')
49
- .version(process.env.MODERN_JS_VERSION || '0.1.0');
50
46
  const initAppDir = async (cwd) => {
51
47
  if (!cwd) {
52
48
  // eslint-disable-next-line no-param-reassign
@@ -69,6 +65,9 @@ const mergeOptions = (options) => {
69
65
  };
70
66
  };
71
67
  exports.mergeOptions = mergeOptions;
68
+ const setProgramVersion = (version = 'unknown') => {
69
+ utils_1.program.name('modern').usage('<command> [options]').version(version);
70
+ };
72
71
  const createCli = () => {
73
72
  let hooksRunner;
74
73
  let isRestart = false;
@@ -82,6 +81,7 @@ const createCli = () => {
82
81
  restartOptions = mergedOptions;
83
82
  const appDirectory = await initAppDir();
84
83
  (0, commander_1.initCommandsMap)();
84
+ setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
85
85
  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
86
  (0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
87
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);
@@ -31,7 +31,6 @@ function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
31
31
  .filter(name => {
32
32
  const config = allPlugins[name];
33
33
  if (config.forced === true) {
34
- // 参考 packages/cli/core/src/cli.ts 文件
35
34
  return true;
36
35
  }
37
36
  return (0, utils_1.isDepExists)(appDirectory, name);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.11.0",
14
+ "version": "1.12.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -27,8 +27,8 @@
27
27
  "default": "./dist/index.js"
28
28
  },
29
29
  "./bin": {
30
- "jsnext:source": "./src/cli.ts",
31
- "default": "./bin/modern-js.js"
30
+ "jsnext:source": "./src/bin.ts",
31
+ "default": "./dist/bin.js"
32
32
  }
33
33
  },
34
34
  "typesVersions": {
@@ -38,16 +38,14 @@
38
38
  ]
39
39
  }
40
40
  },
41
- "bin": "./bin/modern-js.js",
42
41
  "dependencies": {
43
- "@modern-js/load-config": "^1.3.3",
44
- "@modern-js/plugin": "^1.3.5",
45
- "@modern-js/utils": "^1.7.5"
42
+ "@modern-js/load-config": "^1.3.4",
43
+ "@modern-js/plugin": "^1.3.7",
44
+ "@modern-js/utils": "^1.7.7"
46
45
  },
47
46
  "devDependencies": {
48
47
  "@jest/types": "^27.0.6",
49
- "@modern-js/types": "1.5.3",
50
- "@modern-js/webpack": "1.8.0",
48
+ "@modern-js/types": "1.5.4",
51
49
  "@scripts/build": "0.0.0",
52
50
  "@scripts/jest-config": "0.0.0",
53
51
  "@types/babel__code-frame": "^7.0.3",
@@ -60,6 +58,7 @@
60
58
  "autoprefixer": "^10.3.1",
61
59
  "btsm": "2.2.2",
62
60
  "jest": "^27",
61
+ "postcss": "^8.4.14",
63
62
  "sass": "^1.45.0",
64
63
  "electron-builder": "22.7.0",
65
64
  "terser-webpack-plugin": "^5.1.4",
package/bin/modern-js.js DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('../compiled/v8-compile-cache');
4
- const { cli } = require('../');
5
- const { version } = require('../package.json');
6
-
7
- process.env.MODERN_JS_VERSION = version;
8
- if (!process.env.NODE_ENV) {
9
- process.env.NODE_ENV =
10
- // eslint-disable-next-line no-nested-ternary
11
- ['build', 'start', 'deploy'].indexOf(process.argv[2]) !== -1
12
- ? 'production'
13
- : process.argv[2] === 'test'
14
- ? 'test'
15
- : 'development';
16
- }
17
-
18
- cli.run(process.argv.slice(2));
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/cli.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- // 这个文件跟 bin/modern-js.js 基本一样
3
- // 在开发阶段,因为 package.json 的 exports['./bin']['jsnext:source'] 配置
4
- // 了这个文件,所以需要保留, 后续如果找到更好的方式之后会移除这个文件
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const path_1 = __importDefault(require("path"));
10
- const _1 = require(".");
11
- const { version } = require('../package.json');
12
- // XXX: 通过这个方式去掉了 package.json 里面对于 @modern-js/module-tools 的 devDependencies 依赖
13
- // 然后可以正常的执行 modern build
14
- const kModuleToolsCliPath = path_1.default.resolve(__dirname, '../../../solutions/module-tools/src/index.ts');
15
- process.env.MODERN_JS_VERSION = version;
16
- if (!process.env.NODE_ENV) {
17
- process.env.NODE_ENV =
18
- // eslint-disable-next-line no-nested-ternary
19
- ['build', 'start', 'deploy'].includes(process.argv[2])
20
- ? 'production'
21
- : process.argv[2] === 'test'
22
- ? 'test'
23
- : 'development';
24
- }
25
- _1.cli.run(process.argv.slice(2), {
26
- plugins: {
27
- '@modern-js/module-tools': {
28
- cli: kModuleToolsCliPath,
29
- // 是否需要强制加载这个组件,跳过 loadPlugins 里面 filter 的检测逻辑
30
- forced: true,
31
- },
32
- },
33
- });