Skip to content

Commit

Permalink
Fix ESM build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Mar 9, 2024
1 parent b36a4d0 commit 27e2863
Show file tree
Hide file tree
Showing 8 changed files with 692 additions and 64 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class SafeEventEmitter extends EventEmitter {
const len = handler.length;
const listeners = arrayClone(handler);
for (let i = 0; i < len; i += 1) {
safeApply(listeners[i], this, args);
safeApply(listeners[i] as Handler, this, args);
}
}

Expand Down
27 changes: 11 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
"name": "@metamask/safe-event-emitter",
"version": "3.1.0",
"description": "An EventEmitter that isolates the emitter from errors in handlers",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
"types": "./dist/types/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./package.json": "./package.json"
},
Expand All @@ -34,10 +29,9 @@
},
"scripts": {
"prepublishOnly": "yarn build",
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --project .",
"build:esm": "tsc --project tsconfig.esm.json && yarn build:esm:rename",
"build:esm:rename": "./scripts/rename-esm.sh",
"build": "tsup --clean && yarn build:types",
"build:docs": "typedoc",
"build:types": "tsc --project tsconfig.build.json",
"test": "jest",
"lint": "eslint . --ext .ts,.js"
},
Expand All @@ -55,7 +49,8 @@
"eslint-plugin-node": "^11.1.0",
"jest": "^26.4.2",
"ts-jest": "^26.4.0",
"typescript": "^4.0.5"
"tsup": "^8.0.2",
"typescript": "~4.8.4"
},
"dependencies": {}
}
13 changes: 0 additions & 13 deletions scripts/rename-esm.sh

This file was deleted.

24 changes: 24 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"inlineSources": true,
"noEmit": false,
"outDir": "dist/types",
"rootDir": "./",
"sourceMap": true
},
"include": ["./index.ts", "./src/**/*.ts"],
"exclude": [
"./src/**/__fixtures__/**/*",
"./src/**/__mocks__/**/*",
"./src/**/__test__/**/*",
"./src/**/__tests__/**/*",
"./src/**/__snapshots__/**/*",
"./src/**/*.test.ts",
"./src/**/*.test-d.ts",
"./src/**/*.test.*.ts"
]
}
14 changes: 0 additions & 14 deletions tsconfig.esm.json

This file was deleted.

17 changes: 10 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ES2020"],
"module": "CommonJS",
"outDir": "dist/cjs",
"sourceMap": true,
"moduleResolution": "node",
"noEmit": true,
"noErrorTruncation": true,
"noUncheckedIndexedAccess": true,
"strict": true,
"target": "ES2017"
"target": "es2020"
},
"include": [
"./**/*.ts"
]
"exclude": ["./dist", "**/node_modules"]
}
23 changes: 23 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from 'tsup';

export default defineConfig({
// The entry to bundle.
entry: [
'index.ts',
],

// The output formats. We want to generate both CommonJS and ESM bundles.
// https://tsup.egoist.dev/#bundle-formats
format: ['cjs', 'esm'],

// Generate sourcemaps as separate files.
// https://tsup.egoist.dev/#generate-sourcemap-file
sourcemap: true,

// Clean the dist folder before bundling.
clean: true,

// Hide unnecessary logs from the console. Warnings and errors will still be
// shown.
silent: true,
});
Loading

0 comments on commit 27e2863

Please sign in to comment.