diff --git a/lib/application.js b/lib/application.js index e01019796..6849d73fd 100644 --- a/lib/application.js +++ b/lib/application.js @@ -211,6 +211,15 @@ module.exports = class Application extends Emitter { const msg = err.stack || err.toString(); console.error(`\n${msg.replace(/^/gm, ' ')}\n`); } + + /** + * Help TS users comply to CommonJS, ESM, bundler mismatch. + * @see https://github.com/koajs/koa/issues/1513 + */ + + static get default() { + return Application; + } }; /** diff --git a/test/load-with-esm.js b/test/load-with-esm.js index 6e564a4a8..87bffda35 100644 --- a/test/load-with-esm.js +++ b/test/load-with-esm.js @@ -28,9 +28,22 @@ describe('Load with esm', () => { for (const k of ['prototype', 'length', 'name']) { required.delete(k); } - exported.delete('default'); + + // Commented out to "fix" CommonJS, ESM, bundling issue. + // @see https://github.com/koajs/koa/issues/1513 + // exported.delete('default'); assert.strictEqual(exported.size, required.size); assert.strictEqual([...exported].every(property => required.has(property)), true); }); + + it('CommonJS exports default property', async() => { + const required = require('../'); + assert.strictEqual(required.hasOwnProperty('default'), true); + }); + + it('CommonJS exports default property referencing self', async() => { + const required = require('../'); + assert.strictEqual(required.default, required); + }); });