Skip to content

Commit

Permalink
Merge pull request #21 from XantreGodlike/safe-signals-runtime
Browse files Browse the repository at this point in the history
Safe signals runtime early implementation
  • Loading branch information
XantreDev authored Nov 13, 2023
2 parents c2adf4a + d138819 commit e462080
Show file tree
Hide file tree
Showing 80 changed files with 4,726 additions and 1,262 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-meals-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preact-signals/safe-react": patch
---

Package init
5 changes: 5 additions & 0 deletions .changeset/silver-foxes-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preact-signals/utils": patch
---

Removed unnecessary private varitables usage from hocs entry
7 changes: 7 additions & 0 deletions .changeset/spotty-countries-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@preact-signals/unified-signals": patch
"@preact-signals/query": patch
"@preact-signals/utils": patch
---

Added `@preact-signals/safe-react` as peerDependency
5 changes: 5 additions & 0 deletions .changeset/young-parents-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preact-signals/query": minor
---

Removed incorrect `@trackSignals` directives for `@preact/signals-react-transform`
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages/query/src/__tests__/standart-query
node_modules
dist
16 changes: 16 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"project": ["./tsconfig.json"] // Specify it only for TypeScript files
},
"rules": {
"@typescript-eslint/no-floating-promises": [
"error",
{
"ignoreVoid": true
}
]
},
"root": true
}
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ on:
pull_request:
branches:
- main

jobs:
test:
name: Lint x Test react-fast-hoc package
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
name: Lint x Test preact-signals monorepo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release-pr:
name: Release
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand All @@ -26,13 +29,13 @@ jobs:

- name: Install Dependencies
run: pnpm i

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm run release
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ dist-ssr
*.sln
*.sw?

tsconfig.tsbuildinfo
.turbo
tsconfig.tsbuildinfo
vite.config.ts.timestamp-*
vitest.config.ts.timestamp-*
16 changes: 8 additions & 8 deletions apps/preact-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"preview": "vite preview"
},
"dependencies": {
"@preact/signals": "^1.1.4",
"@preact/signals": "^1.2.1",
"components-for-test": "workspace:*",
"preact": "^10.15.1"
"preact": "^10.19.1"
},
"devDependencies": {
"@preact/preset-vite": "^2.5.0",
"autoprefixer": "^10.4.14",
"daisyui": "^3.5.1",
"postcss": "^8.4.27",
"tailwindcss": "^3.3.3",
"vite": "^4.4.0"
"@preact/preset-vite": "^2.6.0",
"autoprefixer": "^10.4.16",
"daisyui": "^3.9.4",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"vite": "^4.5.0"
}
}
14 changes: 0 additions & 14 deletions apps/react-test/.eslintrc.cjs

This file was deleted.

35 changes: 18 additions & 17 deletions apps/react-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@
"version": "0.0.13",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"dev:transform": "cross-env USE_TRANSFORM=1 vite",
"dev": "cross-env USE_TRANSFORM=0 vite",
"build": "cross-env USE_TRANSFORM=0 vite build",
"watch": "pnpm dev",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@preact-signals/safe-react": "workspace:*",
"@preact/signals-react": "^1.3.3",
"components-for-test": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"vite-plugin-babel": "^1.1.3",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitejs/plugin-react-swc": "^3.0.0",
"autoprefixer": "^10.4.14",
"daisyui": "^3.5.1",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"postcss": "^8.4.27",
"tailwindcss": "^3.3.3",
"vite": "^4.3.9"
"@babel/plugin-syntax-jsx": "^7.23.3",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@vitejs/plugin-react": "^4.1.1",
"@vitejs/plugin-react-swc": "^3.4.1",
"autoprefixer": "^10.4.16",
"cross-env": "^7.0.3",
"daisyui": "^3.9.4",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"vite": "^4.5.0"
}
}
84 changes: 81 additions & 3 deletions apps/react-test/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,85 @@
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
import reactBabel from "@vitejs/plugin-react";
import babel from "vite-plugin-babel";
import { PluginOption, defineConfig } from "vite";
import { z } from "zod";
import { createRequire } from "node:module";
import path from "node:path";

