Skip to content

Commit e3298e4

Browse files
authored
fix(vscode): update process handling and add workaround for jiti's babel.cjs (#4951)
1 parent b108906 commit e3298e4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages-integrations/vscode/src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { FilterPattern } from 'unplugin-utils'
22
import type { ExtensionContext, StatusBarItem } from 'vscode'
33
import path, { dirname } from 'path'
4-
import process from 'process'
54
import { defaultPipelineExclude, defaultPipelineInclude } from '#integration/defaults'
65
import { toArray } from '@unocss/core'
76
import { findUp } from 'find-up'
@@ -19,10 +18,6 @@ const skipMap = {
1918
}
2019

2120
export async function activate(ext: ExtensionContext) {
22-
// Neither Jiti2 nor Tsx supports running in VS Code yet
23-
// We have to use Jiti1 for now
24-
process.env.IMPORTX_LOADER = 'jiti-v1'
25-
2621
log.appendLine(`⚪️ UnoCSS for VS Code v${version}\n`)
2722

2823
const projectPath = workspace.workspaceFolders?.[0].uri.fsPath

packages-integrations/vscode/tsup.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { copyFile } from 'node:fs/promises'
2+
import { dirname, join } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
14
import { defineConfig } from 'tsup'
25

36
export default defineConfig({
@@ -19,4 +22,16 @@ export default defineConfig({
1922
'.CMD': 'file',
2023
'.md': 'file',
2124
},
25+
clean: true,
26+
onSuccess: async () => {
27+
// Copy jiti's babel.cjs to dist/babel.cjs as workaround for https://github.com/unocss/unocss/issues/4944
28+
// jiti has hardcoded: require('../dist/babel.cjs') which esbuild cannot resolve correctly
29+
// From dist/*.cjs -> ../dist/babel.cjs resolves to dist/babel.cjs
30+
const jitiPath = dirname(fileURLToPath(import.meta.resolve('jiti/package.json')))
31+
const babelSource = join(jitiPath, 'dist', 'babel.cjs')
32+
const babelDest = join(import.meta.dirname, 'dist', 'babel.cjs')
33+
34+
await copyFile(babelSource, babelDest)
35+
console.log('✓ Copied babel.cjs to dist/')
36+
},
2237
})

0 commit comments

Comments
 (0)