diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 6294fb41..00000000 --- a/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presets": [ - "@babel/preset-env", - "@babel/preset-react", - "@babel/preset-typescript" - ] -} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d66b83ff..9b6b30df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.gitignore b/.gitignore index c187fa42..f3857c75 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ dist .vscode storybook-static yarn.lock +pnpm-lock.yaml +coverage +esbuild-why* \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..7a4ffc46 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +lockfile=false \ No newline at end of file diff --git a/.storybook/main.js b/.storybook/main.js deleted file mode 100644 index 734df700..00000000 --- a/.storybook/main.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - stories: ['../stories/**/*.stories.@(ts|tsx|js|jsx)'], - // https://storybook.js.org/docs/react/configure/typescript#mainjs-configuration - typescript: { - check: true, // type-check stories during Storybook build - }, - - addons: [ - 'storybook-addon-designs', - '@storybook/addon-webpack5-compiler-babel', - ], - - framework: { - name: '@storybook/react-webpack5', - options: {}, - }, - - docs: { - autodocs: true, - }, -}; diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 00000000..a544576b --- /dev/null +++ b/.storybook/main.ts @@ -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; diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html new file mode 100644 index 00000000..05da1e9d --- /dev/null +++ b/.storybook/preview-head.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/README.md b/README.md index 7b27aba8..e30187b4 100644 --- a/README.md +++ b/README.md @@ -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 +

+ + NPM Version + +

