-
Notifications
You must be signed in to change notification settings - Fork 8
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
BREAKING CHANGE: drop Node.js < 18.19.0 support part of eggjs/egg#3644 eggjs/egg#5257
- Loading branch information
Showing
24 changed files
with
270 additions
and
70 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,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
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 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
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.
17 changes: 10 additions & 7 deletions
17
app/middleware/egg_loader_trace.js → src/app/middleware/egg_loader_trace.ts
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,52 @@ | ||
export interface DevelopmentConfig { | ||
/** | ||
* dirs needed watch, when files under these change, application will reload, use relative path | ||
*/ | ||
watchDirs: string[]; | ||
/** | ||
* dirs don't need watch, including subdirectories, use relative path | ||
*/ | ||
ignoreDirs: string[]; | ||
/** | ||
* don't wait all plugins ready, default is false. | ||
*/ | ||
fastReady: boolean; | ||
/** | ||
* whether reload on debug, default is true. | ||
*/ | ||
reloadOnDebug: boolean; | ||
/** | ||
* whether override default watchDirs, default is false. | ||
*/ | ||
overrideDefault: boolean; | ||
/** | ||
* whether override default ignoreDirs, default is false. | ||
*/ | ||
overrideIgnore: boolean; | ||
/** | ||
* whether to reload, use https://github.com/sindresorhus/multimatch | ||
*/ | ||
reloadPattern?: string[] | string; | ||
} | ||
|
||
/** | ||
* @member Config#development | ||
* @property {Array} watchDirs - dirs needed watch, when files under these change, application will reload, use relative path | ||
* @property {Array} ignoreDirs - dirs don't need watch, including subdirectories, use relative path | ||
* @property {Boolean} fastReady - don't wait all plugins ready, default is false. | ||
* @property {Boolean} reloadOnDebug - whether reload on debug, default is true. | ||
* @property {Boolean} overrideDefault - whether override default watchDirs, default is false. | ||
* @property {Boolean} overrideIgnore - whether override default ignoreDirs, default is false. | ||
* @property {Array|String} reloadPattern - whether to reload, use https://github.com/sindresorhus/multimatch | ||
*/ | ||
export default { | ||
development: { | ||
watchDirs: [], | ||
ignoreDirs: [], | ||
fastReady: false, | ||
reloadOnDebug: true, | ||
overrideDefault: false, | ||
overrideIgnore: false, | ||
reloadPattern: undefined, | ||
} as DevelopmentConfig, | ||
}; |
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 @@ | ||
import './types.js'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { DevelopmentConfig } from './config/config.default.js'; | ||
|
||
declare module '@eggjs/core' { | ||
// add EggAppConfig overrides types | ||
interface EggAppConfig { | ||
development: DevelopmentConfig; | ||
} | ||
} |
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,58 @@ | ||
import fs from 'node:fs/promises'; | ||
import { strict as assert } from 'node:assert'; | ||
import { scheduler } from 'node:timers/promises'; | ||
import { mm, MockApplication } from '@eggjs/mock'; | ||
import { escape, getFilepath } from './utils.js'; | ||
|
||
describe('test/development-ts.test.ts', () => { | ||
let app: MockApplication; | ||
before(() => { | ||
mm.env('local'); | ||
app = mm.cluster({ | ||
baseDir: 'development-ts', | ||
}); | ||
return app.ready(); | ||
}); | ||
after(() => app.close()); | ||
afterEach(mm.restore); | ||
// for debounce | ||
afterEach(() => scheduler.wait(500)); | ||
|
||
it('should reload when change service', async () => { | ||
const filepath = getFilepath('development-ts/app/service/a.ts'); | ||
await fs.writeFile(filepath, ''); | ||
await scheduler.wait(5000); | ||
|
||
await fs.unlink(filepath); | ||
app.expect('stdout', new RegExp(escape(`reload worker because ${filepath}`))); | ||
}); | ||
|
||
it('should not reload when change assets', async () => { | ||
const filepath = getFilepath('development-ts/app/assets/b.js'); | ||
await fs.writeFile(filepath, ''); | ||
await scheduler.wait(5000); | ||
|
||
await fs.unlink(filepath); | ||
app.notExpect('stdout', new RegExp(escape(`reload worker because ${filepath}`))); | ||
}); | ||
|
||
it('should reload once when 2 file change', async () => { | ||
const filepath = getFilepath('development-ts/app/service/c.js'); | ||
const filepath1 = getFilepath('development-ts/app/service/d.js'); | ||
await fs.writeFile(filepath, ''); | ||
// set a timeout for watcher's interval | ||
await scheduler.wait(1000); | ||
await fs.writeFile(filepath1, ''); | ||
|
||
await scheduler.wait(2000); | ||
await fs.unlink(filepath); | ||
await fs.unlink(filepath1); | ||
|
||
assert.equal(count(app.stdout, 'reload worker'), 2); | ||
}); | ||
}); | ||
|
||
function count(str: string, match: string) { | ||
const m = str.match(new RegExp(match, 'g')); | ||
return m ? m.length : 0; | ||
} |
Empty file.
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 @@ | ||
alert('bar'); |
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,11 @@ | ||
import { Application } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
app.get('/foo.js', async ctx => { | ||
ctx.body = 'foo.js'; | ||
}); | ||
|
||
app.get('/foo', async ctx => { | ||
ctx.body = 'foo'; | ||
}); | ||
}; |
Empty file.
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,10 @@ | ||
import '../../../../src/index.js'; | ||
|
||
import { EggAppConfig } from 'egg'; | ||
|
||
export default { | ||
keys: 'foo,bar', | ||
development: { | ||
fastReady: false, | ||
}, | ||
} as EggAppConfig; |
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,4 @@ | ||
{ | ||
"name": "development-ts", | ||
"type": "module" | ||
} |
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,10 @@ | ||
{ | ||
"extends": "@eggjs/tsconfig", | ||
"compilerOptions": { | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext" | ||
} | ||
} |
Oops, something went wrong.