Skip to content

Commit

Permalink
Fix default export for some bundlers
Browse files Browse the repository at this point in the history
See [#415](#415).
  • Loading branch information
EvanHahn committed Apr 10, 2023
1 parent 3c3b5b1 commit 8587322
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

- Fix issue with TypeScript default exports. See [#417](https://github.com/helmetjs/helmet/pull/417)

## 6.1.2 - 2023-04-09

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion build/build-package.ts
Expand Up @@ -103,7 +103,11 @@ async function buildCjs({
exports: "named",
format: "cjs",
generatedCode: "es2015",
outro: "module.exports = exports.default;",
outro: [
"module.exports = helmet;",
// Some bundlers import with CommonJS but then pull `default` off.
"module.exports.default = helmet;",
].join("\n"),
});

await bundle.close();
Expand Down
@@ -0,0 +1,7 @@
{
"private": true,
"type": "commonjs",
"scripts": {
"helmet:test": "node test.js"
}
}
31 changes: 31 additions & 0 deletions test/project-setups/javascript-commonjs-default-member/test.js
@@ -0,0 +1,31 @@
const connect = require("connect");
const supertest = require("supertest");
const { default: helmet, frameguard } = require("helmet");

const handler = (_, res) => res.end("Hello world");

async function testTopLevel() {
const app = connect().use(helmet()).use(handler);
await supertest(app)
.get("/")
.expect(200, "Hello world")
.expect("x-download-options", "noopen");
}

async function testMiddleware() {
const app = connect().use(frameguard()).use(handler);
await supertest(app)
.get("/")
.expect(200, "Hello world")
.expect("x-frame-options", "SAMEORIGIN");
}

async function main() {
await testTopLevel();
await testMiddleware();
}

main().catch((err) => {
console.error(err);
process.exit(1);
});

0 comments on commit 8587322

Please sign in to comment.