-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve @magicbell/react-headless cjs/esm support (#391)
- Loading branch information
Showing
49 changed files
with
237 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@magicbell/react-headless': minor | ||
--- | ||
|
||
fix cjs/esm dual module support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fs = require('fs'); | ||
|
||
module.exports = (request, options) => { | ||
const { defaultResolver } = options; | ||
const resolvedPath = defaultResolver(request, options); | ||
|
||
// try resolve tshy module resolution polyfills | ||
const cjsPath = resolvedPath.replace(/\.ts$/, '-cjs.cts'); | ||
if (fs.existsSync(cjsPath)) return cjsPath; | ||
|
||
return resolvedPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { replaceInFile, ReplaceInFileConfig } from 'replace-in-file'; | ||
|
||
import pkgJson from '../package.json'; | ||
import { pkg } from '../src/lib/pkg'; | ||
|
||
const config = { | ||
files: 'dist/*/lib/pkg.js', | ||
from: ['__PACKAGE_NAME__', '__PACKAGE_VERSION__'], | ||
to: [pkgJson.name, pkgJson.version], | ||
} satisfies ReplaceInFileConfig; | ||
|
||
for (const key of Object.values(pkg)) { | ||
if (!config.from.includes(key)) { | ||
process.stdout.write(`Unknown replacement key '${key}' in lib/pkg.ts\n`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
await replaceInFile(config); |
14 changes: 7 additions & 7 deletions
14
packages/react-headless/src/components/MagicBellProvider/MagicBellProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/react-headless/src/components/MagicBellProvider/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import MagicBellProvider from './MagicBellProvider'; | ||
import MagicBellProvider from './MagicBellProvider.js'; | ||
|
||
export type { MagicBellProviderProps } from './MagicBellProvider'; | ||
export type { MagicBellProviderProps } from './MagicBellProvider.js'; | ||
export default MagicBellProvider; |
10 changes: 5 additions & 5 deletions
10
packages/react-headless/src/components/RealtimeListener.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...headless/src/components/WebPushNotificationsSubscriber/WebPushNotificationsSubscriber.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/react-headless/src/components/WebPushNotificationsSubscriber/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import WebPushNotificationsSubscriber from './WebPushNotificationsSubscriber'; | ||
import WebPushNotificationsSubscriber from './WebPushNotificationsSubscriber.js'; | ||
|
||
export type { Props as WebPushNotificationsSubscriberProps } from './WebPushNotificationsSubscriber'; | ||
export type { Props as WebPushNotificationsSubscriberProps } from './WebPushNotificationsSubscriber.js'; | ||
export default WebPushNotificationsSubscriber; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
packages/react-headless/src/hooks/useNotificationFactory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,19 @@ | ||
import warning from 'tiny-warning'; | ||
|
||
export { default as MagicBellProvider } from './components/MagicBellProvider'; | ||
export { default as RealtimeListener } from './components/RealtimeListener'; | ||
export { default as WebPushNotificationsSubscriber } from './components/WebPushNotificationsSubscriber'; | ||
export { default as useBell } from './hooks/useBell'; | ||
export { default as useMagicBellEvent } from './hooks/useMagicBellEvent'; | ||
export { default as useNotification } from './hooks/useNotification'; | ||
export { default as useNotificationFactory } from './hooks/useNotificationFactory'; | ||
export { default as useNotifications } from './hooks/useNotifications'; | ||
export { default as useNotificationUnmount } from './hooks/useNotificationUnmount'; | ||
export { deleteAPI, fetchAPI, postAPI, putAPI } from './lib/ajax'; | ||
export { secondsToDate, toDate, toUnix } from './lib/date'; | ||
export { eventAggregator, pushEventAggregator } from './lib/realtime'; | ||
export { default as clientSettings } from './stores/clientSettings'; | ||
export { default as useConfig } from './stores/config'; | ||
export { default as useNotificationPreferences } from './stores/notification_preferences'; | ||
export { useNotificationStoresCollection } from './stores/notifications'; | ||
export { default as buildStore } from './stores/notifications/helpers/buildStore'; | ||
export * from './types'; | ||
export { type INotification as Notification } from './types'; | ||
|
||
if (__DEV__) { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const testFunc = function testFn() {}; | ||
|
||
warning( | ||
(testFunc.name || testFunc.toString()).indexOf('testFn') !== -1, | ||
"It looks like you're using a minified copy of the development build " + | ||
`of ${__PACKAGE_NAME__}. When deploying your app to production, make sure to use ` + | ||
'the production build which is faster and does not print development warnings.', | ||
); | ||
} | ||
export { default as MagicBellProvider } from './components/MagicBellProvider/index.js'; | ||
export { default as RealtimeListener } from './components/RealtimeListener.js'; | ||
export { default as WebPushNotificationsSubscriber } from './components/WebPushNotificationsSubscriber/index.js'; | ||
export { default as useBell } from './hooks/useBell.js'; | ||
export { default as useMagicBellEvent } from './hooks/useMagicBellEvent.js'; | ||
export { default as useNotification } from './hooks/useNotification.js'; | ||
export { default as useNotificationFactory } from './hooks/useNotificationFactory.js'; | ||
export { default as useNotifications } from './hooks/useNotifications.js'; | ||
export { default as useNotificationUnmount } from './hooks/useNotificationUnmount.js'; | ||
export { deleteAPI, fetchAPI, postAPI, putAPI } from './lib/ajax.js'; | ||
export { secondsToDate, toDate, toUnix } from './lib/date.js'; | ||
export { eventAggregator, pushEventAggregator } from './lib/realtime.js'; | ||
export { default as clientSettings } from './stores/clientSettings.js'; | ||
export { default as useConfig } from './stores/config/index.js'; | ||
export { default as useNotificationPreferences } from './stores/notification_preferences/index.js'; | ||
export { default as buildStore } from './stores/notifications/helpers/buildStore.js'; | ||
export { useNotificationStoresCollection } from './stores/notifications/index.js'; | ||
export * from './types/index.js'; | ||
export { type INotification as Notification } from './types/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Note, constants are replaced right after tsc built the project. | ||
// Update scripts/post-build.ts when requirements here change. | ||
export const pkg = { | ||
name: '__PACKAGE_NAME__', | ||
version: '__PACKAGE_VERSION__', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.