]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
fix: fix type & eslint issues in the cypress plugin file
authorHaoqun Jiang <haoqunjiang@gmail.com>
Sat, 25 Dec 2021 14:45:12 +0000 (22:45 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Sat, 25 Dec 2021 14:45:12 +0000 (22:45 +0800)
index.js
template/config/typescript/cypress/plugins/index.ts [new file with mode: 0644]

index e582f7f3896e9c91438aa55aaa76d06a300dc715..99f695d40feaf08031bb300527c010df440bcd43 100755 (executable)
--- 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 (file)
index 0000000..640496b
--- /dev/null
@@ -0,0 +1,26 @@
+/* eslint-env node */
+/// <reference types="node" />
+/// <reference types="cypress" />
+// ***********************************************************
+// 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