@unframework.dev/compiler 0.2.3 → 0.3.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
@@ -60,6 +60,11 @@ relative to its root, and packages as `pkg:<name>`, a package that is not instal
60
60
  sorted (ADR-0071). It also lists each shared `.ts` module the resolver read, and each `.uf.ts`
61
61
  module whose composables the source imports, one that is missing included, named as `filename` is.
62
62
 
63
+ An oracle that answers `checkDirectiveValues`, as the tsgo adapter does, is asked once per module
64
+ that applies a directive with a value (`directiveValueQueries`), and a value it says is of another
65
+ type than the directive takes is UF6007 (ADR-0109). The files its answer read join
66
+ `CompileResult.dependencies`, and the project graph keeps the answer in the module's key.
67
+
63
68
  **Source maps** (ADR-0074). With `sourceMap: true`, each output file has a `map`: version 3, whose
64
69
  `sources` name the source relative to the file and whose `sourcesContent` holds it. `compile()`
65
70
  anchors each file after the `output` hooks, from its own component's code, and carries the map
@@ -107,6 +112,10 @@ reports UF1205 at the import that closes a cycle, which withholds the module fro
107
112
  an analyser error does. An injection key, a type or a shared module imported back closes no cycle
108
113
  (UF2033's context pattern), and a component that imports itself is UF1203's.
109
114
 
115
+ **Directives** (ADR-0099). A `.uf.ts` module may export directives beside its composables, and
116
+ its API lists them by name. `compile()` emits each exported directive with its target's
117
+ `emitDirective`, as it emits a composable, and reports UF1002 for a target without one.
118
+
110
119
  **Composables** (ADR-0069). The resolver gives a `.uf.ts` module's API too: its `composables`,
111
120
  each with its parameters' kinds and its members' kinds and flags, which a caller's `Use` item is
112
121
  lowered by, so a caller's output never depends on a composable's body. `compile()` also takes a
@@ -166,18 +175,18 @@ a Standard Schema may be. `origin` is what `loadConfig` returned: `directory`, w
166
175
  resolve against, and `file`, which diagnostics name. Each one has a default: the working directory,
167
176
  and `unframework.config.ts`.
168
177
 
169
- | Field | Default | Checked |
170
- | --------------------- | ----------- | ---------------------------------------------------------------- |
171
- | `targets` | all seven | a list of at least one built-in name, none repeated |
172
- | `srcDir` | `src` | a path that isn't empty, made absolute |
173
- | `outDir` | `dist` | a path that isn't empty, made absolute |
174
- | `targetOptions` | `{}` | each key a built-in name, each value through its target's schema |
175
- | `typeOracle` | `syntactic` | `syntactic` or `tsgo` |
176
- | `strict` | `false` | a boolean |
177
- | `package.targets` | left out | as `targets`, and each name also in `targets` |
178
- | `package.resolveFrom` | left out | a path, or a path per built-in name, each made absolute |
179
- | `vite` | left out | a function, kept as it is (ADR-0104) |
180
- | `liveFonts` | `[]` | a list of font family names that aren't empty (ADR-0105) |
178
+ | Field | Default | Checked |
179
+ | --------------------- | ----------- | ------------------------------------------------------------------------------- |
180
+ | `targets` | all seven | a list of at least one built-in selector, none repeated (`solid@2` is `solid2`) |
181
+ | `srcDir` | `src` | a path that isn't empty, made absolute |
182
+ | `outDir` | `dist` | a path that isn't empty, made absolute |
183
+ | `targetOptions` | `{}` | each key a built-in name, each value through its target's schema |
184
+ | `typeOracle` | `syntactic` | `syntactic` or `tsgo` |
185
+ | `strict` | `false` | a boolean |
186
+ | `package.targets` | left out | as `targets`, and each name also in `targets` |
187
+ | `package.resolveFrom` | left out | a path, or a path per built-in name, each made absolute |
188
+ | `vite` | left out | a function, kept as it is (ADR-0104) |
189
+ | `liveFonts` | `[]` | a list of font family names that aren't empty (ADR-0105) |
181
190
 
182
191
  A field of the wrong shape, or one the config doesn't have, is UF7002. A name that isn't a built-in
183
192
  target is UF7003, with a did-you-mean where one is close. Options a target's schema rejects are
package/dist/compile.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TargetName } from "./config-types.js";
1
+ import { TargetSelector } from "./config-types.js";
2
2
  import { Resolver } from "./resolver.js";
