From 82b03db37d776a8c2790ea6f0c66ff7a208ad153 Mon Sep 17 00:00:00 2001 From: Mumtahin Farabi Date: Tue, 27 Aug 2024 21:51:46 -0400 Subject: [PATCH] chore(repo): convert entire NX workspace to use ES modules --- apps/docs-e2e/eslint.config.js | 58 +++++++++++-------- apps/docs-e2e/playwright.config.ts | 3 + apps/docs-e2e/tsconfig.json | 5 +- apps/docs/eslint.config.js | 5 +- .../{postcss.config.js => postcss.config.cjs} | 0 apps/docs/tailwind.config.js | 58 +++++++++---------- apps/docs/tsconfig.json | 14 +++-- apps/portal-e2e/eslint.config.js | 58 +++++++++++-------- apps/portal-e2e/playwright.config.ts | 3 + apps/portal-e2e/tsconfig.json | 5 +- apps/portal/eslint.config.js | 5 +- apps/portal/next.config.js | 4 +- .../{postcss.config.js => postcss.config.cjs} | 0 apps/portal/tailwind.config.js | 26 ++++----- apps/portal/tsconfig.json | 4 +- apps/website-e2e/eslint.config.js | 58 +++++++++++-------- apps/website-e2e/playwright.config.ts | 3 + apps/website-e2e/tsconfig.json | 5 +- eslint.config.js | 4 +- package.json | 1 + 20 files changed, 175 insertions(+), 144 deletions(-) rename apps/docs/{postcss.config.js => postcss.config.cjs} (100%) rename apps/portal/{postcss.config.js => postcss.config.cjs} (100%) diff --git a/apps/docs-e2e/eslint.config.js b/apps/docs-e2e/eslint.config.js index e321b19..a04440e 100644 --- a/apps/docs-e2e/eslint.config.js +++ b/apps/docs-e2e/eslint.config.js @@ -1,32 +1,40 @@ -const { FlatCompat } = require('@eslint/eslintrc') -const js = require('@eslint/js') -const baseConfigPromise = require('../../eslint.config.js') +// TODO: merge with antfu eslint config +// const { FlatCompat } = require('@eslint/eslintrc'); +import baseConfigPromise from '../../eslint.config.js' -module.exports = (async () => { +export default (async () => { const baseConfig = await baseConfigPromise - const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - }) return [ ...baseConfig, - ...compat.extends('plugin:playwright/recommended'), - { - files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], - rules: {}, - }, - { - files: ['**/*.ts', '**/*.tsx'], - rules: {}, - }, - { - files: ['**/*.js', '**/*.jsx'], - rules: {}, - }, - { - files: ['src/**/*.{ts,js,tsx,jsx}'], - rules: {}, - }, + // ...compat.extends("plugin:playwright/recommended"), + // The following configurations are commented out + // ...compat.extends( + // 'plugin:@nx/react-typescript', + // 'next', + // 'next/core-web-vitals' + // ), + // { + // files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + // rules: { + // '@next/next/no-html-link-for-pages': ['error', 'apps/portal/pages'], + // }, + // }, + // { + // files: ['**/*.ts', '**/*.tsx'], + // rules: {}, + // }, + // { + // files: ['**/*.js', '**/*.jsx'], + // rules: {}, + // }, + // ...compat.config({ env: { jest: true } }).map((config) => ({ + // ...config, + // files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx'], + // rules: { + // ...config.rules, + // }, + // })), + // { ignores: ['.next/**/*'] }, ] })() diff --git a/apps/docs-e2e/playwright.config.ts b/apps/docs-e2e/playwright.config.ts index 9e60724..f95e020 100644 --- a/apps/docs-e2e/playwright.config.ts +++ b/apps/docs-e2e/playwright.config.ts @@ -1,10 +1,13 @@ // TODO: Investigate node global process usage /* eslint-disable node/prefer-global/process */ +import { fileURLToPath } from 'node:url' import { defineConfig, devices } from '@playwright/test' import { nxE2EPreset } from '@nx/playwright/preset' import { workspaceRoot } from '@nx/devkit' +const __filename = fileURLToPath(import.meta.url) + // For CI, you may want to set BASE_URL to the deployed application. const baseURL = process.env.BASE_URL || 'http://127.0.0.1:3000' diff --git a/apps/docs-e2e/tsconfig.json b/apps/docs-e2e/tsconfig.json index b811cb6..57ff855 100644 --- a/apps/docs-e2e/tsconfig.json +++ b/apps/docs-e2e/tsconfig.json @@ -1,10 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "module": "commonjs", - "allowJs": true, - "outDir": "../../dist/out-tsc", - "sourceMap": false + "outDir": "../../dist/out-tsc" }, "include": [ "**/*.ts", diff --git a/apps/docs/eslint.config.js b/apps/docs/eslint.config.js index b808bd4..4234592 100644 --- a/apps/docs/eslint.config.js +++ b/apps/docs/eslint.config.js @@ -1,9 +1,10 @@ // TODO: merge with antfu eslint config // const { FlatCompat } = require('@eslint/eslintrc'); -const baseConfigPromise = require('../../eslint.config.js') +// const baseConfigPromise = require('../../eslint.config.js') +import baseConfigPromise from '../../eslint.config.js' // const js = require('@eslint/js'); -module.exports = (async () => { +export default (async () => { const baseConfig = await baseConfigPromise return [ diff --git a/apps/docs/postcss.config.js b/apps/docs/postcss.config.cjs similarity index 100% rename from apps/docs/postcss.config.js rename to apps/docs/postcss.config.cjs diff --git a/apps/docs/tailwind.config.js b/apps/docs/tailwind.config.js index 5660ae1..04c96dd 100644 --- a/apps/docs/tailwind.config.js +++ b/apps/docs/tailwind.config.js @@ -1,39 +1,37 @@ // import type { Config } from 'tailwindcss' // const { fontFamily } = require('tailwindcss/defaultTheme') -const { join } = require('node:path') +import { join } from 'node:path' -const { createPreset } = require('fumadocs-ui/tailwind-plugin') +import { createPreset } from 'fumadocs-ui/tailwind-plugin' -const { createGlobPatternsForDependencies } = require('@nx/react/tailwind') +import { createGlobPatternsForDependencies } from '@nx/react/tailwind' /** @type {import('tailwindcss').Config} */ -module.exports = { - darkMode: ['class'], - content: [ - join( - __dirname, - '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}', - ), - ...createGlobPatternsForDependencies(__dirname), - './mdx-components.tsx', - '../../node_modules/fumadocs-ui/dist/**/*.js', - ], - theme: { - extend: { - fontFamily: { - // sans: ['var(--font-geist-sans)', ...fontFamily.sans], - }, +export const darkMode = ['class'] +export const content = [ + join( + __dirname, + '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}', + ), + ...createGlobPatternsForDependencies(__dirname), + './mdx-components.tsx', + '../../node_modules/fumadocs-ui/dist/**/*.js', +] +export const theme = { + extend: { + fontFamily: { + // sans: ['var(--font-geist-sans)', ...fontFamily.sans], }, }, - presets: [ - createPreset({ - // preset: 'default', - // preset: 'neutral', - // preset: 'dusk', - // preset: 'purple', - // preset: 'ocean', - preset: 'catppuccin', - }), - ], - plugins: [], } +export const presets = [ + createPreset({ + // preset: 'default', + // preset: 'neutral', + // preset: 'dusk', + // preset: 'purple', + // preset: 'ocean', + preset: 'catppuccin', + }), +] +export const plugins = [] diff --git a/apps/docs/tsconfig.json b/apps/docs/tsconfig.json index a1de336..51d6d28 100644 --- a/apps/docs/tsconfig.json +++ b/apps/docs/tsconfig.json @@ -4,7 +4,9 @@ "incremental": true, "jsx": "preserve", "resolveJsonModule": true, - "types": ["node"], + "types": [ + "node" + ], "allowJs": true, "strict": true, "noEmit": true, @@ -28,8 +30,12 @@ "next-env.d.ts", ".next/types/**/*.ts", "next.config.mjs", - "postcss.config.js", - "tailwind.config.js" + "postcss.config.cjs", + "tailwind.config.cjs" ], - "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"] + "exclude": [ + "node_modules", + "**/*.spec.ts", + "**/*.test.ts" + ] } diff --git a/apps/portal-e2e/eslint.config.js b/apps/portal-e2e/eslint.config.js index e321b19..a04440e 100644 --- a/apps/portal-e2e/eslint.config.js +++ b/apps/portal-e2e/eslint.config.js @@ -1,32 +1,40 @@ -const { FlatCompat } = require('@eslint/eslintrc') -const js = require('@eslint/js') -const baseConfigPromise = require('../../eslint.config.js') +// TODO: merge with antfu eslint config +// const { FlatCompat } = require('@eslint/eslintrc'); +import baseConfigPromise from '../../eslint.config.js' -module.exports = (async () => { +export default (async () => { const baseConfig = await baseConfigPromise - const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - }) return [ ...baseConfig, - ...compat.extends('plugin:playwright/recommended'), - { - files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], - rules: {}, - }, - { - files: ['**/*.ts', '**/*.tsx'], - rules: {}, - }, - { - files: ['**/*.js', '**/*.jsx'], - rules: {}, - }, - { - files: ['src/**/*.{ts,js,tsx,jsx}'], - rules: {}, - }, + // ...compat.extends("plugin:playwright/recommended"), + // The following configurations are commented out + // ...compat.extends( + // 'plugin:@nx/react-typescript', + // 'next', + // 'next/core-web-vitals' + // ), + // { + // files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + // rules: { + // '@next/next/no-html-link-for-pages': ['error', 'apps/portal/pages'], + // }, + // }, + // { + // files: ['**/*.ts', '**/*.tsx'], + // rules: {}, + // }, + // { + // files: ['**/*.js', '**/*.jsx'], + // rules: {}, + // }, + // ...compat.config({ env: { jest: true } }).map((config) => ({ + // ...config, + // files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx'], + // rules: { + // ...config.rules, + // }, + // })), + // { ignores: ['.next/**/*'] }, ] })() diff --git a/apps/portal-e2e/playwright.config.ts b/apps/portal-e2e/playwright.config.ts index cb4b535..920ef40 100644 --- a/apps/portal-e2e/playwright.config.ts +++ b/apps/portal-e2e/playwright.config.ts @@ -1,9 +1,12 @@ /* eslint-disable node/prefer-global/process */ +import { fileURLToPath } from 'node:url' import { defineConfig, devices } from '@playwright/test' import { nxE2EPreset } from '@nx/playwright/preset' import { workspaceRoot } from '@nx/devkit' +const __filename = fileURLToPath(import.meta.url) + // For CI, you may want to set BASE_URL to the deployed application. const baseURL = process.env.BASE_URL || 'http://127.0.0.1:3000' diff --git a/apps/portal-e2e/tsconfig.json b/apps/portal-e2e/tsconfig.json index b811cb6..57ff855 100644 --- a/apps/portal-e2e/tsconfig.json +++ b/apps/portal-e2e/tsconfig.json @@ -1,10 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "module": "commonjs", - "allowJs": true, - "outDir": "../../dist/out-tsc", - "sourceMap": false + "outDir": "../../dist/out-tsc" }, "include": [ "**/*.ts", diff --git a/apps/portal/eslint.config.js b/apps/portal/eslint.config.js index b808bd4..4234592 100644 --- a/apps/portal/eslint.config.js +++ b/apps/portal/eslint.config.js @@ -1,9 +1,10 @@ // TODO: merge with antfu eslint config // const { FlatCompat } = require('@eslint/eslintrc'); -const baseConfigPromise = require('../../eslint.config.js') +// const baseConfigPromise = require('../../eslint.config.js') +import baseConfigPromise from '../../eslint.config.js' // const js = require('@eslint/js'); -module.exports = (async () => { +export default (async () => { const baseConfig = await baseConfigPromise return [ diff --git a/apps/portal/next.config.js b/apps/portal/next.config.js index f597533..498e222 100644 --- a/apps/portal/next.config.js +++ b/apps/portal/next.config.js @@ -1,4 +1,4 @@ -const { composePlugins, withNx } = require('@nx/next') +import { composePlugins, withNx } from '@nx/next' /** * @type {import('@nx/next/plugins/with-nx').WithNxOptions} @@ -16,4 +16,4 @@ const plugins = [ withNx, ] -module.exports = composePlugins(...plugins)(nextConfig) +export default composePlugins(...plugins)(nextConfig) diff --git a/apps/portal/postcss.config.js b/apps/portal/postcss.config.cjs similarity index 100% rename from apps/portal/postcss.config.js rename to apps/portal/postcss.config.cjs diff --git a/apps/portal/tailwind.config.js b/apps/portal/tailwind.config.js index 1b63b95..433cc87 100644 --- a/apps/portal/tailwind.config.js +++ b/apps/portal/tailwind.config.js @@ -1,17 +1,15 @@ -const { join } = require('node:path') -const { createGlobPatternsForDependencies } = require('@nx/react/tailwind') +import { join } from 'node:path' +import { createGlobPatternsForDependencies } from '@nx/react/tailwind' /** @type {import('tailwindcss').Config} */ -module.exports = { - content: [ - join( - __dirname, - '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}', - ), - ...createGlobPatternsForDependencies(__dirname), - ], - theme: { - extend: {}, - }, - plugins: [], +export const content = [ + join( + __dirname, + '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}', + ), + ...createGlobPatternsForDependencies(__dirname), +] +export const theme = { + extend: {}, } +export const plugins = [] diff --git a/apps/portal/tsconfig.json b/apps/portal/tsconfig.json index 1549131..669dc04 100644 --- a/apps/portal/tsconfig.json +++ b/apps/portal/tsconfig.json @@ -29,7 +29,9 @@ "../../apps/portal/.next/types/**/*.ts", "../../dist/apps/portal/.next/types/**/*.ts", "next-env.d.ts", - ".next/types/**/*.ts" + ".next/types/**/*.ts", + "postcss.config.cjs", + "next.config.cjs" ], "exclude": [ "node_modules", diff --git a/apps/website-e2e/eslint.config.js b/apps/website-e2e/eslint.config.js index e321b19..a04440e 100644 --- a/apps/website-e2e/eslint.config.js +++ b/apps/website-e2e/eslint.config.js @@ -1,32 +1,40 @@ -const { FlatCompat } = require('@eslint/eslintrc') -const js = require('@eslint/js') -const baseConfigPromise = require('../../eslint.config.js') +// TODO: merge with antfu eslint config +// const { FlatCompat } = require('@eslint/eslintrc'); +import baseConfigPromise from '../../eslint.config.js' -module.exports = (async () => { +export default (async () => { const baseConfig = await baseConfigPromise - const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - }) return [ ...baseConfig, - ...compat.extends('plugin:playwright/recommended'), - { - files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], - rules: {}, - }, - { - files: ['**/*.ts', '**/*.tsx'], - rules: {}, - }, - { - files: ['**/*.js', '**/*.jsx'], - rules: {}, - }, - { - files: ['src/**/*.{ts,js,tsx,jsx}'], - rules: {}, - }, + // ...compat.extends("plugin:playwright/recommended"), + // The following configurations are commented out + // ...compat.extends( + // 'plugin:@nx/react-typescript', + // 'next', + // 'next/core-web-vitals' + // ), + // { + // files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + // rules: { + // '@next/next/no-html-link-for-pages': ['error', 'apps/portal/pages'], + // }, + // }, + // { + // files: ['**/*.ts', '**/*.tsx'], + // rules: {}, + // }, + // { + // files: ['**/*.js', '**/*.jsx'], + // rules: {}, + // }, + // ...compat.config({ env: { jest: true } }).map((config) => ({ + // ...config, + // files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx'], + // rules: { + // ...config.rules, + // }, + // })), + // { ignores: ['.next/**/*'] }, ] })() diff --git a/apps/website-e2e/playwright.config.ts b/apps/website-e2e/playwright.config.ts index 4835400..0e972d9 100644 --- a/apps/website-e2e/playwright.config.ts +++ b/apps/website-e2e/playwright.config.ts @@ -1,9 +1,12 @@ /* eslint-disable node/prefer-global/process */ +import { fileURLToPath } from 'node:url' import { defineConfig, devices } from '@playwright/test' import { nxE2EPreset } from '@nx/playwright/preset' import { workspaceRoot } from '@nx/devkit' +const __filename = fileURLToPath(import.meta.url) + // For CI, you may want to set BASE_URL to the deployed application. const baseURL = process.env.BASE_URL || 'http://localhost:3000' diff --git a/apps/website-e2e/tsconfig.json b/apps/website-e2e/tsconfig.json index b811cb6..57ff855 100644 --- a/apps/website-e2e/tsconfig.json +++ b/apps/website-e2e/tsconfig.json @@ -1,10 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "module": "commonjs", - "allowJs": true, - "outDir": "../../dist/out-tsc", - "sourceMap": false + "outDir": "../../dist/out-tsc" }, "include": [ "**/*.ts", diff --git a/eslint.config.js b/eslint.config.js index fdfb9c7..9a2a283 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -47,9 +47,9 @@ // })), // ]; -const antfu = require('@antfu/eslint-config').default +import antfu from '@antfu/eslint-config' -module.exports = antfu({ +export default antfu({ formatters: true, react: true, }, { diff --git a/package.json b/package.json index 7310559..1f54b2a 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "@cuhacking/source", + "type": "module", "version": "0.0.0", "private": true, "packageManager": "pnpm@9.7.1",