Skip to content

Commit 4878e52

Browse files
authored
chore: rewrite package to esmodules (#57)
* chore: change to ECMAScript modules BREAKING CHANGE: The package won't support CJS anymore.
1 parent 211254e commit 4878e52

29 files changed

+4636
-4025
lines changed

.eslintrc.js .eslintrc.cjs

+11-15
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ module.exports = {
1313
ecmaFeatures: {
1414
jsx: true,
1515
},
16-
ecmaVersion: 11,
16+
ecmaVersion: 20,
1717
sourceType: 'module',
1818
},
19-
plugins: [
20-
'react',
21-
'@typescript-eslint',
22-
],
19+
plugins: ['react', '@typescript-eslint'],
2320
rules: {
2421
semi: ['error', 'never'],
2522
'no-unused-vars': 'off',
@@ -30,19 +27,18 @@ module.exports = {
3027
'import/extensions': 'off',
3128
'import/no-unresolved': 'off',
3229
'react/jsx-filename-extension': 'off',
33-
indent: [
34-
'error',
35-
2,
36-
],
30+
indent: ['error', 2],
3731
'linebreak-style': ['error', 'unix'],
3832
'object-curly-newline': 'off',
3933
'@typescript-eslint/no-explicit-any': 'off',
4034
},
41-
overrides: [{
42-
files: ['*.tsx'],
43-
rules: {
44-
'react/prop-types': 'off',
45-
'react/jsx-props-no-spreading': 'off',
35+
overrides: [
36+
{
37+
files: ['*.tsx'],
38+
rules: {
39+
'react/prop-types': 'off',
40+
'react/jsx-props-no-spreading': 'off',
41+
},
4642
},
47-
}],
43+
],
4844
}

.github/workflows/push.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
- name: Checkout
99
uses: actions/checkout@v2
1010
- name: Setup
11-
uses: actions/setup-node@v1
11+
uses: actions/setup-node@v2
1212
with:
13-
node-version: '12.x'
14-
- uses: actions/cache@v1
13+
node-version: '18.x'
14+
- uses: actions/cache@v2
1515
id: yarn-cache
1616
with:
1717
path: node_modules
@@ -46,10 +46,10 @@ jobs:
4646
- name: Checkout
4747
uses: actions/checkout@v2
4848
- name: Setup
49-
uses: actions/setup-node@v1
49+
uses: actions/setup-node@v2
5050
with:
51-
node-version: '12.x'
52-
- uses: actions/cache@v1
51+
node-version: '18.x'
52+
- uses: actions/cache@v2
5353
id: yarn-cache
5454
with:
5555
path: node_modules
@@ -74,10 +74,10 @@ jobs:
7474
- name: Checkout
7575
uses: actions/checkout@v2
7676
- name: Setup
77-
uses: actions/setup-node@v1
77+
uses: actions/setup-node@v2
7878
with:
79-
node-version: '12.x'
80-
- uses: actions/cache@v1
79+
node-version: '18.x'
80+
- uses: actions/cache@v2
8181
id: yarn-cache
8282
with:
8383
path: node_modules

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}
File renamed without changes.

example-app/src/entity/Car.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ import { Seller } from './Seller'
55
@Entity()
66
export class Car extends BaseEntity {
77
@PrimaryGeneratedColumn()
8-
id: number;
8+
id: number
99

1010
@Column()
11-
name: string;
11+
name: string
1212

1313
@Column({
1414
type: 'jsonb',
1515
nullable: true,
1616
})
17-
meta: any;
17+
meta: any
1818

1919
@ManyToOne((type) => User, (user) => user.cars)
20-
owner: User;
20+
owner: User
2121

2222
@ManyToOne((type) => Seller, (seller) => seller.cars)
23-
seller: User;
23+
seller: User
2424

2525
// in order be able to fetch resources in adminjs - we have to have id available
2626
@RelationId((car: Car) => car.owner)
27-
ownerId: number;
27+
ownerId: number
2828

2929
@RelationId((car: Car) => car.seller)
30-
sellerId: string;
30+
sellerId: string
3131
}

example-app/src/entity/Seller.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export enum UserRoles {
99
@Entity()
1010
export class Seller extends BaseEntity {
1111
@PrimaryGeneratedColumn('uuid')
12-
id: string;
12+
id: string
1313

1414
@Column()
15-
name: string;
15+
name: string
1616

1717
@OneToMany((type) => Car, (car) => car.seller)
18-
cars: Array<Car>
18+
cars: Array<Car>
1919
}

example-app/src/entity/User.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ export enum UserRoles {
99
@Entity()
1010
export class User extends BaseEntity {
1111
@PrimaryGeneratedColumn()
12-
id: number;
12+
id: number
1313

1414
@Column()
15-
firstName: string;
15+
firstName: string
1616

1717
@Column()
18-
lastName: string;
18+
lastName: string
1919

2020
@Column()
21-
age: number;
21+
age: number
2222

2323
@Column({
2424
type: 'enum',
2525
enum: UserRoles,
2626
})
27-
role: UserRoles;
27+
role: UserRoles
2828

2929
@OneToMany((type) => Car, (car) => car.owner)
30-
cars: Array<Car>
30+
cars: Array<Car>
3131
}

package.json

+37-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"name": "@adminjs/typeorm",
3+
"type": "module",
4+
"exports": {
5+
".": {
6+
"import": "./lib/index.js",
7+
"types": "./lib/index.d.ts"
8+
}
9+
},
310
"version": "4.0.0",
411
"description": "TypeORM adapter for AdminJS",
512
"keywords": [
@@ -10,18 +17,16 @@
1017
"typeorm admin",
1118
"admin panel"
1219
],
13-
"main": "lib/index.js",
14-
"types": "lib/index.d.ts",
1520
"scripts": {
1621
"clean": "rm -fR lib",
1722
"build": "tsc",
1823
"dev": "yarn clean && tsc -w",
19-
"test": "mocha -r ts-node/register ./spec/**/*.spec.ts",
24+
"test": "mocha --loader=ts-node/esm ./spec/**/*.spec.ts",
2025
"ts-node": "ts-node",
21-
"lint": "eslint './src/**/*.{ts,js}' './spec/**/*.{ts,js}' './example-app/**/*.{ts,js}' --ignore-pattern 'build' --ignore-pattern 'yarn.lock'",
22-
"migrate": "ts-node ./node_modules/typeorm/cli.js migration:run -d spec/utils/test-data-source.ts",
26+
"lint": "eslint './src/**/*.{ts,js}' --ignore-pattern 'build' --ignore-pattern 'yarn.lock'",
2327
"check:all": "yarn lint && yarn test && yarn build",
24-
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
28+
"typeorm": "typeorm-ts-node-esm -d \"./spec/utils/test-data-source.ts\"",
29+
"migrate": "yarn typeorm migration:run",
2530
"release": "semantic-release"
2631
},
2732
"repository": {
@@ -36,36 +41,36 @@
3641
"author": "Artem Zabolotnyi <[email protected]>",
3742
"license": "MIT",
3843
"peerDependencies": {
39-
"adminjs": ">=6.0.0",
44+
"adminjs": "^7.0.0",
4045
"typeorm": "~0.3.0"
4146
},
4247
"optionalDependencies": {},
4348
"devDependencies": {
44-
"@commitlint/cli": "^8.3.5",
45-
"@commitlint/config-conventional": "^8.3.4",
46-
"@semantic-release/git": "^9.0.0",
47-
"@types/chai": "^4.2.4",
48-
"@types/mocha": "^5.2.7",
49-
"@types/node": "12.0.10",
50-
"@typescript-eslint/eslint-plugin": "^3.7.0",
51-
"@typescript-eslint/parser": "^3.7.0",
52-
"adminjs": "^6.0.0",
53-
"chai": "^4.2.0",
54-
"class-validator": "^0.11.0",
55-
"eslint": "^7.5.0",
56-
"eslint-config-airbnb": "^18.2.0",
57-
"eslint-plugin-import": "^2.22.0",
58-
"eslint-plugin-jsx-a11y": "^6.3.1",
59-
"eslint-plugin-react": "^7.20.3",
60-
"eslint-plugin-react-hooks": "^4.0.8",
49+
"@commitlint/cli": "^17.4.4",
50+
"@commitlint/config-conventional": "^17.4.4",
51+
"@semantic-release/git": "^10.0.1",
52+
"@types/chai": "^4.3.4",
53+
"@types/mocha": "^10.0.1",
54+
"@types/node": "^18.15.3",
55+
"@typescript-eslint/eslint-plugin": "^5.55.0",
56+
"@typescript-eslint/parser": "^5.55.0",
57+
"adminjs": "^7.0.0",
58+
"chai": "^4.3.7",
59+
"class-validator": "^0.14.0",
60+
"eslint": "^8.36.0",
61+
"eslint-config-airbnb": "^19.0.4",
62+
"eslint-plugin-import": "^2.27.5",
63+
"eslint-plugin-jsx-a11y": "^6.7.1",
64+
"eslint-plugin-react": "^7.32.2",
65+
"eslint-plugin-react-hooks": "^4.6.0",
6166
"husky": "^4.2.5",
62-
"mocha": "^6.2.2",
63-
"pg": "^8.7.3",
64-
"semantic-release": "^17.0.7",
65-
"semantic-release-slack-bot": "^1.6.2",
66-
"ts-node": "^10.7.0",
67-
"tsconfig-paths": "^3.14.1",
68-
"typeorm": "~0.3.0",
69-
"typescript": "^4.6.3"
67+
"mocha": "^10.2.0",
68+
"pg": "^8.10.0",
69+
"semantic-release": "^20.1.3",
70+
"semantic-release-slack-bot": "^4.0.0",
71+
"ts-node": "^10.9.1",
72+
"tsconfig-paths": "^4.1.2",
73+
"typeorm": "^0.3.12",
74+
"typescript": "^4.9.5"
7075
}
7176
}

spec/Database.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai'
22

3-
import { dataSource } from './utils/test-data-source'
4-
import { Database } from '../src/Database'
3+
import { Database } from '../src/Database.js'
4+
import { dataSource } from './utils/test-data-source.js'
55

66
describe('Database', () => {
77
before(async () => {

spec/Property.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { expect } from 'chai'
22

3-
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata'
4-
import { Property } from '../src/Property'
5-
import { Car } from './entities/Car'
6-
import { dataSource } from './utils/test-data-source'
3+
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata.js'
4+
import { Property } from '../src/Property.js'
5+
import { Car } from './entities/Car.js'
6+
import { dataSource } from './utils/test-data-source.js'
77

88
describe('Property', () => {
99
let columns: Array<ColumnMetadata>

spec/Resource.spec.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { BaseProperty, BaseRecord, Filter, ValidationError } from 'adminjs'
12
import { expect } from 'chai'
2-
import { BaseProperty, BaseRecord, ValidationError, Filter } from 'adminjs'
33
import { validate } from 'class-validator'
44

5-
import { Car } from './entities/Car'
6-
import { CarDealer } from './entities/CarDealer'
7-
import { dataSource } from './utils/test-data-source'
5+
import { Car } from './entities/Car.js'
6+
import { CarDealer } from './entities/CarDealer.js'
7+
import { dataSource } from './utils/test-data-source.js'
88

9-
import { Resource } from '../src/Resource'
10-
import { CarBuyer } from './entities/CarBuyer'
9+
import { Resource } from '../src/Resource.js'
10+
import { CarBuyer } from './entities/CarBuyer.js'
1111

1212
describe('Resource', () => {
1313
let resource: Resource
@@ -140,7 +140,7 @@ describe('Resource', () => {
140140
const params = await resource.create(data)
141141
const reference: any = {}
142142
reference[resource.idName()] = params.carId
143-
const storedRecord: Car|null = await Car.findOneBy(reference)
143+
const storedRecord: Car | null = await Car.findOneBy(reference)
144144

145145
expect(storedRecord?.streetNumber).to.equal(data.streetNumber)
146146
})
@@ -149,7 +149,7 @@ describe('Resource', () => {
149149
const params = await resource.create(data)
150150
const reference: any = {}
151151
reference[resource.idName()] = params.carId
152-
const storedRecord: Car|null = await Car.findOneBy(reference)
152+
const storedRecord: Car | null = await Car.findOneBy(reference)
153153

154154
expect(storedRecord?.stringAge).to.equal(4)
155155
})
@@ -158,7 +158,7 @@ describe('Resource', () => {
158158
const params = await resource.create(data)
159159
const reference: any = {}
160160
reference[resource.idName()] = params.carId
161-
const storedRecord: Car|null = await Car.findOneBy(reference)
161+
const storedRecord: Car | null = await Car.findOneBy(reference)
162162

163163
expect(storedRecord?.meta).to.deep.equal({
164164
title: data['meta.title'],

0 commit comments

Comments
 (0)