Skip to content

Commit ccd2e22

Browse files
committed
Initial commit
0 parents  commit ccd2e22

20 files changed

+339
-0
lines changed

Diff for: .eslintrc.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": ["simple-import-sort", "solid"],
4+
"extends": [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/eslint-recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"plugin:solid/typescript"
9+
],
10+
"env": {
11+
"browser": true,
12+
"node": true,
13+
"es6": true,
14+
"jest": true
15+
},
16+
"parserOptions": {
17+
"sourceType": "module"
18+
},
19+
"rules": {
20+
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_" }],
21+
"no-unused-vars": "off",
22+
"simple-import-sort/imports": "error",
23+
"simple-import-sort/exports": "error"
24+
},
25+
"ignorePatterns": ["dist", "node_modules"]
26+
}

Diff for: .github/CODEOWNERS

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

Diff for: .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: latest
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

Diff for: .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

Diff for: .nvmrc

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

Diff for: .prettierignore

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

Diff for: .prettierrc

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

Diff for: .vscode/settings.json

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

Diff for: README.md

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

Diff for: bun.lockb

176 KB
Binary file not shown.

Diff for: 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>

Diff for: package.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
"scripts": {
13+
"build": "tsup",
14+
"build:watch": "tsup --watch",
15+
"dev": "vite",
16+
"format": "prettier . --check",
17+
"format:fix": "prettier . --write",
18+
"lint": "eslint . --ext .ts,.tsx",
19+
"lint:fix": "eslint . --ext .ts,.tsx --fix",
20+
"serve": "vite preview",
21+
"start": "vite",
22+
"test": "vitest run",
23+
"test:cov": "vitest run --coverage",
24+
"typecheck": "tsc --noEmit"
25+
},
26+
"devDependencies": {
27+
"@solidjs/testing-library": "^0.8.10",
28+
"@testing-library/jest-dom": "^6.5.0",
29+
"@types/bun": "^1.1.10",
30+
"@typescript-eslint/eslint-plugin": "^8.7.0",
31+
"@typescript-eslint/parser": "^8.7.0",
32+
"@vitest/coverage-istanbul": "^2.1.1",
33+
"eslint": "^8.57.0",
34+
"eslint-plugin-simple-import-sort": "^12.1.1",
35+
"eslint-plugin-solid": "^0.14.3",
36+
"jsdom": "^25.0.1",
37+
"prettier": "^3.3.3",
38+
"tsup": "^8.3.0",
39+
"tsup-preset-solid": "^2.2.0",
40+
"typescript": "^5.6.2",
41+
"vite": "^5.4.8",
42+
"vite-plugin-solid": "^2.10.2",
43+
"vitest": "^2.1.1"
44+
},
45+
"peerDependencies": {
46+
"solid-js": ">=1.8.0"
47+
}
48+
}

Diff for: 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+
};

Diff for: playground/index.css

Whitespace-only changes.

Diff for: 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!);

Diff for: setupTests.ts

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

Diff for: 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

Diff for: 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+
}

Diff for: tsup.config.ts

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

Diff for: vite.config.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference types="vitest" />
2+
/// <reference types="vite/client" />
3+
4+
import { defineConfig } from "vite";
5+
import solidPlugin from "vite-plugin-solid";
6+
import { configDefaults } from "vitest/config";
7+
8+
const TEST_EXCLUDES = [...configDefaults.exclude, "src/index.tsx"];
9+
const COVERAGE_EXCLUDE = [...TEST_EXCLUDES, "**/*.test.{ts,tsx}"];
10+
11+
export default defineConfig({
12+
plugins: [solidPlugin()],
13+
server: {
14+
port: 3000,
15+
},
16+
build: {
17+
target: "esnext",
18+
},
19+
resolve: {
20+
conditions: ["development", "browser"],
21+
},
22+
test: {
23+
globals: true,
24+
environment: "jsdom",
25+
setupFiles: ["./setupTests.ts"],
26+
exclude: TEST_EXCLUDES,
27+
coverage: {
28+
all: true,
29+
provider: "istanbul",
30+
exclude: COVERAGE_EXCLUDE,
31+
thresholds: {
32+
"100": true,
33+
},
34+
},
35+
},
36+
});

0 commit comments

Comments
 (0)