Skip to content

Commit 64604e1

Browse files
committed
chore: clean up dead code
1 parent 4c85507 commit 64604e1

File tree

2 files changed

+6
-47
lines changed

2 files changed

+6
-47
lines changed

src/context.ts

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { relative } from 'path'
22
import Debug from 'debug'
33
import { ResolvedConfig } from 'vite'
4-
import { ComponentInfo, ComponentsImportMap, ResolvedOptions } from './types'
5-
import { pascalCase, toArray, getNameFromFilePath, resolveAlias, kebabCase } from './utils'
4+
import { ComponentInfo, ResolvedOptions } from './types'
5+
import { pascalCase, toArray, getNameFromFilePath, resolveAlias } from './utils'
66
import { searchComponents } from './fs/glob'
77

88
const debug = {
@@ -15,8 +15,6 @@ export class Context {
1515

1616
private _componentPaths = new Set<string>()
1717
private _componentNameMap: Record<string, ComponentInfo> = {}
18-
private _imports: ComponentsImportMap = {}
19-
private _importsResolveTasks: Record<string, [(null | Promise<string[]>), (null | ((result: string[]) => void))]> = {}
2018

2119
constructor(
2220
public readonly options: ResolvedOptions,
@@ -34,8 +32,6 @@ export class Context {
3432
? `${i}/**/*.${extsGlob}`
3533
: `${i}/*.${extsGlob}`,
3634
)
37-
38-
this.searchGlob()
3935
}
4036

4137
get root() {
@@ -62,12 +58,6 @@ export class Context {
6258
return false
6359
}
6460

65-
findReferencesOfComponentName(name: string) {
66-
return Object.entries(this._imports)
67-
.map(([path, components]) => components?.includes(name) ? path : undefined)
68-
.filter(Boolean) as string[]
69-
}
70-
7161
private updateComponentNameMap() {
7262
this._componentNameMap = {}
7363

@@ -131,35 +121,6 @@ export class Context {
131121
return relative(this.root, path).replace(/\\/g, '/')
132122
}
133123

134-
setImports(key: string, names: string[]) {
135-
const casedNames = names.map(name => pascalCase(name))
136-
this._imports[key] = casedNames
137-
if (this._importsResolveTasks[key])
138-
this._importsResolveTasks[key][1]?.(casedNames)
139-
return key
140-
}
141-
142-
/**
143-
* Await for imports to get resolved
144-
*
145-
* @param ctx
146-
* @param force
147-
*/
148-
async getImports(key: string) {
149-
if (this._imports[key])
150-
return this._imports[key]
151-
152-
if (!this._importsResolveTasks[key]) {
153-
this._importsResolveTasks[key] = [null, null]
154-
const p = new Promise<string[]>((resolve) => {
155-
this._importsResolveTasks[key][1] = resolve
156-
})
157-
this._importsResolveTasks[key][0] = p
158-
}
159-
160-
return await Promise.resolve(this._importsResolveTasks[key][0])
161-
}
162-
163124
private _searched = 0
164125

165126
/**

src/transforms/vue.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export function VueTransformer(ctx: Context): Transformer {
1212

1313
if (ctx.viteConfig?.command === 'serve')
1414
ctx.searchGlob(500)
15+
else
16+
ctx.searchGlob()
1517

16-
const isBuild = ctx.viteConfig?.isProduction
1718
const sfcPath = ctx.normalizePath(path)
1819
debug(sfcPath)
1920

@@ -34,12 +35,9 @@ export function VueTransformer(ctx: Context): Transformer {
3435
return str
3536
})
3637

37-
transformed = `${head.join('\n')}\n${transformed}`
38-
39-
// debug(transformed)
38+
debug(`^ (${no})`)
4039

41-
if (isBuild)
42-
ctx.setImports(sfcPath, [])
40+
transformed = `${head.join('\n')}\n${transformed}`
4341

4442
return transformed
4543
}

0 commit comments

Comments
 (0)