@modern-js/utils 3.0.0-alpha.1 → 3.0.0-alpha.2
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/common.js +12 -2
- package/dist/cjs/cli/index.js +32 -39
- package/dist/cjs/cli/is/project.js +7 -12
- package/dist/cjs/cli/require.js +32 -30
- package/dist/cjs/compiled.js +90 -89
- package/dist/cjs/import.js +23 -28
- package/dist/compiled/commander/index.mjs +2 -0
- package/dist/compiled/js-yaml/index.js +102 -99
- package/dist/compiled/js-yaml/index.mjs +2167 -0
- package/dist/compiled/js-yaml/index.mjs.LICENSE.txt +1 -0
- package/dist/compiled/js-yaml/package.json +1 -1
- package/dist/compiled/lodash/index.mjs +1 -0
- package/dist/compiled/nanoid/index.js +4 -4
- package/dist/compiled/nanoid/index.mjs +69 -0
- package/dist/compiled/nanoid/package.json +1 -1
- package/dist/compiled/tsconfig-paths/index.mjs +2 -0
- package/dist/esm/cli/alias.mjs +2 -2
- package/dist/esm/cli/applyOptionsChain.mjs +2 -2
- package/dist/esm/cli/commands.mjs +1 -1
- package/dist/esm/cli/common.mjs +2 -4
- package/dist/esm/cli/constants.mjs +1 -1
- package/dist/esm/cli/fs.mjs +1 -1
- package/dist/esm/cli/get/config.mjs +1 -1
- package/dist/esm/cli/get/data.mjs +3 -3
- package/dist/esm/cli/get/index.mjs +4 -4
- package/dist/esm/cli/index.mjs +21 -22
- package/dist/esm/cli/is/config.mjs +2 -2
- package/dist/esm/cli/is/index.mjs +4 -4
- package/dist/esm/cli/is/project.mjs +10 -39
- package/dist/esm/cli/monorepo.mjs +1 -1
- package/dist/esm/cli/package.mjs +1 -1
- package/dist/esm/cli/path.mjs +1 -1
- package/dist/esm/cli/port.mjs +2 -2
- package/dist/esm/cli/prettyInstructions.mjs +3 -3
- package/dist/esm/cli/require.mjs +43 -37
- package/dist/esm/cli/route.mjs +1 -1
- package/dist/esm/cli/watch.mjs +1 -1
- package/dist/esm/compiled.mjs +46 -111
- package/dist/esm/import.mjs +3 -19
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/universal/index.mjs +1 -1
- package/dist/esm-node/cli/alias.mjs +2 -0
- package/dist/esm-node/cli/applyOptionsChain.mjs +2 -0
- package/dist/esm-node/cli/commands.mjs +2 -0
- package/dist/esm-node/cli/common.mjs +4 -4
- package/dist/esm-node/cli/config.mjs +2 -0
- package/dist/esm-node/cli/constants.mjs +2 -0
- package/dist/esm-node/cli/ensure.mjs +2 -0
- package/dist/esm-node/cli/fs.mjs +2 -0
- package/dist/esm-node/cli/get/config.mjs +2 -0
- package/dist/esm-node/cli/get/data.mjs +2 -0
- package/dist/esm-node/cli/get/index.mjs +2 -0
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/cli/is/config.mjs +2 -0
- package/dist/esm-node/cli/is/env.mjs +2 -0
- package/dist/esm-node/cli/is/index.mjs +2 -0
- package/dist/esm-node/cli/is/project.mjs +8 -35
- package/dist/esm-node/cli/is/type.mjs +2 -0
- package/dist/esm-node/cli/logger.mjs +2 -0
- package/dist/esm-node/cli/monorepo.mjs +2 -0
- package/dist/esm-node/cli/package.mjs +2 -0
- package/dist/esm-node/cli/path.mjs +2 -0
- package/dist/esm-node/cli/port.mjs +2 -0
- package/dist/esm-node/cli/prettyInstructions.mjs +2 -0
- package/dist/esm-node/cli/require.mjs +44 -36
- package/dist/esm-node/cli/route.mjs +2 -0
- package/dist/esm-node/cli/runtimeExports.mjs +2 -0
- package/dist/esm-node/cli/version.mjs +2 -0
- package/dist/esm-node/cli/watch.mjs +2 -0
- package/dist/esm-node/compiled.mjs +39 -113
- package/dist/esm-node/import.mjs +5 -19
- package/dist/esm-node/index.mjs +2 -0
- package/dist/esm-node/universal/constants.mjs +2 -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 +2 -0
- package/dist/types/cli/common.d.ts +2 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/require.d.ts +1 -13
- package/dist/types/compiled.d.ts +2 -1
- package/dist/types/import.d.ts +2 -2
- package/package.json +36 -56
- package/rslib.config.mts +49 -26
- package/rstest.config.ts +8 -0
- package/dist/cjs/cli/babel.js +0 -113
- package/dist/esm/cli/babel.mjs +0 -76
- package/dist/esm-node/cli/babel.mjs +0 -76
- package/dist/types/cli/babel.d.ts +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"js-yaml","author":"Vladimir Zapparov <dervus.grim@gmail.com>","version":"4.1.
|
|
1
|
+
{"name":"js-yaml","author":"Vladimir Zapparov <dervus.grim@gmail.com>","version":"4.1.1","license":"MIT","main":"index.js","module":"index.mjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'lodash-es';
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"use strict";
|
|
5
5
|
e.exports = require("crypto");
|
|
6
6
|
},
|
|
7
|
-
|
|
7
|
+
812: (e, r, t)=>{
|
|
8
8
|
let l = t(982);
|
|
9
|
-
let { urlAlphabet: a } = t(
|
|
9
|
+
let { urlAlphabet: a } = t(132);
|
|
10
10
|
const n = 128;
|
|
11
11
|
let _, u;
|
|
12
12
|
let fillPool = (e)=>{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
random: random
|
|
55
55
|
};
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
132: (e)=>{
|
|
58
58
|
let r = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
59
59
|
e.exports = {
|
|
60
60
|
urlAlphabet: r
|
|
@@ -78,6 +78,6 @@
|
|
|
78
78
|
return a.exports;
|
|
79
79
|
}
|
|
80
80
|
if (void 0 !== __nccwpck_require__) __nccwpck_require__.ab = __dirname + "/";
|
|
81
|
-
var t = __nccwpck_require__(
|
|
81
|
+
var t = __nccwpck_require__(812);
|
|
82
82
|
module.exports = t;
|
|
83
83
|
})();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createRequire as e } from "module";
|
|
2
|
+
var t = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
t.d = (e, r)=>{
|
|
5
|
+
for(var l in r)if (t.o(r, l) && !t.o(e, l)) Object.defineProperty(e, l, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: r[l]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
t.o = (e, t)=>Object.prototype.hasOwnProperty.call(e, t);
|
|
13
|
+
})();
|
|
14
|
+
if (void 0 !== t) t.ab = new URL(".", import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/";
|
|
15
|
+
var r = {};
|
|
16
|
+
t.d(r, {
|
|
17
|
+
d_: ()=>customAlphabet,
|
|
18
|
+
NM: ()=>customRandom,
|
|
19
|
+
Ak: ()=>nanoid,
|
|
20
|
+
yT: ()=>random,
|
|
21
|
+
xO: ()=>a
|
|
22
|
+
});
|
|
23
|
+
const l = e(import.meta.url)("crypto");
|
|
24
|
+
let a = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
25
|
+
const n = 128;
|
|
26
|
+
let o, i;
|
|
27
|
+
let fillPool = (e)=>{
|
|
28
|
+
if (!o || o.length < e) {
|
|
29
|
+
o = Buffer.allocUnsafe(e * n);
|
|
30
|
+
l.randomFillSync(o);
|
|
31
|
+
i = 0;
|
|
32
|
+
} else if (i + e > o.length) {
|
|
33
|
+
l.randomFillSync(o);
|
|
34
|
+
i = 0;
|
|
35
|
+
}
|
|
36
|
+
i += e;
|
|
37
|
+
};
|
|
38
|
+
let random = (e)=>{
|
|
39
|
+
fillPool(e |= 0);
|
|
40
|
+
return o.subarray(i - e, i);
|
|
41
|
+
};
|
|
42
|
+
let customRandom = (e, t, r)=>{
|
|
43
|
+
let l = (2 << 31 - Math.clz32(e.length - 1 | 1)) - 1;
|
|
44
|
+
let a = Math.ceil(1.6 * l * t / e.length);
|
|
45
|
+
return (n = t)=>{
|
|
46
|
+
let o = "";
|
|
47
|
+
while(true){
|
|
48
|
+
let t = r(a);
|
|
49
|
+
let i = a;
|
|
50
|
+
while(i--){
|
|
51
|
+
o += e[t[i] & l] || "";
|
|
52
|
+
if (o.length === n) return o;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
let customAlphabet = (e, t = 21)=>customRandom(e, t, random);
|
|
58
|
+
let nanoid = (e = 21)=>{
|
|
59
|
+
fillPool(e |= 0);
|
|
60
|
+
let t = "";
|
|
61
|
+
for(let r = i - e; r < i; r++)t += a[63 & o[r]];
|
|
62
|
+
return t;
|
|
63
|
+
};
|
|
64
|
+
var m = r.d_;
|
|
65
|
+
var u = r.NM;
|
|
66
|
+
var c = r.Ak;
|
|
67
|
+
var f = r.yT;
|
|
68
|
+
var s = r.xO;
|
|
69
|
+
export { m as customAlphabet, u as customRandom, c as nanoid, f as random, s as urlAlphabet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"nanoid","author":"Andrey Sitnik <andrey@sitnik.ru>","version":"3.3.11","funding":[{"type":"github","url":"https://github.com/sponsors/ai"}],"license":"MIT","types":"./index.d.ts"}
|
|
1
|
+
{"name":"nanoid","author":"Andrey Sitnik <andrey@sitnik.ru>","version":"3.3.11","funding":[{"type":"github","url":"https://github.com/sponsors/ai"}],"license":"MIT","types":"./index.d.ts","main":"index.js","module":"index.mjs"}
|
package/dist/esm/cli/alias.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { applyOptionsChain } from "./applyOptionsChain";
|
|
4
|
-
import { readTsConfigByFile } from "./get";
|
|
3
|
+
import { applyOptionsChain } from "./applyOptionsChain.mjs";
|
|
4
|
+
import { readTsConfigByFile } from "./get/index.mjs";
|
|
5
5
|
const mergeAlias = (alias)=>applyOptionsChain({}, alias);
|
|
6
6
|
const getAliasConfig = (aliasOption, option)=>{
|
|
7
7
|
const isTsProject = fs.existsSync(option.tsconfigPath);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isFunction, isPlainObject } from "./is";
|
|
2
|
-
import { logger } from "./logger";
|
|
1
|
+
import { isFunction, isPlainObject } from "./is/index.mjs";
|
|
2
|
+
import { logger } from "./logger.mjs";
|
|
3
3
|
function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
|
|
4
4
|
if (!options) return defaults;
|
|
5
5
|
if (isPlainObject(options)) return mergeFn(defaults, options);
|
package/dist/esm/cli/common.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
const index_js_namespaceObject = __rspack_createRequire_require("../../compiled/debug/index.js");
|
|
4
|
-
const createDebugger = (scope)=>(0, index_js_namespaceObject.debug)(`modern-js:${scope}`);
|
|
1
|
+
import debug from "../../compiled/debug/index.js";
|
|
2
|
+
const createDebugger = (scope)=>debug(`modern-js:${scope}`);
|
|
5
3
|
const clearConsole = ()=>{
|
|
6
4
|
if (process.stdout.isTTY && !process.env.DEBUG) process.stdout.write('\x1B[H\x1B[2J');
|
|
7
5
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_ENTRY_NAME, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_PLUGIN_BFF, SERVER_PLUGIN_POLYFILL, SERVER_RENDER_FUNCTION_NAME } from "../universal/constants";
|
|
1
|
+
import { DEFAULT_ENTRY_NAME, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_PLUGIN_BFF, SERVER_PLUGIN_POLYFILL, SERVER_RENDER_FUNCTION_NAME } from "../universal/constants.mjs";
|
|
2
2
|
const JS_EXTENSIONS = [
|
|
3
3
|
'.js',
|
|
4
4
|
'.ts',
|
package/dist/esm/cli/fs.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import os from "os";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { browserslist, fs, json5 } from "../../compiled";
|
|
4
|
-
import { isDepExists } from "../is";
|
|
5
|
-
import { canUsePnpm, canUseYarn } from "../package";
|
|
3
|
+
import { browserslist, fs, json5 } from "../../compiled.mjs";
|
|
4
|
+
import { isDepExists } from "../is/index.mjs";
|
|
5
|
+
import { canUsePnpm, canUseYarn } from "../package.mjs";
|
|
6
6
|
const MAX_TIMES = 5;
|
|
7
7
|
async function getPackageManager(cwd = process.cwd()) {
|
|
8
8
|
let appDirectory = cwd;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { CONFIG_FILE_EXTENSIONS } from "../constants";
|
|
3
|
-
import { findExists } from "../fs";
|
|
4
|
-
export * from "./data";
|
|
5
|
-
export * from "./config";
|
|
2
|
+
import { CONFIG_FILE_EXTENSIONS } from "../constants.mjs";
|
|
3
|
+
import { findExists } from "../fs.mjs";
|
|
4
|
+
export * from "./data.mjs";
|
|
5
|
+
export * from "./config.mjs";
|
|
6
6
|
const getServerConfig = async (appDirectory, configFile)=>{
|
|
7
7
|
const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(appDirectory, `${configFile}${extension}`)));
|
|
8
8
|
return configFilePath;
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
|
-
export * from "./get";
|
|
3
|
-
export * from "./is";
|
|
4
|
-
export * from "./alias";
|
|
5
|
-
export * from "./applyOptionsChain";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./
|
|
12
|
-
export * from "./
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
-
export * from "./
|
|
18
|
-
export * from "./
|
|
19
|
-
export * from "./
|
|
20
|
-
export * from "./
|
|
21
|
-
export * from "./
|
|
22
|
-
export * from "./route";
|
|
1
|
+
export * from "./constants.mjs";
|
|
2
|
+
export * from "./get/index.mjs";
|
|
3
|
+
export * from "./is/index.mjs";
|
|
4
|
+
export * from "./alias.mjs";
|
|
5
|
+
export * from "./applyOptionsChain.mjs";
|
|
6
|
+
export * from "./commands.mjs";
|
|
7
|
+
export * from "./common.mjs";
|
|
8
|
+
export * from "./ensure.mjs";
|
|
9
|
+
export * from "./fs.mjs";
|
|
10
|
+
export * from "./logger.mjs";
|
|
11
|
+
export * from "./monorepo.mjs";
|
|
12
|
+
export * from "./package.mjs";
|
|
13
|
+
export * from "./path.mjs";
|
|
14
|
+
export * from "./port.mjs";
|
|
15
|
+
export * from "./prettyInstructions.mjs";
|
|
16
|
+
export * from "./require.mjs";
|
|
17
|
+
export * from "./runtimeExports.mjs";
|
|
18
|
+
export * from "./watch.mjs";
|
|
19
|
+
export * from "./config.mjs";
|
|
20
|
+
export * from "./version.mjs";
|
|
21
|
+
export * from "./route.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./env";
|
|
2
|
-
export * from "./type";
|
|
3
|
-
export * from "./config";
|
|
4
|
-
export * from "./project";
|
|
1
|
+
export * from "./env.mjs";
|
|
2
|
+
export * from "./type.mjs";
|
|
3
|
+
export * from "./config.mjs";
|
|
4
|
+
export * from "./project.mjs";
|
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
var __webpack_require__ = {};
|
|
9
|
-
(()=>{
|
|
10
|
-
__webpack_require__.n = (module)=>{
|
|
11
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
12
|
-
__webpack_require__.d(getter, {
|
|
13
|
-
a: getter
|
|
14
|
-
});
|
|
15
|
-
return getter;
|
|
16
|
-
};
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
20
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: definition[key]
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
})();
|
|
26
|
-
(()=>{
|
|
27
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
28
|
-
})();
|
|
29
|
-
const index_js_namespaceObject = __rspack_createRequire_require("../../../compiled/pkg-up/index.js");
|
|
30
|
-
var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject);
|
|
2
|
+
import pkg_up from "../../../compiled/pkg-up/index.js";
|
|
3
|
+
import { fs, minimist, semver } from "../../compiled.mjs";
|
|
4
|
+
import { getArgv } from "../commands.mjs";
|
|
5
|
+
import { createDebugger } from "../common.mjs";
|
|
6
|
+
import { ensureArray } from "../ensure.mjs";
|
|
7
|
+
import { tryResolve } from "../require.mjs";
|
|
31
8
|
const debug = createDebugger('judge-depExists');
|
|
32
9
|
const isDepExists = (appDirectory, name)=>{
|
|
33
10
|
const pkgPath = path.resolve(appDirectory, './package.json');
|
|
@@ -35,15 +12,13 @@ const isDepExists = (appDirectory, name)=>{
|
|
|
35
12
|
debug("can't find package.json under: %s", appDirectory);
|
|
36
13
|
return false;
|
|
37
14
|
}
|
|
38
|
-
const json =
|
|
15
|
+
const json = fs.readJSONSync(pkgPath);
|
|
39
16
|
const { dependencies = {}, devDependencies = {} } = json;
|
|
40
17
|
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
|
41
18
|
};
|
|
42
19
|
const isPackageInstalled = (name, resolvePaths)=>{
|
|
43
20
|
try {
|
|
44
|
-
|
|
45
|
-
paths: ensureArray(resolvePaths)
|
|
46
|
-
});
|
|
21
|
+
tryResolve(name, ...ensureArray(resolvePaths));
|
|
47
22
|
return true;
|
|
48
23
|
} catch (err) {
|
|
49
24
|
return false;
|
|
@@ -62,7 +37,7 @@ const isWebOnly = async ()=>{
|
|
|
62
37
|
};
|
|
63
38
|
const isVersionBeyond17 = (version)=>semver.gte(semver.minVersion(version), '17.0.0');
|
|
64
39
|
const getReactVersion = (cwd)=>{
|
|
65
|
-
const pkgPath =
|
|
40
|
+
const pkgPath = pkg_up.sync({
|
|
66
41
|
cwd
|
|
67
42
|
});
|
|
68
43
|
if (!pkgPath) return false;
|
|
@@ -73,11 +48,7 @@ const getReactVersion = (cwd)=>{
|
|
|
73
48
|
};
|
|
74
49
|
if ('string' != typeof deps.react) return false;
|
|
75
50
|
try {
|
|
76
|
-
const reactPath =
|
|
77
|
-
paths: [
|
|
78
|
-
cwd
|
|
79
|
-
]
|
|
80
|
-
});
|
|
51
|
+
const reactPath = tryResolve('react/package.json', cwd);
|
|
81
52
|
const reactVersion = JSON.parse(fs.readFileSync(reactPath, 'utf8')).version;
|
|
82
53
|
return reactVersion;
|
|
83
54
|
} catch (error) {
|
package/dist/esm/cli/package.mjs
CHANGED
package/dist/esm/cli/path.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import os from "os";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { nanoid, upath } from "../compiled";
|
|
4
|
+
import { nanoid, upath } from "../compiled.mjs";
|
|
5
5
|
const isPathString = (test)=>path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
|
6
6
|
const isRelativePath = (test)=>/^\.\.?($|[\\/])/.test(test);
|
|
7
7
|
const normalizeOutputPath = (s)=>s.replace(/\\/g, '\\\\');
|
package/dist/esm/cli/port.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import net from "net";
|
|
2
|
-
import { chalk } from "../compiled";
|
|
3
|
-
import { logger } from "./logger";
|
|
2
|
+
import { chalk } from "../compiled.mjs";
|
|
3
|
+
import { logger } from "./logger.mjs";
|
|
4
4
|
const getPort = async (expectPort, { tryLimits = 20, strictPort = false, slient = false } = {})=>{
|
|
5
5
|
let port = expectPort;
|
|
6
6
|
if ('string' == typeof port) port = parseInt(port, 10);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isIPv6 } from "net";
|
|
2
2
|
import os from "os";
|
|
3
|
-
import { chalk } from "../compiled";
|
|
4
|
-
import { DEFAULT_DEV_HOST } from "./constants";
|
|
5
|
-
import { isDev, isSingleEntry } from "./is";
|
|
3
|
+
import { chalk } from "../compiled.mjs";
|
|
4
|
+
import { DEFAULT_DEV_HOST } from "./constants.mjs";
|
|
5
|
+
import { isDev, isSingleEntry } from "./is/index.mjs";
|
|
6
6
|
const normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1');
|
|
7
7
|
const getIpv4Interfaces = ()=>{
|
|
8
8
|
const interfaces = os.networkInterfaces();
|
package/dist/esm/cli/require.mjs
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { isAbsolute } from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
3
|
+
import { moduleResolve } from "import-meta-resolve";
|
|
4
|
+
import { findExists } from "./fs.mjs";
|
|
5
|
+
async function importPath(path, options) {
|
|
6
|
+
const modulePath = isAbsolute(path) ? pathToFileURL(path).href : path;
|
|
7
|
+
if ('development' !== process.env.NODE_ENV) return await import(modulePath, options);
|
|
8
|
+
{
|
|
9
|
+
const timestamp = Date.now();
|
|
10
|
+
return await import(`${modulePath}?t=${timestamp}`, options);
|
|
19
11
|
}
|
|
20
|
-
|
|
12
|
+
}
|
|
13
|
+
async function compatibleRequireESM(path, interop = true) {
|
|
14
|
+
if (path.endsWith('.json')) {
|
|
15
|
+
const res = await importPath(path, {
|
|
16
|
+
with: {
|
|
17
|
+
type: 'json'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return res.default;
|
|
21
|
+
}
|
|
22
|
+
const requiredModule = await importPath(path);
|
|
23
|
+
return interop ? requiredModule.default : requiredModule;
|
|
24
|
+
}
|
|
25
|
+
async function compatibleRequire(path, interop = true) {
|
|
26
|
+
return await compatibleRequireESM(path, interop);
|
|
21
27
|
}
|
|
22
28
|
async function loadFromProject(moduleName, appDir) {
|
|
23
29
|
let requiredModule;
|
|
@@ -26,11 +32,10 @@ async function loadFromProject(moduleName, appDir) {
|
|
|
26
32
|
process.cwd()
|
|
27
33
|
];
|
|
28
34
|
try {
|
|
35
|
+
const modulePath = tryResolve(moduleName, ...paths);
|
|
29
36
|
{
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
requiredModule = require(modulePath);
|
|
37
|
+
const moduleUrl = pathToFileURL(modulePath).href;
|
|
38
|
+
requiredModule = await import(moduleUrl);
|
|
34
39
|
}
|
|
35
40
|
return requiredModule.default || requiredModule;
|
|
36
41
|
} catch (error) {
|
|
@@ -52,28 +57,29 @@ const requireExistModule = async (filename, opt)=>{
|
|
|
52
57
|
if (!exist) return null;
|
|
53
58
|
return compatibleRequire(exist, final.interop);
|
|
54
59
|
};
|
|
55
|
-
const cleanRequireCache = (filelist)=>{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
const cleanRequireCache = (filelist)=>{};
|
|
61
|
+
const tryResolveESM = (name, ...resolvePath)=>{
|
|
62
|
+
const conditions = new Set([
|
|
63
|
+
'node',
|
|
64
|
+
'import',
|
|
65
|
+
'module',
|
|
66
|
+
'default'
|
|
67
|
+
]);
|
|
68
|
+
for (const p of resolvePath)try {
|
|
69
|
+
return moduleResolve(name, pathToFileURL(`${p}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:');
|
|
70
|
+
} catch (err) {}
|
|
71
|
+
const err = new Error(`Can not find module ${name}.`);
|
|
72
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
73
|
+
throw err;
|
|
59
74
|
};
|
|
60
|
-
|
|
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)=>{
|
|
75
|
+
const tryResolve = (name, ...resolvePath)=>{
|
|
65
76
|
let filePath = '';
|
|
66
77
|
try {
|
|
67
|
-
filePath =
|
|
68
|
-
paths: [
|
|
69
|
-
resolvePath
|
|
70
|
-
]
|
|
71
|
-
});
|
|
72
|
-
delete require.cache[filePath];
|
|
78
|
+
filePath = tryResolveESM(name, ...resolvePath);
|
|
73
79
|
} catch (err) {
|
|
74
80
|
if ('MODULE_NOT_FOUND' === err.code) throw new Error(`Can not find module ${name}.`);
|
|
75
81
|
throw err;
|
|
76
82
|
}
|
|
77
83
|
return filePath;
|
|
78
84
|
};
|
|
79
|
-
export { cleanRequireCache, compatibleRequire,
|
|
85
|
+
export { cleanRequireCache, compatibleRequire, dynamicImport, loadFromProject, requireExistModule, tryResolve };
|
package/dist/esm/cli/route.mjs
CHANGED
package/dist/esm/cli/watch.mjs
CHANGED