Skip to content

Commit

Permalink
Apply format
Browse files Browse the repository at this point in the history
  • Loading branch information
macropygia committed Jun 1, 2024
1 parent b2c3b3f commit 0b0b783
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 51 deletions.
8 changes: 4 additions & 4 deletions packages/pug-graph/__tests__/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ describe('Multiple Files', () => {
})
const files = fg.sync('__tests__/src/**/*.pug')
await Promise.all(
files.map((file) => graph.parse(file, { insertOnly: true }))
files.map((file) => graph.parse(file, { insertOnly: true })),
)
})
test('getImportedFiles', async () => {
expect(
JSON.stringify([...graph.getImportedFiles(indexPug)])
JSON.stringify([...graph.getImportedFiles(indexPug)]),
).toMatchSnapshot()
})
test('getImporters', async () => {
expect(
JSON.stringify([...graph.getImporters(templatePug)])
JSON.stringify([...graph.getImporters(templatePug)]),
).toMatchSnapshot()
})
test('getImporters (ignorePartial)', async () => {
expect(
JSON.stringify([...graph.getImporters(templatePug, true)])
JSON.stringify([...graph.getImporters(templatePug, true)]),
).toMatchSnapshot()
})
test('getRawData', async () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/pug-graph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class PugGraph {
filepath: string,
sliceSize = 100,
encoding: BufferEncoding = 'utf8',
linefeed = '\n'
linefeed = '\n',
): Promise<Set<string>> {
const readStream = createReadStream(filepath, { encoding })
// 未処理文字列バッファ
Expand All @@ -208,7 +208,7 @@ class PugGraph {
// コメント判定のために順序の保証が必要
Object.assign(
accumulator,
this.#parseLines(filepath, lines.splice(0, sliceSize), accumulator)
this.#parseLines(filepath, lines.splice(0, sliceSize), accumulator),
)
}
}
Expand All @@ -226,7 +226,7 @@ class PugGraph {
#parseLines(
filepath: string,
lines: string[],
accumulator: ParseLinesAccumulator
accumulator: ParseLinesAccumulator,
): ParseLinesAccumulator {
// ループバック展開
const { deps } = accumulator
Expand Down Expand Up @@ -286,7 +286,7 @@ class PugGraph {
settings: Partial<ParseSettigs> = {
recursive: false,
insertOnly: false,
}
},
) {
// HTMLやSVGを読み込んで更に依存関係が続いている場合もあるが
// 現時点ではパーサを組み込んでいないためスキップ
Expand All @@ -308,7 +308,7 @@ class PugGraph {
if (!settings.updateDescendants && this.#existsRecord(dep))
return null
return this.parse(dep, settings)
})
}),
)
}
}
Expand All @@ -323,7 +323,7 @@ class PugGraph {
*/
getImportedFiles(
filepath: string,
importedFiles: Set<string> = new Set()
importedFiles: Set<string> = new Set(),
): Set<string> {
const result: DepsResult | null = this.#deps.findOne({ path: filepath })
if (result && result.deps.length > 0) {
Expand All @@ -348,7 +348,7 @@ class PugGraph {
getImporters(
filepath: string,
ignorePartial = false,
importers: Set<string> = new Set()
importers: Set<string> = new Set(),
): Set<string> {
const result: DepsRecord[] = this.#deps.find({
deps: { $contains: filepath },
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-connect-middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Connect, Plugin } from 'vite'
export type Middleware = (
req: Connect.IncomingMessage,
res: http.ServerResponse,
next: Connect.NextFunction
next: Connect.NextFunction,
) => void | http.ServerResponse | Promise<void | http.ServerResponse>

export type Settings =
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-glob-input/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const convertFilesToInput = (
settings: Settings,
config: ResolvedConfig,
input: Record<string, string>,
targetFiles: string[]
targetFiles: string[],
): Record<string, string> => {
targetFiles.forEach((targetFile) => {
const parsedRelPath = path.parse(path.relative(config.root, targetFile))
Expand Down Expand Up @@ -100,7 +100,7 @@ const vitePluginGlobInput = (userSettings: UserSettings): Plugin => {
settings,
config,
input,
targetFiles
targetFiles,
)

return options
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-imagemin-cache/src/cachebuster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function cachebuster(code: string, prefix: string | true): string {
const replacementString = `__VITE_ASSET__${hash}__$_${updatePostfix(
postfix,
typeof prefix === 'string' ? prefix : '?',
hash!
hash!,
)}__`
s.overwrite(match.index, match.index + full!.length, replacementString, {
contentOnly: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-imagemin-cache/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function initContext(config: Settings): Context {
cacheDb: new CacheDb(
path.join(config.cacheDir, 'cache.db'),
config.expireDuration,
config.countToExpire
config.countToExpire,
),
excludeMatcher: initMatcher(config.exclude),
targetExtentions: new Set(),
Expand All @@ -92,7 +92,7 @@ export function initContext(config: Settings): Context {
export function updateViteUserConfig(
ctx: Context,
config: Settings,
viteUserConfig: UserConfig
viteUserConfig: UserConfig,
) {
const root = getResolvedRoot(viteUserConfig.root)
ctx.publicDir = getResolvedPublicDir(viteUserConfig.publicDir, root)
Expand Down
6 changes: 3 additions & 3 deletions packages/vite-plugin-imagemin-cache/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CacheDb {
(obj: CacheDocument) => {
obj.expirationCountdown = obj.expirationCountdown - 1
return obj
}
},
)
}

Expand All @@ -52,7 +52,7 @@ class CacheDb {
obj.expirationCountdown = this.#countToExpire
obj.lastProcessed = now
return obj
}
},
)
}

Expand Down Expand Up @@ -94,7 +94,7 @@ class CacheDb {
upsertPublic(
fileName: string,
checksum: number,
now: number = new Date().getTime()
now: number = new Date().getTime(),
) {
const result = this.#coll.findOne({ fileName })
if (result) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-imagemin-cache/src/keepStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Context } from './types.js'

export function setupRollupOptionsForKeepStructure(
ctx: Context,
config: UserConfig
config: UserConfig,
): UserConfig {
const root = getResolvedRoot(config.root)
let defaultAssetFileNames = 'assets/[name].[hash].[ext]' // Same as Vite
Expand Down
9 changes: 4 additions & 5 deletions packages/vite-plugin-imagemin-cache/src/processAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { imageProcessor } from './imageProcessor.js'
export async function processAsset(
ctx: Context,
viteConfig: ResolvedConfig,
bundle: Rollup.OutputBundle
bundle: Rollup.OutputBundle,
) {
// Add files to compressing queue
const queue = [...ctx.assetTargets].map(async (fileName) => {
Expand All @@ -33,9 +33,8 @@ export async function processAsset(

// Use cache if it exists
if (fse.existsSync(cachePath)) {
;(bundle[fileName] as Rollup.OutputAsset).source = await fse.readFile(
cachePath
)
;(bundle[fileName] as Rollup.OutputAsset).source =
await fse.readFile(cachePath)
ctx.outputLog('info', 'cache hit:', fileName)
return
}
Expand All @@ -57,7 +56,7 @@ export async function processAsset(
'info',
'compressed:',
fileName,
`(processing: ${ctx.limit.activeCount.toString()}, pending: ${ctx.limit.pendingCount.toString()})`
`(processing: ${ctx.limit.activeCount.toString()}, pending: ${ctx.limit.pendingCount.toString()})`,
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { imageProcessor } from './imageProcessor.js'

export async function processAssetWithoutHash(
ctx: Context,
bundle: Rollup.OutputBundle
bundle: Rollup.OutputBundle,
) {
// Add files to compressing queue
const queue = [...ctx.assetTargets].map(async (fileName) => {
Expand All @@ -32,9 +32,8 @@ export async function processAssetWithoutHash(
cacheData.checksum === checksum && // Checksum match
fse.existsSync(cachePath) // File exists
) {
;(bundle[fileName] as Rollup.OutputAsset).source = await fse.readFile(
cachePath
)
;(bundle[fileName] as Rollup.OutputAsset).source =
await fse.readFile(cachePath)
ctx.outputLog('info', 'cache hit:', fileName)
return
} else {
Expand All @@ -51,7 +50,7 @@ export async function processAssetWithoutHash(
'info',
'compressed:',
fileName,
`(processing: ${ctx.limit.activeCount.toString()}, pending: ${ctx.limit.pendingCount.toString()})`
`(processing: ${ctx.limit.activeCount.toString()}, pending: ${ctx.limit.pendingCount.toString()})`,
)
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-imagemin-cache/src/processCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function processCache(ctx: Context, now: number) {
await Promise.all(
expiredFiles.map((file): Promise<void> => {
return fse.remove(path.join(config.cacheDir, file.fileName))
})
}),
)
cacheDb.removeExpired(now)

Expand Down
10 changes: 5 additions & 5 deletions packages/vite-plugin-imagemin-cache/src/processPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ const getTargets = (ctx: Context): Set<string> => {
(ext) =>
`${path
.relative(process.cwd(), ctx.publicDir)
.replaceAll(path.sep, '/')}/**/*${ext}`
)
.replaceAll(path.sep, '/')}/**/*${ext}`,
),
)
// Convert cwd relative path to root relative path
return new Set(
fgResults.flatMap((relPath) => {
const fileName = path.relative(
ctx.publicDir,
path.join(process.cwd(), relPath)
path.join(process.cwd(), relPath),
)
if (ctx.excludeMatcher && ctx.excludeMatcher(fileName)) return []
return fileName
})
}),
)
}

Expand Down Expand Up @@ -82,7 +82,7 @@ export async function processPublic(ctx: Context, viteConfig: ResolvedConfig) {
'info',
'compressed:',
fileName,
`(processing: ${ctx.limit.activeCount.toString()}, pending: ${ctx.limit.pendingCount.toString()})`
`(processing: ${ctx.limit.activeCount.toString()}, pending: ${ctx.limit.pendingCount.toString()})`,
)
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-imagemin-cache/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface Context {
type: 'info' | 'warn' | 'warnOnce' | 'error',
green?: string,
yellow?: string,
dim?: string
dim?: string,
) => void
publicDir: string
limit: LimitFunction
Expand Down
10 changes: 5 additions & 5 deletions packages/vite-plugin-imagemin-cache/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ansis from 'ansis'
const logger = createLogger()

export function initMatcher(
pattern: Picomatch.Glob | Picomatch.Matcher | undefined
pattern: Picomatch.Glob | Picomatch.Matcher | undefined,
): Picomatch.Matcher | false {
if (pattern === undefined) return false
if (typeof pattern === 'string' || Array.isArray(pattern))
Expand All @@ -21,13 +21,13 @@ export function outputLog(
type: 'info' | 'warn' | 'warnOnce' | 'error',
green?: string,
yellow?: string,
dim?: string
dim?: string,
) {
return logger[type](
ansis.cyanBright('[imagemin-cache]') +
(green ? ansis.green(` ${green}`) : '') +
(yellow ? ansis.yellow(` ${yellow}`) : '') +
(dim ? ansis.dim(` ${dim}`) : '')
(dim ? ansis.dim(` ${dim}`) : ''),
)
}

Expand All @@ -54,12 +54,12 @@ export function getResolvedRoot(root: string | undefined) {
// https://github.com/vitejs/vite/blob/b9511f1ed8e36a618214944c69e2de6504ebcb3c/packages/vite/src/node/config.ts#L587-L593
export function getResolvedPublicDir(
publicDir: string | false | undefined,
resolvedRoot: string
resolvedRoot: string,
) {
return publicDir !== false && publicDir !== ''
? path.resolve(
resolvedRoot,
typeof publicDir === 'string' ? publicDir : 'public'
typeof publicDir === 'string' ? publicDir : 'public',
)
: ''
}
2 changes: 1 addition & 1 deletion packages/vite-plugin-importer-invalidator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const defaultSettings: Settings = {
}

const initMatcher = (
pattern: Picomatch.Glob | Picomatch.Matcher | undefined
pattern: Picomatch.Glob | Picomatch.Matcher | undefined,
): Picomatch.Matcher | null => {
if (pattern === undefined) return null
if (typeof pattern === 'string' || Array.isArray(pattern))
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-pug-static/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const vitePluginPugBuild = (settings: BuildSettings): Plugin => {
outputLog(
'info',
'compiled:',
path.relative(process.cwd(), pathMap.get(id)!)
path.relative(process.cwd(), pathMap.get(id)!),
)
return html
}
Expand Down
8 changes: 4 additions & 4 deletions packages/vite-plugin-pug-static/src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ interface ServeSettings {
export type Middleware = (
req: Connect.IncomingMessage,
res: http.ServerResponse,
next: Connect.NextFunction
next: Connect.NextFunction,
) => void | http.ServerResponse | Promise<void | http.ServerResponse>

const middleware = (
settings: ServeSettings,
server: ViteDevServer
server: ViteDevServer,
): Middleware => {
const { options, locals, ignorePattern } = settings
const ignoreMatcher = ignorePattern ? picomatch(ignorePattern) : null
Expand All @@ -52,7 +52,7 @@ const middleware = (
const reqAbsPath = path.posix.join(
server.config.root,
url,
url.endsWith('/') ? 'index.html' : ''
url.endsWith('/') ? 'index.html' : '',
)

const parsedReqAbsPath = path.posix.parse(reqAbsPath)
Expand All @@ -75,7 +75,7 @@ const middleware = (
url,
pugAbsPath,
options,
locals
locals,
)

// Pug compile error
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-pug-static/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export function outputLog(
type: 'info' | 'warn' | 'warnOnce' | 'error',
green?: string,
yellow?: string,
dim?: string
dim?: string,
) {
return logger[type](
ansis.cyanBright('[pug-static]') +
(green ? ansis.green(` ${green}`) : '') +
(yellow ? ansis.yellow(` ${yellow}`) : '') +
(dim ? ansis.dim(` ${dim}`) : '')
(dim ? ansis.dim(` ${dim}`) : ''),
)
}

0 comments on commit 0b0b783

Please sign in to comment.