@modern-js/core 2.26.0 → 2.28.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 (66) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/bin.d.ts +1 -1
  3. package/dist/bin.js +5 -3
  4. package/dist/config/createDefaultConfig.d.ts +1 -1
  5. package/dist/config/createDefaultConfig.js +12 -6
  6. package/dist/config/createLoadedConfig.d.ts +1 -1
  7. package/dist/config/createLoadedConfig.js +81 -73
  8. package/dist/config/createResolvedConfig.d.ts +1 -1
  9. package/dist/config/createResolvedConfig.js +60 -72
  10. package/dist/config/index.d.ts +1 -1
  11. package/dist/config/index.js +7 -18
  12. package/dist/config/loadConfig.d.ts +5 -5
  13. package/dist/config/loadConfig.js +115 -112
  14. package/dist/context.d.ts +21 -14
  15. package/dist/context.js +74 -60
  16. package/dist/createCli.d.ts +13 -13
  17. package/dist/createCli.js +134 -113
  18. package/dist/index.d.ts +16 -16
  19. package/dist/index.js +59 -35
  20. package/dist/loadEnv.d.ts +1 -1
  21. package/dist/loadEnv.js +23 -17
  22. package/dist/loadPlugins.d.ts +4 -4
  23. package/dist/loadPlugins.js +55 -54
  24. package/dist/manager.d.ts +62 -62
  25. package/dist/manager.js +40 -23
  26. package/dist/nodeApi.d.ts +1 -1
  27. package/dist/nodeApi.js +25 -9
  28. package/dist/runBin.d.ts +2 -2
  29. package/dist/runBin.js +57 -53
  30. package/dist/schema/patchSchema.d.ts +15 -15
  31. package/dist/schema/patchSchema.js +56 -53
  32. package/dist/schema/testing.d.ts +11 -11
  33. package/dist/schema/testing.js +26 -8
  34. package/dist/schema/traverseSchema.d.ts +1 -1
  35. package/dist/schema/traverseSchema.js +25 -17
  36. package/dist/types/config/index.d.ts +37 -37
  37. package/dist/types/config/index.js +3 -1
  38. package/dist/types/config/testing.d.ts +11 -11
  39. package/dist/types/config/testing.js +3 -1
  40. package/dist/types/context.d.ts +27 -27
  41. package/dist/types/context.js +3 -1
  42. package/dist/types/coreOptions.d.ts +22 -22
  43. package/dist/types/coreOptions.js +3 -1
  44. package/dist/types/hooks.d.ts +41 -41
  45. package/dist/types/hooks.js +3 -1
  46. package/dist/types/index.d.ts +3 -3
  47. package/dist/types/index.js +10 -21
  48. package/dist/types/plugin.d.ts +10 -10
  49. package/dist/types/plugin.js +3 -1
  50. package/dist/types/pluginAPI.d.ts +10 -10
  51. package/dist/types/pluginAPI.js +3 -1
  52. package/dist/utils/checkIsDuplicationPlugin.d.ts +1 -1
  53. package/dist/utils/checkIsDuplicationPlugin.js +24 -21
  54. package/dist/utils/commander.d.ts +1 -1
  55. package/dist/utils/commander.js +31 -17
  56. package/dist/utils/createFileWatcher.d.ts +1 -1
  57. package/dist/utils/createFileWatcher.js +85 -106
  58. package/dist/utils/index.d.ts +1 -1
  59. package/dist/utils/index.js +10 -21
  60. package/dist/utils/initAppDir.d.ts +1 -1
  61. package/dist/utils/initAppDir.js +22 -17
  62. package/dist/utils/mergeConfig.d.ts +1 -1
  63. package/dist/utils/mergeConfig.js +37 -27
  64. package/dist/utils/repeatKeyWarning.d.ts +1 -1
  65. package/dist/utils/repeatKeyWarning.js +29 -16
  66. package/package.json +11 -10
