Skip to content

Commit

Permalink
build!: drop support for cjs usage (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Feb 18, 2025
1 parent f098566 commit 155d771
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 112 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,8 @@ jobs:
- name: Test unit
run: pnpm run test-unit

- name: Test serve (ESM)
- name: Test serve
run: pnpm run test-serve

- name: Test build (ESM)
- name: Test build
run: pnpm run test-build

- name: Test serve (CJS)
if: ${{ matrix.node_version == 18 && matrix.os == 'ubuntu-latest' }}
run: pnpm run test-serve-cjs

- name: Test build (CJS)
if: ${{ matrix.node_version == 18 && matrix.os == 'ubuntu-latest' }}
run: pnpm run test-build-cjs
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
"test": "pnpm test-unit && pnpm test-serve && pnpm test-build",
"test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"test-build-cjs": "VITEST_TEST_CJS=1 pnpm run test-build",
"test-knip": "knip",
"test-serve": "vitest run -c vitest.config.e2e.ts",
"test-serve-cjs": "VITEST_TEST_CJS=1 pnpm run test-serve",
"test-unit": "vitest run",
"test-unit:watch": "vitest",
"type-check": "pnpm -r --parallel --filter \"vite-plugin-checker\" exec tsc --noEmit"
Expand Down
17 changes: 7 additions & 10 deletions packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
"author": "fi3ework <[email protected]>",
"type": "module",
"exports": {
".": {
"import": "./dist/esm/main.js",
"require": "./dist/cjs/main.cjs"
}
".": "./dist/main.js"
},
"main": "./dist/cjs/main.cjs",
"types": "./dist/cjs/main.d.cts",
"main": "./dist/main.js",
"types": "./dist/main.d.ts",
"files": [
"dist",
"!dist/checkers/vueTsc/typescript-vue-tsc"
],
"scripts": {
"build": "tsup && node ../../scripts/patchCjs.mjs",
"build": "tsup",
"build:test": "tsup --sourcemap inline",
"clean": "rimraf dist",
"dev": "tsup --watch"
Expand All @@ -38,10 +35,10 @@
"@babel/code-frame": "^7.26.2",
"chokidar": "^3.6.0",
"colorette": "^2.0.20",
"npm-run-path": "^4.0.1",
"strip-ansi": "^6.0.1",
"npm-run-path": "^6.0.0",
"strip-ansi": "^7.1.0",
"tiny-invariant": "^1.3.3",
"tinyglobby": "^0.2.10",
"tinyglobby": "^0.2.11",
"vscode-uri": "^3.1.0"
},
"devDependencies": {
Expand Down
5 changes: 1 addition & 4 deletions packages/vite-plugin-checker/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ export const WS_CHECKER_ERROR_EVENT = 'vite-plugin-checker:error'
export const WS_CHECKER_RECONNECT_EVENT = 'vite-plugin-checker:reconnect'
// #endregion

export const runtimeSourceFilePath = import.meta.url.endsWith('.ts')
? // for development only, maybe should use NODE_ENV to distinguish
_require.resolve('../@runtime/main.js')
: _require.resolve('../../@runtime/main.js')
export const runtimeSourceFilePath = _require.resolve('../@runtime/main.js')
export const runtimeCode = `${fs.readFileSync(runtimeSourceFilePath, 'utf-8')};`
6 changes: 3 additions & 3 deletions packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn } from 'node:child_process'
import * as colors from 'colorette'
import npmRunPath from 'npm-run-path'
import { type ProcessEnv, npmRunPathEnv } from 'npm-run-path'

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

const localEnv = npmRunPath.env({
const localEnv = npmRunPathEnv({
env: process.env,
cwd: process.cwd(),
execPath: process.execPath,
Expand Down Expand Up @@ -233,7 +233,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
function spawnChecker(
checker: ServeAndBuildChecker,
userConfig: Partial<PluginConfig>,
localEnv: npmRunPath.ProcessEnv,
localEnv: ProcessEnv,
) {
return new Promise<number>((resolve) => {
const buildBin = checker.build.buildBin
Expand Down
45 changes: 11 additions & 34 deletions packages/vite-plugin-checker/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { copyFile } from 'node:fs/promises'
import { type Options, defineConfig } from 'tsup'
import { defineConfig } from 'tsup'

const shared: Options = {
export default defineConfig({
format: ['esm'],
outDir: 'dist',
async onSuccess() {
await copyFile(
'src/checkers/vueTsc/languagePlugins.cjs',
'dist/checkers/vueTsc/languagePlugins.cjs',
)
},
entry: ['src', '!src/checkers/vueTsc/languagePlugins.cjs'],
splitting: false,
bundle: false,
Expand All @@ -10,35 +18,4 @@ const shared: Options = {
target: 'node14',
platform: 'node',
dts: true,
}

export default defineConfig([
{
format: ['cjs'],
outDir: 'dist/cjs',
shims: true,
outExtension() {
return {
js: '.cjs',
}
},
async onSuccess() {
await copyFile(
'src/checkers/vueTsc/languagePlugins.cjs',
'dist/cjs/checkers/vueTsc/languagePlugins.cjs',
)
},
...shared,
},
{
format: ['esm'],
outDir: 'dist/esm',
async onSuccess() {
await copyFile(
'src/checkers/vueTsc/languagePlugins.cjs',
'dist/esm/checkers/vueTsc/languagePlugins.cjs',
)
},
...shared,
},
])
})
10 changes: 0 additions & 10 deletions playground/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { rmSync } from 'node:fs'
import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { glob } from 'tinyglobby'
import { chromium } from 'playwright-chromium'

import type { BrowserServer } from 'playwright-chromium'
Expand Down Expand Up @@ -40,15 +39,6 @@ export async function setup(): Promise<void> {
throw error
}
})

if (process.env['VITEST_TEST_CJS']) {
const packageJsons = await glob(`${tempDir}/**/package.json`)
for (const packageJson of packageJsons) {
const packageJsonContents = await fs.readFile(packageJson, 'utf-8').then(r => JSON.parse(r.toString()))
delete packageJsonContents['module']
await fs.writeFile(packageJson, JSON.stringify(packageJsonContents, null, 2) + '\n')
}
}
}

export async function teardown(): Promise<void> {
Expand Down
42 changes: 17 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions scripts/patchCjs.mjs

This file was deleted.

0 comments on commit 155d771

Please sign in to comment.