From 23051db54a3250a78fb035d832c9357bc5e24681 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 6 Mar 2024 11:38:26 -0500 Subject: [PATCH] chore: converts dev script from cjs to esm --- next.config.js => next.config.mjs | 8 ++++--- package.json | 1 + packages/next/src/withPayload.js | 2 +- test/dev.js | 39 ++++++++++++++++++++----------- 4 files changed, 32 insertions(+), 18 deletions(-) rename next.config.js => next.config.mjs (57%) diff --git a/next.config.js b/next.config.mjs similarity index 57% rename from next.config.js rename to next.config.mjs index c35334d85..38ca9fb3c 100644 --- a/next.config.js +++ b/next.config.mjs @@ -1,9 +1,11 @@ -const withPayload = require('./packages/next/src/withPayload') -const withBundleAnalyzer = require('@next/bundle-analyzer')({ +import withPayload from './packages/next/src/withPayload.js' +import bundleAnalyzer from '@next/bundle-analyzer' + +const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true', }) -module.exports = withBundleAnalyzer( +export default withBundleAnalyzer( withPayload({ reactStrictMode: false, async redirects() { diff --git a/package.json b/package.json index 912f4abe8..2f6245a66 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "payload-monorepo", "version": "3.0.0-alpha.19", "private": true, + "type": "module", "workspaces:": [ "packages/*" ], diff --git a/packages/next/src/withPayload.js b/packages/next/src/withPayload.js index 2b59eb5bc..80840273b 100644 --- a/packages/next/src/withPayload.js +++ b/packages/next/src/withPayload.js @@ -70,4 +70,4 @@ const withPayload = (nextConfig = {}) => { } } -module.exports = withPayload +export default withPayload diff --git a/test/dev.js b/test/dev.js index d00f4a3c5..4cdba8bbc 100644 --- a/test/dev.js +++ b/test/dev.js @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const minimist = require('minimist') -const path = require('path') -const { nextDev } = require(path.resolve(__dirname, '..', 'node_modules/next/dist/cli/next-dev')) -const fs = require('fs') -const { readFile } = require('fs').promises -const { writeFile } = require('fs').promises -const { rm } = require('fs').promises -const JSON5 = require('json5') +import { existsSync } from 'fs' +import { promises } from 'fs' +import minimist from 'minimist' +import { nextDev } from 'next/dist/cli/next-dev.js' +import { dirname } from 'path' +import { resolve } from 'path' +import { fileURLToPath } from 'url' +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() @@ -20,24 +27,28 @@ async function main() { process.env.TURBOPACK = '1' } + const __filename = fileURLToPath(import.meta.url) + const __dirname = dirname(__filename) + const testSuite = testSuiteArg || '_community' console.log('\nUsing config:', testSuite, '\n') // Delete next webpack cache - const nextWebpackCache = path.resolve(__dirname, '..', '.next/cache/webpack') - if (fs.existsSync(nextWebpackCache)) { + const nextWebpackCache = resolve(__dirname, '..', '.next/cache/webpack') + if (existsSync(nextWebpackCache)) { await rm(nextWebpackCache, { recursive: true }) } // Set path.'payload-config' in tsconfig.json - const tsConfigPath = path.resolve(__dirname, '..', 'tsconfig.json') - const tsConfig = await JSON5.parse(await readFile(tsConfigPath, 'utf8')) + const tsConfigPath = resolve(__dirname, '..', 'tsconfig.json') + const tsConfig = await parse(await readFile(tsConfigPath, 'utf8')) tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`] + 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 - nextDev({ _: [path.resolve(__dirname, '..')], port: process.env.PORT || 3000 }) + nextDev({ _: [resolve(__dirname, '..')], port: process.env.PORT || 3000 }) }