Skip to content

Commit 064cd98

Browse files
committed
component api
1 parent 6cccaf2 commit 064cd98

File tree

9 files changed

+111
-133
lines changed

9 files changed

+111
-133
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ dist-ssr
99
explorations
1010
node_modules
1111
.eslintcache
12-
# components are libraries!
13-
package-lock.json
1412

1513
# this is a package-json-redirect stub dir, see https://github.com/andrewbranch/example-subpath-exports-ts-compat?tab=readme-ov-file
1614
react/package.json
1715
# npm pack output
1816
*.tgz
17+
*.tsbuildinfo

commonjs.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

eslint.config.js

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
import globals from "globals";
22
import pluginJs from "@eslint/js";
33
import tseslint from "typescript-eslint";
4+
import reactHooks from "eslint-plugin-react-hooks";
5+
import reactRefresh from "eslint-plugin-react-refresh";
46

57
export default [
6-
{ files: ["src/**/*.{js,mjs,cjs,ts,tsx}"] },
78
{
89
ignores: [
910
"dist/**",
1011
"eslint.config.js",
12+
"vitest.config.ts",
1113
"**/_generated/",
1214
"node10stubs.mjs",
1315
],
1416
},
1517
{
18+
files: ["src/**/*.{js,mjs,cjs,ts,tsx}", "example/**/*.{js,mjs,cjs,ts,tsx}"],
1619
languageOptions: {
17-
globals: globals.worker,
1820
parser: tseslint.parser,
19-
2021
parserOptions: {
21-
project: true,
22-
tsconfigRootDir: ".",
22+
project: [
23+
"./tsconfig.json",
24+
"./example/tsconfig.json",
25+
"./example/convex/tsconfig.json",
26+
],
27+
tsconfigRootDir: import.meta.dirname,
2328
},
2429
},
2530
},
2631
pluginJs.configs.recommended,
2732
...tseslint.configs.recommended,
33+
// Convex code - Worker environment
2834
{
35+
files: ["src/**/*.{ts,tsx}", "example/convex/**/*.{ts,tsx}"],
36+
ignores: ["src/react/**"],
37+
languageOptions: {
38+
globals: globals.worker,
39+
},
2940
rules: {
3041
"@typescript-eslint/no-floating-promises": "error",
31-
"eslint-comments/no-unused-disable": "off",
32-
33-
// allow (_arg: number) => {} and const _foo = 1;
42+
"@typescript-eslint/no-explicit-any": "off",
3443
"no-unused-vars": "off",
3544
"@typescript-eslint/no-unused-vars": [
3645
"warn",
@@ -39,6 +48,52 @@ export default [
3948
varsIgnorePattern: "^_",
4049
},
4150
],
51+
"@typescript-eslint/no-unused-expressions": [
52+
"error",
53+
{
54+
allowShortCircuit: true,
55+
allowTernary: true,
56+
allowTaggedTemplates: true,
57+
},
58+
],
59+
},
60+
},
61+
// React app code - Browser environment
62+
{
63+
files: ["src/react/**/*.{ts,tsx}", "example/src/**/*.{ts,tsx}"],
64+
languageOptions: {
65+
ecmaVersion: 2020,
66+
globals: globals.browser,
67+
},
68+
plugins: {
69+
"react-hooks": reactHooks,
70+
"react-refresh": reactRefresh,
71+
},
72+
rules: {
73+
...reactHooks.configs.recommended.rules,
74+
"react-refresh/only-export-components": [
75+
"warn",
76+
{ allowConstantExport: true },
77+
],
78+
"@typescript-eslint/no-explicit-any": "off",
79+
"no-unused-vars": "off",
80+
"@typescript-eslint/no-unused-vars": [
81+
"warn",
82+
{
83+
argsIgnorePattern: "^_",
84+
varsIgnorePattern: "^_",
85+
},
86+
],
87+
},
88+
},
89+
// Example config files (vite.config.ts, etc.) - Node environment
90+
{
91+
files: ["example/vite.config.ts", "example/**/*.config.{js,ts}"],
92+
languageOptions: {
93+
globals: {
94+
...globals.node,
95+
...globals.browser,
96+
},
4297
},
4398
},
4499
];

