Skip to content

Commit

Permalink
fix: crlf
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Feb 9, 2023
1 parent c2bc7b1 commit 8477981
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
node_modules
**/*.js
manifest.json
4 changes: 2 additions & 2 deletions src/utils/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { name } from '../../package.json'
import type { VPPTPluginOptions } from '..'
import { getGlobalConfig } from './globalConfig'
import { assert } from './assert'
import { crlf } from '.'
import { writeFile } from '.'

export function getContentHash(chunk: string | Uint8Array | undefined, hash?: VPPTPluginOptions['hash']) {
if (!chunk) return ''
Expand Down Expand Up @@ -181,6 +181,6 @@ export async function addJsFile(args: IAddFile) {

const fp = normalizePath(path.join(publicDir, outPath))
await fs.ensureDir(path.dirname(fp))
await fs.writeFile(fp, crlf(code))
await writeFile(fp, code)
cache.setCache({ key: fileName, value: outPath })
}
9 changes: 9 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path'
import type { WebSocketServer } from 'vite'
import { normalizePath } from 'vite'
import fs from 'fs-extra'

export const ts = '.ts'

Expand Down Expand Up @@ -41,3 +42,11 @@ export function eq<T extends Record<string, any>>(obj1: T, obj2: T): boolean {
export function isEmptyObject(o: unknown) {
return isObject(o) && Object.keys(o).length === 0
}

export function writeFile(filename: string, content: string | Uint8Array): void {
const dir = path.dirname(filename)
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true })
}
fs.writeFileSync(filename, content)
}
4 changes: 2 additions & 2 deletions src/utils/manifestCache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import fs from 'fs-extra'
import onChange from 'on-change'
import { crlf, eq, isEmptyObject } from '.'
import { eq, isEmptyObject, writeFile } from '.'

interface CacheType {
key: string
Expand Down Expand Up @@ -83,6 +83,6 @@ export class ManifestCache {
return
}

await fs.writeFile(targetPath, crlf(`${JSON.stringify(orderdCache || {}, null, 2)}`))
writeFile(targetPath, `${JSON.stringify(orderdCache || {}, null, 2)}`)
}
}

0 comments on commit 8477981

Please sign in to comment.