1- import { copyFileSync , existsSync , mkdirSync , writeFileSync } from 'node:fs'
1+ import { existsSync } from 'node:fs'
2+ import { copyFile , mkdir , writeFile } from 'node:fs/promises'
23import { join } from 'node:path'
34import process from 'node:process'
45import { fileURLToPath } from 'node:url'
@@ -7,51 +8,51 @@ import { defineConfig } from 'tsdown'
78import { generateCodeblockPatch } from './syntaxes/codeblock-patch.ts'
89
910export default defineConfig ( {
10- // @ts -expect-error `entry` is valid option
1111 entry : {
1212 'index' : 'src/index.ts' ,
1313 'language-server' : 'language-server/bin.ts' ,
1414 } ,
1515 format : 'cjs' ,
16- target : 'node18 ' ,
16+ target : 'node20 ' ,
1717 clean : true ,
1818 minify : process . env . NODE_ENV === 'production' ,
1919 sourcemap : true ,
2020 external : [
2121 'vscode' ,
2222 ] ,
23- shims : [ './language-server/import-meta-url.ts' ] ,
24- define : {
25- 'import.meta.url' : 'import_meta_url' ,
26- } ,
2723 alias : {
2824 '@slidev/parser/fs' : fileURLToPath ( new URL ( '../parser/src/fs.ts' , import . meta. url ) ) ,
2925 '@slidev/parser/core' : fileURLToPath ( new URL ( '../parser/src/core.ts' , import . meta. url ) ) ,
3026 '@slidev/parser/types' : fileURLToPath ( new URL ( '../parser/src/types.ts' , import . meta. url ) ) ,
3127 '@slidev/parser' : fileURLToPath ( new URL ( '../parser/src/index.ts' , import . meta. url ) ) ,
3228 } ,
33- plugins : [ {
34- name : 'umd2esm' ,
35- setup ( build : any ) {
36- build . onResolve ( { filter : / ^ ( v s c o d e - .* - l a n g u a g e s e r v i c e | j s o n c - p a r s e r ) / } , async ( args : any ) => {
37- const pathUmdMay = await resolvePath ( args . path , { url : args . resolveDir } )
38- // Call twice the replace is to solve the problem of the path in Windows
39- const pathEsm = pathUmdMay . replace ( '/umd/' , '/esm/' ) . replace ( '\\umd\\' , '\\esm\\' )
40- return { path : pathEsm }
41- } )
29+ plugins : [
30+ {
31+ name : 'umd2esm' ,
32+ resolveId : {
33+ filter : {
34+ id : / ^ ( v s c o d e - .* - l a n g u a g e s e r v i c e | v s c o d e - l a n g u a g e s e r v e r - t y p e s | j s o n c - p a r s e r ) / ,
35+ } ,
36+ async handler ( source , importer ) {
37+ const pathUmdMay = await resolvePath ( source , { url : importer } )
38+ // Call twice the replace is to solve the problem of the path in Windows
39+ const pathEsm = pathUmdMay . replace ( '/umd/' , '/esm/' ) . replace ( '\\umd\\' , '\\esm\\' )
40+ return { id : pathEsm }
41+ } ,
42+ } ,
4243 } ,
43- } ] ,
44+ ] ,
4445 async onSuccess ( ) {
4546 const assetsDir = join ( import . meta. dirname , '../../assets' )
4647 const resDir = join ( import . meta. dirname , './dist/res' )
4748
4849 if ( ! existsSync ( resDir ) )
49- mkdirSync ( resDir , { recursive : true } )
50+ await mkdir ( resDir , { recursive : true } )
5051
5152 for ( const file of [ 'logo-mono.svg' , 'logo-mono-dark.svg' , 'logo.png' , 'logo.svg' ] )
52- copyFileSync ( join ( assetsDir , file ) , join ( resDir , file ) )
53+ await copyFile ( join ( assetsDir , file ) , join ( resDir , file ) )
5354
54- writeFileSync (
55+ await writeFile (
5556 join ( import . meta. dirname , 'syntaxes/codeblock-patch.json' ) ,
5657 JSON . stringify ( generateCodeblockPatch ( ) , null , 2 ) ,
5758 )
0 commit comments