|
5 | 5 |
|
6 | 6 | import fs from '#internal/fs'
|
7 | 7 | import process from '#internal/process'
|
8 |
| -import canParseUrl from '#lib/can-parse-url' |
9 | 8 | import isFile from '#lib/is-file'
|
| 9 | +import toUrl from '#lib/to-url' |
10 | 10 | import {
|
11 | 11 | ERR_UNSUPPORTED_ESM_URL_SCHEME,
|
12 | 12 | type ErrUnsupportedEsmUrlScheme
|
13 | 13 | } from '@flex-development/errnode'
|
14 |
| -import { isBuiltin } from '@flex-development/is-builtin' |
15 | 14 | import type {
|
16 | 15 | GetSourceContext,
|
17 | 16 | GetSourceHandler,
|
18 | 17 | GetSourceOptions,
|
19 | 18 | ModuleId,
|
20 | 19 | Protocol
|
21 | 20 | } from '@flex-development/mlly'
|
22 |
| -import pathe from '@flex-development/pathe' |
23 | 21 | import { ok } from 'devlop'
|
24 | 22 |
|
25 | 23 | export default getSource
|
26 | 24 |
|
27 | 25 | /**
|
28 | 26 | * Get the source code for `id`.
|
29 | 27 | *
|
30 |
| - * > 👉 **Note**: If `id` is not a [builtin module][builtin-module] and also |
31 |
| - * > cannot be parsed as an {@linkcode URL}, it will be assumed to be a path and |
32 |
| - * > converted to a [`file:` URL][file-url]. |
33 |
| - * |
34 |
| - * [builtin-module]: https://nodejs.org/api/esm.html#builtin-modules |
35 |
| - * [file-url]: https://nodejs.org/api/esm.html#file-urls |
36 |
| - * |
37 | 28 | * @see {@linkcode ErrUnsupportedEsmUrlScheme}
|
38 | 29 | * @see {@linkcode GetSourceOptions}
|
39 | 30 | * @see {@linkcode ModuleId}
|
@@ -85,11 +76,7 @@ async function getSource(
|
85 | 76 | *
|
86 | 77 | * @const {URL} url
|
87 | 78 | */
|
88 |
| - const url: URL = isBuiltin(id) |
89 |
| - ? new URL('node:' + String(id).replace(/^node:/, '')) |
90 |
| - : canParseUrl(id) |
91 |
| - ? new URL(id) |
92 |
| - : (ok(typeof id === 'string', 'expected string'), pathe.pathToFileURL(id)) |
| 79 | + const url: URL = toUrl(id) |
93 | 80 |
|
94 | 81 | /**
|
95 | 82 | * Source code handler for {@linkcode url}.
|
|
0 commit comments