feat(create-eslint-config): implement setup wizard#51
feat(create-eslint-config): implement setup wizard#51hanna-skryl wants to merge 3 commits intomainfrom
Conversation
| describe('collectAllDeps', () => { | ||
| it('should merge dependencies, devDependencies, and peerDependencies', () => { | ||
| const deps = collectAllDeps({ | ||
| dependencies: { a: '1' }, | ||
| devDependencies: { b: '2' }, | ||
| peerDependencies: { c: '3' }, | ||
| }); | ||
| expect([...deps].toSorted()).toEqual(['a', 'b', 'c']); | ||
| }); | ||
|
|
||
| it('should return an empty set for null input', () => { | ||
| expect(collectAllDeps(null).size).toBe(0); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I'd add a test case for duplicate packages. It's quite common to have the same package in devDependencies (for local development) and peerDependencies (for publishing).
| describe('readJsonFile', () => { | ||
| test('should parse a valid JSON file', async ({ tmp }) => { | ||
| const filePath = path.join(tmp, 'pkg.json'); | ||
| await writeFile(filePath, JSON.stringify({ name: 'foo' })); | ||
| await expect(readJsonFile(filePath)).resolves.toEqual({ name: 'foo' }); | ||
| }); | ||
|
|
||
| test('should return null for a missing file', async ({ tmp }) => { | ||
| await expect( | ||
| readJsonFile(path.join(tmp, 'missing.json')), | ||
| ).resolves.toBeNull(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I'd add a test case for an existing file with invalid JSON.
| const manager = await detectPackageManager(targetDir); | ||
| logInfo(`Installing dependencies with ${manager}...`, ''); | ||
| try { | ||
| await installDependencies(targetDir); | ||
| } catch (error) { |
There was a problem hiding this comment.
The detectPackageManager function is called twice - once here and once in installDependencies.
| /** | ||
| * Vitest test with a per-test `tmp` fixture: a fresh temporary directory | ||
| * that is automatically removed when the test settles. | ||
| */ | ||
| export const test = baseTest.extend<{ tmp: string }>({ | ||
| tmp: async ({ task: _task }, use) => { | ||
| const dir = await mkdtemp(path.join(tmpdir(), 'create-eslint-config-')); | ||
| await use(dir); | ||
| await rm(dir, { recursive: true, force: true }); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
I didn't know Vitest had this feature, very cool. 👍
But why not use the recommended builder pattern? 🤔
| }, | ||
| "homepage": "https://github.com/code-pushup/eslint-config/tree/main/packages/create-eslint-config#readme", | ||
| "dependencies": { | ||
| "@inquirer/prompts": "^8.4.1", |
There was a problem hiding this comment.
Although this doesn't happen in CI, I get lint errors locally, even after removing node_modules and re-installing.
29:5 error The version specifier does not contain the installed version of "@inquirer/prompts" package: 7.10.1 @nx/dependency-checks
I think it's because @inquirer/prompts isn't installed in the monorepo root.
Partially addresses #47
Summary
@code-pushup/eslint-config, triggered vianpm init @code-pushup/eslint-configor imported programmaticallyeslint.config.mjs(or.jsfortype: "module"projects) with preset inheritance--yes,--configs,--tsconfig,--node-version-source,--node-version, and--dry-runCLI flagsNote
Merging into existing
eslint.config.*files is not yet implemented. The wizard prints a snippet for the user to paste manually. HandlingdefineConfigandtseslint.configwrappers will ship in a follow-up. Relevant code is marked with TODO comments.