@webority/tokens 0.148.0 → 0.150.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/brand.d.ts +39 -25
- package/dist/brand.js +2 -2
- package/dist/build.d.ts +41 -0
- package/dist/build.js +5 -5
- package/dist/canvas/webority-phone.json +1 -1
- package/dist/canvas/webority-web-390.json +1 -1
- package/dist/canvas/webority-web.json +1 -1
- package/dist/check.d.ts +37 -0
- package/dist/check.js +3 -3
- package/dist/cli.d.ts +15 -96
- package/dist/cli.js +1 -1
- package/dist/emit/canvas.d.ts +8 -0
- package/dist/emit/canvas.js +1 -1
- package/dist/emit/email.d.ts +32 -0
- package/dist/emit/email.js +2 -2
- package/dist/emit/meanings.d.ts +3 -0
- package/dist/emit/phone.d.ts +26 -0
- package/dist/emit/phone.js +3 -3
- package/dist/emit/web.d.ts +18 -0
- package/dist/emit/web.js +14 -14
- package/dist/guards.d.ts +3 -0
- package/dist/guards.js +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/meanings.json +1 -1
- package/dist/model/colour.d.ts +8 -0
- package/dist/model/colour.js +1 -1
- package/dist/model/contrast.d.ts +26 -0
- package/dist/model/contrast.js +1 -1
- package/dist/model/index.d.ts +52 -0
- package/dist/model/length.d.ts +21 -0
- package/dist/model/length.js +1 -1
- package/dist/model/load.d.ts +32 -0
- package/dist/model/load.js +1 -1
- package/dist/model/references.d.ts +3 -0
- package/dist/model/references.js +1 -1
- package/dist/model/resolve.d.ts +4 -0
- package/dist/model/resolve.js +2 -2
- package/dist/names.d.ts +1 -11
- package/dist/names.js +1 -1
- package/dist/outputs.d.ts +51 -102
- package/dist/present.d.ts +1 -0
- package/dist/present.js +1 -0
- package/dist/ramp.d.ts +8 -0
- package/dist/ramp.js +1 -1
- package/dist/upgrade/classes.d.ts +13 -0
- package/dist/upgrade/classes.js +2 -2
- package/dist/upgrade/components.d.ts +19 -0
- package/dist/upgrade/components.js +3 -3
- package/dist/upgrade/css.d.ts +28 -0
- package/dist/upgrade/css.js +2 -2
- package/dist/upgrade/index.d.ts +64 -0
- package/dist/upgrade/index.js +2 -2
- package/dist/upgrade/razorAttributes.d.ts +19 -0
- package/dist/upgrade/razorAttributes.js +2 -2
- package/dist/upgrade/razorTags.d.ts +19 -0
- package/dist/upgrade/razorTags.js +2 -2
- package/dist/upgrade/razorValueSplits.d.ts +19 -0
- package/dist/upgrade/razorValueSplits.js +2 -2
- package/dist/upgrade/source.d.ts +19 -0
- package/dist/upgrade/source.js +3 -3
- package/dist/upgrade/tagScan.d.ts +7 -0
- package/dist/upgrade/tagScan.js +1 -1
- package/dist/upgrade/themeReads.d.ts +55 -0
- package/dist/upgrade/themeReads.js +2 -2
- package/dist/upgrade/valueSplits.d.ts +23 -0
- package/dist/upgrade/valueSplits.js +3 -3
- package/dist/upgrade/wrapperValues.d.ts +71 -0
- package/dist/upgrade/wrapperValues.js +1 -1
- package/dist/webority.d.ts +1 -0
- package/package.json +7 -3
- package/renames/renames.d.ts +1 -1
package/dist/outputs.d.ts
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
export type Mode = "light" | "dark";
|
|
2
2
|
export type Platform = "web" | "phone";
|
|
3
|
-
|
|
4
3
|
export interface ThemeTokensV2 {
|
|
5
4
|
format: "webority-theme-tokens/2";
|
|
6
|
-
source: {
|
|
5
|
+
source: {
|
|
6
|
+
package: string;
|
|
7
|
+
version: string;
|
|
8
|
+
brand: string | null;
|
|
9
|
+
platform: Platform;
|
|
10
|
+
width: number | null;
|
|
11
|
+
};
|
|
7
12
|
modes: Mode[];
|
|
8
13
|
colors: Record<Mode, Record<string, string>>;
|
|
9
14
|
space: Record<string, number>;
|
|
10
15
|
radius: Record<string, number>;
|
|
11
|
-
text: Record<string, {
|
|
16
|
+
text: Record<string, {
|
|
17
|
+
size: number;
|
|
18
|
+
}>;
|
|
12
19
|
/** `leading` holds the line height of each text role (heading, body, display), unitless. */
|
|
13
|
-
typography: {
|
|
20
|
+
typography: {
|
|
21
|
+
fontWeight: Record<string, number>;
|
|
22
|
+
leading: Record<string, number>;
|
|
23
|
+
};
|
|
14
24
|
/** The description of each colour a brand adds, by name; absent when the brand adds none. */
|
|
15
25
|
colorMeanings?: Record<string, string>;
|
|
16
|
-
fonts: Record<string, {
|
|
26
|
+
fonts: Record<string, {
|
|
27
|
+
family: string;
|
|
28
|
+
fallback: string;
|
|
29
|
+
}>;
|
|
17
30
|
/** A role the theme declares as no shadow is null; a role the platform lacks is absent. */
|
|
18
31
|
shadow: Record<string, CanvasShadow | null>;
|
|
19
32
|
components: Record<string, CanvasComponent>;
|
|
20
33
|
}
|
|
21
|
-
|
|
22
34
|
/** A component's values: `base` applies at every size, and a `sizes` entry wins over `base` for the same prop. */
|
|
23
35
|
export interface CanvasComponent {
|
|
24
36
|
base: Record<string, string>;
|
|
25
37
|
sizes: Record<string, Record<string, string>>;
|
|
26
38
|
}
|
|
27
|
-
|
|
28
39
|
/** Lengths in px at scale 1. `color` is the resolved colour with its opacity in the alpha. */
|
|
29
40
|
export interface CanvasShadow {
|
|
30
41
|
x: number;
|
|
@@ -35,113 +46,51 @@ export interface CanvasShadow {
|
|
|
35
46
|
/** Phone only: the Android elevation, when the token sets one. */
|
|
36
47
|
elevation?: number;
|
|
37
48
|
}
|
|
38
|
-
|
|
39
49
|
export interface MeaningRegistry {
|
|
40
50
|
format: "webority-meanings/1";
|
|
41
|
-
source: {
|
|
42
|
-
|
|
51
|
+
source: {
|
|
52
|
+
package: string;
|
|
53
|
+
version: string;
|
|
54
|
+
};
|
|
55
|
+
color: Record<string, {
|
|
56
|
+
description: string;
|
|
57
|
+
platforms: Platform[];
|
|
58
|
+
}>;
|
|
43
59
|
}
|
|
44
|
-
|
|
45
|
-
export type
|
|
46
|
-
|
|
47
|
-
| "canvas"
|
|
48
|
-
| "card"
|
|
49
|
-
| "panel"
|
|
50
|
-
| "panel-alt"
|
|
51
|
-
| "surface"
|
|
52
|
-
| "line"
|
|
53
|
-
| "line-strong"
|
|
54
|
-
| "accent-tint-line"
|
|
55
|
-
| "heading"
|
|
56
|
-
| "strong"
|
|
57
|
-
| "text"
|
|
58
|
-
| "secondary"
|
|
59
|
-
| "muted"
|
|
60
|
-
| "accent"
|
|
61
|
-
| "on-accent"
|
|
62
|
-
| "link"
|
|
63
|
-
| "success"
|
|
64
|
-
| "warning"
|
|
65
|
-
| "danger"
|
|
66
|
-
| "accent-tint"
|
|
67
|
-
| "success-tint"
|
|
68
|
-
| "warning-tint"
|
|
69
|
-
| "danger-tint"
|
|
70
|
-
| "figure-panel";
|
|
71
|
-
|
|
72
|
-
export type EmailTypeRoleKey =
|
|
73
|
-
| "h1"
|
|
74
|
-
| "eyebrow"
|
|
75
|
-
| "lede"
|
|
76
|
-
| "body"
|
|
77
|
-
| "detail-value"
|
|
78
|
-
| "quote"
|
|
79
|
-
| "body-large"
|
|
80
|
-
| "title"
|
|
81
|
-
| "item"
|
|
82
|
-
| "label"
|
|
83
|
-
| "note"
|
|
84
|
-
| "note-small"
|
|
85
|
-
| "figure"
|
|
86
|
-
| "figure-hero"
|
|
87
|
-
| "figure-sub"
|
|
88
|
-
| "range"
|
|
89
|
-
| "sign"
|
|
90
|
-
| "foot"
|
|
91
|
-
| "num"
|
|
92
|
-
| "code-otp"
|
|
93
|
-
| "code-id"
|
|
94
|
-
| "button";
|
|
95
|
-
|
|
96
|
-
export type EmailSpaceKey =
|
|
97
|
-
| "section"
|
|
98
|
-
| "section-phone"
|
|
99
|
-
| "tight"
|
|
100
|
-
| "item"
|
|
101
|
-
| "heading-after"
|
|
102
|
-
| "eyebrow-after"
|
|
103
|
-
| "title-after"
|
|
104
|
-
| "callout-lead-after"
|
|
105
|
-
| "paragraph-gap"
|
|
106
|
-
| "sign-gap"
|
|
107
|
-
| "sign-gap-phone"
|
|
108
|
-
| "step-gap"
|
|
109
|
-
| "step-gutter"
|
|
110
|
-
| "step-gutter-phone"
|
|
111
|
-
| "step-number-space"
|
|
112
|
-
| "step-number-space-phone"
|
|
113
|
-
| "column-top"
|
|
114
|
-
| "column-gap"
|
|
115
|
-
| "row-padding"
|
|
116
|
-
| "panel-padding"
|
|
117
|
-
| "panel-padding-wide"
|
|
118
|
-
| "hero-padding"
|
|
119
|
-
| "hero-padding-wide"
|
|
120
|
-
| "columns-padding"
|
|
121
|
-
| "columns-padding-wide"
|
|
122
|
-
| "details-padding"
|
|
123
|
-
| "details-padding-wide"
|
|
124
|
-
| "signature-gap";
|
|
125
|
-
|
|
60
|
+
export type EmailColorRoleKey = "page" | "canvas" | "card" | "panel" | "panel-alt" | "surface" | "line" | "line-strong" | "accent-tint-line" | "heading" | "strong" | "text" | "secondary" | "muted" | "accent" | "on-accent" | "link" | "success" | "warning" | "danger" | "accent-tint" | "success-tint" | "warning-tint" | "danger-tint" | "figure-panel";
|
|
61
|
+
export type EmailTypeRoleKey = "h1" | "eyebrow" | "lede" | "body" | "detail-value" | "quote" | "body-large" | "title" | "item" | "label" | "note" | "note-small" | "figure" | "figure-hero" | "figure-sub" | "range" | "sign" | "foot" | "num" | "code-otp" | "code-id" | "button";
|
|
62
|
+
export type EmailSpaceKey = "section" | "section-phone" | "tight" | "item" | "heading-after" | "eyebrow-after" | "title-after" | "callout-lead-after" | "paragraph-gap" | "sign-gap" | "sign-gap-phone" | "step-gap" | "step-gutter" | "step-gutter-phone" | "step-number-space" | "step-number-space-phone" | "column-top" | "column-gap" | "row-padding" | "panel-padding" | "panel-padding-wide" | "hero-padding" | "hero-padding-wide" | "columns-padding" | "columns-padding-wide" | "details-padding" | "details-padding-wide" | "signature-gap";
|
|
126
63
|
export type EmailShapeKey = "panel-radius" | "tint-radius" | "code-radius" | "details-radius";
|
|
127
|
-
|
|
128
64
|
export interface EmailThemeTokensV1 {
|
|
129
65
|
format: "webority-email-theme/1";
|
|
130
|
-
source: {
|
|
66
|
+
source: {
|
|
67
|
+
package: string;
|
|
68
|
+
version: string;
|
|
69
|
+
brand: string | null;
|
|
70
|
+
};
|
|
131
71
|
/** "#RRGGBB" in both modes. */
|
|
132
72
|
colors: Record<EmailColorRoleKey, Record<Mode, string>>;
|
|
133
73
|
/** CSS font-family lists; a name with spaces is in single quotes. */
|
|
134
|
-
fonts: {
|
|
74
|
+
fonts: {
|
|
75
|
+
body: string;
|
|
76
|
+
display: string;
|
|
77
|
+
mono: string;
|
|
78
|
+
};
|
|
135
79
|
/** Whole pixels: size and line height at 1440, phone values at 390, and an optional narrow-phone pair a brand sets. */
|
|
136
|
-
type: Record<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
80
|
+
type: Record<EmailTypeRoleKey, {
|
|
81
|
+
size: number;
|
|
82
|
+
lineHeight: number;
|
|
83
|
+
phoneSize: number;
|
|
84
|
+
phoneLineHeight: number;
|
|
85
|
+
narrowSize?: number;
|
|
86
|
+
narrowLineHeight?: number;
|
|
87
|
+
}>;
|
|
140
88
|
/** Px at 1440; a padding entry is a CSS shorthand of px values, such as "24px 16px". */
|
|
141
89
|
space: Record<EmailSpaceKey, number | string>;
|
|
142
90
|
/** Px at 1440. */
|
|
143
91
|
shape: Record<EmailShapeKey, number>;
|
|
144
|
-
button: {
|
|
92
|
+
button: {
|
|
93
|
+
radius: number;
|
|
94
|
+
padding: string;
|
|
95
|
+
};
|
|
145
96
|
}
|
|
146
|
-
|
|
147
|
-
export declare function cssVar(group: string, name: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function present<T>(value: T | undefined, what: string): T;
|
package/dist/present.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){if(e===void 0)throw Error(`webority-tokens: ${t} is missing.`);return e}export{e as present};
|
package/dist/ramp.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The primary ramp steps a brand file may leave out: palette step names without the group prefix. */
|
|
2
|
+
export declare const RAMP_STEPS: readonly ["primary-hover", "primary-pressed", "primary-50", "primary-30", "primary-20", "primary-15", "primary-10", "primary-5"];
|
|
3
|
+
export type RampStep = (typeof RAMP_STEPS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* @param hex "#RRGGBB" in any case.
|
|
6
|
+
* @returns every step as upper case "#RRGGBB", keys in RAMP_STEPS order.
|
|
7
|
+
*/
|
|
8
|
+
export declare function deriveRamp(hex: string): Record<RampStep, string>;
|
package/dist/ramp.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
import{present as e}from"./present.js";var t=Object.freeze([`primary-hover`,`primary-pressed`,`primary-50`,`primary-30`,`primary-20`,`primary-15`,`primary-10`,`primary-5`]),n=Object.freeze({"primary-50":.5,"primary-30":.3,"primary-20":.2,"primary-15":.15,"primary-10":.1,"primary-5":.05}),r=.05,i=/^#([0-9a-f]{6})$/i;function a(t){let a=typeof t==`string`?i.exec(t):null;if(!a)throw Error(`deriveRamp: ${t} is not #RRGGBB.`);let u=parseInt(e(a[1],`the hex digits`),16),d=[u>>16&255,u>>8&255,u&255],[f,p,m]=c(d),h=e=>s(d.map(t=>Math.round(t*e+255*(1-e))));return{"primary-hover":l(f,p,o(m+r)),"primary-pressed":l(f,p,o(m-r)),"primary-50":h(n[`primary-50`]),"primary-30":h(n[`primary-30`]),"primary-20":h(n[`primary-20`]),"primary-15":h(n[`primary-15`]),"primary-10":h(n[`primary-10`]),"primary-5":h(n[`primary-5`])}}function o(e){return Math.min(1,Math.max(0,e))}function s(e){return`#`+e.map(e=>e.toString(16).padStart(2,`0`)).join(``).toUpperCase()}function c([e,t,n]){let r=e/255,i=t/255,a=n/255,o=Math.max(r,i,a),s=Math.min(r,i,a),c=(o+s)/2;if(o===s)return[0,0,c];let l=o-s,u=c>.5?l/(2-o-s):l/(o+s),d;return d=o===r?(i-a)/l+(i<a?6:0):o===i?(a-r)/l+2:(r-i)/l+4,[d*60,u,c]}function l(e,t,n){if(t===0)return s([n,n,n].map(e=>Math.round(e*255)));let r=n<.5?n*(1+t):n+t-n*t,i=2*n-r,a=e/360;return s([a+1/3,a,a-1/3].map(e=>Math.round(u(i,r,e)*255)))}function u(e,t,n){let r=n;return r<0&&(r+=1),r>1&&--r,r<1/6?e+(t-e)*6*r:r<1/2?t:r<2/3?e+(t-e)*(2/3-r)*6:e}export{t as RAMP_STEPS,a as deriveRamp};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClassRename } from "../../renames/renames.d.ts";
|
|
2
|
+
export type ClassHit = {
|
|
3
|
+
line: number;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
};
|
|
7
|
+
export type ClassResult = {
|
|
8
|
+
text: string;
|
|
9
|
+
hits: ClassHit[];
|
|
10
|
+
findings: never[];
|
|
11
|
+
};
|
|
12
|
+
/** @param file repo-relative, forward slashes */
|
|
13
|
+
export declare function applyClasses(source: string, file: string, rules: ClassRename[]): ClassResult;
|
package/dist/upgrade/classes.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`&&t.push(n+1);return t},
|
|
1
|
+
import{present as e}from"../present.js";var t=new Set([`.css`,`.scss`,`.sass`,`.less`]),n=new Set([`.cshtml`,`.razor`,`.html`]),r=new Set([`.js`,`.jsx`,`.ts`,`.tsx`,`.mjs`,`.cjs`,`.mts`,`.cts`]),i=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},o=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
2
|
+
`&&t.push(n+1);return t},s=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`the line start offset`)<=n?r=a:i=a-1}return r+1},c=(e,t)=>e<t?-1:+(e>t);function l(l,u,d){let f=a(u),p=t.has(f)?`selector`:n.has(f)?`attribute`:r.has(f)?`literal`:void 0;if(d.length===0||p===void 0)return{text:l,hits:[],findings:[]};let m=new Map(d),h=[...m.keys()].sort((e,t)=>t.length-e.length).map(i).join(`|`),g=RegExp(`(?<![\\w-])(${h})(?![\\w-])`,`g`),_=o(l),v=[],y=(t,n)=>t.replace(g,(t,r,i)=>{let a=e(m.get(t),`the rename for the class ${t}`);return v.push({line:s(_,n+i),from:t,to:a}),a}),b=l;return b=p===`selector`?l.replace(RegExp(`\\.(${h})(?![\\w-])`,`g`),(e,t,n)=>{let r=m.get(t);return v.push({line:s(_,n),from:`.${t}`,to:`.${r}`}),`.${r}`}):p===`attribute`?l.replace(/(?<=\s)class\s*=\s*(["'])([^"'\n]*)\1/g,(e,t,n,r)=>{let i=y(n,r+e.length-1-n.length);return`${e.slice(0,e.length-1-n.length)}${i}${t}`}):l.replace(/(["'`])([^"'`\n]*)\1/g,(e,t,n,r)=>`${t}${y(n,r+1)}${t}`),v.sort((e,t)=>e.line-t.line||c(e.from,t.from)),{text:b,hits:v,findings:[]}}export{l as applyClasses};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ComponentRule } from "../../renames/renames.d.ts";
|
|
2
|
+
export type ComponentHit = {
|
|
3
|
+
line: number;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
};
|
|
7
|
+
export type ComponentFinding = {
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
path: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export type ComponentResult = {
|
|
14
|
+
text: string;
|
|
15
|
+
hits: ComponentHit[];
|
|
16
|
+
findings: ComponentFinding[];
|
|
17
|
+
};
|
|
18
|
+
/** @param file repo-relative, forward slashes */
|
|
19
|
+
export declare function applyComponents(source: string, file: string, rules: ComponentRule[]): ComponentResult;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`&&t.push(n+1);return t},
|
|
3
|
-
`?
|
|
1
|
+
import{present as e}from"../present.js";var t=new Set([`.js`,`.jsx`,`.ts`,`.tsx`]),n=`[A-Za-z_$][\\w$]*`,r=RegExp(`^(type\\s+)?(${n})(?:\\s+as\\s+(${n}))?$`),i=/[A-Za-z_$][\w$:.-]*/y,a=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),o=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},s=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
2
|
+
`&&t.push(n+1);return t},c=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`the line start offset`)<=n?r=a:i=a-1}return r+1},l=(e,t)=>e<t?-1:+(e>t),u=e=>`${e.typeKw}${e.name}${e.alias===void 0?``:` as ${e.alias}`}`;function d(t){return t.split(`,`).map(e=>e.trim()).filter(e=>e!==``).map(t=>{let n=r.exec(t);if(n===null)throw Error(`cannot read the import specifier "${t}"`);return{typeKw:n[1]===void 0?``:`type `,name:e(n[2],`the import specifier name`),alias:n[3]}})}function f(t,r){let i=RegExp(`\\bimport\\s+(type\\s+)?(?:(${n})\\s*,\\s*)?\\{([^{}]*)\\}\\s*from\\s*(["'])${a(r)}\\4(;?)`,`g`);return[...t.matchAll(i)].map(t=>({start:t.index,end:t.index+t[0].length,typeKw:t[1]===void 0?``:`type `,defaultName:t[2],specs:d(e(t[3],`the import specifier list`)),quote:e(t[4],`the import quote`),semi:e(t[5],`the import semicolon`),pkg:r}))}function p(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===`\\`?i++:t===r&&(r=``);else if(t===`"`||t===`'`||t==="`")r=t;else if(t===`{`)n++;else if(t===`}`)n--;else if(t===`>`&&n===0)return i}return-1}function m(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===`\\`?i++:t===r&&(r=``);else if(t===`"`||t===`'`||t==="`")r=t;else if(t===`{`)n++;else if(t===`}`&&(n--,n===0))return i+1}throw Error(`unbalanced braces in a JSX attribute`)}function h(t,n,r){let a=[],o=n;for(;o<r;){let n=e(t[o],`the JSX attribute character`);if(/\s/.test(n)){o++;continue}if(n===`{`){o=m(t,o);continue}i.lastIndex=o;let r=i.exec(t);if(r===null)break;let s=o,c=o+r[0].length,l=c;for(;/\s/.test(t[l]??``);)l++;if(t[l]!==`=`){a.push({name:r[0],nameStart:s,nameEnd:c,kind:`none`}),o=c;continue}for(l++;/\s/.test(t[l]??``);)l++;let u=t[l];if(u===`"`||u===`'`){let e=t.indexOf(u,l+1);if(e===-1)throw Error(`unterminated value of JSX attribute "${r[0]}"`);a.push({name:r[0],nameStart:s,nameEnd:c,kind:`quoted`,innerStart:l+1,innerEnd:e,inner:t.slice(l+1,e)}),o=e+1}else if(u===`{`){let e=m(t,l);a.push({name:r[0],nameStart:s,nameEnd:c,kind:`braced`,innerStart:l+1,innerEnd:e-1,inner:t.slice(l+1,e-1)}),o=e}else throw Error(`cannot read the value of JSX attribute "${r[0]}"`)}return a}function g(t){if(t.kind===`quoted`)return{start:t.innerStart,end:t.innerEnd,value:t.inner};if(t.kind===`braced`){let n=/^(\s*)(["'])([^"'\n]*)\2\s*$/.exec(t.inner);if(n!==null){let r=e(n[1],`the leading space of a JSX attribute value`),i=e(n[3],`the text of a JSX attribute value`),a=t.innerStart+r.length+1;return{start:a,end:a+i.length,value:i}}}}function _(e,t){let n=[],r=`<${t}`;for(let t=e.indexOf(r);t!==-1;t=e.indexOf(r,t+1)){let i=t+r.length;/[\s/>]/.test(e[i]??``)&&n.push({nameEnd:i,end:p(e,i)})}return n}function v(t,n,r){let i=f(t,r.package),o=i.flatMap(e=>e.specs.filter(e=>e.name===r.from).map(t=>({st:e,spec:t})))[0];if(o===void 0)return{text:t,hits:[],findings:[]};let{st:l,spec:d}=o,p=d.alias??r.from,m=d.alias??r.to,v=m!==p,y=r.from!==r.to&&d.alias===void 0&&i.some(e=>e.specs.some(e=>e!==d&&e.name===r.to&&e.alias===void 0)),b=s(t),x=[],S=[],C=[],w=_(t,p),T=w.filter(e=>e.end===-1);if(T.length>0){for(let{nameEnd:e}of T)C.push({file:n,line:c(b,e),path:`<${p}>`,message:`the element could not be read (a quote or brace does not pair up); rename it by hand`});return{text:t,hits:[],findings:C}}if(r.from!==r.to){let e=y?l.specs.filter(e=>e!==d):l.specs.map(e=>e===d?{...e,name:r.to}:e),n=[];if(l.defaultName!==void 0&&n.push(l.defaultName),e.length>0&&n.push(`{ ${e.map(u).join(`, `)} }`),n.length===0){let e=t[l.end]===`
|
|
3
|
+
`?l.end+1:l.end;x.push({start:l.start,end:e,text:``})}else x.push({start:l.start,end:l.end,text:`import ${l.typeKw}${n.join(`, `)} from ${l.quote}${l.pkg}${l.quote}${l.semi}`});S.push({line:c(b,l.start),from:r.from,to:r.to})}let E=t=>Object.hasOwn(r.renameProps,t)?e(r.renameProps[t],`the new name of prop ${t}`):t;for(let{nameEnd:i,end:a}of w){let o=c(b,i),s=h(t,i,a);for(let e of s){let t=E(e.name);t!==e.name&&(x.push({start:e.nameStart,end:e.nameEnd,text:t}),S.push({line:c(b,e.nameStart),from:e.name,to:t}))}let l=s.map(e=>E(e.name));for(let t of s){let n=E(t.name),i=Object.hasOwn(r.valueMaps,n)?r.valueMaps[n]:void 0;if(i===void 0)continue;let a=g(t);if(a!==void 0&&Object.hasOwn(i,a.value)){let t=e(i[a.value],`the value that ${n}="${a.value}" maps to`);x.push({start:a.start,end:a.end,text:t}),S.push({line:c(b,a.start),from:`${n}="${a.value}"`,to:`${n}="${t}"`})}}let u=Object.entries(r.addProps).filter(([e])=>!l.includes(e)).map(([e,t])=>` ${e}=${typeof t==`string`?`"${t}"`:`{${t}}`}`);u.length>0&&x.push({start:i,end:i,text:u.join(``)}),(v||u.length>0)&&S.push({line:o,from:`<${p}`,to:`<${m}${u.join(``)}`}),v&&x.push({start:i-p.length,end:i,text:m});for(let[e,t]of Object.entries(r.removeProps))s.some(t=>t.name===e)&&C.push({file:n,line:o,path:`<${r.from}> ${e}`,message:t})}if(v)for(let e of t.matchAll(RegExp(`</${a(p)}(?=\\s*>)`,`g`))){let t=e.index+2;x.push({start:t,end:t+p.length,text:m}),S.push({line:c(b,t),from:`</${p}`,to:`</${m}`})}x.sort((e,t)=>t.start-e.start||t.end-e.end);let D=t;for(let e of x)D=D.slice(0,e.start)+e.text+D.slice(e.end);return{text:D,hits:S,findings:C}}function y(e,n,r){if(r.length===0||!t.has(o(n)))return{text:e,hits:[],findings:[]};let i=e,a=[],s=[];for(let e of r){let t=v(i,n,e);i=t.text,a.push(...t.hits),s.push(...t.findings)}return a.sort((e,t)=>e.line-t.line||l(e.from,t.from)),s.sort((e,t)=>e.line-t.line||l(e.path,t.path)),{text:i,hits:a,findings:s}}export{y as applyComponents};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RenameTable } from "../../renames/renames.d.ts";
|
|
2
|
+
export type CssHit = {
|
|
3
|
+
line: number;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
};
|
|
7
|
+
export type CssChoose = {
|
|
8
|
+
line: number;
|
|
9
|
+
name: string;
|
|
10
|
+
hint: string;
|
|
11
|
+
};
|
|
12
|
+
export type CssResult = {
|
|
13
|
+
text: string;
|
|
14
|
+
hits: CssHit[];
|
|
15
|
+
choose: CssChoose[];
|
|
16
|
+
checkRole: CssHit[];
|
|
17
|
+
};
|
|
18
|
+
export declare const CSS_TARGET_EXTENSIONS: Set<string>;
|
|
19
|
+
/** @param relPath repo-relative path, forward or back slashes */
|
|
20
|
+
export declare function isCssTarget(relPath: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The table's ownable names that this text declares (`--radius: 4px`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function ownDeclarations(text: string, fileName: string, table: RenameTable): Set<string>;
|
|
25
|
+
/**
|
|
26
|
+
* @param ownDeclared ownable names the product declares in any file: each stays as written and its declarations are reported
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyCssTable(text: string, fileName: string, table: RenameTable, ownDeclared?: Set<string>): CssResult;
|
package/dist/upgrade/css.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`&&
|
|
1
|
+
import{present as e}from"../present.js";var t=new Set([`.css`,`.scss`,`.sass`,`.less`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.ts`,`.tsx`,`.mts`,`.cts`,`.cshtml`,`.razor`,`.html`,`.vue`,`.json`]),n=new Set([`node_modules`,`dist`,`bin`,`obj`,`.git`,`.next`,`coverage`]);function r(e,t,n){for(let r=0;r+1<e.length;r++)if(e[r]===t&&e[r+1]===n)return!0;return!1}function i(i){let a=i.replace(/\\/g,`/`).split(`/`);if(a.some(e=>n.has(e))||r(a,`wwwroot`,`lib`))return!1;let o=e(a[a.length-1],`file name of the path`).match(/\.[^.]+$/),s=o?o[0].toLowerCase():``;return s===`.css`&&r(a,`wwwroot`,`css`)?!1:t.has(s)}var a=/^\s*:/;function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function s(e){return[...e].sort((e,t)=>t.length-e.length).map(o).join(`|`)}function c(t,n,r){let a=r.css.ownable??[];if(a.length===0||!i(n))return new Set;let o=RegExp(`(?<![\\w-])(${s(a)})\\s*:`,`g`);return new Set(Array.from(t.matchAll(o),t=>e(t[1],`ownable name in a declaration`)))}function l(t,n,r,o=new Set){if(!i(n))return{text:t,hits:[],choose:[],checkRole:[]};let{rename:c,reads:l,choose:u,checkRole:d}=r.css,f=new Map;for(let[e,t]of l)f.set(e,t);for(let[e,t]of c)f.set(e,t);let p=new Set(l.map(([e])=>e)),m=new Set([...c.map(([e])=>e),...Object.keys(u)]),h=[];if(p.size>0&&h.push(`(?<=var\\(\\s*)(${s(p)})(?![\\w-])`),m.size>0&&h.push(`(?<![\\w-])(${s(m)})(?![\\w-])`),h.length===0)return{text:t,hits:[],choose:[],checkRole:[]};let g=new RegExp(h.join(`|`),`g`),_=new Set(d),v=new Set(r.css.ownable??[]),y=[],b=[],x=[],S=1,C=0;return{text:t.replace(g,(n,...r)=>{let i=e(r[r.length-2],`match offset`);if(typeof i!=`number`)throw Error(`webority-tokens: match offset is missing.`);for(;C<i;C++)t[C]===`
|
|
2
|
+
`&&S++;if(Object.hasOwn(u,n))return b.push({line:S,name:n,hint:e(u[n],`the choose hint for ${n}`)}),n;let s=e(f.get(n),`the rename target of ${n}`);return v.has(n)&&o.has(n)?(a.test(t.slice(i+n.length))&&b.push({line:S,name:n,hint:`The product declares its own ${n}, so it and its reads were left as written. If it overrides the library token, rename it to ${s} by hand.`}),n):(y.push({line:S,from:n,to:s}),_.has(s)&&x.push({line:S,from:n,to:s}),s)}),hits:y,choose:b,checkRole:x}}export{t as CSS_TARGET_EXTENSIONS,l as applyCssTable,i as isCssTarget,c as ownDeclarations};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** The options `upgrade` takes; the command line passes the same shape. */
|
|
2
|
+
export interface UpgradeOptions {
|
|
3
|
+
version: string;
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
/** An app folder inside the repo, relative to root. */
|
|
6
|
+
app?: string;
|
|
7
|
+
paths?: string[];
|
|
8
|
+
/** Wrapper package name to the library package its rules name: `{ "@acme/ui": "@webority/ui-react" }`. */
|
|
9
|
+
aliases?: Record<string, string>;
|
|
10
|
+
/** Path of a JSON file for the command line to write the UpgradeResult to; upgrade() ignores it. */
|
|
11
|
+
report?: string;
|
|
12
|
+
/** Defaults to process.cwd(). */
|
|
13
|
+
root?: string;
|
|
14
|
+
}
|
|
15
|
+
/** One rewrite upgrade made, or would make on a dry run. */
|
|
16
|
+
export interface UpgradeHit {
|
|
17
|
+
file: string;
|
|
18
|
+
line: number;
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
}
|
|
22
|
+
/** A use upgrade cannot rewrite on its own; a person picks the new name. */
|
|
23
|
+
export interface UpgradeChoice {
|
|
24
|
+
file: string;
|
|
25
|
+
line: number;
|
|
26
|
+
name: string;
|
|
27
|
+
hint: string;
|
|
28
|
+
}
|
|
29
|
+
export interface UpgradeResult {
|
|
30
|
+
hits: UpgradeHit[];
|
|
31
|
+
choose: UpgradeChoice[];
|
|
32
|
+
changedFiles: string[];
|
|
33
|
+
}
|
|
34
|
+
type Log = (line: string) => void;
|
|
35
|
+
type RunResult = {
|
|
36
|
+
status: number | null;
|
|
37
|
+
};
|
|
38
|
+
type CommandRunner = (cmd: string, args: string[], opts: {
|
|
39
|
+
cwd: string;
|
|
40
|
+
}) => RunResult | Promise<RunResult>;
|
|
41
|
+
type ReenterArgs = {
|
|
42
|
+
appRoot: string;
|
|
43
|
+
designRoot: string;
|
|
44
|
+
app: string | undefined;
|
|
45
|
+
version: string;
|
|
46
|
+
dryRun: boolean;
|
|
47
|
+
from: string;
|
|
48
|
+
aliases: Record<string, string>;
|
|
49
|
+
};
|
|
50
|
+
export interface UpgradeDeps {
|
|
51
|
+
run?: CommandRunner;
|
|
52
|
+
reenter?: (arg: ReenterArgs) => Promise<UpgradeResult>;
|
|
53
|
+
brand?: (arg: {
|
|
54
|
+
root: string;
|
|
55
|
+
}) => Promise<unknown>;
|
|
56
|
+
log?: Log;
|
|
57
|
+
renamesDir?: string;
|
|
58
|
+
ownVersion?: () => string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param deps test seams: the install runner, the second stage, the brand step, the log sink, the renames folder and the tool's own version.
|
|
62
|
+
*/
|
|
63
|
+
export declare function upgrade(options: UpgradeOptions, deps?: UpgradeDeps): Promise<UpgradeResult>;
|
|
64
|
+
export {};
|
package/dist/upgrade/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{brand as e}from"../build.js";import{
|
|
1
|
+
import{brand as e}from"../build.js";import{present as t}from"../present.js";import{applyClasses as n}from"./classes.js";import{applyComponents as r}from"./components.js";import{applyCssTable as i,isCssTarget as a,ownDeclarations as o}from"./css.js";import{applyRazorAttributes as s}from"./razorAttributes.js";import{applyRazorTags as c}from"./razorTags.js";import{applyRazorValueSplits as l}from"./razorValueSplits.js";import{applyMarkup as u,applySource as d}from"./source.js";import{applyComponentProps as f,applyPropSplits as p,applyPropValues as m,applyProps as h,applyThemeReads as g}from"./themeReads.js";import{applyValueSplits as _}from"./valueSplits.js";import{applyWrapperValues as v,findWrappers as y}from"./wrapperValues.js";import{createRequire as b}from"node:module";import{existsSync as x,readFileSync as S,readdirSync as C,realpathSync as w,writeFileSync as T}from"node:fs";import{dirname as E,isAbsolute as D,join as O,relative as k,resolve as A,sep as j}from"node:path";import{fileURLToPath as M,pathToFileURL as N}from"node:url";import{spawnSync as P}from"node:child_process";var F=/^\d+\.\d+\.\d+$/,I=/^(?:workspace:|file:|link:)/,L=`WEBORITY_UPGRADE_FROM`;function R(e){if(typeof e!=`string`||!F.test(e))throw Error(`invalid version "${e}"`)}function z(e,n){R(e),R(n);let r=e.split(`.`).map(Number),i=n.split(`.`).map(Number);for(let e=0;e<3;e++)if(r[e]!==i[e])return t(r[e],`version part`)-t(i[e],`version part`);return 0}function B(){let e=E(M(import.meta.url));for(;;){let t=O(e,`package.json`);if(x(t)&&JSON.parse(S(t,`utf8`)).name===`@webority/tokens`)return e;let n=E(e);if(n===e)throw Error(`cannot find the @webority/tokens package folder`);e=n}}function V(){return JSON.parse(S(O(B(),`package.json`),`utf8`)).version}function H(e){let t=[];for(let n of C(e)){if(!n.endsWith(`.json`))continue;let r=n.slice(0,-5);F.test(r)&&t.push({version:r,table:JSON.parse(S(O(e,n),`utf8`))})}return t.sort((e,t)=>z(e.version,t.version))}function U(e,t){let n=P(`git`,[`ls-files`,`-z`,`--`,...t],{cwd:e,encoding:`utf8`,windowsHide:!0,maxBuffer:67108864});if(n.status!==0)throw Error(`not a git repository: ${e}`);let r=n.stdout.split(`\0`).filter(Boolean).map(e=>e.split(`\\`).join(`/`)).filter(t=>x(O(e,t)));return[...new Set(r)]}function W(e,t){let n=U(e,t??[`.`]);if(t!==void 0&&n.length===0)throw Error(`no tracked files under ${t.join(`, `)}`);return n}function G(e){return e.split(`/`).includes(`node_modules`)}var K=new Set([`node_modules`,`vendor`,`vendors`,`external`]),q=/\.(?:min|bundle)\.(?:js|css)$/,J=new Set([`lib`,`theme`]);function Y(e){let t=e.split(`/`);return t.some(e=>K.has(e))||t.some((e,n)=>{let r=t[n+1];return e===`wwwroot`&&r!==void 0&&J.has(r)})?!0:q.test(e)}function X(e,t){return[...new Set([...e,...t])]}function Z(e,t,n){return H(e).filter(e=>z(e.version,t)>0&&z(e.version,n)<=0).map(e=>e.table)}function ee(e,t){let n=Object.entries(t);if(n.length===0)return e;let r=(e,t)=>e.flatMap(e=>[e,...n.filter(([,n])=>e[t]===n).map(([n])=>({...e,[t]:n}))]),i={...e};return e.props!==void 0&&(i.props=r(e.props,`package`)),e.componentProps!==void 0&&(i.componentProps=r(e.componentProps,`package`)),e.propValues!==void 0&&(i.propValues=r(e.propValues,`package`)),e.propSplits!==void 0&&(i.propSplits=r(e.propSplits,`package`)),e.valueSplits!==void 0&&(i.valueSplits=r(e.valueSplits,`package`)),e.components!==void 0&&(i.components=r(e.components,`package`)),e.source!==void 0&&(i.source={...e.source,flags:r(e.source.flags,`importedFrom`)}),i}function Q(e,b,x,C,w,E={}){C&&w(`dry run: nothing written`);let D=x.map(e=>ee(e,E)),k=[],A=[],j=[],M=b.filter(e=>a(e)&&!Y(e)),N=D.map(()=>new Set);if(D.some(e=>(e.css.ownable??[]).length>0))for(let n of M){let r=S(O(e,n),`utf8`);D.forEach((e,i)=>{for(let a of o(r,n,e))t(N[i],`own declarations of a rename table`).add(a)})}let P=U(e,[`package.json`,`:(glob)**/package.json`]).filter(e=>!G(e)),F=new Map,I=D.map(t=>y(e,[...M,...P],t,F));for(let a of M){let o=S(O(e,a),`utf8`),y=o,b=e=>{for(let t of e)t.from!==t.to&&(k.push({file:a,line:t.line,from:t.from,to:t.to}),w(`${a}:${t.line} ${t.from} -> ${t.to}`))},x=e=>{A.push({file:a,line:e.line,name:e.name,hint:e.hint}),w(`choose ${a}:${e.line} ${e.name}: ${e.hint}`)},E=e=>{for(let t of e)t.message.startsWith(`skipped, it does not parse`)?w(`skipped ${a}: ${t.message}`):x({line:t.line,name:t.path,hint:t.message})};for(let[e,o]of D.entries()){let S=i(y,a,o,N[e]);y=S.text,b(S.hits);for(let e of S.choose)x(e);for(let e of S.checkRole)w(`verify ${a}:${e.line} ${e.from} -> ${e.to}`);let C=g(y,a,o.themeReads);y=C.text,b(C.hits),E(C.findings);let T=[n=>v(n,a,t(I[e],`wrapper index of a rename table`)),e=>h(e,a,o.props),e=>f(e,a,o.componentProps),e=>m(e,a,o.propValues),e=>_(e,a,o.valueSplits??[]),e=>p(e,a,o.propSplits),e=>s(e,a,o.razorAttributes),e=>r(e,a,o.components??[]),e=>c(e,a,o.razorTags??[]),e=>l(e,a,o.razorValueSplits??[]),e=>n(e,a,o.classes??[]),e=>u(e,a,o.markup),e=>d(e,a,o.source)];for(let e of T){let t=e(y);y=t.text,b(t.hits),E(t.findings)}}y!==o&&(j.push(a),C||T(O(e,a),y,`utf8`))}return{hits:k,choose:A,changedFiles:j}}function te(e){let n=/^([ \t]+)\S/m.exec(e);return n?t(n[1],`indentation of a package.json`):4}function ne(e,t,n,r,i){let a=[];for(let o of U(e,[`package.json`,`:(glob)**/package.json`])){if(G(o))continue;let s=S(O(e,o),`utf8`),c=JSON.parse(s),l=!1;for(let e of[`dependencies`,`devDependencies`]){let r=c[e];if(r)for(let e of n.npm){if(!Object.hasOwn(r,e))continue;let n=r[e];I.test(n)||n===t||(r[e]=t,l=!0,i(`pin ${o}: ${e} ${n} -> ${t}`))}}if(l&&(a.push(o),r)){let t=JSON.stringify(c,null,te(s));s.endsWith(`
|
|
2
2
|
`)&&(t+=`
|
|
3
3
|
`),s.includes(`\r
|
|
4
4
|
`)&&(t=t.replace(/\n/g,`\r
|
|
5
|
-
`)),
|
|
5
|
+
`)),T(O(e,o),t,`utf8`)}}return a}function re(e,t,n,r,i){let a=[];for(let o of U(e,[`Directory.Packages.props`,`:(glob)**/Directory.Packages.props`])){if(G(o))continue;let s=S(O(e,o),`utf8`),c=!1,l=s.replace(/<PackageVersion\b[^>]*>/g,e=>{let r=/\sInclude="([^"]*)"/.exec(e)?.[1],a=/\sVersion="([^"]*)"/.exec(e)?.[1];if(r===void 0||a===void 0)return e;let s=/^\[([^\]]*)\]$/.exec(a),l=s?s[1]:a,u=s?`[${t}]`:t;return!n.nuget.includes(r)||l===t?e:(i(`pin ${o}: ${r} ${a} -> ${u}`),c=!0,e.replace(/(\sVersion=")[^"]*(")/,`$1${u}$2`))});c&&(a.push(o),r&&T(O(e,o),l,`utf8`))}return a}function ie(e){let t;try{t=b(O(e,`package.json`)).resolve(`@webority/repo-checks/lockstep.json`)}catch{throw Error(`add @webority/repo-checks at the lockstep version and run again`)}let n=JSON.parse(S(t,`utf8`));if(!ae(n))throw Error(`${t} must hold { npm: string[], nuget: string[] }`);return n}function $(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function ae(e){return typeof e!=`object`||!e||!(`npm`in e)||!(`nuget`in e)?!1:$(e.npm)&&$(e.nuget)}var oe=[{file:`pnpm-lock.yaml`,manager:`pnpm`,command:[`corepack`,`pnpm`,`install`]},{file:`package-lock.json`,manager:`npm`,command:[`npm`,`install`]}];function se(e){let n=oe.filter(t=>x(O(e,t.file)));if(n.length===0)throw Error(`no pnpm-lock.yaml or package-lock.json in ${e}`);if(n.length>1)throw Error(`${e} has both ${t(n[0],`first lockfile entry`).file} and ${t(n[1],`second lockfile entry`).file}; keep one lockfile`);return t(n[0],`lockfile entry`)}function ce(e,t){let n=A(e,t),r=k(e,n);if(r===``||D(r)||r.split(j)[0]===`..`)throw Error(`--app ${t}: give a folder inside the repo root`);if(!x(O(n,`package.json`)))throw Error(`--app ${t}: no package.json in that folder`);return n}function le(e,t,n){return P(e,t,{cwd:n.cwd,env:process.env,stdio:`inherit`,windowsHide:!0,shell:process.platform===`win32`})}async function ue({appRoot:e,designRoot:t,app:n,version:r,from:i,aliases:a}){let o=w.native(O(e,`node_modules`,`@webority`,`tokens`)),s=JSON.parse(S(O(o,`package.json`),`utf8`))?.exports?.[`.`],c=typeof s==`string`?s:s?.default;if(typeof c!=`string`)throw Error(`cannot find the installed @webority/tokens entry`);process.env[L]=i;try{return await(await import(N(O(o,c)).href)).upgrade({root:t,app:n,version:r,dryRun:!1,aliases:a})}finally{delete process.env[L]}}async function de({root:e,designRoot:t,version:n,dryRun:r,from:i,dir:a,log:o,brandFn:s,aliases:c}){let l=Z(a,i,n),u=Q(e,W(e),l,r,o,c);return r||await s({root:t}),u}async function fe({root:e,designRoot:n,app:r,version:i,dryRun:a,deps:o,log:s,aliases:c}){let l=O(e,`node_modules`,`@webority`,`tokens`,`package.json`);if(!x(l))throw Error(`@webority/tokens is not installed; add it at the lockstep version and run again`);let u=JSON.parse(S(l,`utf8`)).version,d=ie(e),f=a?null:se(e),p=[...ne(e,i,d,!a,s),...re(e,i,d,!a,s)];if(a){s(`dry run: install skipped; tables are those of the installed ${u}`);let t=Z(o.renamesDir??O(e,`node_modules`,`@webority`,`tokens`,`renames`),u,i),n=Q(e,W(e),t,!0,s,c);return{...n,changedFiles:X(p,n.changedFiles)}}if(f===null)throw Error(`webority-tokens: package manager is missing.`);let m=o.run??le,[h,...g]=f.command,{status:_}=await m(t(h,`install command`),g,{cwd:e});if(_!==0)throw Error(`${f.manager} install failed with exit code ${_}`);let v=await(o.reenter??ue)({appRoot:e,designRoot:n,app:r,version:i,dryRun:!1,from:u,aliases:c});return{...v,changedFiles:X(p,v.changedFiles)}}async function pe(t,n={}){let r=t.version;R(r);let i=t.root??process.cwd(),a=t.app===void 0?i:ce(i,t.app),o=t.dryRun??!1,s=t.aliases??{},c=n.log??(e=>process.stdout.write(`${e}\n`)),l=()=>n.renamesDir??O(B(),`renames`);if(Array.isArray(t.paths)&&t.paths.length>0){let e=H(l()).filter(e=>e.version===r).map(e=>e.table);if(e.length===0&&r!==(n.ownVersion??V)())throw Error(`no rename table for ${r}`);return Q(a,W(a,t.paths),e,o,c,s)}if(!x(O(i,`.webority`,`design.json`)))throw Error(`write .webority/design.json (design-map.md) and run again`);let u=process.env[L];return u?de({root:a,designRoot:i,version:r,dryRun:o,from:u,dir:l(),log:c,brandFn:n.brand??e,aliases:s}):fe({root:a,designRoot:i,app:t.app,version:r,dryRun:o,deps:n,log:c,aliases:s})}export{pe as upgrade};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RenameTable } from "../../renames/renames.d.ts";
|
|
2
|
+
export type RazorAttributeHit = {
|
|
3
|
+
line: number;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
};
|
|
7
|
+
export type RazorAttributeFinding = {
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
path: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export type RazorAttributeResult = {
|
|
14
|
+
text: string;
|
|
15
|
+
hits: RazorAttributeHit[];
|
|
16
|
+
findings: RazorAttributeFinding[];
|
|
17
|
+
};
|
|
18
|
+
/** @param file repo-relative, forward slashes */
|
|
19
|
+
export declare function applyRazorAttributes(source: string, file: string, rules: RenameTable["razorAttributes"]): RazorAttributeResult;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{present as e}from"../present.js";import{tagOccurrences as t}from"./tagScan.js";var n=new Set([`.cshtml`,`.razor`]);function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function i(e){let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``}function a(e){let t=[];for(let n=e.indexOf(`
|
|
2
2
|
`);n!==-1;n=e.indexOf(`
|
|
3
|
-
`,n+1))t.push(n);return t}function
|
|
3
|
+
`,n+1))t.push(n);return t}function o(t,n){let r=0,i=t.length;for(;r<i;){let a=r+i>>1;e(t[a],`newline offset`)<n?r=a+1:i=a}return r+1}function s(e,t){return e<t?-1:+(e>t)}function c(c,l,u){if(u.length===0||!n.has(i(l)))return{text:c,hits:[],findings:[]};let d=a(c),f=[],p=[],m=[];for(let n of u){let i=n.attribute,a=n.values,s=r(i),u=RegExp(`(?<=\\s)${s}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`,`g`),h=RegExp(`(?<=\\s)${s}(?=[\\s/]|$)(?!\\s*=)`,`g`),g=(e,t)=>({file:l,line:t,path:`<${e}> ${i}`,message:`${i} takes a named value such as "${n.values.true}" or "${n.values.false}" now, not a boolean; set it by hand`});for(let r of n.tags)for(let{nameEnd:n,end:s}of t(c,r)){if(s===-1){m.push({file:l,line:o(d,n),path:`<${r}> ${i}`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let t=c.slice(n,s);for(let s of t.matchAll(u)){let t=n+s.index,c=o(d,t),l=e(s[1]??s[2],`Razor attribute value`),u=t+s[0].length-1,h=u-l.length,_=l.toLowerCase();if(Object.hasOwn(a,_)){let t=e(a[_],`the razor attribute value`);f.push({start:h,end:u,text:t}),p.push({line:c,from:`${i}="${l}"`,to:`${i}="${t}"`})}else l.startsWith(`@`)&&m.push(g(r,c))}for(let e of t.matchAll(h))m.push(g(r,o(d,n+e.index)))}}f.sort((e,t)=>t.start-e.start);let h=c;for(let e of f)h=h.slice(0,e.start)+e.text+h.slice(e.end);return p.sort((e,t)=>e.line-t.line||s(e.from,t.from)),m.sort((e,t)=>e.line-t.line||s(e.path,t.path)),{text:h,hits:p,findings:m}}export{c as applyRazorAttributes};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RazorTagRule } from "../../renames/renames.d.ts";
|
|
2
|
+
export type RazorTagHit = {
|
|
3
|
+
line: number;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
};
|
|
7
|
+
export type RazorTagFinding = {
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
path: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export type RazorTagResult = {
|
|
14
|
+
text: string;
|
|
15
|
+
hits: RazorTagHit[];
|
|
16
|
+
findings: RazorTagFinding[];
|
|
17
|
+
};
|
|
18
|
+
/** @param file repo-relative, forward slashes */
|
|
19
|
+
export declare function applyRazorTags(source: string, file: string, rules: RazorTagRule[]): RazorTagResult;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{findQuoteEnd as
|
|
2
|
-
`&&t.push(n+1);return t},
|
|
1
|
+
import{present as e}from"../present.js";import{findQuoteEnd as t,tagOccurrences as n}from"./tagScan.js";var r=new Set([`.cshtml`,`.razor`]),i=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,a=/[^\s"'>]+/y,o=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),s=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},c=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
2
|
+
`&&t.push(n+1);return t},l=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`line start`)<=n?r=a:i=a-1}return r+1},u=(e,t)=>e<t?-1:+(e>t);function d(n,r,o){let s=[],c=r;for(;;){i.lastIndex=c;let r=i.exec(n);if(r===null)break;let l=e(r[2],`the attribute name`),u=r.index+e(r[1],`the whitespace before the attribute name`).length,d=u+l.length,f={name:l,nameStart:u,nameEnd:d,wsStart:r.index,kind:`none`,attrEnd:d},p=r.index+r[0].length;if(r[3]!==void 0&&(n[p]===`"`||n[p]===`'`)){let e=t(n,p);if(e===-1)break;f.kind=`quoted`,f.value=n.slice(p+1,e),f.valueStart=p+1,f.valueEnd=e,f.attrEnd=e+1}else if(r[3]!==void 0){a.lastIndex=p;let e=a.exec(n);e!==null&&(f.kind=`bare`,f.attrEnd=p+e[0].length)}if(f.attrEnd>o)break;s.push(f),c=f.attrEnd}return s}function f(t,r,i,a){let s=[],c=[],u=[],f=t=>Object.hasOwn(r.renameAttributes,t)?e(r.renameAttributes[t],`the renamed attribute`):t,p=r.from!==r.to,m=n(t,r.from),h=m.filter(e=>e.end===-1);if(h.length>0){for(let{nameEnd:e}of h)u.push({file:a,line:l(i,e),path:`<${r.from}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); rename it by hand`});return{edits:[],hits:[],findings:u}}for(let{nameEnd:n,end:o}of m){let m=l(i,n),h=t.slice(n,o).trimEnd().endsWith(`/`),g=d(t,n,o);for(let[e,t]of Object.entries(r.removeAttributes))g.some(t=>t.name===e)&&u.push({file:a,line:m,path:`<${r.from}> ${e}`,message:t});let _=[];for(let e of g){let t=f(e.name);t!==e.name&&(s.push({start:e.nameStart,end:e.nameEnd,text:t}),c.push({line:l(i,e.nameStart),from:e.name,to:t}))}let v=g.map(e=>f(e.name));for(let t of g){let n=f(t.name),a=Object.hasOwn(r.valueMaps,n)?r.valueMaps[n]:void 0;if(t.kind!==`quoted`||a===void 0||t.value===void 0||!Object.hasOwn(a,t.value))continue;let o=e(a[t.value],`the mapped value`),u=e(t.valueStart,`the start of the quoted value`);s.push({start:u,end:e(t.valueEnd,`the end of the quoted value`),text:o}),c.push({line:l(i,u),from:`${n}="${t.value}"`,to:`${n}="${o}"`})}for(let[e,t]of Object.entries(r.addAttributes))v.includes(e)||_.push(` ${e}="${t}"`);_.length>0&&s.push({start:n,end:n,text:_.join(``)}),(p||_.length>0)&&c.push({line:m,from:`<${r.from}`,to:`<${r.to}${_.join(``)}`}),p&&s.push({start:n-r.from.length,end:n,text:r.to});let y=r.attributeToContent===void 0?void 0:g.find(e=>e.name===r.attributeToContent);if(y===void 0)continue;if(y.kind!==`quoted`){u.push({file:a,line:m,path:`<${r.from}> ${y.name}`,message:`${y.name} must hold a value that becomes the element content; set it by hand`});continue}if(s.push({start:y.wsStart,end:y.attrEnd,text:``}),c.push({line:m,from:`${y.name}="${y.value}"`,to:`element content`}),h){let e=t.lastIndexOf(`/`,o);for(;/\s/.test(t[e-1]??``);)e--;s.push({start:e,end:o+1,text:`>${y.value}</${r.to}>`});continue}let b=t.indexOf(`</${r.from}`,o+1);if(b===-1)throw Error(`no closing </${r.from}> for the element at ${a}:${m}`);t.slice(o+1,b).trim()===``?s.push({start:o+1,end:b,text:e(y.value,`the value of the moved attribute`)}):(u.push({file:a,line:m,path:`<${r.from}> ${y.name}`,message:`the element already has content; move ${y.name} into it by hand`}),s.pop(),c.pop())}if(p)for(let e of t.matchAll(RegExp(`</${o(r.from)}(?=\\s*>)`,`g`))){let t=e.index+2;s.push({start:t,end:t+r.from.length,text:r.to}),c.push({line:l(i,t),from:`</${r.from}`,to:`</${r.to}`})}return{edits:s,hits:c,findings:u}}function p(e,t,n){let{edits:r,hits:i,findings:a}=f(e,n,c(e),t);r.sort((e,t)=>t.start-e.start||t.end-e.end);let o=e;for(let e of r)o=o.slice(0,e.start)+e.text+o.slice(e.end);return{text:o,hits:i,findings:a}}function m(e,t,n){if(n.length===0||!r.has(s(t)))return{text:e,hits:[],findings:[]};let i=e,a=[],o=[];for(let e of n){let n=p(i,t,e);i=n.text,a.push(...n.hits),o.push(...n.findings)}return a.sort((e,t)=>e.line-t.line||u(e.from,t.from)),o.sort((e,t)=>e.line-t.line||u(e.path,t.path)),{text:i,hits:a,findings:o}}export{m as applyRazorTags};
|