esm.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/convex/tsconfig.json

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
{
2-
/* This TypeScript project config describes the environment that
3-
* Convex functions run in and is used to typecheck them.
4-
* You can modify it, but some settings required to use Convex.
5-
*/
62
"compilerOptions": {
7-
/* These settings are not required by Convex and can be modified. */
83
"allowJs": true,
94
"strict": true,
105
"skipLibCheck": true,
11-
12-
/* These compiler options are required by Convex */
136
"target": "ESNext",
14-
"lib": ["ES2021", "dom", "ESNext.Array"],
7+
"lib": ["ES2021", "dom", "DOM.Iterable", "ESNext.Array"],
158
"forceConsistentCasingInFileNames": true,
169
"allowSyntheticDefaultImports": true,
10+
"verbatimModuleSyntax": true,
1711
"module": "ESNext",
1812
"moduleResolution": "Bundler",
1913
"isolatedModules": true,
2014
"noEmit": true,
21-
22-
/* This should only be used in this example. Real apps should not attempt
23-
* to compile TypeScript because differences between tsconfig.json files can
24-
* cause the code to be compiled differently.
25-
*/
26-
"customConditions": ["@convex-dev/component-source"]
15+
"jsx": "react-jsx"
2716
},
28-
"include": ["./**/*"],
17+
"include": [".*"],
2918
"exclude": ["./_generated"]
3019
}

example/eslint.config.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

example/tsconfig.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99
"module": "ESNext",
1010
"moduleResolution": "Bundler",
1111
"resolveJsonModule": true,
12+
"exactOptionalPropertyTypes": true,
1213
"isolatedModules": true,
13-
"allowImportingTsExtensions": true,
14-
"noEmit": true,
1514
"jsx": "react-jsx",
1615
"baseUrl": ".",
1716
"paths": {
1817
"@/*": ["src/*"]
1918
},
20-
/* This should only be used in this example. Real apps should not attempt
21-
* to compile TypeScript because differences between tsconfig.json files can
22-
* cause the code to be compiled differently.
23-
*/
24-
"customConditions": ["@convex-dev/component-source"]
19+
"noEmit": true
2520
},
2621
"include": ["./src", "vite.config.ts", "convex"]
2722
}

