@modern-js/utils 2.22.0 → 2.22.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/FileSizeReporter.d.ts +16 -0
- package/dist/FileSizeReporter.js +162 -0
- package/dist/alias.d.ts +25 -0
- package/dist/alias.js +108 -0
- package/dist/analyzeProject.d.ts +2 -0
- package/dist/analyzeProject.js +71 -0
- package/dist/applyOptionsChain.d.ts +3 -0
- package/dist/applyOptionsChain.js +58 -0
- package/dist/babel.d.ts +3 -0
- package/dist/babel.js +136 -0
- package/dist/chainId.d.ts +244 -0
- package/dist/chainId.js +196 -0
- package/dist/cjs/cli/constants/index.js +4 -0
- package/dist/cjs/runtime-node/walk.js +1 -0
- package/dist/cjs/universal/constants.js +4 -0
- package/dist/clearConsole.d.ts +1 -0
- package/dist/clearConsole.js +31 -0
- package/dist/commands.d.ts +4 -0
- package/dist/commands.js +48 -0
- package/dist/compatRequire.d.ts +13 -0
- package/dist/compatRequire.js +82 -0
- package/dist/compiled.d.ts +43 -0
- package/dist/compiled.js +142 -0
- package/dist/constants.d.ts +244 -0
- package/dist/constants.js +320 -0
- package/dist/debug.d.ts +6 -0
- package/dist/debug.js +28 -0
- package/dist/emptyDir.d.ts +1 -0
- package/dist/emptyDir.js +52 -0
- package/dist/ensureAbsolutePath.d.ts +7 -0
- package/dist/ensureAbsolutePath.js +38 -0
- package/dist/ensureArray.d.ts +1 -0
- package/dist/ensureArray.js +32 -0
- package/dist/esm/cli/constants/index.js +1 -0
- package/dist/esm/runtime-node/walk.js +0 -0
- package/dist/esm/universal/constants.js +1 -0
- package/dist/findExists.d.ts +6 -0
- package/dist/findExists.js +45 -0
- package/dist/generateMetaTags.d.ts +16 -0
- package/dist/generateMetaTags.js +61 -0
- package/dist/getBrowserslist.d.ts +2 -0
- package/dist/getBrowserslist.js +31 -0
- package/dist/getCoreJsVersion.d.ts +1 -0
- package/dist/getCoreJsVersion.js +46 -0
- package/dist/getEntryOptions.d.ts +1 -0
- package/dist/getEntryOptions.js +54 -0
- package/dist/getPackageManager.d.ts +1 -0
- package/dist/getPackageManager.js +87 -0
- package/dist/getPort.d.ts +14 -0
- package/dist/getPort.js +112 -0
- package/dist/getServerConfig.d.ts +1 -0
- package/dist/getServerConfig.js +67 -0
- package/dist/getTargetDir.d.ts +1 -0
- package/dist/getTargetDir.js +41 -0
- package/dist/import.d.ts +5 -0
- package/dist/import.js +33 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +60 -0
- package/dist/is/index.d.ts +58 -0
- package/dist/is/index.js +114 -0
- package/dist/is/nodeEnv.d.ts +8 -0
- package/dist/is/nodeEnv.js +39 -0
- package/dist/is/platform.d.ts +2 -0
- package/dist/is/platform.js +30 -0
- package/dist/is/type.d.ts +8 -0
- package/dist/is/type.js +64 -0
- package/dist/logger.d.ts +65 -0
- package/dist/logger.js +145 -0
- package/dist/monorepo.d.ts +11 -0
- package/dist/monorepo.js +137 -0
- package/dist/nodeEnv.d.ts +3 -0
- package/dist/nodeEnv.js +81 -0
- package/dist/path.d.ts +18 -0
- package/dist/path.js +92 -0
- package/dist/pathSerializer.d.ts +16 -0
- package/dist/pathSerializer.js +76 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +46 -0
- package/dist/prettyInstructions.d.ts +9 -0
- package/dist/prettyInstructions.js +112 -0
- package/dist/printBuildError.d.ts +8 -0
- package/dist/printBuildError.js +57 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +64 -0
- package/dist/readTsConfig.d.ts +2 -0
- package/dist/readTsConfig.js +47 -0
- package/dist/removeSlash.d.ts +3 -0
- package/dist/removeSlash.js +33 -0
- package/dist/resolve.d.ts +13 -0
- package/dist/resolve.js +63 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +58 -0
- package/dist/runtimeExports.d.ts +4 -0
- package/dist/runtimeExports.js +73 -0
- package/dist/ssr.d.ts +8 -0
- package/dist/ssr.js +30 -0
- package/dist/storage.d.ts +5 -0
- package/dist/storage.js +75 -0
- package/dist/testUtils.d.ts +5 -0
- package/dist/testUtils.js +38 -0
- package/dist/types/cli/constants/index.d.ts +4 -0
- package/dist/types/runtime-node/walk.d.ts +0 -0
- package/dist/types/universal/constants.d.ts +5 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.js +15 -0
- package/dist/universal/constants.d.ts +9 -0
- package/dist/universal/constants.js +30 -0
- package/dist/universal/formatWebpack.d.ts +13 -0
- package/dist/universal/formatWebpack.js +100 -0
- package/dist/universal/nestedRoutes.d.ts +8 -0
- package/dist/universal/nestedRoutes.js +131 -0
- package/dist/universal/remixRouter.d.ts +1 -0
- package/dist/universal/remixRouter.js +17 -0
- package/dist/universal/serialize.d.ts +1 -0
- package/dist/universal/serialize.js +40 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +92 -0
- package/dist/wait.d.ts +2 -0
- package/dist/wait.js +29 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +90 -0
- package/package.json +12 -3
@@ -0,0 +1,33 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var removeSlash_exports = {};
|
19
|
+
__export(removeSlash_exports, {
|
20
|
+
removeLeadingSlash: () => removeLeadingSlash,
|
21
|
+
removeSlash: () => removeSlash,
|
22
|
+
removeTailSlash: () => removeTailSlash
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(removeSlash_exports);
|
25
|
+
const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
|
26
|
+
const removeTailSlash = (s) => s.replace(/\/+$/, "");
|
27
|
+
const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
29
|
+
0 && (module.exports = {
|
30
|
+
removeLeadingSlash,
|
31
|
+
removeSlash,
|
32
|
+
removeTailSlash
|
33
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Try to resolve npm package entry file path.
|
3
|
+
* @param name - Package name.
|
4
|
+
* @param resolvePath - Path to resolve dependencies.
|
5
|
+
* @returns Resolved file path.
|
6
|
+
*/
|
7
|
+
export declare const tryResolve: (name: string, resolvePath: string) => string;
|
8
|
+
/**
|
9
|
+
* Try to resolve npm package, return true if package is installed.
|
10
|
+
*/
|
11
|
+
|
12
|
+
export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
|
13
|
+
export declare const getAntdMajorVersion: (appDirectory: string) => number | null;
|
package/dist/resolve.js
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var resolve_exports = {};
|
19
|
+
__export(resolve_exports, {
|
20
|
+
getAntdMajorVersion: () => getAntdMajorVersion,
|
21
|
+
isPackageInstalled: () => isPackageInstalled,
|
22
|
+
tryResolve: () => tryResolve
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(resolve_exports);
|
25
|
+
var import_ensureArray = require("./ensureArray");
|
26
|
+
const tryResolve = (name, resolvePath) => {
|
27
|
+
let filePath = "";
|
28
|
+
try {
|
29
|
+
filePath = require.resolve(name, { paths: [resolvePath] });
|
30
|
+
delete require.cache[filePath];
|
31
|
+
} catch (err) {
|
32
|
+
if (err.code === "MODULE_NOT_FOUND") {
|
33
|
+
throw new Error(`Can not find module ${name}.`);
|
34
|
+
}
|
35
|
+
throw err;
|
36
|
+
}
|
37
|
+
return filePath;
|
38
|
+
};
|
39
|
+
const isPackageInstalled = (name, resolvePaths) => {
|
40
|
+
try {
|
41
|
+
require.resolve(name, { paths: (0, import_ensureArray.ensureArray)(resolvePaths) });
|
42
|
+
return true;
|
43
|
+
} catch (err) {
|
44
|
+
return false;
|
45
|
+
}
|
46
|
+
};
|
47
|
+
const getAntdMajorVersion = (appDirectory) => {
|
48
|
+
try {
|
49
|
+
const pkgJsonPath = require.resolve("antd/package.json", {
|
50
|
+
paths: [appDirectory]
|
51
|
+
});
|
52
|
+
const { version } = require(pkgJsonPath);
|
53
|
+
return Number(version.split(".")[0]);
|
54
|
+
} catch (err) {
|
55
|
+
return null;
|
56
|
+
}
|
57
|
+
};
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
59
|
+
0 && (module.exports = {
|
60
|
+
getAntdMajorVersion,
|
61
|
+
isPackageInstalled,
|
62
|
+
tryResolve
|
63
|
+
});
|
package/dist/routes.d.ts
ADDED
package/dist/routes.js
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
+
var routes_exports = {};
|
29
|
+
__export(routes_exports, {
|
30
|
+
getPathWithoutExt: () => getPathWithoutExt,
|
31
|
+
getRouteId: () => getRouteId
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(routes_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_path2 = require("./path");
|
36
|
+
var import_constants = require("./constants");
|
37
|
+
const getPathWithoutExt = (filename) => {
|
38
|
+
const extname = import_path.default.extname(filename);
|
39
|
+
return filename.slice(0, -extname.length);
|
40
|
+
};
|
41
|
+
const getRouteId = (componentPath, routesDir, entryName) => {
|
42
|
+
const relativePath = (0, import_path2.normalizeToPosixPath)(
|
43
|
+
import_path.default.relative(routesDir, componentPath)
|
44
|
+
);
|
45
|
+
const pathWithoutExt = getPathWithoutExt(relativePath);
|
46
|
+
let id = ``;
|
47
|
+
if (entryName === import_constants.MAIN_ENTRY_NAME) {
|
48
|
+
id = pathWithoutExt;
|
49
|
+
} else {
|
50
|
+
id = `${entryName}_${pathWithoutExt}`;
|
51
|
+
}
|
52
|
+
return id;
|
53
|
+
};
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
55
|
+
0 && (module.exports = {
|
56
|
+
getPathWithoutExt,
|
57
|
+
getRouteId
|
58
|
+
});
|
@@ -0,0 +1,73 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
+
var runtimeExports_exports = {};
|
29
|
+
__export(runtimeExports_exports, {
|
30
|
+
createRuntimeExportsUtils: () => createRuntimeExportsUtils
|
31
|
+
});
|
32
|
+
module.exports = __toCommonJS(runtimeExports_exports);
|
33
|
+
var import_path = __toESM(require("path"));
|
34
|
+
var import_compiled = require("./compiled");
|
35
|
+
var import_path2 = require("./path");
|
36
|
+
const memo = (fn) => {
|
37
|
+
const cache = /* @__PURE__ */ new Map();
|
38
|
+
return (...params) => {
|
39
|
+
const stringifiedParams = JSON.stringify(params);
|
40
|
+
const cachedResult = cache.get(stringifiedParams);
|
41
|
+
if (cachedResult) {
|
42
|
+
return cachedResult;
|
43
|
+
}
|
44
|
+
const res = fn(...params);
|
45
|
+
cache.set(stringifiedParams, res);
|
46
|
+
return res;
|
47
|
+
};
|
48
|
+
};
|
49
|
+
const createRuntimeExportsUtils = memo(
|
50
|
+
(pwd = "", namespace = "index") => {
|
51
|
+
const entryExportFile = import_path.default.join(pwd, `.runtime-exports/${namespace}.js`);
|
52
|
+
const addExport = (statement) => {
|
53
|
+
statement = (0, import_path2.normalizeOutputPath)(statement);
|
54
|
+
try {
|
55
|
+
import_compiled.fs.ensureFileSync(entryExportFile);
|
56
|
+
if (!import_compiled.fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
|
57
|
+
import_compiled.fs.appendFileSync(entryExportFile, `${statement}
|
58
|
+
`);
|
59
|
+
}
|
60
|
+
} catch (e) {
|
61
|
+
}
|
62
|
+
};
|
63
|
+
const getPath = () => entryExportFile;
|
64
|
+
return {
|
65
|
+
addExport,
|
66
|
+
getPath
|
67
|
+
};
|
68
|
+
}
|
69
|
+
);
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
71
|
+
0 && (module.exports = {
|
72
|
+
createRuntimeExportsUtils
|
73
|
+
});
|
package/dist/ssr.d.ts
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
|
3
|
+
/**
|
4
|
+
* ssr helpers
|
5
|
+
*/
|
6
|
+
import type { IncomingHttpHeaders } from 'http';
|
7
|
+
declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
|
8
|
+
export { run, useHeaders };
|
package/dist/ssr.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var ssr_exports = {};
|
19
|
+
__export(ssr_exports, {
|
20
|
+
run: () => run,
|
21
|
+
useHeaders: () => useHeaders
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(ssr_exports);
|
24
|
+
var import_storage = require("./storage");
|
25
|
+
const { run, useContext: useHeaders } = (0, import_storage.createStorage)();
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
27
|
+
0 && (module.exports = {
|
28
|
+
run,
|
29
|
+
useHeaders
|
30
|
+
});
|
package/dist/storage.js
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
+
var storage_exports = {};
|
29
|
+
__export(storage_exports, {
|
30
|
+
createStorage: () => createStorage
|
31
|
+
});
|
32
|
+
module.exports = __toCommonJS(storage_exports);
|
33
|
+
var ah = __toESM(require("async_hooks"));
|
34
|
+
const createStorage = () => {
|
35
|
+
let storage;
|
36
|
+
if (typeof ah.AsyncLocalStorage !== "undefined") {
|
37
|
+
storage = new ah.AsyncLocalStorage();
|
38
|
+
}
|
39
|
+
const run = (context, cb) => {
|
40
|
+
if (!storage) {
|
41
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
42
|
+
`);
|
43
|
+
}
|
44
|
+
return new Promise((resolve, reject) => {
|
45
|
+
storage.run(context, () => {
|
46
|
+
try {
|
47
|
+
return resolve(cb());
|
48
|
+
} catch (error) {
|
49
|
+
return reject(error);
|
50
|
+
}
|
51
|
+
});
|
52
|
+
});
|
53
|
+
};
|
54
|
+
const useContext = () => {
|
55
|
+
if (!storage) {
|
56
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
57
|
+
`);
|
58
|
+
}
|
59
|
+
const context = storage.getStore();
|
60
|
+
if (!context) {
|
61
|
+
throw new Error(
|
62
|
+
`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`
|
63
|
+
);
|
64
|
+
}
|
65
|
+
return context;
|
66
|
+
};
|
67
|
+
return {
|
68
|
+
run,
|
69
|
+
useContext
|
70
|
+
};
|
71
|
+
};
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
73
|
+
0 && (module.exports = {
|
74
|
+
createStorage
|
75
|
+
});
|
@@ -0,0 +1,38 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var testUtils_exports = {};
|
19
|
+
__export(testUtils_exports, {
|
20
|
+
initSnapshotSerializer: () => initSnapshotSerializer
|
21
|
+
});
|
22
|
+
module.exports = __toCommonJS(testUtils_exports);
|
23
|
+
const initSnapshotSerializer = (root) => {
|
24
|
+
expect.addSnapshotSerializer({
|
25
|
+
test: (val) => typeof val === "string" && (val.includes("modern.js") || val.includes("node_modules") || val.includes(root)),
|
26
|
+
print: (val) => (
|
27
|
+
// eslint-disable-next-line no-nested-ternary
|
28
|
+
typeof val === "string" ? (
|
29
|
+
// eslint-disable-next-line no-nested-ternary
|
30
|
+
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, "/")}"`
|
31
|
+
) : val
|
32
|
+
)
|
33
|
+
});
|
34
|
+
};
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
36
|
+
0 && (module.exports = {
|
37
|
+
initSnapshotSerializer
|
38
|
+
});
|
@@ -3,6 +3,10 @@ import { InternalPlugins } from '@modern-js/types';
|
|
3
3
|
* route specification file
|
4
4
|
*/
|
5
5
|
export declare const ROUTE_SPEC_FILE = "route.json";
|
6
|
+
/**
|
7
|
+
* Front-end routing metadata
|
8
|
+
*/
|
9
|
+
export declare const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
|
6
10
|
/**
|
7
11
|
* main entry name
|
8
12
|
*/
|
File without changes
|
@@ -5,4 +5,8 @@ export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
|
|
5
5
|
/**
|
6
6
|
* hmr socket connect path
|
7
7
|
*/
|
8
|
-
export declare const HMR_SOCK_PATH = "/webpack-hmr";
|
8
|
+
export declare const HMR_SOCK_PATH = "/webpack-hmr";
|
9
|
+
/**
|
10
|
+
* html placeholder
|
11
|
+
*/
|
12
|
+
export declare const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export type Falsy = false | null | undefined | 0 | '';
|
package/dist/types.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
7
|
+
for (let key of __getOwnPropNames(from))
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
10
|
+
}
|
11
|
+
return to;
|
12
|
+
};
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
14
|
+
var types_exports = {};
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
@@ -0,0 +1,30 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var constants_exports = {};
|
19
|
+
__export(constants_exports, {
|
20
|
+
HMR_SOCK_PATH: () => HMR_SOCK_PATH,
|
21
|
+
ROUTE_MANIFEST: () => ROUTE_MANIFEST
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
24
|
+
const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
|
25
|
+
const HMR_SOCK_PATH = "/webpack-hmr";
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
27
|
+
0 && (module.exports = {
|
28
|
+
HMR_SOCK_PATH,
|
29
|
+
ROUTE_MANIFEST
|
30
|
+
});
|
@@ -0,0 +1,13 @@
|
|
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
|
+
import type { StatsCompilation } from 'webpack';
|
9
|
+
declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
|
10
|
+
errors: string[];
|
11
|
+
warnings: string[];
|
12
|
+
};
|
13
|
+
export { formatWebpackMessages };
|
@@ -0,0 +1,100 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var formatWebpack_exports = {};
|
19
|
+
__export(formatWebpack_exports, {
|
20
|
+
formatWebpackMessages: () => formatWebpackMessages
|
21
|
+
});
|
22
|
+
module.exports = __toCommonJS(formatWebpack_exports);
|
23
|
+
const friendlySyntaxErrorLabel = "SyntaxError:";
|
24
|
+
function isLikelyASyntaxError(message) {
|
25
|
+
return message.includes(friendlySyntaxErrorLabel);
|
26
|
+
}
|
27
|
+
function formatMessage(stats) {
|
28
|
+
let lines = [];
|
29
|
+
let message;
|
30
|
+
if (typeof stats === "object") {
|
31
|
+
const fileName = stats.moduleName ? `File: ${stats.moduleName}
|
32
|
+
` : "";
|
33
|
+
const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
|
34
|
+
const details = stats.details ? `
|
35
|
+
Details: ${stats.details}
|
36
|
+
` : "";
|
37
|
+
const stack = stats.stack ? `
|
38
|
+
${stats.stack}` : "";
|
39
|
+
message = `${fileName}${mainMessage}${details}${stack}`;
|
40
|
+
} else {
|
41
|
+
message = stats;
|
42
|
+
}
|
43
|
+
lines = message.split("\n");
|
44
|
+
lines = lines.map((line) => {
|
45
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
|
46
|
+
line
|
47
|
+
);
|
48
|
+
if (!parsingError) {
|
49
|
+
return line;
|
50
|
+
}
|
51
|
+
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
52
|
+
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
53
|
+
});
|
54
|
+
message = lines.join("\n");
|
55
|
+
message = message.replace(
|
56
|
+
/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
|
57
|
+
`${friendlySyntaxErrorLabel} $3 ($1:$2)
|
58
|
+
`
|
59
|
+
);
|
60
|
+
lines = message.split("\n");
|
61
|
+
if (lines.length > 2 && lines[1].trim() === "") {
|
62
|
+
lines.splice(1, 1);
|
63
|
+
}
|
64
|
+
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
|
65
|
+
if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
|
66
|
+
lines[1] = lines[1].replace("Error: ", "");
|
67
|
+
}
|
68
|
+
message = lines.join("\n");
|
69
|
+
message = message.replace(
|
70
|
+
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
|
71
|
+
""
|
72
|
+
);
|
73
|
+
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, "");
|
74
|
+
lines = message.split("\n");
|
75
|
+
lines = lines.filter(
|
76
|
+
(line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
|
77
|
+
);
|
78
|
+
message = lines.join("\n");
|
79
|
+
return message.trim();
|
80
|
+
}
|
81
|
+
function formatWebpackMessages(json) {
|
82
|
+
var _a, _b, _c;
|
83
|
+
const formattedErrors = (_a = json == null ? void 0 : json.errors) == null ? void 0 : _a.map(formatMessage);
|
84
|
+
const formattedWarnings = (_b = json == null ? void 0 : json.warnings) == null ? void 0 : _b.map(formatMessage);
|
85
|
+
const result = {
|
86
|
+
errors: formattedErrors || [],
|
87
|
+
warnings: formattedWarnings || []
|
88
|
+
};
|
89
|
+
if ((_c = result.errors) == null ? void 0 : _c.some(isLikelyASyntaxError)) {
|
90
|
+
result.errors = result.errors.filter(isLikelyASyntaxError);
|
91
|
+
}
|
92
|
+
if (result.errors.length > 1) {
|
93
|
+
result.errors.length = 1;
|
94
|
+
}
|
95
|
+
return result;
|
96
|
+
}
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
98
|
+
0 && (module.exports = {
|
99
|
+
formatWebpackMessages
|
100
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import type { NestedRoute } from '@modern-js/types';
|
3
|
+
export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
|
4
|
+
export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
|
5
|
+
parent?: NestedRoute;
|
6
|
+
DeferredDataComponent?: () => JSX.Element | null;
|
7
|
+
props?: Record<string, any>;
|
8
|
+
}) => JSX.Element;
|