Skip to content

Commit

Permalink
v3: ESM & Vite 5 [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Nov 18, 2023
1 parent f39c08f commit 148d072
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 288 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, '[publish]') }}
steps:
- uses: actions/checkout@v2
- run: yarn install --frozen-lockfile
- run: yarn prettier-ci
- run: yarn build
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun ci
- uses: ArnaudBarre/npm-publish@v1
with:
npm-token: ${{ secrets.NPM_TOKEN }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 3.0.0

- Rename named export from `tscPlugin` to `tscWatch`
- Add vite@5 and typescript@5 to peer dependency ranges
- Switch plugin to ESM. This removes the CJS warning when using the plugin with Vite 5. A CJS wrapper is still provided but [migrating](https://vitejs.dev/guide/migration.html#deprecate-cjs-node-api) to running Vite in ESM is encouraged
- Drop support for Vite 2 & 3 & node<18 (aligns with Vite 5)

## 2.0.1

Add vite@4 to peer dependency range
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ npm i -D vite-plugin-tsc-watch

```ts
import { defineConfig } from "vite";
import { tscPlugin } from "vite-plugin-tsc-watch";
import { tscWatch } from "vite-plugin-tsc-watch";

export default defineConfig({
plugins: [tscPlugin()],
plugins: [tscWatch()],
});
```

Expand Down
Binary file added bun.lockb
Binary file not shown.
34 changes: 23 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"name": "vite-plugin-tsc-watch",
"description": "Plugs tsc --watch into Vite dev server",
"version": "2.0.1",
"version": "3.0.0",
"license": "MIT",
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
"main": "dist/index.js",
"type": "module",
"main": "dist/index.cjs",
"types": "dist/index.d.mts",
"module": "dist/index.mjs",
"exports": {
".": {
"types": "./dist/index.d.mts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
}
},
"files": [
"dist"
],
Expand All @@ -16,18 +26,20 @@
"typescript"
],
"scripts": {
"build": "tsc",
"prettier": "yarn prettier-ci --write",
"prettier-ci": "prettier --check '**/*.{ts,json,md,yml}'"
"build": "rm -rf dist/ && tsc && rm dist/worker.d.mts && cp src/index.cjs dist/",
"prettier": "bun prettier-ci --write",
"prettier-ci": "prettier --check '**/*.{ts,json,md,yml}'",
"ci": "bun prettier-ci && bun run build && bun publint"
},
"peerDependencies": {
"typescript": "^4",
"vite": "^2 || ^3 || ^4"
"typescript": "^4 || ^5",
"vite": "^4 || ^5"
},
"devDependencies": {
"@types/node": "^18.11.12",
"prettier": "^2.8.1",
"typescript": "^4.9.4",
"vite": "^4.0.0"
"@types/node": "^18.18.9",
"publint": "^0.2.5",
"prettier": "3.0.3",
"typescript": "^5.2.2",
"vite": "^5.0.0"
}
}
3 changes: 3 additions & 0 deletions src/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.tscWatch = async function tscWatch(options) {
return (await import("./index.mjs")).tscWatch(options);
};
21 changes: 21 additions & 0 deletions src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Worker } from "node:worker_threads";
import { resolve } from "node:path";
import type { Plugin } from "vite";
import { dirname } from "path";
import { fileURLToPath } from "url";

let started = false;

export function tscWatch(): Plugin {
return {
name: "tsc",
apply: "serve",
configureServer: async () => {
if (started) return;
new Worker(
resolve(dirname(fileURLToPath(import.meta.url)), "./worker.mjs"),
);
started = true;
},
};
}
17 changes: 0 additions & 17 deletions src/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/worker.ts → src/worker.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { relative } from "path";
import { relative } from "node:path";
import { createWatchCompilerHost, createWatchProgram, sys } from "typescript";

createWatchProgram(
Expand Down
20 changes: 9 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"include": ["src"],
"compilerOptions": {
/* Target node 14 */
"module": "CommonJS",
"lib": ["ES2020"],
"target": "ES2020",
/* Target node 18 */
"module": "NodeNext",
"lib": ["ES2021"],
"target": "ES2021",
"declaration": true,
"outDir": "dist",
"skipLibCheck": true,

/* Imports */
"moduleResolution": "node", // Allow `index` imports
"resolveJsonModule": true, // Allow json import
"forceConsistentCasingInFileNames": true, // Avoid difference in case between file name and import
"esModuleInterop": true, // Allow import fs from "fs"
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"verbatimModuleSyntax": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": true
"useUnknownInCatchVariables": true,
"noPropertyAccessFromIndexSignature": true
}
}
Loading

0 comments on commit 148d072

Please sign in to comment.