@modern-js/utils 1.0.0 → 1.1.2
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.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -4
- package/dist/js/modern/FileSizeReporter.js +2 -2
- package/dist/js/modern/alias.js +1 -1
- package/dist/js/modern/applyOptionsChain.js +2 -1
- package/dist/js/modern/constants.js +25 -0
- package/dist/js/modern/ensureAbsolutePath.js +1 -1
- package/dist/js/modern/getEntryOptions.js +13 -4
- package/dist/js/modern/getPackageManager.js +1 -1
- package/dist/js/modern/index.js +1 -5
- package/dist/js/modern/is/index.js +1 -1
- package/dist/js/modern/is/type.js +3 -0
- package/dist/js/modern/monorepo.js +1 -1
- package/dist/js/modern/path.js +2 -13
- package/dist/js/modern/prettyInstructions.js +2 -2
- package/dist/js/modern/readTsConfig.js +1 -1
- package/dist/js/modern/runtimeExports.js +6 -2
- package/dist/js/node/FileSizeReporter.js +13 -17
- package/dist/js/node/alias.js +3 -7
- package/dist/js/node/applyOptionsChain.js +6 -5
- package/dist/js/node/constants.js +28 -2
- package/dist/js/node/ensureAbsolutePath.js +3 -5
- package/dist/js/node/getEntryOptions.js +14 -4
- package/dist/js/node/getPackageManager.js +6 -10
- package/dist/js/node/index.js +13 -17
- package/dist/js/node/is/index.js +3 -7
- package/dist/js/node/is/type.js +5 -0
- package/dist/js/node/monorepo.js +13 -17
- package/dist/js/node/path.js +5 -37
- package/dist/js/node/prettyInstructions.js +5 -3
- package/dist/js/node/readTsConfig.js +4 -6
- package/dist/js/node/runtimeExports.js +9 -7
- package/dist/js/treeshaking/FileSizeReporter.js +2 -2
- package/dist/js/treeshaking/alias.js +1 -1
- package/dist/js/treeshaking/applyOptionsChain.js +2 -1
- package/dist/js/treeshaking/constants.js +25 -0
- package/dist/js/treeshaking/ensureAbsolutePath.js +1 -1
- package/dist/js/treeshaking/getEntryOptions.js +14 -3
- package/dist/js/treeshaking/getPackageManager.js +1 -1
- package/dist/js/treeshaking/index.js +1 -5
- package/dist/js/treeshaking/is/index.js +1 -1
- package/dist/js/treeshaking/is/type.js +3 -0
- package/dist/js/treeshaking/monorepo.js +1 -1
- package/dist/js/treeshaking/path.js +4 -26
- package/dist/js/treeshaking/prettyInstructions.js +2 -2
- package/dist/js/treeshaking/readTsConfig.js +1 -1
- package/dist/js/treeshaking/runtimeExports.js +8 -2
- package/dist/types/constants.d.ts +5 -0
- package/dist/types/getEntryOptions.d.ts +1 -1
- package/dist/types/index.d.ts +1 -3
- package/dist/types/is/type.d.ts +2 -1
- package/dist/types/monorepo.d.ts +1 -1
- package/dist/types/path.d.ts +2 -11
- package/dist/types/prettyInstructions.d.ts +6 -1
- package/dist/types/runtimeExports.d.ts +1 -1
- package/package.json +3 -3
- package/src/FileSizeReporter.ts +2 -2
- package/src/alias.ts +1 -1
- package/src/applyOptionsChain.ts +2 -1
- package/src/constants.ts +20 -1
- package/src/ensureAbsolutePath.ts +1 -1
- package/src/getEntryOptions.ts +23 -4
- package/src/getPackageManager.ts +1 -1
- package/src/index.ts +1 -3
- package/src/is/index.ts +1 -1
- package/src/is/type.ts +4 -0
- package/src/monorepo.ts +1 -1
- package/src/path.ts +3 -21
- package/src/prettyInstructions.ts +2 -2
- package/src/readTsConfig.ts +1 -1
- package/src/runtimeExports.ts +32 -31
- package/tests/.eslintrc.js +6 -0
- package/tests/compatRequire.test.ts +1 -1
- package/tests/ensureAbsolutePath.test.ts +7 -4
- package/tests/findExists.test.ts +1 -1
- package/tests/getBrowserslist.test.ts +1 -1
- package/tests/getEntryOptions.test.ts +11 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# @modern-js/utils
|
2
2
|
|
3
|
+
## 1.1.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 0fa83663: support more .env files
|
8
|
+
- f594fbc8: fix apple icon and favicon support
|
9
|
+
|
10
|
+
## 1.1.1
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- c0fc0700: feat: support deploy plugin
|
15
|
+
|
16
|
+
## 1.1.0
|
17
|
+
|
18
|
+
### Minor Changes
|
19
|
+
|
20
|
+
- 96119db2: Relese v1.1.0
|
21
|
+
|
3
22
|
## 1.0.0
|
4
23
|
|
5
24
|
### Patch Changes
|
package/README.md
CHANGED
@@ -17,10 +17,7 @@
|
|
17
17
|
|
18
18
|
> 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.
|
19
19
|
|
20
|
-
-
|
21
|
-
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
22
|
-
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
23
|
-
- [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
|
20
|
+
- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
|
24
21
|
|
25
22
|
## Getting Started
|
26
23
|
|
@@ -13,13 +13,13 @@
|
|
13
13
|
'use strict';
|
14
14
|
|
15
15
|
import fs from 'fs';
|
16
|
-
import
|
16
|
+
import path from 'path';
|
17
17
|
import chalk from 'chalk';
|
18
18
|
import filesize from 'filesize';
|
19
19
|
import recursive from 'recursive-readdir';
|
20
20
|
import stripAnsi from 'strip-ansi';
|
21
21
|
import gzipSize from 'gzip-size';
|
22
|
-
import { logger } from
|
22
|
+
import { logger } from "./logger";
|
23
23
|
|
24
24
|
function canReadAsset(asset) {
|
25
25
|
return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
|
package/dist/js/modern/alias.js
CHANGED
@@ -5,8 +5,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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 fs from 'fs';
|
8
|
+
import path from 'path';
|
8
9
|
import chalk from 'chalk';
|
9
|
-
import * as path from "./path";
|
10
10
|
import { readTsConfigByFile } from "./readTsConfig";
|
11
11
|
import { applyOptionsChain } from "./applyOptionsChain";
|
12
12
|
export const validAlias = (modernConfig, {
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
// eslint-disable-next-line import/no-useless-path-segments
|
2
|
+
import { isFunction, logger, isPlainObject } from "./index";
|
2
3
|
export const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) => {
|
3
4
|
if (!options) {
|
4
5
|
return defaults;
|
@@ -17,6 +17,11 @@ export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
|
17
17
|
*/
|
18
18
|
|
19
19
|
export const ROUTE_SPEC_FILE = 'route.json';
|
20
|
+
/**
|
21
|
+
* main entry name
|
22
|
+
*/
|
23
|
+
|
24
|
+
export const MAIN_ENTRY_NAME = 'main';
|
20
25
|
/**
|
21
26
|
* open editor request path
|
22
27
|
*/
|
@@ -121,6 +126,24 @@ export const INTERNAL_PLUGINS = {
|
|
121
126
|
},
|
122
127
|
'@modern-js/plugin-tailwindcss': {
|
123
128
|
cli: '@modern-js/plugin-tailwindcss/cli'
|
129
|
+
},
|
130
|
+
'@modern-js/plugin-lambda-fc': {
|
131
|
+
cli: '@modern-js/plugin-lambda-fc/cli'
|
132
|
+
},
|
133
|
+
'@modern-js/plugin-lambda-scf': {
|
134
|
+
cli: '@modern-js/plugin-lambda-scf/cli'
|
135
|
+
},
|
136
|
+
'@modern-js/plugin-cdn-oss': {
|
137
|
+
cli: '@modern-js/plugin-cdn-oss/cli'
|
138
|
+
},
|
139
|
+
'@modern-js/plugin-cdn-cos': {
|
140
|
+
cli: '@modern-js/plugin-cdn-cos/cli'
|
141
|
+
},
|
142
|
+
'@modern-js/plugin-static-hosting': {
|
143
|
+
cli: '@modern-js/plugin-static-hosting/cli'
|
144
|
+
},
|
145
|
+
'@modern-js/plugin-polyfill': {
|
146
|
+
server: '@modern-js/plugin-polyfill'
|
124
147
|
}
|
125
148
|
};
|
126
149
|
/**
|
@@ -217,6 +240,8 @@ export const PLUGIN_SCHEMAS = {
|
|
217
240
|
schema: {
|
218
241
|
oneOf: [{
|
219
242
|
type: 'boolean'
|
243
|
+
}, {
|
244
|
+
type: 'object'
|
220
245
|
}, {
|
221
246
|
instanceof: 'Function'
|
222
247
|
}]
|
@@ -5,11 +5,20 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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 const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
|
9
10
|
if (optionsByEntries) {
|
10
|
-
//
|
11
|
-
|
11
|
+
let 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
|
}
|
15
|
-
};
|
22
|
+
};
|
23
|
+
|
24
|
+
const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
|
package/dist/js/modern/index.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
import * as _fs from 'fs-extra';
|
2
2
|
export { _fs as fs };
|
3
|
-
import * as _upath from 'upath';
|
4
|
-
export { _upath as upath };
|
5
3
|
export * from "./chalk";
|
6
4
|
export * from "./formatWebpackMessages";
|
7
5
|
export * from "./FileSizeReporter";
|
@@ -25,9 +23,7 @@ export * from "./monorepo";
|
|
25
23
|
export * from "./getPackageManager";
|
26
24
|
export * from "./runtimeExports";
|
27
25
|
export * from "./readTsConfig";
|
28
|
-
export
|
29
|
-
import * as _path from "./path";
|
30
|
-
export { _path as path };
|
26
|
+
export * from "./path";
|
31
27
|
export * from "./generateMetaTags";
|
32
28
|
export * from "./prettyInstructions";
|
33
29
|
export * from "./alias";
|
@@ -22,4 +22,7 @@ export function isPromise(obj) {
|
|
22
22
|
/* eslint-disable promise/prefer-await-to-then */
|
23
23
|
return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
24
24
|
/* eslint-enable promise/prefer-await-to-then */
|
25
|
+
}
|
26
|
+
export function isRegExp(obj) {
|
27
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
25
28
|
}
|
@@ -5,9 +5,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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 fs from 'fs';
|
8
|
+
import path from 'path';
|
8
9
|
import glob from 'glob';
|
9
10
|
import yaml from 'yaml';
|
10
|
-
import * as path from "./path";
|
11
11
|
const PACKAGE_MAX_DEPTH = 5;
|
12
12
|
const WOKRSPACES_FILES = {
|
13
13
|
YARN: 'package.json',
|
package/dist/js/modern/path.js
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
import path from 'path';
|
2
2
|
import upath from 'upath';
|
3
3
|
export const isRelativePath = test => /^\.\.?($|[\\/])/.test(test);
|
4
|
-
export const
|
5
|
-
export const
|
6
|
-
export const relative = (from, to) => upath.normalizeSafe(path.relative(from, to));
|
7
|
-
export const basename = (p, ext) => upath.normalizeSafe(path.basename(p, ext));
|
8
|
-
export const dirname = p => upath.normalizeSafe(path.dirname(p));
|
9
|
-
export const extname = p => path.extname(p);
|
10
|
-
export const isAbsolute = p => path.isAbsolute(p);
|
11
|
-
export const normalize = p => upath.normalizeSafe(path.normalize(p));
|
12
|
-
export const {
|
13
|
-
sep,
|
14
|
-
win32,
|
15
|
-
posix
|
16
|
-
} = path;
|
4
|
+
export const normalizeOutputPath = s => s.replace(/\\/g, '\\\\');
|
5
|
+
export const normalizeToPosixPath = p => upath.normalizeSafe(path.normalize(p));
|
@@ -3,7 +3,7 @@ import chalk from 'chalk';
|
|
3
3
|
import { isDev } from "./is"; // TODO: type
|
4
4
|
|
5
5
|
// TODO: remove hard code 'main'
|
6
|
-
const
|
6
|
+
export const isSingleEntry = entrypoints => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
|
7
7
|
|
8
8
|
const normalizeUrl = url => url.replace(/([^:]\/)\/+/g, '$1');
|
9
9
|
|
@@ -44,7 +44,7 @@ export const prettyInstructions = (appContext, config) => {
|
|
44
44
|
const routes = serverRoutes.filter(route => route.entryName);
|
45
45
|
let message = 'App running at:\n\n';
|
46
46
|
|
47
|
-
if (
|
47
|
+
if (isSingleEntry(entrypoints)) {
|
48
48
|
message += urls.map(({
|
49
49
|
type,
|
50
50
|
url
|
@@ -1,5 +1,6 @@
|
|
1
|
+
import path from 'path';
|
1
2
|
import fs from 'fs-extra';
|
2
|
-
import
|
3
|
+
import { normalizeOutputPath } from "./path";
|
3
4
|
|
4
5
|
const memo = fn => {
|
5
6
|
const cache = new Map();
|
@@ -17,7 +18,7 @@ const memo = fn => {
|
|
17
18
|
};
|
18
19
|
};
|
19
20
|
|
20
|
-
export const createRuntimeExportsUtils = memo((pwd, namespace) => {
|
21
|
+
export const createRuntimeExportsUtils = memo((pwd = '', namespace) => {
|
21
22
|
const entryExportFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`); // const ensure = () => {
|
22
23
|
// if (!fs.existsSync(entryExportFile)) {
|
23
24
|
// fs.outputFileSync(entryExportFile, '');
|
@@ -26,6 +27,9 @@ export const createRuntimeExportsUtils = memo((pwd, namespace) => {
|
|
26
27
|
// };
|
27
28
|
|
28
29
|
const addExport = statement => {
|
30
|
+
// eslint-disable-next-line no-param-reassign
|
31
|
+
statement = normalizeOutputPath(statement);
|
32
|
+
|
29
33
|
try {
|
30
34
|
fs.ensureFileSync(entryExportFile);
|
31
35
|
|
@@ -20,7 +20,7 @@ exports.printFileSizesAfterBuild = printFileSizesAfterBuild;
|
|
20
20
|
|
21
21
|
var _fs = _interopRequireDefault(require("fs"));
|
22
22
|
|
23
|
-
var
|
23
|
+
var _path = _interopRequireDefault(require("path"));
|
24
24
|
|
25
25
|
var _chalk = _interopRequireDefault(require("chalk"));
|
26
26
|
|
@@ -32,11 +32,7 @@ var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
|
|
32
32
|
|
33
33
|
var _gzipSize = _interopRequireDefault(require("gzip-size"));
|
34
34
|
|
35
|
-
var
|
36
|
-
|
37
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
38
|
-
|
39
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
35
|
+
var _logger = require("./logger");
|
40
36
|
|
41
37
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
42
38
|
|
@@ -52,7 +48,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
52
48
|
all: false,
|
53
49
|
assets: true
|
54
50
|
}).assets.filter(asset => canReadAsset(asset.name)).map(asset => {
|
55
|
-
var fileContents = _fs.default.readFileSync(
|
51
|
+
var fileContents = _fs.default.readFileSync(_path.default.join(root, asset.name));
|
56
52
|
|
57
53
|
var size = fileContents.length;
|
58
54
|
|
@@ -62,8 +58,8 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
62
58
|
var sizeDifference = getDifferenceLabel(size, previousSize);
|
63
59
|
var gzipSizeDifference = getDifferenceLabel(gzippedSize, previousGzipSize);
|
64
60
|
return {
|
65
|
-
folder:
|
66
|
-
name:
|
61
|
+
folder: _path.default.join(_path.default.basename(buildFolder), _path.default.dirname(asset.name)),
|
62
|
+
name: _path.default.basename(asset.name),
|
67
63
|
gzippedSize: gzippedSize,
|
68
64
|
sizeLabel: (0, _filesize.default)(size) + (sizeDifference ? ' (' + sizeDifference + ')' : ''),
|
69
65
|
gzipSizeLabel: (0, _filesize.default)(gzippedSize) + (gzipSizeDifference ? ' (' + gzipSizeDifference + ')' : '')
|
@@ -71,7 +67,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
71
67
|
})).reduce((single, all) => all.concat(single), []);
|
72
68
|
assets.sort((a, b) => b.size - a.size);
|
73
69
|
var longestSizeLabelLength = Math.max.apply(null, assets.map(a => (0, _stripAnsi.default)(a.sizeLabel).length));
|
74
|
-
var longestFileNameLength = Math.max.apply(null, assets.map(a => (0, _stripAnsi.default)(a.folder +
|
70
|
+
var longestFileNameLength = Math.max.apply(null, assets.map(a => (0, _stripAnsi.default)(a.folder + _path.default.sep + a.name).length));
|
75
71
|
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
76
72
|
var suggestBundleSplitting = false;
|
77
73
|
assets.forEach(asset => {
|
@@ -82,7 +78,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
82
78
|
gzipSizeLabel,
|
83
79
|
gzippedSize
|
84
80
|
} = asset;
|
85
|
-
var fileNameLength = (0, _stripAnsi.default)(folder +
|
81
|
+
var fileNameLength = (0, _stripAnsi.default)(folder + _path.default.sep + name).length;
|
86
82
|
var sizeLength = (0, _stripAnsi.default)(sizeLabel).length;
|
87
83
|
|
88
84
|
if (sizeLength < longestSizeLabelLength) {
|
@@ -90,7 +86,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
90
86
|
sizeLabel += rightPadding;
|
91
87
|
}
|
92
88
|
|
93
|
-
var fileNameLabel = _chalk.default.dim(asset.folder +
|
89
|
+
var fileNameLabel = _chalk.default.dim(asset.folder + _path.default.sep) + _chalk.default.cyan(asset.name);
|
94
90
|
|
95
91
|
if (fileNameLength < longestFileNameLength) {
|
96
92
|
var rightPadding = ' '.repeat(longestFileNameLength - fileNameLength);
|
@@ -101,17 +97,17 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
101
97
|
var maxRecommendedSize = isMainBundle ? maxBundleGzipSize : maxChunkGzipSize;
|
102
98
|
var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
|
103
99
|
|
104
|
-
if (isLarge &&
|
100
|
+
if (isLarge && _path.default.extname(asset.name) === '.js') {
|
105
101
|
suggestBundleSplitting = true;
|
106
102
|
}
|
107
103
|
|
108
|
-
|
104
|
+
_logger.logger.log(' ' + fileNameLabel + ' ' + sizeLabel + ' ' + (isLarge ? _chalk.default.yellow(gzipSizeLabel) : gzipSizeLabel));
|
109
105
|
});
|
110
106
|
|
111
107
|
if (suggestBundleSplitting) {
|
112
|
-
|
108
|
+
_logger.logger.log();
|
113
109
|
|
114
|
-
|
110
|
+
_logger.logger.warn('The bundle size is significantly larger than recommended.');
|
115
111
|
}
|
116
112
|
}
|
117
113
|
|
@@ -128,7 +124,7 @@ function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
|
128
124
|
return prev + curLabel + ' ';
|
129
125
|
}, ' ');
|
130
126
|
|
131
|
-
|
127
|
+
_logger.logger.log(_chalk.default.bold(_chalk.default.blue(headerRow)));
|
132
128
|
}
|
133
129
|
|
134
130
|
function removeFileNameHash(buildFolder, fileName) {
|
package/dist/js/node/alias.js
CHANGED
@@ -7,18 +7,14 @@ exports.validAlias = exports.getUserAlias = exports.getAlias = void 0;
|
|
7
7
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
9
9
|
|
10
|
-
var
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
11
11
|
|
12
|
-
var
|
12
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
13
13
|
|
14
14
|
var _readTsConfig = require("./readTsConfig");
|
15
15
|
|
16
16
|
var _applyOptionsChain = require("./applyOptionsChain");
|
17
17
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
19
|
-
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
21
|
-
|
22
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
19
|
|
24
20
|
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; }
|
@@ -77,7 +73,7 @@ const getAlias = (aliasOption, option) => {
|
|
77
73
|
const tsconfig = (0, _readTsConfig.readTsConfigByFile)(option.tsconfigPath);
|
78
74
|
const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig$compilerOpt = tsconfig.compilerOptions) === null || _tsconfig$compilerOpt === void 0 ? void 0 : _tsconfig$compilerOpt.baseUrl;
|
79
75
|
aliasConfig = {
|
80
|
-
absoluteBaseUrl: baseUrl ?
|
76
|
+
absoluteBaseUrl: baseUrl ? _path.default.join(option.appDirectory, baseUrl) : option.appDirectory,
|
81
77
|
paths: _objectSpread(_objectSpread({}, aliasOption || {}), tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig$compilerOpt2 = tsconfig.compilerOptions) === null || _tsconfig$compilerOpt2 === void 0 ? void 0 : _tsconfig$compilerOpt2.paths),
|
82
78
|
isTsPath: true,
|
83
79
|
isTsProject
|
@@ -5,21 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.applyOptionsChain = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _index = require("./index");
|
9
9
|
|
10
|
+
// eslint-disable-next-line import/no-useless-path-segments
|
10
11
|
const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) => {
|
11
12
|
if (!options) {
|
12
13
|
return defaults;
|
13
14
|
}
|
14
15
|
|
15
|
-
if ((0,
|
16
|
+
if ((0, _index.isPlainObject)(options)) {
|
16
17
|
return mergeFn(defaults, options);
|
17
|
-
} else if ((0,
|
18
|
+
} else if ((0, _index.isFunction)(options)) {
|
18
19
|
const ret = options(defaults, utils);
|
19
20
|
|
20
21
|
if (ret) {
|
21
|
-
if (!(0,
|
22
|
-
|
22
|
+
if (!(0, _index.isPlainObject)(ret)) {
|
23
|
+
_index.logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
|
23
24
|
}
|
24
25
|
|
25
26
|
return ret;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_SRC_ALIAS = exports.INTERNAL_PLUGINS = exports.INTERNAL_DIR_ALAIS = exports.HMR_SOCK_PATH = exports.HIDE_MODERN_JS_DIR = exports.ENTRY_NAME_PATTERN = void 0;
|
6
|
+
exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_SRC_ALIAS = exports.INTERNAL_PLUGINS = exports.INTERNAL_DIR_ALAIS = exports.HMR_SOCK_PATH = exports.HIDE_MODERN_JS_DIR = exports.ENTRY_NAME_PATTERN = void 0;
|
7
7
|
|
8
8
|
/**
|
9
9
|
* alias to src directory
|
@@ -28,10 +28,16 @@ const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
|
28
28
|
exports.HMR_SOCK_PATH = HMR_SOCK_PATH;
|
29
29
|
const ROUTE_SPEC_FILE = 'route.json';
|
30
30
|
/**
|
31
|
-
*
|
31
|
+
* main entry name
|
32
32
|
*/
|
33
33
|
|
34
34
|
exports.ROUTE_SPEC_FILE = ROUTE_SPEC_FILE;
|
35
|
+
const MAIN_ENTRY_NAME = 'main';
|
36
|
+
/**
|
37
|
+
* open editor request path
|
38
|
+
*/
|
39
|
+
|
40
|
+
exports.MAIN_ENTRY_NAME = MAIN_ENTRY_NAME;
|
35
41
|
const LAUNCH_EDITOR_ENDPOINT = '/__open-stack-frame-in-editor';
|
36
42
|
/**
|
37
43
|
* server side bundles directory, which relative to dist.
|
@@ -138,6 +144,24 @@ const INTERNAL_PLUGINS = {
|
|
138
144
|
},
|
139
145
|
'@modern-js/plugin-tailwindcss': {
|
140
146
|
cli: '@modern-js/plugin-tailwindcss/cli'
|
147
|
+
},
|
148
|
+
'@modern-js/plugin-lambda-fc': {
|
149
|
+
cli: '@modern-js/plugin-lambda-fc/cli'
|
150
|
+
},
|
151
|
+
'@modern-js/plugin-lambda-scf': {
|
152
|
+
cli: '@modern-js/plugin-lambda-scf/cli'
|
153
|
+
},
|
154
|
+
'@modern-js/plugin-cdn-oss': {
|
155
|
+
cli: '@modern-js/plugin-cdn-oss/cli'
|
156
|
+
},
|
157
|
+
'@modern-js/plugin-cdn-cos': {
|
158
|
+
cli: '@modern-js/plugin-cdn-cos/cli'
|
159
|
+
},
|
160
|
+
'@modern-js/plugin-static-hosting': {
|
161
|
+
cli: '@modern-js/plugin-static-hosting/cli'
|
162
|
+
},
|
163
|
+
'@modern-js/plugin-polyfill': {
|
164
|
+
server: '@modern-js/plugin-polyfill'
|
141
165
|
}
|
142
166
|
};
|
143
167
|
/**
|
@@ -235,6 +259,8 @@ const PLUGIN_SCHEMAS = {
|
|
235
259
|
schema: {
|
236
260
|
oneOf: [{
|
237
261
|
type: 'boolean'
|
262
|
+
}, {
|
263
|
+
type: 'object'
|
238
264
|
}, {
|
239
265
|
instanceof: 'Function'
|
240
266
|
}]
|
@@ -5,11 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.ensureAbsolutePath = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
9
|
|
10
|
-
function
|
11
|
-
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
11
|
|
14
12
|
/**
|
15
13
|
* ensure absolute file path.
|
@@ -17,6 +15,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
17
15
|
* @param filePath - Aboluste or relative file path.
|
18
16
|
* @returns Resolved absolute file path.
|
19
17
|
*/
|
20
|
-
const ensureAbsolutePath = (base, filePath) =>
|
18
|
+
const ensureAbsolutePath = (base, filePath) => _path.default.isAbsolute(filePath) ? filePath : _path.default.resolve(base, filePath);
|
21
19
|
|
22
20
|
exports.ensureAbsolutePath = ensureAbsolutePath;
|
@@ -7,19 +7,29 @@ exports.getEntryOptions = void 0;
|
|
7
7
|
|
8
8
|
var _is = require("./is");
|
9
9
|
|
10
|
+
var _constants = require("./constants");
|
11
|
+
|
10
12
|
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; }
|
11
13
|
|
12
14
|
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; }
|
13
15
|
|
14
16
|
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; }
|
15
17
|
|
16
|
-
const getEntryOptions = (name, baseOptions, optionsByEntries) => {
|
18
|
+
const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
|
17
19
|
if (optionsByEntries) {
|
18
|
-
//
|
19
|
-
|
20
|
+
let optionsByEntry = getOptionsByEntryName(name, optionsByEntries); // compatible with main entry using packageName as the key
|
21
|
+
|
22
|
+
if (optionsByEntry === undefined && name === _constants.MAIN_ENTRY_NAME && packageName) {
|
23
|
+
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
24
|
+
} // eslint-disable-next-line no-nested-ternary
|
25
|
+
|
26
|
+
|
27
|
+
return optionsByEntry !== undefined ? (0, _is.isPlainObject)(optionsByEntry) && (0, _is.isPlainObject)(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntry) : optionsByEntry : baseOptions;
|
20
28
|
} else {
|
21
29
|
return baseOptions;
|
22
30
|
}
|
23
31
|
};
|
24
32
|
|
25
|
-
exports.getEntryOptions = getEntryOptions;
|
33
|
+
exports.getEntryOptions = getEntryOptions;
|
34
|
+
|
35
|
+
const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
|
@@ -7,13 +7,9 @@ exports.getPackageManager = getPackageManager;
|
|
7
7
|
|
8
8
|
var _os = _interopRequireDefault(require("os"));
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
var path = _interopRequireWildcard(require("./path"));
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
12
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
17
13
|
|
18
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
15
|
|
@@ -21,19 +17,19 @@ function getPackageManager(cwd = process.cwd()) {
|
|
21
17
|
let appDirectory = cwd;
|
22
18
|
|
23
19
|
while (_os.default.homedir() !== appDirectory) {
|
24
|
-
if (_fsExtra.default.existsSync(
|
20
|
+
if (_fsExtra.default.existsSync(_path.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
25
21
|
return 'pnpm';
|
26
22
|
}
|
27
23
|
|
28
|
-
if (_fsExtra.default.existsSync(
|
24
|
+
if (_fsExtra.default.existsSync(_path.default.resolve(appDirectory, 'yarn.lock'))) {
|
29
25
|
return 'yarn';
|
30
26
|
}
|
31
27
|
|
32
|
-
if (_fsExtra.default.existsSync(
|
28
|
+
if (_fsExtra.default.existsSync(_path.default.resolve(appDirectory, 'package-lock.json'))) {
|
33
29
|
return 'npm';
|
34
30
|
}
|
35
31
|
|
36
|
-
appDirectory =
|
32
|
+
appDirectory = _path.default.join(appDirectory, '..');
|
37
33
|
}
|
38
34
|
|
39
35
|
return 'npm';
|