@modern-js/core 1.12.1 → 1.12.2

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,19 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.12.2
4
+
5
+ ### Patch Changes
6
+
7
+ - f29e9ba: feat: simplify context usage, no longer depend on containers
8
+ - d9564f2: feat: add watchOptions for server watcher
9
+ - a90bc96: perf(babel): skip babel-plugin-import if package not installed
10
+ - Updated dependencies [3050acc]
11
+ - Updated dependencies [f29e9ba]
12
+ - Updated dependencies [a90bc96]
13
+ - @modern-js/load-config@1.3.6
14
+ - @modern-js/plugin@1.4.0
15
+ - @modern-js/utils@1.7.9
16
+
3
17
  ## 1.12.1
4
18
 
5
19
  ### Patch Changes
@@ -12,5 +12,5 @@ export declare const defineConfig: (config: ConfigParam) => ConfigParam;
12
12
  * Assign the pkg config into the user config.
13
13
  */
14
14
  export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
15
- export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
15
+ export declare const loadUserConfig: (appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<LoadedConfig>;
16
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];
@@ -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,7 +1,7 @@
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
7
  import type { RuleSetRule, Configuration as WebpackConfiguration, WebpackPluginInstance } from 'webpack';
@@ -115,6 +115,7 @@ export interface ServerConfig {
115
115
  logger?: boolean | Record<string, any>;
116
116
  metrics?: boolean | Record<string, any>;
117
117
  enableMicroFrontendDebug?: boolean;
118
+ watchOptions?: WatchOptions;
118
119
  }
119
120
  export declare type DevProxyOptions = string | Record<string, string>;
120
121
  export interface DevConfig {
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);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.12.1",
14
+ "version": "1.12.2",
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.8",
44
- "@modern-js/utils": "^1.7.8"
42
+ "@modern-js/load-config": "^1.3.6",
43
+ "@modern-js/plugin": "^1.4.0",
44
+ "@modern-js/utils": "^1.7.9"
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",
49
49
  "@scripts/build": "0.0.0",
50
50
  "@scripts/jest-config": "0.0.0",
51
51
  "@types/babel__code-frame": "^7.0.3",