@modern-js/core 1.11.2 → 1.12.2-alpha.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,52 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.12.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 9cd364e06: The buildPreset will be split out of a buildConfig, preset only supports built-in strings, config this piece to remove speedyOptions, watch, add platform, splitting, minify, external, and add tools.speedy
8
+ - f29e9bacf: feat: simplify context usage, no longer depend on containers
9
+ - a90bc96bd: perf(babel): skip babel-plugin-import if package not installed
10
+ - Updated dependencies [9cd364e06]
11
+ - Updated dependencies [3050accbe]
12
+ - Updated dependencies [f29e9bacf]
13
+ - Updated dependencies [a90bc96bd]
14
+ - @modern-js/utils@1.7.9-alpha.0
15
+ - @modern-js/load-config@1.3.6-alpha.0
16
+ - @modern-js/plugin@1.4.0-alpha.0
17
+
18
+ ## 1.12.1
19
+
20
+ ### Patch Changes
21
+
22
+ - b255072f2: fix(core): failed to load user plugins in modern.config.js
23
+ - 7975bfa68: fix(core): incorrect type of tools.terser
24
+ - b7302f781: Export some required types
25
+ - Updated dependencies [63c354ad5]
26
+ - Updated dependencies [073e9ad78]
27
+ - Updated dependencies [b7302f781]
28
+ - Updated dependencies [f4a7d49e1]
29
+ - Updated dependencies [e0e708f83]
30
+ - @modern-js/utils@1.7.8
31
+ - @modern-js/plugin@1.3.8
32
+
33
+ ## 1.12.0
34
+
35
+ ### Minor Changes
36
+
37
+ - 8e1cedd8a: feat(webpack): support addIncludes and addExcludes in tools.tsLoader
38
+
39
+ ### Patch Changes
40
+
41
+ - 9377d2d9d: feat: support addPlugins util in tools.postcss
42
+ - b7a1cea52: feat: support utils in tools.babel
43
+ - 3dfee700c: feat: support addExcludes in tools.less and tools.sass
44
+ - Updated dependencies [9377d2d9d]
45
+ - Updated dependencies [8c9ad1749]
46
+ - Updated dependencies [1ac68424f]
47
+ - @modern-js/utils@1.7.7
48
+ - @modern-js/plugin@1.3.7
49
+
3
50
  ## 1.11.2
4
51
 
5
52
  ### Patch Changes
@@ -1,12 +1,17 @@
1
1
  import { ErrorObject } from '../../compiled/ajv';
2
2
  import { defaults } from './defaults';
3
- import { mergeConfig, NormalizedConfig } from './mergeConfig';
3
+ import { NormalizedConfig } from './mergeConfig';
4
4
  import { PluginValidateSchema } from './schema';
5
5
  import type { UserConfig, ConfigParam, LoadedConfig } from './types';
6
6
  export { defaults as defaultsConfig };
7
- export { mergeConfig };
7
+ export * from './mergeConfig';
8
8
  export * from './types';
9
+ export * from './schema';
9
10
  export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
10
11
  export declare const defineConfig: (config: ConfigParam) => ConfigParam;
11
- export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
12
+ /**
13
+ * Assign the pkg config into the user config.
14
+ */
15
+ export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
16
+ export declare const loadUserConfig: (appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<LoadedConfig>;
12
17
  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.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");
@@ -24,10 +28,11 @@ const repeatKeyWarning_1 = require("../utils/repeatKeyWarning");
24
28
  const defaults_1 = require("./defaults");
25
29
  Object.defineProperty(exports, "defaultsConfig", { enumerable: true, get: function () { return defaults_1.defaults; } });
26
30
  const mergeConfig_1 = require("./mergeConfig");
27
- Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function () { return mergeConfig_1.mergeConfig; } });
28
31
  const schema_1 = require("./schema");
29
32
  const debug = (0, utils_1.createDebugger)('resolve-config');
33
+ __exportStar(require("./mergeConfig"), exports);
30
34
  __exportStar(require("./types"), exports);
