Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 0 additions & 13 deletions .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc.cjs

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Prepare repository
run: git fetch --unshallow --tags

- uses: actions/setup-node@v4
- uses: actions/setup-node@v5
with:
node-version: 20
node-version: 22
cache: 'yarn'

# allow the lock file to change (updating our own workspace versions in monorepo)
Expand All @@ -30,7 +30,7 @@ jobs:
- run: yarn test

# commit back the lock file change if it works
- uses: stefanzweifel/git-auto-commit-action@v5
- uses: stefanzweifel/git-auto-commit-action@v6
with:
commit_message: Apply yarn.lock changes

Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tasks": [
{
"type": "npm",
"script": "build:ide",
"script": "typecheck",
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
Expand Down
9 changes: 0 additions & 9 deletions .yarn/plugins/@yarnpkg/plugin-typescript.cjs

This file was deleted.

28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.1.cjs

This file was deleted.

942 changes: 942 additions & 0 deletions .yarn/releases/yarn-4.9.4.cjs

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

npmRegistries:
Expand All @@ -9,10 +13,4 @@ npmScopes:
npmAlwaysAuth: true
npmRegistryServer: "https://npm.pkg.github.com"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.6.1.cjs
yarnPath: .yarn/releases/yarn-4.9.4.cjs
61 changes: 61 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a Vite plugin that allows specifying alternate tsconfig files. **Note: This plugin is no longer necessary in MOST cases** as of Vite 7.1.5, which now supports alternate tsconfig files natively via `optimizeDeps.esbuildOptions.tsconfig`. However, it is **still necessary in monorepos that make extensive use of externalized paths**.

## Architecture

The plugin works by temporarily swapping tsconfig files:

- `src/index.ts` - Main plugin factory and configuration logic
- `src/util.ts` - Core file swapping utilities (`swapTsConfig`, `revertTsConfig`)

The plugin operates in two phases:

1. **config hook**: Backs up existing `tsconfig.json`, writes alternate config file content to `tsconfig.json`
2. **closeBundle hook**: Restores original `tsconfig.json` from backup

## Commands

### Build and Development

```bash
yarn build # Clean and build using tsup
yarn clean # Remove dist directory
yarn typecheck # Run TypeScript compiler check
```

### Code Quality

```bash
yarn lint # Run ESLint with cache
yarn lint:fix # Run ESLint with auto-fix
```

### Testing

```bash
yarn test # Currently no tests (exits 0)
```

### Release

```bash
yarn release # Create release using auto
```

## Build System

- **Bundler**: tsup (configured in `tsup.config.ts`)
- **Output**: ESM format only, with sourcemaps and TypeScript declarations
- **TypeScript**: Extends `@alienfast/tsconfig/node.json`
- **Linting**: Uses `@alienfast/eslint-config` with custom ignores

## Package Management

- Uses Yarn 4.9.4 (Berry)
- ESM-only package with proper exports configuration
- Configured for automatic releases via `auto` tool
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
![CI](https://img.shields.io/github/actions/workflow/status/alienfast/vite-plugin-tsconfig/release.yml?style=for-the-badge)
![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=for-the-badge)

# vite-plugin-tsconfig (ARCHIVED)
# vite-plugin-tsconfig

This plugin is no longer necessary. As of vite 7.1.5, the following has been tested and works:
NOTE: This plugin is no longer necessary in _MOST_ cases, but still is necessary in monorepos that make extensive use of externalized paths.

As of vite 7.1.5, the following has been tested and works for typical use cases:

```ts
optimizeDeps: {
Expand Down
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import af from '@alienfast/eslint-config'
import { defineConfig } from 'eslint/config'

/**
* Project eslint configuration.
*
* View config with `npx @eslint/config-inspector`
*/
export default defineConfig([
af.configs.recommended,
{
ignores: ['.storybook'],
},
])
61 changes: 26 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-tsconfig",
"version": "1.0.5",
"packageManager": "yarn@3.6.1",
"packageManager": "yarn@4.9.4",
"description": "Vite plugin that allows you to use alternate tsconfig files.",
"type": "module",
"main-note": "Though this is ESM only, the following main is to appease tsc and varieties of moduleResolution e.g. node vs nodenext, otherwise types aren't found. see https://github.com/rosskevin/ts-esm-workspaces/tree/bug-main-required-to-build#workaround ",
Expand All @@ -18,7 +18,7 @@
},
"scripts": {
"build": "yarn clean && tsup-node",
"build:ide": "echo 'tsc -b' && tsc -b",
"typecheck": "echo 'tsc -b' && tsc -b",
"clean": "node ./scripts/clean.js",
"clean:yarn": "node ./scripts/clean-yarn.js",
"lint": "eslint . --cache --ext .js,.ts,.tsx",
Expand Down Expand Up @@ -48,40 +48,31 @@
"vite": ">=3.1.6"
},
"devDependencies": {
"@alienfast/eslint-config": "^4.0.9",
"@alienfast/tsconfig": "^1.0.1",
"@auto-it/all-contributors": "^11.0.1",
"@auto-it/first-time-contributor": "^11.0.1",
"@auto-it/released": "^11.0.1",
"@types/marked": "^5",
"@types/marked-terminal": "^3.1.3",
"auto": "^11.0.1",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-n": "^16.0.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-storybook": "^0.6.13",
"eslint-plugin-unicorn": "^48.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"execa": "^8.0.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"@alienfast/eslint-config": "^6.0.7",
"@alienfast/tsconfig": "^1.0.4",
"@auto-it/all-contributors": "^11.3.0",
"@auto-it/first-time-contributor": "^11.3.0",
"@auto-it/released": "^11.3.0",
"@types/marked": "^6",
"@types/marked-terminal": "^6.1.1",
"auto": "^11.3.0",
"eslint": "^9.35.0",
"execa": "^9.6.0",
"husky": "^9.1.7",
"lint-staged": "^16.1.6",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.2",
"rimraf": "^5.0.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite-plugin-dts": "^3.5.2",
"vitest": "^0.34.3"
"prettier": "^3.6.2",
"rimraf": "^6.0.1",
"tsup": "^8.5.0",
"typescript": "^5.9.2",
"vite": "^7.1.5",
"vite-plugin-dts": "^4.5.4",
"vitest": "^3.2.4"
},
"auto": {
"canary": {
"target": "comment"
},
"plugins": [
"npm",
"all-contributors",
Expand All @@ -91,7 +82,7 @@
},
"dependencies": {
"@alienfast/find-monorepo-root": "^1.0.9",
"marked": "^7.0.5",
"marked-terminal": "^5.2.0"
"marked": "^16.3.0",
"marked-terminal": "^7.3.0"
}
}
1 change: 0 additions & 1 deletion scripts/clean-yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { rimraf as r } from 'rimraf'

// TODO: promote this as a script to @alienfast/ci once it is stable

// eslint-disable-next-line no-console
console.log('Cleaning yarn...')

await $`yarn tsc -b --clean`
Expand Down
1 change: 0 additions & 1 deletion scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { rimraf as r } from 'rimraf'

// TODO: promote this as a script to @alienfast/ci once it is stable

// eslint-disable-next-line no-console
console.log('Cleaning...')

await $`yarn tsc -b --clean`
Expand Down
112 changes: 112 additions & 0 deletions src/cleanup-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import fs from 'node:fs'
import path from 'node:path'

import { Logger } from 'vite'

import { TSCONFIG } from './constants.js'
import { hasBanner, performManualRestore, revertTsConfig, Swapped } from './util.js'

export interface CleanupValidationResult {
validationErrors: string[]
hasErrors: boolean
}

/**
* Manages cleanup operations for swapped tsconfig files
*/
export class CleanupManager {
constructor(private log: Logger) {}

/**
* Perform primary cleanup by reverting all swapped files
*/
public performPrimaryCleanup(swapped: Swapped[]): string[] {
const revertErrors: string[] = []

for (const swap of swapped) {
try {
revertTsConfig(swap, this.log)
} catch (revertError) {
const errorMsg = `Failed to revert tsconfig in ${swap.dir}: ${revertError}`
this.log.error(errorMsg)
revertErrors.push(errorMsg)
}
}

return revertErrors
}

/**
* Perform emergency manual cleanup for files that failed primary cleanup
*/
public performEmergencyCleanup(swapped: Swapped[]): void {
this.log.warn('Performing emergency manual cleanup')

for (const swap of swapped) {
try {
const tsconfigPath = path.resolve(swap.dir, TSCONFIG)
performManualRestore(tsconfigPath, swap.backupFilePath, this.log)
} catch (emergencyError) {
this.log.error(`Emergency cleanup failed for ${swap.dir}: ${emergencyError}`)
}
}
}

/**
* Validate that all cleanup operations were successful
*/
public validateCleanup(swapped: Swapped[]): CleanupValidationResult {
const validationErrors: string[] = []

for (const swap of swapped) {
const tsconfigPath = path.resolve(swap.dir, TSCONFIG)

// Check for generated files that weren't properly removed
if (fs.existsSync(tsconfigPath) && hasBanner(tsconfigPath)) {
validationErrors.push(`Generated tsconfig still exists at ${swap.dir}`)
}

// Check for orphaned backup files
if (swap.backupFilePath && fs.existsSync(swap.backupFilePath)) {
validationErrors.push(`Backup file still exists at ${swap.backupFilePath}`)
}
}

return {
validationErrors,
hasErrors: validationErrors.length > 0,
}
}

/**
* Perform complete cleanup with fallbacks and validation
*/
public performCompleteCleanup(swapped: Swapped[], reason: string): CleanupValidationResult {
if (swapped.length === 0) {
this.log.info('No tsconfig files to clean up')
return { validationErrors: [], hasErrors: false }
}

this.log.info(`Performing cleanup: ${reason}`)

// Primary cleanup attempt
const revertErrors = this.performPrimaryCleanup(swapped)

// Emergency cleanup if primary had errors
if (revertErrors.length > 0) {
this.performEmergencyCleanup(swapped)
}

// Final validation
const validation = this.validateCleanup(swapped)

if (validation.hasErrors) {
this.log.error('Cleanup validation failed:')
validation.validationErrors.forEach((error) => this.log.error(` - ${error}`))
} else {
this.log.info('All tsconfig files successfully restored')
}

return validation
}
}
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const TSCONFIG = 'tsconfig.json'
export const BANNER = `// GENERATED via 'vite-plugin-tsconfig' - this should be automatically created and deleted inside the build process. \n`
export const BAK = 'bak.vite-plugin-tsconfig'
Loading