Skip to content

Commit f00c0de

Browse files
committed
fix: js detype error when missing local reference to props
1 parent 5147bd9 commit f00c0de

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/cli/src/utils/updaters/update-files.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Config } from '@/src/utils/get-config'
22
import type { RegistryItem } from '@/src/utils/registry/schema'
33
import { existsSync, promises as fs } from 'node:fs'
4+
import os from 'node:os'
45
import { getProjectInfo } from '@/src/utils/get-project-info'
56
import { highlighter } from '@/src/utils/highlighter'
67
import { logger } from '@/src/utils/logger'
@@ -60,6 +61,23 @@ export async function updateFiles(
6061
const folderSkipped = new Map<string, boolean>()
6162
const filesSkipped = []
6263

64+
let tempRoot = ''
65+
if (!config.typescript) {
66+
for (const file of files) {
67+
if (!file.content) {
68+
continue
69+
}
70+
const dirName = path.dirname(file.path)
71+
tempRoot = path.join(os.tmpdir(), 'shadcn-vue')
72+
73+
// Create the full temp directory path with original directory structure
74+
const tempDir = path.join(tempRoot, dirName)
75+
76+
await fs.mkdir(tempDir, { recursive: true })
77+
await fs.writeFile(path.join(tempRoot, file.path), file.content, 'utf-8')
78+
}
79+
}
80+
6381
for (const file of files) {
6482
if (!file.content) {
6583
continue
@@ -133,7 +151,7 @@ export async function updateFiles(
133151

134152
// Run our transformers.
135153
const content = await transform({
136-
filename: file.path,
154+
filename: path.join(tempRoot, file.path),
137155
raw: file.content,
138156
config,
139157
baseColor,
@@ -145,6 +163,11 @@ export async function updateFiles(
145163
: filesCreated.push(path.relative(config.resolvedPaths.cwd, filePath))
146164
}
147165

166+
// Perform clean up if there's tempRoot generated for compiler-sfc to parse
167+
if (tempRoot) {
168+
await fs.rm(tempRoot, { recursive: true })
169+
}
170+
148171
const hasUpdatedFiles = filesCreated.length || filesUpdated.length
149172
if (!hasUpdatedFiles && !filesSkipped.length) {
150173
filesCreatedSpinner?.info('No files updated.')

0 commit comments

Comments
 (0)