Skip to content

Commit 628382e

Browse files
committed
refactor: move src -> lib/src and split up dependencies
1 parent 0cee673 commit 628382e

23 files changed

+1414
-1359
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ jobs:
3333
run: pnpm run lint
3434

3535
- name: 🔨 Build
36-
run: pnpm run build
36+
run: pnpm run --filter react-compare-slider build
3737

3838
- name: 🧑‍🏫 Build Example Project
3939
run: pnpm run --filter @this/example build
4040

4141
- name: 🕵️ Check Package Configuration
42-
run: pnpm run check:package
42+
run: pnpm run --filter react-compare-slider check:package
4343

4444
- name: 🧪 Test
4545
run: |
@@ -52,7 +52,7 @@ jobs:
5252
token: ${{ secrets.CODECOV_TOKEN }}
5353
fail_ci_if_error: true
5454
verbose: true
55-
files: ./coverage/lcov.info,!./coverage/ssr-tests/*,!./coverage/storybook/*
55+
directory: ./coverage
5656

5757
- name: Upload Code Climate Test Coverage
5858
uses: paambaati/[email protected]

docs/CONTRIBUTING.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ Thanks for contributing!
44

55
## Getting Started
66

7-
This is a pnpm monorepo, consisting of the main package in the root of the repo and [`storybook`](./storybook/) and [`example`](./example/) packages in the `docs` directory.
8-
packages in the `docs` folder. Don't worry if you haven't used pnpm or monorepos before, the
7+
This is a pnpm monorepo, consisting of the main package in [`lib`](../lib/) and [`storybook`](./storybook/) and [`example`](./example/) packages in the `docs` directory. Don't worry if you haven't used pnpm or monorepos before, the
98
commands below will set everything up for you.
109

1110
Ensure you're using the Node version specified in [.nvmrc](../.nvmrc) and run the following to
1211
bootstrap the project:
1312

1413
```sh
15-
npm run dx
14+
npm run bootstrap
1615
# Also useful but not required, install shell auto completion for pnpm.
1716
pnpm install-completion
1817
```
1918

2019
To start the library in watch mode, run the following command:
2120

2221
```sh
23-
pnpm run start
22+
pnpm run --filter react-compare-slider dev
23+
# You can also run the scripts from the directory itself if you prefer.
24+
cd lib
25+
pnpm run dev
2426
```
2527

2628
### Storybook
@@ -39,13 +41,13 @@ pnpm run storybook
3941
If you already have Storybook running, use the following command:
4042

4143
```sh
42-
pnpm run test
44+
pnpm run -w test
4345
```
4446

4547
If you _don't_ have Storybook running, use the following command:
4648

4749
```sh
48-
pnpm run test:ci
50+
pnpm run -w test:ci
4951
```
5052

5153
## Standards

docs/example/package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
22
"name": "react-compare-slider-example",
3-
"private": true,
3+
"license": "MIT",
44
"version": "0.0.0",
5+
"private": true,
56
"type": "module",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/nerdyman/react-compare-slider.git",
10+
"directory": "docs/example"
11+
},
612
"scripts": {
713
"dev": "vite",
814
"build": "tsc && vite build",
@@ -17,8 +23,8 @@
1723
"devDependencies": {
1824
"@types/react": "^18.2.21",
1925
"@types/react-dom": "^18.2.7",
20-
"@typescript-eslint/eslint-plugin": "^6.6.0",
21-
"@typescript-eslint/parser": "^6.6.0",
26+
"@typescript-eslint/eslint-plugin": "^6.7.0",
27+
"@typescript-eslint/parser": "^6.7.0",
2228
"@vitejs/plugin-react": "^4.0.3",
2329
"eslint": "^8.49.0",
2430
"eslint-plugin-react-hooks": "^4.6.0",

docs/ssr-tests/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test-legacy": "node --test"
1313
},
1414
"devDependencies": {
15-
"@types/node": "^20.5.7",
15+
"@types/node": "^20.6.2",
1616
"react": "^18.2.0",
1717
"react-compare-slider": "latest",
1818
"react-dom": "^18.2.0",

docs/ssr-tests/ssr.test.mjs

+10-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ describe('SSR', () => {
3232
}),
3333
});
3434

35-
assert.strictEqual(isValidElement(root), true);
36-
assert.strictEqual(renderToStaticMarkup(root).includes('data-rcs="root"'), true);
37-
assert.strictEqual(renderToStaticMarkup(root).includes('src="example-1.jpg"'), true);
38-
assert.strictEqual(renderToStaticMarkup(root).includes('src="example-2.jpg"'), true);
39-
assert.strictEqual(mockConsoleError.mock.calls.length, 0);
40-
assert.strictEqual(mockConsoleWarn.mock.calls.length, 0);
35+
/**
36+
* TypeScript errors if assertion isn't assigned.
37+
* @see https://github.com/microsoft/TypeScript/issues/36931
38+
*/
39+
let __ = assert.strictEqual(isValidElement(root), true);
40+
__ = assert.strictEqual(renderToStaticMarkup(root).includes('data-rcs="root"'), true);
41+
__ = assert.strictEqual(renderToStaticMarkup(root).includes('src="example-1.jpg"'), true);
42+
__ = assert.strictEqual(renderToStaticMarkup(root).includes('src="example-2.jpg"'), true);
43+
__ = assert.strictEqual(mockConsoleError.mock.calls.length, 0);
44+
__ = assert.strictEqual(mockConsoleWarn.mock.calls.length, 0);
4145

