Skip to content

Commit f921b30

Browse files
committed
chore: template setup
configured with: - solid-js - tsup - bun - nvm - typescript - vitest - eslint - prettier
0 parents  commit f921b30

20 files changed

+1386
-0
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
thedanchez

.github/workflows/ci.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
jobs:
12+
quality-checks:
13+
name: Quality Checks
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Setup Bun
19+
uses: oven-sh/setup-bun@v1
20+
with:
21+
bun-version: 1.2.3
22+
- name: Install Dependencies
23+
run: bun install --frozen-lockfile
24+
- name: Lint Check
25+
run: bun run lint
26+
- name: Format Check
27+
run: bun run format

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coverage
2+
dist
3+
node_modules
4+
5+
.DS_Store
6+
/*.tgz

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.11.0

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
dist
3+
node_modules

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 100
3+
}

.vscode/settings.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll": "always"
4+
},
5+
"editor.formatOnSave": true,
6+
"editor.rulers": [100],
7+
"files.autoSave": "onFocusChange",
8+
"files.insertFinalNewline": true,
9+
"editor.tabSize": 2,
10+
"editor.trimAutoWhitespace": true
11+
}

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<p>
2+
<img width="100%" src="https://assets.solidjs.com/banner?type=Ecosystem&background=tiles&project=library-name" alt="solid-create-script">
3+
</p>
4+
5+
# Template: SolidJS Library
6+
7+
Template for [SolidJS](https://www.solidjs.com/) library package. Bundling of the library is managed by [tsup](https://tsup.egoist.dev/).
8+
9+
Other things configured include:
10+
11+
- Bun (for dependency management and running scripts)
12+
- TypeScript
13+
- ESLint / Prettier
14+
- Solid Testing Library + Vitest (for testing)
15+
- Playground app using library
16+
- GitHub Actions (for all CI/CD)
17+
18+
## Getting Started
19+
20+
Some pre-requisites before install dependencies:
21+
22+
- Install Node Version Manager (NVM)
23+
```bash
24+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
25+
```
26+
- Install Bun
27+
```bash
28+
curl -fsSL https://bun.sh/install | bash
29+
```
30+
31+
### Installing Dependencies
32+
33+
```bash
34+
nvm use
35+
bun install
36+
```
37+
38+
### Local Development Build
39+
40+
```bash
41+
bun start
42+
```
43+
44+
### Linting & Formatting
45+
46+
```bash
47+
bun run lint # checks source for lint violations
48+
bun run format # checks source for format violations
49+
50+
bun run lint:fix # fixes lint violations
51+
bun run format:fix # fixes format violations
52+
```
53+
54+
### Contributing
55+
56+
The only requirements when contributing are:
57+
58+
- You keep a clean git history in your branch
59+
- rebasing `main` instead of making merge commits.
60+
- Using proper commit message formats that adhere to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
61+
- Additionally, squashing (via rebase) commits that are not [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
62+
- CI checks pass before merging into `main`

bun.lock

+978
Large diffs are not rendered by default.

eslint.config.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import js from "@eslint/js";
2+
import simpleImportSort from "eslint-plugin-simple-import-sort";
3+
import solid from "eslint-plugin-solid/configs/typescript";
4+
import globals from "globals";
5+
import tseslint from "typescript-eslint";
6+
7+
export default tseslint.config(
8+
{
9+
// config with just ignores is the replacement for `.eslintignore`
10+
ignores: ["**/build/**", "**/coverage/**", "**/dist/**", "**/node_modules/**"],
11+
},
12+
js.configs.recommended,
13+
tseslint.configs.strict,
14+
{
15+
plugins: {
16+
"simple-import-sort": simpleImportSort,
17+
},
18+
rules: {
19+
"simple-import-sort/imports": "error",
20+
"simple-import-sort/exports": "error",
21+
},
22+
},
23+
{
24+
files: ["**/*.ts", "**/*.tsx"],
25+
languageOptions: {
26+
parser: tseslint.parser,
27+
parserOptions: {
28+
sourceType: "module",
29+
project: "./tsconfig.json",
30+
ecmaFeatures: {
31+
jsx: true,
32+
},
33+
},
34+
globals: {
35+
...globals.browser,
36+
...globals.es2022,
37+
},
38+
},
39+
plugins: solid.plugins,
40+
rules: {
41+
...solid.rules,
42+
"@typescript-eslint/no-non-null-assertion": "off",
43+
"no-unused-vars": "off",
44+
"@typescript-eslint/no-unused-vars": [
45+
"error",
46+
{
47+
varsIgnorePattern: "^_",
48+
argsIgnorePattern: "^_",
49+
destructuredArrayIgnorePattern: "^_",
50+
},
51+
],
52+
},
53+
},
54+
{
55+
files: ["__tests__/**/*.ts", "__tests__/**/*.tsx"],
56+
languageOptions: {
57+
globals: {
58+
...globals.node,
59+
...globals.vitest,
60+
},
61+
},
62+
},
63+
);

