-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from NullVoxPopuli/add-option-to-remove-all-ref…
…erences Add option to remove all references
- Loading branch information
Showing
6 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import crypto from 'node:crypto'; | ||
import fs from 'node:fs/promises'; | ||
import os from 'node:os'; | ||
import path from 'node:path'; | ||
|
||
import { stripIndent } from 'common-tags'; | ||
import { describe, expect as hardAssert, test } from 'vitest'; | ||
|
||
import { fixBadDeclarationOutput } from './index.js'; | ||
|
||
const expect = hardAssert.soft; | ||
|
||
async function mkdirp() { | ||
const tmpDir = os.tmpdir(); | ||
const tmpPath = path.join(tmpDir, 'fix-bad-declaration-output'); | ||
const suffix = crypto.randomBytes(16).toString('hex').slice(0, 16); | ||
const fullPath = path.join(tmpPath, `test-${suffix}`); | ||
|
||
await fs.mkdir(fullPath, { recursive: true }); | ||
|
||
return fullPath; | ||
} | ||
|
||
async function read(filePath: string) { | ||
let buffer = await fs.readFile(filePath); | ||
|
||
return buffer.toString(); | ||
} | ||
|
||
describe('fixBadDeclarationOutput', () => { | ||
test('it works', async () => { | ||
let tmp = await mkdirp(); | ||
|
||
let a = path.join(tmp, 'a.d.ts'); | ||
|
||
await fs.writeFile( | ||
a, | ||
stripIndent` | ||
/// <reference types="@glint/whatever/module"> | ||
/// <reference types="node_modules/@glint/whatever2/module"> | ||
/// <reference types="xyz"> | ||
export declare const two: number; | ||
` | ||
); | ||
|
||
await fixBadDeclarationOutput(`${tmp}/**/*.d.ts`, [['TypeScript#56571', { types: 'all' }]], { | ||
log: true, | ||
}); | ||
|
||
let aContents = await read(a); | ||
|
||
expect(aContents).toBe(`export declare const two: number;`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { issues } from './fixes/index.js'; | ||
|
||
export type IssuesMap = typeof issues; | ||
export type Issue = keyof IssuesMap; | ||
export type IssueFunction = IssuesMap[Issue]; | ||
|
||
export type FixerPair<Key extends Issue> = [Key, IssuesMap[Key]]; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type Fixes = (Issue | FixerPair<any>)[]; |