chore: adds upload export back
This commit is contained in:
@@ -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'
|
||||
|
||||
1
packages/payload/src/exports/uploads.ts
Normal file
1
packages/payload/src/exports/uploads.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { getFileByPath } from '../uploads/getFileByPath.js'
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user