Skip to content

Commit

Permalink
feat: support vite ^5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatAuk committed Nov 26, 2023
1 parent 40fe6c8 commit a399811
Show file tree
Hide file tree
Showing 5 changed files with 4,259 additions and 2,919 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
name: Install pnpm
id: pnpm-install
with:
version: 7
version: 8.7.6
run_install: false

- name: Get pnpm store directory
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"tsx": "^3.12.5",
"turbo": "^1.10.12",
"typescript": "^4.9.5",
"vite": "^4.1.4",
"vite": "^5.0.2",
"vitest": "^0.29.2"
}
}
6 changes: 4 additions & 2 deletions packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
"build": "tsup"
},
"peerDependencies": {
"vite": ">4.0.0 || ^3.0.0 || ^2.0.0"
"vite": "^5.0.0 || >4.0.0 || ^3.0.0"
},
"dependencies": {
"@plugin-web-update-notification/core": "workspace:*"
},
"devDependencies": {}
"devDependencies": {
"vite": "^5.0.2"
}
}
56 changes: 28 additions & 28 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {
get__Dirname,
} from '@plugin-web-update-notification/core'

/**
* Get the version of the current Vite
*
* if the viteVersion is undefined, we assume that vite is less than v3.0(after v3.0, vite export version)
*/
async function getViteVersion(): Promise<string | undefined> {
return await import('vite').then(({ version }) => version)
}
// /**
// * Get the version of the current Vite
// *
// * if the viteVersion is undefined, we assume that vite is less than v3.0(after v3.0, vite export version)
// */
// async function getViteVersion(): Promise<string | undefined> {
// return await import('vite').then(({ version }) => version)
// }

/**
* It injects the hash into the HTML, and injects the notification anchor and the stylesheet and the
Expand Down Expand Up @@ -65,7 +65,7 @@ function injectPluginHtml(

export function webUpdateNotice(options: Options = {}): Plugin {
let viteConfig: ResolvedConfig
let viteVersion: string | undefined
// let viteVersion: string | undefined

const { versionType, customVersion, silence } = options
let version = ''
Expand Down Expand Up @@ -101,7 +101,7 @@ export function webUpdateNotice(options: Options = {}): Plugin {
)
jsFileHash = getFileHash(jsFileSource)

viteVersion = await getViteVersion()
// viteVersion = await getViteVersion()
},
generateBundle(_, bundle = {}) {
if (!version)
Expand Down Expand Up @@ -137,24 +137,24 @@ export function webUpdateNotice(options: Options = {}): Plugin {
}
},
transformIndexHtml:
// if the viteVersion is undefined, we assume that vite is less than v3.0(after v3.0, vite export version)
viteVersion === undefined
? {
enforce: 'post',
async transform(html: string) {
if (version)
return injectPluginHtml(html, version, options, { jsFileHash, cssFileHash })

return html
},
}
: {
order: 'post',
handler(html: string, { chunk }) {
if (version && chunk)
return injectPluginHtml(html, version, options, { jsFileHash, cssFileHash })
return html
},
// if the viteVersion is undefined, we assume that vite is less than v3.0(after v3.0, vite export version)
// viteVersion === undefined
// ? {
// enforce: 'post',
// async transform(html: string) {
// if (version)
// return injectPluginHtml(html, version, options, { jsFileHash, cssFileHash })

// return html
// },
// }
{
order: 'post',
handler(html: string, { chunk }) {
if (version && chunk)
return injectPluginHtml(html, version, options, { jsFileHash, cssFileHash })
return html
},
},
}
}
Loading

0 comments on commit a399811

Please sign in to comment.