@modern-js/utils 2.15.1-alpha.0 → 2.17.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -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 +22 -42
- 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 +3 -9
- 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
@@ -1,5 +1,2 @@
|
|
1
1
|
import path from "path";
|
2
|
-
const ensureAbsolutePath = (base, filePath) => path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
|
3
|
-
export {
|
4
|
-
ensureAbsolutePath
|
5
|
-
};
|
2
|
+
export const ensureAbsolutePath = (base, filePath) => path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
|
package/dist/esm/ensureArray.js
CHANGED
package/dist/esm/findExists.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import fs from "fs";
|
2
|
-
const findExists = (files) => {
|
2
|
+
export const findExists = (files) => {
|
3
3
|
for (const file of files) {
|
4
4
|
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
|
5
5
|
return file;
|
@@ -7,6 +7,3 @@ const findExists = (files) => {
|
|
7
7
|
}
|
8
8
|
return false;
|
9
9
|
};
|
10
|
-
export {
|
11
|
-
findExists
|
12
|
-
};
|
@@ -5,9 +5,11 @@ const tagObjectToString = (tagDefinition) => {
|
|
5
5
|
}
|
6
6
|
return `${attributeName}="${tagDefinition.attributes[attributeName]}"`;
|
7
7
|
});
|
8
|
-
return `<${[
|
8
|
+
return `<${[
|
9
|
+
tagDefinition.tagName
|
10
|
+
].concat(attributes).join(" ")}>${tagDefinition.innerHTML || ""}${tagDefinition.voidTag ? "" : `</${tagDefinition.tagName}>`}`;
|
9
11
|
};
|
10
|
-
const generateMetaTags = (metaOptions) => {
|
12
|
+
export const generateMetaTags = (metaOptions) => {
|
11
13
|
if (!metaOptions) {
|
12
14
|
return "";
|
13
15
|
}
|
@@ -27,12 +29,6 @@ const generateMetaTags = (metaOptions) => {
|
|
27
29
|
voidTag: true,
|
28
30
|
attributes: metaTagAttributes
|
29
31
|
};
|
30
|
-
}).reduce(
|
31
|
-
|
32
|
-
${tagObjectToString(tagObject)}`,
|
33
|
-
""
|
34
|
-
);
|
35
|
-
};
|
36
|
-
export {
|
37
|
-
generateMetaTags
|
32
|
+
}).reduce((memo, tagObject) => `${memo}
|
33
|
+
${tagObjectToString(tagObject)}`, "");
|
38
34
|
};
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { browserslist } from "./compiled";
|
2
|
-
const defaults = [
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
export const defaults = [
|
3
|
+
"> 0.01%",
|
4
|
+
"not dead",
|
5
|
+
"not op_mini all"
|
6
|
+
];
|
7
|
+
export const getBrowserslist = (appDirectory) => browserslist.loadConfig({
|
8
|
+
path: appDirectory
|
9
|
+
}) || defaults;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as fs from "../compiled/fs-extra";
|
2
|
-
const getCoreJsVersion = (corejsPkgPath) => {
|
2
|
+
export const getCoreJsVersion = (corejsPkgPath) => {
|
3
3
|
try {
|
4
4
|
const { version } = fs.readJSONSync(corejsPkgPath);
|
5
5
|
const [major, minor] = version.split(".");
|
@@ -8,6 +8,3 @@ const getCoreJsVersion = (corejsPkgPath) => {
|
|
8
8
|
return "3";
|
9
9
|
}
|
10
10
|
};
|
11
|
-
export {
|
12
|
-
getCoreJsVersion
|
13
|
-
};
|
@@ -1,17 +1,17 @@
|
|
1
1
|
import { isPlainObject } from "./is";
|
2
2
|
import { MAIN_ENTRY_NAME } from "./constants";
|
3
|
-
const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
|
3
|
+
export const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
|
4
4
|
if (optionsByEntries) {
|
5
5
|
let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
|
6
6
|
if (optionsByEntry === void 0 && name === MAIN_ENTRY_NAME && packageName) {
|
7
7
|
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
8
8
|
}
|
9
|
-
return optionsByEntry !== void 0 ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? {
|
9
|
+
return optionsByEntry !== void 0 ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? {
|
10
|
+
...baseOptions,
|
11
|
+
...optionsByEntry
|
12
|
+
} : optionsByEntry : baseOptions;
|
10
13
|
} else {
|
11
14
|
return baseOptions;
|
12
15
|
}
|
13
16
|
};
|
14
17
|
const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
|
15
|
-
export {
|
16
|
-
getEntryOptions
|
17
|
-
};
|
@@ -3,7 +3,7 @@ import path from "path";
|
|
3
3
|
import { fs } from "./compiled";
|
4
4
|
import { canUsePnpm, canUseYarn } from "./nodeEnv";
|
5
5
|
const MAX_TIMES = 5;
|
6
|
-
async function getPackageManager(cwd = process.cwd()) {
|
6
|
+
export async function getPackageManager(cwd = process.cwd()) {
|
7
7
|
let appDirectory = cwd;
|
8
8
|
let times = 0;
|
9
9
|
while (os.homedir() !== appDirectory && times < MAX_TIMES) {
|
@@ -27,6 +27,3 @@ async function getPackageManager(cwd = process.cwd()) {
|
|
27
27
|
}
|
28
28
|
return "npm";
|
29
29
|
}
|
30
|
-
export {
|
31
|
-
getPackageManager
|
32
|
-
};
|
package/dist/esm/getPort.js
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
import net from "net";
|
2
2
|
import { chalk } from "./compiled";
|
3
3
|
import { logger } from "./logger";
|
4
|
-
const getPort = async (port, {
|
5
|
-
tryLimits = 20,
|
6
|
-
strictPort = false
|
7
|
-
} = {}) => {
|
4
|
+
export const getPort = async (port, { tryLimits = 20, strictPort = false } = {}) => {
|
8
5
|
if (typeof port === "string") {
|
9
6
|
port = parseInt(port, 10);
|
10
7
|
}
|
@@ -20,16 +17,13 @@ const getPort = async (port, {
|
|
20
17
|
const server = net.createServer();
|
21
18
|
server.unref();
|
22
19
|
server.on("error", reject);
|
23
|
-
server.listen(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
()
|
29
|
-
|
30
|
-
server.close(resolve);
|
31
|
-
}
|
32
|
-
);
|
20
|
+
server.listen({
|
21
|
+
port,
|
22
|
+
host: "0.0.0.0"
|
23
|
+
}, () => {
|
24
|
+
found = true;
|
25
|
+
server.close(resolve);
|
26
|
+
});
|
33
27
|
});
|
34
28
|
} catch (e) {
|
35
29
|
if (e.code !== "EADDRINUSE") {
|
@@ -41,19 +35,10 @@ const getPort = async (port, {
|
|
41
35
|
}
|
42
36
|
if (port !== original) {
|
43
37
|
if (strictPort) {
|
44
|
-
throw new Error(
|
45
|
-
`Port "${original}" is occupied, please choose another one.`
|
46
|
-
);
|
38
|
+
throw new Error(`Port "${original}" is occupied, please choose another one.`);
|
47
39
|
} else {
|
48
|
-
logger.info(
|
49
|
-
`Something is already running on port ${original}. ${chalk.yellow(
|
50
|
-
`Use port ${port} instead.`
|
51
|
-
)}`
|
52
|
-
);
|
40
|
+
logger.info(`Something is already running on port ${original}. ${chalk.yellow(`Use port ${port} instead.`)}`);
|
53
41
|
}
|
54
42
|
}
|
55
43
|
return port;
|
56
44
|
};
|
57
|
-
export {
|
58
|
-
getPort
|
59
|
-
};
|
@@ -1,14 +1,7 @@
|
|
1
1
|
import * as path from "path";
|
2
2
|
import { CONFIG_FILE_EXTENSIONS } from "./constants";
|
3
3
|
import { findExists } from "./findExists";
|
4
|
-
const getServerConfig = async (appDirectory, configFile) => {
|
5
|
-
const configFilePath = findExists(
|
6
|
-
CONFIG_FILE_EXTENSIONS.map(
|
7
|
-
(extension) => path.resolve(appDirectory, `${configFile}${extension}`)
|
8
|
-
)
|
9
|
-
);
|
4
|
+
export const getServerConfig = async (appDirectory, configFile) => {
|
5
|
+
const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(appDirectory, `${configFile}${extension}`)));
|
10
6
|
return configFilePath;
|
11
7
|
};
|
12
|
-
export {
|
13
|
-
getServerConfig
|
14
|
-
};
|
package/dist/esm/getTargetDir.js
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import * as path from "path";
|
2
|
-
const getTargetDir = (from, baseDir, targetBaseDir) => {
|
2
|
+
export const getTargetDir = (from, baseDir, targetBaseDir) => {
|
3
3
|
const relativePath = path.relative(baseDir, from);
|
4
4
|
return path.resolve(targetBaseDir, relativePath);
|
5
5
|
};
|
6
|
-
export {
|
7
|
-
getTargetDir
|
8
|
-
};
|
package/dist/esm/import.js
CHANGED
@@ -2,8 +2,7 @@ const lazy = (moduleName, requireFn) => {
|
|
2
2
|
const importLazyLocal = require("../compiled/import-lazy")(requireFn);
|
3
3
|
return importLazyLocal(moduleName);
|
4
4
|
};
|
5
|
-
|
6
|
-
export {
|
7
|
-
|
8
|
-
lazy as lazyImport
|
5
|
+
export { lazy as lazyImport };
|
6
|
+
export const Import = {
|
7
|
+
lazy
|
9
8
|
};
|
package/dist/esm/is/index.js
CHANGED
@@ -3,7 +3,7 @@ import path from "path";
|
|
3
3
|
import { createDebugger } from "../debug";
|
4
4
|
import { isDev } from "./nodeEnv";
|
5
5
|
const debug = createDebugger("judge-depExists");
|
6
|
-
const isDepExists = (appDirectory, name) => {
|
6
|
+
export const isDepExists = (appDirectory, name) => {
|
7
7
|
const pkgPath = path.resolve(appDirectory, "./package.json");
|
8
8
|
if (!fs.existsSync(pkgPath)) {
|
9
9
|
debug(`can't find package.json under: %s`, appDirectory);
|
@@ -13,14 +13,14 @@ const isDepExists = (appDirectory, name) => {
|
|
13
13
|
const { dependencies = {}, devDependencies = {} } = json;
|
14
14
|
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
15
15
|
};
|
16
|
-
const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
|
17
|
-
const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
|
18
|
-
const isSSR = (config) => {
|
16
|
+
export const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
|
17
|
+
export const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
|
18
|
+
export const isSSR = (config) => {
|
19
19
|
const { server } = config;
|
20
|
-
if (server
|
20
|
+
if (server === null || server === void 0 ? void 0 : server.ssr) {
|
21
21
|
return true;
|
22
22
|
}
|
23
|
-
if ((server
|
23
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
|
24
24
|
for (const name of Object.keys(server.ssrByEntries)) {
|
25
25
|
if (server.ssrByEntries[name]) {
|
26
26
|
return true;
|
@@ -29,44 +29,32 @@ const isSSR = (config) => {
|
|
29
29
|
}
|
30
30
|
return false;
|
31
31
|
};
|
32
|
-
const isUseSSRBundle = (config) => {
|
32
|
+
export const isUseSSRBundle = (config) => {
|
33
33
|
const { output } = config;
|
34
|
-
if (output
|
34
|
+
if (output === null || output === void 0 ? void 0 : output.ssg) {
|
35
35
|
return true;
|
36
36
|
}
|
37
37
|
return isSSR(config);
|
38
38
|
};
|
39
|
-
const isServiceWorker = (config) => {
|
40
|
-
var
|
39
|
+
export const isServiceWorker = (config) => {
|
40
|
+
var _deploy_worker;
|
41
41
|
const { output, deploy } = config;
|
42
|
-
if ((
|
42
|
+
if ((deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr) && ((output === null || output === void 0 ? void 0 : output.ssg) || isSSR(config))) {
|
43
43
|
return true;
|
44
44
|
}
|
45
45
|
return false;
|
46
46
|
};
|
47
|
-
const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
|
48
|
-
const isRouterV5 = (config) => {
|
49
|
-
var
|
50
|
-
return typeof ((
|
47
|
+
export const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
|
48
|
+
export const isRouterV5 = (config) => {
|
49
|
+
var _config_runtime, _config_runtime1, _config_runtime_router;
|
50
|
+
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
|
51
51
|
};
|
52
|
-
const isSSGEntry = (config, entryName, entrypoints) => {
|
52
|
+
export const isSSGEntry = (config, entryName, entrypoints) => {
|
53
53
|
const ssgConfig = config.output.ssg;
|
54
|
-
const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig
|
54
|
+
const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[entryName]);
|
55
55
|
return useSSG;
|
56
56
|
};
|
57
|
-
const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
|
57
|
+
export const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
|
58
58
|
export * from "./nodeEnv";
|
59
59
|
export * from "./platform";
|
60
60
|
export * from "./type";
|
61
|
-
export {
|
62
|
-
isDepExists,
|
63
|
-
isEmpty,
|
64
|
-
isFastRefresh,
|
65
|
-
isRouterV5,
|
66
|
-
isSSGEntry,
|
67
|
-
isSSR,
|
68
|
-
isServiceWorker,
|
69
|
-
isSingleEntry,
|
70
|
-
isTypescript,
|
71
|
-
isUseSSRBundle
|
72
|
-
};
|
package/dist/esm/is/nodeEnv.js
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
-
const getNodeEnv = () => process.env.NODE_ENV || "development";
|
2
|
-
const isDev = () => getNodeEnv() === "development";
|
3
|
-
const isProd = () => getNodeEnv() === "production";
|
4
|
-
const isTest = () => getNodeEnv() === "test";
|
5
|
-
const isProdProfile = () => isProd() && process.argv.includes("--profile");
|
6
|
-
export {
|
7
|
-
getNodeEnv,
|
8
|
-
isDev,
|
9
|
-
isProd,
|
10
|
-
isProdProfile,
|
11
|
-
isTest
|
12
|
-
};
|
1
|
+
export const getNodeEnv = () => process.env.NODE_ENV || "development";
|
2
|
+
export const isDev = () => getNodeEnv() === "development";
|
3
|
+
export const isProd = () => getNodeEnv() === "production";
|
4
|
+
export const isTest = () => getNodeEnv() === "test";
|
5
|
+
export const isProdProfile = () => isProd() && process.argv.includes("--profile");
|
package/dist/esm/is/platform.js
CHANGED
@@ -1,6 +1,2 @@
|
|
1
|
-
const isNodeJS = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
|
2
|
-
const isBrowser = () => typeof window !== "undefined";
|
3
|
-
export {
|
4
|
-
isBrowser,
|
5
|
-
isNodeJS
|
6
|
-
};
|
1
|
+
export const isNodeJS = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
|
2
|
+
export const isBrowser = () => typeof window !== "undefined";
|
package/dist/esm/is/type.js
CHANGED
@@ -1,34 +1,24 @@
|
|
1
|
-
function isString(str) {
|
1
|
+
export function isString(str) {
|
2
2
|
return typeof str === "string";
|
3
3
|
}
|
4
|
-
function isUndefined(obj) {
|
4
|
+
export function isUndefined(obj) {
|
5
5
|
return typeof obj === "undefined";
|
6
6
|
}
|
7
|
-
function isArray(obj) {
|
7
|
+
export function isArray(obj) {
|
8
8
|
return Array.isArray(obj);
|
9
9
|
}
|
10
|
-
function isFunction(func) {
|
10
|
+
export function isFunction(func) {
|
11
11
|
return typeof func === "function";
|
12
12
|
}
|
13
|
-
function isObject(obj) {
|
13
|
+
export function isObject(obj) {
|
14
14
|
return obj !== null && typeof obj === "object";
|
15
15
|
}
|
16
|
-
function isPlainObject(obj) {
|
16
|
+
export function isPlainObject(obj) {
|
17
17
|
return isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
|
18
18
|
}
|
19
|
-
function isPromise(obj) {
|
19
|
+
export function isPromise(obj) {
|
20
20
|
return Boolean(obj) && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
21
21
|
}
|
22
|
-
function isRegExp(obj) {
|
22
|
+
export function isRegExp(obj) {
|
23
23
|
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
24
24
|
}
|
25
|
-
export {
|
26
|
-
isArray,
|
27
|
-
isFunction,
|
28
|
-
isObject,
|
29
|
-
isPlainObject,
|
30
|
-
isPromise,
|
31
|
-
isRegExp,
|
32
|
-
isString,
|
33
|
-
isUndefined
|
34
|
-
};
|
package/dist/esm/logger.js
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
function _define_property(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value,
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true
|
8
|
+
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
|
+
}
|
1
14
|
import chalk from "../compiled/chalk";
|
2
15
|
const LOG_LEVEL = {
|
3
16
|
error: 0,
|
@@ -32,25 +45,15 @@ const LOG_TYPES = {
|
|
32
45
|
label: "debug",
|
33
46
|
level: "debug"
|
34
47
|
},
|
35
|
-
log: {
|
48
|
+
log: {
|
49
|
+
level: "log"
|
50
|
+
}
|
36
51
|
};
|
37
52
|
const DEFAULT_CONFIG = {
|
38
53
|
displayLabel: true,
|
39
54
|
uppercaseLabel: false
|
40
55
|
};
|
41
56
|
class Logger {
|
42
|
-
constructor(options = {}) {
|
43
|
-
this.level = options.level || LOG_TYPES.log.level;
|
44
|
-
this.config = { ...DEFAULT_CONFIG, ...options.config || {} };
|
45
|
-
this.types = {
|
46
|
-
...LOG_TYPES,
|
47
|
-
...options.types || {}
|
48
|
-
};
|
49
|
-
this.longestLabel = this.getLongestLabel();
|
50
|
-
Object.keys(this.types).forEach((type) => {
|
51
|
-
this[type] = this._log.bind(this, type);
|
52
|
-
});
|
53
|
-
}
|
54
57
|
_log(type, message, ...args) {
|
55
58
|
if (message === void 0 || message === null) {
|
56
59
|
console.log();
|
@@ -91,10 +94,27 @@ ${chalk.grey(rest.join("\n"))}`;
|
|
91
94
|
});
|
92
95
|
return longestLabel;
|
93
96
|
}
|
97
|
+
constructor(options = {}) {
|
98
|
+
_define_property(this, "level", void 0);
|
99
|
+
_define_property(this, "config", void 0);
|
100
|
+
_define_property(this, "types", void 0);
|
101
|
+
_define_property(this, "longestLabel", void 0);
|
102
|
+
this.level = options.level || LOG_TYPES.log.level;
|
103
|
+
this.config = {
|
104
|
+
...DEFAULT_CONFIG,
|
105
|
+
...options.config || {}
|
106
|
+
};
|
107
|
+
this.types = {
|
108
|
+
...LOG_TYPES,
|
109
|
+
...options.types || {}
|
110
|
+
};
|
111
|
+
this.longestLabel = this.getLongestLabel();
|
112
|
+
Object.keys(this.types).forEach((type) => {
|
113
|
+
this[type] = this._log.bind(this, type);
|
114
|
+
});
|
115
|
+
}
|
94
116
|
}
|
95
117
|
const logger = new Logger();
|
96
118
|
logger.Logger = Logger;
|
97
|
-
export {
|
98
|
-
|
99
|
-
logger
|
100
|
-
};
|
119
|
+
export { Logger };
|
120
|
+
export { logger };
|
package/dist/esm/monorepo.js
CHANGED
@@ -7,19 +7,19 @@ const WORKSPACE_FILES = {
|
|
7
7
|
PNPM: "pnpm-workspace.yaml",
|
8
8
|
LERNA: "lerna.json"
|
9
9
|
};
|
10
|
-
const isLerna = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
|
11
|
-
const isYarnWorkspaces = (root) => {
|
12
|
-
var
|
10
|
+
export const isLerna = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
|
11
|
+
export const isYarnWorkspaces = (root) => {
|
12
|
+
var _json_workspaces;
|
13
13
|
const pkg = path.join(root, WORKSPACE_FILES.YARN);
|
14
14
|
if (!fs.existsSync(pkg)) {
|
15
15
|
return false;
|
16
16
|
}
|
17
17
|
const json = JSON.parse(fs.readFileSync(pkg, "utf8"));
|
18
|
-
return Boolean((
|
18
|
+
return Boolean((_json_workspaces = json.workspaces) === null || _json_workspaces === void 0 ? void 0 : _json_workspaces.packages);
|
19
19
|
};
|
20
|
-
const isPnpmWorkspaces = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
|
21
|
-
const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
|
22
|
-
const isModernjsMonorepo = (root) => {
|
20
|
+
export const isPnpmWorkspaces = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
|
21
|
+
export const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
|
22
|
+
export const isModernjsMonorepo = (root) => {
|
23
23
|
const pkgJsonPath = path.join(root, "package.json");
|
24
24
|
if (!fs.existsSync(pkgJsonPath)) {
|
25
25
|
return false;
|
@@ -31,7 +31,7 @@ const isModernjsMonorepo = (root) => {
|
|
31
31
|
};
|
32
32
|
return Boolean(deps["@modern-js/monorepo-tools"]);
|
33
33
|
};
|
34
|
-
const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
34
|
+
export const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
35
35
|
let inMonorepo = false;
|
36
36
|
for (let depth = 0; depth < maxDepth; depth++) {
|
37
37
|
if (isMonorepo(appDirectory)) {
|
@@ -42,46 +42,29 @@ const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
|
42
42
|
}
|
43
43
|
return inMonorepo ? appDirectory : void 0;
|
44
44
|
};
|
45
|
-
const getMonorepoPackages = (root) => {
|
45
|
+
export const getMonorepoPackages = (root) => {
|
46
46
|
let packages = [];
|
47
47
|
if (isYarnWorkspaces(root)) {
|
48
|
-
const json = JSON.parse(
|
49
|
-
fs.readFileSync(path.join(root, "package.json"), "utf8")
|
50
|
-
);
|
48
|
+
const json = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
51
49
|
({ packages } = json.workspaces);
|
52
50
|
} else if (isLerna(root)) {
|
53
|
-
const json = JSON.parse(
|
54
|
-
fs.readFileSync(path.resolve(root, "lerna.json"), "utf8")
|
55
|
-
);
|
51
|
+
const json = JSON.parse(fs.readFileSync(path.resolve(root, "lerna.json"), "utf8"));
|
56
52
|
({ packages } = json);
|
57
53
|
} else {
|
58
|
-
({ packages } = yaml.load(
|
59
|
-
fs.readFileSync(path.join(root, WORKSPACE_FILES.PNPM), "utf8")
|
60
|
-
));
|
54
|
+
({ packages } = yaml.load(fs.readFileSync(path.join(root, WORKSPACE_FILES.PNPM), "utf8")));
|
61
55
|
}
|
62
56
|
if (packages) {
|
63
|
-
return packages.map(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
)
|
70
|
-
).reduce((acc, val) => acc.concat(val), []).filter((filepath) => fs.existsSync(path.resolve(filepath, "package.json"))).map((filepath) => ({
|
57
|
+
return packages.map((name) => (
|
58
|
+
// The trailing / ensures only dirs are picked up
|
59
|
+
glob.sync(path.join(root, `${name}/`), {
|
60
|
+
ignore: [
|
61
|
+
"**/node_modules/**"
|
62
|
+
]
|
63
|
+
})
|
64
|
+
)).reduce((acc, val) => acc.concat(val), []).filter((filepath) => fs.existsSync(path.resolve(filepath, "package.json"))).map((filepath) => ({
|
71
65
|
path: filepath,
|
72
|
-
name: JSON.parse(
|
73
|
-
fs.readFileSync(path.resolve(filepath, "package.json"), "utf8")
|
74
|
-
).name
|
66
|
+
name: JSON.parse(fs.readFileSync(path.resolve(filepath, "package.json"), "utf8")).name
|
75
67
|
}));
|
76
68
|
}
|
77
69
|
return [];
|
78
70
|
};
|
79
|
-
export {
|
80
|
-
findMonorepoRoot,
|
81
|
-
getMonorepoPackages,
|
82
|
-
isLerna,
|
83
|
-
isModernjsMonorepo,
|
84
|
-
isMonorepo,
|
85
|
-
isPnpmWorkspaces,
|
86
|
-
isYarnWorkspaces
|
87
|
-
};
|
package/dist/esm/nodeEnv.js
CHANGED
@@ -1,30 +1,37 @@
|
|
1
1
|
import { execa } from "./compiled";
|
2
|
-
async function canUseNpm() {
|
2
|
+
export async function canUseNpm() {
|
3
3
|
try {
|
4
|
-
await execa("npm", [
|
4
|
+
await execa("npm", [
|
5
|
+
"--version"
|
6
|
+
], {
|
7
|
+
env: process.env
|
8
|
+
});
|
5
9
|
return true;
|
6
10
|
} catch (e) {
|
7
11
|
return false;
|
8
12
|
}
|
9
13
|
}
|
10
|
-
async function canUseYarn() {
|
14
|
+
export async function canUseYarn() {
|
11
15
|
try {
|
12
|
-
await execa("yarn", [
|
16
|
+
await execa("yarn", [
|
17
|
+
"--version"
|
18
|
+
], {
|
19
|
+
env: process.env
|
20
|
+
});
|
13
21
|
return true;
|
14
22
|
} catch (e) {
|
15
23
|
return false;
|
16
24
|
}
|
17
25
|
}
|
18
|
-
async function canUsePnpm() {
|
26
|
+
export async function canUsePnpm() {
|
19
27
|
try {
|
20
|
-
await execa("pnpm", [
|
28
|
+
await execa("pnpm", [
|
29
|
+
"--version"
|
30
|
+
], {
|
31
|
+
env: process.env
|
32
|
+
});
|
21
33
|
return true;
|
22
34
|
} catch (e) {
|
23
35
|
return false;
|
24
36
|
}
|
25
37
|
}
|
26
|
-
export {
|
27
|
-
canUseNpm,
|
28
|
-
canUsePnpm,
|
29
|
-
canUseYarn
|
30
|
-
};
|