-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support cjs and esm both by tshy (#20)
BREAKING CHANGE: drop Node.js < 18.19.0 support part of eggjs/egg#3644 eggjs/egg#5257 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **Package Upgrade** - Renamed package from `egg-session` to `@eggjs/session` - Updated Node.js compatibility to version 18.19.0+ - **New Features** - Enhanced session configuration with improved type safety - Added support for more granular session management - Improved logging and security configurations - **Breaking Changes** - Dropped support for Node.js versions below 18.19.0 - Migrated from generator functions to async/await syntax - Updated session middleware and configuration structure - **Performance** - Updated dependencies, including `koa-session` to version 7.0.2 - Optimized session store handling - **Security** - Strengthened default session configurations - Added warnings for potential security risks in session settings <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Showing
36 changed files
with
397 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
test/fixtures | ||
coverage | ||
__snapshots__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "eslint-config-egg" | ||
"extends": [ | ||
"eslint-config-egg/typescript", | ||
"eslint-config-egg/lib/rules/enforce-node-prefix" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Publish Any Commit | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- run: corepack enable | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build | ||
run: npm run prepublishOnly --if-present | ||
|
||
- run: npx pkg-pr-new publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
exports['test/app/middlewares/session.test.js sessionStore should keep session config stable 1'] = { | ||
"key": "EGG_SESS", | ||
"maxAge": 86400000, | ||
"autoCommit": true, | ||
"overwrite": true, | ||
"httpOnly": true, | ||
"signed": true, | ||
"rolling": false, | ||
"renew": false, | ||
"logValue": true, | ||
"store": {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,92 @@ | ||
{ | ||
"name": "egg-session", | ||
"name": "@eggjs/session", | ||
"version": "3.3.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "session plugin for egg", | ||
"eggPlugin": { | ||
"name": "session" | ||
"name": "session", | ||
"exports": { | ||
"import": "./dist/esm", | ||
"require": "./dist/commonjs", | ||
"typescript": "./src" | ||
} | ||
}, | ||
"files": [ | ||
"config", | ||
"app", | ||
"app.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:eggjs/session.git" | ||
}, | ||
"author": "dead_horse", | ||
"keywords": [ | ||
"egg", | ||
"egg-plugin", | ||
"eggPlugin", | ||
"session", | ||
"cookie" | ||
], | ||
"engines": { | ||
"node": ">= 18.19.0" | ||
}, | ||
"dependencies": { | ||
"koa-session": "^6.0.0" | ||
"@eggjs/core": "^6.2.13", | ||
"koa-session": "^7.0.2", | ||
"zod": "^3.24.1" | ||
}, | ||
"devDependencies": { | ||
"egg": "^3.17.5", | ||
"egg-bin": "6", | ||
"egg-mock": "5", | ||
"egg-redis": "^1.0.1", | ||
"@arethetypeswrong/cli": "^0.17.1", | ||
"@eggjs/bin": "7", | ||
"@eggjs/mock": "^6.0.5", | ||
"@eggjs/supertest": "^8.2.0", | ||
"@eggjs/tsconfig": "1", | ||
"@types/mocha": "10", | ||
"@types/node": "22", | ||
"egg": "^4.0.1", | ||
"egg-redis": "^2.6.0", | ||
"eslint": "8", | ||
"eslint-config-egg": "12", | ||
"mz-modules": "^2.0.0", | ||
"supertest": "^3.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"eslint-config-egg": "14", | ||
"rimraf": "6", | ||
"snap-shot-it": "^7.9.10", | ||
"tshy": "3", | ||
"tshy-after": "1", | ||
"typescript": "5" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "npm run lint -- --fix && npm run test-local", | ||
"test-local": "egg-bin test --ts false", | ||
"cov": "egg-bin cov --ts false", | ||
"ci": "npm run lint && npm run cov" | ||
"lint": "eslint --cache src test --ext .ts", | ||
"pretest": "npm run clean && npm run lint -- --fix", | ||
"test": "egg-bin test", | ||
"test:snapshot:update": "SNAPSHOT_UPDATE=1 egg-bin test", | ||
"preci": "npm run clean && npm run lint", | ||
"ci": "egg-bin cov", | ||
"postci": "npm run prepublishOnly && npm run clean", | ||
"clean": "rimraf dist", | ||
"prepublishOnly": "tshy && tshy-after && attw --pack" | ||
}, | ||
"type": "module", | ||
"tshy": { | ||
"exports": { | ||
".": "./src/index.ts", | ||
"./package.json": "./package.json" | ||
} | ||
}, | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/esm/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/index.d.ts", | ||
"default": "./dist/commonjs/index.js" | ||
} | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"author": "dead_horse" | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"types": "./dist/commonjs/index.d.ts", | ||
"main": "./dist/commonjs/index.js", | ||
"module": "./dist/esm/index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ILifecycleBoot, EggCore } from '@eggjs/core'; | ||
import { SessionConfig } from './config/config.default.js'; | ||
|
||
export default class AppBoot implements ILifecycleBoot { | ||
private readonly app; | ||
|
||
constructor(app: EggCore) { | ||
this.app = app; | ||
} | ||
|
||
configWillLoad() { | ||
const app = this.app; | ||
SessionConfig.parse(app.config.session); | ||
|
||
if (!app.config.session.httpOnly) { | ||
app.coreLogger.warn('[@eggjs/session]: please set `config.session.httpOnly` to true. It is very dangerous if session can read by client JavaScript.'); | ||
} | ||
app.config.coreMiddleware.push('session'); | ||
// listen on session's events | ||
app.on('session:missed', ({ ctx, key }) => { | ||
ctx.coreLogger.warn('[session][missed] key(%s)', key); | ||
}); | ||
app.on('session:expired', ({ ctx, key, value }) => { | ||
ctx.coreLogger.warn('[session][expired] key(%s) value(%j)', key, app.config.session.logValue ? value : ''); | ||
}); | ||
app.on('session:invalid', ({ ctx, key, value }) => { | ||
ctx.coreLogger.warn('[session][invalid] key(%s) value(%j)', key, app.config.session.logValue ? value : ''); | ||
}); | ||
} | ||
} |
Oops, something went wrong.