Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issues after migrating to ESM #6

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example-app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- POSTGRES_USER=adminjs
- POSTGRES_PASSWORD=adminjs
ports:
- "5432:5432"
- "5433:5432"
volumes:
- adminjs_leaflet_db:/var/lib/postgresql/data

Expand Down
18 changes: 10 additions & 8 deletions example-app/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "example-app",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"license": "MIT",
"scripts": {
"start": "ts-node src/app"
"build": "tsc",
"start": "dotenv -c '.env' -- node ./dist/app.js"
},
"dependencies": {
"@adminjs/express": "^5.1.0",
"@adminjs/leaflet": "^1.0.0",
"@adminjs/typeorm": "^4.0.0",
"adminjs": "^6.8.1",
"@adminjs/express": "^6.1.0",
"@adminjs/leaflet": "^2.0.0",
"@adminjs/typeorm": "^5.0.1",
"adminjs": "^7.8.1",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
Expand All @@ -26,7 +27,8 @@
"@types/express": "^4.17.15",
"@types/geojson": "^7946.0.10",
"@types/node": "^18.11.18",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"dotenv-cli": "^7.4.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
}
}
16 changes: 7 additions & 9 deletions example-app/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
import 'reflect-metadata';
import leafletFeatures, { getLeafletDist } from '@adminjs/leaflet';

import dotenv from 'dotenv';
dotenv.config({ path: `${process.cwd()}/.env` });

import AdminJS, { ComponentLoader } from 'adminjs';
import Plugin from '@adminjs/express';
import * as Adapter from '@adminjs/typeorm';
import express from 'express';
import cors from 'cors';

import datasource from './db/datasource';
import { Marker } from './db/marker.entity';
import { Map as MapEntity } from './db/map.entity';
import datasource from './db/datasource.js';
import { Marker } from './db/marker.entity.js';
import { Map as MapEntity } from './db/map.entity.js';

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

Expand All @@ -25,13 +22,14 @@ AdminJS.registerAdapter({
Resource: Adapter.Resource,
});

const componentLoader = new ComponentLoader();

const start = async () => {
await datasource.initialize();

const componentLoader = new ComponentLoader();

const app = express();
app.use(cors({ origin: '*' }));
app.use(express.static('public'));
app.use(express.static(getLeafletDist()));

const markerPaths = {
Expand All @@ -42,6 +40,7 @@ const start = async () => {
};

const admin = new AdminJS({
componentLoader,
assets: {
styles: ['/leaflet.css'],
},
Expand Down Expand Up @@ -74,7 +73,6 @@ const start = async () => {
}),
],
}],
componentLoader,
rootPath: '/',
});

Expand Down
4 changes: 2 additions & 2 deletions example-app/src/db/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataSource, DataSourceOptions } from 'typeorm';

import { Map as MapEntity } from './map.entity';
import { Marker } from './marker.entity';
import { Map as MapEntity } from './map.entity.js';
import { Marker } from './marker.entity.js';

const config: DataSourceOptions = {
type: 'postgres' as const,
Expand Down
2 changes: 1 addition & 1 deletion example-app/src/db/map.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';

import type { Marker } from './marker.entity';
import type { Marker } from './marker.entity.js';

@Entity({ name: 'maps' })
export class Map extends BaseEntity {
Expand Down
2 changes: 1 addition & 1 deletion example-app/src/db/marker.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Point } from 'geojson';

import type { Map as MapEntity } from './map.entity';
import type { Map as MapEntity } from './map.entity.js';

@Entity({ name: 'markers' })
export class Marker extends BaseEntity {
Expand Down
9 changes: 4 additions & 5 deletions example-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
"target": "esnext",
"esModuleInterop": true,
"jsx": "react",
"declaration": true,
"declaration": false,
"importHelpers": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"moduleResolution": "node",
"module": "commonjs",
"moduleResolution": "nodenext",
"module": "nodenext",
"baseUrl": "./",
"outDir": "lib",
"declarationDir": "types",
"outDir": "dist",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"experimentalDecorators": true
Expand Down
Loading
Loading