Skip to content

Commit 31cdd14

Browse files
lint(oxlint): forbid node:path in favor of pathe
`node:path` returns OS-native separators, which breaks any path that ends up embedded in a module specifier, generated source, or compared against Vite's normalized watcher paths — the Windows unit-test regression in #183 was the latest example. `pathe` is a drop-in replacement that always emits forward slashes; we already use it throughout the source. Add an oxlint `no-restricted-imports` rule that flags `node:path` (and bare `path`) and points violators at pathe. Explicit format work is still allowed via `node:path/win32` or `node:path/posix`. Migrate all 145 remaining imports to `pathe` and add the dep to the five packages/playgrounds that didn't already have it.
1 parent 680a55f commit 31cdd14

152 files changed

Lines changed: 181 additions & 146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.oxlintrc.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@
163163
"no-prototype-builtins": "error",
164164
"no-redeclare": "error",
165165
"no-regex-spaces": "error",
166+
"no-restricted-imports": [
167+
"error",
168+
{
169+
"paths": [
170+
{
171+
"name": "node:path",
172+
"message": "Use `pathe` instead. It re-exports the same API but always emits forward slashes, which avoids cross-platform breakage when paths are embedded in module specifiers, generated source, or compared against Vite's normalized watcher events. If you genuinely need format-specific behavior, import `node:path/win32` or `node:path/posix` explicitly."
173+
},
174+
{
175+
"name": "path",
176+
"message": "Use `pathe` instead of the unprefixed `path` import (and prefer `node:path/win32` / `node:path/posix` for explicit format-specific behavior)."
177+
}
178+
]
179+
}
180+
],
166181
"no-self-assign": "error",
167182
"no-setter-return": "error",
168183
"no-shadow-restricted-names": "error",

‎packages/create-void/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"devDependencies": {
1717
"@clack/prompts": "catalog:",
1818
"@types/node": "catalog:",
19+
"pathe": "catalog:",
1920
"picocolors": "^1.1.1",
2021
"tsdown": "catalog:"
2122
}

‎packages/create-void/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

33
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
4-
import { resolve } from 'node:path';
54
import * as p from '@clack/prompts';
5+
import { resolve } from 'pathe';
66
import pc from 'picocolors';
77
import { detectPM, pmExec, pmInstall, run } from './pm.ts';
88

‎packages/md/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"markdown-it-attrs": "^4.3.1",
4343
"markdown-it-container": "^4.0.0",
4444
"markdown-it-emoji": "^3.0.0",
45+
"pathe": "catalog:",
4546
"shiki": "^4.0.2",
4647
"tinyglobby": "^0.2.16"
4748
},

‎packages/md/src/plugin.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createHash } from 'node:crypto';
22
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
3-
import { dirname, join, relative, resolve } from 'node:path';
3+
import { dirname, join, relative, resolve } from 'pathe';
44
import { glob } from 'tinyglobby';
55
import { normalizePath, type Plugin, type ResolvedConfig, type ViteDevServer } from 'vite';
66
import { generateMdTypes } from './codegen/md-types.ts';

‎packages/md/src/plugins/snippet.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync, readFileSync, statSync } from 'node:fs';
2-
import { resolve, dirname } from 'node:path';
32
import type MarkdownExit from 'markdown-exit';
43
import type { RuleBlock, Token } from 'markdown-exit';
4+
import { resolve, dirname } from 'pathe';
55

66
const rawPathRegexp =
77
/^(.+?(?:(?:\.([a-z0-9]+))?))(?:(#[\w-]+))?(?: ?(?:\{(\d+(?:[,-]\d+)*)? ?(\S+)? ?(\S+)?}))? ?(?:\[(.+)\])?$/;

‎packages/md/test/integration/markdown-blog.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execSync } from 'node:child_process';
2-
import { join } from 'node:path';
32
import spawn from 'cross-spawn';
3+
import { join } from 'pathe';
44
import { chromium, type Browser, type Page } from 'playwright';
55
import { describe, expect, it, beforeAll, afterAll } from 'vitest';
66
import { getPort, waitForServer, killChild } from '../../../../test/integration-helpers.ts';

‎packages/md/test/unit/md-types.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
22
import { tmpdir } from 'node:os';
3-
import { join } from 'node:path';
3+
import { join } from 'pathe';
44
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
55
import { generateMdTypes } from '../../src/codegen/md-types.ts';
66

‎packages/react/src/plugin-islands.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync, readFileSync } from 'node:fs';
2-
import { dirname, resolve, relative } from 'node:path';
2+
import { dirname, resolve, relative } from 'pathe';
33
import { normalizePath, type Plugin, type ResolvedConfig } from 'vite';
44
import { scanPages, resolveEffectiveLayoutChain } from 'void/pages';
55
import type { PageScanResult } from 'void/pages';

‎packages/react/src/plugin-pages.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync, readdirSync } from 'node:fs';
2-
import { dirname } from 'node:path';
2+
import { dirname } from 'pathe';
33
import type { Plugin, ResolvedConfig } from 'vite';
44
import { resolveStaticPageDataBuildOptions, scanPages } from 'void/pages';
55
import type { PageScanResult, StaticPageDataBuildOptions } from 'void/pages';

0 commit comments

Comments
 (0)