@modern-js/utils 2.69.7 → 3.0.0-alpha.1
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/dist/cjs/cli/alias.js +76 -70
- package/dist/cjs/cli/applyOptionsChain.js +44 -45
- package/dist/cjs/cli/babel.js +100 -119
- package/dist/cjs/cli/commands.js +61 -59
- package/dist/cjs/cli/common.js +45 -37
- package/dist/cjs/cli/config.js +36 -30
- package/dist/cjs/cli/constants.js +124 -161
- package/dist/cjs/cli/ensure.js +52 -45
- package/dist/cjs/cli/fs.js +41 -38
- package/dist/cjs/cli/get/config.js +43 -38
- package/dist/cjs/cli/get/data.js +108 -125
- package/dist/cjs/cli/get/index.js +109 -58
- package/dist/cjs/cli/index.js +202 -63
- package/dist/cjs/cli/is/config.js +75 -71
- package/dist/cjs/cli/is/env.js +49 -37
- package/dist/cjs/cli/is/index.js +76 -25
- package/dist/cjs/cli/is/project.js +139 -135
- package/dist/cjs/cli/is/type.js +65 -49
- package/dist/cjs/cli/logger.js +36 -27
- package/dist/cjs/cli/monorepo.js +100 -96
- package/dist/cjs/cli/package.js +85 -82
- package/dist/cjs/cli/path.js +101 -82
- package/dist/cjs/cli/port.js +71 -74
- package/dist/cjs/cli/prettyInstructions.js +106 -116
- package/dist/cjs/cli/require.js +116 -136
- package/dist/cjs/cli/route.js +67 -77
- package/dist/cjs/cli/runtimeExports.js +16 -70
- package/dist/cjs/cli/version.js +53 -42
- package/dist/cjs/cli/watch.js +79 -72
- package/dist/cjs/compiled.js +199 -128
- package/dist/cjs/import.js +58 -33
- package/dist/cjs/index.js +69 -23
- package/dist/cjs/universal/constants.js +77 -67
- package/dist/cjs/universal/index.js +33 -25
- package/dist/cjs/universal/path.js +33 -27
- package/dist/cjs/universal/pluginDagSort.js +69 -68
- package/dist/compiled/address/index.js +171 -1
- package/dist/compiled/browserslist/index.js +1329 -1
- package/dist/compiled/chalk/index.js +2368 -1
- package/dist/compiled/chokidar/index.js +4138 -16
- package/dist/compiled/chokidar/index.js.LICENSE.txt +41 -0
- package/dist/compiled/commander/index.js +1540 -1
- package/dist/compiled/debug/index.js +621 -1
- package/dist/compiled/dotenv/index.js +101 -1
- package/dist/compiled/dotenv-expand/index.js +54 -1
- package/dist/compiled/execa/index.js +1738 -1
- package/dist/compiled/fast-glob/index.js +4645 -17
- package/dist/compiled/fast-glob/index.js.LICENSE.txt +38 -0
- package/dist/compiled/filesize/index.js +193 -4
- package/dist/compiled/filesize/index.js.LICENSE.txt +7 -0
- package/dist/compiled/fs-extra/index.js +2222 -1
- package/dist/compiled/glob/index.js +2011 -1
- package/dist/compiled/globby/index.js +690 -1
- package/dist/compiled/gzip-size/index.js +157 -1
- package/dist/compiled/import-lazy/index.js +45 -1
- package/dist/compiled/inquirer/index.js +20162 -4
- package/dist/compiled/inquirer/index.js.LICENSE.txt +7 -0
- package/dist/compiled/js-yaml/index.js +2188 -1
- package/dist/compiled/json5/index.js +983 -1
- package/dist/compiled/lodash/index.js +0 -4
- package/dist/compiled/mime-types/index.js +108 -6
- package/dist/compiled/mime-types/index.js.LICENSE.txt +13 -0
- package/dist/compiled/minimist/index.js +202 -1
- package/dist/compiled/nanoid/index.js +83 -1
- package/dist/compiled/ora/index.js +3936 -3
- package/dist/compiled/ora/index.js.LICENSE.txt +1 -0
- package/dist/compiled/pkg-up/index.js +177 -1
- package/dist/compiled/semver/index.js +1779 -1
- package/dist/compiled/signale/index.js +1704 -1
- package/dist/compiled/slash/index.js +32 -1
- package/dist/compiled/strip-ansi/index.js +34 -1
- package/dist/compiled/tsconfig-paths/index.js +629 -1
- package/dist/compiled/upath/index.js +135 -1
- package/dist/compiled/url-join/index.js +61 -1
- package/dist/compiled/webpack-chain/index.js +1475 -1
- package/dist/esm/cli/alias.mjs +31 -0
- package/dist/esm/cli/applyOptionsChain.mjs +16 -0
- package/dist/esm/cli/babel.mjs +76 -0
- package/dist/esm/cli/commands.mjs +23 -0
- package/dist/esm/cli/common.mjs +11 -0
- package/dist/esm/cli/config.mjs +5 -0
- package/dist/esm/cli/constants.mjs +29 -0
- package/dist/esm/cli/ensure.mjs +9 -0
- package/dist/esm/cli/fs.mjs +9 -0
- package/dist/esm/cli/get/config.mjs +14 -0
- package/dist/esm/cli/get/data.mjs +57 -0
- package/dist/esm/cli/get/index.mjs +18 -0
- package/dist/{esm-node/cli/index.js → esm/cli/index.mjs} +0 -1
- package/dist/esm/cli/is/config.mjs +34 -0
- package/dist/esm/cli/is/env.mjs +6 -0
- package/dist/esm/cli/is/project.mjs +104 -0
- package/dist/esm/cli/is/type.mjs +26 -0
- package/dist/esm/cli/logger.mjs +2 -0
- package/dist/esm/cli/monorepo.mjs +50 -0
- package/dist/esm/cli/package.mjs +51 -0
- package/dist/esm/cli/path.mjs +35 -0
- package/dist/esm/cli/port.mjs +35 -0
- package/dist/esm/cli/prettyInstructions.mjs +68 -0
- package/dist/esm/cli/require.mjs +79 -0
- package/dist/esm/cli/route.mjs +36 -0
- package/dist/esm/cli/runtimeExports.mjs +0 -0
- package/dist/esm/cli/version.mjs +21 -0
- package/dist/esm/cli/watch.mjs +40 -0
- package/dist/esm/compiled.mjs +115 -0
- package/dist/esm/import.mjs +25 -0
- package/dist/esm/universal/constants.mjs +13 -0
- package/dist/{esm-node/universal/index.js → esm/universal/index.mjs} +1 -3
- package/dist/esm/universal/path.mjs +2 -0
- package/dist/esm/universal/pluginDagSort.mjs +41 -0
- package/dist/esm-node/cli/alias.mjs +31 -0
- package/dist/esm-node/cli/applyOptionsChain.mjs +16 -0
- package/dist/esm-node/cli/babel.mjs +76 -0
- package/dist/esm-node/cli/commands.mjs +23 -0
- package/dist/esm-node/cli/common.mjs +11 -0
- package/dist/esm-node/cli/config.mjs +5 -0
- package/dist/esm-node/cli/constants.mjs +29 -0
- package/dist/esm-node/cli/ensure.mjs +9 -0
- package/dist/esm-node/cli/fs.mjs +9 -0
- package/dist/esm-node/cli/get/config.mjs +14 -0
- package/dist/esm-node/cli/get/data.mjs +57 -0
- package/dist/esm-node/cli/get/index.mjs +18 -0
- package/dist/esm-node/cli/index.mjs +22 -0
- package/dist/esm-node/cli/is/config.mjs +34 -0
- package/dist/esm-node/cli/is/env.mjs +6 -0
- package/dist/esm-node/cli/is/index.mjs +4 -0
- package/dist/esm-node/cli/is/project.mjs +104 -0
- package/dist/esm-node/cli/is/type.mjs +26 -0
- package/dist/esm-node/cli/logger.mjs +2 -0
- package/dist/esm-node/cli/monorepo.mjs +50 -0
- package/dist/esm-node/cli/package.mjs +51 -0
- package/dist/esm-node/cli/path.mjs +35 -0
- package/dist/esm-node/cli/port.mjs +35 -0
- package/dist/esm-node/cli/prettyInstructions.mjs +68 -0
- package/dist/esm-node/cli/require.mjs +79 -0
- package/dist/esm-node/cli/route.mjs +36 -0
- package/dist/esm-node/cli/runtimeExports.mjs +0 -0
- package/dist/esm-node/cli/version.mjs +21 -0
- package/dist/esm-node/cli/watch.mjs +40 -0
- package/dist/esm-node/compiled.mjs +115 -0
- package/dist/esm-node/import.mjs +25 -0
- package/dist/esm-node/index.mjs +3 -0
- package/dist/esm-node/universal/constants.mjs +13 -0
- package/dist/esm-node/universal/index.mjs +2 -0
- package/dist/esm-node/universal/path.mjs +2 -0
- package/dist/esm-node/universal/pluginDagSort.mjs +41 -0
- package/dist/types/cli/constants.d.ts +2 -26
- package/dist/types/cli/get/data.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/is/config.d.ts +1 -1
- package/dist/types/cli/runtimeExports.d.ts +1 -4
- package/dist/types/cli/watch.d.ts +1 -1
- package/dist/types/compiled.d.ts +0 -5
- package/dist/types/universal/constants.d.ts +4 -7
- package/package.json +27 -27
- package/rslib.config.mts +140 -0
- package/dist/cjs/cli/action.js +0 -55
- package/dist/cjs/universal/formatWebpack.js +0 -127
- package/dist/esm/cli/action.js +0 -68
- package/dist/esm/cli/alias.js +0 -43
- package/dist/esm/cli/applyOptionsChain.js +0 -29
- package/dist/esm/cli/babel.js +0 -122
- package/dist/esm/cli/commands.js +0 -39
- package/dist/esm/cli/common.js +0 -20
- package/dist/esm/cli/config.js +0 -11
- package/dist/esm/cli/constants.js +0 -114
- package/dist/esm/cli/ensure.js +0 -16
- package/dist/esm/cli/fs.js +0 -65
- package/dist/esm/cli/get/config.js +0 -19
- package/dist/esm/cli/get/data.js +0 -143
- package/dist/esm/cli/get/index.js +0 -38
- package/dist/esm/cli/index.js +0 -23
- package/dist/esm/cli/is/config.js +0 -70
- package/dist/esm/cli/is/env.js +0 -22
- package/dist/esm/cli/is/index.js +0 -4
- package/dist/esm/cli/is/project.js +0 -146
- package/dist/esm/cli/is/type.js +0 -39
- package/dist/esm/cli/logger.js +0 -5
- package/dist/esm/cli/monorepo.js +0 -82
- package/dist/esm/cli/package.js +0 -203
- package/dist/esm/cli/path.js +0 -66
- package/dist/esm/cli/port.js +0 -97
- package/dist/esm/cli/prettyInstructions.js +0 -102
- package/dist/esm/cli/require.js +0 -235
- package/dist/esm/cli/route.js +0 -64
- package/dist/esm/cli/runtimeExports.js +0 -44
- package/dist/esm/cli/version.js +0 -26
- package/dist/esm/cli/watch.js +0 -112
- package/dist/esm/compiled.js +0 -66
- package/dist/esm/import.js +0 -11
- package/dist/esm/index.js +0 -3
- package/dist/esm/universal/constants.js +0 -32
- package/dist/esm/universal/formatWebpack.js +0 -95
- package/dist/esm/universal/index.js +0 -4
- package/dist/esm/universal/path.js +0 -6
- package/dist/esm/universal/pluginDagSort.js +0 -73
- package/dist/esm-node/cli/action.js +0 -30
- package/dist/esm-node/cli/alias.js +0 -40
- package/dist/esm-node/cli/applyOptionsChain.js +0 -27
- package/dist/esm-node/cli/babel.js +0 -107
- package/dist/esm-node/cli/commands.js +0 -39
- package/dist/esm-node/cli/common.js +0 -15
- package/dist/esm-node/cli/config.js +0 -9
- package/dist/esm-node/cli/constants.js +0 -114
- package/dist/esm-node/cli/ensure.js +0 -14
- package/dist/esm-node/cli/fs.js +0 -18
- package/dist/esm-node/cli/get/config.js +0 -19
- package/dist/esm-node/cli/get/data.js +0 -96
- package/dist/esm-node/cli/get/index.js +0 -22
- package/dist/esm-node/cli/is/config.js +0 -50
- package/dist/esm-node/cli/is/env.js +0 -12
- package/dist/esm-node/cli/is/project.js +0 -105
- package/dist/esm-node/cli/is/type.js +0 -36
- package/dist/esm-node/cli/logger.js +0 -5
- package/dist/esm-node/cli/monorepo.js +0 -67
- package/dist/esm-node/cli/package.js +0 -66
- package/dist/esm-node/cli/path.js +0 -48
- package/dist/esm-node/cli/port.js +0 -48
- package/dist/esm-node/cli/prettyInstructions.js +0 -90
- package/dist/esm-node/cli/require.js +0 -111
- package/dist/esm-node/cli/route.js +0 -60
- package/dist/esm-node/cli/runtimeExports.js +0 -38
- package/dist/esm-node/cli/version.js +0 -26
- package/dist/esm-node/cli/watch.js +0 -45
- package/dist/esm-node/compiled.js +0 -66
- package/dist/esm-node/import.js +0 -11
- package/dist/esm-node/universal/constants.js +0 -32
- package/dist/esm-node/universal/formatWebpack.js +0 -102
- package/dist/esm-node/universal/path.js +0 -6
- package/dist/esm-node/universal/pluginDagSort.js +0 -50
- package/dist/types/cli/action.d.ts +0 -2
- package/dist/types/universal/formatWebpack.d.ts +0 -26
- /package/dist/{esm-node/cli/is/index.js → esm/cli/is/index.mjs} +0 -0
- /package/dist/{esm-node/index.js → esm/index.mjs} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import net from "net";
|
|
2
|
+
import { chalk } from "../compiled";
|
|
3
|
+
import { logger } from "./logger";
|
|
4
|
+
const getPort = async (expectPort, { tryLimits = 20, strictPort = false, slient = false } = {})=>{
|
|
5
|
+
let port = expectPort;
|
|
6
|
+
if ('string' == typeof port) port = parseInt(port, 10);
|
|
7
|
+
if (strictPort) tryLimits = 1;
|
|
8
|
+
const original = port;
|
|
9
|
+
let found = false;
|
|
10
|
+
let attempts = 0;
|
|
11
|
+
while(!found && attempts <= tryLimits)try {
|
|
12
|
+
await new Promise((resolve, reject)=>{
|
|
13
|
+
const server = net.createServer();
|
|
14
|
+
server.unref();
|
|
15
|
+
server.on('error', reject);
|
|
16
|
+
server.listen({
|
|
17
|
+
port,
|
|
18
|
+
host: '0.0.0.0'
|
|
19
|
+
}, ()=>{
|
|
20
|
+
found = true;
|
|
21
|
+
server.close(resolve);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if ('EADDRINUSE' !== e.code) throw e;
|
|
26
|
+
port++;
|
|
27
|
+
attempts++;
|
|
28
|
+
}
|
|
29
|
+
if (port !== original) {
|
|
30
|
+
if (strictPort) throw new Error(`Port "${original}" is occupied, please choose another one.`);
|
|
31
|
+
else if (!slient) logger.info(`Port ${original} is in use. ${chalk.yellow(`using port ${port}.`)}`);
|
|
32
|
+
}
|
|
33
|
+
return port;
|
|
34
|
+
};
|
|
35
|
+
export { getPort };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isIPv6 } from "net";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import { chalk } from "../compiled";
|
|
4
|
+
import { DEFAULT_DEV_HOST } from "./constants";
|
|
5
|
+
import { isDev, isSingleEntry } from "./is";
|
|
6
|
+
const normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1');
|
|
7
|
+
const getIpv4Interfaces = ()=>{
|
|
8
|
+
const interfaces = os.networkInterfaces();
|
|
9
|
+
const ipv4Interfaces = [];
|
|
10
|
+
Object.keys(interfaces).forEach((key)=>{
|
|
11
|
+
interfaces[key].forEach((detail)=>{
|
|
12
|
+
const familyV4Value = 'string' == typeof detail.family ? 'IPv4' : 4;
|
|
13
|
+
if (detail.family === familyV4Value) ipv4Interfaces.push(detail);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return ipv4Interfaces;
|
|
17
|
+
};
|
|
18
|
+
const getHostInUrl = (host)=>{
|
|
19
|
+
if (isIPv6(host)) return '::' === host ? '[::1]' : `[${host}]`;
|
|
20
|
+
return host;
|
|
21
|
+
};
|
|
22
|
+
const getAddressUrls = (protocol = 'http', port, host)=>{
|
|
23
|
+
const LOCAL_LABEL = 'Local: ';
|
|
24
|
+
const NETWORK_LABEL = 'Network: ';
|
|
25
|
+
const isLocalhost = (url)=>url?.includes('localhost');
|
|
26
|
+
if (host && host !== DEFAULT_DEV_HOST) return [
|
|
27
|
+
{
|
|
28
|
+
label: isLocalhost(host) ? LOCAL_LABEL : NETWORK_LABEL,
|
|
29
|
+
url: `${protocol}://${getHostInUrl(host)}:${port}`
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
const ipv4Interfaces = getIpv4Interfaces();
|
|
33
|
+
return ipv4Interfaces.reduce((memo, detail)=>{
|
|
34
|
+
if (isLocalhost(detail.address) || detail.internal) memo.push({
|
|
35
|
+
label: LOCAL_LABEL,
|
|
36
|
+
url: `${protocol}://localhost:${port}`
|
|
37
|
+
});
|
|
38
|
+
else memo.push({
|
|
39
|
+
label: NETWORK_LABEL,
|
|
40
|
+
url: `${protocol}://${detail.address}:${port}`
|
|
41
|
+
});
|
|
42
|
+
return memo;
|
|
43
|
+
}, []);
|
|
44
|
+
};
|
|
45
|
+
const prettyInstructions = (appContext, config)=>{
|
|
46
|
+
const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
|
|
47
|
+
const isHttps = isDev() && (config?.dev?.https || config?.tools?.devServer?.https);
|
|
48
|
+
const urls = getAddressUrls(isHttps ? 'https' : 'http', port, config.dev?.host);
|
|
49
|
+
const routes = apiOnly ? serverRoutes : serverRoutes.filter((route)=>route.entryName);
|
|
50
|
+
let message = '\n';
|
|
51
|
+
if (isSingleEntry(entrypoints, config.source?.mainEntryName) || apiOnly) message += urls.map(({ label, url })=>` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}\n`).join('');
|
|
52
|
+
else {
|
|
53
|
+
const maxNameLength = Math.max(...routes.map((r)=>r.entryName.length));
|
|
54
|
+
urls.forEach(({ label, url })=>{
|
|
55
|
+
message += ` ${chalk.bold(`> ${label}`)}${0 === routes.length ? chalk.cyanBright(url) : ''}\n`;
|
|
56
|
+
routes.forEach(({ entryName, urlPath, isSSR })=>{
|
|
57
|
+
if (!checkedEntries.includes(entryName)) return;
|
|
58
|
+
message += ` ${chalk.yellowBright(isSSR ? 'λ' : '○')} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
message += '\n';
|
|
62
|
+
message += chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
|
|
63
|
+
message += chalk.cyanBright(' ○ (Static) client-side renders as static HTML\n');
|
|
64
|
+
}
|
|
65
|
+
if (config.dev?.cliShortcuts) message += ` ${chalk.dim('> press')} ${chalk.bold('h + enter')} ${chalk.dim('to show shortcuts')}\n`;
|
|
66
|
+
return message;
|
|
67
|
+
};
|
|
68
|
+
export { getAddressUrls, prettyInstructions };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { findExists } from "./fs";
|
|
4
|
+
async function compatibleRequire(path, interop = true) {
|
|
5
|
+
if (path.endsWith('.json')) return require(path);
|
|
6
|
+
let requiredModule;
|
|
7
|
+
try {
|
|
8
|
+
requiredModule = require(path);
|
|
9
|
+
} catch (err) {
|
|
10
|
+
if ('ERR_REQUIRE_ESM' === err.code) {
|
|
11
|
+
const modulePath = isAbsolute(path) ? pathToFileURL(path).href : path;
|
|
12
|
+
if ('development' === process.env.NODE_ENV) {
|
|
13
|
+
const timestamp = Date.now();
|
|
14
|
+
requiredModule = await import(`${modulePath}?t=${timestamp}`);
|
|
15
|
+
} else requiredModule = await import(modulePath);
|
|
16
|
+
return interop ? requiredModule.default : requiredModule;
|
|
17
|
+
}
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
return interop && requiredModule?.__esModule ? requiredModule.default : requiredModule;
|
|
21
|
+
}
|
|
22
|
+
async function loadFromProject(moduleName, appDir) {
|
|
23
|
+
let requiredModule;
|
|
24
|
+
const paths = [
|
|
25
|
+
appDir,
|
|
26
|
+
process.cwd()
|
|
27
|
+
];
|
|
28
|
+
try {
|
|
29
|
+
{
|
|
30
|
+
const modulePath = require.resolve(moduleName, {
|
|
31
|
+
paths
|
|
32
|
+
});
|
|
33
|
+
requiredModule = require(modulePath);
|
|
34
|
+
}
|
|
35
|
+
return requiredModule.default || requiredModule;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if ('MODULE_NOT_FOUND' === error.code) throw new Error(`Cannot find module ${moduleName}.`);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const dynamicImport = new Function('modulePath', 'return import(modulePath)');
|
|
42
|
+
const requireExistModule = async (filename, opt)=>{
|
|
43
|
+
const final = {
|
|
44
|
+
extensions: [
|
|
45
|
+
'.ts',
|
|
46
|
+
'.js'
|
|
47
|
+
],
|
|
48
|
+
interop: true,
|
|
49
|
+
...opt
|
|
50
|
+
};
|
|
51
|
+
const exist = findExists(final.extensions.map((ext)=>`${filename}${ext}`));
|
|
52
|
+
if (!exist) return null;
|
|
53
|
+
return compatibleRequire(exist, final.interop);
|
|
54
|
+
};
|
|
55
|
+
const cleanRequireCache = (filelist)=>{
|
|
56
|
+
filelist.forEach((filepath)=>{
|
|
57
|
+
if (require.cache) delete require.cache[filepath];
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
function deleteRequireCache(path) {
|
|
61
|
+
if (require.cache[path]) delete require.cache[path];
|
|
62
|
+
if (module.children) module.children = module.children.filter((item)=>item.filename !== path);
|
|
63
|
+
}
|
|
64
|
+
const tryResolve = (name, resolvePath)=>{
|
|
65
|
+
let filePath = '';
|
|
66
|
+
try {
|
|
67
|
+
filePath = require.resolve(name, {
|
|
68
|
+
paths: [
|
|
69
|
+
resolvePath
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
delete require.cache[filePath];
|
|
73
|
+
} catch (err) {
|
|
74
|
+
if ('MODULE_NOT_FOUND' === err.code) throw new Error(`Can not find module ${name}.`);
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
return filePath;
|
|
78
|
+
};
|
|
79
|
+
export { cleanRequireCache, compatibleRequire, deleteRequireCache, dynamicImport, loadFromProject, requireExistModule, tryResolve };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { lodash } from "../compiled";
|
|
2
|
+
const { cloneDeep } = lodash;
|
|
3
|
+
function filterRoutesForServer(routes) {
|
|
4
|
+
const clonedRoutes = cloneDeep(routes);
|
|
5
|
+
const newRoutes = clonedRoutes.map((route)=>{
|
|
6
|
+
if ('nested' !== route.type) return route;
|
|
7
|
+
if (route.children && route.children.length > 0) route.children = filterRoutesForServer(route.children);
|
|
8
|
+
if (route.inValidSSRRoute) return null;
|
|
9
|
+
return route;
|
|
10
|
+
}).filter((route)=>null !== route);
|
|
11
|
+
return newRoutes;
|
|
12
|
+
}
|
|
13
|
+
function filterRoutesLoader(routes) {
|
|
14
|
+
const clonedRoutes = cloneDeep(routes);
|
|
15
|
+
const newRoutes = clonedRoutes.map((route)=>{
|
|
16
|
+
if ('nested' !== route.type) return route;
|
|
17
|
+
if (route.children && route.children.length > 0) route.children = filterRoutesLoader(route.children);
|
|
18
|
+
if (route.inValidSSRRoute) {
|
|
19
|
+
delete route.loader;
|
|
20
|
+
delete route.data;
|
|
21
|
+
delete route.action;
|
|
22
|
+
}
|
|
23
|
+
return route;
|
|
24
|
+
}).filter((route)=>null !== route);
|
|
25
|
+
return newRoutes;
|
|
26
|
+
}
|
|
27
|
+
function markRoutes(routes, routeIds) {
|
|
28
|
+
return routes.map((route)=>{
|
|
29
|
+
if ('nested' !== route.type) return route;
|
|
30
|
+
if (route.children && route.children.length > 0) route.children = markRoutes(route.children, routeIds);
|
|
31
|
+
if (route.children && route.children.length > 0) route.inValidSSRRoute = route.children.every((child)=>child.inValidSSRRoute ?? false);
|
|
32
|
+
else if (route.id) route.inValidSSRRoute = !routeIds.includes(route.id);
|
|
33
|
+
return route;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export { filterRoutesForServer, filterRoutesLoader, markRoutes };
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function isVersionAtLeast1819() {
|
|
2
|
+
const nodeVersion = process.versions.node;
|
|
3
|
+
const versionArr = nodeVersion.split('.').map(Number);
|
|
4
|
+
return versionArr[0] > 18 || 18 === versionArr[0] && versionArr[1] >= 19;
|
|
5
|
+
}
|
|
6
|
+
function isVersionAtLeast18() {
|
|
7
|
+
const nodeVersion = process.versions.node;
|
|
8
|
+
const versionArr = nodeVersion.split('.').map(Number);
|
|
9
|
+
return versionArr[0] >= 18;
|
|
10
|
+
}
|
|
11
|
+
function isVersionAtLeast22() {
|
|
12
|
+
const nodeVersion = process.versions.node;
|
|
13
|
+
const versionArr = nodeVersion.split('.').map(Number);
|
|
14
|
+
return versionArr[0] >= 22;
|
|
15
|
+
}
|
|
16
|
+
function isVersionAtLeast20() {
|
|
17
|
+
const nodeVersion = process.versions.node;
|
|
18
|
+
const versionArr = nodeVersion.split('.').map(Number);
|
|
19
|
+
return versionArr[0] >= 20;
|
|
20
|
+
}
|
|
21
|
+
export { isVersionAtLeast18, isVersionAtLeast1819, isVersionAtLeast20, isVersionAtLeast22 };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { chokidar } from "../compiled";
|
|
3
|
+
const WatchChangeType = {
|
|
4
|
+
ADD: 'add',
|
|
5
|
+
UNLINK: 'unlink',
|
|
6
|
+
CHANGE: 'change'
|
|
7
|
+
};
|
|
8
|
+
const watch = (watchDir, runTask, ignored = [])=>{
|
|
9
|
+
let ready = false;
|
|
10
|
+
const watcher = chokidar.watch(watchDir, {
|
|
11
|
+
ignored
|
|
12
|
+
});
|
|
13
|
+
watcher.on('ready', ()=>ready = true);
|
|
14
|
+
watcher.on('change', async (filePath)=>{
|
|
15
|
+
const changedFilePath = path.resolve(filePath);
|
|
16
|
+
await runTask({
|
|
17
|
+
changedFilePath,
|
|
18
|
+
changeType: WatchChangeType.CHANGE
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
watcher.on('add', async (filePath)=>{
|
|
22
|
+
const changedFilePath = path.resolve(filePath);
|
|
23
|
+
if (ready) await runTask({
|
|
24
|
+
changedFilePath,
|
|
25
|
+
changeType: WatchChangeType.ADD
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
watcher.on('unlink', async (filePath)=>{
|
|
29
|
+
const changedFilePath = path.resolve(filePath);
|
|
30
|
+
await runTask({
|
|
31
|
+
changedFilePath,
|
|
32
|
+
changeType: WatchChangeType.UNLINK
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
watcher.on('error', (err)=>{
|
|
36
|
+
throw err;
|
|
37
|
+
});
|
|
38
|
+
return watcher;
|
|
39
|
+
};
|
|
40
|
+
export { WatchChangeType, watch };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { Import } from "./import";
|
|
3
|
+
import { createRequire as __rspack_createRequire } from "node:module";
|
|
4
|
+
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.n = (module)=>{
|
|
8
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
+
__webpack_require__.d(getter, {
|
|
10
|
+
a: getter
|
|
11
|
+
});
|
|
12
|
+
return getter;
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
17
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: definition[key]
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
|
+
})();
|
|
26
|
+
const index_js_namespaceObject = __rspack_createRequire_require("../compiled/fs-extra/index.js");
|
|
27
|
+
var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject);
|
|
28
|
+
const ora_index_js_namespaceObject = __rspack_createRequire_require("../compiled/ora/index.js");
|
|
29
|
+
var ora_index_js_default = /*#__PURE__*/ __webpack_require__.n(ora_index_js_namespaceObject);
|
|
30
|
+
const glob_index_js_namespaceObject = __rspack_createRequire_require("../compiled/glob/index.js");
|
|
31
|
+
var glob_index_js_default = /*#__PURE__*/ __webpack_require__.n(glob_index_js_namespaceObject);
|
|
32
|
+
const js_yaml_index_js_namespaceObject = __rspack_createRequire_require("../compiled/js-yaml/index.js");
|
|
33
|
+
var js_yaml_index_js_default = /*#__PURE__*/ __webpack_require__.n(js_yaml_index_js_namespaceObject);
|
|
34
|
+
const chalk_index_js_namespaceObject = __rspack_createRequire_require("../compiled/chalk/index.js");
|
|
35
|
+
var chalk_index_js_default = /*#__PURE__*/ __webpack_require__.n(chalk_index_js_namespaceObject);
|
|
36
|
+
const debug_index_js_namespaceObject = __rspack_createRequire_require("../compiled/debug/index.js");
|
|
37
|
+
var debug_index_js_default = /*#__PURE__*/ __webpack_require__.n(debug_index_js_namespaceObject);
|
|
38
|
+
const slash_index_js_namespaceObject = __rspack_createRequire_require("../compiled/slash/index.js");
|
|
39
|
+
var slash_index_js_default = /*#__PURE__*/ __webpack_require__.n(slash_index_js_namespaceObject);
|
|
40
|
+
const execa_index_js_namespaceObject = __rspack_createRequire_require("../compiled/execa/index.js");
|
|
41
|
+
var execa_index_js_default = /*#__PURE__*/ __webpack_require__.n(execa_index_js_namespaceObject);
|
|
42
|
+
const json5_index_js_namespaceObject = __rspack_createRequire_require("../compiled/json5/index.js");
|
|
43
|
+
var json5_index_js_default = /*#__PURE__*/ __webpack_require__.n(json5_index_js_namespaceObject);
|
|
44
|
+
const upath_index_js_namespaceObject = __rspack_createRequire_require("../compiled/upath/index.js");
|
|
45
|
+
var upath_index_js_default = /*#__PURE__*/ __webpack_require__.n(upath_index_js_namespaceObject);
|
|
46
|
+
const pkg_up_index_js_namespaceObject = __rspack_createRequire_require("../compiled/pkg-up/index.js");
|
|
47
|
+
var pkg_up_index_js_default = /*#__PURE__*/ __webpack_require__.n(pkg_up_index_js_namespaceObject);
|
|
48
|
+
const nanoid_index_js_namespaceObject = __rspack_createRequire_require("../compiled/nanoid/index.js");
|
|
49
|
+
const semver_index_js_namespaceObject = __rspack_createRequire_require("../compiled/semver/index.js");
|
|
50
|
+
var semver_index_js_default = /*#__PURE__*/ __webpack_require__.n(semver_index_js_namespaceObject);
|
|
51
|
+
const dotenv_index_js_namespaceObject = __rspack_createRequire_require("../compiled/dotenv/index.js");
|
|
52
|
+
var dotenv_index_js_default = /*#__PURE__*/ __webpack_require__.n(dotenv_index_js_namespaceObject);
|
|
53
|
+
const lodash_index_js_namespaceObject = __rspack_createRequire_require("../compiled/lodash/index.js");
|
|
54
|
+
var lodash_index_js_default = /*#__PURE__*/ __webpack_require__.n(lodash_index_js_namespaceObject);
|
|
55
|
+
const globby_index_js_namespaceObject = __rspack_createRequire_require("../compiled/globby/index.js");
|
|
56
|
+
var globby_index_js_default = /*#__PURE__*/ __webpack_require__.n(globby_index_js_namespaceObject);
|
|
57
|
+
const address_index_js_namespaceObject = __rspack_createRequire_require("../compiled/address/index.js");
|
|
58
|
+
var address_index_js_default = /*#__PURE__*/ __webpack_require__.n(address_index_js_namespaceObject);
|
|
59
|
+
const signale_index_js_namespaceObject = __rspack_createRequire_require("../compiled/signale/index.js");
|
|
60
|
+
var signale_index_js_default = /*#__PURE__*/ __webpack_require__.n(signale_index_js_namespaceObject);
|
|
61
|
+
const url_join_index_js_namespaceObject = __rspack_createRequire_require("../compiled/url-join/index.js");
|
|
62
|
+
var url_join_index_js_default = /*#__PURE__*/ __webpack_require__.n(url_join_index_js_namespaceObject);
|
|
63
|
+
const minimist_index_js_namespaceObject = __rspack_createRequire_require("../compiled/minimist/index.js");
|
|
64
|
+
var minimist_index_js_default = /*#__PURE__*/ __webpack_require__.n(minimist_index_js_namespaceObject);
|
|
65
|
+
const fast_glob_index_js_namespaceObject = __rspack_createRequire_require("../compiled/fast-glob/index.js");
|
|
66
|
+
var fast_glob_index_js_default = /*#__PURE__*/ __webpack_require__.n(fast_glob_index_js_namespaceObject);
|
|
67
|
+
const filesize_index_js_namespaceObject = __rspack_createRequire_require("../compiled/filesize/index.js");
|
|
68
|
+
var filesize_index_js_default = /*#__PURE__*/ __webpack_require__.n(filesize_index_js_namespaceObject);
|
|
69
|
+
const gzip_size_index_js_namespaceObject = __rspack_createRequire_require("../compiled/gzip-size/index.js");
|
|
70
|
+
var gzip_size_index_js_default = /*#__PURE__*/ __webpack_require__.n(gzip_size_index_js_namespaceObject);
|
|
71
|
+
const strip_ansi_index_js_namespaceObject = __rspack_createRequire_require("../compiled/strip-ansi/index.js");
|
|
72
|
+
var strip_ansi_index_js_default = /*#__PURE__*/ __webpack_require__.n(strip_ansi_index_js_namespaceObject);
|
|
73
|
+
const dotenv_expand_index_js_namespaceObject = __rspack_createRequire_require("../compiled/dotenv-expand/index.js");
|
|
74
|
+
var dotenv_expand_index_js_default = /*#__PURE__*/ __webpack_require__.n(dotenv_expand_index_js_namespaceObject);
|
|
75
|
+
const browserslist_index_js_namespaceObject = __rspack_createRequire_require("../compiled/browserslist/index.js");
|
|
76
|
+
var browserslist_index_js_default = /*#__PURE__*/ __webpack_require__.n(browserslist_index_js_namespaceObject);
|
|
77
|
+
const commander_index_js_namespaceObject = __rspack_createRequire_require("../compiled/commander/index.js");
|
|
78
|
+
const nodeRequire = (()=>{
|
|
79
|
+
const gRequire = globalThis.require;
|
|
80
|
+
if ('function' == typeof gRequire) return gRequire;
|
|
81
|
+
return createRequire(import.meta.url);
|
|
82
|
+
})();
|
|
83
|
+
const mime = Import.lazy('../compiled/mime-types', nodeRequire);
|
|
84
|
+
const chokidar = Import.lazy('../compiled/chokidar', nodeRequire);
|
|
85
|
+
const inquirer = Import.lazy('../compiled/inquirer', nodeRequire);
|
|
86
|
+
var __webpack_exports__Command = commander_index_js_namespaceObject.Command;
|
|
87
|
+
var __webpack_exports__Signale = signale_index_js_namespaceObject.Signale;
|
|
88
|
+
var __webpack_exports__address = address_index_js_default();
|
|
89
|
+
var __webpack_exports__browserslist = browserslist_index_js_default();
|
|
90
|
+
var __webpack_exports__chalk = chalk_index_js_default();
|
|
91
|
+
var __webpack_exports__debug = debug_index_js_default();
|
|
92
|
+
var __webpack_exports__dotenv = dotenv_index_js_default();
|
|
93
|
+
var __webpack_exports__dotenvExpand = dotenv_expand_index_js_default();
|
|
94
|
+
var __webpack_exports__execa = execa_index_js_default();
|
|
95
|
+
var __webpack_exports__fastGlob = fast_glob_index_js_default();
|
|
96
|
+
var __webpack_exports__filesize = filesize_index_js_default();
|
|
97
|
+
var __webpack_exports__fs = index_js_default();
|
|
98
|
+
var __webpack_exports__glob = glob_index_js_default();
|
|
99
|
+
var __webpack_exports__globby = globby_index_js_default();
|
|
100
|
+
var __webpack_exports__gzipSize = gzip_size_index_js_default();
|
|
101
|
+
var __webpack_exports__json5 = json5_index_js_default();
|
|
102
|
+
var __webpack_exports__lodash = lodash_index_js_default();
|
|
103
|
+
var __webpack_exports__minimist = minimist_index_js_default();
|
|
104
|
+
var __webpack_exports__nanoid = nanoid_index_js_namespaceObject.nanoid;
|
|
105
|
+
var __webpack_exports__ora = ora_index_js_default();
|
|
106
|
+
var __webpack_exports__pkgUp = pkg_up_index_js_default();
|
|
107
|
+
var __webpack_exports__program = commander_index_js_namespaceObject.program;
|
|
108
|
+
var __webpack_exports__semver = semver_index_js_default();
|
|
109
|
+
var __webpack_exports__signale = signale_index_js_default();
|
|
110
|
+
var __webpack_exports__slash = slash_index_js_default();
|
|
111
|
+
var __webpack_exports__stripAnsi = strip_ansi_index_js_default();
|
|
112
|
+
var __webpack_exports__upath = upath_index_js_default();
|
|
113
|
+
var __webpack_exports__urlJoin = url_join_index_js_default();
|
|
114
|
+
var __webpack_exports__yaml = js_yaml_index_js_default();
|
|
115
|
+
export { chokidar, inquirer, mime, __webpack_exports__Command as Command, __webpack_exports__Signale as Signale, __webpack_exports__address as address, __webpack_exports__browserslist as browserslist, __webpack_exports__chalk as chalk, __webpack_exports__debug as debug, __webpack_exports__dotenv as dotenv, __webpack_exports__dotenvExpand as dotenvExpand, __webpack_exports__execa as execa, __webpack_exports__fastGlob as fastGlob, __webpack_exports__filesize as filesize, __webpack_exports__fs as fs, __webpack_exports__glob as glob, __webpack_exports__globby as globby, __webpack_exports__gzipSize as gzipSize, __webpack_exports__json5 as json5, __webpack_exports__lodash as lodash, __webpack_exports__minimist as minimist, __webpack_exports__nanoid as nanoid, __webpack_exports__ora as ora, __webpack_exports__pkgUp as pkgUp, __webpack_exports__program as program, __webpack_exports__semver as semver, __webpack_exports__signale as signale, __webpack_exports__slash as slash, __webpack_exports__stripAnsi as stripAnsi, __webpack_exports__upath as upath, __webpack_exports__urlJoin as urlJoin, __webpack_exports__yaml as yaml };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createRequire as __rspack_createRequire } from "node:module";
|
|
2
|
+
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
3
|
+
var __webpack_modules__ = {
|
|
4
|
+
"../compiled/import-lazy" (module) {
|
|
5
|
+
module.exports = __rspack_createRequire_require("../compiled/import-lazy/index.js");
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var __webpack_module_cache__ = {};
|
|
9
|
+
function __webpack_require__(moduleId) {
|
|
10
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
11
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
12
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
13
|
+
exports: {}
|
|
14
|
+
};
|
|
15
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
16
|
+
return module.exports;
|
|
17
|
+
}
|
|
18
|
+
const lazy = (moduleName, requireFn)=>{
|
|
19
|
+
const importLazyLocal = __webpack_require__("../compiled/import-lazy")(requireFn);
|
|
20
|
+
return importLazyLocal(moduleName);
|
|
21
|
+
};
|
|
22
|
+
const Import = {
|
|
23
|
+
lazy
|
|
24
|
+
};
|
|
25
|
+
export { Import, lazy as lazyImport };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
|
|
2
|
+
const ROUTE_MODULES = "_routeModules";
|
|
3
|
+
const HTML_CHUNKSMAP_SEPARATOR = '<!--<?- chunksMap.js ?>-->';
|
|
4
|
+
const LOADER_REPORTER_NAME = "server-loader";
|
|
5
|
+
const ROUTE_SPEC_FILE = 'route.json';
|
|
6
|
+
const NESTED_ROUTE_SPEC_FILE = 'nestedRoutes.json';
|
|
7
|
+
const MAIN_ENTRY_NAME = 'main';
|
|
8
|
+
const DEFAULT_ENTRY_NAME = 'index';
|
|
9
|
+
const SERVER_BUNDLE_DIRECTORY = 'bundles';
|
|
10
|
+
const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
11
|
+
const SERVER_PLUGIN_BFF = '@modern-js/plugin-bff';
|
|
12
|
+
const SERVER_PLUGIN_POLYFILL = '@modern-js/plugin-polyfill';
|
|
13
|
+
export { DEFAULT_ENTRY_NAME, HTML_CHUNKSMAP_SEPARATOR, LOADER_REPORTER_NAME, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST, ROUTE_MODULES, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_PLUGIN_BFF, SERVER_PLUGIN_POLYFILL, SERVER_RENDER_FUNCTION_NAME };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const pluginDagSort = (plugins, key = 'name', preKey = 'pre', postKey = 'post')=>{
|
|
2
|
+
let allLines = [];
|
|
3
|
+
function getPluginByAny(q) {
|
|
4
|
+
const target = plugins.find((item)=>'string' == typeof q ? item[key] === q : item[key] === q[key]);
|
|
5
|
+
if (!target) throw new Error(`plugin ${q} not existed`);
|
|
6
|
+
return target;
|
|
7
|
+
}
|
|
8
|
+
plugins.forEach((item)=>{
|
|
9
|
+
item[preKey]?.forEach((p)=>{
|
|
10
|
+
if (plugins.find((ap)=>ap.name === p)) allLines.push([
|
|
11
|
+
getPluginByAny(p)[key],
|
|
12
|
+
getPluginByAny(item)[key]
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
item[postKey]?.forEach((pt)=>{
|
|
16
|
+
if (plugins.find((ap)=>ap.name === pt)) allLines.push([
|
|
17
|
+
getPluginByAny(item)[key],
|
|
18
|
+
getPluginByAny(pt)[key]
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
let zeroEndPoints = plugins.filter((item)=>!allLines.find((l)=>l[1] === item[key]));
|
|
23
|
+
const sortedPoint = [];
|
|
24
|
+
while(zeroEndPoints.length){
|
|
25
|
+
const zep = zeroEndPoints.shift();
|
|
26
|
+
sortedPoint.push(getPluginByAny(zep));
|
|
27
|
+
allLines = allLines.filter((l)=>l[0] !== getPluginByAny(zep)[key]);
|
|
28
|
+
const restPoints = plugins.filter((item)=>!sortedPoint.find((sp)=>sp[key] === item[key]));
|
|
29
|
+
zeroEndPoints = restPoints.filter((item)=>!allLines.find((l)=>l[1] === item[key]));
|
|
30
|
+
}
|
|
31
|
+
if (allLines.length) {
|
|
32
|
+
const restInRingPoints = {};
|
|
33
|
+
allLines.forEach((l)=>{
|
|
34
|
+
restInRingPoints[l[0]] = true;
|
|
35
|
+
restInRingPoints[l[1]] = true;
|
|
36
|
+
});
|
|
37
|
+
throw new Error(`plugins dependencies has loop: ${Object.keys(restInRingPoints).join(',')}`);
|
|
38
|
+
}
|
|
39
|
+
return sortedPoint;
|
|
40
|
+
};
|
|
41
|
+
export { pluginDagSort };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { applyOptionsChain } from "./applyOptionsChain.mjs";
|
|
4
|
+
import { readTsConfigByFile } from "./get/index.mjs";
|
|
5
|
+
const mergeAlias = (alias)=>applyOptionsChain({}, alias);
|
|
6
|
+
const getAliasConfig = (aliasOption, option)=>{
|
|
7
|
+
const isTsProject = fs.existsSync(option.tsconfigPath);
|
|
8
|
+
const alias = mergeAlias(aliasOption);
|
|
9
|
+
if (!isTsProject) return {
|
|
10
|
+
absoluteBaseUrl: option.appDirectory,
|
|
11
|
+
paths: alias,
|
|
12
|
+
isTsPath: false,
|
|
13
|
+
isTsProject
|
|
14
|
+
};
|
|
15
|
+
const tsconfig = readTsConfigByFile(option.tsconfigPath);
|
|
16
|
+
const baseUrl = tsconfig?.compilerOptions?.baseUrl;
|
|
17
|
+
return {
|
|
18
|
+
absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
|
|
19
|
+
paths: {
|
|
20
|
+
...alias,
|
|
21
|
+
...tsconfig?.compilerOptions?.paths
|
|
22
|
+
},
|
|
23
|
+
isTsPath: true,
|
|
24
|
+
isTsProject
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const getUserAlias = (alias = {})=>Object.keys(alias).reduce((o, k)=>{
|
|
28
|
+
if (Array.isArray(alias[k])) o[k] = alias[k];
|
|
29
|
+
return o;
|
|
30
|
+
}, {});
|
|
31
|
+
export { getAliasConfig, getUserAlias, mergeAlias };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isFunction, isPlainObject } from "./is/index.mjs";
|
|
2
|
+
import { logger } from "./logger.mjs";
|
|
3
|
+
function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
|
|
4
|
+
if (!options) return defaults;
|
|
5
|
+
if (isPlainObject(options)) return mergeFn(defaults, options);
|
|
6
|
+
if (isFunction(options)) {
|
|
7
|
+
const ret = options(defaults, utils);
|
|
8
|
+
if (ret) {
|
|
9
|
+
if (!isPlainObject(ret)) logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
|
|
10
|
+
return ret;
|
|
11
|
+
}
|
|
12
|
+
} else if (Array.isArray(options)) return options.reduce((memo, cur)=>applyOptionsChain(memo, cur, utils, mergeFn), defaults);
|
|
13
|
+
else throw new Error(`applyOptionsChain error:\ndefault options is: ${JSON.stringify(defaults)}`);
|
|
14
|
+
return defaults;
|
|
15
|
+
}
|
|
16
|
+
export { applyOptionsChain };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { isAbsolute, sep } from "path";
|
|
2
|
+
import { applyOptionsChain } from "./applyOptionsChain.mjs";
|
|
3
|
+
import { ensureArray } from "./ensure.mjs";
|
|
4
|
+
import { normalizeToPosixPath } from "./path.mjs";
|
|
5
|
+
const formatPath = (originPath)=>{
|
|
6
|
+
if (isAbsolute(originPath)) return originPath.split(sep).join('/');
|
|
7
|
+
return originPath;
|
|
8
|
+
};
|
|
9
|
+
const getPluginItemName = (item)=>{
|
|
10
|
+
if ('string' == typeof item) return formatPath(item);
|
|
11
|
+
if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
const addPlugins = (plugins, config)=>{
|
|
15
|
+
if (config.plugins) config.plugins.push(...plugins);
|
|
16
|
+
else config.plugins = plugins;
|
|
17
|
+
};
|
|
18
|
+
const addPresets = (presets, config)=>{
|
|
19
|
+
if (config.presets) config.presets.push(...presets);
|
|
20
|
+
else config.presets = presets;
|
|
21
|
+
};
|
|
22
|
+
const removePlugins = (plugins, config)=>{
|
|
23
|
+
if (!config.plugins) return;
|
|
24
|
+
const removeList = ensureArray(plugins);
|
|
25
|
+
config.plugins = config.plugins.filter((item)=>{
|
|
26
|
+
const name = getPluginItemName(item);
|
|
27
|
+
if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const removePresets = (presets, config)=>{
|
|
32
|
+
if (!config.presets) return;
|
|
33
|
+
const removeList = ensureArray(presets);
|
|
34
|
+
config.presets = config.presets.filter((item)=>{
|
|
35
|
+
const name = getPluginItemName(item);
|
|
36
|
+
if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const modifyPresetOptions = (presetName, options, presets = [])=>{
|
|
41
|
+
presets.forEach((preset, index)=>{
|
|
42
|
+
if (Array.isArray(preset)) {
|
|
43
|
+
if ('string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName)) preset[1] = {
|
|
44
|
+
...preset[1] || {},
|
|
45
|
+
...options
|
|
46
|
+
};
|
|
47
|
+
} else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) presets[index] = [
|
|
48
|
+
preset,
|
|
49
|
+
options
|
|
50
|
+
];
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const getBabelUtils = (config)=>{
|
|
54
|
+
const noop = ()=>{};
|
|
55
|
+
return {
|
|
56
|
+
addPlugins: (plugins)=>addPlugins(plugins, config),
|
|
57
|
+
addPresets: (presets)=>addPresets(presets, config),
|
|
58
|
+
removePlugins: (plugins)=>removePlugins(plugins, config),
|
|
59
|
+
removePresets: (presets)=>removePresets(presets, config),
|
|
60
|
+
addIncludes: noop,
|
|
61
|
+
addExcludes: noop,
|
|
62
|
+
modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
|
|
63
|
+
modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
|
|
67
|
+
if (userBabelConfig) {
|
|
68
|
+
const babelUtils = {
|
|
69
|
+
...getBabelUtils(defaultOptions),
|
|
70
|
+
...extraBabelUtils
|
|
71
|
+
};
|
|
72
|
+
return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
|
|
73
|
+
}
|
|
74
|
+
return defaultOptions;
|
|
75
|
+
};
|
|
76
|
+
export { applyUserBabelConfig, getBabelUtils };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { logger } from "./logger.mjs";
|
|
2
|
+
const getFullArgv = ()=>process.env.MODERN_ARGV?.split(' ') || process.argv;
|
|
3
|
+
const getArgv = ()=>getFullArgv().slice(2);
|
|
4
|
+
const getCommand = ()=>{
|
|
5
|
+
const args = getArgv();
|
|
6
|
+
const command = args[0];
|
|
7
|
+
return command;
|
|
8
|
+
};
|
|
9
|
+
const isDevCommand = ()=>{
|
|
10
|
+
const command = getCommand();
|
|
11
|
+
return 'dev' === command || 'start' === command;
|
|
12
|
+
};
|
|
13
|
+
const deprecatedCommands = (program)=>{
|
|
14
|
+
const lintCommand = program.commandsMap?.get('lint');
|
|
15
|
+
if (!lintCommand) program.command('lint [...files]').allowUnknownOption().description('Deprecated').action(()=>{
|
|
16
|
+
logger.warn('The "modern lint" command is deprecated, please use "eslint" or "biome" instead.');
|
|
17
|
+
});
|
|
18
|
+
const preCommitCommand = program.commandsMap?.get('pre-commit');
|
|
19
|
+
if (!preCommitCommand) program.command('pre-commit').description('Deprecated').action(()=>{
|
|
20
|
+
logger.warn('The "modern pre-commit" command is deprecated, please use "lint-staged" instead.');
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export { deprecatedCommands, getArgv, getCommand, getFullArgv, isDevCommand };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire as __rspack_createRequire } from "node:module";
|
|
2
|
+
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
3
|
+
const index_js_namespaceObject = __rspack_createRequire_require("../../compiled/debug/index.js");
|
|
4
|
+
const createDebugger = (scope)=>(0, index_js_namespaceObject.debug)(`modern-js:${scope}`);
|
|
5
|
+
const clearConsole = ()=>{
|
|
6
|
+
if (process.stdout.isTTY && !process.env.DEBUG) process.stdout.write('\x1B[H\x1B[2J');
|
|
7
|
+
};
|
|
8
|
+
const wait = (time = 0)=>new Promise((resolve)=>{
|
|
9
|
+
setTimeout(resolve, time);
|
|
10
|
+
});
|
|
11
|
+
export { clearConsole, createDebugger, wait };
|