From: Haoqun Jiang Date: Sat, 25 Dec 2021 14:45:12 +0000 (+0800) Subject: fix: fix type & eslint issues in the cypress plugin file X-Git-Tag: v3.0.4~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a7b0d37dac523b7f72372d6feeaf8a9cd4f4069;p=thirdparty%2Fvuejs%2Fcreate-vue.git fix: fix type & eslint issues in the cypress plugin file --- diff --git a/index.js b/index.js index e582f7f3..99f695d4 100755 --- a/index.js +++ b/index.js @@ -282,14 +282,24 @@ async function init() { // Cleanup. if (needsTypeScript) { - // rename all `.js` files to `.ts` + // We try to share as many files between TypeScript and JavaScript as possible. + // Check all the remaining `.js` files: + // - If the corresponding TypeScript version already exists (generated by the typescript template), + // remove the `.js` file. + // (Currently it's only `cypress/plugin/index.ts`, but we might add more in the future.) + // - Otherwise, rename the `.js` file to `.ts` // rename jsconfig.json to tsconfig.json preOrderDirectoryTraverse( root, () => {}, (filepath) => { if (filepath.endsWith('.js')) { - fs.renameSync(filepath, filepath.replace(/\.js$/, '.ts')) + const tsFilePath = filepath.replace(/\.js$/, '.ts') + if (fs.existsSync(tsFilePath)) { + fs.unlinkSync(filepath) + } else { + fs.renameSync(filepath, tsFilePath) + } } else if (path.basename(filepath) === 'jsconfig.json') { fs.renameSync(filepath, filepath.replace(/jsconfig\.json$/, 'tsconfig.json')) } diff --git a/template/config/typescript/cypress/plugins/index.ts b/template/config/typescript/cypress/plugins/index.ts new file mode 100644 index 00000000..640496ba --- /dev/null +++ b/template/config/typescript/cypress/plugins/index.ts @@ -0,0 +1,26 @@ +/* eslint-env node */ +/// +/// +// *********************************************************** +// This example plugins/index.ts can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +import { startDevServer } from '@cypress/vite-dev-server' + +export default ((on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config + on('dev-server:start', (options) => { + return startDevServer({ options }) + }) + return config +}) as Cypress.PluginConfig