Files
payloadcms/packages/graphql/bin.js
Alessio Gravili af0105ced5 fix: no longer handle disabling node deprecation warnings within bin script shebangs, as it errored on some systems (#7797)
Fixes https://github.com/payloadcms/payload/issues/7741

I have no idea why it broke and was not able to reproduce this at all.
But given the amount of people reporting this issue, it's not worth
keeping this around for the small benefit this brings
2024-08-21 17:01:57 +00:00

55 lines
1.4 KiB
JavaScript
Executable File

#!/usr/bin/env node
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
const useSwc = process.argv.includes('--use-swc')
const disableTranspile = process.argv.includes('--disable-transpile')
if (disableTranspile) {
// Remove --disable-transpile from arguments
process.argv = process.argv.filter((arg) => arg !== '--disable-transpile')
const start = async () => {
const { bin } = await import('./dist/bin/index.js')
await bin()
}
void start()
} else {
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const url = pathToFileURL(dirname).toString() + '/'
if (!useSwc) {
const start = async () => {
// Use tsx
let tsImport = (await import('tsx/esm/api')).tsImport
const { bin } = await tsImport('./dist/bin/index.js', url)
await bin()
}
void start()
} else if (useSwc) {
const { register } = await import('node:module')
// Remove --use-swc from arguments
process.argv = process.argv.filter((arg) => arg !== '--use-swc')
try {
register('@swc-node/register/esm', url)
} catch (_) {
console.error(
'@swc-node/register is not installed. Please install @swc-node/register in your project, if you want to use swc in payload run.',
)
}
const start = async () => {
const { bin } = await import('./dist/bin/index.js')
await bin()
}
void start()
}
}