unplugin-react-fine-grained-signals 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ import { TransformResult } from "unplugin";
2
+ //#region src/internal/transform.d.ts
3
+ type ReactFineGrainedSignalsMode = "manual" | "auto" | "all";
4
+ type ReactFineGrainedSignalsTransform = "inject" | "managed";
5
+ type ReactFineGrainedSignalsReactCompiler = "auto" | "off";
6
+ //#endregion
7
+ //#region src/unplugin.d.ts
8
+ interface ReactFineGrainedSignalsOptions {
9
+ /**
10
+ * `manual` preserves explicit useSignals() opt-in. `auto` detects signal
11
+ * reads in components and custom hooks; `all` also wraps JSX components that
12
+ * do not statically expose a .value read.
13
+ */
14
+ mode?: ReactFineGrainedSignalsMode;
15
+ /** `managed` (default) adds an exact try/finally boundary; `inject` adds bare useSignals() for best-effort opt-in. */
16
+ transform?: ReactFineGrainedSignalsTransform;
17
+ /**
18
+ * `auto` (default) marks every transformed function with `"use no memo"`, so
19
+ * React Compiler cannot memoize away the signal reads render tracking needs.
20
+ * `off` omits the directive; only choose it when the compiler is not used, or
21
+ * when its memoization has been verified against this library's tracking.
22
+ */
23
+ reactCompiler?: ReactFineGrainedSignalsReactCompiler;
24
+ /** Package that exports `useSignals` and its `/runtime` entry. */
25
+ importSource?: string;
26
+ /**
27
+ * Extra module specifier whose `memo`/`forwardRef` exports are treated as
28
+ * React's own, for a codebase that imports them through one stable internal
29
+ * module instead of directly from `"react"`. Recognition is additive: a
30
+ * direct `"react"` import always counts, so this only widens detection.
31
+ * It does not resolve arbitrary re-export chains, and it cannot cover
32
+ * relative barrel paths that differ per importing file.
33
+ */
34
+ reactImportSource?: string;
35
+ /** Restrict transformation to matching source module identifiers. */
36
+ include?: (id: string) => boolean;
37
+ /** Exclude matching source module identifiers from transformation. */
38
+ exclude?: (id: string) => boolean;
39
+ }
40
+ declare const pluginName = "unplugin-react-fine-grained-signals";
41
+ declare function canTransform(id: string, options: ReactFineGrainedSignalsOptions): boolean;
42
+ /**
43
+ * The esbuild loader names this plugin itself ever chooses. esbuild's own
44
+ * `Loader` union is wider and is not importable here (esbuild is not a
45
+ * dependency of this package), so a value read out of the project's configured
46
+ * loader map is handed straight back and narrowed to this at the hook boundary.
47
+ */
48
+ type EsbuildLoaderName = "js" | "jsx" | "ts" | "tsx";
49
+ /**
50
+ * The loader to label `id`'s contents with, deferring to the build's own
51
+ * `loader` map first so a project that configured an extension keeps its
52
+ * choice. Exported for the adapter tests, which exercise the decision without
53
+ * needing esbuild itself.
54
+ */
55
+ declare function resolveEsbuildLoader(id: string, configuredLoaders?: Record<string, string> | undefined): string;
56
+ declare const reactFineGrainedSignals: import("unplugin").UnpluginInstance<ReactFineGrainedSignalsOptions, boolean>;
57
+ /**
58
+ * The `{ code, map }` shape a bundler's `transform` hook returns on a real
59
+ * change, `null` on none. Derived from unplugin's own `TransformResult`
60
+ * (rather than naming the source-map types by hand) so the accepted `map`
61
+ * shape -- a real source map object when `sourceMaps: true` produces one, not
62
+ * only `null` -- always matches what unplugin itself expects, and follows
63
+ * unplugin's own type surface if that ever changes.
64
+ */
65
+ type BundlerTransformOutput = Extract<TransformResult, {
66
+ code: string;
67
+ }> | null;
68
+ /**
69
+ * The one piece every per-bundler entry file (`vite.ts`, `webpack.ts`,
70
+ * `rollup.ts`, `esbuild.ts`, `rspack.ts`) repeated: casting `reactFineGrainedSignals`'s
71
+ * `bundler` property to a callable factory of its own bundler-specific plugin
72
+ * type. Each entry file supplies only the two things that actually differ
73
+ * between bundlers -- which property to read and what shape it returns.
74
+ */
75
+ declare function createBundlerPlugin<Plugin>(bundler: "vite" | "webpack" | "rollup" | "esbuild" | "rspack"): (options?: ReactFineGrainedSignalsOptions) => Plugin;
76
+ //#endregion
77
+ export { createBundlerPlugin as a, resolveEsbuildLoader as c, ReactFineGrainedSignalsTransform as d, canTransform as i, ReactFineGrainedSignalsMode as l, EsbuildLoaderName as n, pluginName as o, ReactFineGrainedSignalsOptions as r, reactFineGrainedSignals as s, BundlerTransformOutput as t, ReactFineGrainedSignalsReactCompiler as u };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { a as createBundlerPlugin, c as resolveEsbuildLoader, d as ReactFineGrainedSignalsTransform, i as canTransform, l as ReactFineGrainedSignalsMode, n as EsbuildLoaderName, o as pluginName, r as ReactFineGrainedSignalsOptions, s as reactFineGrainedSignals, t as BundlerTransformOutput, u as ReactFineGrainedSignalsReactCompiler } from "./unplugin-CG9_mdcA.js";
2
+ //#region src/vite.d.ts
3
+ /** A Rollup-compatible plugin shape also accepted by Vite. */
4
+ interface VitePlugin {
5
+ name: string;
6
+ enforce?: "pre" | "post";
7
+ transform?: (code: string, id: string) => BundlerTransformOutput;
8
+ }
9
+ declare const _default: (options?: ReactFineGrainedSignalsOptions) => VitePlugin;
10
+ //#endregion
11
+ export { BundlerTransformOutput, EsbuildLoaderName, type ReactFineGrainedSignalsMode, ReactFineGrainedSignalsOptions, type ReactFineGrainedSignalsReactCompiler, type ReactFineGrainedSignalsTransform, VitePlugin, canTransform, createBundlerPlugin, _default as default, pluginName, reactFineGrainedSignals, resolveEsbuildLoader };
package/dist/vite.js ADDED
@@ -0,0 +1,5 @@
1
+ import { a as resolveEsbuildLoader, i as reactFineGrainedSignals, n as createBundlerPlugin, r as pluginName, t as canTransform } from "./unplugin-B2_q8KNi.js";
2
+ //#region src/vite.ts
3
+ var vite_default = createBundlerPlugin("vite");
4
+ //#endregion
5
+ export { canTransform, createBundlerPlugin, vite_default as default, pluginName, reactFineGrainedSignals, resolveEsbuildLoader };
@@ -0,0 +1,9 @@
1
+ import { a as createBundlerPlugin, c as resolveEsbuildLoader, d as ReactFineGrainedSignalsTransform, i as canTransform, l as ReactFineGrainedSignalsMode, n as EsbuildLoaderName, o as pluginName, r as ReactFineGrainedSignalsOptions, s as reactFineGrainedSignals, t as BundlerTransformOutput, u as ReactFineGrainedSignalsReactCompiler } from "./unplugin-CG9_mdcA.js";
2
+ //#region src/webpack.d.ts
3
+ /** The compiler-plugin contract used by webpack. */
4
+ interface WebpackPlugin {
5
+ apply(compiler: unknown): void;
6
+ }
7
+ declare const _default: (options?: ReactFineGrainedSignalsOptions) => WebpackPlugin;
8
+ //#endregion
9
+ export { BundlerTransformOutput, EsbuildLoaderName, type ReactFineGrainedSignalsMode, ReactFineGrainedSignalsOptions, type ReactFineGrainedSignalsReactCompiler, type ReactFineGrainedSignalsTransform, WebpackPlugin, canTransform, createBundlerPlugin, _default as default, pluginName, reactFineGrainedSignals, resolveEsbuildLoader };
@@ -0,0 +1,5 @@
1
+ import { a as resolveEsbuildLoader, i as reactFineGrainedSignals, n as createBundlerPlugin, r as pluginName, t as canTransform } from "./unplugin-B2_q8KNi.js";
2
+ //#region src/webpack.ts
3
+ var webpack_default = createBundlerPlugin("webpack");
4
+ //#endregion
5
+ export { canTransform, createBundlerPlugin, webpack_default as default, pluginName, reactFineGrainedSignals, resolveEsbuildLoader };
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "unplugin-react-fine-grained-signals",
3
+ "version": "0.1.0",
4
+ "description": "Universal useSignals transform for react-fine-grained-signals.",
5
+ "license": "MIT",
6
+ "author": "akazawa",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/sakzw/react-fine-grained-signals.git",
10
+ "directory": "packages/unplugin-react-fine-grained-signals"
11
+ },
12
+ "homepage": "https://github.com/sakzw/react-fine-grained-signals/tree/main/packages/unplugin-react-fine-grained-signals#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/sakzw/react-fine-grained-signals/issues"
15
+ },
16
+ "keywords": [
17
+ "unplugin",
18
+ "vite",
19
+ "rollup",
20
+ "webpack",
21
+ "rspack",
22
+ "esbuild",
23
+ "react",
24
+ "signals",
25
+ "fine-grained",
26
+ "react-fine-grained-signals",
27
+ "alien-signals"
28
+ ],
29
+ "type": "module",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ },
36
+ "./vite": {
37
+ "types": "./dist/vite.d.ts",
38
+ "import": "./dist/vite.js"
39
+ },
40
+ "./rollup": {
41
+ "types": "./dist/rollup.d.ts",
42
+ "import": "./dist/rollup.js"
43
+ },
44
+ "./webpack": {
45
+ "types": "./dist/webpack.d.ts",
46
+ "import": "./dist/webpack.js"
47
+ },
48
+ "./rspack": {
49
+ "types": "./dist/rspack.d.ts",
50
+ "import": "./dist/rspack.js"
51
+ },
52
+ "./esbuild": {
53
+ "types": "./dist/esbuild.d.ts",
54
+ "import": "./dist/esbuild.js"
55
+ },
56
+ "./package.json": "./package.json"
57
+ },
58
+ "files": [
59
+ "dist",
60
+ "README.md",
61
+ "README.ja.md",
62
+ "LICENSE"
63
+ ],
64
+ "peerDependencies": {
65
+ "react-fine-grained-signals": "^0.1.0"
66
+ },
67
+ "dependencies": {
68
+ "@babel/core": "^8.0.1",
69
+ "@babel/helper-plugin-utils": "^8.0.1",
70
+ "@babel/types": "^8.0.4",
71
+ "unplugin": "^3.3.0"
72
+ },
73
+ "devDependencies": {
74
+ "@vitest/coverage-v8": "4.1.11",
75
+ "react-fine-grained-signals": "0.1.0",
76
+ "tsdown": "0.22.14",
77
+ "typescript": "^7.0.2",
78
+ "vitest": "^4.1.11"
79
+ },
80
+ "scripts": {
81
+ "build": "tsdown && node tests/build-smoke.mjs",
82
+ "bench": "node --expose-gc benchmarks/transform.mjs",
83
+ "test": "vitest run",
84
+ "test:coverage": "vitest run --coverage",
85
+ "test:react-compiler": "vitest run tests/react-compiler.test.ts",
86
+ "typecheck": "tsc --noEmit"
87
+ }
88
+ }