Skip to content

Commit 42b385f

Browse files
committed
fix: fix issues after migrating to ESM
1 parent 93339ea commit 42b385f

13 files changed

+2280
-1437
lines changed

example-app/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- POSTGRES_USER=adminjs
1010
- POSTGRES_PASSWORD=adminjs
1111
ports:
12-
- "5432:5432"
12+
- "5433:5432"
1313
volumes:
1414
- adminjs_leaflet_db:/var/lib/postgresql/data
1515

example-app/package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "example-app",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"type": "module",
55
"license": "MIT",
66
"scripts": {
7-
"start": "ts-node src/app"
7+
"build": "tsc",
8+
"start": "dotenv -c '.env' -- node ./dist/app.js"
89
},
910
"dependencies": {
10-
"@adminjs/express": "^5.1.0",
11-
"@adminjs/leaflet": "^1.0.0",
12-
"@adminjs/typeorm": "^4.0.0",
13-
"adminjs": "^6.8.1",
11+
"@adminjs/express": "^6.1.0",
12+
"@adminjs/leaflet": "^2.0.0",
13+
"@adminjs/typeorm": "^5.0.1",
14+
"adminjs": "^7.8.1",
1415
"cors": "^2.8.5",
1516
"dotenv": "^16.0.3",
1617
"express": "^4.18.2",
@@ -26,7 +27,8 @@
2627
"@types/express": "^4.17.15",
2728
"@types/geojson": "^7946.0.10",
2829
"@types/node": "^18.11.18",
29-
"ts-node": "^10.9.1",
30-
"typescript": "^4.9.4"
30+
"dotenv-cli": "^7.4.1",
31+
"ts-node": "^10.9.2",
32+
"typescript": "^4.9.5"
3133
}
3234
}

example-app/src/app.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
import 'reflect-metadata';
66
import leafletFeatures, { getLeafletDist } from '@adminjs/leaflet';
77

8-
import dotenv from 'dotenv';
9-
dotenv.config({ path: `${process.cwd()}/.env` });
10-
118
import AdminJS, { ComponentLoader } from 'adminjs';
129
import Plugin from '@adminjs/express';
1310
import * as Adapter from '@adminjs/typeorm';
1411
import express from 'express';
1512
import cors from 'cors';
1613

17-
import datasource from './db/datasource';
18-
import { Marker } from './db/marker.entity';
19-
import { Map as MapEntity } from './db/map.entity';
14+
import datasource from './db/datasource.js';
15+
import { Marker } from './db/marker.entity.js';
16+
import { Map as MapEntity } from './db/map.entity.js';
2017

2118
const PORT = process.env.PORT ?? 8080;
2219

@@ -25,13 +22,14 @@ AdminJS.registerAdapter({
2522
Resource: Adapter.Resource,
2623
});
2724

25+
const componentLoader = new ComponentLoader();
26+
2827
const start = async () => {
2928
await datasource.initialize();
3029

31-
const componentLoader = new ComponentLoader();
32-
3330
const app = express();
3431
app.use(cors({ origin: '*' }));
32+
app.use(express.static('public'));
3533
app.use(express.static(getLeafletDist()));
3634

3735
const markerPaths = {
@@ -42,6 +40,7 @@ const start = async () => {
4240
};
4341

4442
const admin = new AdminJS({
43+
componentLoader,
4544
assets: {
4645
styles: ['/leaflet.css'],
4746
},
@@ -74,7 +73,6 @@ const start = async () => {
7473
}),
7574
],
7675
}],
77-
componentLoader,
7876
rootPath: '/',
7977
});
8078

example-app/src/db/datasource.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DataSource, DataSourceOptions } from 'typeorm';
22

3-
import { Map as MapEntity } from './map.entity';
4-
import { Marker } from './marker.entity';
3+
import { Map as MapEntity } from './map.entity.js';
4+
import { Marker } from './marker.entity.js';
55

66
const config: DataSourceOptions = {
77
type: 'postgres' as const,

example-app/src/db/map.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
22

3-
import type { Marker } from './marker.entity';
3+
import type { Marker } from './marker.entity.js';
44

55
@Entity({ name: 'maps' })
66
export class Map extends BaseEntity {

example-app/src/db/marker.entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
22
import { Point } from 'geojson';
33

4-
import type { Map as MapEntity } from './map.entity';
4+
import type { Map as MapEntity } from './map.entity.js';
55

66
@Entity({ name: 'markers' })
77
export class Marker extends BaseEntity {

example-app/tsconfig.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
"target": "esnext",
44
"esModuleInterop": true,
55
"jsx": "react",
6-
"declaration": true,
6+
"declaration": false,
77
"importHelpers": true,
88
"strictNullChecks": true,
99
"strictPropertyInitialization": true,
1010
"strictFunctionTypes": true,
1111
"strictBindCallApply": true,
1212
"noImplicitThis": true,
13-
"moduleResolution": "node",
14-
"module": "commonjs",
13+
"moduleResolution": "nodenext",
14+
"module": "nodenext",
1515
"baseUrl": "./",
16-
"outDir": "lib",
17-
"declarationDir": "types",
16+
"outDir": "dist",
1817
"allowSyntheticDefaultImports": true,
1918
"skipLibCheck": true,
2019
"experimentalDecorators": true

0 commit comments

Comments
 (0)