Skip to content

Commit

Permalink
fix: make ESM transpiled CommonJS play nice for TS folks, fix koajs#1513
Browse files Browse the repository at this point in the history
  • Loading branch information
miwnwski committed Jan 4, 2021
1 parent 6e1093b commit 0beef00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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
5 changes: 4 additions & 1 deletion test/load-with-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ 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);
Expand Down

0 comments on commit 0beef00

Please sign in to comment.