From 5e0fc4a59f1396ce5099b51e9002f5f6af994ea7 Mon Sep 17 00:00:00 2001 From: Fran Dios Date: Thu, 25 Apr 2024 15:44:53 -0400 Subject: [PATCH] Add ESM build See [#11]. [#11]: https://github.com/helmetjs/content-security-policy-builder/pull/11 --- package.json | 15 ++++++++++++--- test.ts | 4 ++-- tsconfig.json | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 56fec1a..ffdb030 100644 --- a/package.json +++ b/package.json @@ -24,14 +24,22 @@ "engines": { "node": ">=18.0.0" }, + "sideEffects": false, "main": "./dist/index.js", "typings": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "default": "./dist/index.js" + }, + "./package.json": "./package.json" + }, "files": [ "LICENSE", "README.md", "CHANGELOG.md", - "dist/index.js", - "dist/index.d.ts" + "dist" ], "scripts": { "pretest": "npm run lint", @@ -41,7 +49,8 @@ "lint:prettier": "prettier --check .", "format": "prettier --write .", "clean": "rm -rf dist", - "build": "npm run clean && tsc", + "build": "npm run clean && tsc && npm run build:esm", + "build:esm": "sed 's/module.exports =/export default/' dist/index.js > dist/index.mjs", "test": "ts-node test.ts" }, "devDependencies": { diff --git a/test.ts b/test.ts index 8df85f8..5c0f6c2 100644 --- a/test.ts +++ b/test.ts @@ -1,5 +1,5 @@ -import assert = require("node:assert/strict"); -import builder = require("./index"); +import assert from "node:assert/strict"; +import builder from "./index"; const test = ( message: string, diff --git a/tsconfig.json b/tsconfig.json index 36c0b61..2025eda 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,5 @@ { + "include": ["index.ts"], "compilerOptions": { "declaration": true, "esModuleInterop": true,