@peekling/vite 0.1.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/AUTHORS +8 -0
- package/LICENSE +202 -0
- package/LICENSING.md +20 -0
- package/NOTICE +6 -0
- package/README.md +176 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +253 -0
- package/package.json +60 -0
package/AUTHORS
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Peekling Vite Integration was originally designed and developed by Prajwal S. Venkateshmurthy (https://prajwal.me).
|
|
2
|
+
|
|
3
|
+
Other contributors are recorded in the repository history.
|
|
4
|
+
|
|
5
|
+
This is a factual authorship record. Licensing terms and applicable
|
|
6
|
+
notice-retention requirements are in LICENSE and NOTICE. Redistributions must
|
|
7
|
+
comply with Section 4 of the Apache License 2.0, including its applicable
|
|
8
|
+
notice-retention requirements.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/LICENSING.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Licensing and attribution
|
|
2
|
+
|
|
3
|
+
The Peekling Vite integration code and documentation are licensed under
|
|
4
|
+
Apache-2.0. The license allows personal and commercial use, modification,
|
|
5
|
+
distribution, and sublicensing subject to its terms.
|
|
6
|
+
|
|
7
|
+
Redistributions must comply with Section 4 of the Apache License 2.0, including
|
|
8
|
+
its applicable notice-retention requirements. When a distribution includes a
|
|
9
|
+
`NOTICE` file, Section 4 describes how readable copies of applicable NOTICE
|
|
10
|
+
attributions may be provided. Apache-2.0 does not require every website using
|
|
11
|
+
Peekling to display a visible attribution.
|
|
12
|
+
|
|
13
|
+
`AUTHORS` is a factual authorship record and does not add a license condition.
|
|
14
|
+
Character assets retain their declared Pack licenses. The Peekling name, logo,
|
|
15
|
+
official mascot, and other distinctive brand identity are outside this code
|
|
16
|
+
license except as allowed by applicable law or separate permission. See Section
|
|
17
|
+
6 of Apache-2.0.
|
|
18
|
+
|
|
19
|
+
The Apache License text controls if this summary conflicts with it. This summary
|
|
20
|
+
is informational and is not legal advice.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# `@peekling/vite`
|
|
2
|
+
|
|
3
|
+
Use the Peekling Vite plugin to validate declared Configuration and Pack JSON
|
|
4
|
+
when Vite starts, when either file changes, and before a production build. The
|
|
5
|
+
plugin runs in Node and does not add code or assets to the browser bundle.
|
|
6
|
+
|
|
7
|
+
## Prerequisites and installation
|
|
8
|
+
|
|
9
|
+
- Node.js 22.14.0 or newer
|
|
10
|
+
- Vite 8
|
|
11
|
+
- `@peekling/runtime` 0.1.0 in the application
|
|
12
|
+
|
|
13
|
+
Install the runtime and the development plugin:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @peekling/runtime@0.1.0
|
|
17
|
+
npm install --save-dev @peekling/vite@0.1.0
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Vite is a peer dependency. `@peekling/vite` depends on `@peekling/preflight`,
|
|
21
|
+
which uses the exact matching runtime version for shared validation.
|
|
22
|
+
|
|
23
|
+
## Configure the plugin
|
|
24
|
+
|
|
25
|
+
This framework-neutral example validates two JSON files inside the Vite root:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
// vite.config.js
|
|
29
|
+
import { defineConfig } from "vite";
|
|
30
|
+
import { peekling } from "@peekling/vite";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
plugins: [
|
|
34
|
+
peekling({
|
|
35
|
+
config: "src/peekling.json",
|
|
36
|
+
pack: "public/peekling/character.json",
|
|
37
|
+
baseUrl: "https://example.com/app/",
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
One matching project layout is:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
project/
|
|
47
|
+
vite.config.js
|
|
48
|
+
src/
|
|
49
|
+
peekling.json
|
|
50
|
+
public/
|
|
51
|
+
peekling/
|
|
52
|
+
character.json
|
|
53
|
+
atlas.png
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Expected result: Vite starts normally when both files pass Preflight. An invalid
|
|
57
|
+
file reports the diagnostic code, data path, explanation, and suggested fix.
|
|
58
|
+
During development, that invalid edit stops the affected hot update. During a
|
|
59
|
+
production build, it fails through Vite's plugin error channel.
|
|
60
|
+
|
|
61
|
+
Framework plugins can stay in the same `plugins` array. Peekling does not
|
|
62
|
+
require React, Vue, or another framework plugin.
|
|
63
|
+
|
|
64
|
+
## Options
|
|
65
|
+
|
|
66
|
+
| Option | Required | Meaning |
|
|
67
|
+
| --------- | -------- | ------------------------------------------------------------------------------ |
|
|
68
|
+
| `config` | Yes | Configuration JSON path relative to the resolved Vite root |
|
|
69
|
+
| `pack` | No | Pack JSON path relative to the resolved Vite root |
|
|
70
|
+
| `baseUrl` | No | Absolute HTTP or HTTPS page URL used to resolve relative serialized references |
|
|
71
|
+
|
|
72
|
+
Pass `pack` whenever the Plan names Pack States or Capabilities. Without Pack
|
|
73
|
+
context, Preflight cannot prove that those references exist.
|
|
74
|
+
|
|
75
|
+
When `baseUrl` is omitted, the plugin resolves Vite's configured `base` against
|
|
76
|
+
`https://peekling.invalid/`. That placeholder checks relative URL syntax without
|
|
77
|
+
claiming a deployment origin. Pass the real page URL when validation should
|
|
78
|
+
model an actual development or deployment path.
|
|
79
|
+
|
|
80
|
+
`baseUrl` may use HTTP for local development. Absolute resource URLs stored in
|
|
81
|
+
Configuration or Pack data must still use HTTPS.
|
|
82
|
+
|
|
83
|
+
## When validation runs
|
|
84
|
+
|
|
85
|
+
| Vite phase | Plugin behavior |
|
|
86
|
+
| ------------------------ | --------------------------------------------------------- |
|
|
87
|
+
| Configuration resolved | Resolves the real Vite root and confined input paths |
|
|
88
|
+
| Build start | Reads both files and fails the build on validation errors |
|
|
89
|
+
| Development server start | Confirms both inputs and registers them with the watcher |
|
|
90
|
+
| Hot update | Rechecks both inputs when either declared file changes |
|
|
91
|
+
|
|
92
|
+
A valid edit returns control to normal Vite hot module replacement. The plugin
|
|
93
|
+
does not transform the JSON into a client module or fetch the resource URLs it
|
|
94
|
+
contains.
|
|
95
|
+
|
|
96
|
+
## Node and browser graphs stay separate
|
|
97
|
+
|
|
98
|
+
```mermaid
|
|
99
|
+
flowchart TD
|
|
100
|
+
subgraph node[Node and Vite process]
|
|
101
|
+
data[Configuration and Pack JSON] --> plugin[@peekling/vite]
|
|
102
|
+
plugin --> preflight[@peekling/preflight]
|
|
103
|
+
preflight --> tooling[@peekling/runtime tooling subpaths]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
subgraph browser[Application browser graph]
|
|
107
|
+
app[Application code] --> runtime[@peekling/runtime]
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
In prose, the plugin and Preflight run only in Vite's Node process. Application
|
|
112
|
+
code imports the runtime separately. There is no client edge from the plugin to
|
|
113
|
+
the runtime, so the plugin does not inject Peekling JavaScript, CSS, CDN URLs,
|
|
114
|
+
or framework adapters.
|
|
115
|
+
|
|
116
|
+
Vite executes `vite.config.js` through its normal configuration boundary. Once
|
|
117
|
+
Vite calls `peekling(...)`, this plugin treats the supplied paths as data
|
|
118
|
+
locations and does not execute application source.
|
|
119
|
+
|
|
120
|
+
## File safety
|
|
121
|
+
|
|
122
|
+
Every declared input must resolve to a regular file inside the real Vite root.
|
|
123
|
+
The plugin rejects:
|
|
124
|
+
|
|
125
|
+
- symbolic links in the file or any parent path
|
|
126
|
+
- paths that resolve outside the root
|
|
127
|
+
- duplicate JSON object keys
|
|
128
|
+
- invalid UTF-8 or non-data input
|
|
129
|
+
- files larger than 64 KiB
|
|
130
|
+
- files whose identity changes around the bounded read
|
|
131
|
+
|
|
132
|
+
Watch registration applies the same path boundary before adding a file. Hot
|
|
133
|
+
updates read through the bounded path instead of Vite's unrestricted convenience
|
|
134
|
+
read.
|
|
135
|
+
|
|
136
|
+
## Troubleshooting
|
|
137
|
+
|
|
138
|
+
### Plan references cannot be checked
|
|
139
|
+
|
|
140
|
+
Add the Pack file to the plugin options:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
peekling({
|
|
144
|
+
config: "src/peekling.json",
|
|
145
|
+
pack: "public/peekling/character.json",
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### A relative URL resolves against the wrong page
|
|
150
|
+
|
|
151
|
+
Set `baseUrl` to the full page URL that will host the runtime:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
peekling({
|
|
155
|
+
config: "src/peekling.json",
|
|
156
|
+
pack: "public/peekling/character.json",
|
|
157
|
+
baseUrl: "https://example.com/docs/guide/",
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### A symlinked input is rejected
|
|
162
|
+
|
|
163
|
+
Move or copy the JSON data into the real Vite root. The plugin deliberately does
|
|
164
|
+
not follow a symbolic path outside that boundary.
|
|
165
|
+
|
|
166
|
+
## Related documentation
|
|
167
|
+
|
|
168
|
+
- [Configure Peekling](../../docs/configuration.md)
|
|
169
|
+
- [`@peekling/preflight`](../preflight/README.md)
|
|
170
|
+
- [`@peekling/cli`](../cli/README.md)
|
|
171
|
+
- [`@peekling/runtime`](../runtime/README.md)
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
Apache-2.0. See [licensing and attribution](LICENSING.md) for notice retention,
|
|
176
|
+
authorship, and brand boundaries.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export interface PeeklingViteOptions {
|
|
3
|
+
readonly config: string;
|
|
4
|
+
readonly pack?: string;
|
|
5
|
+
readonly baseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Validate data-only Peekling inputs during Vite development and builds. */
|
|
8
|
+
export declare function peekling(input: PeeklingViteOptions): Plugin;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAInD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CA6F3D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { constants, realpathSync } from "node:fs";
|
|
2
|
+
import { lstat, open, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { preflight } from "@peekling/preflight";
|
|
5
|
+
import { parseDataText } from "@peekling/preflight/json";
|
|
6
|
+
const MAX_INPUT_BYTES = 64 * 1024;
|
|
7
|
+
/** Validate data-only Peekling inputs during Vite development and builds. */
|
|
8
|
+
export function peekling(input) {
|
|
9
|
+
const options = snapshotOptions(input);
|
|
10
|
+
let viteConfig;
|
|
11
|
+
let viteRoot = "";
|
|
12
|
+
let configPath = "";
|
|
13
|
+
let packPath;
|
|
14
|
+
let configWatchPath = "";
|
|
15
|
+
let packWatchPath;
|
|
16
|
+
return {
|
|
17
|
+
name: "peekling:preflight",
|
|
18
|
+
enforce: "pre",
|
|
19
|
+
configResolved(config) {
|
|
20
|
+
viteConfig = config;
|
|
21
|
+
viteRoot = realpathSync(path.resolve(config.root));
|
|
22
|
+
configWatchPath = path.resolve(config.root, options.config);
|
|
23
|
+
packWatchPath = options.pack
|
|
24
|
+
? path.resolve(config.root, options.pack)
|
|
25
|
+
: undefined;
|
|
26
|
+
configPath = resolveInput(viteRoot, options.config, "config");
|
|
27
|
+
packPath = options.pack
|
|
28
|
+
? resolveInput(viteRoot, options.pack, "pack")
|
|
29
|
+
: undefined;
|
|
30
|
+
},
|
|
31
|
+
async buildStart() {
|
|
32
|
+
const report = await validateFiles();
|
|
33
|
+
for (const warning of report.warnings) {
|
|
34
|
+
this.warn(formatIssue("warning", warning));
|
|
35
|
+
}
|
|
36
|
+
if (!report.valid)
|
|
37
|
+
this.error(formatReport(report));
|
|
38
|
+
},
|
|
39
|
+
async configureServer(server) {
|
|
40
|
+
await Promise.all([
|
|
41
|
+
readJsonInput(configPath, viteRoot),
|
|
42
|
+
...(packPath ? [readJsonInput(packPath, viteRoot)] : []),
|
|
43
|
+
]);
|
|
44
|
+
server.watcher.add([configPath, ...(packPath ? [packPath] : [])]);
|
|
45
|
+
},
|
|
46
|
+
async handleHotUpdate(context) {
|
|
47
|
+
const candidate = path.resolve(context.file);
|
|
48
|
+
if (candidate !== configPath &&
|
|
49
|
+
candidate !== packPath &&
|
|
50
|
+
candidate !== configWatchPath &&
|
|
51
|
+
candidate !== packWatchPath) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let changed;
|
|
55
|
+
try {
|
|
56
|
+
changed = await canonicalCandidate(context.file, viteRoot);
|
|
57
|
+
}
|
|
58
|
+
catch (cause) {
|
|
59
|
+
if (cause.code !== "ENOENT")
|
|
60
|
+
throw cause;
|
|
61
|
+
const label = candidate === configPath || candidate === configWatchPath
|
|
62
|
+
? "config"
|
|
63
|
+
: "pack";
|
|
64
|
+
throw new Error(`Peekling ${label} input was removed during a hot update`);
|
|
65
|
+
}
|
|
66
|
+
const expected = candidate === packPath || candidate === packWatchPath
|
|
67
|
+
? packPath
|
|
68
|
+
: configPath;
|
|
69
|
+
if (changed !== expected) {
|
|
70
|
+
throw new Error("Peekling input has a symbolic path component");
|
|
71
|
+
}
|
|
72
|
+
const report = await validateFiles();
|
|
73
|
+
for (const warning of report.warnings) {
|
|
74
|
+
viteConfig?.logger?.warn(formatIssue("warning", warning));
|
|
75
|
+
}
|
|
76
|
+
if (!report.valid)
|
|
77
|
+
throw new Error(formatReport(report));
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
async function validateFiles() {
|
|
81
|
+
if (!viteConfig)
|
|
82
|
+
throw new Error("Peekling Vite plugin is not configured");
|
|
83
|
+
const configuration = await readJsonInput(configPath, viteRoot);
|
|
84
|
+
const pack = packPath ? await readJsonInput(packPath, viteRoot) : undefined;
|
|
85
|
+
return preflight(configuration, {
|
|
86
|
+
...(pack !== undefined ? { pack } : {}),
|
|
87
|
+
baseUrl: options.baseUrl ??
|
|
88
|
+
new URL(viteConfig.base, "https://peekling.invalid/").href,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function formatReport(report) {
|
|
92
|
+
return [
|
|
93
|
+
`Peekling validation failed for ${path.relative(viteConfig.root, configPath)}`,
|
|
94
|
+
...report.errors.map((issue) => formatIssue("error", issue)),
|
|
95
|
+
].join("\n");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function readJsonInput(target, root) {
|
|
99
|
+
const label = path.basename(target);
|
|
100
|
+
const canonical = await canonicalCandidate(target, root);
|
|
101
|
+
if (canonical !== target) {
|
|
102
|
+
throw new Error(`${label} has a symbolic path component`);
|
|
103
|
+
}
|
|
104
|
+
const metadata = await lstat(target);
|
|
105
|
+
if (metadata.isSymbolicLink()) {
|
|
106
|
+
throw new Error(`${label} must not be a symbolic link`);
|
|
107
|
+
}
|
|
108
|
+
if (!metadata.isFile())
|
|
109
|
+
throw new Error(`${label} must be a regular file`);
|
|
110
|
+
if (metadata.size > MAX_INPUT_BYTES) {
|
|
111
|
+
throw new Error(`${label} exceeds 65536 bytes`);
|
|
112
|
+
}
|
|
113
|
+
const handle = await open(target, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
114
|
+
try {
|
|
115
|
+
const opened = await handle.stat();
|
|
116
|
+
if (!opened.isFile())
|
|
117
|
+
throw new Error(`${label} must be a regular file`);
|
|
118
|
+
if (opened.dev !== metadata.dev || opened.ino !== metadata.ino) {
|
|
119
|
+
throw new Error(`${label} changed before it could be read`);
|
|
120
|
+
}
|
|
121
|
+
if (opened.size > MAX_INPUT_BYTES) {
|
|
122
|
+
throw new Error(`${label} exceeds 65536 bytes`);
|
|
123
|
+
}
|
|
124
|
+
const confirmed = await canonicalCandidate(target, root);
|
|
125
|
+
const current = await lstat(target);
|
|
126
|
+
if (confirmed !== target ||
|
|
127
|
+
current.isSymbolicLink() ||
|
|
128
|
+
current.dev !== opened.dev ||
|
|
129
|
+
current.ino !== opened.ino) {
|
|
130
|
+
throw new Error(`${label} changed before it could be read`);
|
|
131
|
+
}
|
|
132
|
+
const bytes = Buffer.alloc(MAX_INPUT_BYTES + 1);
|
|
133
|
+
let offset = 0;
|
|
134
|
+
while (offset < bytes.byteLength) {
|
|
135
|
+
const { bytesRead } = await handle.read(bytes, offset, bytes.byteLength - offset, offset);
|
|
136
|
+
if (bytesRead === 0)
|
|
137
|
+
break;
|
|
138
|
+
offset += bytesRead;
|
|
139
|
+
}
|
|
140
|
+
if (offset > MAX_INPUT_BYTES) {
|
|
141
|
+
throw new Error(`${label} exceeds 65536 bytes`);
|
|
142
|
+
}
|
|
143
|
+
const after = await canonicalCandidate(target, root);
|
|
144
|
+
const final = await lstat(target);
|
|
145
|
+
if (after !== target ||
|
|
146
|
+
final.isSymbolicLink() ||
|
|
147
|
+
final.dev !== opened.dev ||
|
|
148
|
+
final.ino !== opened.ino) {
|
|
149
|
+
throw new Error(`${label} changed while it was read`);
|
|
150
|
+
}
|
|
151
|
+
let text;
|
|
152
|
+
try {
|
|
153
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(0, offset));
|
|
154
|
+
}
|
|
155
|
+
catch (cause) {
|
|
156
|
+
throw new Error(`${label} must be valid UTF-8`, { cause });
|
|
157
|
+
}
|
|
158
|
+
return parseDataText(text, label);
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
await handle.close();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function canonicalCandidate(target, root) {
|
|
165
|
+
const canonical = await realpath(path.resolve(target));
|
|
166
|
+
const relative = path.relative(root, canonical);
|
|
167
|
+
if (relative === ".." ||
|
|
168
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
169
|
+
path.isAbsolute(relative)) {
|
|
170
|
+
throw new Error("Peekling input must stay inside the real Vite root");
|
|
171
|
+
}
|
|
172
|
+
return canonical;
|
|
173
|
+
}
|
|
174
|
+
function snapshotOptions(input) {
|
|
175
|
+
try {
|
|
176
|
+
if (!input ||
|
|
177
|
+
typeof input !== "object" ||
|
|
178
|
+
Array.isArray(input) ||
|
|
179
|
+
(Object.getPrototypeOf(input) !== Object.prototype &&
|
|
180
|
+
Object.getPrototypeOf(input) !== null)) {
|
|
181
|
+
throw new TypeError();
|
|
182
|
+
}
|
|
183
|
+
const descriptors = Object.getOwnPropertyDescriptors(input);
|
|
184
|
+
if (Object.getOwnPropertySymbols(input).length > 0)
|
|
185
|
+
throw new TypeError();
|
|
186
|
+
const output = Object.create(null);
|
|
187
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
188
|
+
if (!("value" in descriptor))
|
|
189
|
+
throw new TypeError();
|
|
190
|
+
output[key] = descriptor.value;
|
|
191
|
+
}
|
|
192
|
+
for (const key of Object.keys(output)) {
|
|
193
|
+
if (key !== "config" && key !== "pack" && key !== "baseUrl") {
|
|
194
|
+
throw new TypeError(`Unknown Peekling Vite option ${key}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const key of ["config", "pack"]) {
|
|
198
|
+
const value = output[key];
|
|
199
|
+
if ((key === "config" || value !== undefined) &&
|
|
200
|
+
(typeof value !== "string" ||
|
|
201
|
+
value.length < 1 ||
|
|
202
|
+
value.length > 4_096 ||
|
|
203
|
+
/[\0\r\n]/.test(value))) {
|
|
204
|
+
throw new TypeError(`Peekling Vite ${key} must be a bounded path`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (output.baseUrl !== undefined &&
|
|
208
|
+
(typeof output.baseUrl !== "string" || !absoluteHttpUrl(output.baseUrl))) {
|
|
209
|
+
throw new TypeError("Peekling Vite baseUrl must be an absolute HTTP or HTTPS URL");
|
|
210
|
+
}
|
|
211
|
+
return output;
|
|
212
|
+
}
|
|
213
|
+
catch (cause) {
|
|
214
|
+
if (cause instanceof TypeError && cause.message.includes("Peekling Vite"))
|
|
215
|
+
throw cause;
|
|
216
|
+
throw new TypeError("Peekling Vite options must be a plain object with own data properties");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function absoluteHttpUrl(value) {
|
|
220
|
+
try {
|
|
221
|
+
const parsed = new URL(value);
|
|
222
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function resolveInput(root, input, label) {
|
|
229
|
+
const resolved = path.resolve(root, input);
|
|
230
|
+
const relative = path.relative(path.resolve(root), resolved);
|
|
231
|
+
if (relative === ".." ||
|
|
232
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
233
|
+
path.isAbsolute(relative)) {
|
|
234
|
+
throw new Error(`Peekling ${label} input must stay inside the Vite root`);
|
|
235
|
+
}
|
|
236
|
+
if (path.extname(resolved).toLowerCase() !== ".json") {
|
|
237
|
+
throw new Error(`Peekling ${label} input must be a JSON data file`);
|
|
238
|
+
}
|
|
239
|
+
const canonical = realpathSync(resolved);
|
|
240
|
+
const canonicalRelative = path.relative(root, canonical);
|
|
241
|
+
if (canonicalRelative === ".." ||
|
|
242
|
+
canonicalRelative.startsWith(`..${path.sep}`) ||
|
|
243
|
+
path.isAbsolute(canonicalRelative)) {
|
|
244
|
+
throw new Error(`Peekling ${label} input must stay inside the real Vite root`);
|
|
245
|
+
}
|
|
246
|
+
if (canonical !== resolved) {
|
|
247
|
+
throw new Error(`Peekling ${label} input has a symbolic path component`);
|
|
248
|
+
}
|
|
249
|
+
return canonical;
|
|
250
|
+
}
|
|
251
|
+
function formatIssue(severity, issue) {
|
|
252
|
+
return `${severity.toUpperCase()} ${issue.code} at ${issue.path}\n ${issue.message}\n Fix: ${issue.fix}`;
|
|
253
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peekling/vite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Development-time Peekling validation for Vite projects",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Prajwal S. Venkateshmurthy",
|
|
8
|
+
"url": "https://prajwal.me"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/peekling/peekling-engine.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/peekling/peekling-engine#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/peekling/peekling-engine/issues"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.14.0"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"provenance": true
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/**/*.js",
|
|
28
|
+
"dist/**/*.d.ts",
|
|
29
|
+
"dist/**/*.d.ts.map",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"NOTICE",
|
|
33
|
+
"AUTHORS",
|
|
34
|
+
"LICENSING.md"
|
|
35
|
+
],
|
|
36
|
+
"main": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@peekling/preflight": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"vite": "^8.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -b",
|
|
52
|
+
"prepack": "npm --prefix ../.. run build",
|
|
53
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
54
|
+
"typecheck": "tsc -b --pretty false"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vite": "^8.2.2"
|
|
59
|
+
}
|
|
60
|
+
}
|