generated from hemengke1997/ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed manifest being undefined under ssr or standalone env
- Loading branch information
1 parent
25e470e
commit 743e58f
Showing
22 changed files
with
201 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { type OptionsTypeWithDefault } from './utils' | ||
|
||
export const DEFAULT_OPTIONS: OptionsTypeWithDefault = { | ||
destination: 'memory', | ||
esbuildOptions: {}, | ||
hash: true, | ||
inputDir: 'public-typescript', | ||
manifestName: 'manifest', | ||
outputDir: '/', | ||
cacheDir: 'node_modules/.vite-plugin-public-typescript', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import createDebug from 'debug' | ||
import fs from 'fs-extra' | ||
import path from 'node:path' | ||
import { globalConfig } from '../global-config' | ||
import { extractHashFromFileName, linebreak } from './utils' | ||
|
||
const debug = createDebug('vite-plugin-public-typescript:io ===> ') | ||
|
||
export function detectLastLine(string: string) { | ||
const last = string.at(-1) || '' | ||
|
||
return /(?:\r?\n)/g.test(last) | ||
} | ||
|
||
const newline = /\r\n|\r|\n/g | ||
export function setEol(text: string) { | ||
if (!detectLastLine(text)) { | ||
text += linebreak | ||
} | ||
|
||
return text.replaceAll(newline, linebreak) | ||
} | ||
|
||
export function readJsonFile(file: string): Record<string, string> { | ||
if (!fs.existsSync(file)) { | ||
return {} | ||
} | ||
|
||
const cacheJson = fs.readFileSync(file, 'utf-8') | ||
if (cacheJson) { | ||
return JSON.parse(cacheJson) | ||
} | ||
|
||
return {} | ||
} | ||
|
||
export function writeFile(filename: string, content: string, hash = true): void { | ||
const dir = path.dirname(filename) | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir, { recursive: true }) | ||
} | ||
|
||
const newContent = setEol(content) | ||
|
||
if (fs.existsSync(filename)) { | ||
if (hash) { | ||
const _hash = globalConfig.get().hash | ||
if (extractHashFromFileName(filename, _hash)) { | ||
// if filename has hash, skip write file | ||
debug('skip writeFile, filename has hash') | ||
return | ||
} | ||
} | ||
|
||
// Read content first | ||
// if content is same, skip write file | ||
const oldContent = fs.readFileSync(filename, 'utf-8') | ||
debug('oldContent:', oldContent, 'newContent:', newContent) | ||
if (oldContent && newContent === oldContent) { | ||
debug('skip writeFile, content is same with old content:', oldContent) | ||
return | ||
} | ||
} | ||
|
||
fs.writeFileSync(filename, newContent) | ||
|
||
debug('writeFile success:', filename) | ||
} | ||
|
||
export function writeJsonFile(filename: string, content: Record<string, string>) { | ||
const formattedContent = JSON.stringify(content || {}, null, 2) | ||
writeFile(filename, formattedContent, false) | ||
return true | ||
} |
Oops, something went wrong.