Skip to content

Commit

Permalink
reafactor: replace tsdx with tsup and tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtute90 authored May 14, 2024
1 parent 1074d49 commit e361652
Show file tree
Hide file tree
Showing 19 changed files with 652 additions and 2,804 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 17 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@
},
"version": "5.0.4",
"license": "BSD-3",
"module": "dist/esm/index.js",
"main": "src/index.tsx",
"types": "dist/types/index.d.ts",
"type": "module",
"module": "./dist/index.js",
"main": "./dist/index.cjs",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"module": "./dist/index.js",
"main": "./dist/index.cjs"
}
},
"sideEffects": false,
"files": [
"dist",
Expand All @@ -42,15 +50,13 @@
},
"scripts": {
"start": "NODE_OPTIONS=--max_old_space_size=16384 npm run storybook:serve",
"build": "tsdx build --format cjs,esm",
"build": "tsup && tsc",
"test": "jest ./src ./test --passWithNoTests",
"test:ci": "jest ./src ./test --passWithNoTests --runInBand --ci",
"lint": "npx eslint src stories test --ext js,ts,tsx,jsx",
"lint:staged": "npx eslint --ext js,ts,tsx,jsx",
"prepare": "tsdx build --format cjs,esm && husky install",
"prepare": "tsup && tsc && husky install",
"format-code": "npx prettier . --write",
"size": "size-limit",
"analyze": "size-limit --why",
"storybook:serve": "storybook dev -p 9001",
"storybook:build": "storybook build --docs",
"storybook:build:base": "storybook build",
Expand All @@ -65,16 +71,6 @@
"browserslist": [
"extends browserslist-config-design-italia"
],
"size-limit": [
{
"path": "dist/cjs/index.js",
"limit": "200 KB"
},
{
"path": "dist/esm/index.js",
"limit": "200 KB"
}
],
"lint-staged": {
"./{src,stories,test}/**/*.{js,ts,tsx,jsx,mdx}": "yarn lint:staged"
},
Expand Down Expand Up @@ -120,18 +116,19 @@
"eslint-plugin-storybook": "^0.8.0",
"husky": "^8.0.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^13.0.3",
"prettier": "^3.2.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sass": "^1.75.0",
"storybook": "^8.0.5",
"ts-jest": "^29.1.2",
"tsdx": "^0.14.1",
"tslib": "^2.4.0",
"tsup": "^8.0.2",
"typeface-lora": "^1.1.13",
"typeface-roboto-mono": "^1.1.13",
"typescript": "^4.8.2",
"typescript": "^5.4.5",
"vite": "^5.2.7"
},
"dependencies": {
Expand All @@ -146,7 +143,6 @@
},
"resolutions": {
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2",
"jest-environment-jsdom": "29.7.0"
"@types/react-dom": "17.0.2"
}
}
2 changes: 1 addition & 1 deletion src/Header/HeaderContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const SLIM = 'slim';
export const CENTER = 'center';
export const NAVBAR = 'navbar';

export const HeaderContext = createContext<{
export const HeaderContext = /* @__PURE__ */ createContext<{
type?: typeof SLIM | typeof CENTER | typeof NAVBAR;
}>({});

Expand Down
15 changes: 7 additions & 8 deletions src/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, ImgHTMLAttributes, SVGProps, useEffect, useState } from 'react';
import classNames from 'classnames';
import { isBundledIcon, loadIcon, allIcons, IconName } from './assets';
import React, { FC, ImgHTMLAttributes, SVGProps, useEffect, useState } from 'react';
import { EmptyIcon } from './EmptyIcon';
import { IconName, allIcons, isBundledIcon, loadIcon } from './assets/index';
export type { IconName } from './assets';

