@aaronellington/vite-plugin-inkwell 0.0.1 → 0.0.4
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/package.json +1 -1
- package/src/plugin.ts +10 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aaronellington/vite-plugin-inkwell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A Vite plugin that transforms directories of markdown files into typed, lazy-loaded content collections with frontmatter parsing, asset hashing, and HMR.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Aaron Ellington",
|
package/src/plugin.ts
CHANGED
|
@@ -117,9 +117,10 @@ export function inkwell(options?: ContentPluginOptions): Plugin {
|
|
|
117
117
|
},
|
|
118
118
|
enforce: "pre",
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
const { file
|
|
120
|
+
hotUpdate(ctx) {
|
|
121
|
+
const { file } = ctx
|
|
122
122
|
if (!file.endsWith(".md")) return
|
|
123
|
+
if (!server) return
|
|
123
124
|
|
|
124
125
|
// Find which watched directory this file belongs to
|
|
125
126
|
let matchedDir: string | undefined
|
|
@@ -137,15 +138,15 @@ export function inkwell(options?: ContentPluginOptions): Plugin {
|
|
|
137
138
|
collections.set(matchedDir, items)
|
|
138
139
|
} catch (error) {
|
|
139
140
|
const message = error instanceof Error ? error.message : String(error)
|
|
140
|
-
|
|
141
|
+
server.config.logger.error(message)
|
|
141
142
|
return []
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
// Invalidate the collection module
|
|
145
146
|
const collectionId = RESOLVED_PREFIX + matchedDir
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
|
|
147
|
+
const mod = this.environment.moduleGraph.getModuleById(collectionId)
|
|
148
|
+
if (mod) {
|
|
149
|
+
this.environment.moduleGraph.invalidateModule(mod)
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
// Invalidate the changed file's slug module
|
|
@@ -157,13 +158,13 @@ export function inkwell(options?: ContentPluginOptions): Plugin {
|
|
|
157
158
|
matchedDir +
|
|
158
159
|
SLUG_SEPARATOR +
|
|
159
160
|
changedItem.frontmatter.slug
|
|
160
|
-
const slugModule =
|
|
161
|
+
const slugModule = this.environment.moduleGraph.getModuleById(slugId)
|
|
161
162
|
if (slugModule) {
|
|
162
|
-
|
|
163
|
+
this.environment.moduleGraph.invalidateModule(slugModule)
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
|
|
167
|
+
server.hot.send({ type: "full-reload" })
|
|
167
168
|
return []
|
|
168
169
|
},
|
|
169
170
|
|