@modern-js/utils 1.1.0 → 1.1.4-rc.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +27 -66
- package/dist/js/modern/alias.js +10 -10
- package/dist/js/modern/compatRequire.js +11 -0
- package/dist/js/modern/constants.js +51 -3
- package/dist/js/modern/getEntryOptions.js +15 -6
- package/dist/js/modern/is/type.js +3 -0
- package/dist/js/modern/logger.js +2 -2
- package/dist/js/modern/monorepo.js +2 -2
- package/dist/js/modern/runtimeExports.js +5 -2
- package/dist/js/node/alias.js +10 -10
- package/dist/js/node/compatRequire.js +16 -2
- package/dist/js/node/constants.js +58 -6
- package/dist/js/node/getEntryOptions.js +16 -6
- package/dist/js/node/is/type.js +5 -0
- package/dist/js/node/logger.js +2 -2
- package/dist/js/node/monorepo.js +2 -2
- package/dist/js/node/runtimeExports.js +8 -2
- package/dist/js/treeshaking/alias.js +9 -9
- package/dist/js/treeshaking/compatRequire.js +14 -0
- package/dist/js/treeshaking/constants.js +51 -3
- package/dist/js/treeshaking/formatWebpackMessages.js +1 -1
- package/dist/js/treeshaking/getEntryOptions.js +16 -5
- package/dist/js/treeshaking/is/type.js +4 -1
- package/dist/js/treeshaking/logger.js +3 -3
- package/dist/js/treeshaking/monorepo.js +2 -2
- package/dist/js/treeshaking/runtimeExports.js +8 -2
- package/dist/types/compatRequire.d.ts +2 -1
- package/dist/types/constants.d.ts +22 -2
- package/dist/types/getEntryOptions.d.ts +1 -1
- package/dist/types/is/type.d.ts +2 -1
- package/dist/types/runtimeExports.d.ts +1 -1
- package/package.json +5 -4
- package/src/alias.ts +7 -7
- package/src/compatRequire.ts +15 -0
- package/src/constants.ts +39 -2
- package/src/getEntryOptions.ts +23 -4
- package/src/is/type.ts +4 -0
- package/src/runtimeExports.ts +12 -1
- package/tests/getEntryOptions.test.ts +11 -0
@@ -29,8 +29,10 @@ const memo = fn => {
|
|
29
29
|
};
|
30
30
|
};
|
31
31
|
|
32
|
-
const createRuntimeExportsUtils = memo((pwd, namespace) => {
|
33
|
-
const entryExportFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`);
|
32
|
+
const createRuntimeExportsUtils = memo((pwd = '', namespace, ts = false) => {
|
33
|
+
const entryExportFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`);
|
34
|
+
|
35
|
+
const entryExportTsFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`); // const ensure = () => {
|
34
36
|
// if (!fs.existsSync(entryExportFile)) {
|
35
37
|
// fs.outputFileSync(entryExportFile, '');
|
36
38
|
// }
|
@@ -45,8 +47,12 @@ const createRuntimeExportsUtils = memo((pwd, namespace) => {
|
|
45
47
|
try {
|
46
48
|
_fsExtra.default.ensureFileSync(entryExportFile);
|
47
49
|
|
50
|
+
_fsExtra.default.ensureFileSync(entryExportTsFile);
|
51
|
+
|
48
52
|
if (!_fsExtra.default.readFileSync(entryExportFile, 'utf8').includes(statement)) {
|
49
53
|
_fsExtra.default.appendFileSync(entryExportFile, `${statement}\n`);
|
54
|
+
|
55
|
+
ts && _fsExtra.default.appendFileSync(entryExportTsFile, `${statement.replace('.js', '.d')}\n`);
|
50
56
|
}
|
51
57
|
} catch (_unused) {// FIXME:
|
52
58
|
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
2
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
4
|
|
5
5
|
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; }
|
6
6
|
|
@@ -58,15 +58,15 @@ export var getAlias = function getAlias(aliasOption, option) {
|
|
58
58
|
}
|
59
59
|
|
60
60
|
return aliasConfig;
|
61
|
-
};
|
61
|
+
}; // filter invalid ts paths that are not array
|
62
|
+
|
62
63
|
export var getUserAlias = function getUserAlias() {
|
63
64
|
var alias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
o[k] = alias[k];
|
65
|
+
return Object.keys(alias).reduce(function (o, k) {
|
66
|
+
if (Array.isArray(alias[k])) {
|
67
|
+
o[k] = alias[k];
|
68
|
+
}
|
69
|
+
|
70
70
|
return o;
|
71
71
|
}, {});
|
72
72
|
};
|
@@ -1,10 +1,24 @@
|
|
1
|
+
import { findExists } from "./findExists";
|
1
2
|
/**
|
2
3
|
* Require function compatible with esm and cjs module.
|
3
4
|
* @param filePath - File to required.
|
4
5
|
* @returns module export object.
|
5
6
|
*/
|
7
|
+
|
6
8
|
export var compatRequire = function compatRequire(filePath) {
|
7
9
|
var mod = require(filePath);
|
8
10
|
|
9
11
|
return mod !== null && mod !== void 0 && mod.__esModule ? mod["default"] : mod;
|
12
|
+
};
|
13
|
+
export var requireExistModule = function requireExistModule(filename) {
|
14
|
+
var extensions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['.ts', '.js'];
|
15
|
+
var exist = findExists(extensions.map(function (ext) {
|
16
|
+
return "".concat(filename).concat(ext);
|
17
|
+
}));
|
18
|
+
|
19
|
+
if (!exist) {
|
20
|
+
return null;
|
21
|
+
}
|
22
|
+
|
23
|
+
return compatRequire(exist);
|
10
24
|
};
|
@@ -19,6 +19,11 @@ export var HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
|
19
19
|
*/
|
20
20
|
|
21
21
|
export var ROUTE_SPEC_FILE = 'route.json';
|
22
|
+
/**
|
23
|
+
* main entry name
|
24
|
+
*/
|
25
|
+
|
26
|
+
export var MAIN_ENTRY_NAME = 'main';
|
22
27
|
/**
|
23
28
|
* open editor request path
|
24
29
|
*/
|
@@ -44,7 +49,18 @@ export var SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
44
49
|
*/
|
45
50
|
|
46
51
|
export var LOADABLE_STATS_FILE = 'loadable-stats.json';
|
52
|
+
/**
|
53
|
+
* real entry generate by modern.js
|
54
|
+
*/
|
55
|
+
|
47
56
|
export var HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
57
|
+
/**
|
58
|
+
* internal specified folder
|
59
|
+
*/
|
60
|
+
|
61
|
+
export var API_DIR = 'api';
|
62
|
+
export var SERVER_DIR = 'server';
|
63
|
+
export var SHARED_DIR = 'shared';
|
48
64
|
/**
|
49
65
|
* Internal plugins that work as soon as they are installed.
|
50
66
|
*/
|
@@ -115,6 +131,10 @@ export var INTERNAL_PLUGINS = {
|
|
115
131
|
'@modern-js/plugin-server-build': {
|
116
132
|
cli: '@modern-js/plugin-server-build'
|
117
133
|
},
|
134
|
+
'@modern-js/plugin-server': {
|
135
|
+
cli: '@modern-js/plugin-server/cli',
|
136
|
+
server: '@modern-js/plugin-server/server'
|
137
|
+
},
|
118
138
|
'@modern-js/plugin-micro-frontend': {
|
119
139
|
cli: '@modern-js/plugin-micro-frontend/cli'
|
120
140
|
},
|
@@ -123,6 +143,30 @@ export var INTERNAL_PLUGINS = {
|
|
123
143
|
},
|
124
144
|
'@modern-js/plugin-tailwindcss': {
|
125
145
|
cli: '@modern-js/plugin-tailwindcss/cli'
|
146
|
+
},
|
147
|
+
'@modern-js/plugin-lambda-fc': {
|
148
|
+
cli: '@modern-js/plugin-lambda-fc/cli'
|
149
|
+
},
|
150
|
+
'@modern-js/plugin-lambda-scf': {
|
151
|
+
cli: '@modern-js/plugin-lambda-scf/cli'
|
152
|
+
},
|
153
|
+
'@modern-js/plugin-cdn-oss': {
|
154
|
+
cli: '@modern-js/plugin-cdn-oss/cli'
|
155
|
+
},
|
156
|
+
'@modern-js/plugin-cdn-cos': {
|
157
|
+
cli: '@modern-js/plugin-cdn-cos/cli'
|
158
|
+
},
|
159
|
+
'@modern-js/plugin-static-hosting': {
|
160
|
+
cli: '@modern-js/plugin-static-hosting/cli'
|
161
|
+
},
|
162
|
+
'@modern-js/plugin-polyfill': {
|
163
|
+
server: '@modern-js/plugin-polyfill'
|
164
|
+
},
|
165
|
+
'@modern-js/plugin-multiprocess': {
|
166
|
+
cli: '@modern-js/plugin-multiprocess/cli'
|
167
|
+
},
|
168
|
+
'@modern-js/plugin-nocode': {
|
169
|
+
cli: '@modern-js/plugin-nocode/cli'
|
126
170
|
}
|
127
171
|
};
|
128
172
|
/**
|
@@ -152,7 +196,10 @@ export var PLUGIN_SCHEMAS = {
|
|
152
196
|
type: 'object',
|
153
197
|
properties: {
|
154
198
|
prefix: {
|
155
|
-
type: 'string'
|
199
|
+
type: ['string', 'array'],
|
200
|
+
items: {
|
201
|
+
type: 'string'
|
202
|
+
}
|
156
203
|
},
|
157
204
|
fetcher: {
|
158
205
|
type: 'string'
|
@@ -160,7 +207,7 @@ export var PLUGIN_SCHEMAS = {
|
|
160
207
|
proxy: {
|
161
208
|
type: 'object'
|
162
209
|
},
|
163
|
-
|
210
|
+
requestCreator: {
|
164
211
|
type: 'string'
|
165
212
|
}
|
166
213
|
}
|
@@ -263,5 +310,6 @@ export var PLUGIN_SCHEMAS = {
|
|
263
310
|
schema: {
|
264
311
|
type: ['object']
|
265
312
|
}
|
266
|
-
}]
|
313
|
+
}],
|
314
|
+
'@modern-js/plugin-nocode': []
|
267
315
|
};
|
@@ -10,7 +10,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
10
10
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
12
12
|
|
13
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
13
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
14
14
|
|
15
15
|
/* eslint-disable no-param-reassign */
|
16
16
|
|
@@ -1,15 +1,26 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
2
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
4
|
|
5
5
|
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; }
|
6
6
|
|
7
7
|
import { isPlainObject } from "./is";
|
8
|
-
|
8
|
+
import { MAIN_ENTRY_NAME } from "./constants";
|
9
|
+
export var getEntryOptions = function getEntryOptions(name, baseOptions, optionsByEntries, packageName) {
|
9
10
|
if (optionsByEntries) {
|
10
|
-
//
|
11
|
-
|
11
|
+
var optionsByEntry = getOptionsByEntryName(name, optionsByEntries); // compatible with main entry using packageName as the key
|
12
|
+
|
13
|
+
if (optionsByEntry === undefined && name === MAIN_ENTRY_NAME && packageName) {
|
14
|
+
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
15
|
+
} // eslint-disable-next-line no-nested-ternary
|
16
|
+
|
17
|
+
|
18
|
+
return optionsByEntry !== undefined ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntry) : optionsByEntry : baseOptions;
|
12
19
|
} else {
|
13
20
|
return baseOptions;
|
14
21
|
}
|
22
|
+
};
|
23
|
+
|
24
|
+
var getOptionsByEntryName = function getOptionsByEntryName(name, optionsByEntries) {
|
25
|
+
return optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
|
15
26
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
2
|
|
3
3
|
export function isString(str) {
|
4
4
|
return typeof str === 'string';
|
@@ -24,4 +24,7 @@ export function isPromise(obj) {
|
|
24
24
|
/* eslint-disable promise/prefer-await-to-then */
|
25
25
|
return Boolean(obj) && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
26
26
|
/* eslint-enable promise/prefer-await-to-then */
|
27
|
+
}
|
28
|
+
export function isRegExp(obj) {
|
29
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
27
30
|
}
|
@@ -10,9 +10,9 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
|
|
10
10
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
12
12
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
14
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
16
16
|
|
17
17
|
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; }
|
18
18
|
|
@@ -20,7 +20,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
20
20
|
|
21
21
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
22
22
|
|
23
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
23
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
24
24
|
|
25
25
|
import chalk from 'chalk';
|
26
26
|
var grey = chalk.grey,
|
@@ -1,6 +1,6 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
2
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
4
|
|
5
5
|
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; }
|
6
6
|
|
@@ -22,8 +22,12 @@ var memo = function memo(fn) {
|
|
22
22
|
};
|
23
23
|
};
|
24
24
|
|
25
|
-
export var createRuntimeExportsUtils = memo(function (
|
26
|
-
var
|
25
|
+
export var createRuntimeExportsUtils = memo(function () {
|
26
|
+
var pwd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
27
|
+
var namespace = arguments.length > 1 ? arguments[1] : undefined;
|
28
|
+
var ts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
29
|
+
var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace ? "".concat(namespace, ".js") : 'index.js'));
|
30
|
+
var entryExportTsFile = path.join(pwd, ".runtime-exports/".concat(namespace ? "".concat(namespace, ".d.ts") : 'index.d.ts')); // const ensure = () => {
|
27
31
|
// if (!fs.existsSync(entryExportFile)) {
|
28
32
|
// fs.outputFileSync(entryExportFile, '');
|
29
33
|
// }
|
@@ -36,9 +40,11 @@ export var createRuntimeExportsUtils = memo(function (pwd, namespace) {
|
|
36
40
|
|
37
41
|
try {
|
38
42
|
fs.ensureFileSync(entryExportFile);
|
43
|
+
fs.ensureFileSync(entryExportTsFile);
|
39
44
|
|
40
45
|
if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
|
41
46
|
fs.appendFileSync(entryExportFile, "".concat(statement, "\n"));
|
47
|
+
ts && fs.appendFileSync(entryExportTsFile, "".concat(statement.replace('.js', '.d'), "\n"));
|
42
48
|
}
|
43
49
|
} catch (_unused) {// FIXME:
|
44
50
|
}
|
@@ -3,4 +3,5 @@
|
|
3
3
|
* @param filePath - File to required.
|
4
4
|
* @returns module export object.
|
5
5
|
*/
|
6
|
-
export declare const compatRequire: (filePath: string) => any;
|
6
|
+
export declare const compatRequire: (filePath: string) => any;
|
7
|
+
export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
|
@@ -17,6 +17,11 @@ export declare const HMR_SOCK_PATH = "/_modern_js_hmr_ws";
|
|
17
17
|
*/
|
18
18
|
|
19
19
|
export declare const ROUTE_SPEC_FILE = "route.json";
|
20
|
+
/**
|
21
|
+
* main entry name
|
22
|
+
*/
|
23
|
+
|
24
|
+
export declare const MAIN_ENTRY_NAME = "main";
|
20
25
|
/**
|
21
26
|
* open editor request path
|
22
27
|
*/
|
@@ -42,7 +47,18 @@ export declare const SERVER_RENDER_FUNCTION_NAME = "serverRender";
|
|
42
47
|
*/
|
43
48
|
|
44
49
|
export declare const LOADABLE_STATS_FILE = "loadable-stats.json";
|
50
|
+
/**
|
51
|
+
* real entry generate by modern.js
|
52
|
+
*/
|
53
|
+
|
45
54
|
export declare const HIDE_MODERN_JS_DIR = "./node_modules/.modern-js";
|
55
|
+
/**
|
56
|
+
* internal specified folder
|
57
|
+
*/
|
58
|
+
|
59
|
+
export declare const API_DIR = "api";
|
60
|
+
export declare const SERVER_DIR = "server";
|
61
|
+
export declare const SHARED_DIR = "shared";
|
46
62
|
/**
|
47
63
|
* Internal plugins that work as soon as they are installed.
|
48
64
|
*/
|
@@ -83,7 +99,10 @@ export declare const PLUGIN_SCHEMAS: {
|
|
83
99
|
type: string;
|
84
100
|
properties: {
|
85
101
|
prefix: {
|
86
|
-
type: string;
|
102
|
+
type: string[];
|
103
|
+
items: {
|
104
|
+
type: string;
|
105
|
+
};
|
87
106
|
};
|
88
107
|
fetcher: {
|
89
108
|
type: string;
|
@@ -91,7 +110,7 @@ export declare const PLUGIN_SCHEMAS: {
|
|
91
110
|
proxy: {
|
92
111
|
type: string;
|
93
112
|
};
|
94
|
-
|
113
|
+
requestCreator: {
|
95
114
|
type: string;
|
96
115
|
};
|
97
116
|
};
|
@@ -175,4 +194,5 @@ export declare const PLUGIN_SCHEMAS: {
|
|
175
194
|
type: string[];
|
176
195
|
};
|
177
196
|
}[];
|
197
|
+
'@modern-js/plugin-nocode': never[];
|
178
198
|
};
|
@@ -1 +1 @@
|
|
1
|
-
export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined) => T | undefined;
|
1
|
+
export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined, packageName?: string | undefined) => T | undefined;
|
package/dist/types/is/type.d.ts
CHANGED
@@ -4,4 +4,5 @@ export declare function isArray(obj: any): obj is any[];
|
|
4
4
|
export declare function isFunction(func: any): func is Function;
|
5
5
|
export declare function isObject(obj: any): obj is object;
|
6
6
|
export declare function isPlainObject(obj: any): obj is Record<string, any>;
|
7
|
-
export declare function isPromise(obj: any): obj is Promise<any>;
|
7
|
+
export declare function isPromise(obj: any): obj is Promise<any>;
|
8
|
+
export declare function isRegExp(obj: any): obj is RegExp;
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.1.0",
|
14
|
+
"version": "1.1.4-rc.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -65,8 +65,8 @@
|
|
65
65
|
"@types/recursive-readdir": "^2.2.0",
|
66
66
|
"typescript": "^4",
|
67
67
|
"webpack": "^5.54.0",
|
68
|
-
"@modern-js/plugin-testing": "^1.
|
69
|
-
"@modern-js/module-tools": "^1.
|
68
|
+
"@modern-js/plugin-testing": "^1.1.1",
|
69
|
+
"@modern-js/module-tools": "^1.1.1"
|
70
70
|
},
|
71
71
|
"peerDependencies": {
|
72
72
|
"typescript": "^4.4.3"
|
@@ -80,5 +80,6 @@
|
|
80
80
|
"new": "modern new",
|
81
81
|
"build": "modern build",
|
82
82
|
"test": "modern test --passWithNoTests"
|
83
|
-
}
|
83
|
+
},
|
84
|
+
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
84
85
|
}
|
package/src/alias.ts
CHANGED
@@ -80,11 +80,11 @@ export const getAlias = (
|
|
80
80
|
return aliasConfig;
|
81
81
|
};
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
// filter invalid ts paths that are not array
|
84
|
+
export const getUserAlias = (alias: Record<string, string | string[]> = {}) =>
|
85
|
+
Object.keys(alias).reduce((o, k) => {
|
86
|
+
if (Array.isArray(alias[k])) {
|
87
|
+
o[k] = alias[k];
|
88
|
+
}
|
88
89
|
return o;
|
89
|
-
}, {});
|
90
|
-
};
|
90
|
+
}, {} as Record<string, string | string[]>);
|
package/src/compatRequire.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { findExists } from './findExists';
|
2
|
+
|
1
3
|
/**
|
2
4
|
* Require function compatible with esm and cjs module.
|
3
5
|
* @param filePath - File to required.
|
@@ -8,3 +10,16 @@ export const compatRequire = (filePath: string) => {
|
|
8
10
|
|
9
11
|
return mod?.__esModule ? mod.default : mod;
|
10
12
|
};
|
13
|
+
|
14
|
+
export const requireExistModule = (
|
15
|
+
filename: string,
|
16
|
+
extensions = ['.ts', '.js'],
|
17
|
+
) => {
|
18
|
+
const exist = findExists(extensions.map(ext => `${filename}${ext}`));
|
19
|
+
|
20
|
+
if (!exist) {
|
21
|
+
return null;
|
22
|
+
}
|
23
|
+
|
24
|
+
return compatRequire(exist);
|
25
|
+
};
|
package/src/constants.ts
CHANGED
@@ -18,6 +18,11 @@ export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
|
18
18
|
*/
|
19
19
|
export const ROUTE_SPEC_FILE = 'route.json';
|
20
20
|
|
21
|
+
/**
|
22
|
+
* main entry name
|
23
|
+
*/
|
24
|
+
export const MAIN_ENTRY_NAME = 'main';
|
25
|
+
|
21
26
|
/**
|
22
27
|
* open editor request path
|
23
28
|
*/
|
@@ -43,8 +48,20 @@ export const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
43
48
|
*/
|
44
49
|
export const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
45
50
|
|
51
|
+
/**
|
52
|
+
* real entry generate by modern.js
|
53
|
+
*/
|
46
54
|
export const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
47
55
|
|
56
|
+
/**
|
57
|
+
* internal specified folder
|
58
|
+
*/
|
59
|
+
export const API_DIR = 'api';
|
60
|
+
|
61
|
+
export const SERVER_DIR = 'server';
|
62
|
+
|
63
|
+
export const SHARED_DIR = 'shared';
|
64
|
+
|
48
65
|
/**
|
49
66
|
* Internal plugins that work as soon as they are installed.
|
50
67
|
*/
|
@@ -86,11 +103,27 @@ export const INTERNAL_PLUGINS: {
|
|
86
103
|
},
|
87
104
|
'@modern-js/plugin-unbundle': { cli: '@modern-js/plugin-unbundle' },
|
88
105
|
'@modern-js/plugin-server-build': { cli: '@modern-js/plugin-server-build' },
|
106
|
+
'@modern-js/plugin-server': {
|
107
|
+
cli: '@modern-js/plugin-server/cli',
|
108
|
+
server: '@modern-js/plugin-server/server',
|
109
|
+
},
|
89
110
|
'@modern-js/plugin-micro-frontend': {
|
90
111
|
cli: '@modern-js/plugin-micro-frontend/cli',
|
91
112
|
},
|
92
113
|
'@modern-js/plugin-jarvis': { cli: '@modern-js/plugin-jarvis/cli' },
|
93
114
|
'@modern-js/plugin-tailwindcss': { cli: '@modern-js/plugin-tailwindcss/cli' },
|
115
|
+
'@modern-js/plugin-lambda-fc': { cli: '@modern-js/plugin-lambda-fc/cli' },
|
116
|
+
'@modern-js/plugin-lambda-scf': { cli: '@modern-js/plugin-lambda-scf/cli' },
|
117
|
+
'@modern-js/plugin-cdn-oss': { cli: '@modern-js/plugin-cdn-oss/cli' },
|
118
|
+
'@modern-js/plugin-cdn-cos': { cli: '@modern-js/plugin-cdn-cos/cli' },
|
119
|
+
'@modern-js/plugin-static-hosting': {
|
120
|
+
cli: '@modern-js/plugin-static-hosting/cli',
|
121
|
+
},
|
122
|
+
'@modern-js/plugin-polyfill': { server: '@modern-js/plugin-polyfill' },
|
123
|
+
'@modern-js/plugin-multiprocess': {
|
124
|
+
cli: '@modern-js/plugin-multiprocess/cli',
|
125
|
+
},
|
126
|
+
'@modern-js/plugin-nocode': { cli: '@modern-js/plugin-nocode/cli' },
|
94
127
|
};
|
95
128
|
|
96
129
|
/**
|
@@ -120,10 +153,13 @@ export const PLUGIN_SCHEMAS = {
|
|
120
153
|
schema: {
|
121
154
|
type: 'object',
|
122
155
|
properties: {
|
123
|
-
prefix: {
|
156
|
+
prefix: {
|
157
|
+
type: ['string', 'array'],
|
158
|
+
items: { type: 'string' },
|
159
|
+
},
|
124
160
|
fetcher: { type: 'string' },
|
125
161
|
proxy: { type: 'object' },
|
126
|
-
|
162
|
+
requestCreator: { type: 'string' },
|
127
163
|
},
|
128
164
|
},
|
129
165
|
},
|
@@ -222,4 +258,5 @@ export const PLUGIN_SCHEMAS = {
|
|
222
258
|
schema: { type: ['object'] },
|
223
259
|
},
|
224
260
|
],
|
261
|
+
'@modern-js/plugin-nocode': [],
|
225
262
|
};
|
package/src/getEntryOptions.ts
CHANGED
@@ -1,18 +1,37 @@
|
|
1
1
|
import { isPlainObject } from './is';
|
2
|
+
import { MAIN_ENTRY_NAME } from './constants';
|
2
3
|
|
3
4
|
export const getEntryOptions = <T>(
|
4
5
|
name: string,
|
5
6
|
baseOptions?: T,
|
6
7
|
optionsByEntries?: Record<string, T>,
|
8
|
+
packageName?: string,
|
7
9
|
) => {
|
8
10
|
if (optionsByEntries) {
|
11
|
+
let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
|
12
|
+
|
13
|
+
// compatible with main entry using packageName as the key
|
14
|
+
if (
|
15
|
+
optionsByEntry === undefined &&
|
16
|
+
name === MAIN_ENTRY_NAME &&
|
17
|
+
packageName
|
18
|
+
) {
|
19
|
+
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
20
|
+
}
|
21
|
+
|
9
22
|
// eslint-disable-next-line no-nested-ternary
|
10
|
-
return
|
11
|
-
? isPlainObject(
|
12
|
-
? { ...baseOptions, ...
|
13
|
-
:
|
23
|
+
return optionsByEntry !== undefined
|
24
|
+
? isPlainObject(optionsByEntry) && isPlainObject(baseOptions)
|
25
|
+
? { ...baseOptions, ...optionsByEntry }
|
26
|
+
: optionsByEntry
|
14
27
|
: baseOptions;
|
15
28
|
} else {
|
16
29
|
return baseOptions;
|
17
30
|
}
|
18
31
|
};
|
32
|
+
|
33
|
+
const getOptionsByEntryName = <T>(
|
34
|
+
name: string,
|
35
|
+
optionsByEntries: Record<string, T>,
|
36
|
+
) =>
|
37
|
+
optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
|
package/src/is/type.ts
CHANGED
package/src/runtimeExports.ts
CHANGED
@@ -21,11 +21,15 @@ const memo = <T extends (...args: any[]) => any>(fn: T) => {
|
|
21
21
|
};
|
22
22
|
|
23
23
|
export const createRuntimeExportsUtils = memo(
|
24
|
-
(pwd
|
24
|
+
(pwd = '', namespace: string, ts = false) => {
|
25
25
|
const entryExportFile = path.join(
|
26
26
|
pwd,
|
27
27
|
`.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`,
|
28
28
|
);
|
29
|
+
const entryExportTsFile = path.join(
|
30
|
+
pwd,
|
31
|
+
`.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`,
|
32
|
+
);
|
29
33
|
|
30
34
|
// const ensure = () => {
|
31
35
|
// if (!fs.existsSync(entryExportFile)) {
|
@@ -39,8 +43,15 @@ export const createRuntimeExportsUtils = memo(
|
|
39
43
|
statement = normalizeOutputPath(statement);
|
40
44
|
try {
|
41
45
|
fs.ensureFileSync(entryExportFile);
|
46
|
+
fs.ensureFileSync(entryExportTsFile);
|
47
|
+
|
42
48
|
if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
|
43
49
|
fs.appendFileSync(entryExportFile, `${statement}\n`);
|
50
|
+
ts &&
|
51
|
+
fs.appendFileSync(
|
52
|
+
entryExportTsFile,
|
53
|
+
`${statement.replace('.js', '.d')}\n`,
|
54
|
+
);
|
44
55
|
}
|
45
56
|
} catch {
|
46
57
|
// FIXME:
|