prunelle 0.6.0 → 0.7.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/LICENSE +21 -0
- package/llms.txt +48 -43
- package/package.json +4 -1
- package/src/a11y/declaration.ts +106 -72
- package/src/a11y/index.ts +59 -39
- package/src/a11y/rgaa-map.ts +95 -49
- package/src/build/bundle.ts +8 -4
- package/src/build/byte-size.ts +11 -0
- package/src/build/client-plugin.ts +3 -1
- package/src/build/compile.ts +2 -1
- package/src/build/ecoindex.ts +15 -14
- package/src/build/files.ts +6 -0
- package/src/build/first-load.ts +83 -11
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +57 -18
- package/src/build/island-promote.ts +229 -0
- package/src/build/islands.ts +9 -201
- package/src/build/manifest.ts +4 -125
- package/src/build/plugin-host.ts +21 -8
- package/src/build/precompress.ts +1 -1
- package/src/build/prerender.ts +97 -44
- package/src/build/reach.ts +136 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +19 -3
- package/src/build/static-headers.ts +93 -0
- package/src/build/static.ts +2 -0
- package/src/cli/check-forms.ts +97 -48
- package/src/cli/check-imports.ts +25 -0
- package/src/cli/check-links.ts +2 -2
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +33 -7
- package/src/cli/commands.ts +35 -7
- package/src/cli/docs.ts +4 -3
- package/src/cli/inspect.ts +2 -1
- package/src/cli/mcp-tools.ts +7 -5
- package/src/cli/mcp.ts +1 -1
- package/src/cli/new.ts +14 -3
- package/src/cli/render.ts +14 -19
- package/src/cli/upgrade.ts +22 -5
- package/src/compiler/analyze.ts +26 -5
- package/src/compiler/cacheability.ts +2 -2
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +110 -4
- package/src/compiler/compliance-urls.ts +145 -0
- package/src/compiler/compliance.ts +168 -116
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +19 -1
- package/src/compiler/props-body.ts +52 -0
- package/src/compiler/shared.ts +2 -2
- package/src/compiler/ssr.ts +2 -2
- package/src/context.ts +34 -0
- package/src/dev/error-log.ts +90 -64
- package/src/dev/host-check.ts +26 -0
- package/src/dev/index.ts +12 -5
- package/src/dev/open-editor.ts +15 -11
- package/src/dev/protocol.ts +2 -0
- package/src/dev/supervisor.ts +8 -0
- package/src/dev/watchers.ts +27 -2
- package/src/dom/action.ts +4 -1
- package/src/dom/extras.ts +1 -2
- package/src/dom/index.ts +13 -2
- package/src/dom/island.ts +22 -10
- package/src/dom/loop.ts +25 -16
- package/src/eco/declaration.ts +257 -0
- package/src/eco/index.ts +65 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +16 -1
- package/src/plugins/load.ts +4 -3
- package/src/plugins/public.ts +2 -2
- package/src/plugins/services.ts +3 -0
- package/src/plugins/types.ts +17 -2
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +38 -37
- package/src/server/action.ts +11 -127
- package/src/server/app-secret.ts +63 -0
- package/src/server/compress.ts +5 -1
- package/src/server/consent.ts +59 -22
- package/src/server/cookies.ts +16 -2
- package/src/server/env.ts +14 -0
- package/src/server/errors.ts +3 -1
- package/src/server/form-schema.ts +1 -1
- package/src/server/health.ts +46 -15
- package/src/server/http.ts +47 -7
- package/src/server/index.ts +52 -30
- package/src/server/loader.ts +6 -2
- package/src/server/plugin-host.ts +3 -1
- package/src/server/public.ts +4 -3
- package/src/server/rate-limit.ts +52 -9
- package/src/server/route-cache.ts +26 -4
- package/src/server/route-table.ts +7 -3
- package/src/server/routing.ts +3 -87
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +71 -20
- package/src/server/serve-handlers.ts +14 -4
- package/src/server/start.ts +1 -1
- package/src/server/static-dir.ts +27 -4
- package/src/server/stream.ts +28 -6
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +20 -4
- package/src/ssr/index.ts +18 -0
- package/src/ssr/navigation.ts +2 -2
- package/src/style.ts +32 -1
- package/templates/_shared/gitignore +5 -0
- package/templates/_shared/src/routes/legal.tsx +10 -1
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +2 -1
- package/templates/app/prunelle.config.ts +2 -0
- package/templates/app/src/auth.ts +4 -6
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +9 -1
- package/templates/app/src/routes/dashboard/index.tsx +42 -8
- package/templates/app/src/routes/login.tsx +49 -30
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +8 -1
- package/templates/app/tests/app.test.ts +44 -3
- package/templates/blog/package.json +1 -1
- package/templates/blog/src/routes/_layout.tsx +6 -1
- package/templates/blog/src/routes/index.tsx +1 -1
- package/templates/blog/src/styles/app.css +6 -1
- package/templates/fullstack/package.json +1 -1
- package/templates/fullstack/src/components/GreetForm.tsx +2 -1
- package/templates/fullstack/src/routes/_layout.tsx +4 -0
- package/templates/fullstack/src/styles/app.css +11 -1
- package/templates/minimal/package.json +1 -1
- package/templates/minimal/src/routes/_layout.tsx +4 -0
- package/templates/minimal/src/styles/app.css +11 -1
package/src/a11y/rgaa-map.ts
CHANGED
|
@@ -19,8 +19,10 @@ export const RGAA_CRITERIA: Readonly<Record<string, RgaaCriterion>> = {
|
|
|
19
19
|
'3.1': { id: '3.1', theme: 3, label: 'Information non donnée uniquement par la couleur' },
|
|
20
20
|
'3.2': { id: '3.2', theme: 3, label: 'Contraste suffisant entre texte et arrière-plan' },
|
|
21
21
|
'4.1': { id: '4.1', theme: 4, label: 'Transcription textuelle ou audiodescription des médias temporels' },
|
|
22
|
+
'4.3': { id: '4.3', theme: 4, label: 'Sous-titres synchronisés des médias temporels synchronisés' },
|
|
22
23
|
'4.10': { id: '4.10', theme: 4, label: 'Contrôle des sons déclenchés automatiquement' },
|
|
23
24
|
'5.1': { id: '5.1', theme: 5, label: 'Résumé des tableaux de données complexes' },
|
|
25
|
+
'5.2': { id: '5.2', theme: 5, label: 'Pertinence du résumé des tableaux de données complexes' },
|
|
24
26
|
'5.3': { id: '5.3', theme: 5, label: 'Compréhension du contenu linéarisé des tableaux de mise en forme' },
|
|
25
27
|
'5.4': { id: '5.4', theme: 5, label: 'Association du titre au tableau de données' },
|
|
26
28
|
'5.6': { id: '5.6', theme: 5, label: 'Déclaration des en-têtes de colonnes et de lignes des tableaux' },
|
|
@@ -34,127 +36,155 @@ export const RGAA_CRITERIA: Readonly<Record<string, RgaaCriterion>> = {
|
|
|
34
36
|
'8.4': { id: '8.4', theme: 8, label: 'Pertinence du code de langue par défaut' },
|
|
35
37
|
'8.5': { id: '8.5', theme: 8, label: 'Présence d\'un titre de page (<title>)' },
|
|
36
38
|
'8.7': { id: '8.7', theme: 8, label: 'Indication des changements de langue dans le code source' },
|
|
39
|
+
'8.8': { id: '8.8', theme: 8, label: 'Validité et pertinence du code de langue des changements de langue' },
|
|
37
40
|
'9.1': { id: '9.1', theme: 9, label: 'Structuration de l\'information par les titres (h1–h6)' },
|
|
38
41
|
'9.2': { id: '9.2', theme: 9, label: 'Cohérence de la structure et des zones principales (landmarks)' },
|
|
39
42
|
'9.3': { id: '9.3', theme: 9, label: 'Structuration correcte des listes' },
|
|
40
43
|
'10.1': { id: '10.1', theme: 10, label: 'Utilisation des feuilles de styles pour contrôler la présentation' },
|
|
41
44
|
'10.4': { id: '10.4', theme: 10, label: 'Lisibilité du texte lors d\'un agrandissement jusqu\'à 200 %' },
|
|
45
|
+
'10.6': { id: '10.6', theme: 10, label: 'Visibilité des liens dont la nature n\'est pas évidente par rapport au texte environnant' },
|
|
46
|
+
'10.8': { id: '10.8', theme: 10, label: 'Contenus cachés destinés à être ignorés par les technologies d\'assistance' },
|
|
42
47
|
'10.11': { id: '10.11', theme: 10, label: 'Présentation sans perte d\'information ni défilement horizontal (reflow)' },
|
|
43
48
|
'10.13': { id: '10.13', theme: 10, label: 'Contrôle des contenus additionnels au focus ou au survol' },
|
|
44
49
|
'11.1': { id: '11.1', theme: 11, label: 'Étiquette associée à chaque champ de formulaire' },
|
|
50
|
+
'11.2': { id: '11.2', theme: 11, label: 'Pertinence de l\'étiquette associée à chaque champ de formulaire' },
|
|
45
51
|
'11.5': { id: '11.5', theme: 11, label: 'Regroupement des champs de même nature dans les formulaires' },
|
|
52
|
+
'11.9': { id: '11.9', theme: 11, label: 'Pertinence de l\'intitulé de chaque bouton' },
|
|
46
53
|
'11.13': { id: '11.13', theme: 11, label: 'Déduction de la finalité des champs de saisie (autocomplete)' },
|
|
47
54
|
'12.6': { id: '12.6', theme: 12, label: 'Accès et évitement des zones de regroupement de contenus' },
|
|
48
55
|
'12.7': { id: '12.7', theme: 12, label: 'Lien d\'évitement ou d\'accès rapide au contenu principal' },
|
|
49
56
|
'12.8': { id: '12.8', theme: 12, label: 'Cohérence de l\'ordre de tabulation' },
|
|
50
57
|
'13.1': { id: '13.1', theme: 13, label: 'Contrôle par l\'utilisateur de chaque limite de temps' },
|
|
51
58
|
'13.8': { id: '13.8', theme: 13, label: 'Contrôle des contenus en mouvement ou clignotants' },
|
|
59
|
+
'13.9': { id: '13.9', theme: 13, label: 'Consultation du contenu quelle que soit l\'orientation de l\'écran' },
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Direct lookup from axe-core rule ID to one or more RGAA 4.1 criterion IDs.
|
|
64
|
+
* A rule axe-core tags `RGAA-x.y.z` maps to what axe names, and `a11y-audit.test.ts` fails when an axe-core upgrade moves one; the rest are axe best-practice rules mapped here.
|
|
65
|
+
*/
|
|
55
66
|
export const AXE_TO_RGAA: Readonly<Record<string, readonly string[]>> = {
|
|
56
|
-
// Theme 1
|
|
67
|
+
// Theme 1 - Images
|
|
68
|
+
'area-alt': ['1.1'],
|
|
57
69
|
'image-alt': ['1.1'],
|
|
58
70
|
'input-image-alt': ['1.1'],
|
|
59
|
-
'area-alt': ['1.1'],
|
|
60
71
|
'object-alt': ['1.1'],
|
|
61
|
-
'svg-img-alt': ['1.1'],
|
|
62
72
|
'role-img-alt': ['1.1'],
|
|
63
|
-
'image-
|
|
73
|
+
'server-side-image-map': ['1.1'],
|
|
74
|
+
'svg-img-alt': ['1.1'],
|
|
64
75
|
'presentation-role-conflict': ['1.2', '7.1'],
|
|
76
|
+
'image-redundant-alt': ['1.3'],
|
|
65
77
|
|
|
66
|
-
// Theme 2
|
|
78
|
+
// Theme 2 - Cadres
|
|
67
79
|
'frame-title': ['2.1'],
|
|
68
80
|
'frame-title-unique': ['2.2'],
|
|
69
|
-
'frame-focusable-content': ['2.1', '7.3'],
|
|
70
81
|
|
|
71
|
-
// Theme 3
|
|
72
|
-
'link-in-text-block': ['3.1'],
|
|
82
|
+
// Theme 3 - Couleurs
|
|
73
83
|
'color-contrast': ['3.2'],
|
|
74
84
|
'color-contrast-enhanced': ['3.2'],
|
|
75
85
|
|
|
76
|
-
// Theme 4
|
|
86
|
+
// Theme 4 - Multimédia
|
|
77
87
|
'audio-caption': ['4.1'],
|
|
78
|
-
'video-caption': ['4.
|
|
88
|
+
'video-caption': ['4.3'],
|
|
79
89
|
'no-autoplay-audio': ['4.10'],
|
|
80
90
|
|
|
81
|
-
// Theme 5
|
|
82
|
-
'table-duplicate-name': ['5.
|
|
83
|
-
'layout-table': ['5.3'],
|
|
91
|
+
// Theme 5 - Tableaux
|
|
92
|
+
'table-duplicate-name': ['5.2'],
|
|
84
93
|
'table-fake-caption': ['5.4'],
|
|
85
94
|
'empty-table-header': ['5.6'],
|
|
86
|
-
'th-has-data-cells': ['5.6'],
|
|
87
|
-
'td-headers-attr': ['5.7'],
|
|
88
|
-
'td-has-header': ['5.7'],
|
|
89
95
|
'scope-attr-valid': ['5.7'],
|
|
96
|
+
'td-has-header': ['5.7'],
|
|
97
|
+
'td-headers-attr': ['5.7'],
|
|
98
|
+
'th-has-data-cells': ['5.7'],
|
|
90
99
|
|
|
91
|
-
// Theme 6
|
|
92
|
-
'link-name': ['6.1', '6.2'],
|
|
100
|
+
// Theme 6 - Liens
|
|
93
101
|
'identical-links-same-purpose': ['6.1'],
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
'
|
|
102
|
+
'label-content-name-mismatch': ['6.1'],
|
|
103
|
+
'link-name': ['6.2'],
|
|
104
|
+
|
|
105
|
+
// Theme 7 - Scripts & ARIA
|
|
106
|
+
'aria-allowed-attr': ['7.1'],
|
|
107
|
+
'aria-conditional-attr': ['7.1'],
|
|
108
|
+
'aria-deprecated-role': ['7.1'],
|
|
109
|
+
'aria-prohibited-attr': ['7.1'],
|
|
110
|
+
'aria-required-attr': ['7.1'],
|
|
111
|
+
'aria-roles': ['7.1'],
|
|
112
|
+
'aria-tab-name': ['7.1'],
|
|
113
|
+
'aria-toggle-field-name': ['7.1'],
|
|
114
|
+
'aria-valid-attr': ['7.1'],
|
|
115
|
+
'aria-valid-attr-value': ['7.1'],
|
|
99
116
|
'nested-interactive': ['7.1'],
|
|
117
|
+
'summary-name': ['7.1'],
|
|
118
|
+
'frame-focusable-content': ['7.3'],
|
|
100
119
|
'scrollable-region-focusable': ['7.3'],
|
|
101
|
-
'focus-order-semantics': ['7.3'],
|
|
102
120
|
|
|
103
|
-
// Theme 8
|
|
121
|
+
// Theme 8 - Éléments obligatoires
|
|
104
122
|
'duplicate-id': ['8.2'],
|
|
105
123
|
'duplicate-id-active': ['8.2'],
|
|
106
124
|
'duplicate-id-aria': ['8.2'],
|
|
107
125
|
'html-has-lang': ['8.3'],
|
|
126
|
+
'html-xml-lang-mismatch': ['8.3'],
|
|
108
127
|
'html-lang-valid': ['8.4'],
|
|
109
|
-
'html-xml-lang-mismatch': ['8.4'],
|
|
110
128
|
'document-title': ['8.5'],
|
|
111
|
-
'valid-lang': ['8.
|
|
129
|
+
'valid-lang': ['8.8'],
|
|
112
130
|
|
|
113
|
-
// Theme 9
|
|
114
|
-
'heading-order': ['9.1'],
|
|
131
|
+
// Theme 9 - Structuration de l'information
|
|
115
132
|
'empty-heading': ['9.1'],
|
|
133
|
+
'heading-order': ['9.1'],
|
|
134
|
+
'p-as-heading': ['9.1'],
|
|
116
135
|
'page-has-heading-one': ['9.1'],
|
|
117
|
-
'landmark-one-main': ['9.2'],
|
|
118
|
-
'landmark-no-duplicate-banner': ['9.2'],
|
|
119
|
-
'landmark-no-duplicate-contentinfo': ['9.2'],
|
|
120
|
-
'landmark-no-duplicate-main': ['9.2'],
|
|
121
136
|
'landmark-banner-is-top-level': ['9.2'],
|
|
122
137
|
'landmark-complementary-is-top-level': ['9.2'],
|
|
123
138
|
'landmark-contentinfo-is-top-level': ['9.2'],
|
|
124
139
|
'landmark-main-is-top-level': ['9.2'],
|
|
140
|
+
'landmark-no-duplicate-banner': ['9.2'],
|
|
141
|
+
'landmark-no-duplicate-contentinfo': ['9.2'],
|
|
142
|
+
'landmark-no-duplicate-main': ['9.2'],
|
|
143
|
+
'landmark-one-main': ['9.2'],
|
|
125
144
|
'landmark-unique': ['9.2'],
|
|
126
145
|
'region': ['9.2'],
|
|
127
|
-
'
|
|
128
|
-
'
|
|
146
|
+
'aria-required-children': ['9.3'],
|
|
147
|
+
'aria-required-parent': ['9.3'],
|
|
129
148
|
'definition-list': ['9.3'],
|
|
130
149
|
'dlitem': ['9.3'],
|
|
150
|
+
'list': ['9.3'],
|
|
151
|
+
'listitem': ['9.3'],
|
|
131
152
|
|
|
132
|
-
// Theme 10
|
|
133
|
-
'blink': ['10.1', '13.8'],
|
|
134
|
-
'marquee': ['10.1', '13.8'],
|
|
153
|
+
// Theme 10 - Présentation de l'information
|
|
135
154
|
'meta-viewport': ['10.4'],
|
|
136
155
|
'meta-viewport-large': ['10.4'],
|
|
156
|
+
'link-in-text-block': ['10.6'],
|
|
157
|
+
'aria-hidden-body': ['10.8'],
|
|
158
|
+
'aria-hidden-focus': ['10.8'],
|
|
137
159
|
'avoid-inline-spacing': ['10.11'],
|
|
138
160
|
'target-size': ['10.13'],
|
|
139
161
|
|
|
140
|
-
// Theme 11
|
|
162
|
+
// Theme 11 - Formulaires
|
|
163
|
+
'aria-input-field-name': ['11.1'],
|
|
164
|
+
'aria-meter-name': ['11.1'],
|
|
165
|
+
'aria-progressbar-name': ['11.1'],
|
|
141
166
|
'label': ['11.1'],
|
|
142
167
|
'label-title-only': ['11.1'],
|
|
143
168
|
'select-name': ['11.1'],
|
|
144
|
-
'form-field-multiple-labels': ['11.
|
|
145
|
-
'
|
|
146
|
-
'
|
|
169
|
+
'form-field-multiple-labels': ['11.2'],
|
|
170
|
+
'aria-command-name': ['11.9'],
|
|
171
|
+
'button-name': ['11.9'],
|
|
172
|
+
'input-button-name': ['11.9'],
|
|
147
173
|
'autocomplete-valid': ['11.13'],
|
|
148
174
|
|
|
149
|
-
// Theme 12
|
|
150
|
-
'skip-link': ['12.7'],
|
|
175
|
+
// Theme 12 - Navigation
|
|
151
176
|
'bypass': ['12.7'],
|
|
152
|
-
'
|
|
177
|
+
'skip-link': ['12.7'],
|
|
153
178
|
'accesskeys': ['12.8'],
|
|
179
|
+
'focus-order-semantics': ['12.8'],
|
|
180
|
+
'tabindex': ['12.8'],
|
|
154
181
|
|
|
155
|
-
// Theme 13
|
|
182
|
+
// Theme 13 - Consultation
|
|
156
183
|
'meta-refresh': ['13.1'],
|
|
157
184
|
'meta-refresh-no-exceptions': ['13.1'],
|
|
185
|
+
'blink': ['13.8'],
|
|
186
|
+
'marquee': ['13.8'],
|
|
187
|
+
'css-orientation-lock': ['13.9'],
|
|
158
188
|
}
|
|
159
189
|
|
|
160
190
|
function lookupCriteria(ids: readonly string[]): RgaaCriterion[] {
|
|
@@ -167,8 +197,24 @@ function lookupCriteria(ids: readonly string[]): RgaaCriterion[] {
|
|
|
167
197
|
return out
|
|
168
198
|
}
|
|
169
199
|
|
|
170
|
-
|
|
171
|
-
|
|
200
|
+
// `RGAA-11.9.1` names test 1 of criterion 11.9.
|
|
201
|
+
function criteriaFromTags(tags: readonly string[]): string[] {
|
|
202
|
+
const ids: string[] = []
|
|
203
|
+
for (const tag of tags) {
|
|
204
|
+
if (!tag.startsWith('RGAA-'))
|
|
205
|
+
continue
|
|
206
|
+
const id = tag.slice(5).split('.').slice(0, 2).join('.')
|
|
207
|
+
if (!ids.includes(id))
|
|
208
|
+
ids.push(id)
|
|
209
|
+
}
|
|
210
|
+
return ids
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Resolves an axe-core rule ID (e.g. `'image-alt'`, `'aria-roles'`) to its RGAA 4.1 criteria, from the result's own `RGAA-x.y.z` tags when it has them. */
|
|
214
|
+
export function rgaaCriteriaForAxeRule(ruleId: string, tags: readonly string[] = []): RgaaCriterion[] {
|
|
215
|
+
const tagged = criteriaFromTags(tags)
|
|
216
|
+
if (tagged.length > 0)
|
|
217
|
+
return lookupCriteria(tagged)
|
|
172
218
|
const exact = AXE_TO_RGAA[ruleId]
|
|
173
219
|
if (exact !== undefined)
|
|
174
220
|
return lookupCriteria(exact)
|
package/src/build/bundle.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { stampFiles, stampsMatch } from './graph'
|
|
|
17
17
|
import { entryStaticImports, hydrateStrategies, writeClientEntries } from './client-entries'
|
|
18
18
|
import { clientLeakError, islandKey } from './islands'
|
|
19
19
|
import { pluginHookError } from './plugin-host'
|
|
20
|
+
import { ensureCacheGitignore } from './precompress'
|
|
20
21
|
import { PRUNELLE_SRC_ROOT, resolvePrunelleSpecifier } from './resolve'
|
|
21
22
|
|
|
22
23
|
export interface BundleEnv {
|
|
@@ -25,6 +26,8 @@ export interface BundleEnv {
|
|
|
25
26
|
clientDir: string
|
|
26
27
|
serverDir: string
|
|
27
28
|
assetPrefix: string
|
|
29
|
+
/** `lang` from the config, handed to plugin `bunPlugins` factories. */
|
|
30
|
+
lang?: string | undefined
|
|
28
31
|
minify: boolean
|
|
29
32
|
isDev: boolean
|
|
30
33
|
nodeEnv?: string | undefined
|
|
@@ -93,11 +96,11 @@ const PRUNELLE_SCOPE_RE = /^@prunellejs\//
|
|
|
93
96
|
const LEADING_DOT_SLASH_RE = /^\.\//
|
|
94
97
|
const EXTERNAL_PRUNELLE_SPECIFIERS = new Set(['prunelle/build', 'prunelle/test'])
|
|
95
98
|
|
|
96
|
-
export function pluginBunPlugins(env: Pick<BundleEnv, 'plugins' | 'root' | 'assetPrefix' | 'minify'>, target: BuildPluginTarget): BunPlugin[] {
|
|
97
|
-
const { root, assetPrefix, minify } = env
|
|
99
|
+
export function pluginBunPlugins(env: Pick<BundleEnv, 'plugins' | 'root' | 'assetPrefix' | 'minify' | 'lang'>, target: BuildPluginTarget): BunPlugin[] {
|
|
100
|
+
const { root, assetPrefix, minify, lang } = env
|
|
98
101
|
return env.plugins.flatMap((p) => {
|
|
99
102
|
const bp = p.bunPlugins
|
|
100
|
-
return typeof bp === 'function' ? bp({ root, assetPrefix, minify, target }) : bp ?? []
|
|
103
|
+
return typeof bp === 'function' ? bp({ root, assetPrefix, minify, target, lang }) : bp ?? []
|
|
101
104
|
})
|
|
102
105
|
}
|
|
103
106
|
|
|
@@ -290,8 +293,9 @@ export async function buildClient(env: BundleEnv, standaloneCss: string[]): Prom
|
|
|
290
293
|
}
|
|
291
294
|
|
|
292
295
|
// Bun hashes an entry's path into its chunk name, so the entries sit at one path per app: a dev rebuild or a static stage then keeps every unchanged chunk name.
|
|
293
|
-
const entriesDir = join(root, '
|
|
296
|
+
const entriesDir = join(root, '.prunelle-cache/entries')
|
|
294
297
|
mkdirSync(entriesDir, { recursive: true })
|
|
298
|
+
ensureCacheGitignore(dirname(entriesDir))
|
|
295
299
|
const { entryPoints, islandEntryToKey, runtimeEntryPath, regionEntryPath } = writeClientEntries(env, entriesDir, { pluginClientEntries, regionClientEntries, hasClientOnlyHydrate, standaloneCss })
|
|
296
300
|
|
|
297
301
|
const clientLeaks = new Set<string>()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Sizes as `prunelle.config.ts` and `--max-js` take them, kept free of imports so the CLI reads them before it loads the build.
|
|
2
|
+
|
|
3
|
+
const SIZE_RE = /^(\d+(?:\.\d+)?)\s*(kb)?$/i
|
|
4
|
+
|
|
5
|
+
/** `40kb`, `40KB` or `40960` as bytes (a KB is 1024 bytes), or `undefined` when it is not a size. */
|
|
6
|
+
export function parseByteSize(raw: number | string): number | undefined {
|
|
7
|
+
if (typeof raw === 'number')
|
|
8
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : undefined
|
|
9
|
+
const match = SIZE_RE.exec(raw.trim())
|
|
10
|
+
return match === null ? undefined : Math.round(Number(match[1]) * (match[2] === undefined ? 1 : 1024))
|
|
11
|
+
}
|
|
@@ -13,6 +13,7 @@ import { resolvePrunelleSpecifier } from './resolve'
|
|
|
13
13
|
export const PRUNELLE_SPECIFIER_FILTER = /^prunelle(?:\/.*)?$/
|
|
14
14
|
export const TS_FILTER = /\.(?:ts|tsx)$/
|
|
15
15
|
const TS_LANG_RE = /\.[cm]?ts$/i
|
|
16
|
+
const BARREL_IMPORT_RE = /['"]prunelle['"]/
|
|
16
17
|
|
|
17
18
|
export interface ClientTransforms {
|
|
18
19
|
active: boolean
|
|
@@ -55,7 +56,8 @@ export function localIslandExports(targets: Iterable<{ file: string, exportName:
|
|
|
55
56
|
* Through the barrel every island reaches every module it re-exports, and Bun then places a module only some islands use (the action runtime) in the shared chunk in one build and in the island's own chunk in the next (#3598).
|
|
56
57
|
*/
|
|
57
58
|
export function directPrunelleImports(code: string, graph: ModuleGraph, filename = 'module.tsx'): string {
|
|
58
|
-
|
|
59
|
+
// Compiled DOM output imports `prunelle/internal/…` only, so it is parsed again only when the module itself imports the barrel.
|
|
60
|
+
if (!BARREL_IMPORT_RE.test(code))
|
|
59
61
|
return code
|
|
60
62
|
const barrel = resolvePrunelleSpecifier('prunelle')!
|
|
61
63
|
const lang = TS_LANG_RE.test(filename) ? 'ts' : 'tsx'
|
package/src/build/compile.ts
CHANGED
|
@@ -108,7 +108,8 @@ export async function compileExecutable(opts: CompileExecutableOptions): Promise
|
|
|
108
108
|
try {
|
|
109
109
|
res = await Bun.build({
|
|
110
110
|
entrypoints: [entryPath],
|
|
111
|
-
|
|
111
|
+
// The host passes the environment: a .env or bunfig.toml (with its preload) in whatever cwd the binary starts in is not the app's.
|
|
112
|
+
compile: { outfile, autoloadDotenv: false, autoloadBunfig: false },
|
|
112
113
|
minify: true,
|
|
113
114
|
plugins: [prunelleResolvePlugin, ...bunPlugins],
|
|
114
115
|
})
|
package/src/build/ecoindex.ts
CHANGED
|
@@ -23,10 +23,12 @@ export interface RouteEcoIndex {
|
|
|
23
23
|
weightBytes: number
|
|
24
24
|
ghgGrams: number
|
|
25
25
|
waterCl: number
|
|
26
|
+
/** Third-party requests, counted in `requests` but not in `weightBytes`. */
|
|
27
|
+
external?: number | undefined
|
|
26
28
|
url?: string | undefined
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
//
|
|
31
|
+
// The EcoIndex as computed by its reference implementation, cnumr/ecoindex_python at 8833bb3 (components/ecoindex/compute/ecoindex.py, data/quantiles.py, data/grades.py): 20-quantile tables of DOM elements, HTTP requests and transfer size in KB of 1000.
|
|
30
32
|
const QUANTILES_DOM = [
|
|
31
33
|
0, 47, 75, 159, 233, 298, 358, 417, 476, 537, 603,
|
|
32
34
|
674, 753, 843, 949, 1076, 1237, 1459, 1801, 2479, 594601,
|
|
@@ -147,17 +149,17 @@ function computeQuantile(quantiles: readonly number[], value: number): number {
|
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
function gradeForScore(score: number): EcoIndexGrade {
|
|
150
|
-
if (score >
|
|
152
|
+
if (score > 80)
|
|
151
153
|
return 'A'
|
|
152
|
-
if (score >
|
|
154
|
+
if (score > 70)
|
|
153
155
|
return 'B'
|
|
154
|
-
if (score >
|
|
156
|
+
if (score > 55)
|
|
155
157
|
return 'C'
|
|
156
|
-
if (score >
|
|
158
|
+
if (score > 40)
|
|
157
159
|
return 'D'
|
|
158
|
-
if (score >
|
|
160
|
+
if (score > 25)
|
|
159
161
|
return 'E'
|
|
160
|
-
if (score >
|
|
162
|
+
if (score > 10)
|
|
161
163
|
return 'F'
|
|
162
164
|
return 'G'
|
|
163
165
|
}
|
|
@@ -169,9 +171,9 @@ export function computeEcoIndex(inputs: EcoIndexInputs): Omit<RouteEcoIndex, 'ur
|
|
|
169
171
|
const weightBytes = Math.max(0, inputs.weightBytes)
|
|
170
172
|
const qDom = computeQuantile(QUANTILES_DOM, dom)
|
|
171
173
|
const qReq = computeQuantile(QUANTILES_REQ, requests)
|
|
172
|
-
const qSize = computeQuantile(QUANTILES_SIZE, weightBytes /
|
|
174
|
+
const qSize = computeQuantile(QUANTILES_SIZE, weightBytes / 1000)
|
|
173
175
|
const raw = 100 - (5 * (3 * qDom + 2 * qReq + qSize)) / 6
|
|
174
|
-
const score = Math.round(Math.min(100, Math.max(0, raw))
|
|
176
|
+
const score = Math.round(Math.min(100, Math.max(0, raw)))
|
|
175
177
|
const ghgGrams = Math.round((2 + (2 * (50 - score)) / 100) * 100) / 100
|
|
176
178
|
const waterCl = Math.round((3 + (3 * (50 - score)) / 100) * 100) / 100
|
|
177
179
|
return { grade: gradeForScore(score), score, dom, requests, weightBytes, ghgGrams, waterCl }
|
|
@@ -211,11 +213,10 @@ export function measureRouteEcoIndex(route: RouteManifestEntry, options: { prere
|
|
|
211
213
|
const html = raw.toString('utf8')
|
|
212
214
|
const htmlBytes = htmlServedSize(abs, raw)
|
|
213
215
|
const load = measureFirstLoad(firstLoadUrls(html), options.locate, htmlBytes)
|
|
214
|
-
const eco =
|
|
215
|
-
dom: countDomElements(html),
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
})
|
|
216
|
+
const eco = {
|
|
217
|
+
...computeEcoIndex({ dom: countDomElements(html), requests: 1 + load.files + load.external, weightBytes: load.total }),
|
|
218
|
+
...(load.external > 0 ? { external: load.external } : {}),
|
|
219
|
+
}
|
|
219
220
|
measured++
|
|
220
221
|
if (worst === undefined || isWorse(eco, worst)) {
|
|
221
222
|
worst = eco
|
package/src/build/files.ts
CHANGED
|
@@ -154,3 +154,9 @@ export function formatBunBuildLogs(logs: readonly unknown[], root?: string): str
|
|
|
154
154
|
return msg
|
|
155
155
|
}).join('\n')
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
/** Whether a `public/` path holds a dotfile or dot folder (`.env`, `.DS_Store`, `.git/`) other than under `.well-known`: the build leaves those out. */
|
|
159
|
+
export function isHiddenPublicPath(rel: string): boolean {
|
|
160
|
+
const segments = rel.split(/[\\/]/).filter(s => s !== '')
|
|
161
|
+
return segments.some((s, i) => s.startsWith('.') && !(i === 0 && s === '.well-known'))
|
|
162
|
+
}
|
package/src/build/first-load.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// What a
|
|
1
|
+
// What a visit scrolled to the bottom downloads, as served (the EcoIndex measures so): the page, the files it links, and the files those pull in (a script's static imports, a stylesheet's `url()`s), each counted once. The docs footer and `prunelle build --analyze` both measure with this.
|
|
2
2
|
|
|
3
3
|
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
4
4
|
import { extname, join, posix } from 'node:path'
|
|
@@ -7,12 +7,17 @@ import { appBrotliCacheDir, brotliSync } from './precompress'
|
|
|
7
7
|
// A static `import ... from "./x.js"` or `import "./x.js"` of an emitted chunk; `import("./x.js")` stays lazy and is left out.
|
|
8
8
|
export const STATIC_CHUNK_IMPORT_RE = /\b(?:import|export)\s*(?:[^"'();]*?\bfrom\s*)?["'](\.\.?\/[^"']+\.js)["']/g
|
|
9
9
|
|
|
10
|
-
const TAG_RE = /<(img|script|link)\b[^>]*>/g
|
|
10
|
+
const TAG_RE = /<(\/?)(img|script|link|source|picture|video|audio|iframe)\b[^>]*>/g
|
|
11
11
|
const SRC_RE = /\bsrc="([^"]+)"/
|
|
12
|
+
const SRCSET_RE = /\bsrcset="([^"]+)"/
|
|
13
|
+
const POSTER_RE = /\bposter="([^"]+)"/
|
|
12
14
|
const HREF_RE = /\bhref="([^"]+)"/
|
|
13
15
|
const REL_RE = /\brel="([^"]+)"/
|
|
14
16
|
const TYPE_RE = /\btype="([^"]+)"/
|
|
15
|
-
const
|
|
17
|
+
const AUTOPLAY_RE = /\bautoplay\b/
|
|
18
|
+
const PRELOAD_AUTO_RE = /\bpreload(?:="auto"|="")?(?=[\s/>])/
|
|
19
|
+
const SRCSET_WIDTH_RE = /\s(\d+(?:\.\d+)?)[wx]$/
|
|
20
|
+
const THIRD_PARTY_RE = /^(?:https?:)?\/\//i
|
|
16
21
|
const FONT_FACE_RE = /@font-face\s*\{[^}]*\}/g
|
|
17
22
|
const CSS_URL_RE = /url\(\s*(["']?)([^)"']+)\1\s*\)/g
|
|
18
23
|
const CSS_IMPORT_RE = /@import\s+(?:url\(\s*)?["']([^"']+)["']/g
|
|
@@ -35,17 +40,80 @@ export interface FirstLoad {
|
|
|
35
40
|
cached: number
|
|
36
41
|
/** Files counted besides the page. */
|
|
37
42
|
files: number
|
|
43
|
+
/** Third-party URLs the page fetches: requests whose size the build cannot know. */
|
|
44
|
+
external: number
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
/** Turns a URL the page links into the file that serves it, or `undefined` when no file does. */
|
|
41
48
|
export type Locate = (url: string) => string | undefined
|
|
42
49
|
|
|
43
|
-
/** The
|
|
50
|
+
/** The widest candidate of a `srcset`: the EcoIndex measures at 1920x1080, where a browser takes the large one. */
|
|
51
|
+
function widestCandidate(srcset: string): string | undefined {
|
|
52
|
+
let best: string | undefined
|
|
53
|
+
let bestSize = -1
|
|
54
|
+
for (const candidate of srcset.split(',')) {
|
|
55
|
+
const text = candidate.trim()
|
|
56
|
+
const size = Number(SRCSET_WIDTH_RE.exec(text)?.[1] ?? 1)
|
|
57
|
+
if (text !== '' && size > bestSize) {
|
|
58
|
+
best = text.split(/\s/)[0]
|
|
59
|
+
bestSize = size
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return best
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const imageUrl = (element: string): string | undefined => {
|
|
66
|
+
const srcset = SRCSET_RE.exec(element)?.[1]
|
|
67
|
+
return (srcset === undefined ? undefined : widestCandidate(srcset)) ?? SRC_RE.exec(element)?.[1]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The URLs a browser fetches from this markup once scrolled to the bottom, as the EcoIndex measures: stylesheets, preloads, scripts, one icon, every image (a `<picture>`'s first source, a `srcset`'s widest candidate), frames, posters, and the media that autoplays or preloads. */
|
|
44
71
|
export function firstLoadUrls(html: string): string[] {
|
|
45
72
|
const urls = new Set<string>()
|
|
46
73
|
const icons: string[] = []
|
|
47
74
|
let svgIcon: string | undefined
|
|
48
|
-
|
|
75
|
+
// Inside a <picture>, or a <video>/<audio> that fetches its media: whether the source a browser takes was found.
|
|
76
|
+
let picture: { taken: boolean } | undefined
|
|
77
|
+
let media: { fetches: boolean, taken: boolean } | undefined
|
|
78
|
+
const add = (url: string | undefined): void => {
|
|
79
|
+
if (url !== undefined)
|
|
80
|
+
urls.add(url)
|
|
81
|
+
}
|
|
82
|
+
for (const [element, closing, name] of html.matchAll(TAG_RE)) {
|
|
83
|
+
if (closing === '/') {
|
|
84
|
+
if (name === 'picture')
|
|
85
|
+
picture = undefined
|
|
86
|
+
else if (name === 'video' || name === 'audio')
|
|
87
|
+
media = undefined
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
if (name === 'picture') {
|
|
91
|
+
picture = { taken: false }
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
94
|
+
if (name === 'video' || name === 'audio') {
|
|
95
|
+
const fetches = AUTOPLAY_RE.test(element) || PRELOAD_AUTO_RE.test(element)
|
|
96
|
+
add(POSTER_RE.exec(element)?.[1])
|
|
97
|
+
const src = SRC_RE.exec(element)?.[1]
|
|
98
|
+
media = { fetches, taken: src !== undefined }
|
|
99
|
+
if (fetches)
|
|
100
|
+
add(src)
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
if (name === 'source') {
|
|
104
|
+
const slot = media ?? picture
|
|
105
|
+
if (slot === undefined || slot.taken)
|
|
106
|
+
continue
|
|
107
|
+
slot.taken = true
|
|
108
|
+
if (media === undefined || media.fetches)
|
|
109
|
+
add(media === undefined ? imageUrl(element) : SRC_RE.exec(element)?.[1])
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
if (name === 'img') {
|
|
113
|
+
if (picture?.taken !== true)
|
|
114
|
+
add(imageUrl(element))
|
|
115
|
+
continue
|
|
116
|
+
}
|
|
49
117
|
if (name === 'link') {
|
|
50
118
|
const url = HREF_RE.exec(element)?.[1]
|
|
51
119
|
const relation = REL_RE.exec(element)?.[1] ?? ''
|
|
@@ -60,9 +128,7 @@ export function firstLoadUrls(html: string): string[] {
|
|
|
60
128
|
}
|
|
61
129
|
continue
|
|
62
130
|
}
|
|
63
|
-
|
|
64
|
-
if (url !== undefined && !LAZY_RE.test(element))
|
|
65
|
-
urls.add(url)
|
|
131
|
+
add(SRC_RE.exec(element)?.[1])
|
|
66
132
|
}
|
|
67
133
|
// A browser that draws SVG icons fetches that one alone; the others are for browsers that do not.
|
|
68
134
|
for (const icon of svgIcon === undefined ? icons : [svgIcon])
|
|
@@ -117,7 +183,7 @@ function cssUrls(css: string): string[] {
|
|
|
117
183
|
urls.push(match[2]!)
|
|
118
184
|
for (const match of rest.matchAll(CSS_IMPORT_RE))
|
|
119
185
|
urls.push(match[1]!)
|
|
120
|
-
return urls.filter(url => !SKIPPED_URL_RE.test(url))
|
|
186
|
+
return urls.filter(url => THIRD_PARTY_RE.test(url) || !SKIPPED_URL_RE.test(url))
|
|
121
187
|
}
|
|
122
188
|
|
|
123
189
|
/** What a file pulls in beside itself: a script's static imports and a stylesheet's `url()`s, as URLs. */
|
|
@@ -128,16 +194,22 @@ function dependenciesOf(url: string, file: string): string[] {
|
|
|
128
194
|
const text = readFileSync(file, 'utf8')
|
|
129
195
|
const base = posix.dirname(url.split(/[?#]/)[0]!)
|
|
130
196
|
const raw = ext === '.js' ? [...text.matchAll(STATIC_CHUNK_IMPORT_RE)].map(m => m[1]!) : cssUrls(text)
|
|
131
|
-
return raw.map(dep => (dep.startsWith('/') ? dep : posix.join(base, dep)))
|
|
197
|
+
return raw.map(dep => (dep.startsWith('/') || THIRD_PARTY_RE.test(dep) ? dep : posix.join(base, dep)))
|
|
132
198
|
}
|
|
133
199
|
|
|
134
200
|
/** Adds up what a first visit fetches from these root URLs and what they pull in; `htmlBytes` is the page itself, brotli; `cacheable` names the URLs served for long caching (prunelle's hashed assets). */
|
|
135
201
|
export function measureFirstLoad(roots: Iterable<string>, locate: Locate, htmlBytes = 0, cacheable: (url: string) => boolean = () => false): FirstLoad {
|
|
136
|
-
const result: FirstLoad = { html: htmlBytes, css: 0, js: 0, fonts: 0, images: 0, other: 0, total: htmlBytes, cached: 0, files: 0 }
|
|
202
|
+
const result: FirstLoad = { html: htmlBytes, css: 0, js: 0, fonts: 0, images: 0, other: 0, total: htmlBytes, cached: 0, files: 0, external: 0 }
|
|
137
203
|
const seen = new Set<string>()
|
|
138
204
|
const stack = [...roots]
|
|
139
205
|
while (stack.length > 0) {
|
|
140
206
|
const url = stack.pop()!
|
|
207
|
+
if (THIRD_PARTY_RE.test(url)) {
|
|
208
|
+
if (!seen.has(url))
|
|
209
|
+
result.external++
|
|
210
|
+
seen.add(url)
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
141
213
|
const file = locate(url)
|
|
142
214
|
if (file === undefined || seen.has(file))
|
|
143
215
|
continue
|