chore: adds upload export back

This commit is contained in:
James
2024-04-08 10:46:41 -04:00
parent c3119a5632
commit 89efcc5db1
13 changed files with 50 additions and 54 deletions

View File

@@ -1,3 +1 @@
export { getFileByPath } from '../uploads/getFileByPath.js'
export { importConfig } from '../utilities/importConfig.js'
export { importWithoutClientFiles } from '../utilities/importWithoutClientFiles.js'
export { importConfig, importWithoutClientFiles } from '../utilities/importWithoutClientFiles.js'

View File

@@ -0,0 +1 @@
export { getFileByPath } from '../uploads/getFileByPath.js'

View File

@@ -1,41 +0,0 @@
import path from 'node:path'
import type { SanitizedConfig } from '../config/types.js'
import { importWithoutClientFiles } from './importWithoutClientFiles.js'
/**
* Resolve and load Payload config from either a relative or absolute path
*/
export const importConfig = async (configPath: string) => {
const isAbsolutePath = path.isAbsolute(configPath)
if (isAbsolutePath) {
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(configPath)
return await config.default
}
const callerDir = path.dirname(getCallerInfo()[1].getFileName()).replace('file://', '')
const fullConfigPath = path.resolve(callerDir, configPath)
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(
fullConfigPath,
)
return await config.default
}
const getCallerInfo = () => {
const _prepareStackTrace = Error.prepareStackTrace
try {
let result = []
Error.prepareStackTrace = (_, callSites) => {
const callSitesWithoutCurrent = callSites.slice(1)
result = callSitesWithoutCurrent
return callSitesWithoutCurrent
}
new Error().stack
return result
} finally {
Error.prepareStackTrace = _prepareStackTrace
}
}

View File

@@ -2,13 +2,51 @@ import { register } from 'node:module'
import { fileURLToPath, pathToFileURL } from 'node:url'
import path from 'path'
import type { SanitizedConfig } from '../config/types.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export const importWithoutClientFiles = async <T = unknown>(filePath: string) => {
const url = pathToFileURL(filePath).toString()
register(path.resolve(dirname, '../../dist/bin/register/index.js'), url)
register(path.resolve(dirname, '../../dist/bin/loader/index.js'), url)
const result = await import(filePath)
return result as T
}
/**
* Resolve and load Payload config from either a relative or absolute path
*/
export const importConfig = async (configPath: string) => {
const isAbsolutePath = path.isAbsolute(configPath)
if (isAbsolutePath) {
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(configPath)
return await config.default
}
const callerDir = path.dirname(getCallerInfo()[1].getFileName()).replace('file://', '')
const fullConfigPath = path.resolve(callerDir, configPath)
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(
fullConfigPath,
)
return await config.default
}
const getCallerInfo = () => {
const _prepareStackTrace = Error.prepareStackTrace
try {
let result = []
Error.prepareStackTrace = (_, callSites) => {
const callSitesWithoutCurrent = callSites.slice(1)
result = callSitesWithoutCurrent
return callSitesWithoutCurrent
}
new Error().stack
return result
} finally {
Error.prepareStackTrace = _prepareStackTrace
}
}

View File

@@ -1,5 +1,5 @@
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'

View File

@@ -1,5 +1,5 @@
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'

View File

@@ -1,7 +1,7 @@
import type { Payload } from 'payload'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { devUser } from '../credentials.js'

View File

@@ -1,7 +1,7 @@
import type { Payload } from 'payload'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import type { NextRESTClient } from '../helpers/NextRESTClient.js'

View File

@@ -2,7 +2,7 @@ import type { Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import type { Page as PayloadPage } from './payload-types.js'

View File

@@ -1,7 +1,7 @@
import type { Payload } from 'payload'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { initPayloadInt } from '../helpers/initPayloadInt.js'

View File

@@ -2,7 +2,7 @@ import type { Payload } from 'payload'
import type { PayloadRequest } from 'payload/types'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { mediaSlug } from '../shared.js'

View File

@@ -1,5 +1,5 @@
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'

View File

@@ -4,7 +4,7 @@ import { File as FileBuffer } from 'buffer'
import NodeFormData from 'form-data'
import fs from 'fs'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { promisify } from 'util'