35
+ __exportStar(require("./schema"), exports);
31
36
  const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
32
37
  const serverConfig = await (0, utils_1.getServerConfig)(appDirectory, serverConfigFile);
33
38
  if (serverConfig) {
@@ -37,6 +42,19 @@ const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFil
37
42
  exports.addServerConfigToDeps = addServerConfigToDeps;
38
43
  const defineConfig = (config) => config;
39
44
  exports.defineConfig = defineConfig;
45
+ /**
46
+ * Assign the pkg config into the user config.
47
+ */
48
+ const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
49
+ // mergeWith can not merge object with symbol, but plugins object contains symbol,
50
+ // so we need to handle it manually.
51
+ if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
52
+ return { ...srcValue };
53
+ }
54
+ // return undefined to use the default behavior of mergeWith
55
+ return undefined;
56
+ });
57
+ exports.assignPkgConfig = assignPkgConfig;
40
58
  const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
41
59
  const loaded = await (0, load_config_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
42
60
  const config = !loaded
@@ -45,7 +63,7 @@ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
45
63
  ? loaded.config(0)
46
64
  : loaded.config);
47
65
  return {
48
- config: (0, lodash_1.mergeWith)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
66
+ config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
49
67
  jsConfig: config || {},
50
68
  pkgConfig: ((loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
51
69
  filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
@@ -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 | {
@@ -150,27 +154,45 @@ export declare type DevServerConfig = {
150
154
  after?: RequestHandler[];
151
155
  [propsName: string]: any;
152
156
  };
153
- export declare type PostCSSConfig = PostCSSLoaderOptions | ((options: PostCSSLoaderOptions) => PostCSSLoaderOptions | void);
154
- 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 = {
155
162
  env: string;
156
163
  name: string;
157
164
  webpack: typeof webpack;
158
- addRules: (rules: RuleSetRule[]) => void;
159
- prependPlugins: (plugins: WebpackConfiguration['plugins']) => void;
160
- appendPlugins: (plugins: WebpackConfiguration['plugins']) => void;
165
+ addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
166
+ prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
167
+ appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
161
168
  removePlugin: (pluginName: string) => void;
162
169
  /**
163
170
  * @deprecated please use `tools.webpackChain` instead.
164
171
  */
165
172
  chain: WebpackChain;
166
- }) => WebpackConfiguration | void);
167
- 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 = {
168
176
  env: string;
169
177
  name: string;
170
178
  webpack: typeof webpack;
171
179
  CHAIN_ID: ChainIdentifier;
172
- }) => void;
173
- 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);
174
196
  export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
175
197
  export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
176
198
  export interface ToolsConfig {
@@ -182,7 +204,7 @@ export interface ToolsConfig {
182
204
  styledComponents?: ConfigFunction;
183
205
  lodash?: ConfigFunction;
184
206
  devServer?: DevServerConfig;
185
- tsLoader?: ConfigFunction;
207
+ tsLoader?: TsLoaderConfig;
186
208
  terser?: TerserConfig;
187
209
  minifyCss?: ConfigFunction;
188
210
  esbuild?: Record<string, unknown>;
@@ -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 });
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
- useResolvedConfigContext: () => import(".").NormalizedConfig;
8
+ useResolvedConfigContext: () => import("./config").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.2",
14
+ "version": "1.12.2-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -39,13 +39,13 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@modern-js/load-config": "^1.3.4",
43
- "@modern-js/plugin": "^1.3.6",
44
- "@modern-js/utils": "^1.7.6"
42
+ "@modern-js/load-config": "^1.3.6-alpha.0",
43
+ "@modern-js/plugin": "^1.4.0-alpha.0",
44
+ "@modern-js/utils": "^1.7.9-alpha.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@jest/types": "^27.0.6",
48
- "@modern-js/types": "1.5.4",
48
+ "@modern-js/types": "1.5.5-alpha.0",
49
49
  "@scripts/build": "0.0.0",
50
50
  "@scripts/jest-config": "0.0.0",
51
51
  "@types/babel__code-frame": "^7.0.3",
@@ -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",