Skip to content

Commit 2adf524

Browse files
committed
feat: support URLs in cwd option
1 parent 096a5b6 commit 2adf524

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/settings.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as assert from 'node:assert';
2+
import { pathToFileURL } from 'node:url';
23

34
import { describe, it } from 'mocha';
45

@@ -66,4 +67,12 @@ describe('Settings', () => {
6667

6768
assert.strictEqual(settings.fs.readdirSync, customReaddirSync);
6869
});
70+
71+
it('should transform URL to string on cwd', () => {
72+
const settings = new Settings({
73+
cwd: new URL(pathToFileURL(process.cwd())),
74+
});
75+
76+
assert.ok(typeof settings.cwd === 'string');
77+
});
6978
});

src/settings.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'node:fs';
2+
import { fileURLToPath } from 'node:url';
23

34
import type { FileSystemAdapter, Pattern } from './types';
45

@@ -42,7 +43,7 @@ export interface Options {
4243
*
4344
* @default process.cwd()
4445
*/
45-
cwd?: string;
46+
cwd?: string | URL;
4647
/**
4748
* Specifies the maximum depth of a read directory relative to the start
4849
* directory.
@@ -176,7 +177,7 @@ export default class Settings {
176177
this.baseNameMatch = options.baseNameMatch ?? false;
177178
this.braceExpansion = options.braceExpansion ?? true;
178179
this.caseSensitiveMatch = options.caseSensitiveMatch ?? true;
179-
this.cwd = options.cwd ?? process.cwd();
180+
this.cwd = options.cwd instanceof URL ? fileURLToPath(options.cwd) : options.cwd ?? process.cwd();
180181
this.deep = options.deep ?? Number.POSITIVE_INFINITY;
181182
this.dot = options.dot ?? false;
182183
this.extglob = options.extglob ?? true;

src/tests/e2e/runner.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable mocha/no-setup-in-describe */
22
import * as assert from 'node:assert';
3+
import { fileURLToPath } from 'node:url';
34

4-
import * as snapshotIt from 'snap-shot-it';
5+
import snapshotIt from 'snap-shot-it';
56
import { describe, it } from 'mocha';
67

78
import * as fg from '../..';
@@ -95,8 +96,9 @@ function getTestPatterns(test: Test): Pattern[] {
9596

9697
function getTestTitle(test: Test): string {
9798
// Replacing placeholders to hide absolute paths from snapshots.
99+
const cwd = test.options?.cwd instanceof URL ? fileURLToPath(test.options.cwd) : test.options?.cwd;
98100
const replacements = {
99-
cwd: test.options?.cwd?.replace(CWD, '<root>'),
101+
cwd: cwd?.replace(CWD, '<root>'),
100102
ignore: test.options?.ignore?.map((pattern) => pattern.replace(CWD, '<root>')),
101103
};
102104

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"noFallthroughCasesInSwitch": true,
2121

2222
"forceConsistentCasingInFileNames": true,
23+
"esModuleInterop": true,
2324
"verbatimModuleSyntax": false,
2425

2526
"downlevelIteration": true,

0 commit comments

Comments
 (0)