Skip to content

Fix issue when require()-ing packages that resolve to paths containing # #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow tests to create symlinks
  • Loading branch information
thecrypticace committed Feb 26, 2025
commit dae553ddcdfeb083b825a8865d49bd6ac04b3d5d
17 changes: 16 additions & 1 deletion packages/tailwindcss-language-server/src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface TestUtils {

export interface Storage {
/** A list of files and their content */
[filePath: string]: string | Uint8Array
[filePath: string]: string | Uint8Array | { [IS_A_SYMLINK]: true; filepath: string }
}

export interface TestConfig<Extras extends {}> {
Expand Down Expand Up @@ -69,6 +69,14 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {
}
}

const IS_A_SYMLINK = Symbol('is-a-symlink')
export const symlinkTo = function (filepath: string) {
return {
[IS_A_SYMLINK]: true as const,
filepath,
}
}

async function prepareFileSystem(base: string, storage: Storage) {
// Create a temporary directory to store the test files
await fs.mkdir(base, { recursive: true })
Expand All @@ -77,6 +85,13 @@ async function prepareFileSystem(base: string, storage: Storage) {
for (let [filepath, content] of Object.entries(storage)) {
let fullPath = path.resolve(base, filepath)
await fs.mkdir(path.dirname(fullPath), { recursive: true })

if (typeof content === 'object' && IS_A_SYMLINK in content) {
let target = path.resolve(base, content.filepath)
await fs.symlink(target, fullPath)
continue
}

await fs.writeFile(fullPath, content, { encoding: 'utf-8' })
}
}
Expand Down