@flex-development/mlly 1.0.0-alpha.11 → 1.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -0
- package/README.md +1 -1
- package/dist/interfaces/options-get-format.d.mts +3 -13
- package/dist/interfaces/options-get-source.d.mts +3 -13
- package/dist/interfaces/options-parse-subpath.d.mts +18 -0
- package/dist/interfaces/parsed-subpath.d.mts +5 -1
- package/dist/internal/regex-invalid-segment.d.mts +14 -0
- package/dist/internal/regex-invalid-segment.mjs +11 -0
- package/dist/internal/regex-invalid-segment.mjs.map +6 -0
- package/dist/internal/resolver.mjs +6 -9
- package/dist/internal/resolver.mjs.map +1 -1
- package/dist/internal/validate-array-set.d.mts +22 -0
- package/dist/internal/validate-array-set.mjs +11 -0
- package/dist/internal/validate-array-set.mjs.map +6 -0
- package/dist/internal/validate-map.d.mts +23 -0
- package/dist/internal/validate-map.mjs +11 -0
- package/dist/internal/validate-map.mjs.map +6 -0
- package/dist/internal/validate-set.d.mts +4 -5
- package/dist/internal/validate-set.mjs.map +1 -1
- package/dist/utils/fill-modules.d.mts +1 -0
- package/dist/utils/fill-modules.mjs +7 -1
- package/dist/utils/fill-modules.mjs.map +1 -1
- package/dist/utils/find-requires.mjs +1 -1
- package/dist/utils/find-subpath.d.mts +2 -1
- package/dist/utils/find-subpath.mjs +2 -0
- package/dist/utils/find-subpath.mjs.map +1 -1
- package/dist/utils/get-format.d.mts +8 -1
- package/dist/utils/get-format.mjs +22 -11
- package/dist/utils/get-format.mjs.map +1 -1
- package/dist/utils/get-source.d.mts +7 -0
- package/dist/utils/get-source.mjs +13 -6
- package/dist/utils/get-source.mjs.map +1 -1
- package/dist/utils/is-absolute-specifier.d.mts +1 -0
- package/dist/utils/is-absolute-specifier.mjs +2 -0
- package/dist/utils/is-absolute-specifier.mjs.map +1 -1
- package/dist/utils/is-bare-specifier.d.mts +1 -0
- package/dist/utils/is-bare-specifier.mjs +2 -0
- package/dist/utils/is-bare-specifier.mjs.map +1 -1
- package/dist/utils/is-exports-sugar.mjs +1 -1
- package/dist/utils/is-exports-sugar.mjs.map +1 -1
- package/dist/utils/is-relative-specifier.mjs.map +1 -1
- package/dist/utils/parse-module-id.d.mts +1 -3
- package/dist/utils/parse-module-id.mjs +3 -0
- package/dist/utils/parse-module-id.mjs.map +1 -1
- package/dist/utils/parse-subpath.d.mts +1 -2
- package/dist/utils/parse-subpath.mjs +115 -5
- package/dist/utils/parse-subpath.mjs.map +1 -1
- package/dist/utils/read-package-json.mjs +7 -5
- package/dist/utils/read-package-json.mjs.map +1 -1
- package/dist/utils/resolve-alias.mjs +3 -2
- package/dist/utils/resolve-alias.mjs.map +1 -1
- package/dist/utils/resolve-module.mjs +16 -1
- package/dist/utils/resolve-module.mjs.map +1 -1
- package/dist/utils/to-bare-specifier.mjs +8 -10
- package/dist/utils/to-bare-specifier.mjs.map +1 -1
- package/dist/utils/to-relative-specifier.d.mts +2 -0
- package/dist/utils/to-relative-specifier.mjs +3 -0
- package/dist/utils/to-relative-specifier.mjs.map +1 -1
- package/dist/utils/to-url.d.mts +2 -3
- package/dist/utils/to-url.mjs.map +1 -1
- package/dist/utils/validate-assertions.mjs +2 -0
- package/dist/utils/validate-assertions.mjs.map +1 -1
- package/dist/utils/validate-exports.d.mts +2 -2
- package/dist/utils/validate-exports.mjs +2 -2
- package/dist/utils/validate-exports.mjs.map +1 -1
- package/package.json +34 -41
- package/src/interfaces/options-get-format.ts +2 -14
- package/src/interfaces/options-get-source.ts +2 -14
- package/src/interfaces/options-parse-subpath.ts +20 -0
- package/src/interfaces/parsed-subpath.ts +10 -1
- package/src/internal/regex-invalid-segment.ts +23 -0
- package/src/internal/resolver.ts +7 -22
- package/src/internal/validate-array-set.ts +32 -0
- package/src/internal/validate-map.ts +33 -0
- package/src/internal/validate-set.ts +4 -5
- package/src/utils/fill-modules.ts +10 -1
- package/src/utils/find-requires.ts +1 -1
- package/src/utils/find-subpath.ts +11 -2
- package/src/utils/get-format.ts +33 -12
- package/src/utils/get-source.ts +21 -6
- package/src/utils/is-absolute-specifier.ts +5 -0
- package/src/utils/is-bare-specifier.ts +5 -0
- package/src/utils/is-exports-sugar.ts +1 -1
- package/src/utils/is-relative-specifier.ts +1 -0
- package/src/utils/parse-module-id.ts +6 -3
- package/src/utils/parse-subpath.ts +154 -9
- package/src/utils/read-package-json.ts +8 -3
- package/src/utils/resolve-alias.ts +3 -2
- package/src/utils/resolve-module.ts +40 -11
- package/src/utils/to-bare-specifier.ts +10 -12
- package/src/utils/to-relative-specifier.ts +7 -0
- package/src/utils/to-url.ts +2 -3
- package/src/utils/validate-assertions.ts +2 -0
- package/src/utils/validate-exports.ts +5 -5
- package/changelog.config.ts +0 -404
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import regexp from "../internal/escape-reg-exp.mjs";
|
|
2
|
+
import validateSet from "../internal/validate-set.mjs";
|
|
2
3
|
import validateURLString from "../internal/validate-url-string.mjs";
|
|
3
4
|
import {
|
|
4
5
|
ERR_OPERATION_FAILED,
|
|
@@ -23,6 +24,7 @@ import toURL from "./to-url.mjs";
|
|
|
23
24
|
const toBareSpecifier = (specifier, parent, conditions = CONDITIONS) => {
|
|
24
25
|
validateURLString(specifier, "specifier");
|
|
25
26
|
validateURLString(parent, "parent");
|
|
27
|
+
validateSet(conditions, "conditions");
|
|
26
28
|
if (specifier instanceof URL)
|
|
27
29
|
specifier = specifier.href;
|
|
28
30
|
if (isBuiltin(specifier))
|
|
@@ -35,16 +37,12 @@ const toBareSpecifier = (specifier, parent, conditions = CONDITIONS) => {
|
|
|
35
37
|
const url = toURL(
|
|
36
38
|
isAbsoluteSpecifier(specifier) || specifier.startsWith("node_modules") ? specifier : `node_modules/${specifier}`
|
|
37
39
|
);
|
|
38
|
-
const scope = lookupPackageScope(
|
|
39
|
-
url,
|
|
40
|
-
pathToFileURL(".")
|
|
41
|
-
);
|
|
40
|
+
const scope = lookupPackageScope(url, pathToFileURL(".")) ?? lookupPackageScope(specifier, pathToFileURL("."));
|
|
42
41
|
if (!scope) {
|
|
43
42
|
throw new ERR_OPERATION_FAILED(`Package scope for '${specifier}' not found`);
|
|
44
43
|
}
|
|
45
|
-
const {
|
|
46
|
-
|
|
47
|
-
specifier = url.pathname.includes(name) ? name + url.pathname.replace(new RegExp(`.*?${regexp(name)}`), "") : name + specifier.replace(fileURLToPath(pkgdir.replace(/\/$/, "")), "");
|
|
44
|
+
const { exports, main, name = "", types } = scope.pkgjson;
|
|
45
|
+
specifier = url.pathname.includes(name) ? name + url.pathname.replace(new RegExp(`.*?${regexp(name)}`), "") : name + specifier.replace(fileURLToPath(scope.dir.replace(/\/$/, "")), "");
|
|
48
46
|
const id = parseModuleId(specifier, {
|
|
49
47
|
internal: false,
|
|
50
48
|
parent,
|
|
@@ -54,18 +52,18 @@ const toBareSpecifier = (specifier, parent, conditions = CONDITIONS) => {
|
|
|
54
52
|
return [main, types].some((ep) => ep === id.path || ep === id.path.slice(2)) ? id.pkg : specifier;
|
|
55
53
|
}
|
|
56
54
|
try {
|
|
57
|
-
parseSubpath(specifier, exports, { dir:
|
|
55
|
+
parseSubpath(specifier, exports, { dir: scope.dir, parent });
|
|
58
56
|
} catch (e) {
|
|
59
57
|
if (e.code === ErrorCode.ERR_PACKAGE_PATH_NOT_EXPORTED) {
|
|
60
58
|
const target = specifier.replace(name, ".");
|
|
61
59
|
let subpath = findSubpath(target, exports, {
|
|
62
60
|
conditions,
|
|
63
|
-
dir:
|
|
61
|
+
dir: scope.dir,
|
|
64
62
|
parent
|
|
65
63
|
});
|
|
66
64
|
if (subpath === null) {
|
|
67
65
|
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
68
|
-
fileURLToPath(
|
|
66
|
+
fileURLToPath(scope.dir),
|
|
69
67
|
id.path,
|
|
70
68
|
fileURLToPath(parent)
|
|
71
69
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|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MAAM;AACpB,cAAM,IAAI;AAAA,UACR,cAAc,MAAM,GAAG;AAAA,UACvB,GAAG;AAAA,UACH,cAAc,MAAM;AAAA,QACtB;AAAA,MACF;AAGA,UAAI,QAAQ,SAAS,iBAAiB,GAAG;AACvC,kBAAU,QAAQ,MAAM,GAAG,QAAQ,QAAQ,iBAAiB,CAAC,EAAE,MAAM,CAAC;AACtE,kBAAU,MAAM,OAAO,MAAM,OAAO,QAAQ,OAAO,CAAC;AAAA,MACtD;AAIA,UAAI,MAAM,QAAQ,MAAM,MAAM,MAAM,QAAQ,OAAO,GAAG;AACpD,kBAAU,MAAM,UAAU,SAAS,EAAE;AAAA,MACvC;AAEA,aAAO,OAAO,QAAQ,MAAM,CAAC;AAAA,IAC/B;AAEA,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAEA,IAAO,4BAAQ;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -17,6 +17,8 @@ import type { ModuleId } from '../types/index.mjs';
|
|
|
17
17
|
* @param {ModuleId} specifier - Module specifier to convert
|
|
18
18
|
* @param {ModuleId} parent - Parent module URL or path to resolve from
|
|
19
19
|
* @return {string} `specifier` as relative specifier
|
|
20
|
+
* @throws {NodeError<TypeError>} If either `specifier` or `parent` is not a
|
|
21
|
+
* string or an instance of {@linkcode URL}
|
|
20
22
|
*/
|
|
21
23
|
declare const toRelativeSpecifier: (specifier: ModuleId, parent: ModuleId) => string;
|
|
22
24
|
export default toRelativeSpecifier;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import validateURLString from "../internal/validate-url-string.mjs";
|
|
1
2
|
import pathe from "@flex-development/pathe";
|
|
2
3
|
import { URL, fileURLToPath } from "node:url";
|
|
3
4
|
const toRelativeSpecifier = (specifier, parent) => {
|
|
5
|
+
validateURLString(specifier, "specifier");
|
|
6
|
+
validateURLString(parent, "parent");
|
|
4
7
|
if (parent instanceof URL)
|
|
5
8
|
parent = parent.href;
|
|
6
9
|
if (specifier instanceof URL)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/to-relative-specifier.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAKA,OAAO,uBAAuB;AAG9B,OAAO,WAAW;AAClB,SAAS,KAAK,qBAAqB;AAmBnC,MAAM,sBAAsB,CAAC,WAAqB,WAA6B;AAC7E,oBAAkB,WAAW,WAAW;AACxC,oBAAkB,QAAQ,QAAQ;AAGlC,MAAI,kBAAkB;AAAK,aAAS,OAAO;AAC3C,MAAI,qBAAqB;AAAK,gBAAY,UAAU;AAGpD,MAAI,OAAO,WAAW,OAAO;AAAG,aAAS,cAAc,MAAM;AAC7D,MAAI,UAAU,WAAW,OAAO;AAAG,gBAAY,cAAc,SAAS;AAGtE,cAAY,MACT,SAAS,MAAM,QAAQ,MAAM,GAAG,MAAM,QAAQ,SAAS,CAAC,EACxD,QAAQ,YAAY,EAAE,EACtB,QAAQ,SAAS,MAAM;AAI1B,MAAI,CAAC;AAAW,gBAAY;AAE5B,SAAO;AACT;AAEA,IAAO,gCAAQ;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/utils/to-url.d.mts
CHANGED
|
@@ -13,10 +13,9 @@ import { URL } from 'node:url';
|
|
|
13
13
|
*
|
|
14
14
|
* @param {ModuleId} id - Module id to evaluate
|
|
15
15
|
* @param {ModuleId?} [base=pathToFileURL('./')] - Base URL to resolve against
|
|
16
|
-
*
|
|
17
|
-
* @return {URL} `id` as instance of `URL`
|
|
16
|
+
* @return {URL} `id` as instance of {@linkcode URL}
|
|
18
17
|
* @throws {NodeError<TypeError>} If either `id` or `base` is not a string or an
|
|
19
|
-
* instance of
|
|
18
|
+
* instance of {@linkcode URL}
|
|
20
19
|
*/
|
|
21
20
|
declare const toURL: (id: ModuleId, base?: ModuleId) => URL;
|
|
22
21
|
export default toURL;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/to-url.ts"],
|
|
4
|
-
"mappings": "AAKA,OAAO,uBAAuB;AAG9B,SAAS,KAAK,qBAAqB;
|
|
4
|
+
"mappings": "AAKA,OAAO,uBAAuB;AAG9B,SAAS,KAAK,qBAAqB;AAenC,MAAM,QAAQ,CAAC,IAAc,OAAiB,cAAc,IAAI,MAAW;AACzE,oBAAkB,IAAI,IAAI;AAC1B,oBAAkB,MAAM,MAAM;AAC9B,SAAO,cAAc,MAAM,KAAK,IAAI,IAAI,IAAI,IAAI;AAClD;AAEA,IAAO,iBAAQ;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AssertType } from "../enums/index.mjs";
|
|
2
2
|
import FORMAT_TYPE_MAP from "../internal/format-type-map.mjs";
|
|
3
|
+
import validateObject from "../internal/validate-object.mjs";
|
|
3
4
|
import validateString from "../internal/validate-string.mjs";
|
|
4
5
|
import validateURLString from "../internal/validate-url-string.mjs";
|
|
5
6
|
import {
|
|
@@ -11,6 +12,7 @@ import { URL } from "node:url";
|
|
|
11
12
|
const validateAssertions = (url, format, assertions = {}) => {
|
|
12
13
|
validateURLString(url, "url");
|
|
13
14
|
validateString(format, "format");
|
|
15
|
+
validateObject(assertions, "assertions");
|
|
14
16
|
if (url instanceof URL)
|
|
15
17
|
url = url.href;
|
|
16
18
|
const has_type = Object.hasOwnProperty.call(assertions, "type");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/validate-assertions.ts"],
|
|
4
|
-
"mappings": "AAMA,SAAS,kBAAkB;AAE3B,OAAO,qBAAqB;AAC5B,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,WAAW;AAepB,MAAM,qBAAqB,CACzB,KACA,QACA,aAA+B,CAA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/pkg-types';
|
|
|
16
16
|
* @param {ModuleId} pkg - URL of relevant `package.json` file
|
|
17
17
|
* @param {ModuleId} parent - URL of module to resolve from
|
|
18
18
|
* @return {true} `true` if `exports` configuration and schema are valid
|
|
19
|
-
* @throws {NodeError<Error | TypeError>} If either `pkg` or `parent` is not
|
|
20
|
-
* instance of {@linkcode URL}
|
|
19
|
+
* @throws {NodeError<Error | TypeError>} If either `pkg` or `parent` is not a
|
|
20
|
+
* string or an instance of {@linkcode URL}, or if `exports` configuration or
|
|
21
21
|
* schema is invalid
|
|
22
22
|
*/
|
|
23
23
|
declare const validateExports: (exports: Exports | undefined, pkg: ModuleId, parent: ModuleId) => true;
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
import { isNIL } from "@flex-development/tutils";
|
|
7
7
|
import { URL, fileURLToPath } from "node:url";
|
|
8
8
|
const validateExports = (exports, pkg, parent) => {
|
|
9
|
+
validateURLString(pkg, "pkg");
|
|
10
|
+
validateURLString(parent, "parent");
|
|
9
11
|
switch (true) {
|
|
10
12
|
case Array.isArray(exports):
|
|
11
13
|
for (const item of exports) {
|
|
@@ -39,8 +41,6 @@ const validateExports = (exports, pkg, parent) => {
|
|
|
39
41
|
);
|
|
40
42
|
default:
|
|
41
43
|
exports = exports;
|
|
42
|
-
validateURLString(pkg, "pkg");
|
|
43
|
-
validateURLString(parent, "parent");
|
|
44
44
|
const keys = Object.getOwnPropertyNames(exports);
|
|
45
45
|
for (const [index, key] of keys.entries()) {
|
|
46
46
|
if (isArrayIndex(key)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/validate-exports.ts"],
|
|
4
|
-
"mappings": "AAKA,OAAO,kBAAkB;AACzB,OAAO,uBAAuB;AAE9B;AAAA,EACE;AAAA,OAEK;AAEP,SAAS,aAAa;AACtB,SAAS,KAAK,qBAAqB;AAkBnC,MAAM,kBAAkB,CACtB,SACA,KACA,WACS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MACF;AAEA;AAAA,IACF,KAAK,MAAM,OAAO;AAAA,IAClB,KAAK,OAAO,YAAY;AACtB;AAAA,IACF,KAAK,OAAO,YAAY;AACtB,YAAM,IAAI;AAAA,QACR,cAAc,GAAG;AAAA,QACjB,cAAc,MAAM;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AACE,gBAAU;AAOV,YAAM,OAAiB,OAAO,oBAAoB,OAAO;AAGzD,iBAAW,CAAC,OAAO,GAAG,KAAK,KAAK,QAAQ,GAAG;AAEzC,YAAI,aAAa,GAAG,GAAG;AACrB,gBAAM,IAAI;AAAA,YACR,cAAc,IAAI,IAAI,KAAK,GAAG,CAAC;AAAA,YAC/B,cAAc,MAAM;AAAA,YACpB;AAAA,UACF;AAAA,QACF;AAIA,YAAI,QAAQ,GAAG;AAMb,gBAAM,OAAe,KAAK,QAAQ,CAAC;AAGnC,cACG,CAAC,IAAI,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG,KAC3C,IAAI,WAAW,GAAG,KAAK,CAAC,KAAK,WAAW,GAAG,GAC5C;AACA,kBAAM,IAAI;AAAA,cACR,cAAc,GAAG;AAAA,cACjB,cAAc,MAAM;AAAA,cACpB;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA;AAAA,EACJ;AAEA,SAAO;AACT;AAEA,IAAO,2BAAQ;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flex-development/mlly",
|
|
3
3
|
"description": "ECMAScript module utilities",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.13",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecmascript",
|
|
7
7
|
"esm",
|
|
@@ -30,22 +30,17 @@
|
|
|
30
30
|
".": "./dist/index.mjs",
|
|
31
31
|
"./package.json": "./package.json"
|
|
32
32
|
},
|
|
33
|
-
"imports": {
|
|
34
|
-
"#mkbuild": "@flex-development/mkbuild",
|
|
35
|
-
"#src": "./src/index.ts",
|
|
36
|
-
"#src/*": "./src/*.ts"
|
|
37
|
-
},
|
|
38
33
|
"module": "./dist/index.mjs",
|
|
39
34
|
"types": "./dist/index.d.mts",
|
|
40
35
|
"scripts": {
|
|
41
36
|
"build": "mkbuild",
|
|
42
|
-
"changelog": "node --loader=./loader.mjs ./changelog.config
|
|
43
|
-
"check:ci": "yarn dedupe --check && yarn check:format && yarn check:lint && yarn check:spelling && yarn typecheck && yarn test:cov && NODE_ENV=production yarn pack -o %s-%v.tgz && yarn
|
|
37
|
+
"changelog": "node --loader=./loader.mjs ./config/changelog.config",
|
|
38
|
+
"check:ci": "yarn dedupe --check && yarn check:format && yarn check:lint && yarn check:spelling && yarn typecheck && yarn test:cov && NODE_ENV=production yarn pack -o %s-%v.tgz && yarn clean:pack && yarn check:types:build && yarn docs:build",
|
|
44
39
|
"check:format": "prettier --check .",
|
|
45
|
-
"check:lint": "eslint --exit-on-fatal-error --ext cjs,
|
|
40
|
+
"check:lint": "eslint --exit-on-fatal-error --ext cjs,gql,js,json,jsonc,md,mjs,mts,ts,vue,yml --max-warnings 0 .",
|
|
46
41
|
"check:spelling": "cspell lint --color --no-progress --relative $@ \"**\"",
|
|
47
42
|
"check:types": "vue-tsc -p tsconfig.typecheck.json",
|
|
48
|
-
"check:types:build": "
|
|
43
|
+
"check:types:build": "bash ./scripts/typecheck-build.sh",
|
|
49
44
|
"check:upgrades": "yarn upgrade-interactive",
|
|
50
45
|
"clean:build": "trash ./{dist,*.tgz}",
|
|
51
46
|
"clean:coverage": "trash ./coverage",
|
|
@@ -80,24 +75,23 @@
|
|
|
80
75
|
"typecheck:watch": "vitest typecheck"
|
|
81
76
|
},
|
|
82
77
|
"dependencies": {
|
|
83
|
-
"@flex-development/errnode": "1.
|
|
78
|
+
"@flex-development/errnode": "1.5.0",
|
|
84
79
|
"@flex-development/export-regex": "1.0.0",
|
|
85
80
|
"@flex-development/import-regex": "2.0.1",
|
|
86
81
|
"@flex-development/is-builtin": "2.0.0",
|
|
87
82
|
"@flex-development/pathe": "1.0.3",
|
|
88
83
|
"@flex-development/pkg-types": "2.0.0",
|
|
89
|
-
"@flex-development/tutils": "6.0.0-alpha.
|
|
84
|
+
"@flex-development/tutils": "6.0.0-alpha.10"
|
|
90
85
|
},
|
|
91
86
|
"devDependencies": {
|
|
92
|
-
"@commitlint/cli": "17.4.
|
|
93
|
-
"@commitlint/config-conventional": "17.4.
|
|
94
|
-
"@commitlint/types": "17.4.0",
|
|
87
|
+
"@commitlint/cli": "17.4.4",
|
|
88
|
+
"@commitlint/config-conventional": "17.4.4",
|
|
95
89
|
"@docsearch/react": "3.3.3",
|
|
96
|
-
"@faker-js/faker": "
|
|
90
|
+
"@faker-js/faker": "8.0.0-alpha.0",
|
|
97
91
|
"@flex-development/docast": "1.0.0-alpha.9",
|
|
98
92
|
"@flex-development/docast-parse": "1.0.0-alpha.4",
|
|
99
|
-
"@flex-development/mkbuild": "1.0.0-alpha.
|
|
100
|
-
"@graphql-eslint/eslint-plugin": "3.
|
|
93
|
+
"@flex-development/mkbuild": "1.0.0-alpha.13",
|
|
94
|
+
"@graphql-eslint/eslint-plugin": "3.16.0",
|
|
101
95
|
"@sindresorhus/slugify": "2.2.0",
|
|
102
96
|
"@types/chai": "4.3.4",
|
|
103
97
|
"@types/chai-string": "1.4.2",
|
|
@@ -107,22 +101,21 @@
|
|
|
107
101
|
"@types/conventional-commits-parser": "3.0.3",
|
|
108
102
|
"@types/conventional-recommended-bump": "6.1.0",
|
|
109
103
|
"@types/dateformat": "5.0.0",
|
|
110
|
-
"@types/eslint": "8.21.
|
|
104
|
+
"@types/eslint": "8.21.1",
|
|
111
105
|
"@types/git-raw-commits": "2.0.1",
|
|
112
106
|
"@types/is-ci": "3.0.0",
|
|
113
107
|
"@types/markdown-it": "12.2.3",
|
|
114
|
-
"@types/node": "18.
|
|
108
|
+
"@types/node": "18.14.0",
|
|
115
109
|
"@types/node-notifier": "8.0.2",
|
|
116
110
|
"@types/prettier": "2.7.2",
|
|
117
111
|
"@types/semver": "7.3.13",
|
|
118
112
|
"@types/unist": "2.0.6",
|
|
119
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
120
|
-
"@typescript-eslint/parser": "5.
|
|
113
|
+
"@typescript-eslint/eslint-plugin": "5.53.0",
|
|
114
|
+
"@typescript-eslint/parser": "5.53.0",
|
|
121
115
|
"@vates/toggle-scripts": "1.0.0",
|
|
122
|
-
"@vitest/coverage-c8": "0.28.
|
|
123
|
-
"@vitest/ui": "0.28.
|
|
116
|
+
"@vitest/coverage-c8": "0.28.5",
|
|
117
|
+
"@vitest/ui": "0.28.5",
|
|
124
118
|
"@vue/runtime-core": "3.2.47",
|
|
125
|
-
"@vuedx/typescript-plugin-vue": "0.7.7-next-1667939290.0",
|
|
126
119
|
"add-stream": "1.0.0",
|
|
127
120
|
"algoliasearch": "4.14.3",
|
|
128
121
|
"chai": "4.3.7",
|
|
@@ -137,15 +130,16 @@
|
|
|
137
130
|
"conventional-commits-parser": "3.2.4",
|
|
138
131
|
"conventional-recommended-bump": "6.1.0",
|
|
139
132
|
"cross-env": "7.0.3",
|
|
140
|
-
"cspell": "6.
|
|
133
|
+
"cspell": "6.26.3",
|
|
134
|
+
"dateformat": "5.0.3",
|
|
141
135
|
"dotenv": "16.0.3",
|
|
142
|
-
"esbuild": "0.17.
|
|
136
|
+
"esbuild": "0.17.10",
|
|
143
137
|
"escape-string-regexp": "5.0.0",
|
|
144
|
-
"eslint": "8.
|
|
138
|
+
"eslint": "8.34.0",
|
|
145
139
|
"eslint-config-prettier": "8.6.0",
|
|
146
140
|
"eslint-plugin-chai-expect": "3.0.0",
|
|
147
141
|
"eslint-plugin-jest-formatting": "3.1.0",
|
|
148
|
-
"eslint-plugin-jsdoc": "
|
|
142
|
+
"eslint-plugin-jsdoc": "40.0.0",
|
|
149
143
|
"eslint-plugin-jsonc": "2.6.0",
|
|
150
144
|
"eslint-plugin-markdown": "3.0.0",
|
|
151
145
|
"eslint-plugin-markdownlint": "0.4.0",
|
|
@@ -154,7 +148,7 @@
|
|
|
154
148
|
"eslint-plugin-promise": "6.1.1",
|
|
155
149
|
"eslint-plugin-unicorn": "45.0.2",
|
|
156
150
|
"eslint-plugin-vue": "9.9.0",
|
|
157
|
-
"eslint-plugin-yml": "1.
|
|
151
|
+
"eslint-plugin-yml": "1.5.0",
|
|
158
152
|
"globby": "13.1.3",
|
|
159
153
|
"graphql": "16.6.0",
|
|
160
154
|
"graphql-config": "4.4.1",
|
|
@@ -162,37 +156,36 @@
|
|
|
162
156
|
"husky": "8.0.3",
|
|
163
157
|
"is-ci": "3.0.1",
|
|
164
158
|
"jsonc-eslint-parser": "2.1.0",
|
|
165
|
-
"lint-staged": "13.1.
|
|
159
|
+
"lint-staged": "13.1.2",
|
|
166
160
|
"mri": "1.2.0",
|
|
167
161
|
"node-fetch": "3.3.0",
|
|
168
162
|
"node-notifier": "10.0.1",
|
|
169
163
|
"prettier": "2.8.4",
|
|
170
164
|
"prettier-plugin-sh": "0.12.8",
|
|
171
|
-
"pretty-format": "29.4.2",
|
|
172
165
|
"pupa": "3.1.0",
|
|
173
166
|
"sade": "1.8.1",
|
|
174
167
|
"semver": "7.3.8",
|
|
175
168
|
"serve": "14.2.0",
|
|
176
169
|
"sitemap": "7.1.1",
|
|
177
|
-
"tempfile": "
|
|
170
|
+
"tempfile": "5.0.0",
|
|
178
171
|
"trash-cli": "5.0.0",
|
|
179
172
|
"ts-dedent": "2.2.0",
|
|
180
|
-
"typescript": "5.0.0-dev.
|
|
173
|
+
"typescript": "5.0.0-dev.20230222",
|
|
181
174
|
"unified": "10.1.2",
|
|
182
175
|
"unist-util-remove": "3.1.0",
|
|
183
176
|
"unist-util-source": "4.0.2",
|
|
184
177
|
"unist-util-visit": "4.1.2",
|
|
185
|
-
"vercel": "28.
|
|
178
|
+
"vercel": "28.16.4",
|
|
186
179
|
"version-bump-prompt": "6.1.0",
|
|
187
180
|
"vfile": "5.3.7",
|
|
188
|
-
"vite": "4.1.
|
|
181
|
+
"vite": "4.1.4",
|
|
189
182
|
"vite-tsconfig-paths": "4.0.5",
|
|
190
183
|
"vitepress": "1.0.0-alpha.34",
|
|
191
|
-
"vitest": "0.28.
|
|
184
|
+
"vitest": "0.28.5",
|
|
192
185
|
"vitest-github-actions-reporter": "0.9.0",
|
|
193
186
|
"vue": "3.2.47",
|
|
194
187
|
"vue-eslint-parser": "9.1.0",
|
|
195
|
-
"vue-tsc": "1.
|
|
188
|
+
"vue-tsc": "1.1.7",
|
|
196
189
|
"yaml-eslint-parser": "1.1.0"
|
|
197
190
|
},
|
|
198
191
|
"peerDependencies": {
|
|
@@ -206,14 +199,14 @@
|
|
|
206
199
|
},
|
|
207
200
|
"resolutions": {
|
|
208
201
|
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
|
|
209
|
-
"@flex-development/tutils": "6.0.0-alpha.
|
|
202
|
+
"@flex-development/tutils": "6.0.0-alpha.10",
|
|
210
203
|
"vitepress@npm:1.0.0-alpha.34": "patch:vitepress@npm%3A1.0.0-alpha.34#patches/vitepress+1.0.0-alpha.34.dev.patch"
|
|
211
204
|
},
|
|
212
205
|
"engines": {
|
|
213
206
|
"node": ">=14.17.0",
|
|
214
|
-
"yarn": "4.0.0-rc.
|
|
207
|
+
"yarn": "4.0.0-rc.39"
|
|
215
208
|
},
|
|
216
|
-
"packageManager": "yarn@4.0.0-rc.
|
|
209
|
+
"packageManager": "yarn@4.0.0-rc.39",
|
|
217
210
|
"readme": "README.md",
|
|
218
211
|
"sideEffects": false,
|
|
219
212
|
"tagPrefix": ""
|
|
@@ -4,29 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Format } from '#src/enums'
|
|
7
|
-
import type { ModuleId } from '#src/types'
|
|
8
7
|
import type { Ext } from '@flex-development/pathe'
|
|
9
8
|
import type { EmptyString } from '@flex-development/tutils'
|
|
10
|
-
import type { RequestInit } from 'node-fetch'
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* Module format retrieval options.
|
|
14
12
|
*
|
|
15
13
|
* @see {@linkcode Ext}
|
|
16
14
|
* @see {@linkcode Format}
|
|
17
|
-
* @see {@linkcode ModuleId}
|
|
18
15
|
* @see {@linkcode RequestInit}
|
|
19
16
|
*/
|
|
20
17
|
interface GetFormatOptions {
|
|
21
|
-
/**
|
|
22
|
-
* Base URL to resolve module id against if module id is not absolute.
|
|
23
|
-
*
|
|
24
|
-
* @see {@linkcode ModuleId}
|
|
25
|
-
*
|
|
26
|
-
* @default undefined
|
|
27
|
-
*/
|
|
28
|
-
base?: ModuleId | undefined
|
|
29
|
-
|
|
30
18
|
/**
|
|
31
19
|
* Enable support for JSON modules.
|
|
32
20
|
*
|
|
@@ -84,9 +72,9 @@ interface GetFormatOptions {
|
|
|
84
72
|
*
|
|
85
73
|
* @see {@linkcode RequestInit}
|
|
86
74
|
*
|
|
87
|
-
* @default
|
|
75
|
+
* @default {}
|
|
88
76
|
*/
|
|
89
|
-
req?: RequestInit | undefined
|
|
77
|
+
req?: import('node-fetch').RequestInit | undefined
|
|
90
78
|
}
|
|
91
79
|
|
|
92
80
|
export type { GetFormatOptions as default }
|
|
@@ -4,26 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Format } from '#src/enums'
|
|
7
|
-
import type { ModuleId } from '#src/types'
|
|
8
|
-
import type { RequestInit } from 'node-fetch'
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Source code retrieval options.
|
|
12
10
|
*
|
|
13
11
|
* @see {@linkcode Format}
|
|
14
|
-
* @see {@linkcode ModuleId}
|
|
15
12
|
* @see {@linkcode RequestInit}
|
|
16
13
|
*/
|
|
17
14
|
interface GetSourceOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Base URL to resolve module id against if module id is not absolute.
|
|
20
|
-
*
|
|
21
|
-
* @see {@linkcode ModuleId}
|
|
22
|
-
*
|
|
23
|
-
* @default undefined
|
|
24
|
-
*/
|
|
25
|
-
base?: ModuleId | undefined
|
|
26
|
-
|
|
27
15
|
/**
|
|
28
16
|
* Enable support for network based modules.
|
|
29
17
|
*
|
|
@@ -62,9 +50,9 @@ interface GetSourceOptions {
|
|
|
62
50
|
*
|
|
63
51
|
* @see {@linkcode RequestInit}
|
|
64
52
|
*
|
|
65
|
-
* @default
|
|
53
|
+
* @default {}
|
|
66
54
|
*/
|
|
67
|
-
req?: RequestInit | undefined
|
|
55
|
+
req?: import('node-fetch').RequestInit | undefined
|
|
68
56
|
}
|
|
69
57
|
|
|
70
58
|
export type { GetSourceOptions as default }
|
|
@@ -11,6 +11,26 @@ import type { ModuleId } from '#src/types'
|
|
|
11
11
|
* @see {@linkcode ModuleId}
|
|
12
12
|
*/
|
|
13
13
|
interface ParseSubpathOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Export condition to apply.
|
|
16
|
+
*
|
|
17
|
+
* @see https://nodejs.org/api/packages.html#conditional-exports
|
|
18
|
+
*
|
|
19
|
+
* @default 'default'
|
|
20
|
+
*/
|
|
21
|
+
condition?: string | undefined
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Export conditions.
|
|
25
|
+
*
|
|
26
|
+
* **Note**: Should be sorted by priority.
|
|
27
|
+
*
|
|
28
|
+
* @see https://nodejs.org/api/packages.html#conditional-exports
|
|
29
|
+
*
|
|
30
|
+
* @default CONDITIONS
|
|
31
|
+
*/
|
|
32
|
+
conditions?: Set<string> | string[] | undefined
|
|
33
|
+
|
|
14
34
|
/**
|
|
15
35
|
* URL of directory containing relevant `package.json` file.
|
|
16
36
|
*/
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
* @module mlly/interfaces/ParsedSubpath
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
EmptyString,
|
|
8
|
+
LiteralUnion,
|
|
9
|
+
Nullable
|
|
10
|
+
} from '@flex-development/tutils'
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Object representing a package subpath.
|
|
@@ -42,6 +46,11 @@ interface ParsedSubpath {
|
|
|
42
46
|
* Module specifier passed by user.
|
|
43
47
|
*/
|
|
44
48
|
specifier: string
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Package target as documented in `package.json` file.
|
|
52
|
+
*/
|
|
53
|
+
target: Nullable<string>
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
export type { ParsedSubpath as default }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Internal - invalidSegmentRegex
|
|
3
|
+
* @module mlly/internal/invalidSegmentRegex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns a regular expression matching invalid path segments.
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.com/nodejs/node/blob/v19.6.1/lib/internal/modules/esm/resolve.js#L299-L300
|
|
10
|
+
*
|
|
11
|
+
* @param {'deprecated'?} type - Pattern type
|
|
12
|
+
* @return {RegExp} Regular expression matching invalid path segments
|
|
13
|
+
*/
|
|
14
|
+
const invalidSegmentRegex = (type?: 'deprecated'): RegExp => {
|
|
15
|
+
return new RegExp(
|
|
16
|
+
`(^|\\\\|\\/)((\\.|%2e)(\\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))${
|
|
17
|
+
type === 'deprecated' ? '' : '?'
|
|
18
|
+
}(\\\\|\\/|$)`,
|
|
19
|
+
'i'
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default invalidSegmentRegex
|
package/src/internal/resolver.ts
CHANGED
|
@@ -45,6 +45,7 @@ import regexp from './escape-reg-exp'
|
|
|
45
45
|
import isArrayIndex from './is-array-index'
|
|
46
46
|
import isDirectory from './is-directory'
|
|
47
47
|
import isFile from './is-file'
|
|
48
|
+
import invalidSegmentRegex from './regex-invalid-segment'
|
|
48
49
|
import PACKAGE_NAME_REGEX from './regex-package-name'
|
|
49
50
|
import PACKAGE_PATH_REGEX from './regex-package-path'
|
|
50
51
|
|
|
@@ -629,11 +630,14 @@ class Resolver {
|
|
|
629
630
|
}
|
|
630
631
|
|
|
631
632
|
// stop resolution attempts if target was resolved
|
|
632
|
-
if (url)
|
|
633
|
+
if (url) {
|
|
634
|
+
error = undefined
|
|
635
|
+
break
|
|
636
|
+
}
|
|
633
637
|
}
|
|
634
638
|
|
|
635
639
|
// throw if error was encountered and package target was not resolved
|
|
636
|
-
if (error
|
|
640
|
+
if (error) throw error
|
|
637
641
|
|
|
638
642
|
break
|
|
639
643
|
case typeof target === 'object':
|
|
@@ -643,7 +647,7 @@ class Resolver {
|
|
|
643
647
|
// ensure prop is not an array index
|
|
644
648
|
if (isArrayIndex(prop)) {
|
|
645
649
|
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
646
|
-
fileURLToPath(dir),
|
|
650
|
+
fileURLToPath(dir).replace(/\/$/, '') + '/package.json',
|
|
647
651
|
fileURLToPath(parent),
|
|
648
652
|
'"exports" cannot contain numeric property keys'
|
|
649
653
|
)
|
|
@@ -691,25 +695,6 @@ class Resolver {
|
|
|
691
695
|
url = this.resolvePackage(target, parent, condition, conditions)
|
|
692
696
|
break
|
|
693
697
|
case target.startsWith('.' + pathe.sep):
|
|
694
|
-
/**
|
|
695
|
-
* Returns a regex pattern matching invalid path segments.
|
|
696
|
-
*
|
|
697
|
-
* Invalid segments include:
|
|
698
|
-
*
|
|
699
|
-
* - `'node_modules/'` (decoded and encoded)
|
|
700
|
-
*
|
|
701
|
-
* @param {'deprecated'?} type - Pattern type
|
|
702
|
-
* @return {RegExp} Regex pattern matching invalid path segments
|
|
703
|
-
*/
|
|
704
|
-
const invalidSegmentRegex = (type?: 'deprecated'): RegExp => {
|
|
705
|
-
return new RegExp(
|
|
706
|
-
`(^|\\\\|\\/)((\\.|%2e)(\\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))${
|
|
707
|
-
type === 'deprecated' ? '' : '?'
|
|
708
|
-
}(\\\\|\\/|$)`,
|
|
709
|
-
'i'
|
|
710
|
-
)
|
|
711
|
-
}
|
|
712
|
-
|
|
713
698
|
// check target for invalid segments
|
|
714
699
|
if (invalidSegmentRegex().test(target.slice(2))) {
|
|
715
700
|
if (invalidSegmentRegex('deprecated').test(target.slice(2))) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Internal - validateArraySet
|
|
3
|
+
* @module mlly/internal/validateArraySet
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks if given `value` is an array or a {@linkcode Set}.
|
|
10
|
+
*
|
|
11
|
+
* Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is of neither type.
|
|
12
|
+
*
|
|
13
|
+
* [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
|
|
14
|
+
*
|
|
15
|
+
* @see {@linkcode ERR_INVALID_ARG_TYPE}
|
|
16
|
+
*
|
|
17
|
+
* @template T - Item type(s)
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown} value - Value supplied by user
|
|
20
|
+
* @param {string} name - Name of invalid argument or property
|
|
21
|
+
* @return {value is Set<T> | T[]} `true` if `value` is array or {@linkcode Set}
|
|
22
|
+
* @throws {NodeError<TypeError>} If `value` is not an array or {@linkcode Set}
|
|
23
|
+
*/
|
|
24
|
+
function validateArraySet<T = unknown>(
|
|
25
|
+
value: unknown,
|
|
26
|
+
name: string
|
|
27
|
+
): value is Set<T> | T[] {
|
|
28
|
+
if (Array.isArray(value) || value instanceof Set) return true
|
|
29
|
+
throw new ERR_INVALID_ARG_TYPE(name, ['Array', 'Set'], value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default validateArraySet
|