Skip to content

Commit

Permalink
refactor: Move off of tsdx and related tooling (#32)
Browse files Browse the repository at this point in the history
* refactor: Move off of tsdx and related tooling

- Remove direct tsdx, babel, jest, tslib deps
- Install vite, vitest, plugins
- Configure vite and vitest
- Update github workflows to use pnpm and node 20

* Fix actions

* Do not read or emit lockfile

* Externalize more dependencies in build

* Upgrade size-limit, fix config

* Upgrade storybook and migrate config

* add types export

* 4.0.0-0

* Remove extraneous vite config

* 4.0.0-1
  • Loading branch information
cephalization authored Dec 6, 2024
1 parent 79d33d2 commit edf9af9
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 341 deletions.
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

56 changes: 31 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
name: CI
on: [push]
jobs:
ci:
ci:
name: Lint TypeScript
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Nodejs
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
with:
useLockFile: false
- name: Lint
run: yarn lint
- name: Prettier
run: yarn prettier:check
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
cache: "pnpm"
- name: Install deps
run: pnpm install
- name: Lint
run: pnpm lint
- name: Prettier
run: pnpm prettier:check
build:
name: Build and test on Node ${{ matrix.node }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['18.x']
node: ["20.x"]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
node-version: ${{ matrix.node }}
version: 9

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
useLockFile: false
node-version: ${{ matrix.node }}
cache: "pnpm"

- name: Install deps
run: pnpm install

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
run: pnpm test -- --coverage

- name: Build
run: yarn build
run: pnpm build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ dist
.vscode
storybook-static
yarn.lock
pnpm-lock.yaml
coverage
esbuild-why*
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lockfile=false
21 changes: 0 additions & 21 deletions .storybook/main.js

This file was deleted.

18 changes: 18 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { StorybookConfig } from "@storybook/react-vite";

export default {
stories: ["../stories/**/*.stories.@(ts|tsx|js|jsx)"],

// https://storybook.js.org/docs/react/configure/typescript#mainjs-configuration
typescript: {
check: true,
reactDocgen: "react-docgen",
},

addons: ["@storybook/addon-designs"],

framework: {
name: "@storybook/react-vite",
options: {},
},
} satisfies StorybookConfig;
3 changes: 3 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
window.global = window;
</script>
180 changes: 6 additions & 174 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,177 +1,9 @@
# point-cloud

A point cloud library for visualizing point clouds using 2D and 3D canvases.

## Commands

TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.

The recommended workflow is to run TSDX in one terminal:

```bash
npm start # or yarn start
```

This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.

Then run either Storybook or the example playground:

### Storybook

Run inside another terminal:

```bash
yarn storybook
```

This loads the stories from `./stories`.

> NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.
### Example

Then run the example inside another:

```bash
cd example
npm i # or yarn to install dependencies
npm start # or yarn start
```

The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).

To do a one-off build, use `npm run build` or `yarn build`.

To run tests, use `npm test` or `yarn test`.

## Configuration

Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.

### Jest

Jest tests are set up to run with `npm test` or `yarn test`.

### Bundle analysis

Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.

#### Setup Files

This is the folder structure we set up for you:

```txt
/example
index.html
index.tsx # test your component here in a demo app
package.json
tsconfig.json
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
/stories
Thing.stories.tsx # EDIT THIS
/.storybook
main.js
preview.js
.gitignore
package.json
README.md # EDIT THIS
tsconfig.json
```

#### React Testing Library

We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.

### Rollup

TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.

### TypeScript
<p align="center">
<a href="https://www.npmjs.com/package/@arizeai/point-cloud">
<img alt="NPM Version" src="https://img.shields.io/npm/v/%40arizeai%2Fpoint-cloud">
</a>
</p>

`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.

## Continuous Integration

### GitHub Actions

Two actions are added by default:

- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
- `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit)

## Optimizations

Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:

```js
// ./types/index.d.ts
declare var __DEV__: boolean;

// inside your code...
if (__DEV__) {
console.log('foo');
}
```

You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.

## Module Formats

CJS, ESModules, and UMD module formats are supported.

The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.

## Deploying the Example Playground

The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):

```bash
cd example # if not already in the example folder
npm run build # builds to dist
netlify deploy # deploy the dist folder
```

Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:

```bash
netlify init
# build command: yarn build && cd example && yarn && yarn build
# directory to deploy: example/dist
# pick yes for netlify.toml
```

## Named Exports

Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.

## Including Styles

There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.

For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.

## Publishing to NPM

We recommend using [np](https://github.com/sindresorhus/np).

## Usage with Lerna

When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.

The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.

Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.

```diff
"alias": {
- "react": "../node_modules/react",
- "react-dom": "../node_modules/react-dom"
+ "react": "../../../node_modules/react",
+ "react-dom": "../../../node_modules/react-dom"
},
```

An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)
A point cloud library for visualizing point clouds using 2D and 3D canvases.
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit edf9af9

Please sign in to comment.