@flex-development/mlly 1.0.0-beta.4 → 1.0.0-beta.5
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 +15 -0
- package/README.md +162 -79
- package/dist/index.d.mts +1885 -5
- package/dist/index.mjs +1 -5
- package/dist/internal/chain-or-call.d.mts +51 -0
- package/dist/internal/chain-or-call.mjs +1 -34
- package/dist/internal/chars.d.mts +16 -0
- package/dist/internal/chars.mjs +1 -17
- package/dist/internal/check-invalid-segments.d.mts +18 -0
- package/dist/internal/check-invalid-segments.mjs +1 -49
- package/dist/internal/constant.d.mts +21 -0
- package/dist/internal/constant.mjs +1 -23
- package/dist/internal/fs.browser.d.mts +12 -0
- package/dist/internal/fs.browser.mjs +1 -42
- package/dist/internal/fs.node.d.mts +12 -0
- package/dist/internal/fs.node.mjs +1 -16
- package/dist/internal/identity.d.mts +21 -0
- package/dist/internal/identity.mjs +1 -23
- package/dist/internal/invalid-package-target.d.mts +31 -0
- package/dist/internal/invalid-package-target.mjs +1 -36
- package/dist/internal/invalid-subpath.d.mts +32 -0
- package/dist/internal/invalid-subpath.mjs +1 -37
- package/dist/internal/is-promise.d.mts +21 -0
- package/dist/internal/is-promise.mjs +1 -26
- package/dist/internal/process.browser.d.mts +9 -0
- package/dist/internal/process.browser.mjs +1 -8
- package/dist/lib/can-parse-url.mjs +1 -31
- package/dist/lib/cwd.mjs +1 -17
- package/dist/lib/default-conditions.mjs +1 -14
- package/dist/lib/default-extensions.mjs +1 -29
- package/dist/lib/default-main-fields.mjs +1 -13
- package/dist/lib/extension-format-map.mjs +1 -31
- package/dist/lib/formats.mjs +1 -22
- package/dist/lib/get-source.mjs +1 -153
- package/dist/lib/index.mjs +1 -41
- package/dist/lib/is-absolute-specifier.mjs +1 -34
- package/dist/lib/is-array-index.mjs +1 -28
- package/dist/lib/is-bare-specifier.mjs +1 -33
- package/dist/lib/is-directory.mjs +1 -54
- package/dist/lib/is-file.mjs +1 -54
- package/dist/lib/is-imports-subpath.mjs +1 -28
- package/dist/lib/is-module-id.mjs +1 -24
- package/dist/lib/is-relative-specifier.mjs +1 -36
- package/dist/lib/lookup-package-scope.mjs +1 -102
- package/dist/lib/pattern-key-compare.mjs +1 -71
- package/dist/lib/pattern-match.mjs +1 -85
- package/dist/lib/read-package-json.mjs +1 -114
- package/dist/lib/resolve-alias.mjs +1 -102
- package/dist/lib/resolve-module.mjs +1 -186
- package/dist/lib/resolver.mjs +1 -1015
- package/dist/lib/root.mjs +1 -12
- package/dist/lib/to-relative-specifier.mjs +1 -63
- package/dist/lib/to-url.mjs +1 -34
- package/package.json +28 -10
- package/dist/interfaces/aliases.d.mts +0 -21
- package/dist/interfaces/buffer-encoding-map.d.mts +0 -29
- package/dist/interfaces/condition-map.d.mts +0 -24
- package/dist/interfaces/file-system.d.mts +0 -29
- package/dist/interfaces/get-source-context.d.mts +0 -44
- package/dist/interfaces/get-source-options.d.mts +0 -56
- package/dist/interfaces/index.d.mts +0 -22
- package/dist/interfaces/is-directory.d.mts +0 -17
- package/dist/interfaces/is-file.d.mts +0 -17
- package/dist/interfaces/main-field-map.d.mts +0 -22
- package/dist/interfaces/module-format-map.d.mts +0 -26
- package/dist/interfaces/pattern-key-comparison-map.d.mts +0 -31
- package/dist/interfaces/protocol-map.d.mts +0 -44
- package/dist/interfaces/read-file.d.mts +0 -42
- package/dist/interfaces/realpath.d.mts +0 -29
- package/dist/interfaces/resolve-alias-options.d.mts +0 -43
- package/dist/interfaces/resolve-module-options.d.mts +0 -79
- package/dist/interfaces/stat.d.mts +0 -27
- package/dist/interfaces/stats.d.mts +0 -23
- package/dist/lib/can-parse-url.d.mts +0 -23
- package/dist/lib/cwd.d.mts +0 -14
- package/dist/lib/default-conditions.d.mts +0 -15
- package/dist/lib/default-extensions.d.mts +0 -14
- package/dist/lib/default-main-fields.d.mts +0 -14
- package/dist/lib/extension-format-map.d.mts +0 -16
- package/dist/lib/formats.d.mts +0 -21
- package/dist/lib/get-source.d.mts +0 -46
- package/dist/lib/index.d.mts +0 -41
- package/dist/lib/is-absolute-specifier.d.mts +0 -23
- package/dist/lib/is-array-index.d.mts +0 -19
- package/dist/lib/is-bare-specifier.d.mts +0 -23
- package/dist/lib/is-directory.d.mts +0 -27
- package/dist/lib/is-file.d.mts +0 -27
- package/dist/lib/is-imports-subpath.d.mts +0 -26
- package/dist/lib/is-module-id.d.mts +0 -23
- package/dist/lib/is-relative-specifier.d.mts +0 -23
- package/dist/lib/lookup-package-scope.d.mts +0 -49
- package/dist/lib/pattern-key-compare.d.mts +0 -28
- package/dist/lib/pattern-match.d.mts +0 -22
- package/dist/lib/read-package-json.d.mts +0 -63
- package/dist/lib/resolve-alias.d.mts +0 -21
- package/dist/lib/resolve-module.d.mts +0 -43
- package/dist/lib/resolver.d.mts +0 -346
- package/dist/lib/root.d.mts +0 -11
- package/dist/lib/to-relative-specifier.d.mts +0 -27
- package/dist/lib/to-url.d.mts +0 -26
- package/dist/types/awaitable.d.mts +0 -12
- package/dist/types/buffer-encoding.d.mts +0 -13
- package/dist/types/change-ext-fn.d.mts +0 -29
- package/dist/types/condition.d.mts +0 -13
- package/dist/types/dot.d.mts +0 -9
- package/dist/types/empty-array.d.mts +0 -9
- package/dist/types/empty-object.d.mts +0 -19
- package/dist/types/empty-string.d.mts +0 -9
- package/dist/types/ext.d.mts +0 -12
- package/dist/types/file-content.d.mts +0 -11
- package/dist/types/get-source-handler.d.mts +0 -23
- package/dist/types/get-source-handlers.d.mts +0 -15
- package/dist/types/index.d.mts +0 -24
- package/dist/types/list.d.mts +0 -12
- package/dist/types/main-field.d.mts +0 -13
- package/dist/types/module-format.d.mts +0 -13
- package/dist/types/module-id.d.mts +0 -12
- package/dist/types/numeric.d.mts +0 -9
- package/dist/types/pattern-key-comparison.d.mts +0 -14
- package/dist/types/pattern-match.d.mts +0 -10
- package/dist/types/protocol.d.mts +0 -13
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file defaultExtensions
|
|
3
|
-
* @module mlly/lib/defaultExtensions
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* The default list of resolvable file extensions.
|
|
7
|
-
*
|
|
8
|
-
* @see {@linkcode Ext}
|
|
9
|
-
*
|
|
10
|
-
* @const {Set<Ext>} defaultExtensions
|
|
11
|
-
*/
|
|
12
|
-
const defaultExtensions = new Set([
|
|
13
|
-
'.mjs',
|
|
14
|
-
'.mts',
|
|
15
|
-
'.cjs',
|
|
16
|
-
'.cts',
|
|
17
|
-
'.js',
|
|
18
|
-
'.ts',
|
|
19
|
-
'.jsx',
|
|
20
|
-
'.tsx',
|
|
21
|
-
'.css',
|
|
22
|
-
'.json',
|
|
23
|
-
'.node',
|
|
24
|
-
'.wasm',
|
|
25
|
-
'.d.mts',
|
|
26
|
-
'.d.cts',
|
|
27
|
-
'.d.ts'
|
|
28
|
-
]);
|
|
29
|
-
export default defaultExtensions;
|
|
1
|
+
const s=new Set([".mjs",".mts",".cjs",".cts",".js",".ts",".jsx",".tsx",".css",".json",".node",".wasm",".d.mts",".d.cts",".d.ts"]);var t=s;export{t as default};
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file defaultMainFields
|
|
3
|
-
* @module mlly/lib/defaultMainFields
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* The default list of main fields.
|
|
7
|
-
*
|
|
8
|
-
* @see {@linkcode MainField}
|
|
9
|
-
*
|
|
10
|
-
* @const {Set<MainField>} defaultMainFields
|
|
11
|
-
*/
|
|
12
|
-
const defaultMainFields = new Set(['main']);
|
|
13
|
-
export default defaultMainFields;
|
|
1
|
+
const e=new Set(["main"]);var t=e;export{t as default};
|
|
@@ -1,31 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file extensionFormatMap
|
|
3
|
-
* @module mlly/lib/extensionFormatMap
|
|
4
|
-
*/
|
|
5
|
-
import formats from '#lib/formats';
|
|
6
|
-
/**
|
|
7
|
-
* Map, where each key is a file extension
|
|
8
|
-
* and each value is a default module format.
|
|
9
|
-
*
|
|
10
|
-
* @see {@linkcode Ext}
|
|
11
|
-
* @see {@linkcode ModuleFormat}
|
|
12
|
-
*
|
|
13
|
-
* @const {Map<Ext, ModuleFormat>} extensionFormatMap
|
|
14
|
-
*/
|
|
15
|
-
const extensionFormatMap = new Map([
|
|
16
|
-
['.cjs', formats.commonjs],
|
|
17
|
-
['.cts', formats.cts],
|
|
18
|
-
['.d.cts', formats.cts],
|
|
19
|
-
['.d.mts', formats.mts],
|
|
20
|
-
['.d.ts', formats.mts],
|
|
21
|
-
['.js', formats.module],
|
|
22
|
-
['.json', formats.json],
|
|
23
|
-
['.jsx', formats.module],
|
|
24
|
-
['.mjs', formats.module],
|
|
25
|
-
['.mts', formats.mts],
|
|
26
|
-
['.node', formats.commonjs],
|
|
27
|
-
['.ts', formats.mts],
|
|
28
|
-
['.tsx', formats.mts],
|
|
29
|
-
['.wasm', formats.wasm]
|
|
30
|
-
]);
|
|
31
|
-
export default extensionFormatMap;
|
|
1
|
+
import s from"#lib/formats";const m=new Map([[".cjs",s.commonjs],[".cts",s.cts],[".d.cts",s.cts],[".d.mts",s.mts],[".d.ts",s.mts],[".js",s.module],[".json",s.json],[".jsx",s.module],[".mjs",s.module],[".mts",s.mts],[".node",s.commonjs],[".ts",s.mts],[".tsx",s.mts],[".wasm",s.wasm]]);var o=m;export{o as default};
|
package/dist/lib/formats.mjs
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file formats
|
|
3
|
-
* @module mlly/lib/formats
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Default module formats.
|
|
7
|
-
*
|
|
8
|
-
* @see {@linkcode ModuleFormat}
|
|
9
|
-
*
|
|
10
|
-
* @enum {ModuleFormat}
|
|
11
|
-
*/
|
|
12
|
-
var formats;
|
|
13
|
-
(function (formats) {
|
|
14
|
-
formats["builtin"] = "builtin";
|
|
15
|
-
formats["commonjs"] = "commonjs";
|
|
16
|
-
formats["cts"] = "commonjs-typescript";
|
|
17
|
-
formats["json"] = "json";
|
|
18
|
-
formats["module"] = "module";
|
|
19
|
-
formats["mts"] = "module-typescript";
|
|
20
|
-
formats["wasm"] = "wasm";
|
|
21
|
-
})(formats || (formats = {}));
|
|
22
|
-
export default formats;
|
|
1
|
+
var o;(function(n){n.builtin="builtin",n.commonjs="commonjs",n.cts="commonjs-typescript",n.json="json",n.module="module",n.mts="module-typescript",n.wasm="wasm"})(o||(o={}));var c=o;export{c as default};
|
package/dist/lib/get-source.mjs
CHANGED
|
@@ -1,153 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file getSource
|
|
3
|
-
* @module mlly/lib/getSource
|
|
4
|
-
*/
|
|
5
|
-
import chainOrCall from '#internal/chain-or-call';
|
|
6
|
-
import fs from '#internal/fs';
|
|
7
|
-
import isPromise from '#internal/is-promise';
|
|
8
|
-
import process from '#internal/process';
|
|
9
|
-
import isFile from '#lib/is-file';
|
|
10
|
-
import isModuleId from '#lib/is-module-id';
|
|
11
|
-
import toUrl from '#lib/to-url';
|
|
12
|
-
import { ERR_UNSUPPORTED_ESM_URL_SCHEME } from '@flex-development/errnode';
|
|
13
|
-
import { ok } from 'devlop';
|
|
14
|
-
export default getSource;
|
|
15
|
-
/**
|
|
16
|
-
* Get the source code for a module.
|
|
17
|
-
*
|
|
18
|
-
* > 👉 **Note**: Returns a promise if the handler for `id` is async.
|
|
19
|
-
*
|
|
20
|
-
* @see {@linkcode Awaitable}
|
|
21
|
-
* @see {@linkcode ErrUnsupportedEsmUrlScheme}
|
|
22
|
-
* @see {@linkcode GetSourceOptions}
|
|
23
|
-
* @see {@linkcode ModuleId}
|
|
24
|
-
*
|
|
25
|
-
* @this {void}
|
|
26
|
-
*
|
|
27
|
-
* @param {ModuleId | null | undefined} id
|
|
28
|
-
* The module id
|
|
29
|
-
* @param {GetSourceOptions | null | undefined} [options]
|
|
30
|
-
* Source code retrieval options
|
|
31
|
-
* @return {Awaitable<FileContent | null | undefined>}
|
|
32
|
-
* The module source code
|
|
33
|
-
* @throws {ErrUnsupportedEsmUrlScheme}
|
|
34
|
-
*/
|
|
35
|
-
function getSource(id, options) {
|
|
36
|
-
if (!isModuleId(id))
|
|
37
|
-
return null;
|
|
38
|
-
/**
|
|
39
|
-
* The source code retrieval context.
|
|
40
|
-
*
|
|
41
|
-
* @const {GetSourceContext} context
|
|
42
|
-
*/
|
|
43
|
-
const context = {
|
|
44
|
-
...options,
|
|
45
|
-
fs: options?.fs ?? fs,
|
|
46
|
-
handlers: {
|
|
47
|
-
'data:': data,
|
|
48
|
-
'file:': file,
|
|
49
|
-
'http:': https,
|
|
50
|
-
'https:': https,
|
|
51
|
-
'node:': node,
|
|
52
|
-
...options?.handlers
|
|
53
|
-
},
|
|
54
|
-
req: { ...options?.req },
|
|
55
|
-
schemes: new Set(options?.schemes
|
|
56
|
-
? [...options.schemes]
|
|
57
|
-
: ['data', 'file', 'http', 'https', 'node'])
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* The module url.
|
|
61
|
-
*
|
|
62
|
-
* @const {URL} url
|
|
63
|
-
*/
|
|
64
|
-
const url = toUrl(id);
|
|
65
|
-
/**
|
|
66
|
-
* The source code handler for {@linkcode url}.
|
|
67
|
-
*
|
|
68
|
-
* @var {GetSourceHandler | null | undefined} handle
|
|
69
|
-
*/
|
|
70
|
-
let handle;
|
|
71
|
-
// get source code handler.
|
|
72
|
-
handle = context.handlers[url.protocol];
|
|
73
|
-
// handle unsupported url scheme.
|
|
74
|
-
if (typeof handle !== 'function') {
|
|
75
|
-
if (context.ignoreErrors)
|
|
76
|
-
return undefined;
|
|
77
|
-
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, [...context.schemes], process.platform === 'win32');
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* The source code.
|
|
81
|
-
*
|
|
82
|
-
* @var {ReturnType<GetSourceHandler>} code
|
|
83
|
-
*/
|
|
84
|
-
let code = handle.call(context, url);
|
|
85
|
-
// resolve source code.
|
|
86
|
-
if (isPromise(code)) {
|
|
87
|
-
void code.then(resolved => (code = resolved));
|
|
88
|
-
}
|
|
89
|
-
return chainOrCall(code, () => {
|
|
90
|
-
return ok(!isPromise(code), 'expected `code` to be resolved'), code;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* @this {GetSourceContext}
|
|
95
|
-
*
|
|
96
|
-
* @param {URL} url
|
|
97
|
-
* The module URL
|
|
98
|
-
* @return {Buffer}
|
|
99
|
-
* The source code buffer
|
|
100
|
-
*/
|
|
101
|
-
function data(url) {
|
|
102
|
-
const [mime, data = ''] = url.pathname.split(',');
|
|
103
|
-
ok(url.protocol === 'data:', 'expected `data:` URL');
|
|
104
|
-
ok(mime !== undefined, 'expected `mime` to be a string');
|
|
105
|
-
return Buffer.from(decodeURIComponent(data), mime.endsWith('base64') ? 'base64' : 'utf8');
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* > 👉 **Note**: Returns a promise if `this.fs.readFile` or `this.fs.stat`
|
|
109
|
-
* > is async.
|
|
110
|
-
*
|
|
111
|
-
* @this {GetSourceContext}
|
|
112
|
-
*
|
|
113
|
-
* @param {URL} url
|
|
114
|
-
* The module URL
|
|
115
|
-
* @return {Awaitable<FileContent | null>}
|
|
116
|
-
* The source code
|
|
117
|
-
*/
|
|
118
|
-
function file(url) {
|
|
119
|
-
ok(url.protocol === 'file:', 'expected `file:` URL');
|
|
120
|
-
/**
|
|
121
|
-
* Whether the file exists.
|
|
122
|
-
*
|
|
123
|
-
* @const {Awaitable<boolean>} exists
|
|
124
|
-
*/
|
|
125
|
-
const exists = isFile(url, this.fs);
|
|
126
|
-
return chainOrCall(exists, isFile => {
|
|
127
|
-
return isFile ?? exists ? this.fs.readFile(url, this.encoding) : null;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* @async
|
|
132
|
-
*
|
|
133
|
-
* @this {GetSourceContext}
|
|
134
|
-
*
|
|
135
|
-
* @param {URL} url
|
|
136
|
-
* The module URL
|
|
137
|
-
* @return {Promise<string>}
|
|
138
|
-
* The source code
|
|
139
|
-
*/
|
|
140
|
-
async function https(url) {
|
|
141
|
-
ok(/^https?:$/.test(url.protocol), 'expected `http:` or `https:` URL');
|
|
142
|
-
return (await fetch(url.href, this.req)).text();
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* @this {GetSourceContext}
|
|
146
|
-
*
|
|
147
|
-
* @param {URL} url
|
|
148
|
-
* The module URL
|
|
149
|
-
* @return {undefined}
|
|
150
|
-
*/
|
|
151
|
-
function node(url) {
|
|
152
|
-
return void ok(url.protocol === 'node:', 'expected `node:` URL');
|
|
153
|
-
}
|
|
1
|
+
var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});import d from"#internal/chain-or-call";import l from"#internal/fs";import c from"#internal/is-promise";import h from"#internal/process";import u from"#lib/is-file";import x from"#lib/is-module-id";import R from"#lib/to-url";import{ERR_UNSUPPORTED_ESM_URL_SCHEME as U}from"@flex-development/errnode";import{ok as i}from"devlop";var I=E;function E(e,t){if(!x(e))return null;const o={...t,fs:t?.fs??l,handlers:{"data:":w,"file:":L,"http:":m,"https:":m,"node:":S,...t?.handlers},req:{...t?.req},schemes:new Set(t?.schemes?[...t.schemes]:["data","file","http","https","node"])},s=R(e);let f;if(f=o.handlers[s.protocol],typeof f!="function"){if(o.ignoreErrors)return;throw new U(s,[...o.schemes],h.platform==="win32")}let r=f.call(o,s);return c(r)&&r.then(a=>r=a),d(r,()=>(i(!c(r),"expected `code` to be resolved"),r))}n(E,"getSource");function w(e){const[t,o=""]=e.pathname.split(",");return i(e.protocol==="data:","expected `data:` URL"),i(t!==void 0,"expected `mime` to be a string"),Buffer.from(decodeURIComponent(o),t.endsWith("base64")?"base64":"utf8")}n(w,"data");function L(e){i(e.protocol==="file:","expected `file:` URL");const t=u(e,this.fs);return d(t,o=>o??t?this.fs.readFile(e,this.encoding):null)}n(L,"file");async function m(e){return i(/^https?:$/.test(e.protocol),"expected `http:` or `https:` URL"),(await fetch(e.href,this.req)).text()}n(m,"https");function S(e){i(e.protocol==="node:","expected `node:` URL")}n(S,"node");export{I as default};
|
package/dist/lib/index.mjs
CHANGED
|
@@ -1,41 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file Entry Point - Library
|
|
3
|
-
* @module mlly/lib
|
|
4
|
-
*
|
|
5
|
-
* @todo `detectModuleSyntax` (esast integration)
|
|
6
|
-
* @todo `findDynamicImports` (esast integration)
|
|
7
|
-
* @todo `findExports` (esast integration)
|
|
8
|
-
* @todo `findImports` (esast integration)
|
|
9
|
-
* @todo `findRequires` (esast integration)
|
|
10
|
-
* @todo `findSpecifiers` (esast integration)
|
|
11
|
-
* @todo `findStaticImports` (esast integration)
|
|
12
|
-
* @todo `resolveAliases` (esast integration)
|
|
13
|
-
* @todo `resolveModules` (esast integration)
|
|
14
|
-
*/
|
|
15
|
-
export { default as canParseUrl } from '#lib/can-parse-url';
|
|
16
|
-
export { default as cwd } from '#lib/cwd';
|
|
17
|
-
export { default as defaultConditions } from '#lib/default-conditions';
|
|
18
|
-
export { default as defaultExtensions } from '#lib/default-extensions';
|
|
19
|
-
export { default as defaultMainFields } from '#lib/default-main-fields';
|
|
20
|
-
export { default as extensionFormatMap } from '#lib/extension-format-map';
|
|
21
|
-
export { default as formats } from '#lib/formats';
|
|
22
|
-
export { default as getSource } from '#lib/get-source';
|
|
23
|
-
export { default as isAbsoluteSpecifier } from '#lib/is-absolute-specifier';
|
|
24
|
-
export { default as isArrayIndex } from '#lib/is-array-index';
|
|
25
|
-
export { default as isBareSpecifier } from '#lib/is-bare-specifier';
|
|
26
|
-
export { default as isDirectory } from '#lib/is-directory';
|
|
27
|
-
export { default as isFile } from '#lib/is-file';
|
|
28
|
-
export { default as isImportsSubpath } from '#lib/is-imports-subpath';
|
|
29
|
-
export { default as isModuleId } from '#lib/is-module-id';
|
|
30
|
-
export { default as isRelativeSpecifier } from '#lib/is-relative-specifier';
|
|
31
|
-
export { default as lookupPackageScope } from '#lib/lookup-package-scope';
|
|
32
|
-
export { default as patternKeyCompare } from '#lib/pattern-key-compare';
|
|
33
|
-
export { default as patternMatch } from '#lib/pattern-match';
|
|
34
|
-
export { default as readPackageJson } from '#lib/read-package-json';
|
|
35
|
-
export { default as resolveAlias } from '#lib/resolve-alias';
|
|
36
|
-
export { default as resolveModule } from '#lib/resolve-module';
|
|
37
|
-
export * from '#lib/resolver';
|
|
38
|
-
export * as resolver from '#lib/resolver';
|
|
39
|
-
export { default as root } from '#lib/root';
|
|
40
|
-
export { default as toRelativeSpecifier } from '#lib/to-relative-specifier';
|
|
41
|
-
export { default as toUrl } from '#lib/to-url';
|
|
1
|
+
import{default as o}from"#lib/can-parse-url";import{default as t}from"#lib/cwd";import{default as s}from"#lib/default-conditions";import{default as p}from"#lib/default-extensions";import{default as u}from"#lib/default-main-fields";import{default as x}from"#lib/extension-format-map";import{default as c}from"#lib/formats";import{default as S}from"#lib/get-source";import{default as M}from"#lib/is-absolute-specifier";import{default as k}from"#lib/is-array-index";import{default as A}from"#lib/is-bare-specifier";import{default as I}from"#lib/is-directory";import{default as b}from"#lib/is-file";import{default as C}from"#lib/is-imports-subpath";import{default as U}from"#lib/is-module-id";import{default as B}from"#lib/is-relative-specifier";import{default as E}from"#lib/lookup-package-scope";import{default as K}from"#lib/pattern-key-compare";import{default as q}from"#lib/pattern-match";import{default as G}from"#lib/read-package-json";import{default as L}from"#lib/resolve-alias";import{default as O}from"#lib/resolve-module";export*from"#lib/resolver";import*as T from"#lib/resolver";import{default as W}from"#lib/root";import{default as Y}from"#lib/to-relative-specifier";import{default as _}from"#lib/to-url";export{o as canParseUrl,t as cwd,s as defaultConditions,p as defaultExtensions,u as defaultMainFields,x as extensionFormatMap,c as formats,S as getSource,M as isAbsoluteSpecifier,k as isArrayIndex,A as isBareSpecifier,I as isDirectory,b as isFile,C as isImportsSubpath,U as isModuleId,B as isRelativeSpecifier,E as lookupPackageScope,K as patternKeyCompare,q as patternMatch,G as readPackageJson,L as resolveAlias,O as resolveModule,T as resolver,W as root,Y as toRelativeSpecifier,_ as toUrl};
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isAbsoluteSpecifier
|
|
3
|
-
* @module mlly/lib/isAbsoluteSpecifier
|
|
4
|
-
*/
|
|
5
|
-
import canParseUrl from '#lib/can-parse-url';
|
|
6
|
-
import isModuleId from '#lib/is-module-id';
|
|
7
|
-
import pathe from '@flex-development/pathe';
|
|
8
|
-
/**
|
|
9
|
-
* Check if `value` is an *absolute specifier*.
|
|
10
|
-
*
|
|
11
|
-
* ::: warning
|
|
12
|
-
* Only checks specifier syntax.
|
|
13
|
-
* Does **not** guarantee the specifier references an existing module.
|
|
14
|
-
* :::
|
|
15
|
-
*
|
|
16
|
-
* @see https://nodejs.org/api/esm.html#terminology
|
|
17
|
-
*
|
|
18
|
-
* @this {void}
|
|
19
|
-
*
|
|
20
|
-
* @param {unknown} value
|
|
21
|
-
* The value to check
|
|
22
|
-
* @return {boolean}
|
|
23
|
-
* `true` if `value` is absolute specifier, `false` otherwise
|
|
24
|
-
*/
|
|
25
|
-
function isAbsoluteSpecifier(value) {
|
|
26
|
-
return (!isModuleId(value)
|
|
27
|
-
? false
|
|
28
|
-
: typeof value === 'string'
|
|
29
|
-
? value.startsWith('file:')
|
|
30
|
-
? canParseUrl(value)
|
|
31
|
-
: pathe.isAbsolute(value)
|
|
32
|
-
: value.protocol === 'file:' && canParseUrl(value));
|
|
33
|
-
}
|
|
34
|
-
export default isAbsoluteSpecifier;
|
|
1
|
+
var f=Object.defineProperty;var o=(t,i)=>f(t,"name",{value:i,configurable:!0});import r from"#lib/can-parse-url";import s from"#lib/is-module-id";import e from"@flex-development/pathe";function p(t){return s(t)?typeof t=="string"?t.startsWith("file:")?r(t):e.isAbsolute(t):t.protocol==="file:"&&r(t):!1}o(p,"isAbsoluteSpecifier");var l=p;export{l as default};
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isArrayIndex
|
|
3
|
-
* @module mlly/lib/isArrayIndex
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Check if `value` is a valid array index.
|
|
7
|
-
*
|
|
8
|
-
* @see {@linkcode Numeric}
|
|
9
|
-
*
|
|
10
|
-
* @this {void}
|
|
11
|
-
*
|
|
12
|
-
* @param {unknown} value
|
|
13
|
-
* The value to check
|
|
14
|
-
* @return {value is Numeric}
|
|
15
|
-
* `true` if `value` is valid array index, `false` otherwise
|
|
16
|
-
*/
|
|
17
|
-
function isArrayIndex(value) {
|
|
18
|
-
if (typeof value !== 'string')
|
|
19
|
-
return false;
|
|
20
|
-
/**
|
|
21
|
-
* The {@linkcode value} as number.
|
|
22
|
-
*
|
|
23
|
-
* @const {number} num
|
|
24
|
-
*/
|
|
25
|
-
const num = +value;
|
|
26
|
-
return value === `${num}` && num >= 0 && num < 0xFFFF_FFFF;
|
|
27
|
-
}
|
|
28
|
-
export default isArrayIndex;
|
|
1
|
+
var F=Object.defineProperty;var t=(n,r)=>F(n,"name",{value:r,configurable:!0});function e(n){if(typeof n!="string")return!1;const r=+n;return n===`${r}`&&r>=0&&r<4294967295}t(e,"isArrayIndex");var i=e;export{i as default};
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isBareSpecifier
|
|
3
|
-
* @module mlly/lib/isBareSpecifier
|
|
4
|
-
*/
|
|
5
|
-
import isAbsoluteSpecifier from '#lib/is-absolute-specifier';
|
|
6
|
-
import isRelativeSpecifier from '#lib/is-relative-specifier';
|
|
7
|
-
import { isBuiltin } from '@flex-development/is-builtin';
|
|
8
|
-
/**
|
|
9
|
-
* Check if `value` is a *bare specifier*.
|
|
10
|
-
*
|
|
11
|
-
* ::: warning
|
|
12
|
-
* Only checks specifier syntax.
|
|
13
|
-
* Does **not** guarantee the specifier references an existing module.
|
|
14
|
-
* :::
|
|
15
|
-
*
|
|
16
|
-
* @see https://nodejs.org/api/esm.html#terminology
|
|
17
|
-
*
|
|
18
|
-
* @this {void}
|
|
19
|
-
*
|
|
20
|
-
* @param {unknown} value
|
|
21
|
-
* The value to check
|
|
22
|
-
* @return {boolean}
|
|
23
|
-
* `true` if `value` is bare specifier, `false` otherwise
|
|
24
|
-
*/
|
|
25
|
-
function isBareSpecifier(value) {
|
|
26
|
-
if (isBuiltin(value))
|
|
27
|
-
return true;
|
|
28
|
-
return (typeof value === 'string' &&
|
|
29
|
-
!!value.length &&
|
|
30
|
-
!isAbsoluteSpecifier(value) &&
|
|
31
|
-
!isRelativeSpecifier(value));
|
|
32
|
-
}
|
|
33
|
-
export default isBareSpecifier;
|
|
1
|
+
var e=Object.defineProperty;var r=(i,t)=>e(i,"name",{value:t,configurable:!0});import f from"#lib/is-absolute-specifier";import o from"#lib/is-relative-specifier";import{isBuiltin as p}from"@flex-development/is-builtin";function n(i){return p(i)?!0:typeof i=="string"&&!!i.length&&!f(i)&&!o(i)}r(n,"isBareSpecifier");var S=n;export{S as default};
|
|
@@ -1,54 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isDirectory
|
|
3
|
-
* @module mlly/lib/isDirectory
|
|
4
|
-
*/
|
|
5
|
-
import chainOrCall from '#internal/chain-or-call';
|
|
6
|
-
import constant from '#internal/constant';
|
|
7
|
-
import dfs from '#internal/fs';
|
|
8
|
-
import identity from '#internal/identity';
|
|
9
|
-
import isPromise from '#internal/is-promise';
|
|
10
|
-
import isModuleId from '#lib/is-module-id';
|
|
11
|
-
export default isDirectory;
|
|
12
|
-
/**
|
|
13
|
-
* Check if a directory exists.
|
|
14
|
-
*
|
|
15
|
-
* > 👉 **Note**: Returns a promise if `fs.stat` is async.
|
|
16
|
-
*
|
|
17
|
-
* @see {@linkcode Awaitable}
|
|
18
|
-
* @see {@linkcode FileSystem}
|
|
19
|
-
*
|
|
20
|
-
* @this {void}
|
|
21
|
-
*
|
|
22
|
-
* @param {unknown} id
|
|
23
|
-
* The module id to check
|
|
24
|
-
* @param {FileSystem | null | undefined} fs
|
|
25
|
-
* The file system API
|
|
26
|
-
* @return {Awaitable<boolean>}
|
|
27
|
-
* `true` if directory exists at `id`, `false` otherwise
|
|
28
|
-
*/
|
|
29
|
-
function isDirectory(id, fs) {
|
|
30
|
-
if (isModuleId(id)) {
|
|
31
|
-
try {
|
|
32
|
-
if (typeof id === 'string' && id.startsWith('file:'))
|
|
33
|
-
id = new URL(id);
|
|
34
|
-
/**
|
|
35
|
-
* The stats object.
|
|
36
|
-
*
|
|
37
|
-
* @var {Awaitable<Stats | null>} stats
|
|
38
|
-
*/
|
|
39
|
-
let stats = (fs ?? dfs).stat(id);
|
|
40
|
-
// resolve the stats object.
|
|
41
|
-
if (isPromise(stats))
|
|
42
|
-
stats = stats.then(identity, constant(null));
|
|
43
|
-
return chainOrCall(stats, () => {
|
|
44
|
-
if (!isPromise(stats))
|
|
45
|
-
return stats.isDirectory();
|
|
46
|
-
return stats.then(stats => stats?.isDirectory() ?? false);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// swallow error.
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
1
|
+
var s=Object.defineProperty;var o=(t,i)=>s(t,"name",{value:i,configurable:!0});import n from"#internal/chain-or-call";import m from"#internal/constant";import a from"#internal/fs";import l from"#internal/identity";import e from"#internal/is-promise";import c from"#lib/is-module-id";var C=p;function p(t,i){if(c(t))try{typeof t=="string"&&t.startsWith("file:")&&(t=new URL(t));let r=(i??a).stat(t);return e(r)&&(r=r.then(l,m(null))),n(r,()=>e(r)?r.then(f=>f?.isDirectory()??!1):r.isDirectory())}catch{}return!1}o(p,"isDirectory");export{C as default};
|
package/dist/lib/is-file.mjs
CHANGED
|
@@ -1,54 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isFile
|
|
3
|
-
* @module mlly/lib/isFile
|
|
4
|
-
*/
|
|
5
|
-
import chainOrCall from '#internal/chain-or-call';
|
|
6
|
-
import constant from '#internal/constant';
|
|
7
|
-
import dfs from '#internal/fs';
|
|
8
|
-
import identity from '#internal/identity';
|
|
9
|
-
import isPromise from '#internal/is-promise';
|
|
10
|
-
import isModuleId from '#lib/is-module-id';
|
|
11
|
-
export default isFile;
|
|
12
|
-
/**
|
|
13
|
-
* Check if a file exists.
|
|
14
|
-
*
|
|
15
|
-
* > 👉 **Note**: Returns a promise if `fs.stat` is async.
|
|
16
|
-
*
|
|
17
|
-
* @see {@linkcode Awaitable}
|
|
18
|
-
* @see {@linkcode FileSystem}
|
|
19
|
-
*
|
|
20
|
-
* @this {void}
|
|
21
|
-
*
|
|
22
|
-
* @param {unknown} id
|
|
23
|
-
* The module id to check
|
|
24
|
-
* @param {FileSystem | null | undefined} fs
|
|
25
|
-
* The file system API
|
|
26
|
-
* @return {Awaitable<boolean>}
|
|
27
|
-
* `true` if file exists at `id`, `false` otherwise
|
|
28
|
-
*/
|
|
29
|
-
function isFile(id, fs) {
|
|
30
|
-
if (isModuleId(id)) {
|
|
31
|
-
try {
|
|
32
|
-
if (typeof id === 'string' && id.startsWith('file:'))
|
|
33
|
-
id = new URL(id);
|
|
34
|
-
/**
|
|
35
|
-
* The stats object.
|
|
36
|
-
*
|
|
37
|
-
* @var {Awaitable<Stats>} stats
|
|
38
|
-
*/
|
|
39
|
-
let stats = (fs ?? dfs).stat(id);
|
|
40
|
-
// resolve the stats object.
|
|
41
|
-
if (isPromise(stats))
|
|
42
|
-
stats = stats.then(identity, constant(null));
|
|
43
|
-
return chainOrCall(stats, () => {
|
|
44
|
-
if (!isPromise(stats))
|
|
45
|
-
return stats.isFile();
|
|
46
|
-
return stats.then(stats => stats?.isFile() ?? false);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// swallow error.
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
1
|
+
var s=Object.defineProperty;var e=(t,i)=>s(t,"name",{value:i,configurable:!0});import n from"#internal/chain-or-call";import l from"#internal/constant";import m from"#internal/fs";import a from"#internal/identity";import o from"#internal/is-promise";import p from"#lib/is-module-id";var C=u;function u(t,i){if(p(t))try{typeof t=="string"&&t.startsWith("file:")&&(t=new URL(t));let r=(i??m).stat(t);return o(r)&&(r=r.then(a,l(null))),n(r,()=>o(r)?r.then(f=>f?.isFile()??!1):r.isFile())}catch{}return!1}e(u,"isFile");export{C as default};
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isImportsSubpath
|
|
3
|
-
* @module mlly/lib/isImportsSubpath
|
|
4
|
-
*/
|
|
5
|
-
import chars from '#internal/chars';
|
|
6
|
-
/**
|
|
7
|
-
* Check if `value` is an [`imports`][subpath-imports] subpath.
|
|
8
|
-
*
|
|
9
|
-
* ::: warning
|
|
10
|
-
* Only checks specifier syntax.
|
|
11
|
-
* Does **not** guarantee the specifier references an existing module.
|
|
12
|
-
* :::
|
|
13
|
-
*
|
|
14
|
-
* [subpath-imports]: https://nodejs.org/api/packages.html#subpath-imports
|
|
15
|
-
*
|
|
16
|
-
* @see {@linkcode ImportsSubpath}
|
|
17
|
-
*
|
|
18
|
-
* @this {void}
|
|
19
|
-
*
|
|
20
|
-
* @param {unknown} value
|
|
21
|
-
* The value to check
|
|
22
|
-
* @return {value is ImportsSubpath}
|
|
23
|
-
* `true` if `value` is `imports` subpath, `false` otherwise
|
|
24
|
-
*/
|
|
25
|
-
function isImportsSubpath(value) {
|
|
26
|
-
return typeof value === 'string' && value[0] === chars.hash;
|
|
27
|
-
}
|
|
28
|
-
export default isImportsSubpath;
|
|
1
|
+
var p=Object.defineProperty;var r=(t,o)=>p(t,"name",{value:o,configurable:!0});import s from"#internal/chars";function f(t){return typeof t=="string"&&t[0]===s.hash}r(f,"isImportsSubpath");var n=f;export{n as default};
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isModuleId
|
|
3
|
-
* @module mlly/lib/isModuleId
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Check if `value` is a module id.
|
|
7
|
-
*
|
|
8
|
-
* ::: warning
|
|
9
|
-
* Does **not** guarantee `value` references an existing file or directory.
|
|
10
|
-
* :::
|
|
11
|
-
*
|
|
12
|
-
* @see {@linkcode ModuleId}
|
|
13
|
-
*
|
|
14
|
-
* @this {void}
|
|
15
|
-
*
|
|
16
|
-
* @param {unknown} value
|
|
17
|
-
* The value to check
|
|
18
|
-
* @return {value is ModuleId}
|
|
19
|
-
* `true` if `value` is module id, `false` otherwise
|
|
20
|
-
*/
|
|
21
|
-
function isModuleId(value) {
|
|
22
|
-
return typeof value === 'string' || value instanceof URL;
|
|
23
|
-
}
|
|
24
|
-
export default isModuleId;
|
|
1
|
+
var o=Object.defineProperty;var n=(t,e)=>o(t,"name",{value:e,configurable:!0});function f(t){return typeof t=="string"||t instanceof URL}n(f,"isModuleId");var r=f;export{r as default};
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @file isRelativeSpecifier
|
|
3
|
-
* @module mlly/lib/isRelativeSpecifier
|
|
4
|
-
*/
|
|
5
|
-
import pathe from '@flex-development/pathe';
|
|
6
|
-
/**
|
|
7
|
-
* Check if `value` is a *relative specifier*.
|
|
8
|
-
*
|
|
9
|
-
* ::: warning
|
|
10
|
-
* Only checks specifier syntax.
|
|
11
|
-
* Does **not** guarantee the specifier references an existing module.
|
|
12
|
-
* :::
|
|
13
|
-
*
|
|
14
|
-
* @see https://nodejs.org/api/esm.html#terminology
|
|
15
|
-
*
|
|
16
|
-
* @this {void}
|
|
17
|
-
*
|
|
18
|
-
* @param {unknown} value
|
|
19
|
-
* The value to check
|
|
20
|
-
* @return {boolean}
|
|
21
|
-
* `true` if `value` is relative specifier, `false` otherwise
|
|
22
|
-
*/
|
|
23
|
-
function isRelativeSpecifier(value) {
|
|
24
|
-
if (typeof value === 'string') {
|
|
25
|
-
if (value[0] === pathe.dot) {
|
|
26
|
-
if (value.length === 1 || value[1] === pathe.sep)
|
|
27
|
-
return true;
|
|
28
|
-
if (value[1] === pathe.dot &&
|
|
29
|
-
(value.length === 2 || value[2] === pathe.sep)) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
export default isRelativeSpecifier;
|
|
1
|
+
var f=Object.defineProperty;var e=(t,i)=>f(t,"name",{value:i,configurable:!0});import r from"@flex-development/pathe";function n(t){return typeof t=="string"&&t[0]===r.dot&&(t.length===1||t[1]===r.sep||t[1]===r.dot&&(t.length===2||t[2]===r.sep))}e(n,"isRelativeSpecifier");var s=n;export{s as default};
|