Skip to content

Commit

Permalink
Fix another issue with TypeScript default exports
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn authored Apr 10, 2023
1 parent 04b2d77 commit 1179da9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

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

## 6.1.3 - 2023-04-10

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions build/build-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ async function buildTypes({
await bundle.write({
file: outputPath,
format: "esm",
// Despite this being an ES module, some TypeScript setups require this.
// (This doesn't remove the `export default` from the final file.)
outro: "export = helmet",
});

await bundle.close();
Expand Down
7 changes: 7 additions & 0 deletions test/project-setups/typescript-nodenext-commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"type": "commonjs",
"scripts": {
"helmet:test": "ts-node-esm --compilerOptions '{\"module\": \"nodenext\", \"moduleResolution\": \"nodenext\"}' test.ts"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"scripts": {
"helmet:test": "ts-node-esm --compilerOptions '{\"module\": \"nodenext\", \"moduleResolution\": \"nodenext\"}' test.ts"
}
Expand Down
42 changes: 42 additions & 0 deletions test/project-setups/typescript-nodenext-esm/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { IncomingMessage, ServerResponse } from "http";
import connect from "connect";
import supertest from "supertest";
import helmet, { frameguard } from "helmet";

const handler = (_: IncomingMessage, res: ServerResponse) =>
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 testImportedMiddleware() {
const app = connect().use(frameguard()).use(handler);
await supertest(app)
.get("/")
.expect(200, "Hello world")
.expect("x-frame-options", "SAMEORIGIN");
}

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

async function main() {
await testTopLevel();
await testImportedMiddleware();
await testAttachedMiddleware();
}

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

0 comments on commit 1179da9

Please sign in to comment.