Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update to Vite 3, TS 4.7.4 #22875

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion npm/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"ts-node": "^10.2.1",
"tslib": "^2.2.0",
"tslint": "5.20.1",
"typescript": "4.2.4",
"typescript": "4.7.4",
"webpack-dev-server": "4.0.0",
"zone.js": "0.11.4"
},
Expand Down
2 changes: 1 addition & 1 deletion npm/create-cypress-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"mock-fs": "5.1.1",
"shx": "0.3.3",
"snap-shot-it": "7.9.3",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion npm/cypress-schematic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"chai": "4.2.0",
"cypress": "0.0.0-development",
"mocha": "3.5.3",
"typescript": "~4.2.4"
"typescript": "4.7.4"
},
"peerDependencies": {
"@angular/cli": ">=12",
Expand Down
2 changes: 1 addition & 1 deletion npm/cypress-schematic/sandbox12/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"typescript": "~4.5.5"
"typescript": "4.7.4"
},
"resolutions": {
"@types/eslint": "8.4.3"
Expand Down
2 changes: 1 addition & 1 deletion npm/mount-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {},
"devDependencies": {
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"files": [
"dist"
Expand Down
7 changes: 3 additions & 4 deletions npm/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
"@cypress/mount-utils": "0.0.0-development",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@vitejs/plugin-react": "1.3.1",
"@vitejs/plugin-react": "2.0.0",
"axios": "0.21.2",
"cypress": "0.0.0-development",
"cypress-plugin-snapshots": "1.4.4",
"prop-types": "15.7.2",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-router": "6.0.0-alpha.1",
"react-router-dom": "6.0.0-alpha.1",
"rollup": "^2.38.5",
"rollup-plugin-typescript2": "^0.29.0",
"typescript": "^4.2.3",
"vite": "2.9.5",
"typescript": "4.7.4",
"vite": "3.0.2",
"vite-plugin-require-transform": "1.0.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion npm/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "esnext",
"moduleResolution": "node",
"lib": [
Expand Down
3 changes: 2 additions & 1 deletion npm/vite-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"debug": "4.3.3",
"find-up": "6.3.0",
"local-pkg": "0.4.1",
"node-html-parser": "5.3.3",
"pathe": "0.2.0"
},
"devDependencies": {
Expand All @@ -26,7 +27,7 @@
"mocha": "^9.2.2",
"sinon": "^13.0.1",
"ts-node": "^10.2.1",
"vite": "2.9.0-beta.3",
"vite": "3.0.2",
"vite-plugin-inspect": "0.4.3"
},
"files": [
Expand Down
41 changes: 33 additions & 8 deletions npm/vite-dev-server/src/plugins/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import debugFn from 'debug'
import { resolve } from 'pathe'
import type { ModuleNode, Plugin, ViteDevServer } from 'vite'
import type { Vite } from '../getVite'
import { parse } from 'node-html-parser'
import fs from 'fs'

import type { ViteDevServerConfig } from '../devServer'
Expand Down Expand Up @@ -52,21 +53,45 @@ export const Cypress = (
configResolved (config) {
base = config.base
},
async transformIndexHtml () {
async transformIndexHtml (html) {
// it's possibe other plugins have modified the HTML
// before we get to. For example vitejs/plugin-react will
// add a preamble. We do our best to look at the HTML we
// receive and inject it.
// For now we just grab any `<script>` tags and inject them to <head>.
// We will add more handling as we learn the use cases.
const root = parse(html)

const scriptTagsToInject = root.childNodes.filter((node) => {
// @ts-ignore
return node.rawTagName === 'script'
})

const indexHtmlPath = resolve(projectRoot, indexHtmlFile)

debug('resolved the indexHtmlPath as', indexHtmlPath, 'from', indexHtmlFile)
const indexHtmlContent = await fs.promises.readFile(indexHtmlPath, { encoding: 'utf8' })

let indexHtmlContent = await fs.promises.readFile(indexHtmlPath, { encoding: 'utf8' })

// Inject the script tags
indexHtmlContent = indexHtmlContent.replace(
'<head>',
`<head>
${scriptTagsToInject.map((script) => script.toString())}
`,
)

// find </body> last index
const endOfBody = indexHtmlContent.lastIndexOf('</body>')

// insert the script in the end of the body
return `${indexHtmlContent.substring(0, endOfBody)
}<script>
${loader}
</script>${
indexHtmlContent.substring(endOfBody)
}`
const newHtml = `
${indexHtmlContent.substring(0, endOfBody)}
<script>${loader}</script>
${indexHtmlContent.substring(endOfBody)}
`

return newHtml
},
configureServer: async (server: ViteDevServer) => {
server.middlewares.use(`${base}index.html`, async (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions npm/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"rollup-plugin-istanbul": "2.0.1",
"rollup-plugin-typescript2": "^0.29.0",
"tailwindcss": "1.1.4",
"typescript": "^4.2.3",
"vite": "2.9.5",
"typescript": "4.7.4",
"vite": "3.0.2",
"vue": "3.2.31",
"vue-i18n": "9.0.0-rc.6",
"vue-router": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion npm/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@rollup/plugin-replace": "^2.3.1",
"rollup-plugin-typescript2": "^0.29.0",
"tslib": "^2.1.0",
"typescript": "^4.2.3",
"typescript": "4.7.4",
"vue": "2.6.12"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-batteries-included-preprocessor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"graphql": "14.0.0",
"mocha": "^8.1.1",
"react": "^16.13.1",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"peerDependencies": {
"@cypress/webpack-preprocessor": "^5.4.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"ts-loader": "7.0.4",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"license": "ISC",
"keywords": []
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"through2": "^4.0.2",
"tree-kill": "1.2.2",
"ts-node": "^10.2.1",
"typescript": "^4.4.4",
"typescript": "4.7.4",
"yarn-deduplicate": "3.1.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"rollup-plugin-polyfill-node": "^0.7.0",
"unplugin-icons": "0.13.2",
"unplugin-vue-components": "^0.15.2",
"vite": "2.9.0-beta.3",
"vite": "3.0.2",
"vite-plugin-components": "0.11.3",
"vite-plugin-pages": "0.18.1",
"vite-plugin-vue-layouts": "0.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeConfig } from '../frontend-shared/vite.config'
import { makeConfig } from '../frontend-shared/vite.config.mjs'
import Layouts from 'vite-plugin-vue-layouts'
import Pages from 'vite-plugin-pages'
import Copy from 'rollup-plugin-copy'
Expand Down
1 change: 1 addition & 0 deletions packages/data-context/src/sources/migration/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export function getSpecPattern (cfg: LegacyCypressConfigJson, testingType: Testi
function formatWithBundledBabel (config: string) {
const ast = parse(config)

// @ts-ignore - babel/types need to be updated to work with TypeScript 4.7.x
let { code } = generate(ast, {}, config)
// By default babel generates imports like this:
// const {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"unfetch": "4.1.0",
"url-parse": "1.5.9",
"vanilla-text-mask": "5.1.1",
"vite": "2.9.0-beta.3",
"vite": "3.0.2",
"webpack": "^4.44.2",
"zone.js": "0.9.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const build = gulp.series(
icons,
logos,
manifest,
background,
html,
css,
),
background,
)

const watchBuild = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"shiki": "^0.9.12",
"unplugin-icons": "0.13.2",
"unplugin-vue-components": "^0.15.4",
"vite": "2.9.0-beta.3",
"vite": "3.0.2",
"vite-plugin-components": "0.11.3",
"vite-plugin-windicss": "^1.4.7",
"vite-svg-loader": "3.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @ts-check
import path from 'path'
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueI18n from '@intlify/vite-plugin-vue-i18n'
import { vueI18n } from '@intlify/vite-plugin-vue-i18n'
import VueSvgLoader from 'vite-svg-loader'
import { CyCSSVitePlugin } from '@cypress-design/css'
import Components from 'unplugin-vue-components/vite'
Expand All @@ -12,18 +14,8 @@ import { FileSystemIconLoader } from 'unplugin-icons/loaders'

import PkgConfig from 'vite-plugin-package-config'

// eslint-disable-next-line no-duplicate-imports
import type { UserConfig } from 'vite'
import type { ArgumentsType } from '@antfu/utils'

type PluginOptions = {
plugins?: any[]

// These types aren't publicly exported
vueI18nOptions?: ArgumentsType<typeof VueI18n>[0]
iconsOptions?: ArgumentsType<typeof Icons>[0]
componentsOptions?: ArgumentsType<typeof Components>[0]
}
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const base = './'

Expand All @@ -39,7 +31,7 @@ const makePlugins = (plugins) => {
return ([
vue(),
vueJsx(), // Used mostly for testing in *.(t|j)sx files.
VueI18n({
vueI18n({
include: path.resolve(__dirname, './src/locales/**'),
...plugins.vueI18nOptions,
}),
Expand Down Expand Up @@ -88,14 +80,26 @@ const makePlugins = (plugins) => {

// package.json is modified and auto-updated when new cjs dependencies
// are added
PkgConfig(),
PkgConfig.default(),
// OptimizationPersist(),
// For new plugins only! Merge options for shared plugins via PluginOptions.
...(plugins?.plugins || []),
])
}

export const makeConfig = (config: Partial<UserConfig> = {}, plugins: PluginOptions = {}): UserConfig => {
/**
* @typedef PluginOptions
* @type {object}
* @property {import('@antfu/utils').ArgumentsType<typeof vueI18n>[0]=} vueI18nOptions
* @property {import('@antfu/utils').ArgumentsType<typeof Icons>[0]=} VueI18n
* @property {import('@antfu/utils').ArgumentsType<typeof Components>[0]=} componentOptions

*
* @param {import('vite').UserConfig} config
* @param {PluginOptions} plugins
* @returns {import('vite').UserConfig}
*/
export const makeConfig = (config = {}, plugins = {}) => {
// Don't overwrite plugins
delete config.plugins

Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"rimraf": "3.0.2",
"sinon": "^10.0.0",
"sinon-chai": "3.4.0",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"files": [
"index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"rimraf": "3.0.2",
"rollup-plugin-polyfill-node": "^0.7.0",
"type-fest": "^2.3.4",
"vite": "2.9.0-beta.3",
"vite": "3.0.2",
"vite-plugin-components": "0.11.3",
"vite-plugin-optimize-persist": "0.0.5",
"vite-plugin-package-config": "0.0.3",
Expand Down
3 changes: 3 additions & 0 deletions packages/launchpad/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ViteConfig from '../frontend-shared/vite.config.mjs'

export default ViteConfig
3 changes: 0 additions & 3 deletions packages/launchpad/vite.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"rimraf": "3.0.2",
"sinon": "7.3.1",
"sinon-chai": "3.3.0",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"files": [
"lib"
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"express": "4.17.1",
"rimraf": "3.0.2",
"supertest": "6.0.1",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"files": [
"lib"
Expand Down
2 changes: 1 addition & 1 deletion packages/socket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"engine.io": "5.2.1",
"engine.io-parser": "4.0.2",
"socket.io": "4.0.1",
"socket.io-client": "4.0.1"
"socket.io-client": "4.5.1"
},
"devDependencies": {
"chai": "3.5.0",
Expand Down
1 change: 1 addition & 0 deletions packages/socket/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./../ts/tsconfig.json",
"compilerOptions": {
"lib": ["DOM"],
"strict": true,
"noImplicitAny": true,
"skipLibCheck": false
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@types/node": "14.14.31",
"rimraf": "3.0.2",
"typescript": "^4.2.3"
"typescript": "4.7.4"
},
"files": [
"src/*"
Expand Down