@modern-js/core 1.0.0-rc.5 → 1.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +274 -0
  2. package/README.md +21 -20
  3. package/dist/js/modern/config/defaults.js +2 -1
  4. package/dist/js/modern/config/index.js +1 -1
  5. package/dist/js/modern/config/schema/deploy.js +1 -15
  6. package/dist/js/modern/config/schema/index.js +3 -0
  7. package/dist/js/modern/config/schema/server.js +3 -0
  8. package/dist/js/modern/context.js +4 -4
  9. package/dist/js/modern/index.js +17 -13
  10. package/dist/js/modern/initWatcher.js +2 -8
  11. package/dist/js/modern/loadEnv.js +1 -1
  12. package/dist/js/modern/loadPlugins.js +3 -3
  13. package/dist/js/node/config/defaults.js +2 -1
  14. package/dist/js/node/config/index.js +1 -1
  15. package/dist/js/node/config/schema/deploy.js +1 -15
  16. package/dist/js/node/config/schema/index.js +3 -0
  17. package/dist/js/node/config/schema/server.js +3 -0
  18. package/dist/js/node/context.js +9 -9
  19. package/dist/js/node/index.js +54 -23
  20. package/dist/js/node/initWatcher.js +5 -12
  21. package/dist/js/node/loadEnv.js +3 -3
  22. package/dist/js/node/loadPlugins.js +2 -2
  23. package/dist/types/config/defaults.d.ts +1 -0
  24. package/dist/types/config/index.d.ts +3 -3
  25. package/dist/types/config/schema/deploy.d.ts +1 -15
  26. package/dist/types/config/schema/index.d.ts +7 -15
  27. package/dist/types/config/schema/server.d.ts +3 -0
  28. package/dist/types/context.d.ts +3 -9
  29. package/dist/types/index.d.ts +5 -3
  30. package/dist/types/initWatcher.d.ts +1 -2
  31. package/package.json +19 -8
  32. package/src/config/defaults.ts +1 -1
  33. package/src/config/index.ts +4 -4
  34. package/src/config/schema/deploy.ts +1 -7
  35. package/src/config/schema/index.ts +6 -1
  36. package/src/config/schema/server.ts +1 -0
  37. package/src/context.ts +4 -4
  38. package/src/index.ts +30 -22
  39. package/src/initWatcher.ts +2 -6
  40. package/src/loadEnv.ts +1 -1
  41. package/src/loadPlugins.ts +2 -1
  42. package/tests/loadEnv.test.ts +1 -1
  43. package/tests/loadPlugin.test.ts +1 -1
@@ -3,20 +3,27 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ manager: true,
8
+ createPlugin: true,
9
+ registerHook: true,
10
+ mountHook: true,
11
+ usePlugins: true,
12
+ cli: true,
13
+ defineConfig: true,
14
+ defaultsConfig: true,
15
+ AppContext: true,
16
+ useAppContext: true,
17
+ useConfigContext: true,
18
+ useResolvedConfigContext: true
19
+ };
6
20
  Object.defineProperty(exports, "AppContext", {
7
21
  enumerable: true,
8
22
  get: function () {
9
23
  return _context.AppContext;
10
24
  }
11
25
  });
12
- exports.cli = void 0;
13
- Object.defineProperty(exports, "createContext", {
14
- enumerable: true,
15
- get: function () {
16
- return _plugin.createContext;
17
- }
18
- });
19
- exports.createPlugin = void 0;
26
+ exports.createPlugin = exports.cli = void 0;
20
27
  Object.defineProperty(exports, "defaultsConfig", {
21
28
  enumerable: true,
22
29
  get: function () {
@@ -50,13 +57,35 @@ Object.defineProperty(exports, "useResolvedConfigContext", {
50
57
  }
51
58
  });
52
59
 
53
- var _path = _interopRequireDefault(require("path"));
60
+ var _utils = require("@modern-js/utils");
54
61
 
55
62
  var _plugin = require("@modern-js/plugin");
56
63
 
64
+ Object.keys(_plugin).forEach(function (key) {
65
+ if (key === "default" || key === "__esModule") return;
66
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
67
+ if (key in exports && exports[key] === _plugin[key]) return;
68
+ Object.defineProperty(exports, key, {
69
+ enumerable: true,
70
+ get: function () {
71
+ return _plugin[key];
72
+ }
73
+ });
74
+ });
75
+
57
76
  var _node = require("@modern-js/plugin/node");
58
77
 
59
- var _utils = require("@modern-js/utils");
78
+ Object.keys(_node).forEach(function (key) {
79
+ if (key === "default" || key === "__esModule") return;
80
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
81
+ if (key in exports && exports[key] === _node[key]) return;
82
+ Object.defineProperty(exports, key, {
83
+ enumerable: true,
84
+ get: function () {
85
+ return _node[key];
86
+ }
87
+ });
88
+ });
60
89
 
61
90
  var _commander = require("./utils/commander");
62
91
 
@@ -70,8 +99,6 @@ var _initWatcher = require("./initWatcher");
70
99
 
71
100
  var _loadEnv = require("./loadEnv");
72
101
 
73
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
74
-
75
102
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
76
103
 
77
104
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -102,7 +129,7 @@ exports.mountHook = mountHook;
102
129
  exports.registerHook = registerHook;
103
130
  exports.createPlugin = createPlugin;
104
131
 
105
- const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(require.resolve(plugin))));
132
+ const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(_utils.upath.normalize(require.resolve(plugin)))));
106
133
 
