Skip to content

Commit

Permalink
chore(admin): simplify user customisation loading
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Nov 14, 2023
1 parent 8ac0ef5 commit c9ec5ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import { loadFile } from './files';
import fs from 'node:fs';

const ADMIN_APP_FILES = ['app.js', 'app.mjs', 'app.ts', 'app.jsx', 'app.tsx'];

Expand All @@ -12,16 +12,14 @@ interface AdminCustomisations {

interface AppFile {
path: string;
config: AdminCustomisations['config'];
}

const loadUserAppFile = async (appDir: string): Promise<AppFile | undefined> => {
for (const file of ADMIN_APP_FILES) {
const filePath = path.join(appDir, 'src', 'admin', file);
const configFile = await loadFile(filePath);

if (configFile) {
return { path: filePath, config: configFile };
if (fs.existsSync(filePath)) {
return { path: filePath };
}
}

Expand Down
4 changes: 1 addition & 3 deletions packages/core/admin/_internal/node/core/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const pathExists = async (path: string) => {
const loadFile = async (path: string): Promise<undefined | any> => {
if (await pathExists(path)) {
const esbuildOptions: Parameters<typeof register>[0] = {
extensions: ['.js', '.mjs', '.ts', '.jsx', '.tsx'],
jsx: 'automatic',
loader: 'jsx',
extensions: ['.js', '.mjs', '.ts'],
};

const { unregister } = register(esbuildOptions);
Expand Down

0 comments on commit c9ec5ee

Please sign in to comment.