@wcstack/lint 4.31.0 → 4.32.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.ja.md CHANGED
@@ -94,7 +94,7 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
94
94
  }
95
95
  ```
96
96
 
97
- - **発見**: HTML ファイルから上へ辿って最も近い `wcstack.manifest.json` が自動で使われます — コマンドラインに渡す必要はありません。`application` artifact を含む `*.manifest.json` を引数に渡した場合は、その実行全体で発見を置き換えます。VS Code 拡張も同じファイルを発見するので IDE と CLI の結果は一致します。
97
+ - **発見**: HTML ファイルから上へ辿って最も近い `wcstack.manifest.json` が自動で使われます — コマンドラインに渡す必要はありません。`application` artifact を含む `*.manifest.json` を引数に渡した場合は、その実行全体で発見を置き換えます。そのうち 2 つが両方 `stateSchema` を宣言すると `wcs/manifest-state-collision`(error)で、どちらも使われません —— ただし 4.32 から、それぞれが違う state のファイル(`stateSource`、下)を名指すときは衝突せず、各ページには、ルートの `<wcs-state src>` が読むファイルの schema が当たります。生成した schema を持つアプリ 2 つを 1 回の実行で検査できます。VS Code 拡張も同じファイルを発見するので IDE と CLI の結果は一致します。
98
98
  - **schema を当てるページ**(4.26 から): schema を作った state のファイルを記した manifest — `wcstack.application.stateSource`、manifest からの相対で、`wcs-schema emit` が書きます — は、そのファイルを root の `<wcs-state src>` で読むページだけの契約です(同じパスの `.js` と `.ts`、`.mjs` と `.mts` は同じファイル)。state がインラインのページや別のファイルのページは、発見した manifest でも引数に渡した manifest でも、manifest が無いものとして検査します。4.25 までは、アプリの schema をその下のすべてのページに当てていたので、アプリの隣で自前のインラインの state を持つページの正しいパスが `wcs/path-nonexistent` の error になっていました。`stateSource` の無い manifest(手書き・それより前の `wcs-schema` が作ったもの)は、これまでどおりすべてのページに当てます。
99
99
  - **効果**: `stateSchema` を宣言すると、schema 上に確定的に存在しないバインドパスは `wcs/path-nonexistent`(**error**・exit `1`)、`for:` に非配列は `wcs/path-type-mismatch`(**error**)になります。schema が開いたままの箇所(素の `{}`)は schema が無いときと同じに検査し(4.31 から。以前は沈黙した)、インラインスクリプトのメソッド / getter / `$listKeys` は引き続き存在扱いです。`stateSchema` が無ければ従来どおりです。
100
100
  - **契約が要るとき**: validator が全体を読めない state は、契約が無いとパスをまったく検査できません。よくあるのはトップレベルの spread です — `export default { ...defaults(), get total() { … } }` は静的には見えないキーを持ち込むので、その state のパスは検査しません。4.4 から、spread の上で 1 回だけそう言います(`wcs/path-dynamic-unknown`、info)。`stateSchema` があれば束縛を —— 4.4 から getter の中で読むパス(`wcs/read-path-missing`)も —— それで検査します。読めない `<wcs-state src>` — / から始まるパス・URL・無いファイル — の state も検査できません。4.7 から、それを属性の上で 1 回だけ言います(`wcs/state-src-unread`、info)。4.6 までは何も言いませんでした。`src` はページからの相対パスで読むので、ファイルはサーバーと同じ並びに置き、/ から始まるパスには 4.10 から `--root=<dir>` を渡してください。
package/README.md CHANGED
@@ -94,7 +94,7 @@ Without a contract, a path the validator cannot resolve is only a **warning** (`
94
94
  }
