Skip to content

Commit fa591ff

Browse files
committed
fix(source): do not edit source.include
1 parent 2548b35 commit fa591ff

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { parseContent } from './utils/content'
2727
import { installMDCModule } from './utils/mdc'
2828
import { findPreset } from './presets'
2929
import type { Manifest } from './types/manifest'
30+
import { parseSourceBase } from './utils/source'
3031

3132
// Export public utils
3233
export * from './utils'
@@ -239,6 +240,7 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
239240
await collection.source.prepare(nuxt)
240241
}
241242

243+
const { fixed } = parseSourceBase(collection.source)
242244
const cwd = collection.source.cwd
243245
const _keys = await fastGlob(collection.source.include, { cwd, ignore: collection.source!.exclude || [], dot: true })
244246
.catch(() => [])
@@ -248,8 +250,10 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
248250
const list: Array<Array<string>> = []
249251
for await (const chunk of chunks(_keys, 25)) {
250252
await Promise.all(chunk.map(async (key) => {
253+
key = key.substring(fixed.length)
251254
const keyInCollection = join(collection.name, collection.source?.prefix || '', key)
252-
const content = await readFile(join(cwd, key), 'utf8')
255+
256+
const content = await readFile(join(cwd, fixed, key), 'utf8')
253257
const checksum = getContentChecksum(configHash + collectionHash + content)
254258
const cache = databaseContents[keyInCollection]
255259

src/runtime/internal/websocket.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ export function useContentWebSocket() {
2424

2525
const db = await loadDatabaseAdapter(data.collection)
2626

27-
for (const s of data.queries) {
28-
await db.exec(s).catch((err: unknown) => console.log(err))
29-
}
27+
await data.queries.reduce(async (prev: Promise<void>, sql: string) => {
28+
await prev
29+
await db.exec(sql).catch((err: unknown) => console.log(err))
30+
}, Promise.resolve())
3031

3132
refreshNuxtData()
3233
}

src/utils/dev.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { Manifest } from '../types/manifest'
1717
import { generateCollectionInsert } from './collection'
1818
import { parseContent } from './content'
1919
import { moduleTemplates } from './templates'
20+
import { parseSourceBase } from './source'
2021

2122
export const logger: ConsolaInstance = useLogger('@nuxt/content')
2223

@@ -87,8 +88,9 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
8788
const collection = localCollections.find(({ source }) => micromatch.isMatch(path, source!.include, { ignore: source!.exclude || [], dot: true }))
8889
if (collection) {
8990
logger.info(`File \`${path}\` changed on \`${collection.name}\` collection`)
91+
const { fixed } = parseSourceBase(collection.source!)
9092

91-
const filePath = join(cwd, path).replace(collection.source!.cwd, '')
93+
const filePath = path.substring(fixed.length)
9294
const keyInCollection = join(collection.name, collection.source?.prefix || '', filePath)
9395

9496
const content = await readFile(join(nuxt.options.rootDir, 'content', path), 'utf8')
@@ -114,8 +116,9 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
114116
const collection = localCollections.find(({ source }) => micromatch.isMatch(path, source!.include, { ignore: source!.exclude || [], dot: true }))
115117
if (collection) {
116118
logger.info(`File \`${path}\` removed from \`${collection.name}\` collection`)
119+
const { fixed } = parseSourceBase(collection.source!)
117120

118-
const filePath = join(cwd, path).replace(collection.source!.cwd, '')
121+
const filePath = path.substring(fixed.length)
119122
const keyInCollection = join(collection.name, collection.source?.prefix || '', filePath)
120123

121124
await db.deleteDevelopmentCache(keyInCollection)

src/utils/source.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import type { CollectionSource, ResolvedCollectionSource } from '../types/collec
44
import { downloadRepository, parseGitHubUrl } from './git'
55

66
export function defineLocalSource(source: CollectionSource): ResolvedCollectionSource {
7-
const { fixed, dynamic } = parseSourceBase(source)
7+
const { fixed } = parseSourceBase(source)
88
const resolvedSource: ResolvedCollectionSource = {
99
_resolved: true,
1010
prefix: withoutTrailingSlash(withLeadingSlash(fixed)),
1111
...source,
12-
include: dynamic,
13-
cwd: withoutTrailingSlash(join('~~/content/', fixed)),
12+
include: source.include,
13+
cwd: '',
1414
prepare: async (nuxt) => {
1515
resolvedSource.cwd = source.cwd
1616
? String(source.cwd).replace(/^~~\//, nuxt.options.rootDir)
17-
: join(nuxt.options.rootDir, 'content', fixed)
17+
: join(nuxt.options.rootDir, 'content')
1818
},
1919
}
2020
return resolvedSource

0 commit comments

Comments
 (0)