Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utils/deploy/deploy-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const deploySite = async (
hashFiles({
assetType,
concurrentHash,
directories: [dir, edgeFunctionsDistPath, deployConfigPath].filter(Boolean),
directories: [dir, edgeFunctionsDistPath, deployConfigPath].filter(Boolean) as string[],
filter,
hashAlgorithm,
normalizer: deployFileNormalizer.bind(null, workingDir),
Expand Down
10 changes: 5 additions & 5 deletions src/utils/deploy/file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import walker from 'folder-walker'
import type { Entry } from 'folder-walker'

export type OriginalFile = walker.Entry
export type OriginalFile = Entry

export type File = walker.Entry & {
hash: string
assetType: string
export type File = Entry & {
hash?: string
assetType?: string
normalizedPath: string
}
26 changes: 16 additions & 10 deletions src/utils/deploy/hash-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import walker from 'folder-walker'

import { fileFilterCtor, fileNormalizerCtor, hasherCtor, manifestCollectorCtor } from './hasher-segments.js'
import { $TSFixMe } from '../../commands/types.js'
import type { File } from './file.js'
import type { StatusCallback } from './status-cb.js'

type Normalizer = (file: File) => Partial<File>

const hashFiles = async ({
assetType = 'file',
Expand All @@ -14,17 +17,20 @@
normalizer,
statusCb,
}: {
assetType?: string | undefined
concurrentHash: $TSFixMe
directories: $TSFixMe
filter: $TSFixMe
hashAlgorithm?: string | undefined
normalizer?: $TSFixMe
statusCb: $TSFixMe
}): Promise<{ files: Record<string, string>; filesShaMap: Record<string, $TSFixMe[]> }> => {
assetType?: string
concurrentHash: number
directories: string[]
filter: (path: string) => boolean
hashAlgorithm?: string
normalizer?: Normalizer
statusCb: StatusCallback
}): Promise<{
files: Record<string, string>
filesShaMap: Record<string, { normalizedPath: string; sha: string }[]>
}> => {
if (!filter) throw new Error('Missing filter function option')

Check failure on line 31 in src/utils/deploy/hash-files.ts

View workflow job for this annotation

GitHub Actions / Lint

Unnecessary conditional, value is always falsy

const fileStream = walker(directories, { filter })
const fileStream = walker(directories, { filter: (filename) => filter(filename) })
const fileFilter = fileFilterCtor()
const hasher = hasherCtor({ concurrentHash, hashAlgorithm })
const fileNormalizer = fileNormalizerCtor({ assetType, normalizer })
Expand Down
4 changes: 2 additions & 2 deletions src/utils/deploy/hasher-segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import transform from 'parallel-transform'

import type { File, OriginalFile } from './file.js'

Check failure on line 8 in src/utils/deploy/hasher-segments.ts

View workflow job for this annotation

GitHub Actions / Lint

'OriginalFile' is defined but never used. Allowed unused vars must match /^_/u
import { normalizePath } from './util.js'
import type { StatusCallback } from './status-cb.js'

Expand Down Expand Up @@ -40,14 +40,14 @@
normalizer: normalizeFunction,
}: {
assetType: string
normalizer?: (file: OriginalFile) => File
normalizer?: (file: File) => Partial<File>
}) => {
return new Transform({
objectMode: true,
transform(fileObj, _, callback) {
const normalizedFile = { ...fileObj, assetType, normalizedPath: normalizePath(fileObj.relname) }

const result = normalizeFunction !== undefined ? normalizeFunction(normalizedFile) : normalizedFile
const result = normalizeFunction !== undefined ? { ...normalizedFile, ...normalizeFunction(normalizedFile) } : normalizedFile

this.push(result)

Expand Down
4 changes: 2 additions & 2 deletions src/utils/deploy/process-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { join } from 'path'

import { getPathInProject } from '../../lib/settings.js'
import { EDGE_FUNCTIONS_FOLDER, PUBLIC_URL_PATH } from '../../lib/edge-functions/consts.js'
import { File } from './file.js'
import type { File } from './file.js'

const DEPLOY_CONFIG_PATH = 'deploy-config'

const deployConfigPathPath = getPathInProject([DEPLOY_CONFIG_PATH])
const edgeFunctionsDistPath = getPathInProject([EDGE_FUNCTIONS_FOLDER])

export const deployFileNormalizer = (workingDir: string, file: File) => {
export const deployFileNormalizer = (workingDir: string, file: File): { normalizedPath: string } => {
let { normalizedPath } = file

switch (file.root) {
Expand Down
29 changes: 29 additions & 0 deletions types/folder-walker/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference types="node" />
declare module 'folder-walker' {
import { Stats } from 'fs'
import { Readable } from 'stream'

export interface Entry {
/** file basename */
basename: string
/** full path to the file */
filepath: string
/** directory where the file is located */
root: string
/** relative path to the file from the root */
relname: string
/** fs.Stats object */
stat: Stats
/** type of file (file, directory, etc) */
type: string
}

export default function walker(
folders: string | string[],
options?: {
filter?: (filename: string, stat: Stats) => boolean
fs?: any

Check failure on line 25 in types/folder-walker/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
maxdepth?: number
},
): Readable
}
Loading