Skip to content

Commit 155d771

Browse files
authored
build!: drop support for cjs usage (#452)
1 parent f098566 commit 155d771

File tree

9 files changed

+41
-112
lines changed

9 files changed

+41
-112
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,8 @@ jobs:
113113
- name: Test unit
114114
run: pnpm run test-unit
115115

116-
- name: Test serve (ESM)
116+
- name: Test serve
117117
run: pnpm run test-serve
118118

119-
- name: Test build (ESM)
119+
- name: Test build
120120
run: pnpm run test-build
121-
122-
- name: Test serve (CJS)
123-
if: ${{ matrix.node_version == 18 && matrix.os == 'ubuntu-latest' }}
124-
run: pnpm run test-serve-cjs
125-
126-
- name: Test build (CJS)
127-
if: ${{ matrix.node_version == 18 && matrix.os == 'ubuntu-latest' }}
128-
run: pnpm run test-build-cjs

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
1616
"test": "pnpm test-unit && pnpm test-serve && pnpm test-build",
1717
"test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
18-
"test-build-cjs": "VITEST_TEST_CJS=1 pnpm run test-build",
1918
"test-knip": "knip",
2019
"test-serve": "vitest run -c vitest.config.e2e.ts",
21-
"test-serve-cjs": "VITEST_TEST_CJS=1 pnpm run test-serve",
2220
"test-unit": "vitest run",
2321
"test-unit:watch": "vitest",
2422
"type-check": "pnpm -r --parallel --filter \"vite-plugin-checker\" exec tsc --noEmit"

packages/vite-plugin-checker/package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717
"author": "fi3ework <fi3ework@gmail.com>",
1818
"type": "module",
1919
"exports": {
20-
".": {
21-
"import": "./dist/esm/main.js",
22-
"require": "./dist/cjs/main.cjs"
23-
}
20+
".": "./dist/main.js"
2421
},
25-
"main": "./dist/cjs/main.cjs",
26-
"types": "./dist/cjs/main.d.cts",
22+
"main": "./dist/main.js",
23+
"types": "./dist/main.d.ts",
2724
"files": [
2825
"dist",
2926
"!dist/checkers/vueTsc/typescript-vue-tsc"
3027
],
3128
"scripts": {
32-
"build": "tsup && node ../../scripts/patchCjs.mjs",
29+
"build": "tsup",
3330
"build:test": "tsup --sourcemap inline",
3431
"clean": "rimraf dist",
3532
"dev": "tsup --watch"
@@ -38,10 +35,10 @@
3835
"@babel/code-frame": "^7.26.2",
3936
"chokidar": "^3.6.0",
4037
"colorette": "^2.0.20",
41-
"npm-run-path": "^4.0.1",
42-
"strip-ansi": "^6.0.1",
38+
"npm-run-path": "^6.0.0",
39+
"strip-ansi": "^7.1.0",
4340
"tiny-invariant": "^1.3.3",
44-
"tinyglobby": "^0.2.10",
41+
"tinyglobby": "^0.2.11",
4542
"vscode-uri": "^3.1.0"
4643
},
4744
"devDependencies": {

packages/vite-plugin-checker/src/client/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,5 @@ export const WS_CHECKER_ERROR_EVENT = 'vite-plugin-checker:error'
2828
export const WS_CHECKER_RECONNECT_EVENT = 'vite-plugin-checker:reconnect'
2929
// #endregion
3030

31-
export const runtimeSourceFilePath = import.meta.url.endsWith('.ts')
32-
? // for development only, maybe should use NODE_ENV to distinguish
33-
_require.resolve('../@runtime/main.js')
34-
: _require.resolve('../../@runtime/main.js')
31+
export const runtimeSourceFilePath = _require.resolve('../@runtime/main.js')
3532
export const runtimeCode = `${fs.readFileSync(runtimeSourceFilePath, 'utf-8')};`

packages/vite-plugin-checker/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawn } from 'node:child_process'
22
import * as colors from 'colorette'
3-
import npmRunPath from 'npm-run-path'
3+
import { type ProcessEnv, npmRunPathEnv } from 'npm-run-path'
44

55
import type { ConfigEnv, Logger, Plugin } from 'vite'
66
import { Checker } from './Checker.js'
@@ -154,7 +154,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
154154
// run a bin command in a separated process
155155
if (!isProduction || !enableBuild) return
156156

157-
const localEnv = npmRunPath.env({
157+
const localEnv = npmRunPathEnv({
158158
env: process.env,
159159
cwd: process.cwd(),
160160
execPath: process.execPath,
@@ -233,7 +233,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
233233
function spawnChecker(
234234
checker: ServeAndBuildChecker,
235235
userConfig: Partial<PluginConfig>,
236-
localEnv: npmRunPath.ProcessEnv,
236+
localEnv: ProcessEnv,
237237
) {
238238
return new Promise<number>((resolve) => {
239239
const buildBin = checker.build.buildBin
Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { copyFile } from 'node:fs/promises'
2-
import { type Options, defineConfig } from 'tsup'
2+
import { defineConfig } from 'tsup'
33

4-
const shared: Options = {
4+
export default defineConfig({
5+
format: ['esm'],
6+
outDir: 'dist',
7+
async onSuccess() {
8+
await copyFile(
9+
'src/checkers/vueTsc/languagePlugins.cjs',
10+
'dist/checkers/vueTsc/languagePlugins.cjs',
11+
)
12+
},
513
entry: ['src', '!src/checkers/vueTsc/languagePlugins.cjs'],
614
splitting: false,
715
bundle: false,
@@ -10,35 +18,4 @@ const shared: Options = {
1018
target: 'node14',
1119
platform: 'node',
1220
dts: true,
13-
}
14-
15-
export default defineConfig([
16-
{
17-
format: ['cjs'],
18-
outDir: 'dist/cjs',
19-
shims: true,
20-
outExtension() {
21-
return {
22-
js: '.cjs',
23-
}
24-
},
25-
async onSuccess() {
26-
await copyFile(
27-
'src/checkers/vueTsc/languagePlugins.cjs',
28-
'dist/cjs/checkers/vueTsc/languagePlugins.cjs',
29-
)
30-
},
31-
...shared,
32-
},
33-
{
34-
format: ['esm'],
35-
outDir: 'dist/esm',
36-
async onSuccess() {
37-
await copyFile(
38-
'src/checkers/vueTsc/languagePlugins.cjs',
39-
'dist/esm/checkers/vueTsc/languagePlugins.cjs',
40-
)
41-
},
42-
...shared,
43-
},
44-
])
21+
})

playground/vitestGlobalSetup.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { rmSync } from 'node:fs'
22
import fs from 'node:fs/promises'
33
import os from 'node:os'
44
import path from 'node:path'
5-
import { glob } from 'tinyglobby'
65
import { chromium } from 'playwright-chromium'
76

87
import type { BrowserServer } from 'playwright-chromium'
@@ -40,15 +39,6 @@ export async function setup(): Promise<void> {
4039
throw error
4140
}
4241
})
43-
44-
if (process.env['VITEST_TEST_CJS']) {
45-
const packageJsons = await glob(`${tempDir}/**/package.json`)
46-
for (const packageJson of packageJsons) {
47-
const packageJsonContents = await fs.readFile(packageJson, 'utf-8').then(r => JSON.parse(r.toString()))
48-
delete packageJsonContents['module']
49-
await fs.writeFile(packageJson, JSON.stringify(packageJsonContents, null, 2) + '\n')
50-
}
51-
}
5242
}
5343

5444
export async function teardown(): Promise<void> {

pnpm-lock.yaml

Lines changed: 17 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/patchCjs.mjs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)