-
Notifications
You must be signed in to change notification settings - Fork 134
fix(migrate): auto-remove esModuleInterop: false from tsconfig.json #1148
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
Open
fengmk2
wants to merge
4
commits into
bun-pm
Choose a base branch
from
auto-remove-esModuleInterop-false-on-migrate
base: bun-pm
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+369
−8
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32dd357
fix(migrate): auto-remove esModuleInterop: false from tsconfig.json
fengmk2 6dab059
test(migrate): add edge case tests with inline snapshots
fengmk2 59afddb
refactor(migrate): remove redundant comment on cleanupDeprecatedTscon…
fengmk2 013eea9
Update packages/cli/src/migration/migrator.ts
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
5 changes: 5 additions & 0 deletions
5
packages/cli/snap-tests-global/migration-tsconfig-esmoduleinterop/package.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "devDependencies": { | ||
| "vite": "latest" | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
packages/cli/snap-tests-global/migration-tsconfig-esmoduleinterop/snap.txt
This file contains hidden or 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,46 @@ | ||
| > vp migrate --no-interactive # should remove esModuleInterop: false from tsconfig.json | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| ◇ Migrated . to Vite+<repeat> | ||
| • Node <semver> pnpm <semver> | ||
| • 3 config updates applied | ||
| ! Warnings: | ||
| - Removed `"esModuleInterop": false` from tsconfig.json — this option has been deprecated. See https://github.com/oxc-project/tsgolint/issues/351, https://github.com/microsoft/TypeScript/issues/62529 | ||
|
|
||
| > cat tsconfig.json # verify esModuleInterop: false is removed | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "module": "ESNext", | ||
| "allowSyntheticDefaultImports": true, | ||
| "strict": true | ||
| } | ||
| } | ||
|
|
||
| > cat vite.config.ts # check vite.config.ts | ||
| import { defineConfig } from 'vite-plus'; | ||
|
|
||
| export default defineConfig({ | ||
| staged: { | ||
| "*": "vp check --fix" | ||
| }, | ||
| lint: {"options":{"typeAware":true,"typeCheck":true}}, | ||
| }); | ||
|
|
||
| > cat package.json # check package.json | ||
| { | ||
| "devDependencies": { | ||
| "vite": "npm:@voidzero-dev/vite-plus-core@latest", | ||
| "vite-plus": "latest" | ||
| }, | ||
| "pnpm": { | ||
| "overrides": { | ||
| "vite": "npm:@voidzero-dev/vite-plus-core@latest", | ||
| "vitest": "npm:@voidzero-dev/vite-plus-test@latest" | ||
| } | ||
| }, | ||
| "packageManager": "pnpm@<semver>", | ||
| "scripts": { | ||
| "prepare": "vp config" | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
packages/cli/snap-tests-global/migration-tsconfig-esmoduleinterop/steps.json
This file contains hidden or 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,8 @@ | ||
| { | ||
| "commands": [ | ||
| "vp migrate --no-interactive # should remove esModuleInterop: false from tsconfig.json", | ||
| "cat tsconfig.json # verify esModuleInterop: false is removed", | ||
| "cat vite.config.ts # check vite.config.ts", | ||
| "cat package.json # check package.json" | ||
| ] | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/cli/snap-tests-global/migration-tsconfig-esmoduleinterop/tsconfig.json
This file contains hidden or 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,9 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "module": "ESNext", | ||
| "esModuleInterop": false, | ||
| "allowSyntheticDefaultImports": true, | ||
| "strict": true | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,205 @@ | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { findTsconfigFiles, removeEsModuleInteropFalseFromFile } from '../tsconfig.js'; | ||
|
|
||
| describe('findTsconfigFiles', () => { | ||
| let tmpDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tsconfig-test-')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('finds all tsconfig variants', () => { | ||
| fs.writeFileSync(path.join(tmpDir, 'tsconfig.json'), '{}'); | ||
| fs.writeFileSync(path.join(tmpDir, 'tsconfig.app.json'), '{}'); | ||
| fs.writeFileSync(path.join(tmpDir, 'tsconfig.node.json'), '{}'); | ||
| fs.writeFileSync(path.join(tmpDir, 'tsconfig.build.json'), '{}'); | ||
| fs.writeFileSync(path.join(tmpDir, 'other.json'), '{}'); | ||
| fs.writeFileSync(path.join(tmpDir, 'package.json'), '{}'); | ||
|
|
||
| const files = findTsconfigFiles(tmpDir); | ||
| const expected = [ | ||
| path.join(tmpDir, 'tsconfig.app.json'), | ||
| path.join(tmpDir, 'tsconfig.build.json'), | ||
| path.join(tmpDir, 'tsconfig.json'), | ||
| path.join(tmpDir, 'tsconfig.node.json'), | ||
| ]; | ||
| expect(new Set(files)).toEqual(new Set(expected)); | ||
| expect(files).toHaveLength(4); | ||
| }); | ||
|
|
||
| it('returns empty array for non-existent directory', () => { | ||
| expect(findTsconfigFiles('/non-existent-dir-12345')).toEqual([]); | ||
| }); | ||
|
|
||
| it('returns empty array when no tsconfig files exist', () => { | ||
| fs.writeFileSync(path.join(tmpDir, 'package.json'), '{}'); | ||
| expect(findTsconfigFiles(tmpDir)).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('removeEsModuleInteropFalseFromFile', () => { | ||
| let tmpDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tsconfig-test-')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function writeAndRemove(filePath: string, content: string): string { | ||
| fs.writeFileSync(filePath, content); | ||
| const result = removeEsModuleInteropFalseFromFile(filePath); | ||
| expect(result).toBe(true); | ||
| return fs.readFileSync(filePath, 'utf-8'); | ||
| } | ||
|
|
||
| it('removes esModuleInterop: false (middle property)', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| expect( | ||
| writeAndRemove( | ||
| filePath, | ||
| `{ | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "esModuleInterop": false, | ||
| "strict": true | ||
| } | ||
| }`, | ||
| ), | ||
| ).toMatchInlineSnapshot(` | ||
| "{ | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "strict": true | ||
| } | ||
| }" | ||
| `); | ||
| }); | ||
|
|
||
| it('preserves comments in JSONC', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| expect( | ||
| writeAndRemove( | ||
| filePath, | ||
| `{ | ||
| // This is a comment | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "esModuleInterop": false, | ||
| /* block comment */ | ||
| "strict": true | ||
| } | ||
| }`, | ||
| ), | ||
| ).toMatchInlineSnapshot(` | ||
| "{ | ||
| // This is a comment | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| /* block comment */ | ||
| "strict": true | ||
| } | ||
| }" | ||
| `); | ||
| }); | ||
|
|
||
| it('handles esModuleInterop: false as last property', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| expect( | ||
| writeAndRemove( | ||
| filePath, | ||
| `{ | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "esModuleInterop": false | ||
| } | ||
| }`, | ||
| ), | ||
| ).toMatchInlineSnapshot(` | ||
| "{ | ||
| "compilerOptions": { | ||
| "target": "ES2023" | ||
| } | ||
| }" | ||
| `); | ||
| }); | ||
|
|
||
| it('handles inline block comment next to esModuleInterop: false', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| expect( | ||
| writeAndRemove( | ||
| filePath, | ||
| `{ | ||
| "compilerOptions": { | ||
| "target": "ES2023", | ||
| "esModuleInterop": false /* reason */, | ||
| "strict": true | ||
| } | ||
| }`, | ||
| ), | ||
| ).toMatchInlineSnapshot(` | ||
| "{ | ||
| "compilerOptions": { | ||
| "target": "ES2023" /* reason */, | ||
| "strict": true | ||
| } | ||
| }" | ||
| `); | ||
| }); | ||
|
|
||
| it('handles compact single-line JSON', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| expect( | ||
| writeAndRemove(filePath, '{"compilerOptions":{"esModuleInterop": false, "strict": true}}'), | ||
| ).toMatchInlineSnapshot(`"{"compilerOptions":{"strict": true}}"`); | ||
| }); | ||
|
|
||
| it('handles compact single-line JSONC with spaces', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| expect( | ||
| writeAndRemove( | ||
| filePath, | ||
| '{ "compilerOptions": { "esModuleInterop": false, "strict": true } }', | ||
| ), | ||
| ).toMatchInlineSnapshot(`"{ "compilerOptions": {"strict": true } }"`); | ||
| }); | ||
|
|
||
| it('leaves esModuleInterop: true untouched', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| const original = JSON.stringify({ compilerOptions: { esModuleInterop: true } }, null, 2); | ||
| fs.writeFileSync(filePath, original); | ||
|
|
||
| const result = removeEsModuleInteropFalseFromFile(filePath); | ||
| expect(result).toBe(false); | ||
| expect(fs.readFileSync(filePath, 'utf-8')).toBe(original); | ||
| }); | ||
|
|
||
| it('returns false for non-existent file', () => { | ||
| expect(removeEsModuleInteropFalseFromFile('/non-existent-file.json')).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when no compilerOptions', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| fs.writeFileSync(filePath, '{}'); | ||
|
|
||
| expect(removeEsModuleInteropFalseFromFile(filePath)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when esModuleInterop is not present', () => { | ||
| const filePath = path.join(tmpDir, 'tsconfig.json'); | ||
| fs.writeFileSync(filePath, JSON.stringify({ compilerOptions: { strict: true } }, null, 2)); | ||
|
|
||
| expect(removeEsModuleInteropFalseFromFile(filePath)).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.