index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<link rel="shortcut icon" type="image/ico" href="/playground/assets/favicon.ico" />
8+
<title>Solid App</title>
9+
</head>
10+
<body>
11+
<noscript>You need to enable JavaScript to run this app.</noscript>
12+
<div id="root"></div>
13+
14+
<script src="/playground/index.tsx" type="module"></script>
15+
</body>
16+
</html>

package.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "template-solidjs-library",
3+
"version": "0.0.0",
4+
"description": "Template for SolidJS library using tsup for bundling. Configured with Bun, NVM, TypeScript, ESLint, Prettier, Vitest, and GHA",
5+
"type": "module",
6+
"author": "Daniel Sanchez <[email protected]>",
7+
"license": "MIT",
8+
"homepage": "https://github.com/thedanchez/template-solidjs-library#readme",
9+
"bugs": {
10+
"url": "https://github.com/thedanchez/template-solidjs-library/issues"
11+
},
12+
"files": [
13+
"dist"
14+
],
15+
"main": "./dist/index.js",
16+
"module": "./dist/index.js",
17+
"types": "./dist/index.d.ts",
18+
"browser": {},
19+
"exports": {
20+
"solid": "./dist/index.jsx",
21+
"import": {
22+
"types": "./dist/index.d.ts",
23+
"default": "./dist/index.js"
24+
}
25+
},
26+
"typesVersions": {},
27+
"scripts": {
28+
"build": "tsup",
29+
"build:watch": "tsup --watch",
30+
"dev": "vite",
31+
"format": "prettier . --check",
32+
"format:fix": "prettier . --write",
33+
"lint": "eslint .",
34+
"lint:fix": "eslint . --fix",
35+
"serve": "vite preview",
36+
"start": "vite",
37+
"test": "vitest run",
38+
"test:cov": "vitest run --coverage",
39+
"typecheck": "tsc --noEmit"
40+
},
41+
"devDependencies": {
42+
"@solidjs/testing-library": "^0.8.10",
43+
"@testing-library/jest-dom": "^6.6.3",
44+
"@types/bun": "^1.2.3",
45+
"@typescript-eslint/eslint-plugin": "^8.25.0",
46+
"@typescript-eslint/parser": "^8.25.0",
47+
"@vitest/coverage-istanbul": "^3.0.7",
48+
"eslint": "^9.21.0",
49+
"eslint-plugin-simple-import-sort": "^12.1.1",
50+
"eslint-plugin-solid": "^0.14.5",
51+
"globals": "^16.0.0",
52+
"jiti": "^2.4.2",
53+
"jsdom": "^26.0.0",
54+
"prettier": "^3.5.2",
55+
"tsup": "^8.3.6",
56+
"tsup-preset-solid": "^2.2.0",
57+
"typescript": "^5.7.3",
58+
"typescript-eslint": "^8.25.0",
59+
"vite": "^6.2.0",
60+
"vite-plugin-solid": "^2.11.2",
61+
"vitest": "^3.0.7"
62+
},
63+
"peerDependencies": {
64+
"solid-js": "^1.9.4"
65+
}
66+
}

