@modern-js/core 0.0.0-windows-20211056953 → 0.0.1-20221226

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 (130) hide show
  1. package/CHANGELOG.md +1164 -6
  2. package/dist/bin.d.ts +2 -0
  3. package/dist/bin.js +5 -0
  4. package/dist/config/createDefaultConfig.d.ts +2 -0
  5. package/dist/config/createDefaultConfig.js +9 -0
  6. package/dist/config/createLoadedConfig.d.ts +6 -0
  7. package/dist/config/createLoadedConfig.js +35 -0
  8. package/dist/config/createResolvedConfig.d.ts +3 -0
  9. package/dist/config/createResolvedConfig.js +92 -0
  10. package/dist/config/index.d.ts +3 -0
  11. package/dist/config/index.js +19 -0
  12. package/dist/context.d.ts +35 -0
  13. package/dist/context.js +61 -0
  14. package/dist/index.d.ts +73 -0
  15. package/dist/index.js +150 -0
  16. package/dist/load-configs/index.d.ts +34 -0
  17. package/dist/load-configs/index.js +124 -0
  18. package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
  19. package/dist/loadEnv.js +21 -0
  20. package/dist/loadPlugins.d.ts +18 -0
  21. package/dist/loadPlugins.js +65 -0
  22. package/dist/manager.d.ts +87 -0
  23. package/dist/manager.js +24 -0
  24. package/dist/runBin.d.ts +5 -0
  25. package/dist/runBin.js +51 -0
  26. package/dist/schema/patchSchema.d.ts +19 -0
  27. package/dist/schema/patchSchema.js +57 -0
  28. package/dist/schema/source.d.ts +9 -0
  29. package/dist/schema/source.js +10 -0
  30. package/dist/schema/testing.d.ts +13 -0
  31. package/dist/schema/testing.js +11 -0
  32. package/dist/schema/traverseSchema.d.ts +2 -0
  33. package/dist/schema/traverseSchema.js +20 -0
  34. package/dist/types/config/index.d.ts +49 -125
  35. package/dist/types/config/index.js +2 -0
  36. package/dist/types/config/testing.d.ts +15 -0
  37. package/dist/types/config/testing.js +2 -0
  38. package/dist/types/context.d.ts +28 -14
  39. package/dist/types/context.js +2 -0
  40. package/dist/types/hooks.d.ts +44 -0
  41. package/dist/types/hooks.js +2 -0
  42. package/dist/types/index.d.ts +9 -87
  43. package/dist/types/index.js +21 -0
  44. package/dist/types/plugin.d.ts +26 -0
  45. package/dist/types/plugin.js +2 -0
  46. package/dist/types/pluginAPI.d.ts +18 -0
  47. package/dist/types/pluginAPI.js +2 -0
  48. package/dist/utils/commander.d.ts +4 -0
  49. package/dist/utils/commander.js +20 -0
  50. package/dist/utils/mergeConfig.d.ts +2 -0
  51. package/dist/utils/mergeConfig.js +32 -0
  52. package/dist/utils/repeatKeyWarning.d.ts +3 -0
  53. package/dist/utils/repeatKeyWarning.js +22 -0
  54. package/package.json +52 -48
  55. package/bin/modern-js.js +0 -18
  56. package/dist/js/modern/config/defaults.js +0 -100
  57. package/dist/js/modern/config/index.js +0 -104
  58. package/dist/js/modern/config/mergeConfig.js +0 -20
  59. package/dist/js/modern/config/schema/deploy.js +0 -20
  60. package/dist/js/modern/config/schema/index.js +0 -107
  61. package/dist/js/modern/config/schema/output.js +0 -147
  62. package/dist/js/modern/config/schema/server.js +0 -170
  63. package/dist/js/modern/config/schema/source.js +0 -59
  64. package/dist/js/modern/config/schema/tools.js +0 -33
  65. package/dist/js/modern/context.js +0 -25
  66. package/dist/js/modern/index.js +0 -142
  67. package/dist/js/modern/initWatcher.js +0 -46
  68. package/dist/js/modern/loadEnv.js +0 -12
  69. package/dist/js/modern/loadPlugins.js +0 -66
  70. package/dist/js/modern/utils/commander.js +0 -19
  71. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  72. package/dist/js/node/config/defaults.js +0 -107
  73. package/dist/js/node/config/index.js +0 -142
  74. package/dist/js/node/config/mergeConfig.js +0 -32
  75. package/dist/js/node/config/schema/deploy.js +0 -29
  76. package/dist/js/node/config/schema/index.js +0 -129
  77. package/dist/js/node/config/schema/output.js +0 -156
  78. package/dist/js/node/config/schema/server.js +0 -179
  79. package/dist/js/node/config/schema/source.js +0 -68
  80. package/dist/js/node/config/schema/tools.js +0 -40
  81. package/dist/js/node/context.js +0 -52
  82. package/dist/js/node/index.js +0 -247
  83. package/dist/js/node/initWatcher.js +0 -67
  84. package/dist/js/node/loadEnv.js +0 -28
  85. package/dist/js/node/loadPlugins.js +0 -76
  86. package/dist/js/node/utils/commander.js +0 -35
  87. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  88. package/dist/types/config/defaults.d.ts +0 -25
  89. package/dist/types/config/mergeConfig.d.ts +0 -29
  90. package/dist/types/config/schema/deploy.d.ts +0 -19
  91. package/dist/types/config/schema/index.d.ts +0 -466
  92. package/dist/types/config/schema/output.d.ts +0 -146
  93. package/dist/types/config/schema/server.d.ts +0 -182
  94. package/dist/types/config/schema/source.d.ts +0 -58
  95. package/dist/types/config/schema/tools.d.ts +0 -33
  96. package/dist/types/initWatcher.d.ts +0 -3
  97. package/dist/types/loadPlugins.d.ts +0 -16
  98. package/dist/types/utils/commander.d.ts +0 -7
  99. package/dist/types/utils/repeatKeyWarning.d.ts +0 -3
  100. package/modern.config.js +0 -13
  101. package/src/config/defaults.ts +0 -101
  102. package/src/config/index.ts +0 -296
  103. package/src/config/mergeConfig.ts +0 -68
  104. package/src/config/schema/deploy.ts +0 -17
  105. package/src/config/schema/index.ts +0 -116
  106. package/src/config/schema/output.ts +0 -66
  107. package/src/config/schema/server.ts +0 -106
  108. package/src/config/schema/source.ts +0 -34
  109. package/src/config/schema/tools.ts +0 -15
  110. package/src/context.ts +0 -46
  111. package/src/index.ts +0 -247
  112. package/src/initWatcher.ts +0 -77
  113. package/src/loadEnv.ts +0 -21
  114. package/src/loadPlugins.ts +0 -81
  115. package/src/types.d.ts +0 -0
  116. package/src/utils/commander.ts +0 -22
  117. package/src/utils/repeatKeyWarning.ts +0 -29
  118. package/tests/.eslintrc.js +0 -6
  119. package/tests/fixtures/load-plugin/not-found/package.json +0 -3
  120. package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
  121. package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
  122. package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
  123. package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
  124. package/tests/loadEnv.test.ts +0 -100
  125. package/tests/loadPlugin.test.ts +0 -29
  126. package/tests/mergeConfig.test.ts +0 -78
  127. package/tests/repeatKeyWarning.test.ts +0 -68
  128. package/tests/schema.test.ts +0 -109
  129. package/tests/tsconfig.json +0 -13
  130. package/tsconfig.json +0 -14
