Skip to content

Commit

Permalink
build: align cjs/esm types + add explicit cjs extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 17, 2025
1 parent 397cd7d commit 6e3b575
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format": "biome format . --write",
"postinstall": "simple-git-hooks install",
"lint": "biome check . --diagnostic-level=warn",
"publint": "pnpm -r --filter='vite-plugin-checker' exec publint",
"publint": "pnpm build && pnpm -r --filter='vite-plugin-checker' exec publint",
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
"test": "run-s test-unit test-serve test-build",
"test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
Expand Down
7 changes: 3 additions & 4 deletions packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
"type": "module",
"exports": {
".": {
"types": "./dist/esm/main.d.ts",
"import": "./dist/esm/main.js",
"require": "./dist/cjs/main.js"
"require": "./dist/cjs/main.cjs"
}
},
"main": "./dist/cjs/main.js",
"types": "./dist/esm/main.d.ts",
"main": "./dist/cjs/main.cjs",
"types": "./dist/cjs/main.d.cts",
"files": [
"dist",
"!dist/checkers/vueTsc/typescript-vue-tsc"
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-checker/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig([
shims: true,
outExtension() {
return {
js: '.js',
js: '.cjs',
}
},
async onSuccess() {
Expand Down
24 changes: 16 additions & 8 deletions scripts/patchCjs.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import fs from 'node:fs/promises'
import path, { dirname } from 'node:path'
import fs, { copyFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { glob } from 'tinyglobby'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const cjsDist = fileURLToPath(new URL('../packages/vite-plugin-checker/dist/cjs', import.meta.url))

async function main() {
await fs.writeFile(
path.resolve(
__dirname,
'../packages/vite-plugin-checker/dist/cjs/package.json',
),
path.join(cjsDist, 'package.json'),
JSON.stringify({ type: 'commonjs' }, null, 2),
)

// correct declaration file extensions
const cjsDeclarations = await glob('**/*.d.ts', {
absolute: true,
cwd: cjsDist
})

for (const file of cjsDeclarations) {
await copyFile(file, file.replace('.d.ts', '.d.cts'))
await fs.rm(file)
}
}

main()

0 comments on commit 6e3b575

Please sign in to comment.