Skip to content

Commit

Permalink
Feat/v6 (#106)
Browse files Browse the repository at this point in the history
* chore: update package to esm

BREAKING CHANGE: The package won't support CJS anymore
  • Loading branch information
dziraf authored Apr 18, 2023
1 parent 3a7c7f0 commit 9e8945f
Show file tree
Hide file tree
Showing 19 changed files with 4,984 additions and 3,992 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {
jsx: true,
Expand Down
37 changes: 9 additions & 28 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: "10.x"
- uses: actions/cache@v1
node-version: "18.x"
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
Expand All @@ -34,10 +34,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: "10.x"
- uses: actions/cache@v1
node-version: "18.x"
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
Expand All @@ -62,10 +62,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: "10.x"
- uses: actions/cache@v1
node-version: "18.x"
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
Expand All @@ -85,22 +85,3 @@ jobs:
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
run: yarn release

notify:
name: Notify
runs-on: ubuntu-latest
if: failure()
needs:
- test
- setup
- publish
steps:
- uses: technote-space/workflow-conclusion-action@v1
- uses: 8398a7/action-slack@v3
with:
status: ${{ env.WORKFLOW_CONCLUSION }}
fields: repo,message,commit,author,action,eventName,ref,workflow # selectable (default: repo,message)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
if: always()
10 changes: 1 addition & 9 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git",
["semantic-release-jira-releases-sb", {
"projectId": "AB",
"releaseNameTemplate": "v${version}",
"jiraHost": "kmpgroup.atlassian.net",
"ticketPrefixes": [ "AB" ],
"released": true,
"setReleaseDate": true
}],
[
"semantic-release-slack-bot",
{
"notifyOnSuccess": true,
"notifyOnFail": true
"notifyOnFail": false
}
]
]
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import MongooseAdapter from "@adminjs/mongoose";
import AdminJS from "adminjs";
import express from "express";
import mongoose from "mongoose";
import AdminJSExpress from "../src";
import "./mongoose/admin-model";

import "./mongoose/article-model";
import AdminJSExpress from "../src/index.js";
import "./mongoose/admin-model.js";
import "./mongoose/article-model.js";

AdminJS.registerAdapter(MongooseAdapter);

Expand Down
9 changes: 4 additions & 5 deletions examples/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import express from "express";
import mongoose from "mongoose";
import MongooseAdapter from "@adminjs/mongoose";

import AdminJSExpress from "../src";
import "./mongoose/article-model";
import "./mongoose/admin-model";
import AdminJSExpress from "../src/index.js";
import "./mongoose/article-model.js";
import "./mongoose/admin-model.js";

AdminJS.registerAdapter(MongooseAdapter);

const start = async () => {
const connection = await mongoose.connect(
process.env.MONGO_URL || "mongodb://localhost:27017/example",
{ useNewUrlParser: true, useUnifiedTopology: true }
process.env.MONGO_URL || "mongodb://localhost:27017/example"
);
const app = express();

Expand Down
26 changes: 26 additions & 0 deletions jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"moduleFileExtensions": ["js", "json", "ts", "tsx"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".test.ts$",
"extensionsToTreatAsEsm": [".ts"],
"transformIgnorePatterns": ["node_modules"],
"transform": {
"^.+\\.(t|j)sx?$": [
"ts-jest",
{
"useESM": true,
"tsconfig": "./tsconfig.test.json",
"isolatedModules": true
}
]
},
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"testTimeout": 10000,
"preset": "ts-jest/presets/default-esm",
"verbose": true,
"silent": true,
"forceExit": true
}
73 changes: 37 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
"version": "5.1.0",
"description": "This is an official AdminJS plugin which integrates it with Express.js framework",
"main": "lib/index.js",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
}
},
"scripts": {
"dev": "rm -rf lib && tsc --watch",
"build": "rm -rf lib && tsc",
"example:simple": "nodemon",
"example:auth": "nodemon --config nodemon.auth.json",
"test": "jest --config ./test/jest.json",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.json --runInBand --detectOpenHandles",
"lint": "eslint './**/*.ts'",
"check:all": "yarn lint && yarn build && yarn test",
"release": "semantic-release"
Expand All @@ -30,55 +37,49 @@
},
"homepage": "https://github.com/SoftwareBrothers/adminjs-expressjs#readme",
"peerDependencies": {
"adminjs": ">=6.0.0",
"express": ">=4.16.4",
"adminjs": "^7.0.0",
"express": ">=4.18.2",
"express-formidable": "^1.2.0",
"express-session": ">=1.15.6",
"tslib": "^2.3.1"
"express-session": ">=1.17.3",
"tslib": "^2.5.0"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"devDependencies": {
"@adminjs/mongoose": "^2.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@adminjs/mongoose": "^4.0.0",
"@commitlint/config-conventional": "^17.4.4",
"@jest/globals": "^29.5.0",
"@semantic-release/git": "^9.0.0",
"@types/express": "^4.17.9",
"@types/express-formidable": "^1.0.4",
"@types/express-serve-static-core": "^4.17.13",
"@types/express-session": "^1.17.3",
"@types/express": "^4.17.17",
"@types/express-formidable": "^1.2.0",
"@types/express-session": "^1.17.6",
"@types/jest": "^26.0.15",
"@types/mongoose": "^5.10.1",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"adminjs": "^6.0.0",
"chai": "^4.2.0",
"commitlint": "^11.0.0",
"eslint": "^7.13.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"express": "^4.17.1",
"@types/node": "^18.15.3",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"adminjs": "^7.0.0",
"commitlint": "^17.4.4",
"eslint": "^8.35.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"express": "^4.18.2",
"express-formidable": "^1.2.0",
"express-session": "^1.17.1",
"express-session": "^1.17.3",
"husky": "^4.3.0",
"jest": "^26.6.3",
"mongoose": "^5.10.15",
"jest": "^29.5.0",
"mongoose": "^6.10.0",
"nodemon": "^2.0.6",
"prettier": "^2.2.0",
"prettier": "^2.8.4",
"semantic-release": "^17.2.4",
"semantic-release-jira-releases-sb": "^0.7.2",
"semantic-release-slack-bot": "^1.6.2",
"sinon": "^9.2.1",
"sinon-chai": "^3.5.0",
"ts-jest": "^26.4.4",
"ts-node": "^9.0.0",
"typescript": "^4.1.2"
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"dependencies": {
"path-to-regexp": "^6.2.0"
}
"dependencies": {}
}
5 changes: 3 additions & 2 deletions src/authentication/login.handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import AdminJS from "adminjs";
import { Router } from "express";
import {

import type {
AuthenticationContext,
AuthenticationMaxRetriesOptions,
AuthenticationOptions,
} from "../types";
} from "../types.js";

const getLoginPath = (admin: AdminJS): string => {
const { loginPath, rootPath } = admin.options;
Expand Down
20 changes: 11 additions & 9 deletions src/buildAuthenticatedRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import AdminJS, { Router as AdminRouter } from "adminjs";
import express, { Router } from "express";
import formidableMiddleware from "express-formidable";
import session from "express-session";
import { withLogin } from "./authentication/login.handler";
import { withLogout } from "./authentication/logout.handler";
import { withProtectedRoutesHandler } from "./authentication/protected-routes.handler";
import { buildAssets, buildRoutes, initializeAdmin } from "./buildRouter";
import { OldBodyParserUsedError } from "./errors";
import { AuthenticationOptions, FormidableOptions } from "./types";

import { withLogin } from "./authentication/login.handler.js";
import { withLogout } from "./authentication/logout.handler.js";
import { withProtectedRoutesHandler } from "./authentication/protected-routes.handler.js";
import { buildAssets, buildRoutes, initializeAdmin } from "./buildRouter.js";
import { OldBodyParserUsedError } from "./errors.js";
import { AuthenticationOptions, FormidableOptions } from "./types.js";

/**
* @typedef {Function} Authenticate
Expand Down Expand Up @@ -64,18 +65,19 @@ export const buildAuthenticatedRouter = (
next();
});

// todo fix types
router.use(
session({
...sessionOptions,
secret: auth.cookiePassword,
name: auth.cookieName || "adminjs",
})
}) as any
);
router.use(formidableMiddleware(formidableOptions));
router.use(formidableMiddleware(formidableOptions) as any);

withLogin(router, admin, auth);
withLogout(router, admin);
buildAssets({ assets, router });
buildAssets({ admin, assets, routes, router });

withProtectedRoutesHandler(router, admin);
buildRoutes({ admin, routes, router });
Expand Down
Loading

0 comments on commit 9e8945f

Please sign in to comment.