8000 fix: make ESM transpiled CommonJS play nice for TS folks, fix #1513 (… · koajs/koa@b5472f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5472f4

Browse files
authored
fix: make ESM transpiled CommonJS play nice for TS folks, fix #1513 (#1518)
1 parent b4398f5 commit b5472f4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/application.js

+9
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ module.exports = class Application extends Emitter {
211211
const msg = err.stack || err.toString();
212212
console.error(`\n${msg.replace(/^/gm, ' ')}\n`);
213213
}
214+
215+
/**
216+
* Help TS users comply to CommonJS, ESM, bundler mismatch.
217+
* @see https://github.com/koajs/koa/issues/1513
218+
*/
219+
220+
static get default() {
221+
return Application;
222+
}
214223
};
215224

216225
/**

test/load-with-esm.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@ describe('Load with esm', () => {
2828
for (const k of ['prototype', 'length', 'name']) {
2929
required.delete(k);
3030
}
31-
exported.delete('default');
31+
32+
// Commented out to "fix" CommonJS, ESM, bundling issue.
33+
// @see https://github.com/koajs/koa/issues/1513
34+
// exported.delete('default');
3235

3336
assert.strictEqual(exported.size, required.size);
3437
assert.strictEqual([...exported].every(property => required.has(property)), true);
3538
});
39+
40+
it('CommonJS exports default property', async() => {
41+
const required = require('../');
42+
assert.strictEqual(required.hasOwnProperty('default'), true);
43+
});
44+
45+
it('CommonJS exports default property referencing self', async() => {
46+
const required = require('../');
47+
assert.strictEqual(required.default, required);
48+
});
3649
});

0 commit comments

Comments
 (0)
0