package/dist/createCli.js CHANGED
@@ -1,122 +1,143 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCli = exports.mergeOptions = void 0;
4
- const utils_1 = require("@modern-js/utils");
5
- const utils_2 = require("./utils");
6
- const loadPlugins_1 = require("./loadPlugins");
7
- const context_1 = require("./context");
8
- const loadEnv_1 = require("./loadEnv");
9
- const manager_1 = require("./manager");
10
- const config_1 = require("./config");
11
- const checkIsDuplicationPlugin_1 = require("./utils/checkIsDuplicationPlugin");
12
- const setProgramVersion = (version = 'unknown') => {
13
- utils_1.program.name('modern').usage('<command> [options]').version(version);
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ mergeOptions: function() {
14
+ return mergeOptions;
15
+ },
16
+ createCli: function() {
17
+ return createCli;
18
+ }
19
+ });
20
+ const _utils = require("@modern-js/utils");
21
+ const _utils1 = require("./utils");
22
+ const _loadPlugins = require("./loadPlugins");
23
+ const _context = require("./context");
24
+ const _loadEnv = require("./loadEnv");
25
+ const _manager = require("./manager");
26
+ const _config = require("./config");
27
+ const _checkIsDuplicationPlugin = require("./utils/checkIsDuplicationPlugin");
28
+ const setProgramVersion = (version = "unknown") => {
29
+ _utils.program.name("modern").usage("<command> [options]").version(version);
14
30
  };
15
31
  const mergeOptions = (options) => {
16
- const defaultOptions = {
17
- serverConfigFile: utils_1.DEFAULT_SERVER_CONFIG,
18
- };
19
- return {
20
- ...defaultOptions,
21
- ...options,
22
- };
32
+ const defaultOptions = {
33
+ serverConfigFile: _utils.DEFAULT_SERVER_CONFIG
34
+ };
35
+ return {
36
+ ...defaultOptions,
37
+ ...options
38
+ };
23
39
  };
