Skip to content

Commit

Permalink
fix: Make package importable for type="module" projects
Browse files Browse the repository at this point in the history
Explicitly set the type of the dist files by changing the file
extension to `mjs` or `cjs` respectively.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
  • Loading branch information
susnux committed Mar 5, 2023
1 parent 059c30f commit 2c7db8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions package.json
Expand Up @@ -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.js",
"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"
},
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js → 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/]

Expand All @@ -25,7 +25,7 @@ export default [
],
output: [
{
dir: 'dist',
file: 'dist/index.cjs',
format: 'cjs',
sourcemap: true,
},
Expand All @@ -37,7 +37,7 @@ export default [
plugins: [typescript(), replacePlugin],
output: [
{
file: 'dist/index.esm.js',
file: 'dist/index.mjs',
format: 'esm',
sourcemap: true,
},
Expand Down
2 changes: 1 addition & 1 deletion 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', () => {
Expand Down
2 changes: 1 addition & 1 deletion 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()
Expand Down

0 comments on commit 2c7db8a

Please sign in to comment.