-
Notifications
You must be signed in to change notification settings - Fork 340
/
deploy.ts
41 lines (32 loc) · 1.2 KB
/
deploy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { stat } from 'fs/promises'
import { join } from 'path'
import { getPathInProject } from '../settings.js'
import { EDGE_FUNCTIONS_FOLDER, PUBLIC_URL_PATH } from './consts.js'
const distPath = getPathInProject([EDGE_FUNCTIONS_FOLDER])
/**
* @param {string} workingDir
* @param {*} file
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'workingDir' implicitly has an 'any' typ... Remove this comment to see the full error message
export const deployFileNormalizer = (workingDir: string, file) => {
const absoluteDistPath = join(workingDir, distPath)
const isEdgeFunction = file.root === absoluteDistPath
const normalizedPath = isEdgeFunction ? `${PUBLIC_URL_PATH}/${file.normalizedPath}` : file.normalizedPath
return {
...file,
normalizedPath,
}
}
export const getDistPathIfExists = async (workingDir: string) => {
try {
const absoluteDistPath = join(workingDir, distPath)
const stats = await stat(absoluteDistPath)
if (!stats.isDirectory()) {
throw new Error(`Path ${absoluteDistPath} must be a directory.`)
}
return absoluteDistPath
} catch {
// no-op
}
}
export const isEdgeFunctionFile = (filePath: string) => filePath.startsWith(`${PUBLIC_URL_PATH}/`)