24
- exports.mergeOptions = mergeOptions;
25
40
  const createCli = () => {
26
- let hooksRunner;
27
- let initOptions;
28
- const init = async (options) => {
29
- var _a, _b, _c, _d, _e;
30
- manager_1.manager.clear();
31
- const mergedOptions = (0, exports.mergeOptions)(options);
32
- initOptions = mergedOptions;
33
- const appDirectory = await (0, utils_2.initAppDir)(options === null || options === void 0 ? void 0 : options.cwd);
34
- (0, utils_2.initCommandsMap)();
35
- setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
36
- 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';
37
- (0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
38
- const loaded = await (0, config_1.createLoadedConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.loadedConfig);
39
- const plugins = await (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
40
- internalPlugins: (_c = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _c === void 0 ? void 0 : _c.cli,
41
- autoLoad: (_d = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _d === void 0 ? void 0 : _d.autoLoad,
42
- forceAutoLoadPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.forceAutoLoadPlugins,
43
- });
44
- (0, checkIsDuplicationPlugin_1.checkIsDuplicationPlugin)(plugins.map(plugin => plugin.name), loaded.config.autoLoadPlugins);
45
- plugins.forEach(plugin => plugin && manager_1.manager.usePlugin(plugin));
46
- const appContext = (0, context_1.initAppContext)({
47
- appDirectory,
48
- plugins,
49
- configFile: loaded.filePath,
50
- options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
51
- serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile,
52
- serverInternalPlugins: ((_e = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _e === void 0 ? void 0 : _e.server) || utils_1.INTERNAL_SERVER_PLUGINS,
53
- });
54
- context_1.ConfigContext.set(loaded.config);
55
- context_1.AppContext.set(appContext);
56
- hooksRunner = await manager_1.manager.init();
57
- ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
58
- process.on(event, async (err) => {
59
- hooksRunner.beforeExit();
60
- if (err instanceof Error) {
61
- utils_1.logger.error(err.stack);
62
- }
63
- process.nextTick(() => {
64
- // eslint-disable-next-line no-process-exit
65
- process.exit(1);
66
- });
67
- });
68
- });
69
- await hooksRunner.beforeConfig();
70
- const extraConfigs = await hooksRunner.config();
71
- const extraSchemas = await hooksRunner.validateSchema();
72
- const normalizedConfig = await (0, config_1.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
73
- const { resolved } = await hooksRunner.resolvedConfig({
74
- resolved: normalizedConfig,
75
- });
76
- // update context value
77
- context_1.ConfigContext.set(loaded.config);
78
- context_1.ResolvedConfigContext.set(resolved);
79
- await hooksRunner.prepare();
80
- await hooksRunner.afterPrepare();
81
- return {
82
- resolved,
83
- appContext: (0, context_1.useAppContext)(),
84
- };
85
- };
86
- async function run(options) {
87
- var _a;
88
- const { appContext } = await init(options);
89
- await hooksRunner.commands({ program: utils_1.program });
90
- await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
91
- utils_1.program.parse(process.argv);
92
- if (!((_a = utils_1.program.commands) === null || _a === void 0 ? void 0 : _a.length)) {
93
- utils_1.logger.warn('No command found, please make sure you have registered plugins correctly.');
41
+ let hooksRunner;
42
+ let initOptions;
43
+ const init = async (options) => {
44
+ var _options, _options1, _mergedOptions_options, _mergedOptions, _mergedOptions1, _mergedOptions2, _mergedOptions3, _mergedOptions_internalPlugins, _mergedOptions4, _mergedOptions_internalPlugins1, _mergedOptions5, _mergedOptions6, _mergedOptions7, _mergedOptions8, _mergedOptions_internalPlugins2, _mergedOptions9, _options2;
45
+ _manager.manager.clear();
46
+ const mergedOptions = mergeOptions(options);
47
+ initOptions = mergedOptions;
48
+ const appDirectory = await (0, _utils1.initAppDir)((_options = options) === null || _options === void 0 ? void 0 : _options.cwd);
49
+ (0, _utils1.initCommandsMap)();
50
+ setProgramVersion((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.version);
51
+ var _mergedOptions_options_metaName;
52
+ const metaName = (_mergedOptions_options_metaName = (_mergedOptions = mergedOptions) === null || _mergedOptions === void 0 ? void 0 : (_mergedOptions_options = _mergedOptions.options) === null || _mergedOptions_options === void 0 ? void 0 : _mergedOptions_options.metaName) !== null && _mergedOptions_options_metaName !== void 0 ? _mergedOptions_options_metaName : "MODERN";
53
+ (0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
54
+ const loaded = await (0, _config.createLoadedConfig)(appDirectory, (_mergedOptions1 = mergedOptions) === null || _mergedOptions1 === void 0 ? void 0 : _mergedOptions1.configFile, (_mergedOptions2 = mergedOptions) === null || _mergedOptions2 === void 0 ? void 0 : _mergedOptions2.packageJsonConfig, (_mergedOptions3 = mergedOptions) === null || _mergedOptions3 === void 0 ? void 0 : _mergedOptions3.loadedConfig);
55
+ const plugins = await (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
56
+ internalPlugins: (_mergedOptions4 = mergedOptions) === null || _mergedOptions4 === void 0 ? void 0 : (_mergedOptions_internalPlugins = _mergedOptions4.internalPlugins) === null || _mergedOptions_internalPlugins === void 0 ? void 0 : _mergedOptions_internalPlugins.cli,
57
+ autoLoad: (_mergedOptions5 = mergedOptions) === null || _mergedOptions5 === void 0 ? void 0 : (_mergedOptions_internalPlugins1 = _mergedOptions5.internalPlugins) === null || _mergedOptions_internalPlugins1 === void 0 ? void 0 : _mergedOptions_internalPlugins1.autoLoad,
58
+ forceAutoLoadPlugins: (_mergedOptions6 = mergedOptions) === null || _mergedOptions6 === void 0 ? void 0 : _mergedOptions6.forceAutoLoadPlugins
59
+ });
60
+ (0, _checkIsDuplicationPlugin.checkIsDuplicationPlugin)(plugins.map((plugin) => plugin.name), loaded.config.autoLoadPlugins);
61
+ plugins.forEach((plugin) => plugin && _manager.manager.usePlugin(plugin));
62
+ const appContext = (0, _context.initAppContext)({
63
+ appDirectory,
64
+ plugins,
65
+ configFile: loaded.filePath,
66
+ options: (_mergedOptions7 = mergedOptions) === null || _mergedOptions7 === void 0 ? void 0 : _mergedOptions7.options,
67
+ serverConfigFile: (_mergedOptions8 = mergedOptions) === null || _mergedOptions8 === void 0 ? void 0 : _mergedOptions8.serverConfigFile,
68
+ serverInternalPlugins: ((_mergedOptions9 = mergedOptions) === null || _mergedOptions9 === void 0 ? void 0 : (_mergedOptions_internalPlugins2 = _mergedOptions9.internalPlugins) === null || _mergedOptions_internalPlugins2 === void 0 ? void 0 : _mergedOptions_internalPlugins2.server) || _utils.INTERNAL_SERVER_PLUGINS
69
+ });
70
+ _context.ConfigContext.set(loaded.config);
71
+ _context.AppContext.set(appContext);
72
+ hooksRunner = await _manager.manager.init();
73
+ [
74
+ "SIGINT",
75
+ "SIGTERM",
76
+ "unhandledRejection",
77
+ "uncaughtException"
78
+ ].forEach((event) => {
79
+ process.on(event, async (err) => {
80
+ hooksRunner.beforeExit();
81
+ if (err instanceof Error) {
82
+ _utils.logger.error(err.stack);
94
83
  }
95
- }
96
- async function runCommand(command, commandOptions = [], options) {
97
- const argv = process.argv
98
- .slice(0, 2)
99
- .concat(command)
100
- .concat(commandOptions);
101
- process.env.MODERN_ARGV = argv.join(' ');
102
- const { appContext } = await init(options);
103
- await hooksRunner.commands({ program: utils_1.program });
104
- await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
105
- utils_1.program.parse(argv);
106
- }
107
- async function test(argv, options) {
108
- const newProgram = new utils_1.Command();
109
- const { coreOptions } = options !== null && options !== void 0 ? options : {};
110
- await init(coreOptions);
111
- await hooksRunner.commands({ program: newProgram });
112
- await newProgram.parseAsync(argv);
113
- }
84
+ process.nextTick(() => {
85
+ process.exit(1);
86
+ });
87
+ });
88
+ });
89
+ await hooksRunner.beforeConfig();
90
+ const extraConfigs = await hooksRunner.config();
91
+ const extraSchemas = await hooksRunner.validateSchema();
92
+ const normalizedConfig = await (0, _config.createResolveConfig)(loaded, extraConfigs, extraSchemas, (_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.onSchemaError);
93
+ const { resolved } = await hooksRunner.resolvedConfig({
94
+ resolved: normalizedConfig
95
+ });
96
+ _context.ConfigContext.set(loaded.config);
97
+ _context.ResolvedConfigContext.set(resolved);
98
+ await hooksRunner.prepare();
99
+ await hooksRunner.afterPrepare();
114
100
  return {
115
- init,
116
- run,
117
- test,
118
- runCommand,
119
- getPrevInitOptions: () => initOptions,
101
+ resolved,
102
+ appContext: (0, _context.useAppContext)()
120
103
  };
104
+ };
105
+ async function run(options) {
106
+ var _program_commands;
107
+ const { appContext } = await init(options);
108
+ await hooksRunner.commands({
109
+ program: _utils.program
110
+ });
111
+ await (0, _utils1.createFileWatcher)(appContext, hooksRunner);
112
+ _utils.program.parse(process.argv);
113
+ if (!((_program_commands = _utils.program.commands) === null || _program_commands === void 0 ? void 0 : _program_commands.length)) {
114
+ _utils.logger.warn("No command found, please make sure you have registered plugins correctly.");
115
+ }
116
+ }
117
+ async function runCommand(command, commandOptions = [], options) {
118
+ const argv = process.argv.slice(0, 2).concat(command).concat(commandOptions);
119
+ process.env.MODERN_ARGV = argv.join(" ");
120
+ const { appContext } = await init(options);
121
+ await hooksRunner.commands({
122
+ program: _utils.program
123
+ });
124
+ await (0, _utils1.createFileWatcher)(appContext, hooksRunner);
125
+ _utils.program.parse(argv);
126
+ }
127
+ async function test(argv, options) {
128
+ const newProgram = new _utils.Command();
129
+ const { coreOptions } = options !== null && options !== void 0 ? options : {};
130
+ await init(coreOptions);
131
+ await hooksRunner.commands({
132
+ program: newProgram
133
+ });
134
+ await newProgram.parseAsync(argv);
135
+ }
136
+ return {
137
+ init,
138
+ run,
139
+ test,
140
+ runCommand,
141
+ getPrevInitOptions: () => initOptions
142
+ };
121
143
  };
122
- exports.createCli = createCli;
package/dist/index.d.ts CHANGED
@@ -2,22 +2,22 @@ export * from './types';
2
2
  export * from '@modern-js/plugin';
3
3
  export { mergeConfig, initAppDir } from './utils';
4
4
  export { manager, createPlugin, registerHook } from './manager';
5
- export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, initAppContext, } from './context';
5
+ export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, initAppContext } from './context';
6
6
  export declare const cli: {
7
- init: (options?: import("./types").CoreOptions | undefined) => Promise<{
8
- resolved: import("./types").NormalizedConfig<{}>;
9
- appContext: import("./types").IAppContext;
10
- }>;
11
- run: (options?: import("./types").CoreOptions | undefined) => Promise<void>;
12
- test: (argv: string[], options?: {
13
- coreOptions?: import("./types").CoreOptions | undefined;
14
- disableWatcher?: boolean | undefined;
15
- } | undefined) => Promise<void>;
16
- runCommand: (command: string, commandOptions?: string[], options?: import("./types").CoreOptions | undefined) => Promise<void>;
17
- getPrevInitOptions: () => import("./types").CoreOptions | undefined;
7
+ init: (options?: import("./types").CoreOptions | undefined) => Promise<{
8
+ resolved: import("./types").NormalizedConfig<{}>;
9
+ appContext: import("./types").IAppContext;
10
+ }>;
11
+ run: (options?: import("./types").CoreOptions | undefined) => Promise<void>;
12
+ test: (argv: string[], options?: {
13
+ coreOptions?: import("./types").CoreOptions | undefined;
14
+ disableWatcher?: boolean | undefined;
15
+ } | undefined) => Promise<void>;
16
+ runCommand: (command: string, commandOptions?: string[], options?: import("./types").CoreOptions | undefined) => Promise<void>;
17
+ getPrevInitOptions: () => import("./types").CoreOptions | undefined;
18
18
  };
19
19
  declare module '@modern-js/utils/compiled/commander' {
20
- interface Command {
21
- commandsMap: Map<string, Command>;
22
- }
23
- }
20
+ interface Command {
21
+ commandsMap: Map<string, Command>;
22
+ }
23
+ }
package/dist/index.js CHANGED
@@ -1,36 +1,60 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.cli = exports.initAppContext = exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = exports.registerHook = exports.createPlugin = exports.manager = exports.initAppDir = exports.mergeConfig = void 0;
18
- const createCli_1 = require("./createCli");
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("@modern-js/plugin"), exports);
21
- var utils_1 = require("./utils");
22
- Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function () { return utils_1.mergeConfig; } });
23
- Object.defineProperty(exports, "initAppDir", { enumerable: true, get: function () { return utils_1.initAppDir; } });
24
- var manager_1 = require("./manager");
25
- Object.defineProperty(exports, "manager", { enumerable: true, get: function () { return manager_1.manager; } });
26
- Object.defineProperty(exports, "createPlugin", { enumerable: true, get: function () { return manager_1.createPlugin; } });
27
- Object.defineProperty(exports, "registerHook", { enumerable: true, get: function () { return manager_1.registerHook; } });
28
- var context_1 = require("./context");
29
- Object.defineProperty(exports, "AppContext", { enumerable: true, get: function () { return context_1.AppContext; } });
30
- Object.defineProperty(exports, "ConfigContext", { enumerable: true, get: function () { return context_1.ConfigContext; } });
31
- Object.defineProperty(exports, "ResolvedConfigContext", { enumerable: true, get: function () { return context_1.ResolvedConfigContext; } });
32
- Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return context_1.useAppContext; } });
33
- Object.defineProperty(exports, "useConfigContext", { enumerable: true, get: function () { return context_1.useConfigContext; } });
34
- Object.defineProperty(exports, "useResolvedConfigContext", { enumerable: true, get: function () { return context_1.useResolvedConfigContext; } });
35
- Object.defineProperty(exports, "initAppContext", { enumerable: true, get: function () { return context_1.initAppContext; } });
36
- exports.cli = (0, createCli_1.createCli)();
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ mergeConfig: function() {
14
+ return _utils.mergeConfig;
15
+ },
16
+ initAppDir: function() {
17
+ return _utils.initAppDir;
18
+ },
19
+ manager: function() {
20
+ return _manager.manager;
21
+ },
22
+ createPlugin: function() {
23
+ return _manager.createPlugin;
24
+ },
25
+ registerHook: function() {
26
+ return _manager.registerHook;
27
+ },
28
+ AppContext: function() {
29
+ return _context.AppContext;
30
+ },
31
+ ConfigContext: function() {
32
+ return _context.ConfigContext;
33
+ },
34
+ ResolvedConfigContext: function() {
35
+ return _context.ResolvedConfigContext;
36
+ },
37
+ useAppContext: function() {
38
+ return _context.useAppContext;
39
+ },
40
+ useConfigContext: function() {
41
+ return _context.useConfigContext;
42
+ },
43
+ useResolvedConfigContext: function() {
44
+ return _context.useResolvedConfigContext;
45
+ },
46
+ initAppContext: function() {
47
+ return _context.initAppContext;
48
+ },
49
+ cli: function() {
50
+ return cli;
51
+ }
52
+ });
53
+ const _export_star = require("@swc/helpers/_/_export_star");
54
+ const _createCli = require("./createCli");
55
+ _export_star._(require("./types"), exports);
56
+ _export_star._(require("@modern-js/plugin"), exports);
57
+ const _utils = require("./utils");
58
+ const _manager = require("./manager");
59
+ const _context = require("./context");
60
+ const cli = (0, _createCli.createCli)();
package/dist/loadEnv.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const loadEnv: (appDirectory: string, mode?: string) => void;
1
+ export declare const loadEnv: (appDirectory: string, mode?: string) => void;
package/dist/loadEnv.js CHANGED
@@ -1,21 +1,27 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadEnv = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const utils_1 = require("@modern-js/utils");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "loadEnv", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return loadEnv;
9
+ }
10
+ });
11
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
+ const _fs = /* @__PURE__ */ _interop_require_default._(require("fs"));
13
+ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
14
+ const _utils = require("@modern-js/utils");
10
15
  const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
