Skip to content

Commit

Permalink
tests passes, but behavious is not wantable
Browse files Browse the repository at this point in the history
  • Loading branch information
XantreDev committed Nov 19, 2023
1 parent 80f43bc commit 8dd7d23
Show file tree
Hide file tree
Showing 32 changed files with 1,191 additions and 215 deletions.
1 change: 0 additions & 1 deletion apps/react-test/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import App from "./App.tsx";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
// strict mode is not allowed
<App />
);
47 changes: 13 additions & 34 deletions apps/react-test/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ 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";
import { createRequire } from "node:module";
import {
createReactAlias,
transformDepPlugin,
} from "@preact-signals/safe-react/integrations/vite";

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

Expand All @@ -21,48 +25,23 @@ export default defineConfig({
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;
},
};
})(),
},
createReactAlias(),
{
find: "@preact/signals-react",
replacement: path.resolve(
resolve("@preact-signals/safe-react"),
"../../esm/index.mjs"
),
replacement: "@preact-signals/safe-react",
},
],
}
: undefined,
plugins: [
USE_TRANSFORM &&
babel({
babelConfig: {
plugins: [
"@babel/plugin-syntax-jsx",
[
"module:@preact/signals-react-transform",
{
importSource: "@preact-signals/safe-react",
},
],
],
transformDepPlugin([
{
type: "nested",
path: ["components-for-test", "@preact-signals/utils"],
},
filter: /utils\/dist\/.+\.mjs$/,
}),
,
]),

reactBabel(
USE_TRANSFORM
? {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"@changesets/cli": "^2.26.2",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@vitest/ui": "^0.34.6",
"eslint": "^8.53.0",
"rimraf": "^5.0.5",
"turbo": "^1.10.16",
"typescript": "^5.2.2",
"vitest": "^0.33.0"
"vitest": "^0.34.6"
},
"scripts": {
"build": "turbo run build --filter=./packages/*",
Expand Down
3 changes: 2 additions & 1 deletion packages/components-for-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"types": "./dist/esm/index.d.ts",
"main": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
}
},
"./package.json": "./package.json"
},
"scripts": {
"clean": "rimraf dist",
Expand Down
17 changes: 0 additions & 17 deletions packages/react/babel.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/babel/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"main": "../babel.mjs"
"main": "../dist/babel.cjs"
}
29 changes: 0 additions & 29 deletions packages/react/global.d.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/react/jsx-dev-runtime.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions packages/react/jsx-runtime.cjs

This file was deleted.

93 changes: 74 additions & 19 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,70 @@
},
"bugs": "https://github.com/XantreGodlike/preact-signals/issues",
"amdName": "reactSignals",
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.mjs",
"types": "./dist/types/index.d.ts",
"source": "src/index.ts",
"main": "./dist/cjs/lib/index.cjs",
"module": "./dist/esm/lib/index.mjs",
"types": "./dist/types/lib/index.d.ts",
"source": "src/lib/index.ts",
"typesVersions": {
"*": {
"tracking": [
"./dist/types/lib/tracking.d.ts"
],
"react": [
"./dist/types/react.d.cts"
],
"jsx-runtime": [
"./dist/types/jsx-runtime.d.cts"
],
"jsx-dev-runtime": [
"./dist/types/jsx-dev-runtime.d.cts"
],
"babel": [
"./dist/types/babel.d.ts"
],
"integrations/vite": [
"./dist/types/integrations/vite.d.mts"
]
}
},
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.cjs",
"react-native": "./src/index.ts"
"types": "./dist/types/lib/index.d.ts",
"import": "./dist/esm/lib/index.mjs",
"require": "./dist/cjs/lib/index.cjs",
"react-native": "./src/lib/index.ts",
"source": "./src/lib/index.ts"
},
"./tracking": {
"types": "./dist/types/tracking.d.ts",
"import": "./dist/esm/tracking.mjs",
"require": "./dist/cjs/tracking.cjs",
"react-native": "./src/tracking.ts"
"types": "./dist/types/lib/tracking.d.ts",
"import": "./dist/esm/lib/tracking.mjs",
"require": "./dist/cjs/lib/tracking.cjs",
"react-native": "./src/lib/tracking.ts",
"source": "./src/lib/tracking.ts"
},
"./react": {
"types": "./dist/types/react.d.cts",
"default": "./src/react.cjs"
},
"./jsx-runtime": {
"types": "./dist/types/jsx-runtime.d.cts",
"default": "./src/jsx-runtime.cjs"
},
"./jsx-dev-runtime": {
"types": "./dist/types/jsx-dev-runtime.d.cts",
"default": "./src/jsx-dev-runtime.cjs"
},
"./react": "./react.cjs",
"./jsx-runtime": "./jsx-runtime.cjs",
"./jsx-dev-runtime": "./jsx-dev-runtime.cjs",
"./wrap-jsx": "./wrap-jsx.cjs",
"./package.json": "./package.json",
"./babel": "./babel.mjs"
"./babel": {
"types": "./dist/types/babel.d.ts",
"import": "./dist/esm/babel.mjs",
"require": "./dist/cjs/babel.cjs"
},
"./integrations/vite": {
"types": "./dist/types/integrations/vite.d.mts",
"import": "./src/integrations/vite.mjs",
"require": "./dist/vite.cjs"
}
},
"scripts": {
"clean": "rimraf dist",
Expand All @@ -60,24 +101,38 @@
"use-sync-external-store": "^1.2.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0",
"react": "^16.14.0 || 17.x || 18.x"
},
"devDependencies": {
"@preact/signals-react-transform": "0.1.0",
"@babel/core": "^7.23.3",
"@babel/helper-module-imports": "^7.22.15",
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/plugin-syntax-jsx": "^7.23.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-typescript": "^11.1.5",
"@types/babel__core": "^7.20.4",
"@types/babel__helper-module-imports": "^7.18.3",
"@types/babel__helper-plugin-utils": "^7.10.3",
"@types/babel__traverse": "^7.20.4",
"@types/debug": "^4.1.12",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/regex-escape": "^3.4.1",
"@types/use-sync-external-store": "^0.0.3",
"@vitejs/plugin-react": "^4.1.1",
"check-export-map": "^1.3.0",
"concurrently": "^8.2.2",
"debug": "^4.3.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-fast-hoc": "0.3.2",
"react-router-dom": "^6.9.0",
"regex-escape": "^3.4.10",
"rollup": "^3.29.4",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-node-externals": "^6.1.2"
"rollup-plugin-node-externals": "^6.1.2",
"vite": "^4.5.0",
"vite-plugin-babel": "^1.1.3"
}
}
16 changes: 13 additions & 3 deletions packages/react/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const useThrowOnError = true; // On error throw and exception
const useSourceMap = true; // Generate source map files
const useEsbuild = true; // `true` -> use esbuild, `false` use tsc

const input = ["src/index.ts"];
const tsInputs = ["src/lib/index.ts", "src/babel.ts"];
const cjsInputs = ["src/integrations/vite.mjs"];

const commonPlugins = [
externals(),
Expand All @@ -31,7 +32,7 @@ const commonPlugins = [
export default [
{
// CJS build
input,
input: tsInputs,
output: {
dir: "dist/cjs",
format: "cjs",
Expand All @@ -57,7 +58,7 @@ export default [
},
{
// ESM builds
input,
input: tsInputs,
output: {
dir: "dist/esm",
format: "es",
Expand All @@ -82,4 +83,13 @@ export default [
}),
],
},
{
input: cjsInputs,
output: {
entryFileNames: "[name].cjs",
assetFileNames: "[name].cjs",
dir: "dist",
format: "cjs",
},
},
];
Loading

0 comments on commit 8dd7d23

Please sign in to comment.