107
134
  exports.usePlugins = usePlugins;
108
135
 
@@ -115,7 +142,7 @@ const initAppDir = async () => {
115
142
  throw new Error(`no package.json found in current work dir: ${process.cwd()}`);
116
143
  }
117
144
 
118
- return _path.default.dirname(pkg);
145
+ return _utils.path.dirname(pkg);
119
146
  };
120
147
 
121
148
  const createCli = () => {
@@ -123,6 +150,7 @@ const createCli = () => {
123
150
  let isRestart = false;
124
151
 
125
152
  const init = async (argv = []) => {
153
+ (0, _node.enable)();
126
154
  manager.clear();
127
155
  const appDirectory = await initAppDir();
128
156
  (0, _loadEnv.loadEnv)(appDirectory);
@@ -173,32 +201,35 @@ const createCli = () => {
173
201
  };
174
202
 
175
203
  async function run(argv) {
176
- (0, _node.enable)();
177
204
  const {
178
205
  loadedConfig,
179
206
  appContext,
180
207
  resolved
181
208
  } = await init(argv);
182
- (0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved, hooksRunner, argv);
183
209
  await hooksRunner.commands({
184
210
  program: _commander.program
185
211
  });
212
+ (0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
186
213
  manager.run(() => _commander.program.parse(process.argv));
187
214
  }
188
215
 
189
216
  async function restart() {
190
217
  isRestart = true;
191
218
 
192
- try {
193
- _utils.logger.info('Restart...\n');
219
+ _utils.logger.info('Restart...\n');
220
+
221
+ let hasGetError = false;
194
222
 
195
- await init();
196
- return true;
223
+ try {
224
+ await init(process.argv.slice(2));
197
225
  } catch (err) {
198
- _utils.logger.error(err);
226
+ console.error(err);
227
+ hasGetError = true;
228
+ } finally {
229
+ if (!hasGetError) {
230
+ manager.run(() => _commander.program.parse(process.argv));
231
+ }
199
232
  }
200
-
201
- return false;
202
233
  }
203
234
 
204
235
  return {
@@ -5,16 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.initWatcher = void 0;
7
7
 
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _crypto = _interopRequireDefault(require("crypto"));
11
9
 
12
10
  var _fs = _interopRequireDefault(require("fs"));
13
11
 
14
- var _chokidar = _interopRequireDefault(require("chokidar"));
15
-
16
12
  var _utils = require("@modern-js/utils");
17
13
 
14
+ var _chokidar = _interopRequireDefault(require("chokidar"));
15
+
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
17
 
20
18
  const debug = (0, _utils.createDebugger)('watch-files');
@@ -23,17 +21,12 @@ const md5 = data => _crypto.default.createHash('md5').update(data).digest('hex')
23
21
 
24
22
  const hashMap = new Map();
25
23
 
26
- const initWatcher = async (loaded, appDirectory, resovledConfig, hooksRunner, argv) => {
24
+ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
27
25
  // only add fs watcher on dev mode.
28
26
  if ((0, _utils.isDev)() && argv[0] === 'dev') {
29
- const {
30
- source: {
31
- configDir
32
- }
33
- } = resovledConfig;
34
27
  const extraFiles = await hooksRunner.watchFiles();
35
28
 
36
- const configPath = _path.default.join(appDirectory, configDir);
29
+ const configPath = _utils.path.join(appDirectory, configDir);
37
30
 
38
31
  const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
39
32
  debug(`watched: %o`, watched);
@@ -46,7 +39,7 @@ const initWatcher = async (loaded, appDirectory, resovledConfig, hooksRunner, ar
46
39
 
47
40
  watcher.on('change', changed => {
48
41
  const lastHash = hashMap.get(changed);
49
- const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, changed), 'utf8'));
42
+ const currentHash = md5(_fs.default.readFileSync(_utils.path.join(appDirectory, changed), 'utf8'));
50
43
 
51
44
  if (currentHash !== lastHash) {
52
45
  debug(`file change: %s`, changed);
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.loadEnv = void 0;
7
7
 
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _fs = _interopRequireDefault(require("fs"));
11
9
 
10
+ var _utils = require("@modern-js/utils");
11
+
12
12
  var _dotenv = _interopRequireDefault(require("dotenv"));
13
13
 
14
14
  var _dotenvExpand = _interopRequireDefault(require("dotenv-expand"));
@@ -16,7 +16,7 @@ var _dotenvExpand = _interopRequireDefault(require("dotenv-expand"));
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
18
  const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
19
- [`.env.${mode}`, '.env'].map(name => _path.default.resolve(appDirectory, name)).filter(filePath => _fs.default.existsSync(filePath) && !_fs.default.statSync(filePath).isDirectory()).forEach(filePath => {
19
+ [`.env.${mode}`, '.env'].map(name => _utils.path.resolve(appDirectory, name)).filter(filePath => _fs.default.existsSync(filePath) && !_fs.default.statSync(filePath).isDirectory()).forEach(filePath => {
20
20
  const envConfig = _dotenv.default.config({
21
21
  path: filePath
22
22
  });
@@ -20,9 +20,9 @@ const resolvePlugin = (appDirectory, plugin) => {
20
20
  let filePath = '';
21
21
 
22
22
  try {
23
- filePath = require.resolve(name, {
23
+ filePath = _utils.upath.normalizeSafe(require.resolve(name, {
24
24
  paths: [appDirectory]
25
- });
25
+ }));
26
26
  delete require.cache[filePath];
27
27
  } catch (err) {
28
28
  if (err.code === 'MODULE_NOT_FOUND') {
@@ -5,6 +5,7 @@ export declare const defaults: {
5
5
  server: ServerConfig;
6
6
  dev: {
7
7
  assetPrefix: boolean;
8
+ https: boolean;
8
9
  };
9
10
  deploy: {
10
11
  domain: string;
@@ -73,14 +73,14 @@ export interface ServerConfig {
73
73
  port?: number;
74
74
  logger?: Record<string, string>;
75
75
  measure?: Record<string, string>;
76
+ enableMicroFrontendDebug?: boolean;
76
77
  }
77
78
  export interface DevConfig {
78
79
  assetPrefix?: string | boolean;
80
+ https?: boolean;
79
81
  }
80
82
  export interface DeployConfig {
81
- microFrontend?: {
82
- enableHtmlEntry?: boolean;
83
- };
83
+ microFrontend?: boolean | Record<string, unknown>;
84
84
  domain?: string | Array<string>;
85
85
  domainByEntries?: Record<string, string | Array<string>>;
86
86
  }
@@ -2,21 +2,7 @@ export declare const deploy: {
2
2
  type: string;
3
3
  properties: {
4
4
  microFrontend: {
5
- type: string;
6
- dependencies: {
7
- enableHtmlEntry: {
8
- properties: {
9
- enableLegacy: {
10
- enum: boolean[];
11
- };
12
- };
13
- };
14
- };
15
- properties: {
16
- enableHtmlEntry: {
17
- type: string;
18
- };
19
- };
5
+ type: string[];
20
6
  };
21
7
  domain: {
22
8
  type: string[];
@@ -388,27 +388,16 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
388
388
  proxy: {
389
389
  type: string;
390
390
  };
391
+ enableMicroFrontendDebug: {
392
+ type: string;
393
+ };
391
394
  };
392
395
  };
393
396
  deploy: {
394
397
  type: string;
395
398
  properties: {
396
399
  microFrontend: {
397
- type: string;
398
- dependencies: {
399
- enableHtmlEntry: {
400
- properties: {
401
- enableLegacy: {
402
- enum: boolean[];
403
- };
404
- };
405
- };
406
- };
407
- properties: {
408
- enableHtmlEntry: {
409
- type: string;
410
- };
411
- };
400
+ type: string[];
412
401
  };
413
402
  domain: {
414
403
  type: string[];
@@ -433,6 +422,9 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
433
422
  assetPrefix: {
434
423
  type: string[];
435
424
  };
425
+ https: {
426
+ type: string;
427
+ };
436
428
  };
437
429
  additionalProperties: boolean;
438
430
  };
@@ -175,5 +175,8 @@ export declare const server: {
175
175
  proxy: {
176
176
  type: string;
177
177
  };
178
+ enableMicroFrontendDebug: {
179
+ type: string;
180
+ };
178
181
  };
179
182
  };
@@ -5,15 +5,9 @@ export type { IAppContext };
5
5
  export declare const AppContext: import("@modern-js/plugin").Context<IAppContext>;
6
6
  export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
7
7
  export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig>;
8
- export declare const useAppContext: () => {
9
- value: IAppContext;
10
- };
11
- export declare const useConfigContext: () => {
12
- value: UserConfig;
13
- };
14
- export declare const useResolvedConfigContext: () => {
15
- value: NormalizedConfig;
16
- };
8
+ export declare const useAppContext: () => IAppContext;
9
+ export declare const useConfigContext: () => UserConfig;
10
+ export declare const useResolvedConfigContext: () => NormalizedConfig;
17
11
  export declare const initAppContext: (appDirectory: string, plugins: Array<{
18
12
  cli: any;
19
13
  server: any;
@@ -1,4 +1,4 @@
1
- import { createContext, ParallelWorkflow, AsyncWorkflow, Progresses2Runners } from '@modern-js/plugin';
1
+ import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners } from '@modern-js/plugin';
2
2
  import type { Hooks } from '@modern-js/types';
3
3
  import { Command } from './utils/commander';
4
4
  import { defineConfig, UserConfig, ToolsConfig } from './config';
@@ -6,6 +6,8 @@ import { AppContext, IAppContext, useAppContext, useConfigContext, useResolvedCo
6
6
  import { NormalizedConfig } from './config/mergeConfig';
7
7
  export type { Hooks };
8
8
  export { defaultsConfig } from './config';
9
+ export * from '@modern-js/plugin';
10
+ export * from '@modern-js/plugin/node';
9
11
  export declare type HooksRunner = Progresses2Runners<{
10
12
  config: ParallelWorkflow<void>;
11
13
  validateSchema: ParallelWorkflow<void>;
@@ -70,7 +72,7 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
70
72
  beforeExit: AsyncWorkflow<void, void>;
71
73
  } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
72
74
  export declare const usePlugins: (plugins: string[]) => void;
73
- export { defineConfig, createContext, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
75
+ export { defineConfig, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
74
76
  export type { NormalizedConfig, IAppContext, UserConfig, ToolsConfig };
75
77
  export interface CoreOption {
76
78
  dryRun?: boolean;
@@ -82,5 +84,5 @@ export declare const cli: {
82
84
  resolved: NormalizedConfig;
83
85
  }>;
84
86
  run: (argv: string[]) => Promise<void>;
85
- restart: () => Promise<boolean>;
87
+ restart: () => Promise<void>;
86
88
  };
@@ -1,4 +1,3 @@
1
- import { NormalizedConfig } from './config/mergeConfig';
2
1
  import { LoadedConfig } from './config';
3
2
  import { HooksRunner } from '.';
4
- export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, resovledConfig: NormalizedConfig, hooksRunner: HooksRunner, argv: string[]) => Promise<void>;
3
+ export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "@modern-js/core",
3
- "version": "1.0.0-rc.5",
3
+ "description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
4
+ "homepage": "https://modernjs.dev",
5
+ "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
+ "repository": "modern-js-dev/modern.js",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "react",
10
+ "framework",
11
+ "modern",
12
+ "modern.js"
13
+ ],
14
+ "version": "1.0.0",
4
15
  "jsnext:source": "./src/index.ts",
5
16
  "types": "./dist/types/index.d.ts",
6
17
  "main": "./dist/js/node/index.js",
@@ -25,11 +36,11 @@
25
36
  },
26
37
  "bin": "./bin/modern-js.js",
27
38
  "dependencies": {
28
- "@babel/runtime": "^7",
29
39
  "@babel/code-frame": "^7.14.5",
30
- "@modern-js/load-config": "^1.0.0-rc.5",
31
- "@modern-js/plugin": "^1.0.0-rc.5",
32
- "@modern-js/utils": "^1.0.0-rc.5",
40
+ "@babel/runtime": "^7",
41
+ "@modern-js/load-config": "^1.0.0",
42
+ "@modern-js/plugin": "^1.0.0",
43
+ "@modern-js/utils": "^1.0.0",
33
44
  "address": "^1.1.2",
34
45
  "ajv": "^8.6.2",
35
46
  "ajv-keywords": "^5.0.0",
@@ -46,7 +57,7 @@
46
57
  },
47
58
  "devDependencies": {
48
59
  "@types/babel__code-frame": "^7.0.3",
49
- "@modern-js/types": "^1.0.0-rc.5",
60
+ "@modern-js/types": "^1.0.0",
50
61
  "@types/jest": "^26",
51
62
  "@types/lodash.clonedeep": "^4.5.6",
52
63
  "@types/lodash.mergewith": "^4.6.6",
@@ -55,8 +66,8 @@
55
66
  "@types/react-dom": "^17",
56
67
  "@types/signale": "^1.4.2",
57
68
  "typescript": "^4",
58
- "@modern-js/plugin-testing": "^1.0.0-rc.5",
59
- "@modern-js/module-tools": "^1.0.0-rc.5"
69
+ "@modern-js/plugin-testing": "^1.0.0",
70
+ "@modern-js/module-tools": "^1.0.0"
60
71
  },
61
72
  "sideEffects": false,
62
73
  "modernConfig": {
@@ -72,7 +72,7 @@ const serverDefaults: ServerConfig = {
72
72
  port: 8080,
73
73
  };
74
74
 
75
- const devDefaults = { assetPrefix: false };
75
+ const devDefaults = { assetPrefix: false, https: false };
76
76
 
77
77
  const deployDefaults = {
78
78
  domain: '',
@@ -107,16 +107,16 @@ export interface ServerConfig {
107
107
  port?: number;
108
108
  logger?: Record<string, string>;
109
109
  measure?: Record<string, string>;
110
+ enableMicroFrontendDebug?: boolean;
110
111
  }
111
112
 
112
113
  export interface DevConfig {
113
114
  assetPrefix?: string | boolean;
115
+ https?: boolean;
114
116
  }
115
117
 
116
118
  export interface DeployConfig {
117
- microFrontend?: {
118
- enableHtmlEntry?: boolean;
119
- };
119
+ microFrontend?: boolean | Record<string, unknown>;
120
120
  domain?: string | Array<string>;
121
121
  domainByEntries?: Record<string, string | Array<string>>;
122
122
  }
@@ -175,7 +175,7 @@ export const loadUserConfig = async (
175
175
  appDirectory: string,
176
176
  filePath?: string,
177
177
  ): Promise<LoadedConfig> => {
178
- const loaded = loadConfig<ConfigParam>(appDirectory, filePath);
178
+ const loaded = await loadConfig<ConfigParam>(appDirectory, filePath);
179
179
 
180
180
  const config = !loaded
181
181
  ? {}
@@ -4,13 +4,7 @@ export const deploy = {
4
4
  type: 'object',
5
5
  properties: {
6
6
  microFrontend: {
7
- type: 'object',
8
- dependencies: {
9
- enableHtmlEntry: { properties: { enableLegacy: { enum: [false] } } },
10
- },
11
- properties: {
12
- enableHtmlEntry: { type: 'boolean' },
13
- },
7
+ type: ['boolean', 'object'],
14
8
  },
15
9
  domain: { type: ['array', 'string'] },
16
10
  domainByEntries: {
@@ -16,7 +16,12 @@ const plugins = {
16
16
 
17
17
  const dev = {
18
18
  type: 'object',
19
- properties: { assetPrefix: { type: ['boolean', 'string'] } },
19
+ properties: {
20
+ assetPrefix: { type: ['boolean', 'string'] },
21
+ https: {
22
+ type: 'boolean',
23
+ },
24
+ },
20
25
  additionalProperties: false,
21
26
  };
22
27
  export interface PluginValidateSchema {
@@ -101,5 +101,6 @@ export const server = {
101
101
  logger: { type: 'object' },
102
102
  measure: { type: 'object' },
103
103
  proxy: { type: 'object' },
104
+ enableMicroFrontendDebug: { type: 'boolean' },
104
105
  },
105
106
  };
package/src/context.ts CHANGED
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import { path } from '@modern-js/utils';
2
2
  import { createContext } from '@modern-js/plugin';
3
3
  import address from 'address';
4
4
  import type { IAppContext } from '@modern-js/types';
@@ -15,11 +15,11 @@ export const ResolvedConfigContext = createContext<NormalizedConfig>(
15
15
  {} as NormalizedConfig,
16
16
  );
17
17
 
18
- export const useAppContext = () => AppContext.use();
18
+ export const useAppContext = () => AppContext.use().value;
19
19
 
20
- export const useConfigContext = () => ConfigContext.use();
20
+ export const useConfigContext = () => ConfigContext.use().value;
21
21
 
22
- export const useResolvedConfigContext = () => ResolvedConfigContext.use();
22
+ export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
23
23
 
24
24
  export const initAppContext = (
25
25
  appDirectory: string,
package/src/index.ts CHANGED
@@ -1,7 +1,13 @@
1
- import path from 'path';
1
+ import {
2
+ path,
3
+ upath,
4
+ compatRequire,
5
+ pkgUp,
6
+ ensureAbsolutePath,
7
+ logger,
8
+ } from '@modern-js/utils';
2
9
  import {
3
10
  createAsyncManager,
4
- createContext,
5
11
  createAsyncWorkflow,
6
12
  createParallelWorkflow,
7
13
  ParallelWorkflow,
@@ -9,12 +15,7 @@ import {
9
15
  Progresses2Runners,
10
16
  } from '@modern-js/plugin';
11
17
  import { enable } from '@modern-js/plugin/node';
12
- import {
13
- compatRequire,
14
- pkgUp,
15
- ensureAbsolutePath,
16
- logger,
17
- } from '@modern-js/utils';
18
+
18
19
  import type { Hooks } from '@modern-js/types';
19
20
  import { program, Command } from './utils/commander';
20
21
  import {
@@ -42,6 +43,9 @@ import { loadEnv } from './loadEnv';
42
43
  export type { Hooks };
43
44
  export { defaultsConfig } from './config';
44
45
 
46
+ export * from '@modern-js/plugin';
47
+ export * from '@modern-js/plugin/node';
48
+
45
49
  program
46
50
  .name('modern')
47
51
  .usage('<command> [options]')
@@ -101,12 +105,11 @@ export const {
101
105
 
102
106
  export const usePlugins = (plugins: string[]) =>
103
107
  plugins.forEach(plugin =>
104
- manager.usePlugin(compatRequire(require.resolve(plugin))),
108
+ manager.usePlugin(compatRequire(upath.normalize(require.resolve(plugin)))),
105
109
  );
106
110
 
107
111
  export {
108
112
  defineConfig,
109
- createContext,
110
113
  AppContext,
111
114
  useAppContext,
112
115
  useConfigContext,
@@ -136,6 +139,8 @@ const createCli = () => {
136
139
  let isRestart = false;
137
140
 
138
141
  const init = async (argv: string[] = []) => {
142
+ enable();
143
+
139
144
  manager.clear();
140
145
 
141
146
  const appDirectory = await initAppDir();
@@ -201,33 +206,36 @@ const createCli = () => {
201
206
  };
202
207
 
203
208
  async function run(argv: string[]) {
204
- enable();
205
-
206
209
  const { loadedConfig, appContext, resolved } = await init(argv);
207
210
 
211
+ await hooksRunner.commands({ program });
212
+
208
213
  initWatcher(
209
214
  loadedConfig,
210
215
  appContext.appDirectory,
211
- resolved,
216
+ resolved.source.configDir,
212
217
  hooksRunner,
213
218
  argv,
214
219
  );
215
-
216
- await hooksRunner.commands({ program });
217
-
218
220
  manager.run(() => program.parse(process.argv));
219
221
  }
220
222
 
221
223
  async function restart() {
222
224
  isRestart = true;
225
+
226
+ logger.info('Restart...\n');
227
+
228
+ let hasGetError = false
223
229
  try {
224
- logger.info('Restart...\n');
225
- await init();
226
- return true;
227
- } catch (err) {
228
- logger.error(err as string);
230
+ await init(process.argv.slice(2));
231
+ } catch(err) {
232
+ console.error(err)
233
+ hasGetError = true
234
+ } finally {
235
+ if (!hasGetError) {
236
+ manager.run(() => program.parse(process.argv));
237
+ }
229
238
  }
230
- return false;
231
239
  }
232
240
 
233
241
  return {