11
- // Don't change the order of the filenames, since they are ordered by the priority.
12
- // Files on the left have more priority than files on the right.
13
- [`.env.${mode}.local`, '.env.local', `.env.${mode}`, '.env']
14
- .map(name => path_1.default.resolve(appDirectory, name))
15
- .filter(filePath => fs_1.default.existsSync(filePath) && !fs_1.default.statSync(filePath).isDirectory())
16
- .forEach(filePath => {
17
- const envConfig = utils_1.dotenv.config({ path: filePath });
18
- (0, utils_1.dotenvExpand)(envConfig);
16
+ [
17
+ `.env.${mode}.local`,
18
+ ".env.local",
19
+ `.env.${mode}`,
20
+ ".env"
21
+ ].map((name) => _path.default.resolve(appDirectory, name)).filter((filePath) => _fs.default.existsSync(filePath) && !_fs.default.statSync(filePath).isDirectory()).forEach((filePath) => {
22
+ const envConfig = _utils.dotenv.config({
23
+ path: filePath
19
24
  });
25
+ (0, _utils.dotenvExpand)(envConfig);
26
+ });
20
27
  };
21
- exports.loadEnv = loadEnv;
@@ -9,7 +9,7 @@ export declare const isOldPluginConfig: (config?: PluginConfig) => config is Old
9
9
  * @returns Plugin Objects has been required.
10
10
  */
11
11
  export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
12
- internalPlugins?: InternalPlugins;
13
- autoLoad?: InternalPlugins;
14
- forceAutoLoadPlugins?: boolean;
15
- }) => Promise<CliPlugin[]>;
12
+ internalPlugins?: InternalPlugins;
13
+ autoLoad?: InternalPlugins;
14
+ forceAutoLoadPlugins?: boolean;
15
+ }) => Promise<CliPlugin[]>;
@@ -1,60 +1,61 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadPlugins = exports.isOldPluginConfig = void 0;
4
- const utils_1 = require("@modern-js/utils");
5
- const manager_1 = require("./manager");
6
- const debug = (0, utils_1.createDebugger)('load-plugins');
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ isOldPluginConfig: function() {
14
+ return isOldPluginConfig;
15
+ },
16
+ loadPlugins: function() {
17
+ return loadPlugins;
18
+ }
19
+ });
20
+ const _utils = require("@modern-js/utils");
21
+ const _manager = require("./manager");
22
+ const debug = (0, _utils.createDebugger)("load-plugins");
7
23
  const resolveCliPlugin = async (p, appDirectory) => {
8
- const pkg = typeof p === 'string' ? p : p[0];
9
- const pluginOptions = typeof p === 'string' ? undefined : p[1];
10
- const path = (0, utils_1.tryResolve)(pkg, appDirectory);
11
- let module;
12
- try {
13
- module = (0, utils_1.compatRequire)(path);
14
- }
15
- catch (e) {
16
- // load esm module
17
- ({ default: module } = await (0, utils_1.dynamicImport)(path));
18
- }
19
- if (typeof module === 'function') {
20
- const result = module(pluginOptions);
21
- return (0, manager_1.createPlugin)(result.setup, result);
22
- }
23
- return module;
24
+ const pkg = typeof p === "string" ? p : p[0];
25
+ const pluginOptions = typeof p === "string" ? void 0 : p[1];
26
+ const path = (0, _utils.tryResolve)(pkg, appDirectory);
27
+ let module;
28
+ try {
29
+ module = (0, _utils.compatRequire)(path);
30
+ } catch (e) {
31
+ ({ default: module } = await (0, _utils.dynamicImport)(path));
32
+ }
33
+ if (typeof module === "function") {
34
+ const result = module(pluginOptions);
35
+ return (0, _manager.createPlugin)(result.setup, result);
36
+ }
37
+ return module;
24
38
  };