95
95
  ```
96
96
 
97
- - **Discovery**: the nearest `wcstack.manifest.json` walking up from the HTML file is used automatically — nothing to pass on the command line. Passing `*.manifest.json` arguments that contain an `application` artifact replaces discovery for the whole run. The VS Code extension discovers the same file, so IDE and CLI agree.
97
+ - **Discovery**: the nearest `wcstack.manifest.json` walking up from the HTML file is used automatically — nothing to pass on the command line. Passing `*.manifest.json` arguments that contain an `application` artifact replaces discovery for the whole run. Two of them that both declare a `stateSchema` are a `wcs/manifest-state-collision` error, and neither is used — except, since 4.32, when each names a different state file (`stateSource`, below): then each page gets the schema of the file its root `<wcs-state src>` loads, and two apps with a generated schema are checked in one run. The VS Code extension discovers the same file, so IDE and CLI agree.
98
98
  - **Which pages a schema is for** (since 4.26): a manifest that names the state file its schema was generated from — `wcstack.application.stateSource`, relative to the manifest, which `wcs-schema emit` writes — is the contract only of a page whose root `<wcs-state src>` loads that file (`.js` and `.ts`, `.mjs` and `.mts` of one path being one file). A page whose state is inline, or another file, is checked as if there were no manifest, whether the manifest was discovered or passed on the command line. Up to 4.25 the app's schema was applied to every page under it, so a page with its own inline state beside the app got `wcs/path-nonexistent` errors for its correct paths. A manifest without `stateSource` (hand-written, or generated by an earlier `wcs-schema`) applies to every page as before.
99
99
  - **Effect**: when a `stateSchema` is declared, a bound path that the schema definitely lacks is `wcs/path-nonexistent` (**error**, exit `1`); `for:` on a non-array is `wcs/path-type-mismatch` (**error**). Paths the schema leaves open (a bare `{}`) are checked as they are without a schema — since 4.31; they were silent — and methods / getters / `$listKeys` from the inline script still count as existing. Without a `stateSchema`, behavior is unchanged.
100
100
  - **When a contract is needed**: a state the validator cannot read in full needs one for its paths to be checked at all. A top-level spread is the common case — `export default { ...defaults(), get total() { … } }` brings in keys no static reader sees, so the validator checks no path of that state, and since 4.4 it says so once, at the spread (`wcs/path-dynamic-unknown`, info). With a `stateSchema` the bindings — and, since 4.4, the paths the getters read (`wcs/read-path-missing`) — are checked against it. A `<wcs-state src>` it cannot read — a path from `/`, a URL, a file that is not there — leaves that state unchecked as well; since 4.7 it says so once, at the attribute (`wcs/state-src-unread`, info), where up to 4.6 it said nothing. It reads a `src` relative to the page: keep the files laid out as on the server, and since 4.10 pass `--root=<dir>` for a path from `/`.
package/dist/cli.cjs CHANGED
@@ -2687,7 +2687,7 @@ function getWcsManifest() {
2687
2687
  }
2688
2688
 
2689
2689
  // ../state/package.json
2690
- var version = "4.31.0";
2690
+ var version = "4.32.0";
2691
2691
 
2692
2692
  // src/service/wcsManifest.ts
2693
2693
  var ENGINE_VERSION = version;
@@ -22803,6 +22803,30 @@ function parseJsonWithSpans(text3) {
22803
22803
  }
22804
22804
  }
22805
22805
 
22806
+ // src/core/sidecar/statePaths.ts
22807
+ function segmentsOf(path) {
22808
+ const norm = path.replace(/\\/g, "/");
22809
+ const absolute = norm.startsWith("/") || /^[A-Za-z]:\//.test(norm);
22810
+ const segments = [];
22811
+ for (const segment of norm.split("/")) {
22812
+ if (segment === "" || segment === ".") continue;
22813
+ if (segment === ".." && segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
22814
+ else segments.push(/^[A-Za-z]:$/.test(segment) ? segment.toUpperCase() : segment);
22815
+ }
22816
+ return { absolute, segments };
22817
+ }
22818
+ function sameStateFile(a, b) {
22819
+ const canonical = (p) => p.replace(/\.ts$/, ".js").replace(/\.mts$/, ".mjs");
22820
+ return canonical(a) === canonical(b);
22821
+ }
22822
+ function differentStateFiles(manifestA, stateSourceA, manifestB, stateSourceB) {
22823
+ const a = segmentsOf(manifestA);
22824
+ const b = segmentsOf(manifestB);
22825
+ if (a.absolute !== b.absolute) return false;
22826
+ const file = (manifest2, stateSource) => segmentsOf([...manifest2.slice(0, -1), stateSource].join("/")).segments.join("/");
22827
+ return !sameStateFile(file(a.segments, stateSourceA), file(b.segments, stateSourceB));
22828
+ }
22829
+
22806
22830
  // src/core/sidecar/types.ts
22807
22831
  var SUPPORTED_SCHEMA_VERSION = 2;
22808
22832
  var SUPPORTED_NAMESPACE_VERSION = 2;
@@ -22895,9 +22919,8 @@ function resolvePackageContracts(loaded) {
22895
22919
  const collided = /* @__PURE__ */ new Set();
22896
22920
  const firstSource = /* @__PURE__ */ new Map();
22897
22921
  const filterOwner = /* @__PURE__ */ new Map();
22898
- let schemaOwner;
22899
- let schemaWinner;
22900
- let schemaStateSource;
22922
+ const schemaEntries = [];
22923
+ let schemaCollided = false;
22901
22924
  let hasApplicationArtifact = false;
22902
22925
  for (const lm of loaded) {
22903
22926
  if (lm.manifest === null) continue;
@@ -22956,16 +22979,21 @@ function resolvePackageContracts(loaded) {
22956
22979
  if (lm.manifest.kind === "application" && application?.stateSchema !== void 0) {
22957
22980
  const schema = application.stateSchema;
22958
22981
  if (schema !== null && typeof schema === "object" && !Array.isArray(schema)) {
22959
- if (schemaOwner === void 0) {
22960
- schemaOwner = lm.artifact.source;
22961
- schemaWinner = schema;
22962
- schemaStateSource = application.stateSource;
22982
+ const stateSource = typeof application.stateSource === "string" && application.stateSource.trim() !== "" ? application.stateSource.trim() : void 0;
22983
+ const entry = {
22984
+ schema,
22985
+ source: lm.artifact.source,
22986
+ ...stateSource !== void 0 ? { stateSource } : {}
22987
+ };
22988
+ const other = schemaEntries.find((e) => !(e.stateSource !== void 0 && entry.stateSource !== void 0 && differentStateFiles(e.source, e.stateSource, entry.source, entry.stateSource)));
22989
+ if (other === void 0) {
22990
+ schemaEntries.push(entry);
22963
22991
  } else {
22964
- schemaWinner = void 0;
22992
+ schemaCollided = true;
22965
22993
  ctxFor(lm).add(
22966
22994
  WcsDiagnosticCode.ManifestStateCollision,
22967
22995
  pointer("manifestExtensions", "wcstack.application", "stateSchema"),
22968
- `Multiple application artifacts declare a stateSchema (also in "${schemaOwner}"); neither is used.`,
22996
+ `Multiple application artifacts declare a stateSchema (also in "${other.source}"); neither is used.`,
22969
22997
  "error",
22970
22998
  void 0,
22971
22999
  true
@@ -22979,12 +23007,14 @@ function resolvePackageContracts(loaded) {
22979
23007
  const kept = diags.filter((d) => !(d.code === WcsDiagnosticCode.ManifestOverride && d.tag !== void 0 && collided.has(d.tag)));
22980
23008
  if (kept.length > 0) diagnosticsBySource.set(source, kept);
22981
23009
  }
22982
- const stateSource = schemaWinner !== void 0 && typeof schemaStateSource === "string" && schemaStateSource.trim() !== "" ? schemaStateSource.trim() : void 0;
23010
+ const schemas = schemaCollided ? [] : schemaEntries;
23011
+ const single = schemas.length === 1 ? schemas[0] : void 0;
22983
23012
  return {
22984
23013
  tags: winners,
22985
- applicationSchema: schemaWinner,
22986
- ...schemaWinner !== void 0 ? { applicationSchemaSource: schemaOwner } : {},
22987
- ...stateSource !== void 0 ? { applicationStateSource: stateSource } : {},
23014
+ applicationSchema: single?.schema,
23015
+ ...single !== void 0 ? { applicationSchemaSource: single.source } : {},
23016
+ ...single?.stateSource !== void 0 ? { applicationStateSource: single.stateSource } : {},
23017
+ applicationSchemas: schemas,
22988
23018
  hasApplicationArtifact,
22989
23019
  diagnosticsBySource
22990
23020
  };
@@ -23026,17 +23056,6 @@ function applicationStateSourceOf(loaded) {
23026
23056
  const stateSource = manifest2.manifestExtensions?.["wcstack.application"]?.stateSource;
23027
23057
  return typeof stateSource === "string" && stateSource.trim() !== "" ? stateSource.trim() : void 0;
23028
23058
  }
23029
- function segmentsOf(path) {
23030
- const norm = path.replace(/\\/g, "/");
23031
- const absolute = norm.startsWith("/") || /^[A-Za-z]:\//.test(norm);
23032
- const segments = [];
23033
- for (const segment of norm.split("/")) {
23034
- if (segment === "" || segment === ".") continue;
23035
- if (segment === ".." && segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
23036
- else segments.push(/^[A-Za-z]:$/.test(segment) ? segment.toUpperCase() : segment);
23037
- }
23038
- return { absolute, segments };
23039
- }
23040
23059
  function stateSourceFromPage(pageSource, manifestSource, stateSource) {
23041
23060
  const page = segmentsOf(pageSource);
23042
23061
  const manifest2 = segmentsOf(manifestSource);
@@ -23047,10 +23066,6 @@ function stateSourceFromPage(pageSource, manifestSource, stateSource) {
23047
23066
  while (common < dir.length && common < target.length && dir[common] === target[common] && dir[common] !== "..") common++;
23048
23067
  return [...dir.slice(common).map(() => ".."), ...target.slice(common)].join("/");
23049
23068
  }
23050
- function sameStateFile(a, b) {
23051
- const canonical = (p) => p.replace(/\.ts$/, ".js").replace(/\.mts$/, ".mjs");
23052
- return canonical(a) === canonical(b);
23053
- }
23054
23069
  function schemaAppliesToPage(html, stateTagName, stateSource, fileReader) {
23055
23070
  const roots = parseWcsStateElements(html, stateTagName).filter((e) => e.mountPath === null && !e.bindComponent && e.srcAttr !== void 0);
23056
23071
  if (roots.length === 0) return false;
@@ -23650,6 +23665,7 @@ function validateManifestSet(input) {
23650
23665
  resolvedSchema: resolved.applicationSchema,
23651
23666
  ...resolved.applicationSchemaSource !== void 0 ? { resolvedSchemaSource: resolved.applicationSchemaSource } : {},
23652
23667
  ...resolved.applicationStateSource !== void 0 ? { resolvedStateSource: resolved.applicationStateSource } : {},
23668
+ resolvedSchemas: resolved.applicationSchemas,
23653
23669
  hasApplicationArtifact: resolved.hasApplicationArtifact
23654
23670
  };
23655
23671
  }
@@ -23666,12 +23682,27 @@ function hasAnythingToCheck(text3, bindAttribute, stateTagName) {
23666
23682
  return text3.includes(bindAttribute) || /<wcs-/i.test(text3) || text3.includes(`<${stateTagName}`) || /@wcstack\/|\bwcstack(?:@[\w.-]+)?\/auto\b/.test(text3);
23667
23683
  }
23668
23684
  var severityLabel = { error: "error", warning: "warning", info: "info" };
23685
+ function explicitSchemaFor(input, schemas, stateTagName) {
23686
+ if (schemas.length === 1) {
23687
+ const [only] = schemas;
23688
+ return {
23689
+ schema: only.schema,
23690
+ stateSource: only.stateSource === void 0 ? void 0 : stateSourceFromPage(input.source, only.source, only.stateSource)
23691
+ };
23692
+ }
23693
+ for (const entry of schemas) {
23694
+ const stateSource = stateSourceFromPage(input.source, entry.source, entry.stateSource);
23695
+ if (stateSource !== void 0 && schemaAppliesToPage(input.text, stateTagName, stateSource, input.fileReader)) {
23696
+ return { schema: entry.schema, stateSource };
23697
+ }
23698
+ }
23699
+ return void 0;
23700
+ }
23669
23701
  function runValidation(inputs, options = {}) {
23670
23702
  const diagnosticsBySource = /* @__PURE__ */ new Map();
23671
23703
  const textBySource = new Map(inputs.map((i) => [i.source, i.text]));
23672
23704
  const manifestInputs = inputs.filter((i) => i.kind === "manifest");
23673
- let explicitSchema;
23674
- let explicitStateSource;
23705
+ let explicitSchemas = [];
23675
23706
  let haveExplicitApplication = false;
23676
23707
  if (manifestInputs.length > 0) {
23677
23708
  const result = validateManifestSet({
@@ -23683,10 +23714,7 @@ function runValidation(inputs, options = {}) {
23683
23714
  }
23684
23715
  if (result.hasApplicationArtifact) {
23685
23716
  haveExplicitApplication = true;
23686
- explicitSchema = result.resolvedSchema;
23687
- if (result.resolvedSchemaSource !== void 0 && result.resolvedStateSource !== void 0) {
23688
- explicitStateSource = { manifest: result.resolvedSchemaSource, stateSource: result.resolvedStateSource };
23689
- }
23717
+ explicitSchemas = result.resolvedSchemas;
23690
23718
  }
23691
23719
  }
23692
23720
  const inFiles = /* @__PURE__ */ new Map();
@@ -23696,8 +23724,9 @@ function runValidation(inputs, options = {}) {
23696
23724
  if (!hasAnythingToCheck(input.text, options.bindAttribute ?? "data-wcs", options.stateTagName ?? "wcs-state")) {
23697
23725
  nothingToCheck.push(input.source);
23698
23726
  }
23699
- let applicationSchema = explicitSchema;
23700
- let applicationStateSource = explicitStateSource === void 0 ? void 0 : stateSourceFromPage(input.source, explicitStateSource.manifest, explicitStateSource.stateSource);
23727
+ const explicit = explicitSchemaFor(input, explicitSchemas, options.stateTagName ?? "wcs-state");
23728
+ let applicationSchema = explicit?.schema;
23729
+ let applicationStateSource = explicit?.stateSource;
23701
23730
  if (!haveExplicitApplication && input.fileReader !== void 0) {
23702
23731
  const discovered = discoverApplicationManifest(input.fileReader);
23703
23732
  applicationSchema = discovered?.schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/lint",
3
- "version": "4.31.0",
3
+ "version": "4.32.0",
4
4
  "description": "Static-contract validator CLI (wcs-validate) for wcstack data-wcs bindings and wcstack.manifest.json sidecars. Thin npm wrapper around the wcstack-intellisense validator core.",
5
5
  "type": "module",
6
6
  "bin": {