3
3
  import "./targets.js";
4
4
  import { OutputFile, Target } from "@unframework.dev/codegen";
@@ -34,8 +34,11 @@ export interface CompileOptions {
34
34
  * with forward slashes for output that does not depend on the machine.
35
35
  */
36
36
  filename: string;
37
- /** The targets to emit, by name or as target objects. */
38
- targets: readonly (TargetName | Target)[];
37
+ /**
38
+ * The targets to emit, by selector (`solid@2`, ADR-0102) or as target objects. Outputs are keyed
39
+ * by each target's id, so `solid@2`'s are under `solid2`.
40
+ */
41
+ targets: readonly (TargetSelector | Target)[];
39
42
  /** Formats the output with oxfmt. Defaults to `true`; the dev server may skip it. */
40
43
  format?: boolean;
41
44
  /**
package/dist/compile.js CHANGED
@@ -2,7 +2,7 @@ import { checkCapabilities } from "./capabilities.js";
2
2
  import { isSpanIn, pluginIrProblems } from "./plugin-ir.js";
3
3
  import { componentImportNames, directoryOf, joinPath, relativePath, stylesheetSource, takesComponent } from "./resolver.js";
4
4
  import { resolveTarget } from "./targets.js";
5
- import { analyze, componentImports, shapeQueries, sharedModuleImports, stylesheetImports } from "@unframework.dev/analyzer";
5
+ import { analyze, componentImports, directiveValueQueries, shapeQueries, sharedModuleImports, stylesheetImports } from "@unframework.dev/analyzer";
6
6
  import { anchorOutput, formatOutput, identityMapped, kebabCase, remapFormatted, scopeStylesheet } from "@unframework.dev/codegen";
7
7
  import { createDiagnostic, sortDiagnostics } from "@unframework.dev/diagnostics";
8
8
  import { checkInvariants, validateModule } from "@unframework.dev/ir";
@@ -59,6 +59,18 @@ async function compile(source, options) {
59
59
  const type = source.slice(query.span.start, query.span.end);
60
60
  diagnostics.push(internal(file, error, `The type oracle failed on \`${type}\``));
61
61
  }
62
+ const directiveValues = /* @__PURE__ */ new Map();
63
+ const valueQueries = oracle.checkDirectiveValues ? directiveValueQueries(parsed) : [];
64
+ if (valueQueries.length) try {
65
+ const answer = await oracle.checkDirectiveValues(file, source, valueQueries);
66
+ valueQueries.forEach((query, index) => {
67
+ const check = answer.checks[index];
68
+ if (check) directiveValues.set(`${query.value.start}:${query.value.end}`, check);
69
+ });
70
+ for (const dependency of answer.dependencies) dependencies.add(dependency);
71
+ } catch (error) {
72
+ diagnostics.push(internal(file, error, "The type oracle failed on the directives' values"));
73
+ }
62
74
  const imports = /* @__PURE__ */ new Map();
63
75
  for (const specifier of options.resolve ? componentImports(parsed) : []) {
64
76
  const composable = COMPOSABLE_SPECIFIER.test(specifier) ? joinPath(directoryOf(file), specifier) : void 0;
@@ -137,6 +149,7 @@ async function compile(source, options) {
137
149
  modules,
138
150
  stylesheets,
139
151
  shapes: (span) => shapes.get(`${span.start}:${span.end}`),
152
+ ...directiveValues.size ? { directiveValues: (span) => directiveValues.get(`${span.start}:${span.end}`) } : {},
140
153
  ...options.passThrough ? { passThrough: options.passThrough } : {}
141
154
  });
142
155
  diagnostics.push(...analysis.diagnostics);
@@ -327,7 +340,8 @@ async function emitTarget(target, module, source, options, diagnostics, sheets,
327
340
  const own = {
328
341
  ...module,
329
342
  components: [component],
330
- composables: []
343
+ composables: [],
344
+ directives: (module.directives ?? []).filter((directive) => !directive.exported)
331
345
  };
332
346
  files = files.map((output) => anchorOutput(output, own, source));
333
347
  }
@@ -355,27 +369,45 @@ async function emitTarget(target, module, source, options, diagnostics, sheets,
355
369
  written.push(output);
356
370
  }
357
371
  }
