Skip to content

Commit

Permalink
build: make package.json pure ESM
Browse files Browse the repository at this point in the history
BREAKING CHANGE: node requires >=14.16
  • Loading branch information
fi3ework committed Aug 26, 2022
1 parent 8d3abf3 commit a24809c
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 199 deletions.
2 changes: 1 addition & 1 deletion docs/introduction/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A Vite plugin that can run TypeScript, VLS, vue-tsc, ESLint in worker thread.
<img alt="screenshot" src="https://user-images.githubusercontent.com/12322740/152739742-7444ee62-9ca7-4379-8f02-495c612ecc5c.png">
</p>

> History version documentations [0.1](https://github.com/fi3ework/vite-plugin-checker/tree/v0.1.x), [0.2](https://github.com/fi3ework/vite-plugin-checker/tree/v0.2), [0.3](https://github.com/fi3ework/vite-plugin-checker/tree/v0.3.x). It's highly recommended to use latest version before 1.0.0, although there's some breaking changes, the plugin configuration is quite simple.
> History version documentations [0.1](https://github.com/fi3ework/vite-plugin-checker/tree/v0.1.x), [0.2](https://github.com/fi3ework/vite-plugin-checker/tree/v0.2), [0.3](https://github.com/fi3ework/vite-plugin-checker/tree/v0.3.x), [0.4](https://github.com/fi3ework/vite-plugin-checker/tree/v0.4.x/docs). It's highly recommended to use latest version before 1.0.0, although there's some breaking changes, the plugin configuration is quite simple.
## Online playground

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"klaw": "^4.0.1",
"lint-staged": "^11.0.0",
"minimist": "^1.2.5",
"nodemon": "^2.0.15",
"npm-run-all": "^4.1.5",
"playwright-chromium": "^1.24.0",
"prettier": "^2.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pnpm preview

### with vite-plugin-checker

Watch and compile bundled JS to `../vite-plugin-checker/lib/@runtime/main.js`. Run `pnpm dev` in monorepo root will invoke below scripts.
Watch and compile bundled JS to `../vite-plugin-checker/dist/@runtime/main.js`. Run `pnpm dev` in monorepo root will invoke below scripts.

```bash
pnpm dev
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config = isLocal
}
: {
entryPoints: ['./src/main.js'],
outfile: '../vite-plugin-checker/lib/@runtime/main.js',
outfile: '../vite-plugin-checker/dist/@runtime/main.js',
}

esbuild
Expand Down
13 changes: 8 additions & 5 deletions packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
"name": "vite-plugin-checker",
"version": "0.4.9",
"description": "Vite plugin that runs TypeScript type checker on a separate process.",
"main": "lib/main.js",
"type": "module",
"types": "lib/main.d.ts",
"types": "./dist/main.d.ts",
"exports": "./dist/main.js",
"engines": {
"node": ">=14.16"
},
"files": [
"lib",
"!lib/checkers/vueTsc/typescript-vue-tsc"
"dist",
"!dist/checkers/vueTsc/typescript-vue-tsc"
],
"scripts": {
"dev": "tsup --watch",
"clean": "rimraf lib",
"clean": "rimraf dist",
"build": "tsup",
"build:test": "tsup --sourcemap inline",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package vite-plugin-checker",
Expand Down
54 changes: 1 addition & 53 deletions packages/vite-plugin-checker/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import chalk from 'chalk'
import { Plugin } from 'esbuild'
import { relative, join } from 'path'
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src'],
outDir: 'lib',
outDir: 'dist',
splitting: false,
bundle: false,
format: ['esm'],
Expand All @@ -15,53 +12,4 @@ export default defineConfig({
target: 'node14',
platform: 'node',
dts: true,
// esbuildPlugins: [
// addImportExt(),
// createPatchEsbuildDistPlugin()
// ],
})

// copied from https://github.com/vitejs/vite/blob/5d6ea8efc36bfdcd8b70afa8e82026ad1ccc0a77/scripts/patchEsbuildDist.ts, with a slight modification :)
function createPatchEsbuildDistPlugin(): Plugin {
return {
name: 'patch-esbuild-dist',
setup(build) {
build.onEnd((result) => {
const targetFile = result.outputFiles!.filter((f) => {
return relative(__dirname, f.path) === join('lib', 'main.js')
})[0]

if (!targetFile) {
console.error(chalk.red(`did not find targetFile`))
process.exit(1)
}

const modifiedCode = patchEsbuildDist(targetFile.text, 'checker')

if (modifiedCode) {
Object.defineProperty(targetFile, 'text', { value: modifiedCode })
}
})
},
}
}

function patchEsbuildDist(_code: string, varName: string) {
let code = _code
const moduleExportsLine = `module.exports = __toCommonJS(main_exports);`

if (code.includes(moduleExportsLine)) {
// overwrite for cjs require('...')() usage
code = code.replace(
moduleExportsLine,
`module.exports = ${varName};
${varName}['default'] = ${varName};`
)

console.log(chalk.bold(`patched with overwrite for cjs require('...')()`))
return code
} else {
console.error(chalk.red(`post-esbuild bundling patch failed`))
process.exit(1)
}
}
1 change: 0 additions & 1 deletion playground/multiple-hmr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"type": "module",
"scripts": {
"dev": "vite",
"dev:watch": "nodemon --watch ../../packages/vite-plugin-checker/lib --exec 'vite'",
"build": "vite build",
"serve": "vite preview"
},
Expand Down
1 change: 0 additions & 1 deletion playground/typescript-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"version": "0.0.0",
"scripts": {
"dev": "vite",
"dev:watch": "nodemon --watch ../../packages/vite-plugin-checker/lib --exec 'vite'",
"build": "vite build",
"serve": "vite preview"
},
Expand Down
2 changes: 1 addition & 1 deletion playground/vitestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { chromium } from 'playwright-chromium'
import strip from 'strip-ansi'
import { createServer, mergeConfig } from 'vite'
import { beforeAll, expect } from 'vitest'
import { Checker } from 'vite-plugin-checker/lib/Checker'
import { Checker } from 'vite-plugin-checker/dist/Checker'

import { normalizeWindowsLogSerializer } from './serializers'

Expand Down

0 comments on commit a24809c

Please sign in to comment.