@flex-development/mlly 1.0.0-alpha.17 → 1.0.0-alpha.18
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 +47 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +2 -2
- package/dist/utils/resolve-module.d.mts +1 -1
- package/dist/utils/resolve-module.mjs.map +1 -1
- package/dist/utils/to-bare-specifier.mjs +8 -1
- package/dist/utils/to-bare-specifier.mjs.map +2 -2
- package/package.json +13 -13
- package/dist/interfaces/index.mjs +0 -0
- package/dist/types/index.mjs +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
## [1.0.0-alpha.18](https://github.com/flex-development/mlly/compare/1.0.0-alpha.17...1.0.0-alpha.18) (2023-08-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### ⚠ BREAKING CHANGES
|
|
5
|
+
|
|
6
|
+
* **ts:** use `export type *`
|
|
7
|
+
|
|
8
|
+
### :package: Build
|
|
9
|
+
|
|
10
|
+
* **deps-dev:** Bump @commitlint/cli from 17.6.7 to 17.7.0 ([#405](https://github.com/flex-development/mlly/issues/405)) ([6e3e9c7](https://github.com/flex-development/mlly/commit/6e3e9c71ecd58f20a74b782c629914ecb404f5d8))
|
|
11
|
+
* **deps-dev:** Bump @commitlint/cli from 17.7.0 to 17.7.1 ([#409](https://github.com/flex-development/mlly/issues/409)) ([060725c](https://github.com/flex-development/mlly/commit/060725c8d5c6c8002f197e360697a22c35bc1145))
|
|
12
|
+
* **deps-dev:** Bump cspell from 7.0.1-alpha.8 to 7.0.1-alpha.9 ([#408](https://github.com/flex-development/mlly/issues/408)) ([772778a](https://github.com/flex-development/mlly/commit/772778a3df76d005e9b765275b275d8e1e91498a))
|
|
13
|
+
* **deps-dev:** Bump esbuild from 0.19.0 to 0.19.1 ([#410](https://github.com/flex-development/mlly/issues/410)) ([d3804d7](https://github.com/flex-development/mlly/commit/d3804d76d76afbc5a9172a1cacce22f6c8a42a8c))
|
|
14
|
+
* **deps-dev:** Bump esbuild from 0.19.1 to 0.19.2 ([#416](https://github.com/flex-development/mlly/issues/416)) ([eaf8d51](https://github.com/flex-development/mlly/commit/eaf8d5182f47c6855f80eed73e25f0e3f0dba1e4))
|
|
15
|
+
* **deps-dev:** Bump eslint from 8.46.0 to 8.47.0 ([#411](https://github.com/flex-development/mlly/issues/411)) ([a3374af](https://github.com/flex-development/mlly/commit/a3374af2b18028ff56cd17ef4b145169fff1e640))
|
|
16
|
+
* **deps-dev:** Bump eslint-import-resolver-typescript from 3.5.5 to 3.6.0 ([#406](https://github.com/flex-development/mlly/issues/406)) ([c2dbf48](https://github.com/flex-development/mlly/commit/c2dbf483ec9ce4581306c7c41608dd2fa9a04631))
|
|
17
|
+
* **deps-dev:** Bump eslint-plugin-vue from 9.16.1 to 9.17.0 ([#404](https://github.com/flex-development/mlly/issues/404)) ([f0892eb](https://github.com/flex-development/mlly/commit/f0892eb5ec7bc66311b168bf118cb4d11b0b2185))
|
|
18
|
+
* **deps-dev:** Bump graphql from 16.7.1 to 16.8.0 ([#415](https://github.com/flex-development/mlly/issues/415)) ([6f2a71d](https://github.com/flex-development/mlly/commit/6f2a71d2aedc265ac79770a77716a073a53f3407))
|
|
19
|
+
* **deps-dev:** Bump lint-staged from 13.2.3 to 14.0.0 ([#417](https://github.com/flex-development/mlly/issues/417)) ([a2443bd](https://github.com/flex-development/mlly/commit/a2443bd75c4386601b8c67f106a5a0656ce1730b))
|
|
20
|
+
* **deps-dev:** Bump the flex-development group with 1 update ([#403](https://github.com/flex-development/mlly/issues/403)) ([f6e4fb7](https://github.com/flex-development/mlly/commit/f6e4fb74e86c98b784b55ef8880259fd1a1cfb7f))
|
|
21
|
+
* **deps-dev:** Bump the typescript-eslint group with 2 updates ([#413](https://github.com/flex-development/mlly/issues/413)) ([099b5ae](https://github.com/flex-development/mlly/commit/099b5aec18c9bb92608619d4e0c8259533ac6882))
|
|
22
|
+
* **deps:** bump @flex-development/tutils from 6.0.0-alpha.20 to 6.0.0-alpha.21 ([1992970](https://github.com/flex-development/mlly/commit/199297040a08963491aef355fbfcf7c0c0120e9b))
|
|
23
|
+
* **deps:** Bump the flex-development group with 1 update ([#407](https://github.com/flex-development/mlly/issues/407)) ([41be3a2](https://github.com/flex-development/mlly/commit/41be3a267ea674fec6a2e2092c350a6783f0c026))
|
|
24
|
+
* **deps:** Bump the flex-development group with 1 update ([#414](https://github.com/flex-development/mlly/issues/414)) ([2d07755](https://github.com/flex-development/mlly/commit/2d07755998172d705f92c6d1669bc1b0df8fc2fc))
|
|
25
|
+
* **ts:** use `export type *` ([e0a1dce](https://github.com/flex-development/mlly/commit/e0a1dce59094797a7bc0ddf7b26840a43765155c))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### :robot: Continuous Integration
|
|
29
|
+
|
|
30
|
+
* [[@dependabot](https://github.com/dependabot)] add group `flex-development` ([5a4e169](https://github.com/flex-development/mlly/commit/5a4e169100278e773d78c8e2b1c3b921fb240394))
|
|
31
|
+
* **deps:** Bump actions/setup-node from 3.7.0 to 3.8.0 ([#412](https://github.com/flex-development/mlly/issues/412)) ([3465e63](https://github.com/flex-development/mlly/commit/3465e63ba2cea348833de890a71a21ff16472897))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### :pencil: Documentation
|
|
35
|
+
|
|
36
|
+
* **utils:** [`resolveModule`] fix valid npm package name note ([e869100](https://github.com/flex-development/mlly/commit/e8691007ada207792915130997917d98d5aebc19))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### :bug: Fixes
|
|
40
|
+
|
|
41
|
+
* **utils:** [`toBareSpecifier`] specifier conversion ([4d9fdaf](https://github.com/flex-development/mlly/commit/4d9fdaff221109a6fd90fc046fdcf61296bccbd0))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### :house_with_garden: Housekeeping
|
|
45
|
+
|
|
46
|
+
* **tests:** remove `serve.json` ([7e6d3b8](https://github.com/flex-development/mlly/commit/7e6d3b8cfb0915cb0ed4dfd37f4d21c3da926545))
|
|
47
|
+
|
|
1
48
|
## [1.0.0-alpha.17](https://github.com/flex-development/mlly/compare/1.0.0-alpha.16...1.0.0-alpha.17) (2023-08-08)
|
|
2
49
|
|
|
3
50
|
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file Package Entry Point\n * @module mlly\n */\n\nexport * from './enums'\nexport * from './interfaces'\nexport * from './types'\nexport * from './utils'\n"],
|
|
6
|
-
"mappings": "AAKA,cAAc;
|
|
5
|
+
"sourcesContent": ["/**\n * @file Package Entry Point\n * @module mlly\n */\n\nexport * from './enums'\nexport type * from './interfaces'\nexport type * from './types'\nexport * from './utils'\n"],
|
|
6
|
+
"mappings": "AAKA,cAAc;AAGd,cAAc;",
|
|
7
7
|
"names": []
|
|
8
8
|
}
|
|
@@ -16,7 +16,7 @@ import { URL } from 'node:url';
|
|
|
16
16
|
*
|
|
17
17
|
* - [Subpath import][2] targets (that are strings) must be relative to the
|
|
18
18
|
* current working directory (e.g. `'./src/index.ts'`, `'./src/*.ts'`) or
|
|
19
|
-
* start with a [NPM
|
|
19
|
+
* start with a [valid NPM package name][3]. See [`nodejs/node#40579`][4] for
|
|
20
20
|
* details.
|
|
21
21
|
*
|
|
22
22
|
* [1]: https://nodejs.org/api/esm.html#esm_resolver_algorithm
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/resolve-module.ts"],
|
|
4
4
|
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file resolveModule\n * @module mlly/utils/resolveModule\n */\n\nimport type { ResolveModuleOptions } from '#src/interfaces'\nimport Resolver from '#src/internal/resolver'\nimport validateArraySet from '#src/internal/validate-array-set'\nimport validateBoolean from '#src/internal/validate-boolean'\nimport validateString from '#src/internal/validate-string'\nimport validateURLString from '#src/internal/validate-url-string'\nimport { ErrorCode, type NodeError } from '@flex-development/errnode'\nimport { isBuiltin } from '@flex-development/is-builtin'\nimport pathe from '@flex-development/pathe'\nimport { cast, isFunction, type Nullable } from '@flex-development/tutils'\nimport { URL, fileURLToPath } from 'node:url'\nimport CONDITIONS from './conditions'\nimport RESOLVE_EXTENSIONS from './resolve-extensions'\n\n/**\n * Resolves `specifier` according to the [ESM Resolver algorithm][1], mostly 😉.\n *\n * Adds support for:\n *\n * - Extensionless file and directory index resolution\n * - Replacing file extensions\n *\n * Other differences between Node.js:\n *\n * - [Subpath import][2] targets (that are strings) must be relative to the\n * current working directory (e.g. `'./src/index.ts'`, `'./src/*.ts'`) or\n * start with a [NPM
|
|
5
|
+
"sourcesContent": ["/**\n * @file resolveModule\n * @module mlly/utils/resolveModule\n */\n\nimport type { ResolveModuleOptions } from '#src/interfaces'\nimport Resolver from '#src/internal/resolver'\nimport validateArraySet from '#src/internal/validate-array-set'\nimport validateBoolean from '#src/internal/validate-boolean'\nimport validateString from '#src/internal/validate-string'\nimport validateURLString from '#src/internal/validate-url-string'\nimport { ErrorCode, type NodeError } from '@flex-development/errnode'\nimport { isBuiltin } from '@flex-development/is-builtin'\nimport pathe from '@flex-development/pathe'\nimport { cast, isFunction, type Nullable } from '@flex-development/tutils'\nimport { URL, fileURLToPath } from 'node:url'\nimport CONDITIONS from './conditions'\nimport RESOLVE_EXTENSIONS from './resolve-extensions'\n\n/**\n * Resolves `specifier` according to the [ESM Resolver algorithm][1], mostly 😉.\n *\n * Adds support for:\n *\n * - Extensionless file and directory index resolution\n * - Replacing file extensions\n *\n * Other differences between Node.js:\n *\n * - [Subpath import][2] targets (that are strings) must be relative to the\n * current working directory (e.g. `'./src/index.ts'`, `'./src/*.ts'`) or\n * start with a [valid NPM package name][3]. See [`nodejs/node#40579`][4] for\n * details.\n *\n * [1]: https://nodejs.org/api/esm.html#esm_resolver_algorithm\n * [2]: https://nodejs.org/api/packages.html#subpath-imports\n * [3]: https://regex101.com/r/BHcJfc\n * [4]: https://github.com/nodejs/node/issues/40579\n *\n * @see {@linkcode NodeError}\n * @see {@linkcode ResolveModuleOptions}\n * @see {@linkcode URL}\n *\n * @async\n *\n * @param {string} specifier - Module specifier to resolve\n * @param {ResolveModuleOptions} [options={}] - Module resolution options\n * @return {Promise<URL>} Resolved module URL\n * @throws {NodeError}\n */\nconst resolveModule = async (\n specifier: string,\n options: ResolveModuleOptions = {}\n): Promise<URL> => {\n const {\n condition = 'default',\n conditions = CONDITIONS,\n extensions = RESOLVE_EXTENSIONS,\n parent = import.meta.url,\n preserveSymlinks = false\n } = options\n\n // ensure specifier is a string\n validateString(specifier, 'specifier')\n\n // ensure option schemas\n validateString(condition, 'options.condition')\n validateArraySet(conditions, 'options.conditions')\n validateArraySet(extensions, 'options.extensions')\n validateURLString(parent, 'options.parent')\n validateBoolean(preserveSymlinks, 'options.preserveSymlinks')\n\n /**\n * Module resolver.\n *\n * @const {Resolver} resolver\n */\n const resolver: Resolver = new Resolver()\n\n /**\n * Boolean indicating only module id should be tried for resolution.\n *\n * @const {boolean} onetry\n */\n const onetry: boolean =\n isBuiltin(specifier) ||\n (/^\\S+:/.test(specifier) && !specifier.startsWith('file:'))\n\n /**\n * Module ids to try resolving.\n *\n * @const {string[]} tries\n */\n const tries: string[] = onetry\n ? []\n : [...extensions]\n .flatMap(ext => [\n specifier + (ext = pathe.formatExt(ext)),\n specifier.startsWith('#') ? specifier + '/index' : '',\n specifier + '/index' + ext\n ])\n .filter(id => !!id.length)\n\n // try @types resolution\n if (!onetry) {\n specifier.startsWith('@types')\n ? tries.unshift(specifier + '/index.d.ts')\n : tries.unshift('@types/' + specifier + '/index.d.ts')\n }\n\n // ensure attempt to resolve original specifier is first\n tries.unshift(specifier)\n\n /**\n * Error codes to ignore when attempting to resolve {@linkcode specifier}.\n *\n * **Note**: If an error is thrown, it'll be reported **_after_** all module\n * ids in {@linkcode tries} have been evaluated.\n *\n * @const {Set<ErrorCode>} ignore\n */\n const ignore: Set<ErrorCode> = new Set<ErrorCode>([\n ErrorCode.ERR_INVALID_MODULE_SPECIFIER,\n ErrorCode.ERR_MODULE_NOT_FOUND,\n ErrorCode.ERR_PACKAGE_PATH_NOT_EXPORTED,\n ErrorCode.ERR_UNSUPPORTED_DIR_IMPORT\n ])\n\n /**\n * Module resolution error.\n *\n * @var {NodeError} error\n */\n let error: NodeError\n\n /**\n * Resolved module URL.\n *\n * @var {Nullable<URL>} url\n */\n let url: Nullable<URL> = null\n\n // try module resolution\n for (const id of tries) {\n try {\n url = resolver.resolveModule(\n id,\n parent,\n condition,\n new Set(conditions),\n preserveSymlinks\n )\n } catch (e: unknown) {\n url = null\n if (id === specifier) error = cast(e)\n if (!ignore.has(cast<NodeError>(e).code)) throw e\n }\n\n // stop resolution attempts if module was resolved\n if (url) break\n }\n\n // throw if module was not resolved\n if (!url) throw error!\n\n // replace file extension\n if (url.protocol === 'file:') {\n let { ext } = options\n\n // get replacement extension\n ext = isFunction(ext) ? await ext(specifier, url) : ext\n\n // replace file extension in url href and pathname\n url.href = pathe.changeExt(url.href, ext).replace(/\\/index$/, '')\n url.pathname = fileURLToPath(url.href)\n }\n\n return url\n}\n\nexport default resolveModule\n"],
|
|
6
6
|
"mappings": "AAMA,OAAO,cAAc;AACrB,OAAO,sBAAsB;AAC7B,OAAO,qBAAqB;AAC5B,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAC9B,SAAS,iBAAiC;AAC1C,SAAS,iBAAiB;AAC1B,OAAO,WAAW;AAClB,SAAS,MAAM,kBAAiC;AAChD,SAAS,KAAK,qBAAqB;AACnC,OAAO,gBAAgB;AACvB,OAAO,wBAAwB;AAiC/B,MAAM,gBAAgB,OACpB,WACA,UAAgC,CAAC,MAChB;AACjB,QAAM;AAAA,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;AAGA,MAAI,CAAC;AAAK,UAAM;AAGhB,MAAI,IAAI,aAAa,SAAS;AAC5B,QAAI,EAAE,IAAI,IAAI;AAGd,UAAM,WAAW,GAAG,IAAI,MAAM,IAAI,WAAW,GAAG,IAAI,KAGpD,IAAI,OAAO,MAAM,UAAU,IAAI,MAAM,GAAG,EAAE,QAAQ,YAAY,EAAE,GAChE,IAAI,WAAW,cAAc,IAAI,IAAI;AAAA,EACvC;AAEA,SAAO;AACT;AAEA,IAAO,yBAAQ;",
|
|
7
7
|
"names": []
|
|
8
8
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import PACKAGE_NAME_REGEX from "../internal/regex-package-name.mjs";
|
|
1
2
|
import validateSet from "../internal/validate-set.mjs";
|
|
2
3
|
import validateURLString from "../internal/validate-url-string.mjs";
|
|
3
4
|
import {
|
|
@@ -10,6 +11,7 @@ import pathe from "@flex-development/pathe";
|
|
|
10
11
|
import {
|
|
11
12
|
DOT,
|
|
12
13
|
cast,
|
|
14
|
+
includes,
|
|
13
15
|
isNIL,
|
|
14
16
|
regexp
|
|
15
17
|
} from "@flex-development/tutils";
|
|
@@ -28,6 +30,8 @@ import toURL from "./to-url.mjs";
|
|
|
28
30
|
const toBareSpecifier = (specifier, parent, conditions = CONDITIONS) => {
|
|
29
31
|
if (validateURLString(specifier, "specifier"), validateURLString(parent, "parent"), validateSet(conditions, "conditions"), specifier instanceof URL && (specifier = specifier.href), isBuiltin(specifier))
|
|
30
32
|
return toNodeURL(specifier);
|
|
33
|
+
if (PACKAGE_NAME_REGEX.test(specifier))
|
|
34
|
+
return specifier;
|
|
31
35
|
specifier.startsWith("file:") && (specifier = fileURLToPath(specifier)), isRelativeSpecifier(specifier) && (specifier = fileURLToPath(toAbsoluteSpecifier(specifier)));
|
|
32
36
|
const url = toURL(
|
|
33
37
|
isAbsoluteSpecifier(specifier) || specifier.startsWith("node_modules") ? specifier : `node_modules/${specifier}`
|
|
@@ -35,7 +39,10 @@ const toBareSpecifier = (specifier, parent, conditions = CONDITIONS) => {
|
|
|
35
39
|
if (!scope)
|
|
36
40
|
throw new ERR_OPERATION_FAILED(`Package scope for '${specifier}' not found`);
|
|
37
41
|
const { exports, main, name = "", types } = scope.pkgjson;
|
|
38
|
-
specifier =
|
|
42
|
+
specifier = includes(url.pathname, "node_modules" + pathe.sep + name) ? url.pathname.replace(
|
|
43
|
+
new RegExp(`.*?node_modules${regexp(pathe.sep)}(?=${regexp(name)})`),
|
|
44
|
+
""
|
|
45
|
+
) : name + specifier.replace(fileURLToPath(scope.dir.replace(/\/$/, "")), "");
|
|
39
46
|
const id = parseModuleId(specifier, {
|
|
40
47
|
internal: !1,
|
|
41
48
|
parent,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/to-bare-specifier.ts"],
|
|
4
4
|
"sourceRoot": "file://",
|
|
5
|
-
"sourcesContent": ["/**\n * @file toBareSpecifier\n * @module mlly/utils/toBareSpecifier\n */\n\nimport type { PackageScope, ParsedModuleId } from '#src/interfaces'\nimport validateSet from '#src/internal/validate-set'\nimport validateURLString from '#src/internal/validate-url-string'\nimport type { ModuleId } from '#src/types'\nimport {\n ERR_OPERATION_FAILED,\n ERR_PACKAGE_PATH_NOT_EXPORTED,\n ErrorCode,\n type NodeError\n} from '@flex-development/errnode'\nimport { isBuiltin } from '@flex-development/is-builtin'\nimport pathe from '@flex-development/pathe'\nimport {\n DOT,\n cast,\n isNIL,\n regexp,\n type Nullable\n} from '@flex-development/tutils'\nimport { URL, fileURLToPath, pathToFileURL } from 'node:url'\nimport CONDITIONS from './conditions'\nimport findSubpath from './find-subpath'\nimport isAbsoluteSpecifier from './is-absolute-specifier'\nimport isRelativeSpecifier from './is-relative-specifier'\nimport lookupPackageScope from './lookup-package-scope'\nimport parseModuleId from './parse-module-id'\nimport parseSubpath from './parse-subpath'\nimport PATTERN_CHARACTER from './pattern-character'\nimport toAbsoluteSpecifier from './to-absolute-specifier'\nimport toNodeURL from './to-node-url'\nimport toURL from './to-url'\n\n/**\n * Converts the given module `specifier` into a bare specifier.\n *\n * The new specifier is **not** guaranteed to resolve to an existing module, nor\n * is it guaranteed to have a file extension, but it *is* guaranteed to be a\n * package path containing a valid [subpath export][1] if the specifier's parent\n * package uses package [`exports`][2]. If the parent package does not use\n * `exports`, the new specifier is only guaranteed to begin with a valid NPM\n * package name or Node.js [builtin module][3] name.\n *\n * The given module `specifier` should be absolute, syntactically bare (i.e. not\n * begin with `'/'` or `'.'`), or relative to the current working directory\n * (e.g. `'./dist/index.mjs'`).\n *\n * ::: warning\n * Internal specifier (i.e. [subpath import][4]; `'#src'`, `'#src/utils'`)\n * conversion is not supported. Converting *_to_* an internal specifier will be\n * supported in the future.\n * :::\n *\n * [1]: https://nodejs.org/api/packages.html#subpath-exports\n * [2]: https://nodejs.org/api/packages.html#exports\n * [3]: https://nodejs.org/api/module.html#modulebuiltinmodules\n * [4]: https://nodejs.org/api/packages.html#subpath-imports\n *\n * @see {@linkcode CONDITIONS}\n * @see {@linkcode ModuleId}\n * @see https://nodejs.org/api/esm.html#terminology\n *\n * @param {ModuleId} specifier - Module specifier to convert\n * @param {ModuleId} parent - URL of module to resolve from\n * @param {Set<string>?} [conditions=CONDITIONS] - Export conditions\n * @return {string} `specifier` as bare specifier\n * @throws {NodeError}\n */\nconst toBareSpecifier = (\n specifier: ModuleId,\n parent: ModuleId,\n conditions: Set<string> = CONDITIONS\n): string => {\n validateURLString(specifier, 'specifier')\n validateURLString(parent, 'parent')\n validateSet(conditions, 'conditions')\n\n // ensure specifier is a string\n if (specifier instanceof URL) specifier = specifier.href\n\n // exit early if specifier is builtin module\n if (isBuiltin(specifier)) return toNodeURL(specifier)\n\n // ensure specifier is a path\n if (specifier.startsWith('file:')) specifier = fileURLToPath(specifier)\n\n // convert relative specifiers to absolute paths\n if (isRelativeSpecifier(specifier)) {\n specifier = fileURLToPath(toAbsoluteSpecifier(specifier))\n }\n\n /**\n * Location to begin package scope search for {@linkcode specifier}.\n *\n * @const {URL} url\n */\n const url: URL = toURL(\n isAbsoluteSpecifier(specifier) || specifier.startsWith('node_modules')\n ? specifier\n : `node_modules/${specifier}`\n )\n\n /**\n * Package scope result for {@linkcode specifier}.\n *\n * @const {Nullable<PackageScope>} scope\n */\n const scope: Nullable<PackageScope> =\n lookupPackageScope(url, pathToFileURL(DOT)) ??\n lookupPackageScope(specifier, pathToFileURL(DOT))\n\n // throw if package scope was not found\n if (!scope) {\n throw new ERR_OPERATION_FAILED(`Package scope for '${specifier}' not found`)\n }\n\n // get package exports and name\n const { exports, main, name = '', types } = scope.pkgjson\n\n // convert specifier to bare specifier\n specifier = url.pathname.
|
|
6
|
-
"mappings": "AAMA,OAAO,iBAAiB;AACxB,OAAO,uBAAuB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB;AAC1B,OAAO,WAAW;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,KAAK,eAAe,qBAAqB;AAClD,OAAO,gBAAgB;AACvB,OAAO,iBAAiB;AACxB,OAAO,yBAAyB;AAChC,OAAO,yBAAyB;AAChC,OAAO,wBAAwB;AAC/B,OAAO,mBAAmB;AAC1B,OAAO,kBAAkB;AACzB,OAAO,uBAAuB;AAC9B,OAAO,yBAAyB;AAChC,OAAO,eAAe;AACtB,OAAO,WAAW;AAqClB,MAAM,kBAAkB,CACtB,WACA,QACA,aAA0B,eACf;AASX,MARA,kBAAkB,WAAW,WAAW,GACxC,kBAAkB,QAAQ,QAAQ,GAClC,YAAY,YAAY,YAAY,GAGhC,qBAAqB,QAAK,YAAY,UAAU,OAGhD,UAAU,SAAS;AAAG,WAAO,UAAU,SAAS;AAGpD,EAAI,UAAU,WAAW,OAAO,MAAG,YAAY,cAAc,SAAS,IAGlE,oBAAoB,SAAS,MAC/B,YAAY,cAAc,oBAAoB,SAAS,CAAC;AAQ1D,QAAM,MAAW;AAAA,IACf,oBAAoB,SAAS,KAAK,UAAU,WAAW,cAAc,IACjE,YACA,gBAAgB,SAAS;AAAA,EAC/B,GAOM,QACJ,mBAAmB,KAAK,cAAc,GAAG,CAAC,KAC1C,mBAAmB,WAAW,cAAc,GAAG,CAAC;AAGlD,MAAI,CAAC;AACH,UAAM,IAAI,qBAAqB,sBAAsB,SAAS,aAAa;AAI7E,QAAM,EAAE,SAAS,MAAM,OAAO,IAAI,MAAM,IAAI,MAAM;AAGlD,
|
|
5
|
+
"sourcesContent": ["/**\n * @file toBareSpecifier\n * @module mlly/utils/toBareSpecifier\n */\n\nimport type { PackageScope, ParsedModuleId } from '#src/interfaces'\nimport PACKAGE_NAME_REGEX from '#src/internal/regex-package-name'\nimport validateSet from '#src/internal/validate-set'\nimport validateURLString from '#src/internal/validate-url-string'\nimport type { ModuleId } from '#src/types'\nimport {\n ERR_OPERATION_FAILED,\n ERR_PACKAGE_PATH_NOT_EXPORTED,\n ErrorCode,\n type NodeError\n} from '@flex-development/errnode'\nimport { isBuiltin } from '@flex-development/is-builtin'\nimport pathe from '@flex-development/pathe'\nimport {\n DOT,\n cast,\n includes,\n isNIL,\n regexp,\n type Nullable\n} from '@flex-development/tutils'\nimport { URL, fileURLToPath, pathToFileURL } from 'node:url'\nimport CONDITIONS from './conditions'\nimport findSubpath from './find-subpath'\nimport isAbsoluteSpecifier from './is-absolute-specifier'\nimport isRelativeSpecifier from './is-relative-specifier'\nimport lookupPackageScope from './lookup-package-scope'\nimport parseModuleId from './parse-module-id'\nimport parseSubpath from './parse-subpath'\nimport PATTERN_CHARACTER from './pattern-character'\nimport toAbsoluteSpecifier from './to-absolute-specifier'\nimport toNodeURL from './to-node-url'\nimport toURL from './to-url'\n\n/**\n * Converts the given module `specifier` into a bare specifier.\n *\n * The new specifier is **not** guaranteed to resolve to an existing module, nor\n * is it guaranteed to have a file extension, but it *is* guaranteed to be a\n * package path containing a valid [subpath export][1] if the specifier's parent\n * package uses package [`exports`][2]. If the parent package does not use\n * `exports`, the new specifier is only guaranteed to begin with a valid NPM\n * package name or Node.js [builtin module][3] name.\n *\n * The given module `specifier` should be absolute, syntactically bare (i.e. not\n * begin with `'/'` or `'.'`), or relative to the current working directory\n * (e.g. `'./dist/index.mjs'`).\n *\n * ::: warning\n * Internal specifier (i.e. [subpath import][4]; `'#src'`, `'#src/utils'`)\n * conversion is not supported. Converting *_to_* an internal specifier will be\n * supported in the future.\n * :::\n *\n * [1]: https://nodejs.org/api/packages.html#subpath-exports\n * [2]: https://nodejs.org/api/packages.html#exports\n * [3]: https://nodejs.org/api/module.html#modulebuiltinmodules\n * [4]: https://nodejs.org/api/packages.html#subpath-imports\n *\n * @see {@linkcode CONDITIONS}\n * @see {@linkcode ModuleId}\n * @see https://nodejs.org/api/esm.html#terminology\n *\n * @param {ModuleId} specifier - Module specifier to convert\n * @param {ModuleId} parent - URL of module to resolve from\n * @param {Set<string>?} [conditions=CONDITIONS] - Export conditions\n * @return {string} `specifier` as bare specifier\n * @throws {NodeError}\n */\nconst toBareSpecifier = (\n specifier: ModuleId,\n parent: ModuleId,\n conditions: Set<string> = CONDITIONS\n): string => {\n validateURLString(specifier, 'specifier')\n validateURLString(parent, 'parent')\n validateSet(conditions, 'conditions')\n\n // ensure specifier is a string\n if (specifier instanceof URL) specifier = specifier.href\n\n // exit early if specifier is builtin module\n if (isBuiltin(specifier)) return toNodeURL(specifier)\n\n // exit early if specifier is package name\n if (PACKAGE_NAME_REGEX.test(specifier)) return specifier\n\n // ensure specifier is a path\n if (specifier.startsWith('file:')) specifier = fileURLToPath(specifier)\n\n // convert relative specifiers to absolute paths\n if (isRelativeSpecifier(specifier)) {\n specifier = fileURLToPath(toAbsoluteSpecifier(specifier))\n }\n\n /**\n * Location to begin package scope search for {@linkcode specifier}.\n *\n * @const {URL} url\n */\n const url: URL = toURL(\n isAbsoluteSpecifier(specifier) || specifier.startsWith('node_modules')\n ? specifier\n : `node_modules/${specifier}`\n )\n\n /**\n * Package scope result for {@linkcode specifier}.\n *\n * @const {Nullable<PackageScope>} scope\n */\n const scope: Nullable<PackageScope> =\n lookupPackageScope(url, pathToFileURL(DOT)) ??\n lookupPackageScope(specifier, pathToFileURL(DOT))\n\n // throw if package scope was not found\n if (!scope) {\n throw new ERR_OPERATION_FAILED(`Package scope for '${specifier}' not found`)\n }\n\n // get package exports and name\n const { exports, main, name = '', types } = scope.pkgjson\n\n // convert specifier to bare specifier\n specifier = !includes(url.pathname, 'node_modules' + pathe.sep + name)\n ? name + specifier.replace(fileURLToPath(scope.dir.replace(/\\/$/, '')), '')\n : url.pathname.replace(\n new RegExp(`.*?node_modules${regexp(pathe.sep)}(?=${regexp(name)})`),\n ''\n )\n\n /**\n * Parsed module specifier.\n *\n * Ensures {@linkcode specifier} has become a bare specifier.\n *\n * @const {ParsedModuleId} id\n */\n const id: ParsedModuleId = parseModuleId(specifier, {\n internal: false,\n parent,\n pkgname: true\n })\n\n // exit early if subpath does not need to be validated\n if (isNIL(exports)) {\n // set specifier to package name if specifier is main or types entry point\n if ([main, types].some(ep => ep === id.path || ep === id.path.slice(2))) {\n specifier = id.pkg\n }\n\n // remove '@types/' prefix to avoid 'Cannot import type declaration files.\n // Consider importing \"*\" instead of \"@types/*\"' (TS6137) error\n specifier = specifier.replace(/^@types\\//, '')\n\n return specifier\n }\n\n // check if specifier contains valid subpath export\n try {\n parseSubpath(specifier, exports, { dir: scope.dir, parent })\n } catch (e: unknown) {\n // try finding defined subpath if specifier is invalid package path\n if (cast<NodeError>(e).code === ErrorCode.ERR_PACKAGE_PATH_NOT_EXPORTED) {\n /**\n * Package target to find defined subpath for.\n *\n * @const {string} target\n */\n const target: string = specifier.replace(name, DOT)\n\n /**\n * Subpath in {@linkcode exports} thats maps to {@linkcode target}, if any\n * at all.\n *\n * @var {Nullable<string>} subpath\n */\n let subpath: Nullable<string> = findSubpath(target, exports, {\n conditions,\n dir: scope.dir,\n parent\n })\n\n // throw if target was not matched to a subpath\n if (subpath === null) {\n throw new ERR_PACKAGE_PATH_NOT_EXPORTED(\n fileURLToPath(scope.dir),\n id.path,\n fileURLToPath(parent)\n )\n }\n\n // replace pattern character in subpath\n if (subpath.includes(PATTERN_CHARACTER)) {\n subpath = subpath.slice(0, subpath.indexOf(PATTERN_CHARACTER)).slice(1)\n subpath = DOT + target.slice(target.indexOf(subpath))\n }\n\n // subpath should not include extension if extension is already included\n // via package target\n if (pathe.extname(target) === pathe.extname(subpath)) {\n subpath = pathe.changeExt(subpath, '')\n }\n\n return name + subpath.slice(1)\n } /* c8 ignore next 3 */\n // throw original error if package path error is not encountered\n throw e\n }\n\n return specifier\n}\n\nexport default toBareSpecifier\n"],
|
|
6
|
+
"mappings": "AAMA,OAAO,wBAAwB;AAC/B,OAAO,iBAAiB;AACxB,OAAO,uBAAuB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB;AAC1B,OAAO,WAAW;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,KAAK,eAAe,qBAAqB;AAClD,OAAO,gBAAgB;AACvB,OAAO,iBAAiB;AACxB,OAAO,yBAAyB;AAChC,OAAO,yBAAyB;AAChC,OAAO,wBAAwB;AAC/B,OAAO,mBAAmB;AAC1B,OAAO,kBAAkB;AACzB,OAAO,uBAAuB;AAC9B,OAAO,yBAAyB;AAChC,OAAO,eAAe;AACtB,OAAO,WAAW;AAqClB,MAAM,kBAAkB,CACtB,WACA,QACA,aAA0B,eACf;AASX,MARA,kBAAkB,WAAW,WAAW,GACxC,kBAAkB,QAAQ,QAAQ,GAClC,YAAY,YAAY,YAAY,GAGhC,qBAAqB,QAAK,YAAY,UAAU,OAGhD,UAAU,SAAS;AAAG,WAAO,UAAU,SAAS;AAGpD,MAAI,mBAAmB,KAAK,SAAS;AAAG,WAAO;AAG/C,EAAI,UAAU,WAAW,OAAO,MAAG,YAAY,cAAc,SAAS,IAGlE,oBAAoB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AY;AACd,cAAM,IAAI;AAAA,UACR,cAAc,MAAM,GAAG;AAAA,UACvB,GAAG;AAAA,UACH,cAAc,MAAM;AAAA,QACtB;AAIF,aAAI,QAAQ,SAAS,iBAAiB,MACpC,UAAU,QAAQ,MAAM,GAAG,QAAQ,QAAQ,iBAAiB,CAAC,EAAE,MAAM,CAAC,GACtE,UAAU,MAAM,OAAO,MAAM,OAAO,QAAQ,OAAO,CAAC,IAKlD,MAAM,QAAQ,MAAM,MAAM,MAAM,QAAQ,OAAO,MACjD,UAAU,MAAM,UAAU,SAAS,EAAE,IAGhC,OAAO,QAAQ,MAAM,CAAC;AAAA,IAC/B;AAEA,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAEA,IAAO,4BAAQ;",
|
|
7
7
|
"names": []
|
|
8
8
|
}
|
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.18",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecmascript",
|
|
7
7
|
"esm",
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"@flex-development/is-builtin": "3.1.0",
|
|
85
85
|
"@flex-development/pathe": "2.0.0",
|
|
86
86
|
"@flex-development/pkg-types": "3.0.0",
|
|
87
|
-
"@flex-development/tutils": "6.0.0-alpha.
|
|
87
|
+
"@flex-development/tutils": "6.0.0-alpha.21"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@arethetypeswrong/cli": "0.7.1",
|
|
91
|
-
"@commitlint/cli": "17.
|
|
91
|
+
"@commitlint/cli": "17.7.1",
|
|
92
92
|
"@commitlint/types": "17.4.4",
|
|
93
93
|
"@docsearch/react": "3.5.1",
|
|
94
94
|
"@faker-js/faker": "8.0.2",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"@flex-development/docast": "1.0.0-alpha.13",
|
|
98
98
|
"@flex-development/docast-parse": "1.0.0-alpha.5",
|
|
99
99
|
"@flex-development/esm-types": "2.0.0",
|
|
100
|
-
"@flex-development/mkbuild": "1.0.0-alpha.
|
|
100
|
+
"@flex-development/mkbuild": "1.0.0-alpha.21",
|
|
101
101
|
"@graphql-eslint/eslint-plugin": "3.20.1",
|
|
102
102
|
"@sindresorhus/slugify": "2.2.1",
|
|
103
103
|
"@types/chai": "4.3.5",
|
|
@@ -116,8 +116,8 @@
|
|
|
116
116
|
"@types/prettier": "3.0.0",
|
|
117
117
|
"@types/semver": "7.5.0",
|
|
118
118
|
"@types/unist": "3.0.0",
|
|
119
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
120
|
-
"@typescript-eslint/parser": "6.
|
|
119
|
+
"@typescript-eslint/eslint-plugin": "6.4.0",
|
|
120
|
+
"@typescript-eslint/parser": "6.4.0",
|
|
121
121
|
"@vates/toggle-scripts": "1.0.0",
|
|
122
122
|
"@vitest/coverage-v8": "0.34.1",
|
|
123
123
|
"@vue/runtime-core": "3.3.4",
|
|
@@ -134,13 +134,13 @@
|
|
|
134
134
|
"conventional-changelog-writer": "6.0.1",
|
|
135
135
|
"conventional-recommended-bump": "7.0.1",
|
|
136
136
|
"cross-env": "7.0.3",
|
|
137
|
-
"cspell": "7.0.1-alpha.
|
|
137
|
+
"cspell": "7.0.1-alpha.9",
|
|
138
138
|
"dateformat": "5.0.3",
|
|
139
139
|
"dotenv": "16.3.1",
|
|
140
|
-
"esbuild": "0.19.
|
|
141
|
-
"eslint": "8.
|
|
140
|
+
"esbuild": "0.19.2",
|
|
141
|
+
"eslint": "8.47.0",
|
|
142
142
|
"eslint-config-prettier": "9.0.0",
|
|
143
|
-
"eslint-import-resolver-typescript": "3.
|
|
143
|
+
"eslint-import-resolver-typescript": "3.6.0",
|
|
144
144
|
"eslint-plugin-chai-expect": "3.0.0",
|
|
145
145
|
"eslint-plugin-import": "2.27.5",
|
|
146
146
|
"eslint-plugin-jest-formatting": "3.1.0",
|
|
@@ -152,17 +152,17 @@
|
|
|
152
152
|
"eslint-plugin-prettier": "5.0.0",
|
|
153
153
|
"eslint-plugin-promise": "6.1.1",
|
|
154
154
|
"eslint-plugin-unicorn": "48.0.1",
|
|
155
|
-
"eslint-plugin-vue": "9.
|
|
155
|
+
"eslint-plugin-vue": "9.17.0",
|
|
156
156
|
"eslint-plugin-yml": "1.8.0",
|
|
157
157
|
"globby": "13.2.2",
|
|
158
|
-
"graphql": "16.
|
|
158
|
+
"graphql": "16.8.0",
|
|
159
159
|
"graphql-config": "5.0.2",
|
|
160
160
|
"gray-matter": "4.0.3",
|
|
161
161
|
"growl": "1.10.5",
|
|
162
162
|
"husky": "8.0.3",
|
|
163
163
|
"is-ci": "3.0.1",
|
|
164
164
|
"jsonc-eslint-parser": "2.3.0",
|
|
165
|
-
"lint-staged": "
|
|
165
|
+
"lint-staged": "14.0.0",
|
|
166
166
|
"mri": "1.2.0",
|
|
167
167
|
"node-fetch": "3.3.2",
|
|
168
168
|
"node-notifier": "10.0.1",
|
|
File without changes
|
package/dist/types/index.mjs
DELETED
|
File without changes
|