prunelle 0.8.0 → 0.10.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/llms.txt +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
package/src/reactivity/store.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// Deep reactive proxy store (tree-shakable: 0 B if unused).
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
import { batch, isObserving, isTracking,
|
|
3
|
+
import type { HmrHost } from './hmr'
|
|
4
|
+
import { batch, beginBatch, bumpWrites, endBatch, isBatching, isObserving, isSharedWrite, isTracking, recordSharedWrite, shareOutsideRender, sharedPath, SignalNode, untrack, writeRecorder } from './index'
|
|
5
|
+
|
|
6
|
+
declare const PRUNELLE_BROWSER: boolean | undefined
|
|
7
|
+
// The client build defines PRUNELLE_BROWSER, which drops what only the server checks.
|
|
8
|
+
const onServer = (): boolean => typeof PRUNELLE_BROWSER === 'undefined' || !PRUNELLE_BROWSER
|
|
5
9
|
|
|
6
10
|
const RAW = Symbol('prunelle.store.raw')
|
|
7
11
|
const OWN_KEYS = Symbol('prunelle.store.keys')
|
|
@@ -29,8 +33,48 @@ const arrayMethods = new Map<PropertyKey, (this: unknown[], ...args: unknown[])
|
|
|
29
33
|
])
|
|
30
34
|
|
|
31
35
|
const proxyCache = new WeakMap<object, object>()
|
|
32
|
-
const depsCache = new WeakMap<object, Map<PropertyKey,
|
|
33
|
-
const verCache = new WeakMap<object,
|
|
36
|
+
const depsCache = new WeakMap<object, Map<PropertyKey, SignalNode<number>>>()
|
|
37
|
+
const verCache = new WeakMap<object, SignalNode<number>>()
|
|
38
|
+
let verCount = 0
|
|
39
|
+
|
|
40
|
+
class StoreVer extends SignalNode<number> {
|
|
41
|
+
_t: object
|
|
42
|
+
constructor(target: object) {
|
|
43
|
+
super(0)
|
|
44
|
+
this._t = target
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
u(): void {
|
|
48
|
+
this.v++
|
|
49
|
+
bumpWrites()
|
|
50
|
+
if (verCache.get(this._t) === this) {
|
|
51
|
+
verCache.delete(this._t)
|
|
52
|
+
verCount--
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class StoreDep extends SignalNode<number> {
|
|
58
|
+
_t: object
|
|
59
|
+
_m: Map<PropertyKey, SignalNode<number>>
|
|
60
|
+
_k: PropertyKey
|
|
61
|
+
constructor(target: object, map: Map<PropertyKey, SignalNode<number>>, key: PropertyKey) {
|
|
62
|
+
super(0)
|
|
63
|
+
this._t = target
|
|
64
|
+
this._m = map
|
|
65
|
+
this._k = key
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
u(): void {
|
|
69
|
+
this.v++
|
|
70
|
+
bumpWrites()
|
|
71
|
+
if (this._m.get(this._k) === this) {
|
|
72
|
+
this._m.delete(this._k)
|
|
73
|
+
if (this._m.size === 0)
|
|
74
|
+
depsCache.delete(this._t)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
34
78
|
|
|
35
79
|
function isPlain(value: unknown): value is Record<PropertyKey, unknown> {
|
|
36
80
|
if (typeof value !== 'object' || value === null)
|
|
@@ -43,24 +87,25 @@ function isPlain(value: unknown): value is Record<PropertyKey, unknown> {
|
|
|
43
87
|
|
|
44
88
|
// The target behind a store proxy, or the value itself.
|
|
45
89
|
function unwrap<T>(value: T): T {
|
|
46
|
-
return typeof value === 'object' && value !== null
|
|
90
|
+
return typeof value === 'object' && value !== null ? ((value as { [RAW]?: T })[RAW] ?? value) : value
|
|
47
91
|
}
|
|
48
92
|
|
|
49
93
|
function bumpVer(target: object): void {
|
|
50
94
|
const ver = verCache.get(target)
|
|
51
95
|
if (ver !== undefined)
|
|
52
|
-
ver.value = ver.
|
|
96
|
+
ver.value = ver._v + 1
|
|
53
97
|
}
|
|
54
98
|
|
|
55
|
-
function getDep(target: object, key: PropertyKey):
|
|
99
|
+
function getDep(target: object, key: PropertyKey): SignalNode<number> {
|
|
56
100
|
if (!isObserving()) {
|
|
57
101
|
const existing = depsCache.get(target)?.get(key)
|
|
58
102
|
if (existing !== undefined)
|
|
59
103
|
return existing
|
|
60
104
|
let ver = verCache.get(target)
|
|
61
105
|
if (ver === undefined) {
|
|
62
|
-
ver =
|
|
106
|
+
ver = new StoreVer(target)
|
|
63
107
|
verCache.set(target, ver)
|
|
108
|
+
verCount++
|
|
64
109
|
}
|
|
65
110
|
return ver
|
|
66
111
|
}
|
|
@@ -71,13 +116,7 @@ function getDep(target: object, key: PropertyKey): Signal<number> {
|
|
|
71
116
|
}
|
|
72
117
|
let dep = map.get(key)
|
|
73
118
|
if (dep === undefined) {
|
|
74
|
-
dep =
|
|
75
|
-
if (map!.get(key) === dep) {
|
|
76
|
-
map!.delete(key)
|
|
77
|
-
if (map!.size === 0)
|
|
78
|
-
depsCache.delete(target)
|
|
79
|
-
}
|
|
80
|
-
})
|
|
119
|
+
dep = new StoreDep(target, map, key)
|
|
81
120
|
map.set(key, dep)
|
|
82
121
|
}
|
|
83
122
|
return dep
|
|
@@ -86,20 +125,22 @@ function getDep(target: object, key: PropertyKey): Signal<number> {
|
|
|
86
125
|
function notifyKey(target: object, key: PropertyKey): void {
|
|
87
126
|
const dep = depsCache.get(target)?.get(key)
|
|
88
127
|
if (dep !== undefined)
|
|
89
|
-
dep.value = dep.
|
|
90
|
-
|
|
128
|
+
dep.value = dep._v + 1
|
|
129
|
+
if (verCount > 0)
|
|
130
|
+
bumpVer(target)
|
|
91
131
|
}
|
|
92
132
|
|
|
93
133
|
function deleteDep(target: object, key: PropertyKey): void {
|
|
94
134
|
const map = depsCache.get(target)
|
|
95
135
|
const dep = map?.get(key)
|
|
96
136
|
if (dep !== undefined) {
|
|
97
|
-
dep.value = dep.
|
|
137
|
+
dep.value = dep._v + 1
|
|
98
138
|
map!.delete(key)
|
|
99
139
|
if (map!.size === 0)
|
|
100
140
|
depsCache.delete(target)
|
|
101
141
|
}
|
|
102
|
-
|
|
142
|
+
if (verCount > 0)
|
|
143
|
+
bumpVer(target)
|
|
103
144
|
}
|
|
104
145
|
|
|
105
146
|
function evictTruncated(target: object, nextLen: number, prevLen: number): void {
|
|
@@ -109,7 +150,7 @@ function evictTruncated(target: object, nextLen: number, prevLen: number): void
|
|
|
109
150
|
if (typeof k === 'string') {
|
|
110
151
|
const idx = Number(k)
|
|
111
152
|
if ((idx >>> 0) === idx && idx >= nextLen && idx < prevLen && String(idx) === k) {
|
|
112
|
-
dep.value = dep.
|
|
153
|
+
dep.value = dep._v + 1
|
|
113
154
|
map.delete(k)
|
|
114
155
|
}
|
|
115
156
|
}
|
|
@@ -117,97 +158,285 @@ function evictTruncated(target: object, nextLen: number, prevLen: number): void
|
|
|
117
158
|
if (map.size === 0)
|
|
118
159
|
depsCache.delete(target)
|
|
119
160
|
}
|
|
120
|
-
|
|
161
|
+
if (verCount > 0)
|
|
162
|
+
bumpVer(target)
|
|
121
163
|
}
|
|
122
164
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
165
|
+
// A write to a store every request shares, kept in the request: `redo` applies it again for the islands after, `undo` takes it back.
|
|
166
|
+
function recordWrite(obj: object, key: PropertyKey, redo: () => void, undo: () => void, value: unknown, deleted = false): void {
|
|
167
|
+
const { root, path } = sharedPath(obj)
|
|
168
|
+
recordSharedWrite(proxyCache.get(root)!, [...path, key], redo, undo, value, deleted)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function notifySet(obj: object, key: PropertyKey, had: boolean, isArr: boolean, changed: boolean, lenChanged: boolean, prevLength: number): void {
|
|
172
|
+
if (changed) {
|
|
173
|
+
notifyKey(obj, key)
|
|
174
|
+
if (!had || isArr)
|
|
175
|
+
notifyKey(obj, OWN_KEYS)
|
|
176
|
+
}
|
|
177
|
+
// Writing past the end grows the array without a later `length` write that differs; truncating drops trailing elements.
|
|
178
|
+
if (lenChanged) {
|
|
179
|
+
const nextLen = (obj as unknown[]).length
|
|
180
|
+
if (key !== 'length')
|
|
181
|
+
notifyKey(obj, 'length')
|
|
182
|
+
else if (nextLen < prevLength)
|
|
183
|
+
evictTruncated(obj, nextLen, prevLength)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function setRaw(obj: object, key: PropertyKey, value: unknown, receiver: object, isArr: boolean): boolean {
|
|
188
|
+
const rawValue = unwrap(value)
|
|
189
|
+
const had = Object.hasOwn(obj, key)
|
|
190
|
+
const prev = Reflect.get(obj, key, obj)
|
|
191
|
+
const prevLength = isArr ? (obj as unknown[]).length : 0
|
|
192
|
+
const recorder = writeRecorder()
|
|
193
|
+
const isShared = onServer() && isSharedWrite(obj)
|
|
194
|
+
let dropped: [number, unknown][] | undefined
|
|
195
|
+
let restore: ((fixLen: boolean) => void) | undefined
|
|
196
|
+
if (recorder || isShared) {
|
|
197
|
+
if (isArr && key === 'length') {
|
|
198
|
+
const nextLen = typeof rawValue === 'number' || typeof rawValue === 'string' ? +rawValue : -1
|
|
199
|
+
if (Number.isInteger(nextLen) && nextLen >= 0 && nextLen < prevLength) {
|
|
200
|
+
dropped = []
|
|
201
|
+
const arr = obj as unknown[]
|
|
202
|
+
for (let i = nextLen; i < prevLength; i++) {
|
|
203
|
+
if (Object.hasOwn(arr, i))
|
|
204
|
+
dropped.push([i, arr[i]])
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const proxy = wrap(obj)
|
|
209
|
+
restore = (fixLen: boolean) => {
|
|
210
|
+
const self = proxy as Record<PropertyKey, unknown>
|
|
211
|
+
if (had)
|
|
212
|
+
self[key] = prev
|
|
213
|
+
else
|
|
214
|
+
delete self[key]
|
|
215
|
+
if (dropped) {
|
|
216
|
+
for (const [i, v] of dropped)
|
|
217
|
+
self[i] = v
|
|
218
|
+
}
|
|
219
|
+
else if (fixLen) {
|
|
220
|
+
self.length = prevLength
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (isShared && (!had || !Object.is(prev, rawValue))) {
|
|
224
|
+
const self = proxy as Record<PropertyKey, unknown>
|
|
225
|
+
recordWrite(obj, key, () => self[key] = rawValue, () => restore!(isArr), rawValue)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const ok = Reflect.set(obj, key, rawValue, receiver)
|
|
229
|
+
if (!ok)
|
|
230
|
+
return false
|
|
231
|
+
const changed = !had || !Object.is(prev, rawValue)
|
|
232
|
+
const lenChanged = isArr && (obj as unknown[]).length !== prevLength
|
|
233
|
+
// Undone through the proxy so readers hear it; an index written past the end also grew `length`, and truncating `length` restores dropped elements.
|
|
234
|
+
if (changed && recorder)
|
|
235
|
+
recorder(() => restore!(lenChanged))
|
|
236
|
+
if (changed || lenChanged) {
|
|
237
|
+
if (!isArr && had && verCount === 0) {
|
|
238
|
+
notifyKey(obj, key)
|
|
239
|
+
}
|
|
240
|
+
else if (isBatching()) {
|
|
241
|
+
notifySet(obj, key, had, isArr, changed, lenChanged, prevLength)
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
beginBatch()
|
|
245
|
+
let threw = true
|
|
246
|
+
try {
|
|
247
|
+
notifySet(obj, key, had, isArr, changed, lenChanged, prevLength)
|
|
248
|
+
threw = false
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
endBatch(threw)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return true
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function deleteRaw(obj: object, key: PropertyKey): boolean {
|
|
259
|
+
const had = Object.hasOwn(obj, key)
|
|
260
|
+
const prev = Reflect.get(obj, key, obj)
|
|
261
|
+
if (had && onServer() && isSharedWrite(obj)) {
|
|
262
|
+
const self = wrap(obj) as Record<PropertyKey, unknown>
|
|
263
|
+
recordWrite(obj, key, () => delete self[key], () => self[key] = prev, undefined, true)
|
|
264
|
+
}
|
|
265
|
+
const ok = Reflect.deleteProperty(obj, key)
|
|
266
|
+
if (had && ok) {
|
|
267
|
+
const recorder = writeRecorder()
|
|
268
|
+
if (recorder) {
|
|
269
|
+
const self = wrap(obj) as Record<PropertyKey, unknown>
|
|
270
|
+
recorder(() => self[key] = prev)
|
|
271
|
+
}
|
|
272
|
+
if (isBatching()) {
|
|
273
|
+
deleteDep(obj, key)
|
|
274
|
+
notifyKey(obj, OWN_KEYS)
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
batch(() => {
|
|
278
|
+
deleteDep(obj, key)
|
|
279
|
+
notifyKey(obj, OWN_KEYS)
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return ok
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function getProp(obj: object, key: PropertyKey, receiver: object): unknown {
|
|
287
|
+
if (isTracking())
|
|
288
|
+
getDep(obj, key).value
|
|
289
|
+
const value = Reflect.get(obj, key, receiver)
|
|
290
|
+
if (!isPlain(value))
|
|
291
|
+
return value
|
|
292
|
+
const desc = Object.getOwnPropertyDescriptor(obj, key)
|
|
293
|
+
if (desc !== undefined && !desc.configurable && !desc.writable && !desc.get)
|
|
294
|
+
return value
|
|
295
|
+
if (onServer())
|
|
296
|
+
shareOutsideRender(value, obj, key)
|
|
297
|
+
return wrap(value)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function hasProp(obj: object, key: PropertyKey): boolean {
|
|
301
|
+
if (isTracking())
|
|
302
|
+
getDep(obj, key).value
|
|
303
|
+
return Reflect.has(obj, key)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function ownKeysProp(obj: object): (string | symbol)[] {
|
|
307
|
+
if (isTracking())
|
|
308
|
+
getDep(obj, OWN_KEYS).value
|
|
309
|
+
return Reflect.ownKeys(obj)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const baseHandler: ProxyHandler<object> = {
|
|
313
|
+
deleteProperty: deleteRaw,
|
|
314
|
+
has: hasProp,
|
|
315
|
+
ownKeys: ownKeysProp,
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const objectHandler: ProxyHandler<object> = {
|
|
319
|
+
...baseHandler,
|
|
320
|
+
get(obj, key, receiver) {
|
|
321
|
+
return key === RAW ? obj : getProp(obj, key, receiver)
|
|
322
|
+
},
|
|
323
|
+
set(obj, key, value, receiver) {
|
|
324
|
+
return setRaw(obj, key, value, receiver, false)
|
|
325
|
+
},
|
|
326
|
+
}
|
|
127
327
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
328
|
+
const arrayHandler: ProxyHandler<object> = {
|
|
329
|
+
...baseHandler,
|
|
330
|
+
get(obj, key, receiver) {
|
|
331
|
+
if (key === RAW)
|
|
332
|
+
return obj
|
|
333
|
+
if (typeof key === 'string' && key.charCodeAt(0) >= 97) {
|
|
334
|
+
const method = arrayMethods.get(key)
|
|
133
335
|
if (method !== undefined)
|
|
134
336
|
return method
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
337
|
+
// A reader of an array's length is walking it (a list loop reads entries untracked), so any entry write reaches it.
|
|
338
|
+
if (key === 'length') {
|
|
339
|
+
if (isTracking()) {
|
|
340
|
+
getDep(obj, key).value
|
|
139
341
|
getDep(obj, OWN_KEYS).value
|
|
342
|
+
}
|
|
343
|
+
return (obj as unknown[]).length
|
|
140
344
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
},
|
|
149
|
-
set(obj, key, value, receiver) {
|
|
150
|
-
const rawValue = unwrap(value)
|
|
151
|
-
const had = Object.prototype.hasOwnProperty.call(obj, key)
|
|
152
|
-
const prev = Reflect.get(obj, key, obj)
|
|
153
|
-
const isArr = Array.isArray(obj)
|
|
154
|
-
const prevLength = isArr ? obj.length : 0
|
|
155
|
-
const ok = Reflect.set(obj, key, rawValue, receiver)
|
|
156
|
-
if (!ok)
|
|
157
|
-
return false
|
|
158
|
-
const changed = !had || !Object.is(prev, rawValue)
|
|
159
|
-
const lenChanged = isArr && obj.length !== prevLength
|
|
160
|
-
if (changed || lenChanged) {
|
|
161
|
-
batch(() => {
|
|
162
|
-
if (changed) {
|
|
163
|
-
notifyKey(obj, key)
|
|
164
|
-
if (!had || isArr)
|
|
165
|
-
notifyKey(obj, OWN_KEYS)
|
|
166
|
-
}
|
|
167
|
-
// Writing past the end grows the array without a later `length` write that differs; truncating drops trailing elements.
|
|
168
|
-
if (lenChanged) {
|
|
169
|
-
if (key !== 'length')
|
|
170
|
-
notifyKey(obj, 'length')
|
|
171
|
-
else if (obj.length < prevLength)
|
|
172
|
-
evictTruncated(obj, obj.length, prevLength)
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
}
|
|
176
|
-
return true
|
|
177
|
-
},
|
|
178
|
-
deleteProperty(obj, key) {
|
|
179
|
-
const had = Object.prototype.hasOwnProperty.call(obj, key)
|
|
180
|
-
const ok = Reflect.deleteProperty(obj, key)
|
|
181
|
-
if (had && ok) {
|
|
182
|
-
batch(() => {
|
|
183
|
-
deleteDep(obj, key)
|
|
184
|
-
notifyKey(obj, OWN_KEYS)
|
|
185
|
-
})
|
|
186
|
-
}
|
|
187
|
-
return ok
|
|
188
|
-
},
|
|
189
|
-
has(obj, key) {
|
|
190
|
-
if (key === RAW)
|
|
191
|
-
return true
|
|
192
|
-
if (isTracking())
|
|
193
|
-
getDep(obj, key).value
|
|
194
|
-
return Reflect.has(obj, key)
|
|
195
|
-
},
|
|
196
|
-
ownKeys(obj) {
|
|
197
|
-
if (isTracking())
|
|
198
|
-
getDep(obj, OWN_KEYS).value
|
|
199
|
-
return Reflect.ownKeys(obj)
|
|
200
|
-
},
|
|
201
|
-
})
|
|
345
|
+
}
|
|
346
|
+
return getProp(obj, key, receiver)
|
|
347
|
+
},
|
|
348
|
+
set(obj, key, value, receiver) {
|
|
349
|
+
return setRaw(obj, key, value, receiver, true)
|
|
350
|
+
},
|
|
351
|
+
}
|
|
202
352
|
|
|
353
|
+
function wrap<T extends object>(target: T): T {
|
|
354
|
+
const existing = proxyCache.get(target)
|
|
355
|
+
if (existing !== undefined)
|
|
356
|
+
return existing as T
|
|
357
|
+
const proxy = new Proxy(target, Array.isArray(target) ? arrayHandler : objectHandler)
|
|
203
358
|
proxyCache.set(target, proxy)
|
|
204
|
-
return proxy
|
|
359
|
+
return proxy as T
|
|
205
360
|
}
|
|
206
361
|
|
|
207
362
|
export function store<T extends object>(initial: T): T {
|
|
208
363
|
if (!isPlain(initial))
|
|
209
364
|
return initial
|
|
210
|
-
|
|
365
|
+
if (onServer())
|
|
366
|
+
shareOutsideRender(initial)
|
|
367
|
+
const proxy = wrap(initial)
|
|
368
|
+
if (process.env.NODE_ENV !== 'production')
|
|
369
|
+
(globalThis as HmrHost).__pruHmr?.noteStore?.(proxy, snapshot, reconcile)
|
|
370
|
+
return proxy
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const reconcileSeen = new WeakSet<object>()
|
|
374
|
+
|
|
375
|
+
function reconcileNode(targetRaw: Record<PropertyKey, unknown>, nextRaw: Record<PropertyKey, unknown>): void {
|
|
376
|
+
if (targetRaw === nextRaw || reconcileSeen.has(nextRaw))
|
|
377
|
+
return
|
|
378
|
+
reconcileSeen.add(nextRaw)
|
|
379
|
+
try {
|
|
380
|
+
if (Array.isArray(targetRaw)) {
|
|
381
|
+
if (!Array.isArray(nextRaw))
|
|
382
|
+
return
|
|
383
|
+
const nextLen = nextRaw.length
|
|
384
|
+
const targetLen = targetRaw.length
|
|
385
|
+
for (let i = 0; i < nextLen; i++) {
|
|
386
|
+
const nv = unwrap(nextRaw[i])
|
|
387
|
+
if (i < targetLen) {
|
|
388
|
+
const tv = targetRaw[i]
|
|
389
|
+
if (Object.is(tv, nv))
|
|
390
|
+
continue
|
|
391
|
+
if (isPlain(tv) && isPlain(nv) && Array.isArray(tv) === Array.isArray(nv) && !Object.isFrozen(tv)) {
|
|
392
|
+
if (onServer() && isSharedWrite(targetRaw))
|
|
393
|
+
shareOutsideRender(tv, targetRaw, String(i))
|
|
394
|
+
reconcileNode(tv, nv)
|
|
395
|
+
continue
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
setRaw(targetRaw, String(i), nv, targetRaw, true)
|
|
399
|
+
}
|
|
400
|
+
if (targetRaw.length !== nextLen)
|
|
401
|
+
setRaw(targetRaw, 'length', nextLen, targetRaw, true)
|
|
402
|
+
return
|
|
403
|
+
}
|
|
404
|
+
if (Array.isArray(nextRaw))
|
|
405
|
+
return
|
|
406
|
+
for (const key in targetRaw) {
|
|
407
|
+
if (Object.hasOwn(targetRaw, key) && !Object.hasOwn(nextRaw, key))
|
|
408
|
+
deleteRaw(targetRaw, key)
|
|
409
|
+
}
|
|
410
|
+
for (const key in nextRaw) {
|
|
411
|
+
if (key === '__proto__' || !Object.hasOwn(nextRaw, key))
|
|
412
|
+
continue
|
|
413
|
+
const nv = unwrap(nextRaw[key])
|
|
414
|
+
if (Object.hasOwn(targetRaw, key)) {
|
|
415
|
+
const tv = targetRaw[key]
|
|
416
|
+
if (Object.is(tv, nv))
|
|
417
|
+
continue
|
|
418
|
+
if (isPlain(tv) && isPlain(nv) && Array.isArray(tv) === Array.isArray(nv) && !Object.isFrozen(tv)) {
|
|
419
|
+
if (onServer() && isSharedWrite(targetRaw))
|
|
420
|
+
shareOutsideRender(tv, targetRaw, key)
|
|
421
|
+
reconcileNode(tv, nv)
|
|
422
|
+
continue
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
setRaw(targetRaw, key, nv, targetRaw, false)
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
finally {
|
|
429
|
+
reconcileSeen.delete(nextRaw)
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export function reconcile<T extends object>(target: T, next: T): T {
|
|
434
|
+
const targetRaw = unwrap(target)
|
|
435
|
+
const nextRaw = unwrap(next)
|
|
436
|
+
if (!isPlain(targetRaw) || !isPlain(nextRaw))
|
|
437
|
+
return target
|
|
438
|
+
batch(() => untrack(() => reconcileNode(targetRaw as Record<PropertyKey, unknown>, nextRaw as Record<PropertyKey, unknown>)))
|
|
439
|
+
return target
|
|
211
440
|
}
|
|
212
441
|
|
|
213
442
|
export function snapshot<T>(value: T): T {
|
|
@@ -219,6 +448,11 @@ export function _storeDepsSize(target: object): number {
|
|
|
219
448
|
return depsCache.get(unwrap(target))?.size ?? 0
|
|
220
449
|
}
|
|
221
450
|
|
|
451
|
+
/** @internal Test helper: whether `target` currently has a cached fallback version signal. */
|
|
452
|
+
export function _storeVerCached(target: object): boolean {
|
|
453
|
+
return verCache.has(unwrap(target))
|
|
454
|
+
}
|
|
455
|
+
|
|
222
456
|
function cloneRaw<T>(value: T, seen: Map<object, unknown>): T {
|
|
223
457
|
const raw = unwrap(value)
|
|
224
458
|
if (typeof raw !== 'object' || raw === null)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Drafts the French privacy notice (RGPD art. 13) and the record of processing (art. 30) from what the plugins and the app's forms process.
|
|
2
|
+
|
|
3
|
+
import type { ProcessingDeclaration } from '../plugins/types'
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, resolve } from 'node:path'
|
|
6
|
+
import { escapeAttr, escapeJsxText, formatFrenchDate, layoutRendersMain, STATEMENT_PLACEHOLDER } from '../a11y/declaration'
|
|
7
|
+
import { relPosix } from '../build/files'
|
|
8
|
+
|
|
9
|
+
/** The record of processing, kept beside the code and out of the site: it is for the controller and the CNIL. */
|
|
10
|
+
export const REGISTER_PATH = 'registre-des-traitements.md'
|
|
11
|
+
|
|
12
|
+
export interface PrivacyNoticeOptions {
|
|
13
|
+
root: string
|
|
14
|
+
/** The notice's path from `root`; default `<routesDir>/confidentialite.tsx`. */
|
|
15
|
+
outPath?: string | undefined
|
|
16
|
+
/** Default `'src/routes'`. */
|
|
17
|
+
routesDir?: string | undefined
|
|
18
|
+
processing: readonly ProcessingDeclaration[]
|
|
19
|
+
organization?: string | undefined
|
|
20
|
+
contactEmail?: string | undefined
|
|
21
|
+
/** Day the drafts are dated (defaults to today). */
|
|
22
|
+
date?: Date | undefined
|
|
23
|
+
/** Write both files (default: `true`). */
|
|
24
|
+
write?: boolean | undefined
|
|
25
|
+
/** Overwrite files already there (default: `false`). */
|
|
26
|
+
force?: boolean | undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface DraftedFile {
|
|
30
|
+
path: string
|
|
31
|
+
/** From the app root, such as `'src/routes/confidentialite.tsx'`. */
|
|
32
|
+
relativePath: string
|
|
33
|
+
content: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface PrivacyNoticeDraft {
|
|
37
|
+
notice: DraftedFile
|
|
38
|
+
register: DraftedFile
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const todo = (what: string): string => `${STATEMENT_PLACEHOLDER} : ${what}]`
|
|
42
|
+
const NO_TRANSFER = todo('aucun, ou les pays et les garanties')
|
|
43
|
+
|
|
44
|
+
interface Details { purpose: string, data: string, people: string, legalBasis: string, retention: string, recipients: string }
|
|
45
|
+
|
|
46
|
+
function detailsOf(p: ProcessingDeclaration): Details {
|
|
47
|
+
return {
|
|
48
|
+
purpose: p.purpose,
|
|
49
|
+
data: p.data.join(' ; '),
|
|
50
|
+
people: p.people ?? todo('personnes concernées'),
|
|
51
|
+
legalBasis: p.legalBasis ?? todo('base légale (RGPD art. 6)'),
|
|
52
|
+
retention: p.retention ?? todo('durée de conservation'),
|
|
53
|
+
recipients: p.recipients === undefined || p.recipients.length === 0 ? todo('destinataires, ou aucun') : p.recipients.join(' ; '),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function noticeSection(p: ProcessingDeclaration): string {
|
|
58
|
+
const d = detailsOf(p)
|
|
59
|
+
const rows: [string, string][] = [['Finalité', d.purpose], ['Données', d.data], ['Personnes concernées', d.people], ['Base légale', d.legalBasis], ['Durée de conservation', d.retention], ['Destinataires', d.recipients]]
|
|
60
|
+
return [
|
|
61
|
+
` <h3>${escapeJsxText(p.name)}</h3>`,
|
|
62
|
+
' <dl>',
|
|
63
|
+
...rows.map(([term, value]) => ` <dt>${term}</dt><dd>${escapeJsxText(value)}</dd>`),
|
|
64
|
+
' </dl>',
|
|
65
|
+
].join('\n')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function registerSection(p: ProcessingDeclaration): string {
|
|
69
|
+
const d = detailsOf(p)
|
|
70
|
+
const security = p.security === undefined || p.security.length === 0 ? todo('mesures de sécurité') : `${p.security.join(' ; ')} ; ${todo('autres mesures')}`
|
|
71
|
+
return [
|
|
72
|
+
`### ${p.name}`,
|
|
73
|
+
'',
|
|
74
|
+
`- Finalité : ${d.purpose}`,
|
|
75
|
+
`- Base légale : ${d.legalBasis}`,
|
|
76
|
+
`- Personnes concernées : ${d.people}`,
|
|
77
|
+
`- Données : ${d.data}`,
|
|
78
|
+
`- Destinataires : ${d.recipients}`,
|
|
79
|
+
`- Transferts hors de l'Union européenne : ${NO_TRANSFER}`,
|
|
80
|
+
`- Durée de conservation : ${d.retention}`,
|
|
81
|
+
`- Mesures de sécurité : ${security}`,
|
|
82
|
+
].join('\n')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function noticeContent(options: PrivacyNoticeOptions, wrapper: string): string {
|
|
86
|
+
const org = options.organization?.trim() || todo('nom de la personne ou de l\'organisme qui publie le site')
|
|
87
|
+
const email = options.contactEmail?.trim()
|
|
88
|
+
const contact = email ? `<a href="mailto:${escapeAttr(email)}">${escapeJsxText(email)}</a>` : todo('adresse de contact')
|
|
89
|
+
const { iso, human } = formatFrenchDate(options.date ?? new Date())
|
|
90
|
+
const sections = options.processing.length === 0 ? ` <p>${todo('les traitements de données personnelles du site')}</p>` : options.processing.map(noticeSection).join('\n')
|
|
91
|
+
return `// Brouillon de politique de confidentialité (RGPD art. 13) généré par \`prunelle rgpd --draft\`, d'après les plugins et les formulaires de l'app.
|
|
92
|
+
// Remplacez chaque mention entre crochets avant publication : \`prunelle check\` signale celles qui restent.
|
|
93
|
+
// Le registre des traitements (RGPD art. 30) est dans ${REGISTER_PATH} : tenez-les à jour ensemble.
|
|
94
|
+
|
|
95
|
+
import { CookieTable, Head } from 'prunelle'
|
|
96
|
+
|
|
97
|
+
export const prerender = true
|
|
98
|
+
|
|
99
|
+
export default function Confidentialite() {
|
|
100
|
+
return (
|
|
101
|
+
<>
|
|
102
|
+
<Head>
|
|
103
|
+
<title>Politique de confidentialité</title>
|
|
104
|
+
</Head>
|
|
105
|
+
<${wrapper} lang="fr">
|
|
106
|
+
<h1>Politique de confidentialité</h1>
|
|
107
|
+
<p>Mise à jour le <time dateTime="${escapeAttr(iso)}">${escapeJsxText(human)}</time>.</p>
|
|
108
|
+
<h2>Responsable du traitement</h2>
|
|
109
|
+
<p>${escapeJsxText(org)} est responsable des traitements décrits sur cette page. Pour toute question sur vos données, ou pour exercer vos droits, écrivez à ${contact}.</p>
|
|
110
|
+
<p>Délégué à la protection des données : ${todo('son nom et son contact, ou aucun')}</p>
|
|
111
|
+
<h2>Données traitées</h2>
|
|
112
|
+
${sections}
|
|
113
|
+
<h2>Cookies</h2>
|
|
114
|
+
<CookieTable />
|
|
115
|
+
<h2>Transferts hors de l'Union européenne</h2>
|
|
116
|
+
<p>${NO_TRANSFER}</p>
|
|
117
|
+
<h2>Vos droits</h2>
|
|
118
|
+
<p>Vous pouvez accéder à vos données, les faire rectifier ou effacer, limiter leur traitement ou vous y opposer et, dans les cas prévus par le RGPD, les recevoir dans un format réutilisable (articles 15 à 21). Si un traitement repose sur votre consentement, vous pouvez le retirer à tout moment. Vous pouvez aussi définir des directives sur le sort de vos données après votre décès.</p>
|
|
119
|
+
<p>Si vous estimez, après nous avoir écrit, que vos droits ne sont pas respectés, vous pouvez adresser une réclamation à la CNIL (<a href="https://www.cnil.fr">www.cnil.fr</a>).</p>
|
|
120
|
+
</${wrapper}>
|
|
121
|
+
</>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
`
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function registerContent(options: PrivacyNoticeOptions): string {
|
|
128
|
+
const { human } = formatFrenchDate(options.date ?? new Date())
|
|
129
|
+
const sections = options.processing.length === 0 ? todo('les traitements de données personnelles') : options.processing.map(registerSection).join('\n\n')
|
|
130
|
+
return `# Registre des activités de traitement
|
|
131
|
+
|
|
132
|
+
Brouillon généré par \`prunelle rgpd --draft\` le ${human}, d'après les plugins et les formulaires de l'app. Le RGPD (art. 30) demande au responsable du traitement de tenir ce registre à jour et de le présenter à la CNIL si elle le demande : il reste hors du site. Remplacez chaque mention entre crochets, et ajoutez les traitements que prunelle ne voit pas, comme la paie, le fichier clients ou la prospection.
|
|
133
|
+
|
|
134
|
+
## Responsable du traitement
|
|
135
|
+
|
|
136
|
+
- Nom : ${options.organization?.trim() || todo('nom')}
|
|
137
|
+
- Adresse : ${todo('adresse')}
|
|
138
|
+
- Contact : ${options.contactEmail?.trim() || todo('adresse de contact')}
|
|
139
|
+
- Délégué à la protection des données : ${todo('nom et contact, ou aucun')}
|
|
140
|
+
|
|
141
|
+
## Mesures de sécurité communes
|
|
142
|
+
|
|
143
|
+
- Par défaut, prunelle applique une politique de sécurité du contenu (CSP) stricte, protège les formulaires contre la falsification de requêtes (CSRF) et limite la taille des requêtes : vérifiez que la configuration de l'app n'en désactive aucune.
|
|
144
|
+
- ${todo('chiffrement des échanges (HTTPS), sauvegardes, accès au serveur, journalisation')}
|
|
145
|
+
|
|
146
|
+
## Traitements
|
|
147
|
+
|
|
148
|
+
${sections}
|
|
149
|
+
`
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Drafts both files, and writes them unless `write` is false; refuses before writing either when one exists and `force` is not set. */
|
|
153
|
+
export function draftPrivacyNotice(options: PrivacyNoticeOptions): PrivacyNoticeDraft {
|
|
154
|
+
const root = resolve(options.root)
|
|
155
|
+
const routesDir = resolve(root, options.routesDir ?? 'src/routes')
|
|
156
|
+
const noticePath = options.outPath === undefined ? resolve(routesDir, 'confidentialite.tsx') : resolve(root, options.outPath)
|
|
157
|
+
const registerPath = resolve(root, REGISTER_PATH)
|
|
158
|
+
const wrapper = layoutRendersMain(root, noticePath) ? 'article' : 'main'
|
|
159
|
+
const notice = { path: noticePath, relativePath: relPosix(root, noticePath), content: noticeContent(options, wrapper) }
|
|
160
|
+
const register = { path: registerPath, relativePath: REGISTER_PATH, content: registerContent(options) }
|
|
161
|
+
if (options.write !== false) {
|
|
162
|
+
const taken = [notice, register].find(file => existsSync(file.path))
|
|
163
|
+
if (taken !== undefined && options.force !== true)
|
|
164
|
+
throw new Error(`prunelle: ${taken.relativePath} already exists: pass --force to overwrite it.`)
|
|
165
|
+
for (const file of [notice, register]) {
|
|
166
|
+
mkdirSync(dirname(file.path), { recursive: true })
|
|
167
|
+
writeFileSync(file.path, file.content)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { notice, register }
|
|
171
|
+
}
|