package.json

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,57 @@
1515
],
1616
"type": "module",
1717
"scripts": {
18-
"build": "npm run build:esm && npm run build:cjs",
19-
"build:esm": "tsc --project ./esm.json && echo '{\\n \"type\": \"module\"\\n}' > dist/esm/package.json",
20-
"build:cjs": "tsc --project ./commonjs.json && echo '{\\n \"type\": \"commonjs\"\\n}' > dist/commonjs/package.json",
21-
"dev": "cd example; npm run dev",
22-
"typecheck": "tsc --noEmit",
23-
"prepare": "npm run build",
24-
"prepack": "node node10stubs.mjs",
25-
"postpack": "node node10stubs.mjs --cleanup",
26-
"alpha": "rm -rf dist && npm run build && npm run test && npm version prerelease --preid alpha && npm publish --tag alpha && git push --tags",
27-
"release": "rm -rf dist && npm run build && npm run test && npm version patch && npm publish && git push --tags",
28-
"test": "vitest run",
18+
"dev": "run-p -r 'dev:*'",
19+
"dev:backend": "convex dev --typecheck-components",
20+
"dev:frontend": "cd example && vite --clearScreen false",
21+
"dev:build": "npx chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'npx convex codegen --component ./src/component && npm run build' --initial",
22+
"predev": "npm run dev:backend -- --until-success",
23+
"clean": "rm -rf dist *.tsbuildinfo",
24+
"build": "tsc --project ./tsconfig.build.json",
25+
"typecheck": "tsc --noEmit && tsc -p example && tsc -p example/convex",
26+
"lint": "eslint src && eslint example",
27+
"all": "run-p -r 'dev:*' 'test:watch'",
28+
"test": "vitest run --typecheck",
29+
"test:watch": "vitest --typecheck --clearScreen false",
2930
"test:debug": "vitest --inspect-brk --no-file-parallelism",
30-
"test:coverage": "vitest run --coverage --coverage.reporter=text"
31+
"test:coverage": "vitest run --coverage --coverage.reporter=text",
32+
"attw": "attw $(npm pack -s) --exclude-entrypoints ./convex.config --profile esm-only",
33+
"prepare": "npm run build",
34+
"alpha": "npm run clean && npm ci && run-p test lint typecheck attw && npm version prerelease --preid alpha && npm publish --tag alpha && git push --tags",
35+
"release": "npm run clean && npm ci && run-p test lint typecheck attw && npm version patch && npm publish && git push --tags",
36+
"version": "pbcopy <<<$npm_package_version; vim CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
3137
},
3238
"files": [
3339
"dist",
34-
"src",
35-
"react"
40+
"src"
3641
],
3742
"exports": {
3843
"./package.json": "./package.json",
3944
".": {
40-
"import": {
41-
"@convex-dev/component-source": "./src/client/index.ts",
42-
"types": "./dist/esm/client/index.d.ts",
43-
"default": "./dist/esm/client/index.js"
44-
},
45-
"require": {
46-
"@convex-dev/component-source": "./src/client/index.ts",
47-
"types": "./dist/commonjs/client/index.d.ts",
48-
"default": "./dist/commonjs/client/index.js"
49-
}
45+
"types": "./dist/client/index.d.ts",
46+
"default": "./dist/client/index.js"
5047
},
5148
"./react": {
52-
"import": {
53-
"@convex-dev/component-source": "./src/react/index.ts",
54-
"types": "./dist/esm/react/index.d.ts",
55-
"default": "./dist/esm/react/index.js"
56-
},
57-
"require": {
58-
"@convex-dev/component-source": "./src/react/index.ts",
59-
"types": "./dist/commonjs/react/index.d.ts",
60-
"default": "./dist/commonjs/react/index.js"
61-
}
49+
"types": "./dist/react/index.d.ts",
50+
"default": "./dist/react/index.js"
51+
},
52+
"./test": "./src/test.ts",
53+
"./_generated/component.js": {
54+
"types": "./dist/component/_generated/component.d.ts"
6255
},
6356
"./convex.config": {
64-
"import": {
65-
"@convex-dev/component-source": "./src/component/convex.config.ts",
66-
"types": "./dist/esm/component/convex.config.d.ts",
67-
"default": "./dist/esm/component/convex.config.js"
68-
}
57+
"types": "./dist/component/convex.config.d.ts",
58+
"default": "./dist/component/convex.config.js"
6959
}
7060
},
7161
"peerDependencies": {
72-
"convex": ">=1.23.0 <1.35.0",
62+
"convex": "^1.24.8",
7363
"react": "~18.3.1 || ^19.0.0",
7464
"react-dom": "~18.3.1 || ^19.0.0"
7565
},
7666
"devDependencies": {
7767
"@eslint/js": "^9.9.1",
78-
"@types/node": "^18.17.0",
68+
"@types/node": "20.19.24",
7969
"@types/react": "^19.0.10",
8070
"convex-test": "^0.0.36",
8171
"eslint": "^9.9.1",
@@ -85,7 +75,6 @@
8575
"typescript-eslint": "^8.4.0",
8676
"vitest": "^3.1.4"
8777
},
88-
"main": "./dist/commonjs/client/index.js",
89-
"types": "./dist/commonjs/client/index.d.ts",
90-
"module": "./dist/esm/client/index.js"
78+
"types": "./dist/client/index.d.ts",
79+
"module": "./dist/client/index.js"
9180
}

tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@
55
"strict": true,
66

77
"target": "ESNext",
8-
"lib": ["ES2021", "dom"],
8+
"lib": ["ES2021", "dom", "DOM.Iterable"],
9+
"jsx": "react-jsx",
910
"forceConsistentCasingInFileNames": true,
1011
"allowSyntheticDefaultImports": true,
12+
"noErrorTruncation": true,
13+
// We enforce stricter module resolution for Node16 compatibility
14+
// But when building we use Bundler & ESNext for ESM
1115
"module": "ESNext",
1216
"moduleResolution": "Bundler",
1317

18+
"composite": true,
1419
"isolatedModules": true,
1520
"declaration": true,
1621
"declarationMap": true,
1722
"sourceMap": true,
23+
"rootDir": "./src",
1824
"outDir": "./dist",
25+
"verbatimModuleSyntax": true,
1926
"skipLibCheck": true
2027
},
2128
"include": ["./src/**/*"]

0 commit comments

Comments
 (0)