From e54b36ae28fcd749d7ab8f7c5b83c1dbcf9643d4 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sat, 4 Nov 2023 19:23:47 +0100 Subject: [PATCH] refactor(core): remove slots patch --- packages/core/package.json | 3 +- packages/core/patch/slots.js | 63 ------------------------------------ 2 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 packages/core/patch/slots.js diff --git a/packages/core/package.json b/packages/core/package.json index a168614c..078a5599 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -54,9 +54,8 @@ "dev": "pnpm types:watch & pnpm build:watch", "build": "vite build && vite build -c vite.config.iife.ts", "build:watch": "vite build --watch & vite build -c vite.config.iife.ts --watch", - "types": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly && tsc -p ./tsconfig.build.json && shx rm -rf tmp && pnpm lint:dist && pnpm run patch", + "types": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly && tsc -p ./tsconfig.build.json && shx rm -rf tmp && pnpm lint:dist", "types:watch": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly --watch & tsc -p ./tsconfig.build.json --watch", - "patch": "node patch/slots.js", "theme": "postcss src/style.css -o dist/style.css && postcss src/theme-default.css -o dist/theme-default.css", "lint": "eslint --ext .js,.ts,.vue ./", "lint:dist": "eslint --ext \".ts,.tsx\" -c .eslintrc.js --fix --ignore-pattern !**/* ./dist", diff --git a/packages/core/patch/slots.js b/packages/core/patch/slots.js deleted file mode 100644 index 69563e42..00000000 --- a/packages/core/patch/slots.js +++ /dev/null @@ -1,63 +0,0 @@ -const { readFile, writeFile } = require('node:fs/promises') -const { resolve } = require('node:path') - -/** - * This is a workaround until slots can be properly typed from inside the VueFlow component - * It will overwrite `{}` typings with the correct prop types and add slot types for dynamic node and edge slots - */ - -async function content(path) { - return readFile(path, 'utf8') -} - -const filePath = resolve(__dirname, '../dist/container/VueFlow/VueFlow.vue.d.ts') - -const typeImportsString = /import type {\n(.*\n)+} from '\.\.\/\.\.\/types'/ - -const patchedTypeImports = `import type { - Connection, - ConnectionLineProps, - EdgeChange, - EdgeMouseEvent, - EdgeProps, - EdgeUpdateEvent, - GraphEdge, - GraphNode, - NodeChange, - NodeDragEvent, - NodeMouseEvent, - NodeProps, - OnConnectStartParams, - ViewportTransform, - VueFlowStore, -} from '../../types'` - -const unpatchedSlots = `Partial any>> & - Partial any>> & { - 'connection-line'?(_: {}): any - 'zoom-pane'?(_: {}): any - default?(_: {}): any - }` - -const patchedSlots = `Partial any>> & { - 'connection-line': (connectionLineProps: ConnectionLineProps) => any - 'zoom-pane': () => any - 'default': () => any - } & { - [key: \`node-\${string}\`]: (nodeProps: NodeProps) => any - } & { - [key: \`edge-\${string}\`]: (edgeProps: EdgeProps) => any - }` - -async function patchSlots() { - const fileContents = await content(filePath) - - const patchedFileContents = fileContents.replace(typeImportsString, patchedTypeImports).replace(unpatchedSlots, patchedSlots) - - await writeFile(filePath, patchedFileContents) -} - -patchSlots() - // eslint-disable-next-line no-console - .then(() => console.log('slots patched')) - .catch(console.error)