From 1df0b73c7855ab9be8dc8081a92fcff2609711ae Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 5 Mar 2023 17:57:51 +0100 Subject: [PATCH] fix: Make package importable for `type="module"` projects Explicitly set the type of the dist files by changing the file extension to `mjs` or `cjs` respectively. Signed-off-by: Ferdinand Thiessen --- package.json | 14 ++++++++------ rollup.config.js => rollup.config.mjs | 6 +++--- test/ProxyBus.test.js | 2 +- test/index.test.js | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) rename rollup.config.js => rollup.config.mjs (86%) diff --git a/package.json b/package.json index 3abee63f..90808414 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,23 @@ "name": "@nextcloud/event-bus", "version": "3.0.2", "description": "A simple event bus to communicate between Nextcloud components.", - "main": "dist/index.js", - "module": "dist/index.esm.js", + "main": "dist/index.cjs", "types": "dist/index.d.ts", "exports": { - "import": "./dist/index.esm.js", - "require": "./dist/index.js" + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs", + "types": "./dist/index.d.ts" + } }, "files": [ "dist/" ], "scripts": { - "build": "rollup --config rollup.config.js", + "build": "rollup --config rollup.config.mjs", "build:doc": "typedoc --out dist/doc lib/index.ts && touch dist/doc/.nojekyll", "check-types": "tsc --noEmit", - "dev": "rollup --config rollup.config.js --watch", + "dev": "rollup --config rollup.config.mjs --watch", "test": "jest", "test:watch": "jest --watchAll" }, diff --git a/rollup.config.js b/rollup.config.mjs similarity index 86% rename from rollup.config.js rename to rollup.config.mjs index 81376b45..53075e81 100644 --- a/rollup.config.js +++ b/rollup.config.mjs @@ -1,7 +1,7 @@ import typescript from '@rollup/plugin-typescript' import replace from '@rollup/plugin-replace' -import pkg from './package.json' +import pkg from './package.json' assert { type: 'json' } const external = [/semver/] @@ -25,7 +25,7 @@ export default [ ], output: [ { - dir: 'dist', + file: 'dist/index.cjs', format: 'cjs', sourcemap: true, }, @@ -37,7 +37,7 @@ export default [ plugins: [typescript(), replacePlugin], output: [ { - file: 'dist/index.esm.js', + file: 'dist/index.mjs', format: 'esm', sourcemap: true, }, diff --git a/test/ProxyBus.test.js b/test/ProxyBus.test.js index 8e5e65d3..895c53e6 100644 --- a/test/ProxyBus.test.js +++ b/test/ProxyBus.test.js @@ -1,7 +1,7 @@ /** * @jest-environment jsdom */ -const { SimpleBus, ProxyBus } = require('../dist') +const { SimpleBus, ProxyBus } = require('..') describe('ProxyBus', () => { test('proxy invalid bus', () => { diff --git a/test/index.test.js b/test/index.test.js index 9170f9f0..9c3aaaa8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,7 +1,7 @@ /** * @jest-environment jsdom */ -const { emit, subscribe, unsubscribe } = require('../dist/index') +const { emit, subscribe, unsubscribe } = require('..') test('readme example', () => { const h = jest.fn()