358
- for (const composable of module.composables ?? []) {
359
- if (!target.emitComposable) {
372
+ const emitComposable = target.emitComposable?.bind(target);
373
+ const emitDirective = target.emitDirective?.bind(target);
374
+ const modules = [...(module.composables ?? []).map((composable) => ({
375
+ name: composable.name,
376
+ span: composable.span,
377
+ what: "composables: it has no `emitComposable`",
378
+ emit: emitComposable && ((context) => emitComposable(composable, context)),
379
+ own: { composables: [composable] }
380
+ })), ...(module.directives ?? []).filter((directive) => directive.exported).map((directive) => ({
381
+ name: directive.name,
382
+ span: directive.span,
383
+ what: "directives: it has no `emitDirective`",
384
+ emit: emitDirective && ((context) => emitDirective(directive, context)),
385
+ own: {
386
+ composables: [],
387
+ directives: [directive]
388
+ }
389
+ }))].toSorted((a, b) => a.span.start - b.span.start);
390
+ for (const each of modules) {
391
+ if (!each.emit) {
360
392
  diagnostics.push(createDiagnostic("UF1002", {
361
393
  file,
362
- span: composable.span,
363
- message: `The ${target.name} target does not emit composables: it has no \`emitComposable\`.`,
394
+ span: each.span,
395
+ message: `The ${target.name} target does not emit ${each.what}.`,
364
396
  target: target.name
365
397
  }));
366
398
  continue;
367
399
  }
368
400
  let files;
369
401
  try {
370
- const emitted = readFiles(target.emitComposable(composable, {
402
+ const emitted = readFiles(each.emit({
371
403
  module,
372
404
  options: options.targetOptions?.[target.name],
373
405
  report: (diagnostic) => diagnostics.push(reported(diagnostic, source, file, target.name))
374
406
  }));
375
- if ("problem" in emitted) throw new TypeError(`emitComposable returned ${emitted.problem}`);
407
+ if ("problem" in emitted) throw new TypeError(`emitting ${each.name} returned ${emitted.problem}`);
376
408
  files = emitted.files;
377
409
  } catch (error) {
378
- const what = `The ${target.name} target failed on ${composable.name}`;
410
+ const what = `The ${target.name} target failed on ${each.name}`;
379
411
  diagnostics.push(internal(file, error, what, target.name));
380
412
  continue;
381
413
  }
@@ -383,7 +415,7 @@ async function emitTarget(target, module, source, options, diagnostics, sheets,
383
415
  const own = {
384
416
  ...module,
385
417
  components: [],
386
- composables: [composable]
418
+ ...each.own
387
419
  };
388
420
  files = files.map((output) => anchorOutput(output, own, source));
389
421
  }
@@ -401,12 +433,12 @@ async function emitTarget(target, module, source, options, diagnostics, sheets,
401
433
  const key = output.path.toLowerCase();
402
434
  const owner = owners.get(key);
403
435
  if (owner) {
404
- diagnostics.push(internal(file, `${owner.path} (${owner.component}) and ${output.path} (${composable.name}) are one file on a case-insensitive file system`, `The ${target.name} target wrote two files at one path`, target.name));
436
+ diagnostics.push(internal(file, `${owner.path} (${owner.component}) and ${output.path} (${each.name}) are one file on a case-insensitive file system`, `The ${target.name} target wrote two files at one path`, target.name));
405
437
  continue;
406
438
  }
407
439
  owners.set(key, {
408
440
  path: output.path,
409
- component: composable.name
441
+ component: each.name
410
442
  });
411
443
  written.push(output);
412
444
  }
@@ -1,8 +1,16 @@
1
- /** The names of the built-in targets. */
2
- export type TargetName = "react" | "vue" | "svelte" | "solid" | "angular" | "qwik" | "astro";
1
+ /**
2
+ * The ids of the built-in targets. An id names a target wherever it becomes a path, a package or a
3
+ * project: `solid2` is Solid 2, which a configuration selects as `solid@2` (ADR-0102).
4
+ */
5
+ export type TargetName = "react" | "vue" | "svelte" | "solid" | "solid2" | "angular" | "qwik" | "astro";
6
+ /**
7
+ * What a configuration, the CLI and `compile()` accept: a target's id, or its framework and major
8
+ * (ADR-0102). `solid` and `solid@1` select Solid 1, and `solid@2` selects Solid 2.
9
+ */
10
+ export type TargetSelector = TargetName | "solid@1" | "solid@2";
3
11
  /** The targets packaging covers, and where each packager resolves from (ADR-0076). */
4
12
  export interface PackageConfig {
5
- targets?: readonly TargetName[];
13
+ targets?: readonly TargetSelector[];
6
14
  /** One directory, or one per target. */
7
15
  resolveFrom?: string | Partial<Record<TargetName, string>>;
8
16
  }
@@ -32,8 +40,11 @@ export type ProjectViteConfig = {
32
40
  } & object;
33
41
  /** The configuration as a project writes it, with `defineConfig` from `@uxfront/unframework/config`. */
34
42
  export interface UnframeworkConfig {
35
- /** Defaults to all seven targets. */
36
- targets?: readonly TargetName[];
43
+ /**
44
+ * Defaults to the seven targets of `DEFAULT_TARGETS`. `solid@2` is opt-in, since a project that
45
+ * selects both Solid majors needs two Solid installs (ADR-0102).
46
+ */
47
+ targets?: readonly TargetSelector[];
37
48
  /** Defaults to `src`, relative to the config's directory. */
38
49
  srcDir?: string;
39
50
  /** Defaults to `dist`, relative to the config's directory. */
package/dist/config.d.ts CHANGED
@@ -8,12 +8,16 @@ export interface ResolvedConfig {
8
8
  targetOptions: Partial<Record<TargetName, unknown>>;
9
9
  typeOracle: "syntactic" | "tsgo";
10
10
  strict: boolean;
11
- package?: PackageConfig;
11
+ package?: ResolvedPackageConfig;
12
12
  /** The project's Vite config, as a function each server calls (ADR-0104). */
13
13
  vite?: UnframeworkConfig["vite"];
14
14
  /** The font families that may draw text when pixels compare live, besides Inter (ADR-0105). */
15
15
  liveFonts: readonly string[];
16
16
  }
17
+ /** The packaging config with its selectors resolved to target ids (ADR-0102). */
18
+ export interface ResolvedPackageConfig extends Omit<PackageConfig, "targets"> {
19
+ targets?: readonly TargetName[];
20
+ }
17
21
  /** Where a configuration came from: what {@link loadConfig} gives {@link resolveConfig}. */
18
22
  export interface ConfigOrigin {
19
23
  /** The directory relative paths resolve against. Defaults to the working directory. */
package/dist/config.js CHANGED
@@ -1,4 +1,4 @@
1
- import { TARGET_NAMES, builtinTargets } from "./targets.js";
1
+ import { DEFAULT_TARGETS, TARGET_NAMES, TARGET_SELECTORS, builtinTargets, isTargetSelector, targetName } from "./targets.js";
2
2
  import { closest } from "@unframework.dev/analyzer";
3
3
  import { createDiagnostic } from "@unframework.dev/diagnostics";
4
4
  import { existsSync } from "node:fs";
@@ -103,7 +103,7 @@ async function checkConfig(raw, directory, report) {
103
103
  return;
104
104
  }
105
105
  checkFields(raw, "", FIELDS, report);
106
- const targets = raw.targets === void 0 ? [...TARGET_NAMES] : targetList(raw.targets, "/targets", report);
106
+ const targets = raw.targets === void 0 ? [...DEFAULT_TARGETS] : targetList(raw.targets, "/targets", report);
107
107
  const srcDir = pathField(raw.srcDir === void 0 ? "src" : raw.srcDir, "/srcDir", directory, report);
108
108
  const outDir = pathField(raw.outDir === void 0 ? "dist" : raw.outDir, "/outDir", directory, report);
109
109
  const targetOptions = await resolveTargetOptions(raw.targetOptions, report);
@@ -180,9 +180,10 @@ function checkFields(record, pointer, fields, report) {
180
180
  function isTargetName(name) {
181
181
  return Object.hasOwn(builtinTargets, name);
182
182
  }
183
- function reportUnknownTarget(name, pointer, report) {
184
- const meant = didYouMean(name, TARGET_NAMES);
185
- report("UF7003", pointer, `names the unknown target ${JSON.stringify(name)}.${meant || ` The built-in targets are ${TARGET_NAMES.join(", ")}.`}`);
183
+ /** `targetOptions` and `resolveFrom` are keyed by id, so the hint lists ids alone there. */
184
+ function reportUnknownTarget(name, pointer, report, names = TARGET_SELECTORS) {
185
+ const meant = didYouMean(name, names);
186
+ report("UF7003", pointer, `names the unknown target ${JSON.stringify(name)}.${meant || ` The built-in targets are ${names.join(", ")}.`}`);
186
187
  }
187
188
  /** A list of targets: `compile()` throws on a repeated one, so it is reported here first. */
188
189
  function targetList(value, pointer, report, within) {
@@ -194,10 +195,14 @@ function targetList(value, pointer, report, within) {
194
195
  for (const [index, item] of value.entries()) {
195
196
  const at = `${pointer}/${index}`;
196
197
  if (typeof item !== "string") report("UF7002", at, "must be a target name.");
197
- else if (!isTargetName(item)) reportUnknownTarget(item, at, report);
198
- else if (seen.includes(item)) report("UF7002", at, `repeats the target "${item}".`);
199
- else if (within && !within.includes(item)) report("UF7002", at, `names the target "${item}", which "/targets" leaves out.`);
200
- else seen.push(item);
198
+ else if (!isTargetSelector(item)) reportUnknownTarget(item, at, report);
199
+ else {
200
+ const name = targetName(item);
201
+ const named = item === name ? `"${name}"` : `"${name}" (${JSON.stringify(item)})`;
202
+ if (seen.includes(name)) report("UF7002", at, `repeats the target ${named}.`);
203
+ else if (within && !within.includes(name)) report("UF7002", at, `names the target ${named}, which "/targets" leaves out.`);
204
+ else seen.push(name);
205
+ }
201
206
  }
202
207
  return seen;
203
208
  }
@@ -218,7 +223,7 @@ async function resolveTargetOptions(value, report) {
218
223
  for (const [name, options] of Object.entries(value)) {
219
224
  const pointer = `/targetOptions${segment(name)}`;
220
225
  if (!isTargetName(name)) {
221
- reportUnknownTarget(name, pointer, report);
226
+ reportUnknownTarget(name, pointer, report, TARGET_NAMES);
222
227
  continue;
223
228
  }
224
229
  if (options === void 0) continue;
@@ -262,7 +267,7 @@ function resolvePackage(value, targets, directory, report) {
262
267
  for (const [name, path] of Object.entries(from)) {
263
268
  const pointer = `/package/resolveFrom${segment(name)}`;
264
269
  if (!isTargetName(name)) {
265
- reportUnknownTarget(name, pointer, report);
270
+ reportUnknownTarget(name, pointer, report, TARGET_NAMES);
266
271
  continue;
267
272
  }
268
273
  if (path === void 0) continue;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { CompileOptions, CompileResult, CompilerPlugin, OutputHookContext, checkPassThrough, compile } from "./compile.js";
2
2
  import { Project, ProjectOptions, ProjectUpdate, createFileResolver, createProject } from "./project.js";
3
3
  import { FileResolverOptions, ResolveRequest, ResolvedModule, ResolvedStylesheet, Resolver } from "./resolver.js";
4
- import { ConfigOrigin, LoadedConfig, ResolveConfigResult, ResolvedConfig, loadConfig, resolveConfig } from "./config.js";
5
- import { PackageConfig, ProjectViteConfig, TargetName, UnframeworkConfig, ViteContext, ViteMode, VitePluginOption } from "./config-types.js";
6
- import { TARGET_NAMES, builtinTargets, resolveTarget } from "./targets.js";
4
+ import { ConfigOrigin, LoadedConfig, ResolveConfigResult, ResolvedConfig, ResolvedPackageConfig, loadConfig, resolveConfig } from "./config.js";
5
+ import { PackageConfig, ProjectViteConfig, TargetName, TargetSelector, UnframeworkConfig, ViteContext, ViteMode, VitePluginOption } from "./config-types.js";
6
+ import { DEFAULT_TARGETS, TARGET_NAMES, TARGET_SELECTORS, builtinTargets, isTargetSelector, resolveTarget, targetName } from "./targets.js";
7
7
  import { checkCapabilities } from "./capabilities.js";
8
8
  import { DEFAULT_PASS_THROUGH } from "@unframework.dev/analyzer";
9
9
  import { OutputFile, Target, requiredCapabilities } from "@unframework.dev/codegen";
10
10
  import { Diagnostic } from "@unframework.dev/diagnostics";
11
11
  import { UfModule } from "@unframework.dev/ir";
12
12
  import { SyntacticOracleOptions, TypeOracle, createSyntacticOracle } from "@unframework.dev/type-oracle";
13
- export { type CompileOptions, type CompileResult, type CompilerPlugin, type ConfigOrigin, DEFAULT_PASS_THROUGH, type Diagnostic, type FileResolverOptions, type LoadedConfig, type OutputFile, type OutputHookContext, type PackageConfig, type Project, type ProjectOptions, type ProjectUpdate, type ProjectViteConfig, type ResolveConfigResult, type ResolveRequest, type ResolvedConfig, type ResolvedModule, type ResolvedStylesheet, type Resolver, type SyntacticOracleOptions, TARGET_NAMES, type Target, type TargetName, type TypeOracle, type UfModule, type UnframeworkConfig, type ViteContext, type ViteMode, type VitePluginOption, builtinTargets, checkCapabilities, checkPassThrough, compile, createFileResolver, createProject, createSyntacticOracle, loadConfig, requiredCapabilities, resolveConfig, resolveTarget };
13
+ export { type CompileOptions, type CompileResult, type CompilerPlugin, type ConfigOrigin, DEFAULT_PASS_THROUGH, DEFAULT_TARGETS, type Diagnostic, type FileResolverOptions, type LoadedConfig, type OutputFile, type OutputHookContext, type PackageConfig, type Project, type ProjectOptions, type ProjectUpdate, type ProjectViteConfig, type ResolveConfigResult, type ResolveRequest, type ResolvedConfig, type ResolvedModule, type ResolvedPackageConfig, type ResolvedStylesheet, type Resolver, type SyntacticOracleOptions, TARGET_NAMES, TARGET_SELECTORS, type Target, type TargetName, type TargetSelector, type TypeOracle, type UfModule, type UnframeworkConfig, type ViteContext, type ViteMode, type VitePluginOption, builtinTargets, checkCapabilities, checkPassThrough, compile, createFileResolver, createProject, createSyntacticOracle, isTargetSelector, loadConfig, requiredCapabilities, resolveConfig, resolveTarget, targetName };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { checkPassThrough, compile } from "./compile.js";
2
2
  import { createFileResolver, createProject } from "./project.js";
3
3
  import { loadConfig, resolveConfig } from "./config.js";
4
- import { TARGET_NAMES, builtinTargets, resolveTarget } from "./targets.js";
4
+ import { DEFAULT_TARGETS, TARGET_NAMES, TARGET_SELECTORS, builtinTargets, isTargetSelector, resolveTarget, targetName } from "./targets.js";
5
5
  import { checkCapabilities } from "./capabilities.js";
6
6
  import { DEFAULT_PASS_THROUGH } from "@unframework.dev/analyzer";
7
7
  import { requiredCapabilities } from "@unframework.dev/codegen";
8
8
  import { createSyntacticOracle } from "@unframework.dev/type-oracle";
9
- export { DEFAULT_PASS_THROUGH, TARGET_NAMES, builtinTargets, checkCapabilities, checkPassThrough, compile, createFileResolver, createProject, createSyntacticOracle, loadConfig, requiredCapabilities, resolveConfig, resolveTarget };
9
+ export { DEFAULT_PASS_THROUGH, DEFAULT_TARGETS, TARGET_NAMES, TARGET_SELECTORS, builtinTargets, checkCapabilities, checkPassThrough, compile, createFileResolver, createProject, createSyntacticOracle, isTargetSelector, loadConfig, requiredCapabilities, resolveConfig, resolveTarget, targetName };
package/dist/project.js CHANGED
@@ -223,6 +223,14 @@ function createProject(options) {
223
223
  edges: shape.dependencies
224
224
  };
225
225
  }
226
+ if (call.kind === "directive-values") {
227
+ const answer = await typeOracle.checkDirectiveValues(call.file, call.source, call.queries);
228
+ return {
229
+ value: answer,
230
+ held: answer,
231
+ edges: answer.dependencies
232
+ };
233
+ }
226
234
  const { request } = call;
227
235
  const path = joinPath(directoryOf(request.importer), request.specifier);
228
236
  if (call.kind === "api") {
@@ -336,6 +344,12 @@ function createProject(options) {
336
344
  kind: "shape",
337
345
  query
338
346
  }),
347
+ ...typeOracle.checkDirectiveValues ? { checkDirectiveValues: (file, source, queries) => record({
348
+ kind: "directive-values",
349
+ file,
350
+ source,
351
+ queries
352
+ }) } : {},
339
353
  printType: (query) => typeOracle.printType(query),
340
354
  update: (changes) => typeOracle.update(changes),
341
355
  dispose: () => typeOracle.dispose()
@@ -449,10 +463,10 @@ function createFileResolver(options) {
449
463
  /**
450
464
  * The file a question named, so a question that threw is still an edge: a fix to that file
451
465
  * recompiles the module, whose UF9001 would otherwise stay until its own source changed. A shape
452
- * query names the module's own file, which is no edge.
466
+ * query, or a check of the directives' values, names the module's own file, which is no edge.
453
467
  */
454
468
  function namedFile(call) {
455
- if (call.kind === "shape") return void 0;
469
+ if (call.kind === "shape" || call.kind === "directive-values") return void 0;
456
470
  return call.kind === "module" ? modulePath(call.request) : joinPath(directoryOf(call.request.importer), call.request.specifier);
457
471
  }
458
472
  /** A SHA-256 of a text, in hex. */
package/dist/targets.d.ts CHANGED
@@ -1,9 +1,20 @@
1
- import { TargetName } from "./config-types.js";
1
+ import { TargetName, TargetSelector } from "./config-types.js";
2
2
  import { Target } from "@unframework.dev/codegen";
3
3
  /** The built-in targets, in the order the docs and reports list them. */
4
4
  export declare const TARGET_NAMES: readonly TargetName[];
5
+ /**
6
+ * The targets a configuration without `targets` compiles to: every built-in but `solid2`, which
7
+ * is opt-in, since a project that selects both Solid majors needs two Solid installs (ADR-0102).
8
+ */
9
+ export declare const DEFAULT_TARGETS: readonly TargetName[];
10
+ /** Every selector a configuration or the CLI accepts: the ids, then the versioned forms. */
11
+ export declare const TARGET_SELECTORS: readonly TargetSelector[];
12
+ /** Whether a string selects a built-in target. Own names only: `toString` is not a target. */
13
+ export declare function isTargetSelector(value: string): value is TargetSelector;
14
+ /** The id of the target a selector selects: `solid@2` is `solid2`, `solid@1` is `solid`. */
15
+ export declare function targetName(selector: TargetSelector): TargetName;
5
16
  /** The built-in targets by name. */
6
17
  export declare const builtinTargets: Readonly<Record<TargetName, Target>>;
7
- /** Resolves a target name, or passes a target object through (third-party targets). */
8
- export declare function resolveTarget(target: TargetName | Target): Target;
9
- export type { TargetName };
18
+ /** Resolves a target selector, or passes a target object through (third-party targets). */
19
+ export declare function resolveTarget(target: TargetSelector | Target): Target;
20
+ export type { TargetName, TargetSelector };
package/dist/targets.js CHANGED
@@ -3,6 +3,7 @@ import astro from "@unframework.dev/target-astro";
3
3
  import qwik from "@unframework.dev/target-qwik";
4
4
  import react from "@unframework.dev/target-react";
5
5
  import solid from "@unframework.dev/target-solid";
6
+ import solid2 from "@unframework.dev/target-solid2";
6
7
  import svelte from "@unframework.dev/target-svelte";
7
8
  import vue from "@unframework.dev/target-vue";
8
9
  // src/targets.ts
@@ -12,24 +13,50 @@ const TARGET_NAMES = [
12
13
  "vue",
13
14
  "svelte",
14
15
  "solid",
16
+ "solid2",
15
17
  "angular",
16
18
  "qwik",
17
19
  "astro"
18
20
  ];
21
+ /**
22
+ * The targets a configuration without `targets` compiles to: every built-in but `solid2`, which
23
+ * is opt-in, since a project that selects both Solid majors needs two Solid installs (ADR-0102).
24
+ */
25
+ const DEFAULT_TARGETS = TARGET_NAMES.filter((name) => name !== "solid2");
26
+ /**
27
+ * The selectors that name a framework's major, and the target each selects (ADR-0102), the newest
28
+ * first: a major that doesn't exist (`solid@3`) is as close to each, and the hint names the first.
29
+ */
30
+ const VERSIONED = {
31
+ "solid@2": "solid2",
32
+ "solid@1": "solid"
33
+ };
34
+ /** Every selector a configuration or the CLI accepts: the ids, then the versioned forms. */
35
+ const TARGET_SELECTORS = [...TARGET_NAMES, ...Object.keys(VERSIONED)];
36
+ /** Whether a string selects a built-in target. Own names only: `toString` is not a target. */
37
+ function isTargetSelector(value) {
38
+ return Object.hasOwn(builtinTargets, value) || Object.hasOwn(VERSIONED, value);
39
+ }
40
+ /** The id of the target a selector selects: `solid@2` is `solid2`, `solid@1` is `solid`. */
41
+ function targetName(selector) {
42
+ return Object.hasOwn(VERSIONED, selector) ? VERSIONED[selector] : selector;
43
+ }
19
44
  /** The built-in targets by name. */
20
45
  const builtinTargets = {
21
46
  react,
22
47
  vue,
23
48
  svelte,
24
49
  solid,
50
+ solid2,
25
51
  angular,
26
52
  qwik,
27
53
  astro
28
54
  };
29
- /** Resolves a target name, or passes a target object through (third-party targets). */
55
+ /** Resolves a target selector, or passes a target object through (third-party targets). */
30
56
  function resolveTarget(target) {
31
57
  if (typeof target !== "string") return target;
32
- if (!Object.hasOwn(builtinTargets, target)) throw new TypeError(`Unknown target "${target}".`);
33
- return builtinTargets[target];
58
+ const name = target;
59
+ if (!isTargetSelector(name)) throw new TypeError(`Unknown target "${name}".`);
60
+ return builtinTargets[targetName(name)];
34
61
  }
35
- export { TARGET_NAMES, builtinTargets, resolveTarget };
62
+ export { DEFAULT_TARGETS, TARGET_NAMES, TARGET_SELECTORS, builtinTargets, isTargetSelector, resolveTarget, targetName };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unframework.dev/compiler",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "The Unframework compiler: compile() turns one .uf.tsx source into native React, Vue, Svelte, Solid, Angular, Qwik and Astro components.",
5
5
  "keywords": [
6
6
  "angular",
@@ -41,19 +41,20 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@unframework.dev/analyzer": "0.1.2",
45
- "@unframework.dev/codegen": "0.1.3",
46
- "@unframework.dev/diagnostics": "0.2.0",
47
- "@unframework.dev/ir": "0.1.1",
44
+ "@unframework.dev/analyzer": "0.2.0",
45
+ "@unframework.dev/codegen": "0.2.0",
46
+ "@unframework.dev/diagnostics": "0.3.0",
47
+ "@unframework.dev/ir": "0.2.0",
48
48
  "@unframework.dev/parser": "0.1.1",
49
- "@unframework.dev/target-angular": "0.1.3",
50
- "@unframework.dev/target-astro": "0.1.3",
51
- "@unframework.dev/target-qwik": "0.1.3",
52
- "@unframework.dev/target-react": "0.1.3",
53
- "@unframework.dev/target-solid": "0.1.3",
54
- "@unframework.dev/target-svelte": "0.1.3",
55
- "@unframework.dev/target-vue": "0.1.3",
56
- "@unframework.dev/type-oracle": "0.1.1"
49
+ "@unframework.dev/target-angular": "0.2.0",
50
+ "@unframework.dev/target-astro": "0.2.0",
51
+ "@unframework.dev/target-qwik": "0.2.0",
52
+ "@unframework.dev/target-react": "0.2.0",
53
+ "@unframework.dev/target-solid": "0.2.0",
54
+ "@unframework.dev/target-solid2": "0.1.0",
55
+ "@unframework.dev/target-svelte": "0.2.0",
56
+ "@unframework.dev/target-vue": "0.2.0",
57
+ "@unframework.dev/type-oracle": "0.2.0"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@types/node": "^24.19.0",