25
- const isOldPluginConfig = (config) => Array.isArray(config) &&
26
- config.some(item => {
27
- return typeof item === 'string' || Array.isArray(item);
28
- });
29
- exports.isOldPluginConfig = isOldPluginConfig;
30
- /**
31
- * Load internal plugins which in @modern-js scope and user's custom plugins.
32
- * @param appDirectory - Application root directory.
33
- * @param userConfig - Resolved user config.
34
- * @param options.internalPlugins - Internal plugins.
35
- * @returns Plugin Objects has been required.
36
- */
39
+ const isOldPluginConfig = (config) => Array.isArray(config) && config.some((item) => {
40
+ return typeof item === "string" || Array.isArray(item);
41
+ });
37
42
  const loadPlugins = async (appDirectory, userConfig, options = {}) => {
38
- const pluginConfig = userConfig.plugins;
39
- const plugins = [
40
- ...(options.forceAutoLoadPlugins || userConfig.autoLoadPlugins
41
- ? (0, utils_1.getInternalPlugins)(appDirectory, options.internalPlugins)
42
- : []),
43
- ...((0, exports.isOldPluginConfig)(pluginConfig) ? pluginConfig : []),
44
- ...(options.autoLoad
45
- ? (0, utils_1.getInternalPlugins)(appDirectory, options.autoLoad)
46
- : []),
47
- ];
48
- const loadedPlugins = await Promise.all(plugins.map(plugin => {
49
- const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
50
- debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
51
- return loadedPlugin;
52
- }));
53
- if (!(0, exports.isOldPluginConfig)(pluginConfig)) {
54
- if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.length) {
55
- loadedPlugins.push(...pluginConfig.map(item => (0, manager_1.createPlugin)(item.setup, item)));
56
- }
43
+ const pluginConfig = userConfig.plugins;
44
+ const plugins = [
45
+ ...options.forceAutoLoadPlugins || userConfig.autoLoadPlugins ? (0, _utils.getInternalPlugins)(appDirectory, options.internalPlugins) : [],
46
+ ...isOldPluginConfig(pluginConfig) ? pluginConfig : [],
47
+ ...options.autoLoad ? (0, _utils.getInternalPlugins)(appDirectory, options.autoLoad) : []
48
+ ];
49
+ const loadedPlugins = await Promise.all(plugins.map((plugin) => {
50
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
51
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
52
+ return loadedPlugin;
53
+ }));
54
+ if (!isOldPluginConfig(pluginConfig)) {
55
+ var _pluginConfig;
56
+ if ((_pluginConfig = pluginConfig) === null || _pluginConfig === void 0 ? void 0 : _pluginConfig.length) {
57
+ loadedPlugins.push(...pluginConfig.map((item) => (0, _manager.createPlugin)(item.setup, item)));
57
58
  }
58
- return loadedPlugins;
59
+ }
60
+ return loadedPlugins;
59
61
  };
60
- exports.loadPlugins = loadPlugins;