diff --git a/.gitignore b/.gitignore index 99b9e9b..d54c2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -*.js -*.d.ts -*.map +.DS_Store +dist/ +coverage/ +docs/ # Logs logs @@ -8,6 +9,10 @@ logs npm-debug.log* yarn-debug.log* yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids @@ -15,20 +20,24 @@ pids *.seed *.pid.lock -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - # Coverage directory used by tools like istanbul coverage +*.lcov # nyc test coverage .nyc_output +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + # Dependency directories node_modules/ -# TypeScript v1 declaration files -typings/ +# TypeScript cache +*.tsbuildinfo # Optional npm cache directory .npm @@ -36,6 +45,12 @@ typings/ # Optional eslint cache .eslintcache +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + # Optional REPL history .node_repl_history @@ -47,49 +62,17 @@ typings/ # dotenv environment variables file .env - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# next.js build output -.next - -# nuxt.js build output -.nuxt - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless - -### OSX ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - - -# End of https://www.gitignore.io/api/osx,node +.env.test + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v3 (w/o zero-install) +# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions diff --git a/.nvmrc b/.nvmrc index dae199a..b009dfb 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v12 +lts/* diff --git a/package.json b/package.json index 05ba330..2196e7c 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,28 @@ "name": "@metamask/safe-event-emitter", "version": "3.0.0", "description": "An EventEmitter that isolates the emitter from errors in handlers", - "main": "index.js", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "dist/cjs/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" + } + }, + "./package.json": "./package.json" + }, "publishConfig": { "registry": "https://registry.npmjs.org/", "access": "public" }, "files": [ - "index.js", - "index.d.ts", - "index.js.map" + "dist" ], "repository": { "type": "git", @@ -21,7 +34,10 @@ }, "scripts": { "prepublishOnly": "yarn build", - "build": "tsc --project .", + "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", "test": "jest", "lint": "eslint . --ext .ts,.js" }, diff --git a/scripts/rename-esm.sh b/scripts/rename-esm.sh new file mode 100755 index 0000000..526904d --- /dev/null +++ b/scripts/rename-esm.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +if [[ ${RUNNER_DEBUG:-0} == 1 ]]; then + set -x +fi + +for file in dist/esm/*.js; do + mv "$file" "${file%.js}.mjs" +done diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..e2b6d0b --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "declaration": true, + "module": "ES6", + "moduleResolution": "Node", + "outDir": "dist/esm", + "sourceMap": true, + "strict": true, + "target": "ES2017" + }, + "include": [ + "./**/*.ts" + ] +} diff --git a/tsconfig.json b/tsconfig.json index c08a0fa..413414b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "declaration": true, "module": "CommonJS", + "outDir": "dist/cjs", "sourceMap": true, "strict": true, "target": "ES2017"