Skip to content

Commit

Permalink
fix: sync removing ts file with js
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Feb 1, 2023
1 parent ed63d13 commit d59abad
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 15 deletions.
1 change: 0 additions & 1 deletion playground/spa/public/a.d43b8524.js

This file was deleted.

1 change: 0 additions & 1 deletion playground/spa/public/spa.d43b8524.js

This file was deleted.

2 changes: 0 additions & 2 deletions playground/spa/publicTypescript/a.ts

This file was deleted.

5 changes: 1 addition & 4 deletions playground/spa/publicTypescript/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
{
"a": "/a.d43b8524.js",
"spa": "/spa.d43b8524.js"
}
{}
2 changes: 0 additions & 2 deletions playground/spa/publicTypescript/spa.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const defaultOptions: Required<VitePluginOptions> = {
sideEffects: false,
}

const cache = new ManifestCache()

export function publicTypescript(options: VitePluginOptions = {}) {
const opts = {
...defaultOptions,
Expand All @@ -65,7 +67,6 @@ export function publicTypescript(options: VitePluginOptions = {}) {
let config: ResolvedConfig
let files: string[]
let buildLength = 0
const cache = new ManifestCache()

const plugins: PluginOption = [
{
Expand Down Expand Up @@ -107,7 +108,7 @@ export function publicTypescript(options: VitePluginOptions = {}) {
if (
isPublicTypescript({
filePath: ctx.file,
inputDir: opts.inputDir!,
inputDir: opts.inputDir,
root: config.root,
})
) {
Expand Down
5 changes: 2 additions & 3 deletions src/utils/manifestCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ export class ManifestCache {
Object.keys(cacheObj)
.sort()
.forEach((k) => (orderdCache[k] = cacheObj[k]))

await fs.ensureDir(path.dirname(targetPath))
if (Object.keys(orderdCache).length) {
await fs.writeFile(targetPath, crlf(`${JSON.stringify(orderdCache, null, 2)}`))
}
await fs.writeFile(targetPath, crlf(`${JSON.stringify(orderdCache || {}, null, 2)}`))
}
}

0 comments on commit d59abad

Please sign in to comment.