From 96e8c4697dd667892f1b5fd9b490a9d52a0050a6 Mon Sep 17 00:00:00 2001 From: "Alex.hxy" <1872591453@qq.com> Date: Fri, 20 Sep 2024 14:59:03 +0800 Subject: [PATCH] chore: replace local prettier plugin with npm package (#3197) * chore: replace local prettier plugin with npm package * fix: test --- .prettierrc | 2 +- package.json | 2 +- packages/nutui-prettier-plugin/index.js | 80 --------------------- packages/nutui-prettier-plugin/package.json | 18 ----- pnpm-lock.yaml | 69 +++--------------- 5 files changed, 13 insertions(+), 158 deletions(-) delete mode 100644 packages/nutui-prettier-plugin/index.js delete mode 100644 packages/nutui-prettier-plugin/package.json diff --git a/.prettierrc b/.prettierrc index f6f0690340..40e0ca3b99 100644 --- a/.prettierrc +++ b/.prettierrc @@ -8,5 +8,5 @@ "proseWrap": "preserve", "htmlWhitespaceSensitivity": "strict", "trailingComma": "none", - "plugins": ["@nutui/prettier-plugin"] + "plugins": ["prettier-markdown-table"] } diff --git a/package.json b/package.json index 7f3580a109..142ebb2612 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,6 @@ "@eslint/config-inspector": "^0.5.1", "@eslint/eslintrc": "^3.1.0", "@nutui/eslint-config": "workspace:*", - "@nutui/prettier-plugin": "workspace:*", "@nutui/vite-plugins": "workspace:*", "@tarojs/taro": "3.6.34", "@types/node": "^20.14.9", @@ -106,6 +105,7 @@ "markdown-it": "^14.1.0", "nano-staged": "^0.8.0", "prettier": "^3.3.2", + "prettier-markdown-table": "^1.0.1", "rimraf": "^6.0.0", "typescript": "^5.4.5", "unplugin-vue-components": "^0.27.2", diff --git a/packages/nutui-prettier-plugin/index.js b/packages/nutui-prettier-plugin/index.js deleted file mode 100644 index ad6aa194b2..0000000000 --- a/packages/nutui-prettier-plugin/index.js +++ /dev/null @@ -1,80 +0,0 @@ -import linguistLanguages from 'linguist-languages' -import { printers as MarkdownPrinter, parsers as MarkdownParsers } from 'prettier/plugins/markdown' - -export const languages = [ - { - ...linguistLanguages.Markdown, - parsers: ['markdown'] - } -] - -export const parsers = { - markdown: { - ...MarkdownParsers.markdown - } -} - -export const printers = { - mdast: { - ...MarkdownPrinter.mdast, - print: pluginPrint - } -} - -function pluginPrint(path, options, print) { - const node = path.getValue() - - if (node.type == 'table') { - return printTable(path, options, print) - } - return MarkdownPrinter.mdast.print(path, options, print) -} - -function printTable(path, options, print) { - const contents = path.map( - () => - path.map(() => { - const text = print() - .flat(Infinity) - .map((item) => { - if (typeof item === 'string') { - return item - } - return item.parts.flat(Infinity).join('') - }) - .join('') - return { text } - }, 'children'), - 'children' - ) - - const alignedTable = printTableContents() - return [alignedTable] - - function printTableContents() { - /** @type{Doc[]} */ - const parts = [printRow(contents[0]), printAlign()] - if (contents.length > 1) { - for (let i = 1; i < contents.length - 1; i++) { - parts.push(printRow(contents[i])) - } - parts.push(printRow(contents[contents.length - 1], true)) - } - return parts - } - - function printAlign() { - const align = contents[0].map(() => { - return `---` - }) - - return `| ${align.join(' | ')} |\n` - } - - function printRow(rowContents, end = false) { - const columns = rowContents.map(({ text }) => { - return ` ${text} ` - }) - return end ? `|${columns.join('|')}|` : `|${columns.join('|')}|\n` - } -} diff --git a/packages/nutui-prettier-plugin/package.json b/packages/nutui-prettier-plugin/package.json deleted file mode 100644 index 8c07dc976a..0000000000 --- a/packages/nutui-prettier-plugin/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "@nutui/prettier-plugin", - "version": "0.0.1", - "private": "true", - "description": "", - "type": "module", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "devDependencies": { - "linguist-languages": "^7.27.0", - "prettier": "^3.3.2" - }, - "keywords": [], - "author": "jdf2e", - "license": "MIT" -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 576fe92931..98954f30b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,9 +42,6 @@ importers: '@nutui/eslint-config': specifier: workspace:* version: link:packages/nutui-eslint-config - '@nutui/prettier-plugin': - specifier: workspace:* - version: link:packages/nutui-prettier-plugin '@nutui/vite-plugins': specifier: workspace:* version: link:packages/nutui-vite-plugins @@ -108,6 +105,9 @@ importers: prettier: specifier: ^3.3.2 version: 3.3.2 + prettier-markdown-table: + specifier: ^1.0.1 + version: 1.0.2 rimraf: specifier: ^6.0.0 version: 6.0.0 @@ -204,15 +204,6 @@ importers: specifier: ^3.4.31 version: 3.4.31(typescript@5.4.5) - packages/nutui-prettier-plugin: - devDependencies: - linguist-languages: - specifier: ^7.27.0 - version: 7.27.0 - prettier: - specifier: ^3.3.2 - version: 3.3.2 - packages/nutui-taro-demo: dependencies: '@babel/runtime': @@ -2079,7 +2070,6 @@ packages: engines: {node: '>= 16'} cpu: [x64] os: [linux] - libc: [glibc] '@tarojs/binding-win32-x64-msvc@3.6.34': resolution: {integrity: sha512-vEO0autpmk1k+EHOdEsJcDgozzJn6BsDeJcD3nwKMMBfRoyE+nilUJD6XFmFP/GaBRP4nLgsUvsshVaC+GOJ5A==} @@ -2163,28 +2153,24 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [glibc] '@tarojs/plugin-doctor-linux-arm64-musl@0.0.11': resolution: {integrity: sha512-SXes1wj2MLQod50+9sgSZlN4eli3VXVxMNqdk03ArrWtFURCpuDiHwRERjoqlo91Hf4IxU6zU7ml86gPZ0dkaw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [musl] '@tarojs/plugin-doctor-linux-x64-gnu@0.0.11': resolution: {integrity: sha512-nyW2tjzYA8nw39pKpaYtpGbEOZNRTV97Ir+UEvsuZbAr5F1lV2Q+2IwN8dGY41/lXw9JQay6FDRqUPRXAMB4kw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] '@tarojs/plugin-doctor-linux-x64-musl@0.0.11': resolution: {integrity: sha512-epKcAwJdVYMGmeWdqGZrdOS+nhDz4SiGlZqYMcDjSlGK7OM0wlSor6xpz59adYVe86t/a/gjimu5IT2ofVEfsA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] '@tarojs/plugin-doctor-win32-ia32-msvc@0.0.11': resolution: {integrity: sha512-UBKdbbtDK1QmsRZiKEjo+TtSt+E/ljIzx5wbDna2yEuDtJqBwNg6SqkYg3LxUiJK8O5hwwVJGdJWI9a9bHpI8w==} @@ -7332,6 +7318,9 @@ packages: resolution: {integrity: sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA==} engines: {node: '>=4'} + prettier-markdown-table@1.0.2: + resolution: {integrity: sha512-WYaAn3GX8hn1v+dZcHljxgZfG0PeWvP2Ufav0vzvlDiWhb8uj+FIKpUIMiaf6uP1PF8Ni/1m7X6FwucSgCvY2w==} + prettier@2.8.8: resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} @@ -10989,26 +10978,6 @@ snapshots: - '@types/webpack' - '@types/webpack-dev-server' - '@tarojs/components-advanced@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(@tarojs/shared@3.6.34)(@tarojs/taro@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5)))(vue@3.4.31(typescript@5.4.5))': - dependencies: - '@tarojs/components': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5)) - '@tarojs/runtime': 3.6.34(@tarojs/shared@3.6.34) - '@tarojs/shared': 3.6.34 - '@tarojs/taro': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5)) - classnames: 2.5.1 - csstype: 3.1.3 - memoize-one: 6.0.0 - postcss: 8.4.39 - tslib: 2.6.2 - optionalDependencies: - vue: 3.4.31(typescript@5.4.5) - transitivePeerDependencies: - - '@tarojs/helper' - - '@types/react' - - '@types/react-native' - - '@types/webpack' - - '@types/webpack-dev-server' - '@tarojs/components-react@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(@tarojs/shared@3.6.34)(postcss@8.4.38)(vue@3.4.31(typescript@5.4.5))': dependencies: '@babel/runtime': 7.24.6 @@ -11054,7 +11023,7 @@ snapshots: '@tarojs/components@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(@tarojs/shared@3.6.34)(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5))': dependencies: '@stencil/core': 2.22.3 - '@tarojs/components-advanced': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(@tarojs/shared@3.6.34)(@tarojs/taro@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5)))(vue@3.4.31(typescript@5.4.5)) + '@tarojs/components-advanced': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(@tarojs/shared@3.6.34)(@tarojs/taro@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.38)(vue@3.4.31(typescript@5.4.5)))(vue@3.4.31(typescript@5.4.5)) '@tarojs/taro': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5)) classnames: 2.5.1 hammerjs: 2.0.8 @@ -11073,26 +11042,6 @@ snapshots: - postcss - react - '@tarojs/components@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5))': - dependencies: - '@stencil/core': 2.22.3 - '@tarojs/components-advanced': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(@tarojs/shared@3.6.34)(@tarojs/taro@3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.38)(vue@3.4.31(typescript@5.4.5)))(vue@3.4.31(typescript@5.4.5)) - '@tarojs/taro': 3.6.34(@tarojs/helper@3.6.34)(@tarojs/runtime@3.6.34(@tarojs/shared@3.6.34))(postcss@8.4.39)(vue@3.4.31(typescript@5.4.5)) - classnames: 2.5.1 - hammerjs: 2.0.8 - hls.js: 1.5.8 - resolve-pathname: 3.0.0 - swiper: 6.8.0 - tslib: 2.6.2 - optionalDependencies: - vue: 3.4.31(typescript@5.4.5) - transitivePeerDependencies: - - '@tarojs/helper' - - '@tarojs/runtime' - - '@types/webpack' - - '@types/webpack-dev-server' - - postcss - '@tarojs/helper@3.6.34': dependencies: '@babel/core': 7.24.6 @@ -17213,6 +17162,10 @@ snapshots: prepend-http@2.0.0: {} + prettier-markdown-table@1.0.2: + dependencies: + linguist-languages: 7.27.0 + prettier@2.8.8: optional: true