@@ -1,68 +0,0 @@
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;
@@ -1,40 +0,0 @@
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;
@@ -1,52 +0,0 @@
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().value;
24
-
25
- exports.useAppContext = useAppContext;
26
-
27
- const useConfigContext = () => ConfigContext.use().value;
28
-
29
- exports.useConfigContext = useConfigContext;
30
-
31
- const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
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;
@@ -1,247 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- };
20
- Object.defineProperty(exports, "AppContext", {
21
- enumerable: true,
22
- get: function () {
23
- return _context.AppContext;
24
- }
25
- });
26
- exports.createPlugin = exports.cli = void 0;
27
- Object.defineProperty(exports, "defaultsConfig", {
28
- enumerable: true,
29
- get: function () {
30
- return _config.defaultsConfig;
31
- }
32
- });
33
- Object.defineProperty(exports, "defineConfig", {
34
- enumerable: true,
35
- get: function () {
36
- return _config.defineConfig;
37
- }
38
- });
39
- exports.registerHook = exports.mountHook = exports.manager = void 0;
40
- Object.defineProperty(exports, "useAppContext", {
41
- enumerable: true,
42
- get: function () {
43
- return _context.useAppContext;
44
- }
45
- });
46
- Object.defineProperty(exports, "useConfigContext", {
47
- enumerable: true,
48
- get: function () {
49
- return _context.useConfigContext;
50
- }
51
- });
52
- exports.usePlugins = void 0;
53
- Object.defineProperty(exports, "useResolvedConfigContext", {
54
- enumerable: true,
55
- get: function () {
56
- return _context.useResolvedConfigContext;
57
- }
58
- });
59
-
60
- var _path = _interopRequireDefault(require("path"));
61
-
62
- var _utils = require("@modern-js/utils");
63
-
64
- var _plugin = require("@modern-js/plugin");
65
-
66
- Object.keys(_plugin).forEach(function (key) {
67
- if (key === "default" || key === "__esModule") return;
68
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
69
- if (key in exports && exports[key] === _plugin[key]) return;
70
- Object.defineProperty(exports, key, {
71
- enumerable: true,
72
- get: function () {
73
- return _plugin[key];
74
- }
75
- });
76
- });
77
-
78
- var _node = require("@modern-js/plugin/node");
79
-
80
- Object.keys(_node).forEach(function (key) {
81
- if (key === "default" || key === "__esModule") return;
82
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
83
- if (key in exports && exports[key] === _node[key]) return;
84
- Object.defineProperty(exports, key, {
85
- enumerable: true,
86
- get: function () {
87
- return _node[key];
88
- }
89
- });
90
- });
91
-
92
- var _commander = require("./utils/commander");
93
-
94
- var _config = require("./config");
95
-
96
- var _loadPlugins = require("./loadPlugins");
97
-
98
- var _context = require("./context");
99
-
100
- var _initWatcher = require("./initWatcher");
101
-
102
- var _loadEnv = require("./loadEnv");
103
-
104
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
105
-
106
- 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; }
107
-
108
- 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; }
109
-
110
- 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; }
111
-
112
- _commander.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
113
-
114
- const hooksMap = {
115
- config: (0, _plugin.createParallelWorkflow)(),
116
- validateSchema: (0, _plugin.createParallelWorkflow)(),
117
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
118
- prepare: (0, _plugin.createAsyncWorkflow)(),
119
- commands: (0, _plugin.createAsyncWorkflow)(),
120
- watchFiles: (0, _plugin.createParallelWorkflow)(),
121
- fileChange: (0, _plugin.createAsyncWorkflow)(),
122
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
123
- beforeExit: (0, _plugin.createAsyncWorkflow)()
124
- };
125
- const manager = (0, _plugin.createAsyncManager)(hooksMap);
126
- exports.manager = manager;
127
- const {
128
- createPlugin,
129
- registe: registerHook,
130
- useRunner: mountHook
131
- } = manager;
132
- exports.mountHook = mountHook;
133
- exports.registerHook = registerHook;
134
- exports.createPlugin = createPlugin;
135
-
136
- const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(require.resolve(plugin))));
137
-
138
- exports.usePlugins = usePlugins;
139
-
140
- const initAppDir = async () => {
141
- const pkg = await (0, _utils.pkgUp)({
142
- cwd: process.cwd()
143
- });
144
-
145
- if (!pkg) {
146
- throw new Error(`no package.json found in current work dir: ${process.cwd()}`);
147
- }
148
-
149
- return _path.default.dirname(pkg);
150
- };
151
-
152
- const createCli = () => {
153
- let hooksRunner;
154
- let isRestart = false;
155
-
156
- const init = async (argv = []) => {
157
- (0, _node.enable)();
158
- manager.clear();
159
- const appDirectory = await initAppDir();
160
- (0, _loadEnv.loadEnv)(appDirectory);
161
- const loaded = await (0, _config.loadUserConfig)(appDirectory);
162
- const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || []);
163
- plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
164
- const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath);
165
- manager.run(() => {
166
- _context.ConfigContext.set(loaded.config);
167
-
168
- _context.AppContext.set(appContext);
169
- });
170
- hooksRunner = await manager.init();
171
- ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
172
- process.on(event, async err => {
173
- await hooksRunner.beforeExit();
174
-
175
- if (err instanceof Error) {
176
- _utils.logger.error(err.stack);
177
- }
178
-
179
- process.nextTick(() => {
180
- // eslint-disable-next-line no-process-exit
181
- process.exit(1);
182
- });
183
- });
184
- });
185
- const extraConfigs = await hooksRunner.config();
186
- const extraSchemas = await hooksRunner.validateSchema();
187
- const resolved = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, isRestart, argv); // update context value
188
-
189
- manager.run(() => {
190
- _context.ConfigContext.set(loaded.config);
191
-
192
- _context.ResolvedConfigContext.set(resolved);
193
-
194
- _context.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
195
- port: resolved.server.port,
196
- distDirectory: (0, _utils.ensureAbsolutePath)(appDirectory, resolved.output.path)
197
- }));
198
- });
199
- await hooksRunner.prepare();
200
- return {
201
- loadedConfig: loaded,
202
- appContext,
203
- resolved
204
- };
205
- };
206
-
207
- async function run(argv) {
208
- const {
209
- loadedConfig,
210
- appContext,
211
- resolved
212
- } = await init(argv);
213
- await hooksRunner.commands({
214
- program: _commander.program
215
- });
216
- (0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
217
- manager.run(() => _commander.program.parse(process.argv));
218
- }
219
-
220
- async function restart() {
221
- isRestart = true;
222
-
223
- _utils.logger.info('Restart...\n');
224
-
225
- let hasGetError = false;
226
-
227
- try {
228
- await init(process.argv.slice(2));
229
- } catch (err) {
230
- console.error(err);
231
- hasGetError = true;
232
- } finally {
233
- if (!hasGetError) {
234
- manager.run(() => _commander.program.parse(process.argv));
235
- }
236
- }
237
- }
238
-
239
- return {
240
- init,
241
- run,
242
- restart
243
- };
244
- };
245
-
246
- const cli = createCli();
247
- exports.cli = cli;
@@ -1,67 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initWatcher = void 0;
7
-
8
- var _crypto = _interopRequireDefault(require("crypto"));
9
-
10
- var _fs = _interopRequireDefault(require("fs"));
11
-
12
- var _path = _interopRequireDefault(require("path"));
13
-
14
- var _utils = require("@modern-js/utils");
15
-
16
- var _chokidar = _interopRequireDefault(require("chokidar"));
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, configDir, hooksRunner, argv) => {
27
- // only add fs watcher on dev mode.
28
- if ((0, _utils.isDev)() && argv[0] === 'dev') {
29
- const extraFiles = await hooksRunner.watchFiles();
30
-
31
- const configPath = _path.default.join(appDirectory, configDir);
32
-
33
- const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
34
- debug(`watched: %o`, watched);
35
-
36
- const watcher = _chokidar.default.watch(watched, {
37
- cwd: appDirectory,
38
- ignorePermissionErrors: true,
39
- ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
40
- });
41
-
42
- watcher.on('change', changed => {
43
- const lastHash = hashMap.get(changed);
44
- const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, changed), 'utf8'));
45
-
46
- if (currentHash !== lastHash) {
47
- debug(`file change: %s`, changed);
48
- hashMap.set(changed, currentHash);
49
- hooksRunner.fileChange({
50
- filename: changed
51
- });
52
- }
53
- });
54
- watcher.on('unlink', name => {
55
- debug(`remove file: %s`, name);
56
-
57
- if (hashMap.has(name)) {
58
- hashMap.delete(name);
59
- }
60
- });
61
- watcher.on('error', err => {
62
- throw err;
63
- });
64
- }
65
- };
66
-
67
- exports.initWatcher = initWatcher;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.loadEnv = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
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;
@@ -1,76 +0,0 @@
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;
@@ -1,35 +0,0 @@
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
- }
@@ -1,31 +0,0 @@
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;
@@ -1,25 +0,0 @@
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
- https: boolean;
9
- };
10
- deploy: {
11
- domain: string;
12
- domainByEntries: undefined;
13
- };
14
- tools: {
15
- webpack: undefined;
16
- babel: undefined;
17
- postcss: undefined;
18
- autoprefixer: undefined;
19
- lodash: undefined;
20
- devServer: undefined;
21
- tsLoader: undefined;
22
- terser: undefined;
23
- minifyCss: undefined;
24
- };
25
- };