From d7d873b6f1dcc4f0b6189198a9151797e5abe072 Mon Sep 17 00:00:00 2001 From: Mr-ccyou <1787176370@qq.com> Date: Sat, 6 May 2023 15:58:14 +0800 Subject: [PATCH] fix: update vite + vue2 compiler dependencies --- examples/react-vite/package.json | 1 - examples/vue2-vite/index.html | 12 ++++ examples/vue2-vite/package.json | 16 +++++ examples/vue2-vite/src/App.vue | 34 ++++++++++ examples/vue2-vite/src/assets/logo.png | Bin 0 -> 6849 bytes examples/vue2-vite/src/icons/icon-addUser.svg | 3 + examples/vue2-vite/src/icons/icon-barCode.svg | 3 + examples/vue2-vite/src/icons/icon-card2.svg | 7 ++ examples/vue2-vite/src/icons/vue.svg | 1 + examples/vue2-vite/src/main.js | 13 ++++ examples/vue2-vite/vite.config.js | 16 +++++ examples/vue2-webpack/package.json | 6 +- examples/vue2-webpack/src/App.vue | 11 ++- examples/vue2-webpack/vue.config.js | 2 +- examples/vue3-vite/package.json | 3 +- package.json | 15 +--- pnpm-lock.yaml | 64 +++++++++++------- src/core/generator.ts | 36 ++++------ src/core/snippets.ts | 1 + src/core/sprite.ts | 5 +- src/core/utils.ts | 1 + test/gen-module-code.test.ts | 2 +- 22 files changed, 175 insertions(+), 77 deletions(-) create mode 100644 examples/vue2-vite/index.html create mode 100644 examples/vue2-vite/package.json create mode 100644 examples/vue2-vite/src/App.vue create mode 100644 examples/vue2-vite/src/assets/logo.png create mode 100644 examples/vue2-vite/src/icons/icon-addUser.svg create mode 100644 examples/vue2-vite/src/icons/icon-barCode.svg create mode 100644 examples/vue2-vite/src/icons/icon-card2.svg create mode 100644 examples/vue2-vite/src/icons/vue.svg create mode 100644 examples/vue2-vite/src/main.js create mode 100644 examples/vue2-vite/vite.config.js diff --git a/examples/react-vite/package.json b/examples/react-vite/package.json index 6bb8421..b9a1521 100644 --- a/examples/react-vite/package.json +++ b/examples/react-vite/package.json @@ -1,7 +1,6 @@ { "name": "react", "type": "module", - "private": true, "scripts": { "dev": "vite", "build": "tsc && vite build", diff --git a/examples/vue2-vite/index.html b/examples/vue2-vite/index.html new file mode 100644 index 0000000..f31c3f7 --- /dev/null +++ b/examples/vue2-vite/index.html @@ -0,0 +1,12 @@ + + +
+ + + + + + + + + diff --git a/examples/vue2-vite/package.json b/examples/vue2-vite/package.json new file mode 100644 index 0000000..8a4430c --- /dev/null +++ b/examples/vue2-vite/package.json @@ -0,0 +1,16 @@ +{ + "name": "vue2-vite", + "version": "1.0.0", + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "devDependencies": { + "@vitejs/plugin-vue2": "^2.2.0", + "@vue/compiler-sfc": "^2.7.0", + "unplugin-svg-component": "workspace:*", + "vite": "^3.2.3", + "vue": "^2.7.14" + + } +} diff --git a/examples/vue2-vite/src/App.vue b/examples/vue2-vite/src/App.vue new file mode 100644 index 0000000..7605346 --- /dev/null +++ b/examples/vue2-vite/src/App.vue @@ -0,0 +1,34 @@ + + + +Rz$KlnO_H2c< z(XX#lPuW_%H#Q+c&(nRyX1-Ia dKR-%$4FYC0fsCmL9ky3 zKpxyjd^JFR+vg2!=HWf}2Z?@Td`0EG`kU?{8zKrvtsm)|7>pPk9nu@2^z96aU2<#` z2QhvH5w&V;wER?mopu+nqu*n8p~(%Q kwSs&*0eJwa zMXR05`OSFpfyRb! Y_+H@O%Y z0=K^y6B8Gcbl?SA)qMP3Z+=C(?8zL@=74R=EVnE?vY!1BQy2@q*RUgRx4yJ$k}MnL zs!?74QciNb-LcG*&o<9=DSL>1n}ZNd)w1z3-0Pd^4ED1{qd=9|!!N?xnXjM!EuylY z5=!H>&hSofh8V?Jofyd!h`xDI1fYAuV(sZwwN~{$a}MX^=+0TH*SFp$vyxmUv7C*W zv^3Gl0+eTFgBi3FVD;$nhcp)ka*4gSskYIqQ&+M}xP9yLAkWzBI^I%zR^l1e?bW_6 zIn{mo{dD=)9@V?s^fa55jh78rP*Ze<3`tRCN4*mpO$@7a^*2B*7N_|A(Ve2VB|)_o z$=#_=aBkhe(ifX}MLT()@5? OV+~7cXC3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z^T z9rrj=?I H*qI5{G@Rn&}^Z{+TW}mQe b9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk #r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VC bJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{ *ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^ 4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- + + diff --git a/examples/vue2-vite/src/icons/icon-barCode.svg b/examples/vue2-vite/src/icons/icon-barCode.svg new file mode 100644 index 0000000..c9fa084 --- /dev/null +++ b/examples/vue2-vite/src/icons/icon-barCode.svg @@ -0,0 +1,3 @@ + diff --git a/examples/vue2-vite/src/icons/icon-card2.svg b/examples/vue2-vite/src/icons/icon-card2.svg new file mode 100644 index 0000000..d08ba04 --- /dev/null +++ b/examples/vue2-vite/src/icons/icon-card2.svg @@ -0,0 +1,7 @@ + diff --git a/examples/vue2-vite/src/icons/vue.svg b/examples/vue2-vite/src/icons/vue.svg new file mode 100644 index 0000000..770e9d3 --- /dev/null +++ b/examples/vue2-vite/src/icons/vue.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/vue2-vite/src/main.js b/examples/vue2-vite/src/main.js new file mode 100644 index 0000000..50d41a9 --- /dev/null +++ b/examples/vue2-vite/src/main.js @@ -0,0 +1,13 @@ +import Vue from 'vue' +import App from './App.vue' +import MySvgIcon from '~virtual/svg-component' + +Vue.config.productionTip = false + +const app = new Vue({ + render: h => h(App), +}) + +Vue.component(MySvgIcon.name, MySvgIcon) + +app.$mount('#app') diff --git a/examples/vue2-vite/vite.config.js b/examples/vue2-vite/vite.config.js new file mode 100644 index 0000000..210bd16 --- /dev/null +++ b/examples/vue2-vite/vite.config.js @@ -0,0 +1,16 @@ +import path from 'node:path' +import { defineConfig } from 'vite' +import UnpluginSvgComponent from 'unplugin-svg-component/vite' +import vitePluginVue2 from '@vitejs/plugin-vue2' + +export default defineConfig({ + plugins: [ + vitePluginVue2(), + UnpluginSvgComponent({ + iconDir: path.resolve(__dirname, './src/icons'), + vueVersion: 'auto', + componentName: 'MySvgIcon', + preserveColor: /vue\.svg$/, + }), + ], +}) diff --git a/examples/vue2-webpack/package.json b/examples/vue2-webpack/package.json index 2886265..5dd41c3 100644 --- a/examples/vue2-webpack/package.json +++ b/examples/vue2-webpack/package.json @@ -1,6 +1,5 @@ { "name": "webpack-demo", - "private": true, "scripts": { "dev": "vue-cli-service serve", "build": "vue-cli-service build" @@ -13,8 +12,7 @@ "@babel/core": "^7.12.16", "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-service": "~5.0.0", - "unplugin-svg-component": "workspace:*", - "vue-template-compiler": "^2.7.13", - "vue-template-es2015-compiler": "^1.9.0" + "@vue/compiler-sfc": "^2.7.0", + "unplugin-svg-component": "workspace:*" } } diff --git a/examples/vue2-webpack/src/App.vue b/examples/vue2-webpack/src/App.vue index abc72b0..7605346 100644 --- a/examples/vue2-webpack/src/App.vue +++ b/examples/vue2-webpack/src/App.vue @@ -5,15 +5,20 @@ export default { return { } }, + methods: { + handleClick() { + console.log('click') + }, + }, } diff --git a/examples/vue2-webpack/vue.config.js b/examples/vue2-webpack/vue.config.js index 7991ac1..a5d1f94 100644 --- a/examples/vue2-webpack/vue.config.js +++ b/examples/vue2-webpack/vue.config.js @@ -1,4 +1,4 @@ -const path = require('path') +const path = require('node:path') const { defineConfig } = require('@vue/cli-service') const UnpluginSvgComponent = require('unplugin-svg-component/webpack').default diff --git a/examples/vue3-vite/package.json b/examples/vue3-vite/package.json index a71464b..e659394 100644 --- a/examples/vue3-vite/package.json +++ b/examples/vue3-vite/package.json @@ -1,6 +1,5 @@ { - "name": "vite-demo", - "private": true, + "name": "vue3-vite", "scripts": { "dev": "vite", "build": "vite build" diff --git a/package.json b/package.json index 028d1ec..04d36e1 100644 --- a/package.json +++ b/package.json @@ -86,20 +86,7 @@ "test": "vitest" }, "peerDependencies": { - "@vue/compiler-sfc": "^3.2.40", - "vue-template-compiler": "^2.6.12", - "vue-template-es2015-compiler": "^1.9.0" - }, - "peerDependenciesMeta": { - "@vue/compiler-sfc": { - "optional": true - }, - "vue-template-compiler": { - "optional": true - }, - "vue-template-es2015-compiler": { - "optional": true - } + "@vue/compiler-sfc": ">=2.7.0 <=3.2.47" }, "dependencies": { "cors": "^2.8.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0e24c1d..fce7b5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,26 +68,38 @@ importers: unplugin-svg-component: link:../.. vite: 3.2.5 + examples/vue2-vite: + specifiers: + '@vitejs/plugin-vue2': ^2.2.0 + '@vue/compiler-sfc': ^2.7.0 + unplugin-svg-component: workspace:* + vite: ^3.2.3 + vue: ^2.7.14 + devDependencies: + '@vitejs/plugin-vue2': 2.2.0_vite@3.2.5+vue@2.7.14 + '@vue/compiler-sfc': 2.7.14 + unplugin-svg-component: link:../.. + vite: 3.2.5 + vue: 2.7.14 + examples/vue2-webpack: specifiers: '@babel/core': ^7.12.16 '@vue/cli-plugin-babel': ~5.0.0 '@vue/cli-service': ~5.0.0 + '@vue/compiler-sfc': ^2.7.0 core-js: ^3.8.3 unplugin-svg-component: workspace:* vue: ^2.6.14 - vue-template-compiler: ^2.7.13 - vue-template-es2015-compiler: ^1.9.0 dependencies: core-js: 3.28.0 vue: 2.7.14 devDependencies: '@babel/core': 7.20.12 '@vue/cli-plugin-babel': 5.0.8_vfrs7jxtjuumwvfadksxpk7hby - '@vue/cli-service': 5.0.8_3vxek7nnw77fnzqahcoxmafvnm + '@vue/cli-service': 5.0.8_4r2fywy46pkb5e5bsf7746yn7m + '@vue/compiler-sfc': 2.7.14 unplugin-svg-component: link:../.. - vue-template-compiler: 2.7.14 - vue-template-es2015-compiler: 1.9.1 examples/vue3-vite: specifiers: @@ -2283,6 +2295,17 @@ packages: vue: 3.2.47 dev: true + /@vitejs/plugin-vue2/2.2.0_vite@3.2.5+vue@2.7.14: + resolution: {integrity: sha512-1km7zEuZ/9QRPvzXSjikbTYGQPG86Mq1baktpC4sXqsXlb02HQKfi+fl8qVS703JM7cgm24Ga9j+RwKmvFn90A==} + engines: {node: ^14.18.0 || >= 16.0.0} + peerDependencies: + vite: ^3.0.0 || ^4.0.0 + vue: ^2.7.0-0 + dependencies: + vite: 3.2.5 + vue: 2.7.14 + dev: true + /@vitest/expect/0.31.0: resolution: {integrity: sha512-Jlm8ZTyp6vMY9iz9Ny9a0BHnCG4fqBa8neCF6Pk/c/6vkUk49Ls6UBlgGAU82QnzzoaUs9E/mUhq/eq9uMOv/g==} dependencies: @@ -2487,7 +2510,7 @@ packages: dependencies: '@babel/core': 7.20.12 '@vue/babel-preset-app': 5.0.8_dof6ucvk3udqnpfayd5uczwvxe - '@vue/cli-service': 5.0.8_3vxek7nnw77fnzqahcoxmafvnm + '@vue/cli-service': 5.0.8_4r2fywy46pkb5e5bsf7746yn7m '@vue/cli-shared-utils': 5.0.8 babel-loader: 8.3.0_la66t7xldg4uecmyawueag5wkm thread-loader: 3.0.4_webpack@5.75.0 @@ -2508,7 +2531,7 @@ packages: peerDependencies: '@vue/cli-service': ^3.0.0 || ^4.0.0 || ^5.0.0-0 dependencies: - '@vue/cli-service': 5.0.8_3vxek7nnw77fnzqahcoxmafvnm + '@vue/cli-service': 5.0.8_4r2fywy46pkb5e5bsf7746yn7m '@vue/cli-shared-utils': 5.0.8 transitivePeerDependencies: - encoding @@ -2519,10 +2542,10 @@ packages: peerDependencies: '@vue/cli-service': ^3.0.0 || ^4.0.0 || ^5.0.0-0 dependencies: - '@vue/cli-service': 5.0.8_3vxek7nnw77fnzqahcoxmafvnm + '@vue/cli-service': 5.0.8_4r2fywy46pkb5e5bsf7746yn7m dev: true - /@vue/cli-service/5.0.8_3vxek7nnw77fnzqahcoxmafvnm: + /@vue/cli-service/5.0.8_4r2fywy46pkb5e5bsf7746yn7m: resolution: {integrity: sha512-nV7tYQLe7YsTtzFrfOMIHc5N2hp5lHG2rpYr0aNja9rNljdgcPZLyQRb2YRivTHqTv7lI962UXFURcpStHgyFw==} engines: {node: ^12.0.0 || >= 14.0.0} hasBin: true @@ -2562,7 +2585,7 @@ packages: '@vue/cli-plugin-vuex': 5.0.8_@vue+cli-service@5.0.8 '@vue/cli-shared-utils': 5.0.8 '@vue/component-compiler-utils': 3.3.0 - '@vue/vue-loader-v15': /vue-loader/15.10.1_y5o36p7qrshhm4v7l6yk7rwfsu + '@vue/vue-loader-v15': /vue-loader/15.10.1_fxcgrrlws65jeno5qa4wlljt4e '@vue/web-component-wrapper': 1.3.0 acorn: 8.8.2 acorn-walk: 8.2.0 @@ -2599,9 +2622,8 @@ packages: ssri: 8.0.1 terser-webpack-plugin: 5.3.6_webpack@5.75.0 thread-loader: 3.0.4_webpack@5.75.0 - vue-loader: 17.0.1_vue@2.7.14+webpack@5.75.0 + vue-loader: 17.0.1_3w3mfv4lojkhslia7fw4xoexcy vue-style-loader: 4.1.3 - vue-template-compiler: 2.7.14 webpack: 5.75.0 webpack-bundle-analyzer: 4.8.0 webpack-chain: 6.5.1 @@ -4256,10 +4278,6 @@ packages: time-zone: 1.0.0 dev: true - /de-indent/1.0.2: - resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} - dev: true - /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -9571,7 +9589,7 @@ packages: resolution: {integrity: sha512-BXq3jwIagosjgNVae6tkHzzIk6a8MHFtzAdwhnV5VlvPTFxDCvIttgSiHWjdGoTJvXtmRu5HacExfdarRcFhog==} dev: true - /vue-loader/15.10.1_y5o36p7qrshhm4v7l6yk7rwfsu: + /vue-loader/15.10.1_fxcgrrlws65jeno5qa4wlljt4e: resolution: {integrity: sha512-SaPHK1A01VrNthlix6h1hq4uJu7S/z0kdLUb6klubo738NeQoLbS6V9/d8Pv19tU0XdQKju3D1HSKuI8wJ5wMA==} peerDependencies: '@vue/compiler-sfc': ^3.0.8 @@ -9587,13 +9605,13 @@ packages: vue-template-compiler: optional: true dependencies: + '@vue/compiler-sfc': 2.7.14 '@vue/component-compiler-utils': 3.3.0 css-loader: 6.7.3_webpack@5.75.0 hash-sum: 1.0.2 loader-utils: 1.4.2 vue-hot-reload-api: 2.3.4 vue-style-loader: 4.1.3 - vue-template-compiler: 2.7.14 webpack: 5.75.0 transitivePeerDependencies: - arc-templates @@ -9651,7 +9669,7 @@ packages: - whiskers dev: true - /vue-loader/17.0.1_vue@2.7.14+webpack@5.75.0: + /vue-loader/17.0.1_3w3mfv4lojkhslia7fw4xoexcy: resolution: {integrity: sha512-/OOyugJnImKCkAKrAvdsWMuwoCqGxWT5USLsjohzWbMgOwpA5wQmzQiLMzZd7DjhIfunzAGIApTOgIylz/kwcg==} peerDependencies: '@vue/compiler-sfc': '*' @@ -9663,6 +9681,7 @@ packages: vue: optional: true dependencies: + '@vue/compiler-sfc': 2.7.14 chalk: 4.1.2 hash-sum: 2.0.0 loader-utils: 2.0.4 @@ -9677,13 +9696,6 @@ packages: loader-utils: 1.4.2 dev: true - /vue-template-compiler/2.7.14: - resolution: {integrity: sha512-zyA5Y3ArvVG0NacJDkkzJuPQDF8RFeRlzV2vLeSnhSpieO6LK2OVbdLPi5MPPs09Ii+gMO8nY4S3iKQxBxDmWQ==} - dependencies: - de-indent: 1.0.2 - he: 1.2.0 - dev: true - /vue-template-es2015-compiler/1.9.1: resolution: {integrity: sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==} dev: true diff --git a/src/core/generator.ts b/src/core/generator.ts index dd1b786..a0d2600 100644 --- a/src/core/generator.ts +++ b/src/core/generator.ts @@ -1,5 +1,5 @@ -import path from 'path' -import fs from 'fs/promises' +import path from 'node:path' +import fs from 'node:fs/promises' import { getPackageInfo, importModule, isPackageExists } from 'local-pkg' import type { Options, VueVersion } from '../types' import { dts, golbalDts, reactDts, reactTemplate, template } from './snippets' @@ -99,14 +99,13 @@ async function genComponent(options: Options, isVueProject: boolean) { if (!vueVerison) return 'export default {}' - const compilers = { - vue2: compileVue2Template, - vue3: compileVue3Template, - } + const tempTemplate = vueVerison === 'vue3' + ? template.replace('v-on="$listeners"', '') + : template - const processedTemplate = template.replace(/\$component_style/, componentStyle!) + const processedTemplate = tempTemplate.replace(/\$component_style/, componentStyle!) - let code = await compilers[vueVerison](processedTemplate) + let code = await compileVueTemplate(processedTemplate, vueVerison) code += ` \nexport default{ @@ -122,8 +121,12 @@ async function genComponent(options: Options, isVueProject: boolean) { return code } -async function compileVue3Template(template: string): Promise-
- - + + + { - const { compileTemplate } = await importModule('@vue/compiler-sfc') +async function compileVueTemplate(template: string, vueVerison: string): Promise { + const pkgInfo = await getPackageInfo('@vue/compiler-sfc') + if (pkgInfo?.version[0] !== vueVerison.slice(-1)) + throw new Error(`The current major version of @vue/compiler-sfc(${pkgInfo?.version[0]}.x.x) is not matching the major version of Vue(${vueVerison.slice(-1)}.x.x).`) + const pkg = await importModule('@vue/compiler-sfc') + const { compileTemplate } = pkg const { code } = compileTemplate({ source: template, id: '__svg-component__', @@ -132,19 +135,6 @@ async function compileVue3Template(template: string): Promise { return code.replace(/export/g, '') } -async function compileVue2Template(template: string): Promise { - const { compile } = await importModule('vue-template-compiler') - const transpile = (await importModule('vue-template-es2015-compiler')).default - const { render } = compile(template) - const toFunction = (code: string): string => { - return `function () {${code}}` - } - const res = transpile(`var __render__ = ${toFunction(render as any)}\n`, {}) - const code = res.replace(/\s__(render|staticRenderFns)__\s/g, ' $1 ') - - return code -} - async function getVueVersion(vueVerison: VueVersion): Promise<'vue2' | 'vue3' | null > { if (vueVerison === 'auto') { try { diff --git a/src/core/snippets.ts b/src/core/snippets.ts index 5e88750..015bb16 100644 --- a/src/core/snippets.ts +++ b/src/core/snippets.ts @@ -5,6 +5,7 @@ export const template = ` xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="$component_style" + v-on="$listeners" > diff --git a/src/core/sprite.ts b/src/core/sprite.ts index e1e52d5..53b1e63 100644 --- a/src/core/sprite.ts +++ b/src/core/sprite.ts @@ -1,5 +1,5 @@ -import path from 'path' -import fs from 'fs/promises' +import path from 'node:path' +import fs from 'node:fs/promises' import fg from 'fast-glob' import { optimize } from 'svgo' import SvgCompiler from 'svg-baker' @@ -71,6 +71,7 @@ export async function createSymbol( } } +// eslint-disable-next-line n/prefer-global/buffer async function optimizeSvg(source: Buffer, preserveColor: boolean, optimizeOptions?: OptimizeOptions) { const { data: optimizedSvgContent } = await optimize(source, optimizeOptions) as OptimizedSvg if (preserveColor) { diff --git a/src/core/utils.ts b/src/core/utils.ts index a2247fa..d229ddc 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -8,6 +8,7 @@ export function debounce(fn: (...args: any) => void, delay: number) { clearTimeout(timer) timer = setTimeout(() => { // @ts-expect-error: this + // eslint-disable-next-line @typescript-eslint/no-invalid-this fn.apply(this, args) clearTimeout(timer) }, delay) diff --git a/test/gen-module-code.test.ts b/test/gen-module-code.test.ts index 9dbdabf..e212380 100644 --- a/test/gen-module-code.test.ts +++ b/test/gen-module-code.test.ts @@ -1,4 +1,4 @@ -import path from 'path' +import path from 'node:path' import { expect, test } from 'vitest' import { genCode } from '../src/core/generator'