const resolve = createRequire(import.meta.url).resolve;

const envSchema = z
.object({
USE_TRANSFORM: z.enum(["0", "1"]),
})
.transform((it) => ({
USE_TRANSFORM: it.USE_TRANSFORM === "0" ? false : true,
}));
const { USE_TRANSFORM } = envSchema.parse(process.env);

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: USE_TRANSFORM
? {
alias: [
{
find: /^react$/,
replacement: "@preact-signals/safe-react/react",
// TODO: extract to lib
customResolver: (() => {
const reactUrl = resolve("react");
const fakeUrl = resolve("@preact-signals/safe-react/react");
return {
resolveId(source, importer) {
const useRealImport = importer?.endsWith("react.cjs");
return useRealImport ? reactUrl : fakeUrl;
},
};
})(),
},
{
find: "@preact/signals-react",
replacement: path.resolve(
resolve("@preact-signals/safe-react"),
"../../esm/index.mjs"
),
},
],
}
: undefined,
plugins: [
USE_TRANSFORM &&
babel({
babelConfig: {
plugins: [
"@babel/plugin-syntax-jsx",
[
"module:@preact/signals-react-transform",
{
importSource: "@preact-signals/safe-react",
},
],
],
},
filter: /utils\/dist\/.+\.mjs$/,
}),
,
reactBabel(
USE_TRANSFORM
? {
jsxImportSource: "@preact-signals/safe-react",
babel: {
plugins: [
[
"module:@preact/signals-react-transform",
{
importSource: "@preact-signals/safe-react",
},
],
],
},
include: /\.(mdx|js|jsx|ts|tsx)$/,
}
: undefined
) as PluginOption[],
].filter(Boolean),
});
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
"version": "0.0.1",
"devDependencies": {
"@changesets/cli": "^2.26.2",
"rimraf": "^5.0.1",
"turbo": "^1.10.12",
"typescript": "^5.1.6",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"eslint": "^8.53.0",
"rimraf": "^5.0.5",
"turbo": "^1.10.16",
"typescript": "^5.2.2",
"vitest": "^0.33.0"
},
"scripts": {
"build": "turbo run build --filter=./packages/*",
"build:with-apps": "turbo run build",
"watch": "turbo run watch --parallel",
"test": "turbo run test --parallel",
"eslint": "eslint --ext .ts,.tsx,.js,.jsx,.cjs,.mjs . --cache --cache-location=node_modules/.eslintcache",
"lint": "turbo run lint",
"changeset": "changeset",
"release": "pnpm build && changeset publish"
Expand Down
12 changes: 7 additions & 5 deletions packages/components-for-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
},
"dependencies": {
"@preact-signals/utils": "workspace:*",
"@tanstack/react-router": "0.0.1-beta.209",
"@tanstack/router": "0.0.1-beta.140"
},
"peerDependencies": {
"@preact-signals/query": "workspace:*",
"@preact/signals-react": "^1.3",
"@preact-signals/safe-react": "*",
"@preact/signals": "^1.*",
"@preact/signals-react": "^1.3",
"react": "17.*.* || 18.*.*"
},
"peerDependenciesMeta": {
Expand All @@ -46,12 +48,12 @@
"devDependencies": {
"@preact-signals/query": "workspace:*",
"@preact/signals-react": "^1.3.6",
"@types/react": "^18",
"@types/react-dom": "^18",
"concurrently": "^8.2.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"concurrently": "^8.2.2",
"react": "^18",
"react-dom": "^18",
"type-fest": "^3.12.0"
"type-fest": "^3.13.1"
},
"keywords": [],
"license": "MIT"
Expand Down
Loading

0 comments on commit e462080

Please sign in to comment.