@modern-js/utils 1.3.7-alpha.prebundle.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +14 -1
- package/dist/getServerConfig.d.ts +1 -0
- package/dist/{src/watch.js → getServerConfig.js} +8 -34
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/ssrHelpers.d.ts +4 -0
- package/dist/ssrHelpers.js +7 -0
- package/dist/storage.d.ts +5 -0
- package/dist/storage.js +61 -0
- package/package.json +2 -2
- package/dist/compiled/upath/index.d.ts +0 -225
- package/dist/compiled/upath/index.js +0 -1
- package/dist/pkgUp.d.ts +0 -2
- package/dist/pkgUp.js +0 -8
- package/dist/src/FileSizeReporter.d.ts +0 -16
- package/dist/src/FileSizeReporter.js +0 -152
- package/dist/src/alias.d.ts +0 -21
- package/dist/src/alias.js +0 -62
- package/dist/src/applyOptionsChain.d.ts +0 -6
- package/dist/src/applyOptionsChain.js +0 -30
- package/dist/src/clearConsole.d.ts +0 -1
- package/dist/src/clearConsole.js +0 -9
- package/dist/src/compatRequire.d.ts +0 -8
- package/dist/src/compatRequire.js +0 -28
- package/dist/src/compiled.d.ts +0 -7
- package/dist/src/compiled.js +0 -19
- package/dist/src/constants.d.ts +0 -209
- package/dist/src/constants.js +0 -264
- package/dist/src/debug.d.ts +0 -7
- package/dist/src/debug.js +0 -14
- package/dist/src/emptyDir.d.ts +0 -1
- package/dist/src/emptyDir.js +0 -22
- package/dist/src/ensureAbsolutePath.d.ts +0 -7
- package/dist/src/ensureAbsolutePath.js +0 -15
- package/dist/src/findExists.d.ts +0 -6
- package/dist/src/findExists.js +0 -21
- package/dist/src/format.d.ts +0 -16
- package/dist/src/format.js +0 -115
- package/dist/src/generateMetaTags.d.ts +0 -16
- package/dist/src/generateMetaTags.js +0 -48
- package/dist/src/getBrowserslist.d.ts +0 -2
- package/dist/src/getBrowserslist.js +0 -7
- package/dist/src/getCacheIdentifier.d.ts +0 -7
- package/dist/src/getCacheIdentifier.js +0 -24
- package/dist/src/getEntryOptions.d.ts +0 -1
- package/dist/src/getEntryOptions.js +0 -26
- package/dist/src/getPackageManager.d.ts +0 -1
- package/dist/src/getPackageManager.js +0 -47
- package/dist/src/getPort.d.ts +0 -7
- package/dist/src/getPort.js +0 -62
- package/dist/src/import.d.ts +0 -5
- package/dist/src/import.js +0 -10
- package/dist/src/index.d.ts +0 -32
- package/dist/src/index.js +0 -57
- package/dist/src/is/index.d.ts +0 -34
- package/dist/src/is/index.js +0 -82
- package/dist/src/is/node-env.d.ts +0 -4
- package/dist/src/is/node-env.js +0 -12
- package/dist/src/is/platform.d.ts +0 -2
- package/dist/src/is/platform.js +0 -10
- package/dist/src/is/type.d.ts +0 -8
- package/dist/src/is/type.js +0 -38
- package/dist/src/logger.d.ts +0 -63
- package/dist/src/logger.js +0 -129
- package/dist/src/monorepo.d.ts +0 -11
- package/dist/src/monorepo.js +0 -81
- package/dist/src/nodeEnv.d.ts +0 -3
- package/dist/src/nodeEnv.js +0 -52
- package/dist/src/path.d.ts +0 -3
- package/dist/src/path.js +0 -14
- package/dist/src/prettyInstructions.d.ts +0 -6
- package/dist/src/prettyInstructions.js +0 -64
- package/dist/src/printBuildError.d.ts +0 -8
- package/dist/src/printBuildError.js +0 -43
- package/dist/src/readTsConfig.d.ts +0 -2
- package/dist/src/readTsConfig.js +0 -19
- package/dist/src/removeSlash.d.ts +0 -3
- package/dist/src/removeSlash.js +0 -9
- package/dist/src/runtimeExports.d.ts +0 -4
- package/dist/src/runtimeExports.js +0 -53
- package/dist/src/wait.d.ts +0 -2
- package/dist/src/wait.js +0 -7
- package/dist/src/watch.d.ts +0 -8
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# @modern-js/utils
|
2
2
|
|
3
|
+
## 1.4.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 6800be3b: feat: move storage from plugin-ssr to utils
|
8
|
+
|
9
|
+
## 1.4.0
|
10
|
+
|
11
|
+
### Minor Changes
|
12
|
+
|
13
|
+
- 77ff9754: feat: prebundle some deps (chalk, filesize, import-lazy, strip-ansi)
|
14
|
+
- d2d1d6b2: feat: support server config
|
15
|
+
|
16
|
+
### Patch Changes
|
17
|
+
|
18
|
+
- 07a4887e: feat: prebundle commander and signale to @modern-js/utils
|
19
|
+
- ea2ae711: feat: prebundle dependencies, reduce install size
|
20
|
+
- 17d0cc46: feat: prebundle lodash to @modern-js/utils/lodash
|
21
|
+
- d2d1d6b2: feat: add prepare hook
|
22
|
+
|
3
23
|
## 1.3.7
|
4
24
|
|
5
25
|
### Patch Changes
|
package/dist/constants.d.ts
CHANGED
@@ -36,6 +36,19 @@ export declare const LOADABLE_STATS_FILE = "loadable-stats.json";
|
|
36
36
|
export declare const API_DIR = "api";
|
37
37
|
export declare const SERVER_DIR = "server";
|
38
38
|
export declare const SHARED_DIR = "shared";
|
39
|
+
/**
|
40
|
+
* Modern.config.ts cached dir
|
41
|
+
*/
|
42
|
+
export declare const CONFIG_CACHE_DIR = "./node_modules/.node-bundle-require";
|
43
|
+
export declare const CONFIG_FILE_EXTENSIONS: string[];
|
44
|
+
/**
|
45
|
+
* Serialized config path
|
46
|
+
*/
|
47
|
+
export declare const OUTPUT_CONFIG_FILE = "modern.config.json";
|
48
|
+
/**
|
49
|
+
* Default server config basename
|
50
|
+
*/
|
51
|
+
export declare const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
|
39
52
|
/**
|
40
53
|
* Internal plugins that work as soon as they are installed.
|
41
54
|
*/
|
package/dist/constants.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.PLUGIN_SCHEMAS = exports.INTERNAL_PLUGINS = exports.SHARED_DIR = exports.SERVER_DIR = exports.API_DIR = exports.LOADABLE_STATS_FILE = exports.SERVER_RENDER_FUNCTION_NAME = exports.ENTRY_NAME_PATTERN = exports.SERVER_BUNDLE_DIRECTORY = exports.LAUNCH_EDITOR_ENDPOINT = exports.MAIN_ENTRY_NAME = exports.ROUTE_SPEC_FILE = exports.HMR_SOCK_PATH = void 0;
|
3
|
+
exports.PLUGIN_SCHEMAS = exports.INTERNAL_PLUGINS = exports.DEFAULT_SERVER_CONFIG = exports.OUTPUT_CONFIG_FILE = exports.CONFIG_FILE_EXTENSIONS = exports.CONFIG_CACHE_DIR = exports.SHARED_DIR = exports.SERVER_DIR = exports.API_DIR = exports.LOADABLE_STATS_FILE = exports.SERVER_RENDER_FUNCTION_NAME = exports.ENTRY_NAME_PATTERN = exports.SERVER_BUNDLE_DIRECTORY = exports.LAUNCH_EDITOR_ENDPOINT = exports.MAIN_ENTRY_NAME = exports.ROUTE_SPEC_FILE = exports.HMR_SOCK_PATH = void 0;
|
4
4
|
/**
|
5
5
|
* hmr socket connect path
|
6
6
|
*/
|
@@ -39,6 +39,19 @@ exports.LOADABLE_STATS_FILE = 'loadable-stats.json';
|
|
39
39
|
exports.API_DIR = 'api';
|
40
40
|
exports.SERVER_DIR = 'server';
|
41
41
|
exports.SHARED_DIR = 'shared';
|
42
|
+
/**
|
43
|
+
* Modern.config.ts cached dir
|
44
|
+
*/
|
45
|
+
exports.CONFIG_CACHE_DIR = './node_modules/.node-bundle-require';
|
46
|
+
exports.CONFIG_FILE_EXTENSIONS = ['.js', '.ts', '.ejs', '.mjs'];
|
47
|
+
/**
|
48
|
+
* Serialized config path
|
49
|
+
*/
|
50
|
+
exports.OUTPUT_CONFIG_FILE = 'modern.config.json';
|
51
|
+
/**
|
52
|
+
* Default server config basename
|
53
|
+
*/
|
54
|
+
exports.DEFAULT_SERVER_CONFIG = 'modern.server-runtime.config';
|
42
55
|
/**
|
43
56
|
* Internal plugins that work as soon as they are installed.
|
44
57
|
*/
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getServerConfig: (appDirectory: string, configFile: string) => Promise<string | false>;
|
@@ -28,38 +28,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
28
28
|
});
|
29
29
|
};
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
31
|
-
exports.
|
31
|
+
exports.getServerConfig = void 0;
|
32
32
|
const path = __importStar(require("path"));
|
33
|
-
const
|
34
|
-
const
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
const watch = (watchDir, runTask, ignored = []) => {
|
41
|
-
let ready = false;
|
42
|
-
const watcher = chokidar.watch(watchDir, {
|
43
|
-
ignored,
|
44
|
-
});
|
45
|
-
watcher.on('ready', () => (ready = true));
|
46
|
-
watcher.on('change', (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
47
|
-
const changedFilePath = path.resolve(filePath);
|
48
|
-
yield runTask({ changedFilePath, changeType: exports.WatchChangeType.CHANGE });
|
49
|
-
}));
|
50
|
-
watcher.on('add', (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
51
|
-
const changedFilePath = path.resolve(filePath);
|
52
|
-
if (ready) {
|
53
|
-
yield runTask({ changedFilePath, changeType: exports.WatchChangeType.ADD });
|
54
|
-
}
|
55
|
-
}));
|
56
|
-
watcher.on('unlink', (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
57
|
-
const changedFilePath = path.resolve(filePath);
|
58
|
-
yield runTask({ changedFilePath, changeType: exports.WatchChangeType.UNLINK });
|
59
|
-
}));
|
60
|
-
watcher.on('error', err => {
|
61
|
-
throw err;
|
62
|
-
});
|
63
|
-
return watcher;
|
64
|
-
};
|
65
|
-
exports.watch = watch;
|
33
|
+
const constants_1 = require("./constants");
|
34
|
+
const findExists_1 = require("./findExists");
|
35
|
+
const getServerConfig = (appDirectory, configFile) => __awaiter(void 0, void 0, void 0, function* () {
|
36
|
+
const configFilePath = (0, findExists_1.findExists)(constants_1.CONFIG_FILE_EXTENSIONS.map(extension => path.resolve(appDirectory, `${configFile}${extension}`)));
|
37
|
+
return configFilePath;
|
38
|
+
});
|
39
|
+
exports.getServerConfig = getServerConfig;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -41,3 +41,5 @@ __exportStar(require("./watch"), exports);
|
|
41
41
|
__exportStar(require("./nodeEnv"), exports);
|
42
42
|
__exportStar(require("./wait"), exports);
|
43
43
|
__exportStar(require("./emptyDir"), exports);
|
44
|
+
__exportStar(require("./getServerConfig"), exports);
|
45
|
+
__exportStar(require("./ssrHelpers"), exports);
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.useHeaders = exports.run = void 0;
|
4
|
+
const storage_1 = require("./storage");
|
5
|
+
const { run, useContext: useHeaders } = (0, storage_1.createStorage)();
|
6
|
+
exports.run = run;
|
7
|
+
exports.useHeaders = useHeaders;
|
package/dist/storage.js
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
22
|
+
exports.createStorage = void 0;
|
23
|
+
const ah = __importStar(require("async_hooks"));
|
24
|
+
const createStorage = () => {
|
25
|
+
let storage;
|
26
|
+
if (typeof ah.AsyncLocalStorage !== 'undefined') {
|
27
|
+
storage = new ah.AsyncLocalStorage();
|
28
|
+
}
|
29
|
+
const run = (context, cb) => {
|
30
|
+
if (!storage) {
|
31
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
32
|
+
`);
|
33
|
+
}
|
34
|
+
return new Promise((resolve, reject) => {
|
35
|
+
storage.run(context, () => {
|
36
|
+
try {
|
37
|
+
return resolve(cb());
|
38
|
+
}
|
39
|
+
catch (error) {
|
40
|
+
return reject(error);
|
41
|
+
}
|
42
|
+
});
|
43
|
+
});
|
44
|
+
};
|
45
|
+
const useContext = () => {
|
46
|
+
if (!storage) {
|
47
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
48
|
+
`);
|
49
|
+
}
|
50
|
+
const context = storage.getStore();
|
51
|
+
if (!context) {
|
52
|
+
throw new Error(`Can't call useContext out of scope, it should be placed on top of the function`);
|
53
|
+
}
|
54
|
+
return context;
|
55
|
+
};
|
56
|
+
return {
|
57
|
+
run,
|
58
|
+
useContext,
|
59
|
+
};
|
60
|
+
};
|
61
|
+
exports.createStorage = createStorage;
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.4.1",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/index.d.ts",
|
17
17
|
"main": "./dist/index.js",
|
@@ -60,7 +60,7 @@
|
|
60
60
|
"typescript": "^4"
|
61
61
|
},
|
62
62
|
"devDependencies": {
|
63
|
-
"@modern-js/types": "^1.
|
63
|
+
"@modern-js/types": "^1.4.0",
|
64
64
|
"@scripts/build": "0.0.0",
|
65
65
|
"@scripts/jest-config": "0.0.0",
|
66
66
|
"@types/debug": "4.1.7",
|
@@ -1,225 +0,0 @@
|
|
1
|
-
declare module "upath" {
|
2
|
-
/**
|
3
|
-
* A parsed path object generated by path.parse() or consumed by path.format().
|
4
|
-
*/
|
5
|
-
interface ParsedPath {
|
6
|
-
/**
|
7
|
-
* The root of the path such as '/' or 'c:\'
|
8
|
-
*/
|
9
|
-
root: string;
|
10
|
-
/**
|
11
|
-
* The full directory path such as '/home/user/dir' or 'c:\path\dir'
|
12
|
-
*/
|
13
|
-
dir: string;
|
14
|
-
/**
|
15
|
-
* The file name including extension (if any) such as 'index.html'
|
16
|
-
*/
|
17
|
-
base: string;
|
18
|
-
/**
|
19
|
-
* The file extension (if any) such as '.html'
|
20
|
-
*/
|
21
|
-
ext: string;
|
22
|
-
/**
|
23
|
-
* The file name without extension (if any) such as 'index'
|
24
|
-
*/
|
25
|
-
name: string;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Version of the library
|
29
|
-
*/
|
30
|
-
var VERSION: string;
|
31
|
-
/**
|
32
|
-
* Just converts all `to/` and consolidates duplicates, without performing any normalization.
|
33
|
-
*
|
34
|
-
* @param p string path to convert to unix.
|
35
|
-
*/
|
36
|
-
function toUnix(p: string): string;
|
37
|
-
/**
|
38
|
-
* Exactly like path.normalize(path), but it keeps the first meaningful ./.
|
39
|
-
*
|
40
|
-
* Note that the unix / is returned everywhere, so windows \ is always converted to unix /.
|
41
|
-
*
|
42
|
-
* @param p string path to normalize.
|
43
|
-
*/
|
44
|
-
function normalizeSafe(p: string): string;
|
45
|
-
/**
|
46
|
-
* Exactly like path.normalizeSafe(path), but it trims any useless ending /.
|
47
|
-
*
|
48
|
-
* @param p string path to normalize
|
49
|
-
*/
|
50
|
-
function normalizeTrim(p: string): string;
|
51
|
-
/**
|
52
|
-
* Exactly like path.join(), but it keeps the first meaningful ./.
|
53
|
-
*
|
54
|
-
* Note that the unix / is returned everywhere, so windows \ is always converted to unix /.
|
55
|
-
*
|
56
|
-
* @param paths string paths to join
|
57
|
-
*/
|
58
|
-
function joinSafe(...p: any[]): string;
|
59
|
-
/**
|
60
|
-
* Adds .ext to filename, but only if it doesn't already have the exact extension.
|
61
|
-
*
|
62
|
-
* @param file string filename to add extension to
|
63
|
-
* @param ext string extension to add
|
64
|
-
*/
|
65
|
-
function addExt(file: string, ext: string): string;
|
66
|
-
/**
|
67
|
-
* Trims a filename's extension.
|
68
|
-
*
|
69
|
-
* Extensions are considered to be up to maxSize chars long, counting the dot (defaults to 7).
|
70
|
-
*
|
71
|
-
* An Array of ignoreExts (eg ['.min']) prevents these from being considered as extension, thus are not trimmed.
|
72
|
-
*
|
73
|
-
* @param filename string filename to trim it's extension
|
74
|
-
* @param ignoreExts array extensions to ignore
|
75
|
-
* @param maxSize number max length of the extension
|
76
|
-
*/
|
77
|
-
function trimExt(filename: string, ignoreExts?: string[], maxSize?: number): string;
|
78
|
-
/**
|
79
|
-
* Removes the specific ext extension from filename, if it has it. Otherwise it leaves it as is. As in all upath functions, it be .ext or ext.
|
80
|
-
*
|
81
|
-
* @param file string filename to remove extension to
|
82
|
-
* @param ext string extension to remove
|
83
|
-
*/
|
84
|
-
function removeExt(filename: string, ext: string): string;
|
85
|
-
/**
|
86
|
-
* Changes a filename's extension to ext. If it has no (valid) extension, it adds it.
|
87
|
-
*
|
88
|
-
* Valid extensions are considered to be up to maxSize chars long, counting the dot (defaults to 7).
|
89
|
-
*
|
90
|
-
* An Array of ignoreExts (eg ['.min']) prevents these from being considered as extension, thus are not changed - the new extension is added instead.
|
91
|
-
*
|
92
|
-
* @param filename string filename to change it's extension
|
93
|
-
* @param ext string extension to change to
|
94
|
-
* @param ignoreExts array extensions to ignore
|
95
|
-
* @param maxSize number max length of the extension
|
96
|
-
*/
|
97
|
-
function changeExt(filename: string, ext: string, ignoreExts?: string[], maxSize?: number): string;
|
98
|
-
/**
|
99
|
-
* Adds .ext to filename, only if it doesn't already have any old extension.
|
100
|
-
*
|
101
|
-
* (Old) extensions are considered to be up to maxSize chars long, counting the dot (defaults to 7).
|
102
|
-
*
|
103
|
-
* An Array of ignoreExts (eg ['.min']) will force adding default .ext even if one of these is present.
|
104
|
-
*
|
105
|
-
* @param filename string filename to default to it's extension
|
106
|
-
* @param ext string extension to default to
|
107
|
-
* @param ignoreExts array extensions to ignore
|
108
|
-
* @param maxSize number max length of the extension
|
109
|
-
*/
|
110
|
-
function defaultExt(filename: string, ext: string, ignoreExts?: string[], maxSize?: number): string;
|
111
|
-
/**
|
112
|
-
* Normalize a string path, reducing '..' and '.' parts.
|
113
|
-
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
|
114
|
-
*
|
115
|
-
* @param p string path to normalize.
|
116
|
-
*/
|
117
|
-
function normalize(p: string): string;
|
118
|
-
/**
|
119
|
-
* Join all arguments together and normalize the resulting path.
|
120
|
-
* Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
|
121
|
-
*
|
122
|
-
* @param paths string paths to join.
|
123
|
-
*/
|
124
|
-
function join(...paths: any[]): string;
|
125
|
-
/**
|
126
|
-
* Join all arguments together and normalize the resulting path.
|
127
|
-
* Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
|
128
|
-
*
|
129
|
-
* @param paths string paths to join.
|
130
|
-
*/
|
131
|
-
function join(...paths: string[]): string;
|
132
|
-
/**
|
133
|
-
* The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
|
134
|
-
*
|
135
|
-
* Starting from leftmost {from} parameter, resolves {to} to an absolute path.
|
136
|
-
*
|
137
|
-
* If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.
|
138
|
-
*
|
139
|
-
* @param pathSegments string paths to join. Non-string arguments are ignored.
|
140
|
-
*/
|
141
|
-
function resolve(...pathSegments: any[]): string;
|
142
|
-
/**
|
143
|
-
* Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
|
144
|
-
*
|
145
|
-
* @param path path to test.
|
146
|
-
*/
|
147
|
-
function isAbsolute(path: string): boolean;
|
148
|
-
/**
|
149
|
-
* Solve the relative path from {from} to {to}.
|
150
|
-
* At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
|
151
|
-
*
|
152
|
-
* @param from
|
153
|
-
* @param to
|
154
|
-
*/
|
155
|
-
function relative(from: string, to: string): string;
|
156
|
-
/**
|
157
|
-
* Return the directory name of a path. Similar to the Unix dirname command.
|
158
|
-
*
|
159
|
-
* @param p the path to evaluate.
|
160
|
-
*/
|
161
|
-
function dirname(p: string): string;
|
162
|
-
/**
|
163
|
-
* Return the last portion of a path. Similar to the Unix basename command.
|
164
|
-
* Often used to extract the file name from a fully qualified path.
|
165
|
-
*
|
166
|
-
* @param p the path to evaluate.
|
167
|
-
* @param ext optionally, an extension to remove from the result.
|
168
|
-
*/
|
169
|
-
function basename(p: string, ext?: string): string;
|
170
|
-
/**
|
171
|
-
* Return the extension of the path, from the last '.' to end of string in the last portion of the path.
|
172
|
-
* If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
|
173
|
-
*
|
174
|
-
* @param p the path to evaluate.
|
175
|
-
*/
|
176
|
-
function extname(p: string): string;
|
177
|
-
/**
|
178
|
-
* The platform-specific file separator. '\\' or '/'.
|
179
|
-
*/
|
180
|
-
var sep: string;
|
181
|
-
/**
|
182
|
-
* The platform-specific file delimiter. ';' or ':'.
|
183
|
-
*/
|
184
|
-
var delimiter: string;
|
185
|
-
/**
|
186
|
-
* Returns an object from a path string - the opposite of format().
|
187
|
-
*
|
188
|
-
* @param pathString path to evaluate.
|
189
|
-
*/
|
190
|
-
function parse(pathString: string): ParsedPath;
|
191
|
-
/**
|
192
|
-
* Returns a path string from an object - the opposite of parse().
|
193
|
-
*
|
194
|
-
* @param pathString path to evaluate.
|
195
|
-
*/
|
196
|
-
function format(pathObject: ParsedPath): string;
|
197
|
-
module posix {
|
198
|
-
function normalize(p: string): string;
|
199
|
-
function join(...paths: any[]): string;
|
200
|
-
function resolve(...pathSegments: any[]): string;
|
201
|
-
function isAbsolute(p: string): boolean;
|
202
|
-
function relative(from: string, to: string): string;
|
203
|
-
function dirname(p: string): string;
|
204
|
-
function basename(p: string, ext?: string): string;
|
205
|
-
function extname(p: string): string;
|
206
|
-
var sep: string;
|
207
|
-
var delimiter: string;
|
208
|
-
function parse(p: string): ParsedPath;
|
209
|
-
function format(pP: ParsedPath): string;
|
210
|
-
}
|
211
|
-
module win32 {
|
212
|
-
function normalize(p: string): string;
|
213
|
-
function join(...paths: any[]): string;
|
214
|
-
function resolve(...pathSegments: any[]): string;
|
215
|
-
function isAbsolute(p: string): boolean;
|
216
|
-
function relative(from: string, to: string): string;
|
217
|
-
function dirname(p: string): string;
|
218
|
-
function basename(p: string, ext?: string): string;
|
219
|
-
function extname(p: string): string;
|
220
|
-
var sep: string;
|
221
|
-
var delimiter: string;
|
222
|
-
function parse(p: string): ParsedPath;
|
223
|
-
function format(pP: ParsedPath): string;
|
224
|
-
}
|
225
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|
package/dist/pkgUp.d.ts
DELETED
package/dist/pkgUp.js
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.pkgUp = void 0;
|
7
|
-
const pkg_up_1 = __importDefault(require("pkg-up"));
|
8
|
-
exports.pkgUp = pkg_up_1.default;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file at
|
6
|
-
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
|
-
*/
|
8
|
-
declare function printFileSizesAfterBuild(webpackStats: any, previousSizeMap: {
|
9
|
-
root: string;
|
10
|
-
sizes: Record<string, number[]>;
|
11
|
-
}, buildFolder: string, maxBundleGzipSize: number, maxChunkGzipSize: number): void;
|
12
|
-
declare function measureFileSizesBeforeBuild(buildFolder: string): Promise<{
|
13
|
-
root: string;
|
14
|
-
sizes: Record<string, number[]>;
|
15
|
-
}>;
|
16
|
-
export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
|
@@ -1,152 +0,0 @@
|
|
1
|
-
/* eslint-disable eslint-comments/no-unlimited-disable */
|
2
|
-
/* eslint-disable */
|
3
|
-
/**
|
4
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
5
|
-
*
|
6
|
-
* This source code is licensed under the MIT license found in the
|
7
|
-
* LICENSE file at
|
8
|
-
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
9
|
-
*/
|
10
|
-
// Modified by Chao Xu (xuchaobei)
|
11
|
-
'use strict';
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
14
|
-
};
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
16
|
-
exports.printFileSizesAfterBuild = exports.measureFileSizesBeforeBuild = void 0;
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
18
|
-
const path_1 = __importDefault(require("path"));
|
19
|
-
const compiled_1 = require("./compiled");
|
20
|
-
const recursive_readdir_1 = __importDefault(require("recursive-readdir"));
|
21
|
-
const logger_1 = require("./logger");
|
22
|
-
function canReadAsset(asset) {
|
23
|
-
return (/\.(js|css)$/.test(asset) &&
|
24
|
-
!/service-worker\.js/.test(asset) &&
|
25
|
-
!/precache-manifest\.[0-9a-f]+\.js/.test(asset));
|
26
|
-
}
|
27
|
-
// Prints a detailed summary of build files.
|
28
|
-
function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, maxBundleGzipSize, maxChunkGzipSize) {
|
29
|
-
var root = previousSizeMap.root;
|
30
|
-
var sizes = previousSizeMap.sizes;
|
31
|
-
var assets = (webpackStats.stats || [webpackStats])
|
32
|
-
.map((stats) => stats
|
33
|
-
.toJson({ all: false, assets: true })
|
34
|
-
.assets.filter((asset) => canReadAsset(asset.name))
|
35
|
-
.map((asset) => {
|
36
|
-
var fileContents = fs_1.default.readFileSync(path_1.default.join(root, asset.name));
|
37
|
-
var size = fileContents.length;
|
38
|
-
var gzippedSize = compiled_1.gzipSize.sync(fileContents);
|
39
|
-
var [previousSize, previousGzipSize] = sizes[removeFileNameHash(root, asset.name)] || [];
|
40
|
-
var sizeDifference = getDifferenceLabel(size, previousSize);
|
41
|
-
var gzipSizeDifference = getDifferenceLabel(gzippedSize, previousGzipSize);
|
42
|
-
return {
|
43
|
-
folder: path_1.default.join(path_1.default.basename(buildFolder), path_1.default.dirname(asset.name)),
|
44
|
-
name: path_1.default.basename(asset.name),
|
45
|
-
gzippedSize: gzippedSize,
|
46
|
-
sizeLabel: (0, compiled_1.filesize)(size) +
|
47
|
-
(sizeDifference ? ' (' + sizeDifference + ')' : ''),
|
48
|
-
gzipSizeLabel: (0, compiled_1.filesize)(gzippedSize) +
|
49
|
-
(gzipSizeDifference ? ' (' + gzipSizeDifference + ')' : ''),
|
50
|
-
};
|
51
|
-
}))
|
52
|
-
.reduce((single, all) => all.concat(single), []);
|
53
|
-
assets.sort((a, b) => b.size - a.size);
|
54
|
-
var longestSizeLabelLength = Math.max.apply(null, assets.map((a) => (0, compiled_1.stripAnsi)(a.sizeLabel).length));
|
55
|
-
var longestFileNameLength = Math.max.apply(null, assets.map((a) => (0, compiled_1.stripAnsi)(a.folder + path_1.default.sep + a.name).length));
|
56
|
-
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
57
|
-
var suggestBundleSplitting = false;
|
58
|
-
assets.forEach((asset) => {
|
59
|
-
var { folder, name, sizeLabel, gzipSizeLabel, gzippedSize } = asset;
|
60
|
-
var fileNameLength = (0, compiled_1.stripAnsi)(folder + path_1.default.sep + name).length;
|
61
|
-
var sizeLength = (0, compiled_1.stripAnsi)(sizeLabel).length;
|
62
|
-
if (sizeLength < longestSizeLabelLength) {
|
63
|
-
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
|
64
|
-
sizeLabel += rightPadding;
|
65
|
-
}
|
66
|
-
var fileNameLabel = compiled_1.chalk.dim(asset.folder + path_1.default.sep) + compiled_1.chalk.cyan(asset.name);
|
67
|
-
if (fileNameLength < longestFileNameLength) {
|
68
|
-
var rightPadding = ' '.repeat(longestFileNameLength - fileNameLength);
|
69
|
-
fileNameLabel += rightPadding;
|
70
|
-
}
|
71
|
-
var isMainBundle = asset.name.indexOf('main.') === 0;
|
72
|
-
var maxRecommendedSize = isMainBundle
|
73
|
-
? maxBundleGzipSize
|
74
|
-
: maxChunkGzipSize;
|
75
|
-
var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
|
76
|
-
if (isLarge && path_1.default.extname(asset.name) === '.js') {
|
77
|
-
suggestBundleSplitting = true;
|
78
|
-
}
|
79
|
-
logger_1.logger.log(' ' +
|
80
|
-
fileNameLabel +
|
81
|
-
' ' +
|
82
|
-
sizeLabel +
|
83
|
-
' ' +
|
84
|
-
(isLarge ? compiled_1.chalk.yellow(gzipSizeLabel) : gzipSizeLabel));
|
85
|
-
});
|
86
|
-
if (suggestBundleSplitting) {
|
87
|
-
logger_1.logger.log();
|
88
|
-
logger_1.logger.warn('The bundle size is significantly larger than recommended.');
|
89
|
-
}
|
90
|
-
}
|
91
|
-
exports.printFileSizesAfterBuild = printFileSizesAfterBuild;
|
92
|
-
function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
93
|
-
const longestLengths = [longestFileNameLength, longestSizeLabelLength];
|
94
|
-
const headerRow = ['File', 'Size', 'Gzipped'].reduce((prev, cur, index) => {
|
95
|
-
const length = longestLengths[index];
|
96
|
-
let curLabel = cur;
|
97
|
-
if (length) {
|
98
|
-
curLabel =
|
99
|
-
cur.length < length ? cur + ' '.repeat(length - cur.length) : cur;
|
100
|
-
}
|
101
|
-
return prev + curLabel + ' ';
|
102
|
-
}, ' ');
|
103
|
-
logger_1.logger.log(compiled_1.chalk.bold(compiled_1.chalk.blue(headerRow)));
|
104
|
-
}
|
105
|
-
function removeFileNameHash(buildFolder, fileName) {
|
106
|
-
return fileName
|
107
|
-
.replace(buildFolder, '')
|
108
|
-
.replace(/\\/g, '/')
|
109
|
-
.replace(/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, (match, p1, p2, p3, p4) => p1 + p4);
|
110
|
-
}
|
111
|
-
// Input: 1024, 2048
|
112
|
-
// Output: "(+1 KB)"
|
113
|
-
function getDifferenceLabel(currentSize, previousSize) {
|
114
|
-
var FIFTY_KILOBYTES = 1024 * 50;
|
115
|
-
var difference = currentSize - previousSize;
|
116
|
-
var fileSize = !Number.isNaN(difference) ? (0, compiled_1.filesize)(difference) : 0;
|
117
|
-
if (difference >= FIFTY_KILOBYTES) {
|
118
|
-
return compiled_1.chalk.red('+' + fileSize);
|
119
|
-
}
|
120
|
-
else if (difference < FIFTY_KILOBYTES && difference > 0) {
|
121
|
-
return compiled_1.chalk.yellow('+' + fileSize);
|
122
|
-
}
|
123
|
-
else if (difference < 0) {
|
124
|
-
return compiled_1.chalk.green(fileSize);
|
125
|
-
}
|
126
|
-
else {
|
127
|
-
return '';
|
128
|
-
}
|
129
|
-
}
|
130
|
-
function measureFileSizesBeforeBuild(buildFolder) {
|
131
|
-
return new Promise(resolve => {
|
132
|
-
(0, recursive_readdir_1.default)(buildFolder, (err, fileNames) => {
|
133
|
-
var sizes;
|
134
|
-
if (!err && fileNames) {
|
135
|
-
sizes = fileNames
|
136
|
-
.filter(canReadAsset)
|
137
|
-
.reduce((memo, fileName) => {
|
138
|
-
var contents = fs_1.default.readFileSync(fileName);
|
139
|
-
var key = removeFileNameHash(buildFolder, fileName);
|
140
|
-
// save both the original size and gzip size
|
141
|
-
memo[key] = [contents.length, compiled_1.gzipSize.sync(contents)];
|
142
|
-
return memo;
|
143
|
-
}, {});
|
144
|
-
}
|
145
|
-
resolve({
|
146
|
-
root: buildFolder,
|
147
|
-
sizes: sizes || {},
|
148
|
-
});
|
149
|
-
});
|
150
|
-
});
|
151
|
-
}
|
152
|
-
exports.measureFileSizesBeforeBuild = measureFileSizesBeforeBuild;
|