@modern-js/core 1.0.0-alpha.3

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 (83) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +21 -0
  3. package/README.md +32 -0
  4. package/bin/modern-js.js +18 -0
  5. package/dist/js/modern/config/defaults.js +102 -0
  6. package/dist/js/modern/config/index.js +104 -0
  7. package/dist/js/modern/config/mergeConfig.js +20 -0
  8. package/dist/js/modern/config/schema/deploy.js +34 -0
  9. package/dist/js/modern/config/schema/index.js +104 -0
  10. package/dist/js/modern/config/schema/output.js +147 -0
  11. package/dist/js/modern/config/schema/server.js +167 -0
  12. package/dist/js/modern/config/schema/source.js +59 -0
  13. package/dist/js/modern/config/schema/tools.js +33 -0
  14. package/dist/js/modern/context.js +25 -0
  15. package/dist/js/modern/index.js +137 -0
  16. package/dist/js/modern/initWatcher.js +51 -0
  17. package/dist/js/modern/loadEnv.js +12 -0
  18. package/dist/js/modern/loadPlugins.js +66 -0
  19. package/dist/js/modern/utils/commander.js +19 -0
  20. package/dist/js/modern/utils/repeatKeyWarning.js +18 -0
  21. package/dist/js/node/config/defaults.js +109 -0
  22. package/dist/js/node/config/index.js +142 -0
  23. package/dist/js/node/config/mergeConfig.js +32 -0
  24. package/dist/js/node/config/schema/deploy.js +43 -0
  25. package/dist/js/node/config/schema/index.js +126 -0
  26. package/dist/js/node/config/schema/output.js +156 -0
  27. package/dist/js/node/config/schema/server.js +176 -0
  28. package/dist/js/node/config/schema/source.js +68 -0
  29. package/dist/js/node/config/schema/tools.js +40 -0
  30. package/dist/js/node/context.js +52 -0
  31. package/dist/js/node/index.js +212 -0
  32. package/dist/js/node/initWatcher.js +72 -0
  33. package/dist/js/node/loadEnv.js +28 -0
  34. package/dist/js/node/loadPlugins.js +76 -0
  35. package/dist/js/node/utils/commander.js +35 -0
  36. package/dist/js/node/utils/repeatKeyWarning.js +31 -0
  37. package/dist/types/config/defaults.d.ts +27 -0
  38. package/dist/types/config/index.d.ts +125 -0
  39. package/dist/types/config/mergeConfig.d.ts +29 -0
  40. package/dist/types/config/schema/deploy.d.ts +33 -0
  41. package/dist/types/config/schema/index.d.ts +474 -0
  42. package/dist/types/config/schema/output.d.ts +146 -0
  43. package/dist/types/config/schema/server.d.ts +179 -0
  44. package/dist/types/config/schema/source.d.ts +58 -0
  45. package/dist/types/config/schema/tools.d.ts +33 -0
  46. package/dist/types/context.d.ts +20 -0
  47. package/dist/types/index.d.ts +86 -0
  48. package/dist/types/initWatcher.d.ts +4 -0
  49. package/dist/types/loadEnv.d.ts +1 -0
  50. package/dist/types/loadPlugins.d.ts +16 -0
  51. package/dist/types/utils/commander.d.ts +7 -0
  52. package/dist/types/utils/repeatKeyWarning.d.ts +3 -0
  53. package/modern.config.js +13 -0
  54. package/package.json +73 -0
  55. package/src/config/defaults.ts +104 -0
  56. package/src/config/index.ts +296 -0
  57. package/src/config/mergeConfig.ts +68 -0
  58. package/src/config/schema/deploy.ts +23 -0
  59. package/src/config/schema/index.ts +111 -0
  60. package/src/config/schema/output.ts +66 -0
  61. package/src/config/schema/server.ts +105 -0
  62. package/src/config/schema/source.ts +34 -0
  63. package/src/config/schema/tools.ts +15 -0
  64. package/src/context.ts +46 -0
  65. package/src/index.ts +240 -0
  66. package/src/initWatcher.ts +81 -0
  67. package/src/loadEnv.ts +21 -0
  68. package/src/loadPlugins.ts +81 -0
  69. package/src/types.d.ts +0 -0
  70. package/src/utils/commander.ts +22 -0
  71. package/src/utils/repeatKeyWarning.ts +29 -0
  72. package/tests/fixtures/load-plugin/not-found/package.json +3 -0
  73. package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +1 -0
  74. package/tests/fixtures/load-plugin/user-plugins/package.json +3 -0
  75. package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +1 -0
  76. package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +3 -0
  77. package/tests/loadEnv.test.ts +100 -0
  78. package/tests/loadPlugin.test.ts +29 -0
  79. package/tests/mergeConfig.test.ts +78 -0
  80. package/tests/repeatKeyWarning.test.ts +68 -0
  81. package/tests/schema.test.ts +109 -0
  82. package/tests/tsconfig.json +13 -0
  83. package/tsconfig.json +14 -0
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.source = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ const source = {
11
+ type: 'object',
12
+ additionalProperties: false,
13
+ properties: {
14
+ entries: {
15
+ type: 'object',
16
+ patternProperties: {
17
+ [_utils.ENTRY_NAME_PATTERN]: {
18
+ if: {
19
+ type: 'object'
20
+ },
21
+ then: {
22
+ required: ['entry'],
23
+ properties: {
24
+ entry: {
25
+ type: ['string', 'array']
26
+ },
27
+ disableMount: {
28
+ type: 'boolean'
29
+ },
30
+ enableFileSystemRoutes: {
31
+ type: 'boolean'
32
+ }
33
+ },
34
+ additionalProperties: false
35
+ },
36
+ else: {
37
+ type: ['string', 'array']
38
+ }
39
+ }
40
+ }
41
+ },
42
+ alias: {
43
+ typeof: ['object', 'function']
44
+ },
45
+ disableDefaultEntries: {
46
+ type: 'boolean'
47
+ },
48
+ envVars: {
49
+ type: 'array'
50
+ },
51
+ globalVars: {
52
+ type: 'object'
53
+ },
54
+ moduleScopes: {
55
+ instanceof: ['Array', 'Function']
56
+ },
57
+ entriesDir: {
58
+ type: 'string'
59
+ },
60
+ configDir: {
61
+ type: 'string'
62
+ },
63
+ include: {
64
+ type: ['array']
65
+ }
66
+ }
67
+ };
68
+ exports.source = source;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.tools = void 0;
7
+ const tools = {
8
+ type: 'object',
9
+ additionalProperties: false,
10
+ properties: {
11
+ webpack: {
12
+ typeof: ['object', 'function']
13
+ },
14
+ babel: {
15
+ typeof: ['object', 'function']
16
+ },
17
+ postcss: {
18
+ typeof: ['object', 'function']
19
+ },
20
+ lodash: {
21
+ typeof: ['object', 'function']
22
+ },
23
+ devServer: {
24
+ type: 'object'
25
+ },
26
+ tsLoader: {
27
+ typeof: ['object', 'function']
28
+ },
29
+ autoprefixer: {
30
+ typeof: ['object', 'function']
31
+ },
32
+ terser: {
33
+ typeof: ['object', 'function']
34
+ },
35
+ minifyCss: {
36
+ typeof: ['object', 'function']
37
+ }
38
+ }
39
+ };
40
+ exports.tools = tools;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.initAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _plugin = require("@modern-js/plugin");
11
+
12
+ var _address = _interopRequireDefault(require("address"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const AppContext = (0, _plugin.createContext)({});
17
+ exports.AppContext = AppContext;
18
+ const ConfigContext = (0, _plugin.createContext)({});
19
+ exports.ConfigContext = ConfigContext;
20
+ const ResolvedConfigContext = (0, _plugin.createContext)({});
21
+ exports.ResolvedConfigContext = ResolvedConfigContext;
22
+
23
+ const useAppContext = () => AppContext.use();
24
+
25
+ exports.useAppContext = useAppContext;
26
+
27
+ const useConfigContext = () => ConfigContext.use();
28
+
29
+ exports.useConfigContext = useConfigContext;
30
+
31
+ const useResolvedConfigContext = () => ResolvedConfigContext.use();
32
+
33
+ exports.useResolvedConfigContext = useResolvedConfigContext;
34
+
35
+ const initAppContext = (appDirectory, plugins, configFile) => ({
36
+ appDirectory,
37
+ configFile,
38
+ ip: _address.default.ip(),
39
+ port: 0,
40
+ packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
41
+ srcDirectory: _path.default.resolve(appDirectory, './src'),
42
+ distDirectory: '',
43
+ sharedDirectory: _path.default.resolve(appDirectory, './shared'),
44
+ nodeModulesDirectory: _path.default.resolve(appDirectory, './node_modules'),
45
+ internalDirectory: _path.default.resolve(appDirectory, './node_modules/.modern-js'),
46
+ plugins,
47
+ htmlTemplates: {},
48
+ serverRoutes: [],
49
+ entrypoints: []
50
+ });
51
+
52
+ exports.initAppContext = initAppContext;
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "AppContext", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _context.AppContext;
10
+ }
11
+ });
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;
20
+ Object.defineProperty(exports, "defaultsConfig", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _config.defaultsConfig;
24
+ }
25
+ });
26
+ Object.defineProperty(exports, "defineConfig", {
27
+ enumerable: true,
28
+ get: function () {
29
+ return _config.defineConfig;
30
+ }
31
+ });
32
+ exports.registerHook = exports.mountHook = exports.manager = void 0;
33
+ Object.defineProperty(exports, "useAppContext", {
34
+ enumerable: true,
35
+ get: function () {
36
+ return _context.useAppContext;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "useConfigContext", {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _context.useConfigContext;
43
+ }
44
+ });
45
+ exports.usePlugins = void 0;
46
+ Object.defineProperty(exports, "useResolvedConfigContext", {
47
+ enumerable: true,
48
+ get: function () {
49
+ return _context.useResolvedConfigContext;
50
+ }
51
+ });
52
+
53
+ var _path = _interopRequireDefault(require("path"));
54
+
55
+ var _plugin = require("@modern-js/plugin");
56
+
57
+ var _node = require("@modern-js/plugin/node");
58
+
59
+ var _utils = require("@modern-js/utils");
60
+
61
+ var _commander = require("./utils/commander");
62
+
63
+ var _config = require("./config");
64
+
65
+ var _loadPlugins = require("./loadPlugins");
66
+
67
+ var _context = require("./context");
68
+
69
+ var _initWatcher = require("./initWatcher");
70
+
71
+ var _loadEnv = require("./loadEnv");
72
+
73
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
74
+
75
+ 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
+
77
+ 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; }
78
+
79
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
80
+
81
+ _commander.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
82
+
83
+ const hooksMap = {
84
+ config: (0, _plugin.createParallelWorkflow)(),
85
+ validateSchema: (0, _plugin.createParallelWorkflow)(),
86
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
87
+ prepare: (0, _plugin.createAsyncWorkflow)(),
88
+ commands: (0, _plugin.createAsyncWorkflow)(),
89
+ watchFiles: (0, _plugin.createParallelWorkflow)(),
90
+ fileChange: (0, _plugin.createAsyncWorkflow)(),
91
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
92
+ beforeExit: (0, _plugin.createAsyncWorkflow)()
93
+ };
94
+ const manager = (0, _plugin.createAsyncManager)(hooksMap);
95
+ exports.manager = manager;
96
+ const {
97
+ createPlugin,
98
+ registe: registerHook,
99
+ useRunner: mountHook
100
+ } = manager;
101
+ exports.mountHook = mountHook;
102
+ exports.registerHook = registerHook;
103
+ exports.createPlugin = createPlugin;
104
+
105
+ const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(require.resolve(plugin))));
106
+
107
+ exports.usePlugins = usePlugins;
108
+
109
+ const initAppDir = async () => {
110
+ const pkg = await (0, _utils.pkgUp)({
111
+ cwd: process.cwd()
112
+ });
113
+
114
+ if (!pkg) {
115
+ throw new Error(`no package.json found in current work dir: ${process.cwd()}`);
116
+ }
117
+
118
+ return _path.default.dirname(pkg);
119
+ };
120
+
121
+ const createCli = () => {
122
+ let hooksRunner;
123
+ let isRestart = false;
124
+
125
+ const init = async (argv = []) => {
126
+ manager.clear();
127
+ const appDirectory = await initAppDir();
128
+ (0, _loadEnv.loadEnv)(appDirectory);
129
+ const loaded = await (0, _config.loadUserConfig)(appDirectory);
130
+ const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || []);
131
+ plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
132
+ const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath);
133
+ manager.run(() => {
134
+ _context.ConfigContext.set(loaded.config);
135
+
136
+ _context.AppContext.set(appContext);
137
+ });
138
+ hooksRunner = await manager.init();
139
+ ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
140
+ process.on(event, async err => {
141
+ await hooksRunner.beforeExit();
142
+
143
+ if (err instanceof Error) {
144
+ _utils.logger.error(err.stack);
145
+ }
146
+
147
+ process.nextTick(() => {
148
+ // eslint-disable-next-line no-process-exit
149
+ process.exit(1);
150
+ });
151
+ });
152
+ });
153
+ const extraConfigs = await hooksRunner.config();
154
+ const extraSchemas = await hooksRunner.validateSchema();
155
+ const resolved = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, isRestart, argv); // update context value
156
+
157
+ manager.run(() => {
158
+ _context.ConfigContext.set(loaded.config);
159
+
160
+ _context.ResolvedConfigContext.set(resolved);
161
+
162
+ _context.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
163
+ port: resolved.server.port,
164
+ distDirectory: (0, _utils.ensureAbsolutePath)(appDirectory, resolved.output.path)
165
+ }));
166
+ });
167
+ await hooksRunner.prepare();
168
+ return {
169
+ loadedConfig: loaded,
170
+ appContext,
171
+ resolved
172
+ };
173
+ };
174
+
175
+ async function run(argv) {
176
+ (0, _node.enable)();
177
+ const {
178
+ loadedConfig,
179
+ appContext,
180
+ resolved
181
+ } = await init(argv);
182
+ (0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved, hooksRunner, argv);
183
+ await hooksRunner.commands({
184
+ program: _commander.program
185
+ });
186
+ manager.run(() => _commander.program.parse(process.argv));
187
+ }
188
+
189
+ async function restart() {
190
+ isRestart = true;
191
+
192
+ try {
193
+ _utils.logger.info('Restart...\n');
194
+
195
+ await init();
196
+ return true;
197
+ } catch (err) {
198
+ _utils.logger.error(err);
199
+ }
200
+
201
+ return false;
202
+ }
203
+
204
+ return {
205
+ init,
206
+ run,
207
+ restart
208
+ };
209
+ };
210
+
211
+ const cli = createCli();
212
+ exports.cli = cli;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initWatcher = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _crypto = _interopRequireDefault(require("crypto"));
11
+
12
+ var _fs = _interopRequireDefault(require("fs"));
13
+
14
+ var _chokidar = _interopRequireDefault(require("chokidar"));
15
+
16
+ var _utils = require("@modern-js/utils");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const debug = (0, _utils.createDebugger)('watch-files');
21
+
22
+ const md5 = data => _crypto.default.createHash('md5').update(data).digest('hex');
23
+
24
+ const hashMap = new Map();
25
+
26
+ const initWatcher = async (loaded, appDirectory, resovledConfig, hooksRunner, argv) => {
27
+ // only add fs watcher on dev mode.
28
+ if ((0, _utils.isDev)() && argv[0] === 'dev') {
29
+ const {
30
+ source: {
31
+ configDir
32
+ }
33
+ } = resovledConfig;
34
+ const extraFiles = await hooksRunner.watchFiles();
35
+
36
+ const configPath = _path.default.join(appDirectory, configDir);
37
+
38
+ const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
39
+ debug(`watched: %o`, watched);
40
+
41
+ const watcher = _chokidar.default.watch(watched, {
42
+ cwd: appDirectory,
43
+ ignorePermissionErrors: true,
44
+ ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
45
+ });
46
+
47
+ watcher.on('change', changed => {
48
+ const lastHash = hashMap.get(changed);
49
+ const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, changed), 'utf8'));
50
+
51
+ if (currentHash !== lastHash) {
52
+ debug(`file change: %s`, changed);
53
+ hashMap.set(changed, currentHash);
54
+ hooksRunner.fileChange({
55
+ filename: changed
56
+ });
57
+ }
58
+ });
59
+ watcher.on('unlink', name => {
60
+ debug(`remove file: %s`, name);
61
+
62
+ if (hashMap.has(name)) {
63
+ hashMap.delete(name);
64
+ }
65
+ });
66
+ watcher.on('error', err => {
67
+ throw err;
68
+ });
69
+ }
70
+ };
71
+
72
+ exports.initWatcher = initWatcher;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadEnv = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+
12
+ var _dotenv = _interopRequireDefault(require("dotenv"));
13
+
14
+ var _dotenvExpand = _interopRequireDefault(require("dotenv-expand"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
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 => {
20
+ const envConfig = _dotenv.default.config({
21
+ path: filePath
22
+ });
23
+
24
+ (0, _dotenvExpand.default)(envConfig);
25
+ });
26
+ };
27
+
28
+ exports.loadEnv = loadEnv;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadPlugins = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ const debug = (0, _utils.createDebugger)('load-plugins');
11
+
12
+ /**
13
+ * Try to resolve plugin entry file path.
14
+ * @param appDirectory - Application root directory.
15
+ * @param plugin - Plugin name or plugin name with options.
16
+ * @returns Resolved file path.
17
+ */
18
+ const resolvePlugin = (appDirectory, plugin) => {
19
+ const tryResolve = name => {
20
+ let filePath = '';
21
+
22
+ try {
23
+ filePath = require.resolve(name, {
24
+ paths: [appDirectory]
25
+ });
26
+ delete require.cache[filePath];
27
+ } catch (err) {
28
+ if (err.code === 'MODULE_NOT_FOUND') {
29
+ throw new Error(`Can not find plugin ${name}.`);
30
+ }
31
+
32
+ throw err;
33
+ }
34
+
35
+ return filePath;
36
+ };
37
+
38
+ const resolved = {};
39
+
40
+ if (plugin.cli) {
41
+ resolved.cli = tryResolve(plugin.cli);
42
+ }
43
+
44
+ if (plugin.server) {
45
+ resolved.server = tryResolve(plugin.server);
46
+ }
47
+
48
+ return resolved;
49
+ };
50
+ /**
51
+ * Load internal plugins which in @modern-js scope and user's custom plugins.
52
+ * @param appDirectory - Application root directory.
53
+ * @param pluginsConfig - Plugins declared in the user configuration.
54
+ * @returns Plugin Objects has been required.
55
+ */
56
+
57
+
58
+ const loadPlugins = (appDirectory, pluginConfig) => {
59
+ const plugins = [...Object.keys(_utils.INTERNAL_PLUGINS).filter(name => (0, _utils.isDepExists)(appDirectory, name)).map(name => _utils.INTERNAL_PLUGINS[name]), ...pluginConfig];
60
+ return plugins.map(plugin => {
61
+ const {
62
+ cli,
63
+ server
64
+ } = resolvePlugin(appDirectory, plugin);
65
+ debug(`resolve plugin %s: %s`, plugin, {
66
+ cli,
67
+ server
68
+ });
69
+ return {
70
+ cli: cli && (0, _utils.compatRequire)(cli),
71
+ server: server && (0, _utils.compatRequire)(server)
72
+ };
73
+ });
74
+ };
75
+
76
+ exports.loadPlugins = loadPlugins;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Command", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _commander.Command;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "program", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _commander.program;
16
+ }
17
+ });
18
+
19
+ var _commander = require("commander");
20
+
21
+ if (!_commander.program.hasOwnProperty('commandsMap')) {
22
+ Object.defineProperty(_commander.program, 'commandsMap', {
23
+ get() {
24
+ const map = new Map();
25
+
26
+ for (const command of _commander.program.commands) {
27
+ map.set(command._name, command);
28
+ }
29
+
30
+ return map;
31
+ },
32
+
33
+ configurable: false
34
+ });
35
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.repeatKeyWarning = exports.deepGet = void 0;
7
+
8
+ var _schema = require("../config/schema");
9
+
10
+ const deepGet = (obj, key) => {
11
+ for (const p of key.split('.')) {
12
+ // eslint-disable-next-line no-param-reassign
13
+ obj = obj ? obj[p] : undefined;
14
+ }
15
+
16
+ return obj;
17
+ };
18
+
19
+ exports.deepGet = deepGet;
20
+
21
+ const repeatKeyWarning = (schema, jsConfig, pkgConfig) => {
22
+ const keys = (0, _schema.traverseSchema)(schema);
23
+
24
+ for (const key of keys) {
25
+ if (deepGet(jsConfig, key) !== undefined && deepGet(pkgConfig, key) !== undefined) {
26
+ throw new Error(`The same configuration ${key} exists in modern.config.js and package.json.\n Please remove it from package.json.`);
27
+ }
28
+ }
29
+ };
30
+
31
+ exports.repeatKeyWarning = repeatKeyWarning;
@@ -0,0 +1,27 @@
1
+ import { OutputConfig, ServerConfig, SourceConfig } from '.';
2
+ export declare const defaults: {
3
+ source: SourceConfig;
4
+ output: OutputConfig;
5
+ server: ServerConfig;
6
+ dev: {
7
+ assetPrefix: boolean;
8
+ };
9
+ deploy: {
10
+ microFrontend: {
11
+ enableHtmlEntry: boolean;
12
+ };
13
+ domain: string;
14
+ domainByEntries: undefined;
15
+ };
16
+ tools: {
17
+ webpack: undefined;
18
+ babel: undefined;
19
+ postcss: undefined;
20
+ autoprefixer: undefined;
21
+ lodash: undefined;
22
+ devServer: undefined;
23
+ tsLoader: undefined;
24
+ terser: undefined;
25
+ minifyCss: undefined;
26
+ };
27
+ };