Skip to content

Commit 4dbc19d

Browse files
committed
refactor(lib): [relative] drop partial url support
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 6b8a3be commit 4dbc19d

File tree

7 files changed

+25
-37
lines changed

7 files changed

+25
-37
lines changed

src/interfaces/platform-path.mts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import type dot from '#lib/dot'
77
import type resolveWith from '#lib/resolve-with'
8-
import type toPath from '#lib/to-path'
98
import type {
109
Delimiter,
1110
EmptyString,
@@ -245,29 +244,26 @@ interface PlatformPath {
245244
* If a zero-length string is passed as `from` or `to`, the current working
246245
* directory will be used instead of the zero-length strings.
247246
*
248-
* > 👉 **Note**: If `from` or `to` is a {@linkcode URL}, or can be parsed to
249-
* > a `URL`, they'll be converted to paths using {@linkcode toPath}.
250-
*
251247
* @see {@linkcode RelativeOptions}
252248
*
253249
* @category
254250
* core
255251
*
256252
* @this {void}
257253
*
258-
* @param {URL | string[] | string} from
259-
* Start path, path segments, or URL
260-
* @param {URL | string[] | string} to
261-
* Destination path, path segments, or URL
254+
* @param {string[] | string} from
255+
* Start path or path segments
256+
* @param {string[] | string} to
257+
* Destination path or path segments
262258
* @param {RelativeOptions | null | undefined} [options]
263259
* Relative path generation options
264260
* @return {string}
265261
* Relative path from `from` to `to`
266262
*/
267263
relative(
268264
this: void,
269-
from: URL | string[] | string,
270-
to: URL | string[] | string,
265+
from: string[] | string,
266+
to: string[] | string,
271267
options?: RelativeOptions | null | undefined
272268
): string
273269

src/lib/__tests__/relative.spec.mts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file Unit Tests - relative
33
* @module pathe/lib/tests/unit/relative
4-
* @see https://github.com/nodejs/node/blob/v23.2.0/test/parallel/test-path-relative.js
4+
* @see https://github.com/nodejs/node/blob/v23.4.0/test/parallel/test-path-relative.js
55
*/
66

77
import process from '#internal/process'
@@ -13,7 +13,7 @@ import { posix, win32 } from 'node:path'
1313

1414
describe('unit:lib/relative', () => {
1515
describe('posix', () => {
16-
it.each<[URL | string, URL | string]>([
16+
it.each<[string, string]>([
1717
['', ''],
1818
['/Users/a/web/b/test/mails', '/Users/a/web/b'],
1919
['/baz', '/baz-quux'],
@@ -30,7 +30,6 @@ describe('unit:lib/relative', () => {
3030
['/var/lib', '/var'],
3131
['/var/lib', '/var/apache'],
3232
['/var/lib', '/var/lib'],
33-
['file:///package.json', new URL('file:///test/index.mjs')],
3433
[posix.sep, '/foo'],
3534
[posix.sep, '/var/lib']
3635
])('should return relative path (%j, %j)', (from, to) => {
@@ -47,7 +46,7 @@ describe('unit:lib/relative', () => {
4746
vi.spyOn(process, 'cwd').mockImplementation(cwdWindows)
4847
})
4948

50-
it.each<[URL | string, URL | string]>([
49+
it.each<[string, string]>([
5150
['C:\\', 'C:\\foo'],
5251
['C:\\baz', 'C:\\baz-quux'],
5352
['C:\\baz', '\\\\foo\\bar\\baz'],

src/lib/__tests__/resolve-with.spec.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file Unit Tests - resolveWith
33
* @module pathe/lib/tests/unit/resolveWith
4-
* @see https://github.com/nodejs/node/blob/v23.2.0/test/parallel/test-path-resolve.js
4+
* @see https://github.com/nodejs/node/blob/v23.4.0/test/parallel/test-path-resolve.js
55
*/
66

77
import DRIVE from '#fixtures/drive'

src/lib/relative.mts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
*/
55

66
import { DRIVE_PATH_REGEX } from '#internal/constants'
7-
import validateURLString from '#internal/validate-url-string'
7+
import validateString from '#internal/validate-string'
88
import dot from '#lib/dot'
99
import isSep from '#lib/is-sep'
1010
import resolveWith from '#lib/resolve-with'
1111
import sep from '#lib/sep'
12-
import toPath from '#lib/to-path'
1312
import type { RelativeOptions } from '@flex-development/pathe'
1413

1514
export default relative
@@ -24,40 +23,32 @@ export default relative
2423
* If a zero-length string is passed as `from` or `to`, the current working
2524
* directory will be used instead of the zero-length strings.
2625
*
27-
* > 👉 **Note**: If `from` or `to` is a {@linkcode URL}, or can be parsed to a
28-
* > `URL`, they'll be converted to paths using {@linkcode toPath}.
29-
*
3026
* @see {@linkcode RelativeOptions}
3127
*
28+
* @todo url support
29+
*
3230
* @category
3331
* core
3432
*
3533
* @this {void}
3634
*
37-
* @param {URL | string[] | string} from
38-
* Start path, path segments, or URL
39-
* @param {URL | string[] | string} to
40-
* Destination path, path segments, or URL
35+
* @param {string[] | string} from
36+
* Start path or path segments
37+
* @param {string[] | string} to
38+
* Destination path or path segments
4139
* @param {RelativeOptions | null | undefined} [options]
4240
* Relative path generation options
4341
* @return {string}
4442
* Relative path from `from` to `to`
4543
*/
4644
function relative(
4745
this: void,
48-
from: URL | string[] | string,
49-
to: URL | string[] | string,
46+
from: string[] | string,
47+
to: string[] | string,
5048
options?: RelativeOptions | null | undefined
5149
): string {
52-
if (!Array.isArray(from)) {
53-
validateURLString(from, 'from')
54-
from = toPath(from)
55-
}
56-
57-
if (!Array.isArray(to)) {
58-
validateURLString(to, 'to')
59-
to = toPath(to)
60-
}
50+
if (!Array.isArray(from)) validateString(from, 'from')
51+
if (!Array.isArray(to)) validateString(to, 'to')
6152

6253
if (from === to) return ''
6354

src/lib/resolve-with.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import type { Cwd, ResolveWithOptions } from '@flex-development/pathe'
3636
*
3737
* @see {@linkcode ResolveWithOptions}
3838
*
39+
* @todo url support
40+
*
3941
* @category
4042
* utils
4143
*

src/types/__tests__/ext.spec-d.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @module pathe/types/tests/unit-d/Ext
44
*/
55

6+
import type TestSubject from '#types/ext'
67
import type { Dot } from '@flex-development/pathe'
7-
import type TestSubject from '../ext'
88

99
describe('unit-d:types/Ext', () => {
1010
it('should equal `${Dot}${string}`', () => {

tsconfig.typecheck.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"include": [
1818
"__fixtures__/**/*",
1919
"__tests__/**/*",
20-
"src/**.mts",
20+
"src/**/**.mts",
2121
"typings/**/*",
2222
"vitest-env.d.mts"
2323
]

0 commit comments

Comments
 (0)