@jk2908/mdsrc 0.1.3 → 0.1.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/CHANGELOG.md +7 -0
- package/dist/index.js +39 -7
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.4 - 2026-04-27
|
|
4
|
+
|
|
5
|
+
- Fixed generated `.mdsrc/index.d.ts` to export collection symbols directly, so root `.mdsrc` imports like `import { allPosts } from '../../.mdsrc'` typecheck correctly.
|
|
6
|
+
- Fixed `@jk2908/mdsrc` runtime imports in Vite apps by resolving the package name to generated collection data instead of the plugin package entry.
|
|
7
|
+
- Switched generated collection module filenames to lowercase while keeping the exported symbol names unchanged.
|
package/dist/index.js
CHANGED
|
@@ -115,6 +115,9 @@ function debounce(fn, wait) {
|
|
|
115
115
|
|
|
116
116
|
// src/index.ts
|
|
117
117
|
var fileCache = new Map;
|
|
118
|
+
function toModuleName(name) {
|
|
119
|
+
return name.toLowerCase();
|
|
120
|
+
}
|
|
118
121
|
function parse(content) {
|
|
119
122
|
const regex = /^---\r?\n([\s\S]*?)\r?\n---([\s\S]*)$/;
|
|
120
123
|
const match = content.match(regex);
|
|
@@ -317,6 +320,12 @@ async function build(src, buildContext) {
|
|
|
317
320
|
promises.push(maybeWrite(path.join(outDir, "index.d.ts"), `
|
|
318
321
|
import type { ${names.map((name) => capitalise(name)).join(", ")} } from './types.js'
|
|
319
322
|
|
|
323
|
+
${names.map((name) => `
|
|
324
|
+
export const all${capitalise(pluralise(name, 2))}: ${capitalise(name)}[]
|
|
325
|
+
`).join(`
|
|
326
|
+
|
|
327
|
+
`)}
|
|
328
|
+
|
|
320
329
|
declare module '${PKG_NAME}' {
|
|
321
330
|
${names.map((name) => `
|
|
322
331
|
export const all${capitalise(pluralise(name, 2))}: ${capitalise(name)}[]
|
|
@@ -327,9 +336,10 @@ async function build(src, buildContext) {
|
|
|
327
336
|
`.trim()));
|
|
328
337
|
for (const name of names) {
|
|
329
338
|
const collection = collections[name]?.items;
|
|
330
|
-
|
|
339
|
+
const fileName = toModuleName(name);
|
|
340
|
+
promises.push(maybeWrite(path.join(outDir, `${fileName}.js`), `export const all${capitalise(pluralise(name, 2))} = ${collection?.length ? JSON.stringify(collection) : "[]"}`.trim()));
|
|
331
341
|
}
|
|
332
|
-
promises.push(maybeWrite(path.join(outDir, "index.js"), names.map((name) => `export * from './${name}.js'`).join(`
|
|
342
|
+
promises.push(maybeWrite(path.join(outDir, "index.js"), names.map((name) => `export * from './${toModuleName(name)}.js'`).join(`
|
|
333
343
|
`)));
|
|
334
344
|
const writes = await Promise.all(promises);
|
|
335
345
|
buildContext.names = names;
|
|
@@ -377,9 +387,9 @@ function plugin(src) {
|
|
|
377
387
|
try {
|
|
378
388
|
const changed = await build(src, buildContext);
|
|
379
389
|
if (changed)
|
|
380
|
-
logger2.info(`[watch]:
|
|
390
|
+
logger2.info(`[watch]: content rebuilt (${rebuildReason})`);
|
|
381
391
|
} catch (err) {
|
|
382
|
-
logger2.error("[watch]
|
|
392
|
+
logger2.error("[watch] content rebuild failed", err);
|
|
383
393
|
}
|
|
384
394
|
} while (rebuildQueued);
|
|
385
395
|
rebuildRunning = false;
|
|
@@ -394,6 +404,27 @@ function plugin(src) {
|
|
|
394
404
|
return {
|
|
395
405
|
name: "mdsrc",
|
|
396
406
|
enforce: "pre",
|
|
407
|
+
config(viteConfig) {
|
|
408
|
+
viteConfig.optimizeDeps ??= {};
|
|
409
|
+
viteConfig.optimizeDeps.exclude = [
|
|
410
|
+
...new Set([...viteConfig.optimizeDeps.exclude ?? [], PKG_NAME])
|
|
411
|
+
];
|
|
412
|
+
viteConfig.resolve ??= {};
|
|
413
|
+
if (Array.isArray(viteConfig.resolve.alias)) {
|
|
414
|
+
viteConfig.resolve.alias = [
|
|
415
|
+
...viteConfig.resolve.alias,
|
|
416
|
+
{
|
|
417
|
+
find: PKG_NAME,
|
|
418
|
+
replacement: path.join(outDir, "index.js")
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
} else {
|
|
422
|
+
viteConfig.resolve.alias = {
|
|
423
|
+
...viteConfig.resolve.alias,
|
|
424
|
+
[PKG_NAME]: path.join(outDir, "index.js")
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
},
|
|
397
428
|
async buildStart() {
|
|
398
429
|
await build(src, buildContext);
|
|
399
430
|
},
|
|
@@ -407,8 +438,9 @@ function plugin(src) {
|
|
|
407
438
|
}
|
|
408
439
|
if (id.startsWith(`${PKG_NAME}/`)) {
|
|
409
440
|
const subpath = id.slice(PKG_NAME.length + 1);
|
|
410
|
-
|
|
411
|
-
|
|
441
|
+
const match = buildContext.names.find((name) => name === subpath || toModuleName(name) === subpath);
|
|
442
|
+
if (match) {
|
|
443
|
+
return path.join(outDir, `${toModuleName(match)}.js`);
|
|
412
444
|
}
|
|
413
445
|
}
|
|
414
446
|
return null;
|
|
@@ -420,4 +452,4 @@ export {
|
|
|
420
452
|
create
|
|
421
453
|
};
|
|
422
454
|
|
|
423
|
-
//# debugId=
|
|
455
|
+
//# debugId=C119839BC806C05964756E2164756E21
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jk2908/mdsrc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Jerome Kenway",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"description": "A Vite plugin for managing markdown content with type safety",
|
|
40
40
|
"files": [
|
|
41
41
|
"dist/*.js",
|
|
42
|
-
"dist/*.d.ts"
|
|
42
|
+
"dist/*.d.ts",
|
|
43
|
+
"CHANGELOG.md"
|
|
43
44
|
],
|
|
44
45
|
"homepage": "https://github.com/jk2908/mdsrc#readme",
|
|
45
46
|
"keywords": [
|