playground/App.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createSignal } from "solid-js";
2+
3+
export const App = () => {
4+
const [count, setCount] = createSignal(0);
5+
6+
return (
7+
<div>
8+
<div>Playground App</div>
9+
<div>Count: {count()}</div>
10+
<button
11+
onClick={() => {
12+
setCount((prev) => prev + 1);
13+
}}
14+
>
15+
Increment Count
16+
</button>
17+
</div>
18+
);
19+
};

playground/index.css

Whitespace-only changes.

playground/index.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import "./index.css";
2+
3+
import { render } from "solid-js/web";
4+
5+
import { App } from "./App";
6+
7+
const root = document.getElementById("root");
8+
9+
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
10+
throw new Error(
11+
"Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
12+
);
13+
}
14+
15+
render(() => <App />, root!);

setupTests.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "@testing-library/jest-dom/vitest";

src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Main library export site
2+
// Use playground app (via Vite) to test and document the library

tsconfig.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
/* Base Options: */
4+
"outDir": "dist",
5+
"esModuleInterop": true,
6+
"skipLibCheck": true,
7+
"target": "ESNext",
8+
"module": "ESNext",
9+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
10+
"allowJs": true,
11+
"resolveJsonModule": true,
12+
"moduleResolution": "Bundler",
13+
"moduleDetection": "force",
14+
"isolatedModules": true,
15+
"verbatimModuleSyntax": true,
16+
17+
/* Strictness */
18+
"strict": true,
19+
"allowUnreachableCode": false,
20+
"noImplicitOverride": true,
21+
"noFallthroughCasesInSwitch": true,
22+
"noUncheckedIndexedAccess": true,
23+
"noUnusedLocals": true,
24+
"noUnusedParameters": true,
25+
26+
/* JSX */
27+
"jsx": "preserve",
28+
"jsxImportSource": "solid-js",
29+
30+
/* Types */
31+
"types": ["vite/client", "bun-types", "@testing-library/jest-dom"]
32+
},
33+
"exclude": ["node_modules", "coverage", "dist"]
34+
}

tsup.config.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { defineConfig } from "tsup";
2+
import * as preset from "tsup-preset-solid";
3+
4+
import pkg from "./package.json";
5+
6+
const generateSolidPresetOptions = (watching: boolean): preset.PresetOptions => ({
7+
entries: [
8+
{
9+
// entries with '.tsx' extension will have `solid` export condition generated
10+
entry: "src/index.tsx",
11+
dev_entry: false,
12+
server_entry: false,
13+
},
14+
],
15+
drop_console: !watching, // remove all `console.*` calls and `debugger` statements in prod builds
16+
cjs: false,
17+
});
18+
19+
export default defineConfig((config) => {
20+
const watching = !!config.watch;
21+
const solidPresetOptions = generateSolidPresetOptions(watching);
22+
const parsedOptions = preset.parsePresetOptions(solidPresetOptions, watching);
23+
24+
if (!watching) {
25+
const packageFields = preset.generatePackageExports(parsedOptions);
26+
// console.log(`\npackage.json: \n${JSON.stringify(packageFields, null, 2)}\n\n`);
27+
/* will update ./package.json with the correct export fields */
28+
preset.writePackageJson(packageFields);
29+
}
30+
31+
const tsupOptions = preset
32+
.generateTsupOptions(parsedOptions)
33+
.map((tsupOption) => ({ name: pkg.name, ...tsupOption }));
34+
35+
return tsupOptions;
36+
});

0 commit comments

Comments
 (0)