chore: converts dev script from cjs to esm

This commit is contained in:
James
2024-03-06 11:38:26 -05:00
parent f51434880f
commit 23051db54a
4 changed files with 32 additions and 18 deletions

View File

@@ -1,9 +1,11 @@
const withPayload = require('./packages/next/src/withPayload') import withPayload from './packages/next/src/withPayload.js'
const withBundleAnalyzer = require('@next/bundle-analyzer')({ import bundleAnalyzer from '@next/bundle-analyzer'
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === 'true', enabled: process.env.ANALYZE === 'true',
}) })
module.exports = withBundleAnalyzer( export default withBundleAnalyzer(
withPayload({ withPayload({
reactStrictMode: false, reactStrictMode: false,
async redirects() { async redirects() {

View File

@@ -2,6 +2,7 @@
"name": "payload-monorepo", "name": "payload-monorepo",
"version": "3.0.0-alpha.19", "version": "3.0.0-alpha.19",
"private": true, "private": true,
"type": "module",
"workspaces:": [ "workspaces:": [
"packages/*" "packages/*"
], ],

View File

@@ -70,4 +70,4 @@ const withPayload = (nextConfig = {}) => {
} }
} }
module.exports = withPayload export default withPayload

View File

@@ -1,12 +1,19 @@
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
const minimist = require('minimist') import { existsSync } from 'fs'
const path = require('path') import { promises } from 'fs'
const { nextDev } = require(path.resolve(__dirname, '..', 'node_modules/next/dist/cli/next-dev')) import minimist from 'minimist'
const fs = require('fs') import { nextDev } from 'next/dist/cli/next-dev.js'
const { readFile } = require('fs').promises import { dirname } from 'path'
const { writeFile } = require('fs').promises import { resolve } from 'path'
const { rm } = require('fs').promises import { fileURLToPath } from 'url'
const JSON5 = require('json5') const { readFile } = promises
import { promises as _promises } from 'fs'
const { writeFile } = _promises
import { promises as __promises } from 'fs'
const { rm } = __promises
import json5 from 'json5'
const { parse } = json5
main() main()
@@ -20,24 +27,28 @@ async function main() {
process.env.TURBOPACK = '1' process.env.TURBOPACK = '1'
} }
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const testSuite = testSuiteArg || '_community' const testSuite = testSuiteArg || '_community'
console.log('\nUsing config:', testSuite, '\n') console.log('\nUsing config:', testSuite, '\n')
// Delete next webpack cache // Delete next webpack cache
const nextWebpackCache = path.resolve(__dirname, '..', '.next/cache/webpack') const nextWebpackCache = resolve(__dirname, '..', '.next/cache/webpack')
if (fs.existsSync(nextWebpackCache)) { if (existsSync(nextWebpackCache)) {
await rm(nextWebpackCache, { recursive: true }) await rm(nextWebpackCache, { recursive: true })
} }
// Set path.'payload-config' in tsconfig.json // Set path.'payload-config' in tsconfig.json
const tsConfigPath = path.resolve(__dirname, '..', 'tsconfig.json') const tsConfigPath = resolve(__dirname, '..', 'tsconfig.json')
const tsConfig = await JSON5.parse(await readFile(tsConfigPath, 'utf8')) const tsConfig = await parse(await readFile(tsConfigPath, 'utf8'))
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`] tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`]
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2)) await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
const PAYLOAD_CONFIG_PATH = path.resolve(testSuite, 'config') const PAYLOAD_CONFIG_PATH = resolve(testSuite, 'config')
process.env.PAYLOAD_CONFIG_PATH = PAYLOAD_CONFIG_PATH process.env.PAYLOAD_CONFIG_PATH = PAYLOAD_CONFIG_PATH
nextDev({ _: [path.resolve(__dirname, '..')], port: process.env.PORT || 3000 }) nextDev({ _: [resolve(__dirname, '..')], port: process.env.PORT || 3000 })
} }