Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make ESM transpiled CommonJS play nice for TS folks, fix #1513 #1518

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

/**
Expand Down
15 changes: 14 additions & 1 deletion test/load-with-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});