@modern-js/utils 2.15.0 → 2.16.0
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 +16 -0
- package/dist/cjs/FileSizeReporter.js +69 -92
- package/dist/cjs/alias.js +34 -58
- package/dist/cjs/analyzeProject.js +58 -41
- package/dist/cjs/applyOptionsChain.js +15 -42
- package/dist/cjs/babel.js +28 -39
- package/dist/cjs/chainId.js +7 -25
- package/dist/cjs/clearConsole.js +7 -25
- package/dist/cjs/commands.js +14 -29
- package/dist/cjs/compatRequire.js +22 -38
- package/dist/cjs/compiled.js +120 -139
- package/dist/cjs/constants.js +143 -98
- package/dist/cjs/debug.js +8 -26
- package/dist/cjs/emptyDir.js +10 -28
- package/dist/cjs/ensureAbsolutePath.js +13 -36
- package/dist/cjs/ensureArray.js +10 -26
- package/dist/cjs/findExists.js +14 -37
- package/dist/cjs/generateMetaTags.js +12 -31
- package/dist/cjs/getBrowserslist.js +20 -27
- package/dist/cjs/getCoreJsVersion.js +49 -37
- package/dist/cjs/getEntryOptions.js +14 -29
- package/dist/cjs/getPackageManager.js +23 -46
- package/dist/cjs/getPort.js +26 -61
- package/dist/cjs/getServerConfig.js +51 -43
- package/dist/cjs/getTargetDir.js +50 -38
- package/dist/cjs/import.js +16 -27
- package/dist/cjs/index.js +61 -60
- package/dist/cjs/is/index.js +53 -68
- package/dist/cjs/is/nodeEnv.js +13 -29
- package/dist/cjs/is/platform.js +13 -26
- package/dist/cjs/is/type.js +14 -33
- package/dist/cjs/logger.js +54 -50
- package/dist/cjs/monorepo.js +47 -78
- package/dist/cjs/nodeEnv.js +29 -31
- package/dist/cjs/path.js +42 -63
- package/dist/cjs/pathSerializer.js +43 -51
- package/dist/cjs/plugin.js +11 -29
- package/dist/cjs/prettyInstructions.js +35 -68
- package/dist/cjs/printBuildError.js +15 -37
- package/dist/cjs/react.js +18 -41
- package/dist/cjs/readTsConfig.js +21 -39
- package/dist/cjs/removeSlash.js +13 -27
- package/dist/cjs/resolve.js +25 -31
- package/dist/cjs/routes.js +23 -43
- package/dist/cjs/runtime/index.js +18 -17
- package/dist/cjs/runtime/parsed.js +8 -26
- package/dist/cjs/runtimeExports.js +31 -56
- package/dist/cjs/ssr.js +13 -26
- package/dist/cjs/storage.js +51 -41
- package/dist/cjs/testUtils.js +8 -29
- package/dist/cjs/types.js +4 -15
- package/dist/cjs/universal/constants.js +13 -26
- package/dist/cjs/universal/formatWebpack.js +16 -44
- package/dist/cjs/universal/nestedRoutes.js +94 -46
- package/dist/cjs/universal/pluginDagSort.js +58 -0
- package/dist/cjs/universal/remixRouter.js +18 -17
- package/dist/cjs/universal/serialize.js +16 -37
- package/dist/cjs/version.js +25 -41
- package/dist/cjs/wait.js +7 -25
- package/dist/cjs/watch.js +69 -43
- package/dist/esm/FileSizeReporter.js +40 -52
- package/dist/esm/alias.js +9 -19
- package/dist/esm/analyzeProject.js +3 -7
- package/dist/esm/applyOptionsChain.js +5 -17
- package/dist/esm/babel.js +6 -8
- package/dist/esm/chainId.js +1 -4
- package/dist/esm/clearConsole.js +1 -4
- package/dist/esm/commands.js +6 -12
- package/dist/esm/compatRequire.js +10 -17
- package/dist/esm/compiled.js +32 -76
- package/dist/esm/constants.js +143 -89
- package/dist/esm/debug.js +1 -4
- package/dist/esm/emptyDir.js +1 -4
- package/dist/esm/ensureAbsolutePath.js +1 -4
- package/dist/esm/ensureArray.js +4 -5
- package/dist/esm/findExists.js +1 -4
- package/dist/esm/generateMetaTags.js +6 -10
- package/dist/esm/getBrowserslist.js +8 -6
- package/dist/esm/getCoreJsVersion.js +1 -4
- package/dist/esm/getEntryOptions.js +5 -5
- package/dist/esm/getPackageManager.js +1 -4
- package/dist/esm/getPort.js +10 -25
- package/dist/esm/getServerConfig.js +2 -9
- package/dist/esm/getTargetDir.js +1 -4
- package/dist/esm/import.js +3 -4
- package/dist/esm/is/index.js +18 -30
- package/dist/esm/is/nodeEnv.js +5 -12
- package/dist/esm/is/platform.js +2 -6
- package/dist/esm/is/type.js +8 -18
- package/dist/esm/logger.js +37 -17
- package/dist/esm/monorepo.js +21 -38
- package/dist/esm/nodeEnv.js +18 -11
- package/dist/esm/path.js +16 -23
- package/dist/esm/pathSerializer.js +21 -21
- package/dist/esm/plugin.js +1 -4
- package/dist/esm/prettyInstructions.js +13 -32
- package/dist/esm/printBuildError.js +4 -11
- package/dist/esm/react.js +1 -4
- package/dist/esm/readTsConfig.js +2 -6
- package/dist/esm/removeSlash.js +3 -8
- package/dist/esm/resolve.js +14 -11
- package/dist/esm/routes.js +4 -10
- package/dist/esm/runtime/parsed.js +2 -5
- package/dist/esm/runtimeExports.js +17 -22
- package/dist/esm/ssr.js +1 -4
- package/dist/esm/storage.js +2 -6
- package/dist/esm/testUtils.js +2 -8
- package/dist/esm/types.js +1 -0
- package/dist/esm/universal/constants.js +2 -6
- package/dist/esm/universal/formatWebpack.js +10 -22
- package/dist/esm/universal/nestedRoutes.js +41 -27
- package/dist/esm/universal/pluginDagSort.js +50 -0
- package/dist/esm/universal/serialize.js +4 -5
- package/dist/esm/version.js +5 -7
- package/dist/esm/wait.js +1 -3
- package/dist/esm/watch.js +14 -9
- package/dist/types/universal/pluginDagSort.d.ts +1 -0
- package/package.json +17 -5
package/dist/esm/path.js
CHANGED
|
@@ -2,29 +2,34 @@ import path from "path";
|
|
|
2
2
|
import os from "os";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { nanoid, upath, lodash as _ } from "./compiled";
|
|
5
|
-
const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
|
6
|
-
const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
|
|
7
|
-
const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
|
|
8
|
-
const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_2, m) => `/${m.toLowerCase()}`);
|
|
9
|
-
const getTemplatePath = (prefix) => {
|
|
5
|
+
export const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
|
6
|
+
export const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
|
|
7
|
+
export const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
|
|
8
|
+
export const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_2, m) => `/${m.toLowerCase()}`);
|
|
9
|
+
export const getTemplatePath = (prefix) => {
|
|
10
10
|
const tmpRoot = fs.realpathSync(os.tmpdir());
|
|
11
|
-
const parts = [
|
|
11
|
+
const parts = [
|
|
12
|
+
tmpRoot
|
|
13
|
+
];
|
|
12
14
|
prefix && parts.push(prefix);
|
|
13
15
|
parts.push(nanoid());
|
|
14
16
|
return path.resolve(...parts);
|
|
15
17
|
};
|
|
16
|
-
function compilePathMatcherRegExp(match) {
|
|
18
|
+
export function compilePathMatcherRegExp(match) {
|
|
17
19
|
if (typeof match !== "string") {
|
|
18
20
|
return match;
|
|
19
21
|
}
|
|
20
22
|
const escaped = _.escapeRegExp(match);
|
|
21
23
|
return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
|
|
22
24
|
}
|
|
23
|
-
const _joinPathParts = (_part, i, parts) => _(parts).filter((part) => ![
|
|
24
|
-
|
|
25
|
+
export const _joinPathParts = (_part, i, parts) => _(parts).filter((part) => ![
|
|
26
|
+
"/",
|
|
27
|
+
"\\"
|
|
28
|
+
].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
|
|
29
|
+
export function upwardPaths(start) {
|
|
25
30
|
return _(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
|
|
26
31
|
}
|
|
27
|
-
function getRealTemporaryDirectory() {
|
|
32
|
+
export function getRealTemporaryDirectory() {
|
|
28
33
|
let ret = null;
|
|
29
34
|
try {
|
|
30
35
|
ret = os.tmpdir();
|
|
@@ -33,18 +38,6 @@ function getRealTemporaryDirectory() {
|
|
|
33
38
|
}
|
|
34
39
|
return ret;
|
|
35
40
|
}
|
|
36
|
-
function splitPathString(str) {
|
|
41
|
+
export function splitPathString(str) {
|
|
37
42
|
return str.split(/[\\/]/);
|
|
38
43
|
}
|
|
39
|
-
export {
|
|
40
|
-
_joinPathParts,
|
|
41
|
-
compilePathMatcherRegExp,
|
|
42
|
-
getRealTemporaryDirectory,
|
|
43
|
-
getTemplatePath,
|
|
44
|
-
isPathString,
|
|
45
|
-
isRelativePath,
|
|
46
|
-
normalizeOutputPath,
|
|
47
|
-
normalizeToPosixPath,
|
|
48
|
-
splitPathString,
|
|
49
|
-
upwardPaths
|
|
50
|
-
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import os from "os";
|
|
2
2
|
import _ from "../compiled/lodash";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./path";
|
|
10
|
-
const matchUpwardPathsAsUnknown = (p) => _(upwardPaths(normalizeToPosixPath(p))).map((match) => ({ match, mark: "unknown" })).slice(1, -1).value();
|
|
11
|
-
function applyPathMatcher(matcher, str, options = {}) {
|
|
3
|
+
import { compilePathMatcherRegExp, normalizeToPosixPath, getRealTemporaryDirectory, splitPathString, upwardPaths } from "./path";
|
|
4
|
+
export const matchUpwardPathsAsUnknown = (p) => _(upwardPaths(normalizeToPosixPath(p))).map((match) => ({
|
|
5
|
+
match,
|
|
6
|
+
mark: "unknown"
|
|
7
|
+
})).slice(1, -1).value();
|
|
8
|
+
export function applyPathMatcher(matcher, str, options = {}) {
|
|
12
9
|
const regex = compilePathMatcherRegExp(matcher.match);
|
|
13
10
|
const replacer = (substring, ...args) => {
|
|
14
11
|
if (options.minPartials && splitPathString(substring).length < options.minPartials) {
|
|
@@ -19,28 +16,31 @@ function applyPathMatcher(matcher, str, options = {}) {
|
|
|
19
16
|
};
|
|
20
17
|
return str.replace(regex, replacer);
|
|
21
18
|
}
|
|
22
|
-
function applyMatcherReplacement(matchers, str, options = {}) {
|
|
19
|
+
export function applyMatcherReplacement(matchers, str, options = {}) {
|
|
23
20
|
return matchers.reduce((ret, matcher) => {
|
|
24
21
|
return applyPathMatcher(matcher, ret, options);
|
|
25
22
|
}, str);
|
|
26
23
|
}
|
|
27
|
-
const createDefaultPathMatchers = (root) => {
|
|
24
|
+
export const createDefaultPathMatchers = (root) => {
|
|
28
25
|
const ret = [
|
|
29
26
|
{
|
|
30
|
-
match:
|
|
27
|
+
match: RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
|
|
31
28
|
mark: "pnpmInner"
|
|
32
29
|
}
|
|
33
30
|
];
|
|
34
31
|
const tmpdir = getRealTemporaryDirectory();
|
|
35
|
-
tmpdir && ret.push({
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
tmpdir && ret.push({
|
|
33
|
+
match: tmpdir,
|
|
34
|
+
mark: "temp"
|
|
35
|
+
});
|
|
36
|
+
ret.push({
|
|
37
|
+
match: os.tmpdir(),
|
|
38
|
+
mark: "temp"
|
|
39
|
+
});
|
|
40
|
+
ret.push({
|
|
41
|
+
match: os.homedir(),
|
|
42
|
+
mark: "home"
|
|
43
|
+
});
|
|
38
44
|
ret.push(...matchUpwardPathsAsUnknown(root));
|
|
39
45
|
return ret;
|
|
40
46
|
};
|
|
41
|
-
export {
|
|
42
|
-
applyMatcherReplacement,
|
|
43
|
-
applyPathMatcher,
|
|
44
|
-
createDefaultPathMatchers,
|
|
45
|
-
matchUpwardPathsAsUnknown
|
|
46
|
-
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { INTERNAL_CLI_PLUGINS } from "./constants";
|
|
2
2
|
import { isDepExists } from "./is";
|
|
3
|
-
function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_PLUGINS) {
|
|
3
|
+
export function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_PLUGINS) {
|
|
4
4
|
return [
|
|
5
5
|
...Object.keys(internalPlugins).filter((name) => {
|
|
6
6
|
const config = internalPlugins[name];
|
|
@@ -18,6 +18,3 @@ function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_PLUGINS
|
|
|
18
18
|
})
|
|
19
19
|
];
|
|
20
20
|
}
|
|
21
|
-
export {
|
|
22
|
-
getInternalPlugins
|
|
23
|
-
};
|
|
@@ -3,7 +3,7 @@ import { chalk } from "./compiled";
|
|
|
3
3
|
import { isDev, isSingleEntry } from "./is";
|
|
4
4
|
import { DEFAULT_DEV_HOST } from "./constants";
|
|
5
5
|
const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, "$1");
|
|
6
|
-
const getIpv4Interfaces = () => {
|
|
6
|
+
export const getIpv4Interfaces = () => {
|
|
7
7
|
const interfaces = os.networkInterfaces();
|
|
8
8
|
const ipv4Interfaces = [];
|
|
9
9
|
Object.keys(interfaces).forEach((key) => {
|
|
@@ -16,10 +16,12 @@ const getIpv4Interfaces = () => {
|
|
|
16
16
|
});
|
|
17
17
|
return ipv4Interfaces;
|
|
18
18
|
};
|
|
19
|
-
const getAddressUrls = (protocol = "http", port, host) => {
|
|
19
|
+
export const getAddressUrls = (protocol = "http", port, host) => {
|
|
20
20
|
const LOCAL_LABEL = "Local: ";
|
|
21
21
|
const NETWORK_LABEL = "Network: ";
|
|
22
|
-
const isLocalhost = (url) =>
|
|
22
|
+
const isLocalhost = (url) => {
|
|
23
|
+
return url === null || url === void 0 ? void 0 : url.includes("localhost");
|
|
24
|
+
};
|
|
23
25
|
if (host && host !== DEFAULT_DEV_HOST) {
|
|
24
26
|
return [
|
|
25
27
|
{
|
|
@@ -44,23 +46,15 @@ const getAddressUrls = (protocol = "http", port, host) => {
|
|
|
44
46
|
return memo;
|
|
45
47
|
}, []);
|
|
46
48
|
};
|
|
47
|
-
const prettyInstructions = (appContext, config) => {
|
|
48
|
-
var
|
|
49
|
+
export const prettyInstructions = (appContext, config) => {
|
|
50
|
+
var _config_dev;
|
|
49
51
|
const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
|
|
50
|
-
const urls = getAddressUrls(
|
|
51
|
-
config.dev.https && isDev() ? "https" : "http",
|
|
52
|
-
port,
|
|
53
|
-
(_a = config.dev) == null ? void 0 : _a.host
|
|
54
|
-
);
|
|
52
|
+
const urls = getAddressUrls(config.dev.https && isDev() ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
|
|
55
53
|
const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
|
|
56
54
|
let message = "App running at:\n\n";
|
|
57
55
|
if (isSingleEntry(entrypoints) || apiOnly) {
|
|
58
|
-
message += urls.map(
|
|
59
|
-
|
|
60
|
-
normalizeUrl(`${url}/${routes[0].urlPath}`)
|
|
61
|
-
)}
|
|
62
|
-
`
|
|
63
|
-
).join("");
|
|
56
|
+
message += urls.map(({ label, url }) => ` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
|
|
57
|
+
`).join("");
|
|
64
58
|
} else {
|
|
65
59
|
const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
|
|
66
60
|
urls.forEach(({ label, url }) => {
|
|
@@ -70,26 +64,13 @@ const prettyInstructions = (appContext, config) => {
|
|
|
70
64
|
if (!checkedEntries.includes(entryName)) {
|
|
71
65
|
return;
|
|
72
66
|
}
|
|
73
|
-
message += ` ${chalk.yellowBright(
|
|
74
|
-
isSSR ? "λ" : "○"
|
|
75
|
-
)} ${chalk.yellowBright(
|
|
76
|
-
entryName.padEnd(maxNameLength + 8)
|
|
77
|
-
)}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}
|
|
67
|
+
message += ` ${chalk.yellowBright(isSSR ? "λ" : "○")} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}
|
|
78
68
|
`;
|
|
79
69
|
});
|
|
80
70
|
});
|
|
81
71
|
message += "\n";
|
|
82
|
-
message += chalk.cyanBright(
|
|
83
|
-
|
|
84
|
-
);
|
|
85
|
-
message += chalk.cyanBright(
|
|
86
|
-
" ○ (Static) client-side renders as static HTML\n"
|
|
87
|
-
);
|
|
72
|
+
message += chalk.cyanBright(" λ (Server) server-side renders at runtime\n");
|
|
73
|
+
message += chalk.cyanBright(" ○ (Static) client-side renders as static HTML\n");
|
|
88
74
|
}
|
|
89
75
|
return message;
|
|
90
76
|
};
|
|
91
|
-
export {
|
|
92
|
-
getAddressUrls,
|
|
93
|
-
getIpv4Interfaces,
|
|
94
|
-
prettyInstructions
|
|
95
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { chalk } from "./compiled";
|
|
2
2
|
import { logger } from "./logger";
|
|
3
|
-
function printBuildError(err) {
|
|
3
|
+
export function printBuildError(err) {
|
|
4
4
|
const message = err != null && err.message;
|
|
5
5
|
const stack = err != null && err.stack;
|
|
6
6
|
if (stack && typeof message === "string" && message.indexOf("from Terser") !== -1) {
|
|
@@ -12,14 +12,10 @@ function printBuildError(err) {
|
|
|
12
12
|
const problemPath = matched[2];
|
|
13
13
|
const line = matched[3];
|
|
14
14
|
const column = matched[4];
|
|
15
|
-
logger.error(
|
|
16
|
-
`Failed to minify the code from this file:
|
|
15
|
+
logger.error(`Failed to minify the code from this file:
|
|
17
16
|
|
|
18
|
-
${chalk.yellow(
|
|
19
|
-
|
|
20
|
-
)}
|
|
21
|
-
`
|
|
22
|
-
);
|
|
17
|
+
${chalk.yellow(` ${problemPath}:${line}${column !== "0" ? ":" + column : ""}`)}
|
|
18
|
+
`);
|
|
23
19
|
} catch (ignored) {
|
|
24
20
|
logger.error(`Failed to minify the bundle. ${err}
|
|
25
21
|
`);
|
|
@@ -29,6 +25,3 @@ function printBuildError(err) {
|
|
|
29
25
|
}
|
|
30
26
|
logger.log();
|
|
31
27
|
}
|
|
32
|
-
export {
|
|
33
|
-
printBuildError
|
|
34
|
-
};
|
package/dist/esm/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs, semver } from ".";
|
|
3
|
-
const isBeyondReact17 = (cwd) => {
|
|
3
|
+
export const isBeyondReact17 = (cwd) => {
|
|
4
4
|
const pkgPath = path.join(cwd, "package.json");
|
|
5
5
|
if (!fs.existsSync(pkgPath)) {
|
|
6
6
|
return false;
|
|
@@ -15,6 +15,3 @@ const isBeyondReact17 = (cwd) => {
|
|
|
15
15
|
}
|
|
16
16
|
return semver.satisfies(semver.minVersion(deps.react), ">=17.0.0");
|
|
17
17
|
};
|
|
18
|
-
export {
|
|
19
|
-
isBeyondReact17
|
|
20
|
-
};
|
package/dist/esm/readTsConfig.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs, json5 } from "./compiled";
|
|
3
|
-
const readTsConfig = (root) => {
|
|
3
|
+
export const readTsConfig = (root) => {
|
|
4
4
|
return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
|
|
5
5
|
};
|
|
6
|
-
const readTsConfigByFile = (filename) => {
|
|
6
|
+
export const readTsConfigByFile = (filename) => {
|
|
7
7
|
const content = fs.readFileSync(path.resolve(filename), "utf-8");
|
|
8
8
|
return json5.parse(content);
|
|
9
9
|
};
|
|
10
|
-
export {
|
|
11
|
-
readTsConfig,
|
|
12
|
-
readTsConfigByFile
|
|
13
|
-
};
|
package/dist/esm/removeSlash.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
|
|
2
|
-
const removeTailSlash = (s) => s.replace(/\/+$/, "");
|
|
3
|
-
const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
|
|
4
|
-
export {
|
|
5
|
-
removeLeadingSlash,
|
|
6
|
-
removeSlash,
|
|
7
|
-
removeTailSlash
|
|
8
|
-
};
|
|
1
|
+
export const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
|
|
2
|
+
export const removeTailSlash = (s) => s.replace(/\/+$/, "");
|
|
3
|
+
export const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
|
package/dist/esm/resolve.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { ensureArray } from "./ensureArray";
|
|
2
|
-
const tryResolve = (name, resolvePath) => {
|
|
2
|
+
export const tryResolve = (name, resolvePath) => {
|
|
3
3
|
let filePath = "";
|
|
4
4
|
try {
|
|
5
|
-
filePath = require.resolve(name, {
|
|
5
|
+
filePath = require.resolve(name, {
|
|
6
|
+
paths: [
|
|
7
|
+
resolvePath
|
|
8
|
+
]
|
|
9
|
+
});
|
|
6
10
|
delete require.cache[filePath];
|
|
7
11
|
} catch (err) {
|
|
8
12
|
if (err.code === "MODULE_NOT_FOUND") {
|
|
@@ -12,18 +16,22 @@ const tryResolve = (name, resolvePath) => {
|
|
|
12
16
|
}
|
|
13
17
|
return filePath;
|
|
14
18
|
};
|
|
15
|
-
const isPackageInstalled = (name, resolvePaths) => {
|
|
19
|
+
export const isPackageInstalled = (name, resolvePaths) => {
|
|
16
20
|
try {
|
|
17
|
-
require.resolve(name, {
|
|
21
|
+
require.resolve(name, {
|
|
22
|
+
paths: ensureArray(resolvePaths)
|
|
23
|
+
});
|
|
18
24
|
return true;
|
|
19
25
|
} catch (err) {
|
|
20
26
|
return false;
|
|
21
27
|
}
|
|
22
28
|
};
|
|
23
|
-
const getAntdMajorVersion = (appDirectory) => {
|
|
29
|
+
export const getAntdMajorVersion = (appDirectory) => {
|
|
24
30
|
try {
|
|
25
31
|
const pkgJsonPath = require.resolve("antd/package.json", {
|
|
26
|
-
paths: [
|
|
32
|
+
paths: [
|
|
33
|
+
appDirectory
|
|
34
|
+
]
|
|
27
35
|
});
|
|
28
36
|
const { version } = require(pkgJsonPath);
|
|
29
37
|
return Number(version.split(".")[0]);
|
|
@@ -31,8 +39,3 @@ const getAntdMajorVersion = (appDirectory) => {
|
|
|
31
39
|
return null;
|
|
32
40
|
}
|
|
33
41
|
};
|
|
34
|
-
export {
|
|
35
|
-
getAntdMajorVersion,
|
|
36
|
-
isPackageInstalled,
|
|
37
|
-
tryResolve
|
|
38
|
-
};
|
package/dist/esm/routes.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { normalizeToPosixPath } from "./path";
|
|
3
3
|
import { MAIN_ENTRY_NAME } from "./constants";
|
|
4
|
-
const getPathWithoutExt = (filename) => {
|
|
4
|
+
export const getPathWithoutExt = (filename) => {
|
|
5
5
|
const extname = path.extname(filename);
|
|
6
6
|
return filename.slice(0, -extname.length);
|
|
7
7
|
};
|
|
8
|
-
const getRouteId = (componentPath, routesDir, entryName) => {
|
|
9
|
-
const relativePath = normalizeToPosixPath(
|
|
10
|
-
path.relative(routesDir, componentPath)
|
|
11
|
-
);
|
|
8
|
+
export const getRouteId = (componentPath, routesDir, entryName) => {
|
|
9
|
+
const relativePath = normalizeToPosixPath(path.relative(routesDir, componentPath));
|
|
12
10
|
const pathWithoutExt = getPathWithoutExt(relativePath);
|
|
13
11
|
let id = ``;
|
|
14
12
|
if (entryName === MAIN_ENTRY_NAME) {
|
|
@@ -16,9 +14,5 @@ const getRouteId = (componentPath, routesDir, entryName) => {
|
|
|
16
14
|
} else {
|
|
17
15
|
id = `${entryName}_${pathWithoutExt}`;
|
|
18
16
|
}
|
|
19
|
-
return id;
|
|
20
|
-
};
|
|
21
|
-
export {
|
|
22
|
-
getPathWithoutExt,
|
|
23
|
-
getRouteId
|
|
17
|
+
return id.replace(/\[(.*?)\]/g, "($1)");
|
|
24
18
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const parsedJSONFromElement = (id) => {
|
|
1
|
+
export const parsedJSONFromElement = (id) => {
|
|
2
2
|
const element = document.getElementById(id);
|
|
3
3
|
if (element) {
|
|
4
4
|
try {
|
|
5
|
-
const parsed = JSON.parse(element.textContent || "");
|
|
5
|
+
const parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
|
|
6
6
|
return parsed;
|
|
7
7
|
} catch (e) {
|
|
8
8
|
console.error(`parse ${id} error`, e);
|
|
@@ -11,6 +11,3 @@ const parsedJSONFromElement = (id) => {
|
|
|
11
11
|
}
|
|
12
12
|
return void 0;
|
|
13
13
|
};
|
|
14
|
-
export {
|
|
15
|
-
parsedJSONFromElement
|
|
16
|
-
};
|
|
@@ -14,27 +14,22 @@ const memo = (fn) => {
|
|
|
14
14
|
return res;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
const createRuntimeExportsUtils = memo(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fs.appendFileSync(entryExportFile, `${statement}
|
|
17
|
+
export const createRuntimeExportsUtils = memo((pwd = "", namespace = "index") => {
|
|
18
|
+
const entryExportFile = path.join(pwd, `.runtime-exports/${namespace}.js`);
|
|
19
|
+
const addExport = (statement) => {
|
|
20
|
+
statement = normalizeOutputPath(statement);
|
|
21
|
+
try {
|
|
22
|
+
fs.ensureFileSync(entryExportFile);
|
|
23
|
+
if (!fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
|
|
24
|
+
fs.appendFileSync(entryExportFile, `${statement}
|
|
26
25
|
`);
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
26
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
createRuntimeExportsUtils
|
|
40
|
-
};
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const getPath = () => entryExportFile;
|
|
31
|
+
return {
|
|
32
|
+
addExport,
|
|
33
|
+
getPath
|
|
34
|
+
};
|
|
35
|
+
});
|
package/dist/esm/ssr.js
CHANGED
package/dist/esm/storage.js
CHANGED
|
@@ -26,9 +26,7 @@ const createStorage = () => {
|
|
|
26
26
|
}
|
|
27
27
|
const context = storage.getStore();
|
|
28
28
|
if (!context) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`
|
|
31
|
-
);
|
|
29
|
+
throw new Error(`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`);
|
|
32
30
|
}
|
|
33
31
|
return context;
|
|
34
32
|
};
|
|
@@ -37,6 +35,4 @@ const createStorage = () => {
|
|
|
37
35
|
useContext
|
|
38
36
|
};
|
|
39
37
|
};
|
|
40
|
-
export {
|
|
41
|
-
createStorage
|
|
42
|
-
};
|
|
38
|
+
export { createStorage };
|
package/dist/esm/testUtils.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
const initSnapshotSerializer = (root) => {
|
|
1
|
+
export const initSnapshotSerializer = (root) => {
|
|
2
2
|
expect.addSnapshotSerializer({
|
|
3
3
|
test: (val) => typeof val === "string" && (val.includes("modern.js") || val.includes("node_modules") || val.includes(root)),
|
|
4
4
|
print: (val) => (
|
|
5
5
|
// eslint-disable-next-line no-nested-ternary
|
|
6
|
-
typeof val === "string" ? (
|
|
7
|
-
// eslint-disable-next-line no-nested-ternary
|
|
8
|
-
val.includes("node_modules") ? `"${val.replace(/.+node_modules/, ``).replace(/\\/g, "/")}"` : val.includes("modern.js") ? `"${val.replace(/.+modern\.js/, ``).replace(/\\/g, "/")}"` : `"${val.replace(root, "").replace(/\\/g, "/")}"`
|
|
9
|
-
) : val
|
|
6
|
+
typeof val === "string" ? val.includes("node_modules") ? `"${val.replace(/.+node_modules/, ``).replace(/\\/g, "/")}"` : val.includes("modern.js") ? `"${val.replace(/.+modern\.js/, ``).replace(/\\/g, "/")}"` : `"${val.replace(root, "").replace(/\\/g, "/")}"` : val
|
|
10
7
|
)
|
|
11
8
|
});
|
|
12
9
|
};
|
|
13
|
-
export {
|
|
14
|
-
initSnapshotSerializer
|
|
15
|
-
};
|
package/dist/esm/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -20,9 +20,7 @@ ${stats.stack}` : "";
|
|
|
20
20
|
}
|
|
21
21
|
lines = message.split("\n");
|
|
22
22
|
lines = lines.map((line) => {
|
|
23
|
-
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
|
|
24
|
-
line
|
|
25
|
-
);
|
|
23
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
|
26
24
|
if (!parsingError) {
|
|
27
25
|
return line;
|
|
28
26
|
}
|
|
@@ -30,11 +28,8 @@ ${stats.stack}` : "";
|
|
|
30
28
|
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
|
31
29
|
});
|
|
32
30
|
message = lines.join("\n");
|
|
33
|
-
message = message.replace(
|
|
34
|
-
|
|
35
|
-
`${friendlySyntaxErrorLabel} $3 ($1:$2)
|
|
36
|
-
`
|
|
37
|
-
);
|
|
31
|
+
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)
|
|
32
|
+
`);
|
|
38
33
|
lines = message.split("\n");
|
|
39
34
|
if (lines.length > 2 && lines[1].trim() === "") {
|
|
40
35
|
lines.splice(1, 1);
|
|
@@ -44,27 +39,22 @@ ${stats.stack}` : "";
|
|
|
44
39
|
lines[1] = lines[1].replace("Error: ", "");
|
|
45
40
|
}
|
|
46
41
|
message = lines.join("\n");
|
|
47
|
-
message = message.replace(
|
|
48
|
-
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
|
|
49
|
-
""
|
|
50
|
-
);
|
|
42
|
+
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, "");
|
|
51
43
|
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, "");
|
|
52
44
|
lines = message.split("\n");
|
|
53
|
-
lines = lines.filter(
|
|
54
|
-
(line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
|
|
55
|
-
);
|
|
45
|
+
lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
|
|
56
46
|
message = lines.join("\n");
|
|
57
47
|
return message.trim();
|
|
58
48
|
}
|
|
59
49
|
function formatWebpackMessages(json) {
|
|
60
|
-
var
|
|
61
|
-
const formattedErrors =
|
|
62
|
-
const formattedWarnings =
|
|
50
|
+
var _json_errors, _json_warnings, _result_errors;
|
|
51
|
+
const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
|
52
|
+
const formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
|
63
53
|
const result = {
|
|
64
54
|
errors: formattedErrors || [],
|
|
65
55
|
warnings: formattedWarnings || []
|
|
66
56
|
};
|
|
67
|
-
if ((
|
|
57
|
+
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
|
68
58
|
result.errors = result.errors.filter(isLikelyASyntaxError);
|
|
69
59
|
}
|
|
70
60
|
if (result.errors.length > 1) {
|
|
@@ -72,6 +62,4 @@ function formatWebpackMessages(json) {
|
|
|
72
62
|
}
|
|
73
63
|
return result;
|
|
74
64
|
}
|
|
75
|
-
export {
|
|
76
|
-
formatWebpackMessages
|
|
77
|
-
};
|
|
65
|
+
export { formatWebpackMessages };
|