@usefragments/core 1.7.1 → 1.8.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/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ CompiledFragmentsFileValidationError,
3
+ parseCompiledFragmentsFile
4
+ } from "./chunk-RANPUC6C.js";
1
5
  import {
2
6
  generateContext
3
7
  } from "./chunk-X34IA4LR.js";
@@ -7,6 +11,11 @@ import {
7
11
  import {
8
12
  resolveArea
9
13
  } from "./chunk-3LLRNCPX.js";
14
+ import {
15
+ GOVERNANCE_TELEMETRY_FIELDS,
16
+ GOVERNANCE_TELEMETRY_SOURCE_DISCLOSURE,
17
+ GOVERNANCE_TELEMETRY_TOP_LEVEL_FIELDS
18
+ } from "./chunk-MZ4SW3TP.js";
10
19
  import {
11
20
  REGISTRY_ARTIFACT_SCHEMA_VERSION,
12
21
  REGISTRY_INSTALL_RECEIPT_SCHEMA_VERSION,
@@ -41,11 +50,16 @@ import {
41
50
  sha256Hex
42
51
  } from "./chunk-YF65VYRY.js";
43
52
  import {
53
+ AGENT_FORMAT_SCHEMA_VERSION,
44
54
  CODES,
45
55
  EXPLAIN_URL_BASE,
46
56
  FactIndex,
47
57
  RULE_FAMILY_IDS,
48
58
  RULE_FAMILY_MEMBERS,
59
+ agentErrorEnvelopeSchema,
60
+ agentFormatSchema,
61
+ agentIntegritySchema,
62
+ agentOutputSchema,
49
63
  asComponentId,
50
64
  bridgeSourceViolation,
51
65
  bridgeSourceViolations,
@@ -61,13 +75,25 @@ import {
61
75
  describePolicyExclude,
62
76
  excludeGlobToRegExp,
63
77
  explainUrlForCode,
78
+ factEvidenceSchema,
64
79
  factId,
80
+ factLocationSchema,
81
+ findingFixSchema,
82
+ findingReplaceClassTokenFixSchema,
83
+ findingReplaceComponentFixSchema,
84
+ findingReplaceImportFixSchema,
85
+ findingReplacePropValueFixSchema,
86
+ findingReplaceStyleValueFixSchema,
87
+ findingSchema,
88
+ fixSchema,
65
89
  g,
66
90
  globalGovernanceRecordSchema,
67
91
  globalJsxGovernanceRecordSchema,
68
92
  globalStyleGovernanceRecordSchema,
69
93
  governanceConfigSchema,
70
94
  governanceSeveritySchema,
95
+ governanceVerdictMetadataSchema,
96
+ governanceVerdictSchema,
71
97
  hash64Hex,
72
98
  isPresetSourcedRule,
73
99
  isRuleFamilyId,
@@ -116,8 +142,11 @@ import {
116
142
  matchPolicyExclude,
117
143
  matchesGlob,
118
144
  normalizeExcludePath,
145
+ normalizeFinding,
119
146
  normalizeGovernanceConfig,
120
147
  normalizePolicyExcludes,
148
+ normalizeSeverity,
149
+ normalizeViolation,
121
150
  ownedComponentIdsEqual,
122
151
  ownedImportMatchesRoot,
123
152
  ownedImportsEqual,
@@ -126,33 +155,11 @@ import {
126
155
  projectSupersededImportPathPreferences,
127
156
  resolveComponentGovernance,
128
157
  ruleFamilyMembers,
129
- scaleGovernanceRecordSchema
130
- } from "./chunk-WNMWKUYG.js";
131
- import {
132
- AGENT_FORMAT_SCHEMA_VERSION,
133
- agentErrorEnvelopeSchema,
134
- agentFormatSchema,
135
- agentIntegritySchema,
136
- agentOutputSchema,
137
- factEvidenceSchema,
138
- factLocationSchema,
139
- findingFixSchema,
140
- findingReplaceClassTokenFixSchema,
141
- findingReplaceComponentFixSchema,
142
- findingReplaceImportFixSchema,
143
- findingReplacePropValueFixSchema,
144
- findingReplaceStyleValueFixSchema,
145
- findingSchema,
146
- fixSchema,
147
- governanceVerdictMetadataSchema,
148
- governanceVerdictSchema,
149
- normalizeFinding,
150
- normalizeSeverity,
151
- normalizeViolation,
158
+ scaleGovernanceRecordSchema,
152
159
  suppressionDirectiveSchema,
153
160
  validatorResultSchema,
154
161
  violationSchema
155
- } from "./chunk-ZHS52OT4.js";
162
+ } from "./chunk-UUREQ4HD.js";
156
163
  import {
157
164
  OWNED_PACKAGE_IDENTITY_EPOCH,
158
165
  OWNED_PACKAGE_IDENTITY_SOURCE_SHA256,
@@ -182,10 +189,6 @@ import {
182
189
  severitySchema,
183
190
  sortBySeverity
184
191
  } from "./chunk-V4VQB57N.js";
185
- import {
186
- CompiledFragmentsFileValidationError,
187
- parseCompiledFragmentsFile
188
- } from "./chunk-RANPUC6C.js";
189
192
 
190
193
  // src/constants.ts
191
194
  var BRAND = {
@@ -8760,16 +8763,28 @@ function indexTokensByCssVariable(tokens) {
8760
8763
  var RULE_ID22 = "tokens/css-vars-must-be-defined";
8761
8764
  var RULE_VERSION23 = "1";
8762
8765
  var CSS_VAR_REFERENCE = /var\(\s*(--[A-Za-z0-9_-]+)/gi;
8766
+ function contractVocabularyContext(ix) {
8767
+ if (!ix.policy.cssVarsMustBeDefined()) return void 0;
8768
+ const vocabulary = new Set(ix.byKind("contract_token").map((token) => token.name));
8769
+ if (vocabulary.size === 0) return void 0;
8770
+ return {
8771
+ vocabulary,
8772
+ prefixes: contractPrefixFamilies(vocabulary),
8773
+ hasFlatTokens: [...vocabulary].some(isSingleSegmentVarName),
8774
+ locallyDefinedCustomProperties: new Set(
8775
+ ix.byKind("style_declaration").filter((decl) => decl.property.startsWith("--")).map((decl) => decl.property)
8776
+ )
8777
+ };
8778
+ }
8779
+ function isJudgedReference(tokenName, context) {
8780
+ return context.vocabulary.has(tokenName) || sharesContractPrefix(tokenName, context.prefixes) || context.hasFlatTokens && isSingleSegmentVarName(tokenName) || context.locallyDefinedCustomProperties.has(tokenName);
8781
+ }
8763
8782
  function ruleTokensCssVarsMustBeDefined(ix) {
8764
8783
  const policy = ix.policy.cssVarsMustBeDefined();
8765
8784
  if (!policy) return [];
8766
- const vocabulary = new Set(ix.byKind("contract_token").map((token) => token.name));
8767
- if (vocabulary.size === 0) return [];
8768
- const prefixes = contractPrefixFamilies(vocabulary);
8769
- const hasFlatTokens = [...vocabulary].some(isSingleSegmentVarName);
8770
- const locallyDefinedCustomProperties = new Set(
8771
- ix.byKind("style_declaration").filter((decl) => decl.property.startsWith("--")).map((decl) => decl.property)
8772
- );
8785
+ const context = contractVocabularyContext(ix);
8786
+ if (!context) return [];
8787
+ const { vocabulary } = context;
8773
8788
  const findings = [];
8774
8789
  for (const decl of ix.byKind("style_declaration")) {
8775
8790
  const seen = /* @__PURE__ */ new Set();
@@ -8779,8 +8794,7 @@ function ruleTokensCssVarsMustBeDefined(ix) {
8779
8794
  const tokenName = match[1];
8780
8795
  CSS_VAR_REFERENCE.lastIndex = skipToCloseParen(decl.value, match.index + 3);
8781
8796
  if (vocabulary.has(tokenName)) continue;
8782
- const shaped = sharesContractPrefix(tokenName, prefixes) || hasFlatTokens && isSingleSegmentVarName(tokenName) || locallyDefinedCustomProperties.has(tokenName);
8783
- if (!shaped) continue;
8797
+ if (!isJudgedReference(tokenName, context)) continue;
8784
8798
  if (seen.has(tokenName)) continue;
8785
8799
  seen.add(tokenName);
8786
8800
  findings.push(
@@ -8819,6 +8833,23 @@ function sharesContractPrefix(name, prefixes) {
8819
8833
  function isSingleSegmentVarName(name) {
8820
8834
  return name.indexOf("-", 2) === -1;
8821
8835
  }
8836
+ function contractTokenReferenceCensus(ix) {
8837
+ const context = contractVocabularyContext(ix);
8838
+ if (!context) return void 0;
8839
+ const checked = /* @__PURE__ */ new Set();
8840
+ for (const decl of ix.byKind("style_declaration")) {
8841
+ CSS_VAR_REFERENCE.lastIndex = 0;
8842
+ let match;
8843
+ while ((match = CSS_VAR_REFERENCE.exec(decl.value)) !== null) {
8844
+ const tokenName = match[1];
8845
+ CSS_VAR_REFERENCE.lastIndex = skipToCloseParen(decl.value, match.index + 3);
8846
+ if (!isJudgedReference(tokenName, context)) continue;
8847
+ checked.add(`${decl.location.file}:${decl.location.line}:${decl.location.column}`);
8848
+ break;
8849
+ }
8850
+ }
8851
+ return { checkedSites: checked.size };
8852
+ }
8822
8853
  function skipToCloseParen(value, openParenIndex) {
8823
8854
  let depth = 0;
8824
8855
  for (let i = openParenIndex; i < value.length; i++) {
@@ -10282,6 +10313,9 @@ export {
10282
10313
  EXPLAIN_URL_BASE,
10283
10314
  FRAGMENTS_INTERNAL_RULE_IDS,
10284
10315
  FactIndex,
10316
+ GOVERNANCE_TELEMETRY_FIELDS,
10317
+ GOVERNANCE_TELEMETRY_SOURCE_DISCLOSURE,
10318
+ GOVERNANCE_TELEMETRY_TOP_LEVEL_FIELDS,
10285
10319
  OWNED_PACKAGE_IDENTITY_EPOCH,
10286
10320
  OWNED_PACKAGE_IDENTITY_SOURCE_SHA256,
10287
10321
  PRESET_NAMES,
@@ -10383,6 +10417,7 @@ export {
10383
10417
  contractHash,
10384
10418
  contractPolicyFromGovernanceConfig,
10385
10419
  contractTierRuleIds,
10420
+ contractTokenReferenceCensus,
10386
10421
  customerDefaultRuleStates,
10387
10422
  defineBlock,
10388
10423
  defineConfig,