@unframework.dev/unplugin 0.1.3 → 0.2.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.
package/README.md CHANGED
@@ -90,7 +90,7 @@ integration harness does (`sourceUtilities` in `tests/integration/harness/stylef
90
90
 
91
91
  | Option | Meaning |
92
92
  | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
93
- | `target` | A built-in target's name (`"react"`, `"vue"`, `"svelte"`, `"solid"`, `"angular"`, `"qwik"`, `"astro"`) or a third-party `Target`. Optional on Vite, which detects a built-in target. Required on every other bundler. |
93
+ | `target` | A built-in target's name (`"react"`, `"vue"`, `"svelte"`, `"solid"`, `"angular"`, `"qwik"`, `"astro"`), `"solid@2"`, or a third-party `Target`. Optional on Vite, which detects a built-in target. Required on every other bundler. |
94
94
  | `extension` | What module ids append to the `.uf.tsx` path. Built-in targets have one; a third-party target must set it. |
95
95
  | `onCompile` | Called each time a module loads, with `{ id, file, target, files, diagnostics }`. Returning a string (or a promise of one) fails that module with it: the integration harness's golden guard. |
96
96
  | `plugins` | Compiler plugins, passed to `compile()` (the harness's canaries). |
@@ -123,6 +123,7 @@ name matches as this table writes it, so `vite:vue-jsx` and `vite-plugin-qwik-po
123
123
  | Svelte | `vite-plugin-svelte` | `@sveltejs/vite-plugin-svelte` |
124
124
  | React | `vite:react-*` | `@vitejs/plugin-react` |
125
125
  | Solid | `solid` | `vite-plugin-solid` |
126
+ | Solid 2 | `solid`, with `solid-js` 2 | `@solidjs/vite-plugin` |
126
127
  | Qwik | `vite-plugin-qwik` | `qwikVite` from Qwik |
127
128
  | Astro | `astro:*` | Astro's own plugins |
128
129
  | Angular | `@analogjs/vite-plugin-angular` | `@analogjs/vite-plugin-angular` |
package/dist/detect.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { createRequire } from "node:module";
2
+ import { join } from "node:path";
1
3
  import { readFileSync, realpathSync, statSync } from "node:fs";
2
4
  import { createDiagnostic, formatDiagnostic } from "@unframework.dev/diagnostics";
3
5
  // src/detect.ts
@@ -9,6 +11,7 @@ const FRAMEWORK_PLUGINS = {
9
11
  vue: (name) => name === VUE_PLUGIN,
10
12
  svelte: (name) => name === "vite-plugin-svelte",
11
13
  solid: (name) => name === "solid",
14
+ solid2: (name) => name === "solid",
12
15
  angular: (name) => name === "@analogjs/vite-plugin-angular",
13
16
  qwik: (name) => name === "vite-plugin-qwik",
14
17
  astro: (name) => name.startsWith("astro:")
@@ -18,17 +21,39 @@ const NO_SPAN = {
18
21
  end: 0
19
22
  };
20
23
  /**
24
+ * The major of the `solid-js` that resolves from `root`, or `undefined` when none does. Read from
25
+ * its `package.json`, so neither Solid build loads.
26
+ */
27
+ function solidMajor(root) {
28
+ try {
29
+ const manifest = createRequire(join(root, "package.json")).resolve("solid-js/package.json");
30
+ const { version } = JSON.parse(readFileSync(manifest, "utf8"));
31
+ const major = typeof version === "string" ? Number.parseInt(version, 10) : NaN;
32
+ return Number.isNaN(major) ? void 0 : major;
33
+ } catch {
34
+ return;
35
+ }
36
+ }
37
+ /**
21
38
  * The one target whose framework's plugin is among `plugins`, or the UF7005 or UF7006 message that
22
- * says why there isn't one. `file` names the configuration in the message.
39
+ * says why there isn't one. `file` names the configuration in the message. The `"solid"` plugin is
40
+ * Solid 2's when the `solid-js` that resolves from `root` is 2.x, and Solid 1's otherwise, as it
41
+ * was before `solid@2` (ADR-0102).
23
42
  */
24
- function detectTarget(plugins, file) {
43
+ function detectTarget(plugins, file, root = process.cwd()) {
25
44
  const names = plugins.flatMap(({ name }) => typeof name === "string" ? [name] : []);
45
+ let solid;
26
46
  const found = Object.entries(FRAMEWORK_PLUGINS).flatMap(([target, belongs]) => {
27
47
  const plugin = names.find((name) => belongs(name));
28
- return plugin ? [{
48
+ if (!plugin) return [];
49
+ if (target === "solid" || target === "solid2") {
50
+ solid ??= solidMajor(root) === 2 ? "solid2" : "solid";
51
+ if (target !== solid) return [];
52
+ }
53
+ return [{
29
54
  target,
30
55
  plugin
31
- }] : [];
56
+ }];
32
57
  });
33
58
  if (found.length === 1) return { target: found[0].target };
34
59
  const diagnostic = found.length ? createDiagnostic("UF7006", {
@@ -113,4 +138,4 @@ function fillVueScriptFs(plugins) {
113
138
  }
114
139
  };
115
140
  }
116
- export { NODE_SCRIPT_FS, detectTarget, fillVueScriptFs, hostOptionWarning };
141
+ export { NODE_SCRIPT_FS, detectTarget, fillVueScriptFs, hostOptionWarning, solidMajor };
package/dist/ids.js CHANGED
@@ -29,6 +29,7 @@ const ID_SUFFIXES = {
29
29
  vue: ".vue",
30
30
  svelte: ".svelte",
31
31
  solid: "",
32
+ solid2: "",
32
33
  angular: ".ts",
33
34
  qwik: "",
34
35
  astro: ".astro"
@@ -47,6 +48,7 @@ const COMPOSABLE_ID_SUFFIXES = {
47
48
  vue: "",
48
49
  svelte: ".svelte.ts",
49
50
  solid: "",
51
+ solid2: "",
50
52
  angular: ".ts",
51
53
  qwik: "",
52
54
  astro: ""
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CompilerPlugin, TargetName, UfModule } from "@unframework.dev/compiler";
1
+ import { CompilerPlugin, TargetSelector, UfModule } from "@unframework.dev/compiler";
2
2
  import { Diagnostic } from "@unframework.dev/diagnostics";
3
3
  import { UnpluginInstance } from "unplugin";
4
4
  import { OutputFile, Target } from "@unframework.dev/codegen";
@@ -23,11 +23,11 @@ export interface CompileEvent {
23
23
  /** Options of the unframework plugin. */
24
24
  export interface UnframeworkOptions {
25
25
  /**
26
- * The framework to compile to: a built-in target's name, or a third-party target. On Vite it may
27
- * be left out, and the framework's plugin in the configuration decides (ADR-0075). Every other
28
- * bundler needs it.
26
+ * The framework to compile to: a built-in target's selector, such as `"solid@2"` (ADR-0102), or a
27
+ * third-party target. On Vite it may be left out, and the framework's plugin in the configuration
28
+ * decides (ADR-0075). Every other bundler needs it.
29
29
  */
30
- target?: TargetName | Target;
30
+ target?: TargetSelector | Target;
31
31
  /**
32
32
  * What module ids append to the `.uf.tsx` path: the extension the framework's own Vite plugin
33
33
  * claims, such as `".vue"`, or `""` to keep the `.uf.tsx` id. Defaults to the built-in
package/dist/plugin.js CHANGED
@@ -3,7 +3,7 @@ import { chainQwikSegments, chainSvelteOnce } from "./chain.js";
3
3
  import { detectTarget, fillVueScriptFs, hostOptionWarning } from "./detect.js";
4
4
  import { COMPONENT_ID_FILTER, COMPOSABLE_EXTENSION, COMPOSABLE_ID_SUFFIXES, ID_SUFFIXES, SCAN_ID_PREFIX, SOURCE_EXTENSION, componentId, composableFilter, composableId, composableIdSuffix, idSuffix, moduleId, moduleIdCandidates, moduleIdFilter, parseComponentId, parseComposableId, parseModuleId, specifierFilter } from "./ids.js";
5
5
  import { basename, extname, isAbsolute, posix, relative, sep } from "node:path";
6
- import { checkPassThrough, createProject, createSyntacticOracle, resolveTarget } from "@unframework.dev/compiler";
6
+ import { checkPassThrough, createProject, createSyntacticOracle, isTargetSelector, resolveTarget, targetName } from "@unframework.dev/compiler";
7
7
  import { existsSync, readFileSync } from "node:fs";
8
8
  import { readFile } from "node:fs/promises";
9
9
  import { formatDiagnostic, formatDiagnostics } from "@unframework.dev/diagnostics";
@@ -85,7 +85,8 @@ const factory = (options = {}, meta) => {
85
85
  let extension;
86
86
  let joins;
87
87
  let subRequest;
88
- const selectTarget = (selected) => {
88
+ const selectTarget = (selector) => {
89
+ const selected = typeof selector === "string" && isTargetSelector(selector) ? targetName(selector) : selector;
89
90
  target = resolveTarget(selected);
90
91
  suffix = idSuffix(selected, options.extension);
91
92
  composableSuffix = composableIdSuffix(selected);
@@ -473,7 +474,7 @@ const factory = (options = {}, meta) => {
473
474
  compiled.set(id, assembly.code);
474
475
  if (verdict === void 0) failed.delete(id);
475
476
  else {
476
- const names = (result.ir?.composables ?? []).map(({ name }) => name);
477
+ const names = [...result.ir?.composables ?? [], ...(result.ir?.directives ?? []).filter((directive) => directive.exported)].map(({ name }) => name);
477
478
  failed.set(id, {
478
479
  message: verdict,
479
480
  exports: names
@@ -757,7 +758,7 @@ const factory = (options = {}, meta) => {
757
758
  resolveBare = import("vite").then(({ createIdResolver }) => createIdResolver(config));
758
759
  const file = config.configFile ? filenameOf(config.configFile) : "inline Vite configuration";
759
760
  if (options.target === void 0) {
760
- const detected = detectTarget(config.plugins, file);
761
+ const detected = detectTarget(config.plugins, file, config.root);
761
762
  if ("error" in detected) this.error(detected.error);
762
763
  else selectTarget(detected.target);
763
764
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unframework.dev/unplugin",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "The Unframework bundler plugin: imports of .uf.tsx files compile to the selected framework, and that framework's own plugin finishes the job.",
5
5
  "keywords": [
6
6
  "astro",
@@ -79,22 +79,22 @@
79
79
  "access": "public"
80
80
  },
81
81
  "dependencies": {
82
- "@unframework.dev/codegen": "0.1.2",
83
- "@unframework.dev/compiler": "0.2.2",
84
- "@unframework.dev/diagnostics": "0.1.1",
82
+ "@unframework.dev/codegen": "0.2.0",
83
+ "@unframework.dev/compiler": "0.3.0",
84
+ "@unframework.dev/diagnostics": "0.3.0",
85
85
  "@unframework.dev/parser": "0.1.1",
86
86
  "magic-string": "^1.4.2",
87
87
  "unplugin": "^3.4.0"
88
88
  },
89
89
  "devDependencies": {
90
- "@qwik.dev/core": "2.0.0-beta.47",
90
+ "@qwik.dev/core": "2.0.0-rc.5",
91
91
  "@types/node": "^24.19.0",
92
- "@unframework.dev/target-angular": "0.1.2",
93
- "@unframework.dev/target-qwik": "0.1.2",
94
- "@unframework.dev/target-react": "0.1.2",
95
- "@unframework.dev/target-solid": "0.1.2",
96
- "@unframework.dev/target-svelte": "0.1.2",
97
- "@unframework.dev/target-vue": "0.1.2",
92
+ "@unframework.dev/target-angular": "0.2.0",
93
+ "@unframework.dev/target-qwik": "0.2.0",
94
+ "@unframework.dev/target-react": "0.2.0",
95
+ "@unframework.dev/target-solid": "0.2.0",
96
+ "@unframework.dev/target-svelte": "0.2.0",
97
+ "@unframework.dev/target-vue": "0.2.0",
98
98
  "@uxfront/typescript-config": "^0.1.0",
99
99
  "astro": "7.3.5",
100
100
  "react": "19.3.0",