Skip to content

Commit ceca0ca

Browse files
author
Jarosław Wasiak
committed
chore: change to ECMAScript modules
1 parent 262c58b commit ceca0ca

File tree

11 files changed

+144
-130
lines changed

11 files changed

+144
-130
lines changed

.eslintrc.cjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module.exports = {
2+
env: {
3+
es2020: true,
4+
},
5+
extends: [
6+
"airbnb",
7+
"plugin:react/recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
],
10+
parser: "@typescript-eslint/parser",
11+
parserOptions: {
12+
ecmaFeatures: {
13+
jsx: true,
14+
},
15+
ecmaVersion: 20,
16+
sourceType: "module",
17+
},
18+
plugins: ["react", "@typescript-eslint"],
19+
rules: {
20+
semi: ["error", "always"],
21+
"no-unused-vars": "off",
22+
"import/extensions": "off",
23+
"import/no-unresolved": "off",
24+
"react/jsx-filename-extension": "off",
25+
indent: ["error", 2],
26+
"linebreak-style": ["error", "unix"],
27+
"object-curly-newline": "off",
28+
"@typescript-eslint/no-explicit-any": "off",
29+
},
30+
overrides: [
31+
{
32+
files: ["*.tsx"],
33+
rules: {
34+
"react/prop-types": "off",
35+
"react/jsx-props-no-spreading": "off",
36+
"import/no-extraneous-dependencies": "off",
37+
},
38+
},
39+
{
40+
files: ["./src/**/*.spec.ts", "spec/*.ts"],
41+
rules: {
42+
"no-unused-expressions": "off",
43+
"prefer-arrow-callback": "off",
44+
"func-names": "off",
45+
"import/no-extraneous-dependencies": "off",
46+
},
47+
},
48+
],
49+
};

.eslintrc.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* @type {typeof BaseDatabase}
7979
* @static
8080
*/
81-
import Database from './src/database';
81+
import Database from './src/database.js';
8282

8383
/**
8484
* Implementation of {@link BaseResource} for Sequelize Adapter
@@ -87,10 +87,10 @@ import Database from './src/database';
8787
* @type {typeof BaseResource}
8888
* @static
8989
*/
90-
import Resource from './src/resource';
90+
import Resource from './src/resource.js';
9191

92-
export { default as Resource } from './src/resource';
93-
export { default as Database } from './src/database';
92+
export { default as Database } from './src/database.js';
93+
export { default as Resource } from './src/resource.js';
9494

9595
module.exports = { Database, Resource };
9696

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
"name": "@adminjs/sequelize",
33
"version": "3.0.0",
44
"description": "Sequelize adapter for AdminJS",
5-
"main": "lib/index.js",
6-
"types": "lib/index.d.ts",
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"import": "./build/index.js",
9+
"types": "./types/index.d.ts"
10+
}
11+
},
712
"scripts": {
813
"build": "tsc",
914
"dev": "tsc --watch",
@@ -59,7 +64,7 @@
5964
"sinon": "^12.0.1",
6065
"sinon-chai": "^3.7.0",
6166
"ts-node": "^9.0.0",
62-
"typescript": "^4.0.2"
67+
"typescript": "^4.9.5"
6368
},
6469
"dependencies": {
6570
"escape-regexp": "0.0.1",

src/database.spec.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,53 @@
1-
import Sequelize from 'sequelize';
1+
import Sequelize from "sequelize";
22

3-
import chai, { expect } from 'chai';
4-
import sinonChai from 'sinon-chai';
3+
import chai, { expect } from "chai";
4+
import sinonChai from "sinon-chai";
55

6-
import Database from './database';
7-
import Resource from './resource';
8-
import db from '../models/index.js';
6+
import db from "../models/index.js";
7+
import Database from "./database.js";
8+
import Resource from "./resource.js";
99

1010
chai.use(sinonChai);
1111

12-
const config = require('../config/config');
13-
14-
describe('Database', () => {
15-
before(function () {
16-
this.sequelize = new (Sequelize as any)(config[process.env.NODE_ENV as string]) as any;
17-
this.sequelize.define('User', {
18-
firstName: Sequelize.STRING,
19-
lastName: Sequelize.STRING,
20-
email: Sequelize.STRING,
21-
arrayed: Sequelize.ARRAY(Sequelize.STRING),
22-
}, {});
12+
const config = require("../config/config.js");
13+
14+
describe("Database", () => {
15+
before(function() {
16+
this.sequelize = new (Sequelize as any)(
17+
config[process.env.NODE_ENV as string]
18+
) as any;
19+
this.sequelize.define(
20+
"User",
21+
{
22+
firstName: Sequelize.STRING,
23+
lastName: Sequelize.STRING,
24+
email: Sequelize.STRING,
25+
arrayed: Sequelize.ARRAY(Sequelize.STRING),
26+
},
27+
{}
28+
);
2329
});
2430

25-
describe('.isAdapterFor', () => {
26-
it('returns true when user gives entire db object generated by cli', () => {
31+
describe(".isAdapterFor", () => {
32+
it("returns true when user gives entire db object generated by cli", () => {
2733
expect(Database.isAdapterFor(db)).to.equal(true);
2834
});
2935

30-
it('returns true when user gives sequelize', function () {
36+
it("returns true when user gives sequelize", function() {
3137
expect(Database.isAdapterFor(this.sequelize)).to.equal(true);
3238
});
3339
});
3440

35-
describe('#resources', () => {
36-
it('fetches all resources when entire db is given', () => {
41+
describe("#resources", () => {
42+
it("fetches all resources when entire db is given", () => {
3743
const database = new Database(db);
38-
expect(database.resources()).to.have.lengthOf(Object.keys(db.sequelize.models).length);
44+
expect(database.resources()).to.have.lengthOf(
45+
Object.keys(db.sequelize.models).length
46+
);
3947
expect(database.resources()[0]).to.be.an.instanceof(Resource);
4048
});
4149

42-
it('fetches all resources when user gives sequelize', function () {
50+
it("fetches all resources when user gives sequelize", function() {
4351
const database = new Database(this.sequelize);
4452
expect(database.resources()).to.have.lengthOf(1);
4553
expect(database.resources()[0]).to.be.an.instanceof(Resource);

src/database.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { BaseDatabase, BaseResource } from 'adminjs';
22
import { Sequelize } from 'sequelize';
33

4-
import Resource from './resource';
4+
import Resource from './resource.js';
55

66
class Database extends BaseDatabase {
77
private sequelize: Sequelize
88

99
static isAdapterFor(database: any): boolean {
1010
return (database.sequelize
11-
&& database.sequelize.constructor.name === 'Sequelize')
12-
|| database.constructor.name === 'Sequelize';
11+
&& database.sequelize.constructor.name === 'Sequelize')
12+
|| database.constructor.name === 'Sequelize';
1313
}
1414

1515
constructor(database: any) {

src/property.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
import chai, { expect } from 'chai';
33
import sinonChai from 'sinon-chai';
4-
import { AvailableTestModels } from './utils/available-test-models';
4+
import { AvailableTestModels } from './utils/available-test-models.js';
55

6-
import Property from './property';
6+
import Property from './property.js';
77

88
chai.use(sinonChai);
99

0 commit comments

Comments
 (0)