-`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. diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 9f10ab66..00000000 --- a/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - transformIgnorePatterns: ['/node_modules/(?!@react-three).+\\.js$'], -}; diff --git a/package.json b/package.json index 602c988f..9db1358c 100644 --- a/package.json +++ b/package.json @@ -1,112 +1,123 @@ { - "name": "@arizeai/point-cloud", - "version": "3.0.6", - "license": "MIT", - "main": "dist/index.js", - "typings": "dist/index.d.ts", - "files": [ - "dist", - "src" - ], - "engines": { - "node": ">=10" + "name": "@arizeai/point-cloud", + "version": "4.0.0-1", + "license": "MIT", + "author": "Mikyo King ", + "main": "dist/index.cjs", + "module": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.cjs", + "import": "./dist/index.js" + } + }, + "files": [ + "dist", + "src" + ], + "engines": { + "node": ">=10" + }, + "scripts": { + "start": "vite", + "build": "vite build && tsc --emitDeclarationOnly --outDir dist", + "test": "vitest run", + "typecheck": "tsc --noEmit", + "lint": "eslint ./src", + "lint:ts:fix": "eslint --fix ./src", + "prettier": "prettier --write './src/**/*'", + "prettier:check": "prettier --check './src/**/*'", + "size": "size-limit", + "analyze": "size-limit --why", + "storybook": "storybook dev -p 6006", + "build-storybook": "storybook build", + "chromatic": "npx chromatic --project-token=46df7a59e0a8" + }, + "peerDependencies": { + "@react-three/drei": "^9.105.5", + "@react-three/fiber": "^8.0.12", + "react": ">=18", + "three": "^0.139.2", + "three-stdlib": "2.23.9" + }, + "husky": { + "hooks": { + "pre-commit": "npm run lint" + } + }, + "prettier": { + "tabWidth": 4, + "semi": true, + "singleQuote": false, + "trailingComma": "all" + }, + "size-limit": [ + { + "name": "cjs", + "path": "dist/index.cjs", + "limit": "10 kB" }, - "scripts": { - "start": "tsdx watch", - "build": "tsdx build", - "test": "tsdx test --passWithNoTests", - "lint": "eslint ./src", - "lint:ts:fix": "eslint --fix ./src", - "prettier": "prettier --write './src/**/*'", - "prettier:check": "prettier --check './src/**/*'", - "prepare": "tsdx build", - "size": "size-limit", - "analyze": "size-limit --why", - "storybook": "storybook dev -p 6006", - "build-storybook": "storybook build", - "chromatic": "npx chromatic --project-token=46df7a59e0a8" - }, - "peerDependencies": { - "@react-three/drei": "^9.105.5", - "@react-three/fiber": "^8.0.12", - "react": ">=18", - "three": "^0.139.2", - "three-stdlib": "2.23.9" - }, - "husky": { - "hooks": { - "pre-commit": "tsdx lint" - } - }, - "prettier": { - "tabWidth": 4, - "semi": true, - "singleQuote": false, - "trailingComma": "all" - }, - "author": "Mikyo King ", - "module": "dist/point-cloud.esm.js", - "size-limit": [ - { - "path": "dist/point-cloud.cjs.production.min.js", - "limit": "800 KB" - }, - { - "path": "dist/point-cloud.esm.js", - "limit": "10 KB" - } - ], - "devDependencies": { - "@babel/core": "^7.17.9", - "@babel/preset-react": "^7.24.1", - "@babel/preset-typescript": "^7.24.7", - "@react-three/drei": "^9.105.5", - "@react-three/fiber": "8.13.3", - "@size-limit/preset-small-lib": "^7.0.8", - "@storybook/addon-webpack5-compiler-babel": "^3.0.3", - "@storybook/addons": "^7.6.17", - "@storybook/react": "^8.0.9", - "@storybook/react-webpack5": "^8.0.9", - "@types/d3-scale-chromatic": "^3.0.3", - "@types/react": "^18.0.8", - "@types/react-dom": "^18.0.0", - "@types/three": "^0.139.0", - "@typescript-eslint/eslint-plugin": "^7.7.1", - "@typescript-eslint/parser": "^7.7.1", - "babel-loader": "^8.2.5", - "chromatic": "^6.5.4", - "d3-scale-chromatic": "^3.0.0", - "eslint": "^8.56.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-import": "^2.29.1", - "eslint-plugin-react": "^7.34.1", - "eslint-plugin-react-hooks": "^4.6.2", - "eslint-plugin-unused-imports": "^3.1.0", - "husky": "^7.0.4", - "react": "18", - "react-dom": "18", - "react-is": "^18.1.0", - "size-limit": "^7.0.8", - "storybook": "^8.0.9", - "three": "^0.153.0", - "tsdx": "^0.14.1", - "tslib": "^2.4.0", - "typescript": "^5.4.5" - }, - "description": "A point cloud library for visualizing point clouds using 2D and 3D canvases.", - "directories": { - "example": "example", - "test": "test" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Arize-ai/point-cloud.git" - }, - "keywords": [ - "point-cloud" - ], - "bugs": { - "url": "https://github.com/Arize-ai/point-cloud/issues" - }, - "homepage": "https://github.com/Arize-ai/point-cloud#readme" + { + "name": "esm", + "path": "dist/index.js", + "limit": "10 kB" + } + ], + "devDependencies": { + "@react-three/drei": "^9.105.5", + "@react-three/fiber": "8.13.3", + "@size-limit/esbuild": "^11.1.6", + "@size-limit/esbuild-why": "^11.1.6", + "@size-limit/preset-small-lib": "^11.1.6", + "@storybook/addon-designs": "^8.0.4", + "@storybook/react": "^8.4.3", + "@storybook/react-vite": "^8.4.3", + "@types/d3-scale-chromatic": "^3.0.3", + "@types/node": "^22.9.0", + "@types/react": "^18.0.8", + "@types/react-dom": "^18.0.0", + "@types/three": "^0.139.0", + "@typescript-eslint/eslint-plugin": "^7.7.1", + "@typescript-eslint/parser": "^7.7.1", + "@vitejs/plugin-react": "^4.3.3", + "@vitest/coverage-v8": "2.1.5", + "chromatic": "^6.5.4", + "d3-scale-chromatic": "^3.0.0", + "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-react": "^7.34.1", + "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-unused-imports": "^3.1.0", + "husky": "^7.0.4", + "react": "18", + "react-dom": "18", + "react-is": "^18.1.0", + "size-limit": "^11.1.6", + "storybook": "^8.4.3", + "three": "^0.153.0", + "tslib": "^2.8.1", + "typescript": "^5.6.3", + "vite": "^5.4.11", + "vitest": "^2.1.5" + }, + "description": "A point cloud library for visualizing point clouds using 2D and 3D canvases.", + "directories": { + "example": "example", + "test": "test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Arize-ai/point-cloud.git" + }, + "keywords": [ + "point-cloud" + ], + "bugs": { + "url": "https://github.com/Arize-ai/point-cloud/issues" + }, + "homepage": "https://github.com/Arize-ai/point-cloud#readme" } diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 00000000..4601c622 --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,27 @@ +// This tsconfig is for vscode's sake. It's not used for building. +// Without it, vscode won't know how to intellisense the test files. +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", + "target": "ES2022", + "lib": ["ES2023"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true, + "types": ["vitest/globals"] + }, + "include": ["."] +} diff --git a/tsconfig.json b/tsconfig.json index 86186366..330ade71 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,7 +30,5 @@ "skipLibCheck": true, // error out if import and file system have a casing mismatch. Recommended by TS "forceConsistentCasingInFileNames": true, - // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` - "noEmit": true, } } diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 00000000..196c6d65 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", + "target": "ES2022", + "lib": ["ES2023"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 00000000..0737bd31 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,40 @@ +import { resolve } from "path"; +import { defineConfig, mergeConfig } from "vite"; +import { defineConfig as defineVitestConfig } from "vitest/config"; +import react from "@vitejs/plugin-react"; + +const vitestConfig = defineVitestConfig({ + test: { + globals: true, + include: ["test/**/*.{ts,tsx}"], + }, +}); + +export default mergeConfig( + defineConfig({ + plugins: [react()], + build: { + lib: { + // Could also be a dictionary or array of multiple entry points + entry: resolve(__dirname, "src/index.tsx"), + // the proper extensions will be added + fileName: "index", + formats: ["es", "cjs"], + }, + minify: false, + rollupOptions: { + // make sure to externalize deps that shouldn't be bundled + // into your library + external: [ + "react", + "react-dom", + "@react-three/fiber", + "@react-three/drei", + "three", + "three-stdlib", + ], + }, + }, + }), + vitestConfig, +);