4246
mock.reset();
4347
});

docs/storybook/.storybook/hack-coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const coveragePath = path.join(__dirname, '..', 'coverage', 'storybook', 'covera
1313

1414
const coverage = fs
1515
.readFileSync(coveragePath, 'utf8')
16-
.replaceAll('react-compare-slider/docs/storybook/src', 'react-compare-slider/src');
16+
.replaceAll('react-compare-slider/docs/storybook/src', 'react-compare-slider/lib/src');
1717

1818
fs.writeFileSync(coveragePath, coverage);
1919

docs/storybook/.storybook/main.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { resolve } from 'node:path';
44

5-
import type { AddonOptionsVite } from '@storybook/addon-coverage';
65
import type { StorybookConfig } from '@storybook/react-vite';
76
import remarkGfm from 'remark-gfm';
87
import { mergeConfig } from 'vite';
@@ -15,12 +14,7 @@ const config: StorybookConfig = {
1514
framework: '@storybook/react-vite',
1615

1716
addons: [
18-
{
19-
name: '@storybook/addon-essentials',
20-
options: {
21-
docs: false,
22-
},
23-
},
17+
'@storybook/addon-essentials',
2418
{
2519
name: '@storybook/addon-docs',
2620
options: {

docs/storybook/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@storybook/react": "^7.4.0",
3535
"@storybook/react-vite": "^7.4.0",
3636
"@storybook/test-runner": "^0.13.0",
37-
"@storybook/testing-library": "^0.2.0",
37+
"@storybook/testing-library": "^0.2.1",
3838
"@storybook/theming": "^7.4.0",
3939
"remark-gfm": "^3.0.1",
4040
"storybook": "^7.4.0",

docs/storybook/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"extends": "../../tsconfig.json",
3-
"include": ["src", "content"],
2+
"extends": "../../lib/tsconfig.json",
3+
"include": ["src", "dist", "content"],
44
"compilerOptions": {
55
"module": "ESNext",
66
"moduleResolution": "Bundler",

lib/package.json

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "react-compare-slider",
3+
"version": "2.2.0",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/nerdyman/react-compare-slider.git",
8+
"directory": "lib"
9+
},
10+
"homepage": "https://react-compare-slider.vercel.app",
11+
"author": {
12+
"email": "[email protected]",
13+
"name": "nerdyman",
14+
"url": "https://github.com/nerdyman"
15+
},
16+
"description": "A slider component to compare any two React components in landscape or portrait orientation. It supports custom images, videos... and everything else.",
17+
"keywords": [
18+
"react",
19+
"slider",
20+
"comparison",
21+
"compare",
22+
"image",
23+
"video",
24+
"canvas",
25+
"component",
26+
"image comparison",
27+
"twentytwenty",
28+
"portrait",
29+
"typescript"
30+
],
31+
"engines": {
32+
"node": ">=16.9.0"
33+
},
34+
"sideEffects": false,
35+
"module": "dist/index.mjs",
36+
"types": "dist/index.d.mts",
37+
"exports": {
38+
"./package.json": "./package.json",
39+
".": {
40+
"import": "./dist/index.mjs",
41+
"types": "./dist/index.d.mts"
42+
}
43+
},
44+
"files": [
45+
"dist"
46+
],
47+
"scripts": {
48+
"dev": "concurrently -k -s first -n \"tsup,ts\" -c \"blue,cyan\" \"tsup --watch\" \"pnpm run check:types --watch --preserveWatchOutput\"",
49+
"start": "pnpm run dev",
50+
"build": "pnpm run check:types && NODE_ENV=production tsup",
51+
"release": "pnpm run -w lint && pnpm run -w test && pnpm run build && pnpm run check && np --no-tests --no-cleanup",
52+
"check": "concurrently -n \"package,types\" -c \"blue,magenta\" \"pnpm run check:package\" \"pnpm run check:types\"",
53+
"check:package": "attw -P . --ignore-rules cjs-resolves-to-esm",
54+
"check:types": "tsc --noEmit"
55+
},
56+
"browserslist": {
57+
"production": [
58+
"last 2 chrome versions",
59+
"last 2 edge versions",
60+
"last 2 firefox versions",
61+
"safari >= 15.6",
62+
"ios >= 15.6",
63+
"not dead",
64+
"not ie > 0",
65+
"not op_mini all"
66+
],
67+
"development": [
68+
"last 1 chrome version",
69+
"last 1 firefox version",
70+
"last 1 safari version"
71+
]
72+
},
73+
"np": {
74+
"pnpm": true
75+
},
76+
"peerDependencies": {
77+
"react": ">=16.8",
78+
"react-dom": ">=16.8"
79+
},
80+
"devDependencies": {
81+
"@arethetypeswrong/cli": "^0.10.2",
82+
"@ianvs/prettier-plugin-sort-imports": "^3.7.2",
83+
"@types/node": "^20.6.2",
84+
"@types/react": "^18.2.21",
85+
"@types/react-dom": "^18.2.7",
86+
"browserslist": "^4.21.10",
87+
"concurrently": "^8.2.1",
88+
"esbuild-plugin-browserslist": "^0.9.0",
89+
"np": "^8.0.4",
90+
"react": "^18.2.0",
91+
"react-dom": "^18.2.0",
92+
"tslib": "~2.6.2",
93+
"tsup": "^7.2.0",
94+
"typescript": "^5.2.2"
95+
}
96+
}
File renamed without changes.

src/ReactCompareSlider.tsx renamed to lib/src/ReactCompareSlider.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ export const ReactCompareSlider: ForwardRefExoticComponent<
194194
);
195195

196196
/**
197-
* Yo dawg, we heard you like handles, so we handled in your handle so you can handle
198-
* while you handle.
197+
* Yo dawg, we heard you like handles, so we handled in your handle so you can handle while you
198+
* handle.
199199
*/
200200
const handleHandleClick = useCallback((ev: PointerEvent) => {
201201
ev.preventDefault();
@@ -210,7 +210,6 @@ export const ReactCompareSlider: ForwardRefExoticComponent<
210210
}
211211

212212
ev.preventDefault();
213-
214213
setCanTransition(true);
215214

216215
const { top, left } = (
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tsup.config.ts renamed to lib/tsup.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export default defineConfig((options) => ({
1515
target,
1616
sourcemap: true,
1717
splitting: true,
18-
// Storybook docgen won't work with files sourced from outside of its root directory, so we need
19-
// to copy the src into the docs folder.
20-
onSuccess: 'cp -r src ./docs/storybook',
18+
// Storybook test coverage won't work with files sourced from outside of its root directory, so
19+
// we need to copy the lib into the docs folder.
20+
onSuccess: 'cp -r src ../docs/storybook',
2121
esbuildOptions(esbuild) {
2222
esbuild.banner = {
2323
js: '"use client"',

0 commit comments

Comments
 (0)