export const iconsList = allIcons;
Expand All @@ -13,13 +13,12 @@ let iconsCache: Record<IconName, FC<SVGProps<SVGSVGElement>>> = {};
* @param icons - the list of icons to preload
* @returns true if the icons have been preloaded
*/
export function preloadIcons(icons: IconName[]) {
return Promise.all(icons.map((icon) => loadIcon(icon))).then((preloadedIcons) => {
preloadedIcons.forEach(({ component }, i) => {
iconsCache[icons[i]] = (() => component) as unknown as FC<SVGProps<SVGSVGElement>>;
});
return true;
export async function preloadIcons(icons: IconName[]) {
const preloadedIcons = await Promise.all(icons.map((icon) => loadIcon(icon)));
preloadedIcons.forEach(({ component }, i) => {
iconsCache[icons[i]] = (() => component) as unknown as FC<SVGProps<SVGSVGElement>>;
});
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/NavScroll/index.tsx → src/NavScroll/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Released under the MIT license by Marco Liberati
* Code: https://github.com/dej611/react-use-navscroll
*/

/* @internal */
export type { ChangesType, RegisterOptions, useNavScrollArgs, useNavScrollResult } from './types';

export { useNavScroll } from './useNavScroll';
4 changes: 2 additions & 2 deletions src/Notification/Notification.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { CSSProperties, FC, useEffect } from 'react';
import { ToastProps, useToast, cssTransition } from 'react-toastify';
import { ToastProps, cssTransition, useToast } from 'react-toastify';
import { NotificationToastProps } from './NotificationContent';
import { NotificationCommonProps } from './types';

export type NotificationProps = Omit<ToastProps, 'transition'> & NotificationCommonProps & NotificationToastProps;

const dummyTransition = cssTransition({ enter: '', exit: '' });
const dummyTransition = /* @__PURE__ */ cssTransition({ enter: '', exit: '' });

export const Notification: FC<NotificationProps> = (props) => {
const { toastRef, eventHandlers } = useToast({
Expand Down
2 changes: 1 addition & 1 deletion src/Notification/NotificationManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getBorderStyleFix } from './NotificationContent';
import { NotificationCommonProps } from './types';
import { PositionContext } from './usePosition';

const KitTransition = cssTransition({
const KitTransition = /* @__PURE__ */ cssTransition({
enter: `d-block`,
exit: `d-none`,
appendPosition: false
Expand Down
2 changes: 1 addition & 1 deletion src/Notification/usePosition.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useContext } from 'react';
import { NotificationCommonProps } from './types';

export const PositionContext = createContext<NotificationCommonProps['fix']>(undefined);
export const PositionContext = /* @__PURE__ */ createContext<NotificationCommonProps['fix']>(undefined);

export function usePosition() {
const context = useContext(PositionContext);
Expand Down
4 changes: 2 additions & 2 deletions src/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ElementType, FC, HTMLAttributes, createContext } from 'react';
import classnames from 'classnames';
import React, { ElementType, FC, HTMLAttributes, createContext } from 'react';

export const SizeContext = createContext<ToolbarProps['size']>(undefined);
export const SizeContext = /* @__PURE__ */ createContext<ToolbarProps['size']>(undefined);

export interface ToolbarProps extends HTMLAttributes<HTMLElement> {
tag?: ElementType;
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export { ModalBody } from './Modal/ModalBody';
export { ModalFooter } from './Modal/ModalFooter';
export { ModalHeader } from './Modal/ModalHeader';
export { Nav } from './Nav/Nav';
export { useNavScroll } from './NavScroll';
export { NotificationManager, createNotification, notify } from './Notification';
export { useNavScroll } from './NavScroll/index';
export { NotificationManager, createNotification, notify } from './Notification/index';
export { Pager } from './Pager/Pager';
export { Progress } from './Progress/Progress';
export { Rating } from './Rating/Rating';
Expand Down Expand Up @@ -219,6 +219,7 @@ export type { ModalBodyProps } from './Modal/ModalBody';
export type { ModalFooterProps } from './Modal/ModalFooter';
export type { ModalHeaderProps } from './Modal/ModalHeader';
export type { NavProps } from './Nav/Nav';
export type { ChangesType, RegisterOptions, useNavScrollArgs, useNavScrollResult } from './NavScroll';
export type { NotificationId, NotificationManagerProps, NotificationOptions, NotificationProps } from './Notification';
export type { PagerProps } from './Pager/Pager';
export type { ProgressProps } from './Progress/Progress';
Expand Down Expand Up @@ -292,4 +293,3 @@ export type {
UncontrolledCollapseProps,
UncontrolledTooltipProps
} from 'reactstrap';
export type { ChangesType, RegisterOptions, useNavScrollArgs, useNavScrollResult } from './NavScroll';
16 changes: 6 additions & 10 deletions test/Storybook.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { composeStories, type Meta, type StoryFn } from '@storybook/react';
import { act, render } from '@testing-library/react';
import * as glob from 'glob';
import path from 'path';
import './__mocks__/IntersectionObserverMock.ts';
import './__mocks__/IntersectionObserverMock';

type StoryFile = {
default: Meta;
Expand All @@ -14,17 +14,13 @@ const compose = (entry: StoryFile): ReturnType<typeof composeStories<StoryFile>>
try {
return composeStories(entry);
} catch (e) {
throw new Error(
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${e}`,
);
throw new Error(`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${e}`);
}
};

function getAllStoryFiles() {
// Place the glob you want to match your stories files
const storyFiles = glob.sync(
path.join(__dirname, '..', 'stories/**/*.{stories,story}.{js,jsx,mjs,ts,tsx}'),
);
const storyFiles = glob.sync(path.join(__dirname, '..', 'stories/**/*.{stories,story}.{js,jsx,mjs,ts,tsx}'));

return storyFiles.map((filePath) => {
const storyFile = require(filePath);
Expand All @@ -45,7 +41,7 @@ describe('Stories Snapshots', () => {

if (stories.length <= 0) {
throw new Error(
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`,
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`
);
}

Expand All @@ -55,10 +51,10 @@ describe('Stories Snapshots', () => {
await act(async () => {
// Ensures a consistent snapshot by waiting for the component to render by adding a delay of 1 ms before taking the snapshot.
await new Promise((resolve) => setTimeout(resolve, 1));
})
});
expect(mounted.container).toMatchSnapshot();
});
});
});
});
});
});
16 changes: 8 additions & 8 deletions src/utils.test.tsx → test/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
jest.spyOn(console, 'error').mockImplementation();

// eslint-disable-next-line import/first
import { flushMessageCache, logError, mapToCssModules, notifyDeprecation, omit, pick } from './utils';
import { flushMessageCache, logError, mapToCssModules, notifyDeprecation, omit, pick } from '../src/utils';

describe('Kit utils', () => {
describe('mapToCssModules', () => {
it('should return empty string for undefined or null', () => {
expect(mapToCssModules(null)).toBe('');
expect(mapToCssModules(null, {})).toBe('');
expect(mapToCssModules(null, { null: 'nil' })).toBe('');
// @ts-expect-error
// @ts-expect-error descrizione
expect(mapToCssModules(undefined)).toBe('');
});

Expand Down Expand Up @@ -45,9 +45,9 @@ describe('Kit utils', () => {
});

it("should return an empty object if there's no key overlapping", () => {
// @ts-expect-error
// @ts-expect-error descrizione
expect(pick({ a: 'value', b: 'value', c: 'value' }, ['e'])).toEqual({});
// @ts-expect-error
// @ts-expect-error descrizione
expect(pick({ a: 'value', b: 'value', c: 'value' }, 'e')).toEqual({});
});
});
Expand All @@ -72,13 +72,13 @@ describe('Kit utils', () => {
});

it("should return the same object if there's no key overlapping", () => {
// @ts-expect-error
// @ts-expect-error descrizione
expect(omit({ a: 'value', b: 'value', c: 'value' }, ['e'])).toEqual({
a: 'value',
b: 'value',
c: 'value'
});
// @ts-expect-error
// @ts-expect-error descrizione
expect(omit({ a: 'value', b: 'value', c: 'value' }, 'e')).toEqual({
a: 'value',
b: 'value',
Expand All @@ -90,7 +90,7 @@ describe('Kit utils', () => {
describe('logError', () => {
beforeEach(() => {
flushMessageCache();
// @ts-expect-error
// @ts-expect-error descrizione
console.error.mockClear();
});
it('should basically work', () => {
Expand All @@ -102,7 +102,7 @@ describe('Kit utils', () => {
describe('notifyDeprecation', () => {
beforeEach(() => {
flushMessageCache();
// @ts-expect-error
// @ts-expect-error descrizione
console.error.mockClear();
});
it('should propagate the error message', () => {
Expand Down
Loading

0 comments on commit e361652

Please sign in to comment.