@contentlayer/client
Advanced tools
Comparing version 0.0.2-16 to 0.0.2-17
@@ -1,2 +0,2 @@ | ||
import { Cache, Config, GetDocumentTypeGen, GetDocumentTypeNamesGen, GetDocumentTypesGen } from '@contentlayer/core'; | ||
import { Cache, GetDocumentTypeGen, GetDocumentTypeNamesGen, GetDocumentTypesGen, SourcePlugin } from '@contentlayer/core'; | ||
export declare const getDocuments: () => import("@contentlayer/core").Document[]; | ||
@@ -6,6 +6,6 @@ export declare class ContentlayerClient { | ||
cache?: Cache; | ||
config?: Config; | ||
source?: SourcePlugin; | ||
}); | ||
private cache; | ||
private config; | ||
private source; | ||
fetchData(): Promise<void>; | ||
@@ -12,0 +12,0 @@ private setCache; |
@@ -53,4 +53,4 @@ "use strict"; | ||
}; | ||
if (props === null || props === void 0 ? void 0 : props.config) { | ||
this.config = props.config; | ||
if (props === null || props === void 0 ? void 0 : props.source) { | ||
this.source = props.source; | ||
} | ||
@@ -62,13 +62,5 @@ else { | ||
else { | ||
// this.cache = require(`${process.cwd()}/node_modules/.contentlayer/cache.json`) | ||
// needs to use `eval` otherwise can't import from `node_modules` | ||
eval("delete require.cache[require.resolve(\".contentlayer/cache.json\")]"); | ||
this.cache = eval("require(\".contentlayer/cache.json\")"); | ||
// if (process.env.NODE_ENV === 'development') { | ||
// import('fs').then((fs) => { | ||
// fs.watchFile(`${process.cwd()}/node_modules/.contentlayer/cache.json`, () => { | ||
// eval(`delete require.cache[require.resolve(".contentlayer/cache.json")]`) | ||
// this.cache = eval(`require(".contentlayer/cache.json")`) | ||
// }) | ||
// }) | ||
// } | ||
} | ||
@@ -83,6 +75,6 @@ } | ||
case 0: | ||
if (this.config === undefined) { | ||
throw new Error("When running `fetchData`, you need to provide the `config` property when initializing the ContentlayerClient"); | ||
if (this.source === undefined) { | ||
throw new Error("When running `fetchData`, you need to provide the `source` property when initializing the ContentlayerClient"); | ||
} | ||
observable = this.config.source.fetchData({ | ||
observable = this.source.fetchData({ | ||
watch: false, | ||
@@ -89,0 +81,0 @@ force: false, |
@@ -1,2 +0,2 @@ | ||
import { Cache, Config, GetDocumentTypeGen, GetDocumentTypeNamesGen, GetDocumentTypesGen } from '@contentlayer/core'; | ||
import { Cache, GetDocumentTypeGen, GetDocumentTypeNamesGen, GetDocumentTypesGen, SourcePlugin } from '@contentlayer/core'; | ||
export declare const getDocuments: () => import("@contentlayer/core").Document[]; | ||
@@ -6,6 +6,6 @@ export declare class ContentlayerClient { | ||
cache?: Cache; | ||
config?: Config; | ||
source?: SourcePlugin; | ||
}); | ||
private cache; | ||
private config; | ||
private source; | ||
fetchData(): Promise<void>; | ||
@@ -12,0 +12,0 @@ private setCache; |
@@ -21,4 +21,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
if (props === null || props === void 0 ? void 0 : props.config) { | ||
this.config = props.config; | ||
if (props === null || props === void 0 ? void 0 : props.source) { | ||
this.source = props.source; | ||
} | ||
@@ -30,13 +30,5 @@ else { | ||
else { | ||
// this.cache = require(`${process.cwd()}/node_modules/.contentlayer/cache.json`) | ||
// needs to use `eval` otherwise can't import from `node_modules` | ||
eval(`delete require.cache[require.resolve(".contentlayer/cache.json")]`); | ||
this.cache = eval(`require(".contentlayer/cache.json")`); | ||
// if (process.env.NODE_ENV === 'development') { | ||
// import('fs').then((fs) => { | ||
// fs.watchFile(`${process.cwd()}/node_modules/.contentlayer/cache.json`, () => { | ||
// eval(`delete require.cache[require.resolve(".contentlayer/cache.json")]`) | ||
// this.cache = eval(`require(".contentlayer/cache.json")`) | ||
// }) | ||
// }) | ||
// } | ||
} | ||
@@ -47,6 +39,6 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.config === undefined) { | ||
throw new Error(`When running \`fetchData\`, you need to provide the \`config\` property when initializing the ContentlayerClient`); | ||
if (this.source === undefined) { | ||
throw new Error(`When running \`fetchData\`, you need to provide the \`source\` property when initializing the ContentlayerClient`); | ||
} | ||
const observable = this.config.source.fetchData({ | ||
const observable = this.source.fetchData({ | ||
watch: false, | ||
@@ -53,0 +45,0 @@ force: false, |
{ | ||
"name": "@contentlayer/client", | ||
"version": "0.0.2-16", | ||
"version": "0.0.2-17", | ||
"main": "./dist/cjs/index.js", | ||
@@ -18,6 +18,6 @@ "module": "./dist/esm/index.js", | ||
"dependencies": { | ||
"@contentlayer/core": "0.0.2-16", | ||
"@contentlayer/utils": "0.0.2-16", | ||
"rxjs": "^7.0.0" | ||
"@contentlayer/core": "0.0.2-17", | ||
"@contentlayer/utils": "0.0.2-17", | ||
"rxjs": "^7.0.1" | ||
} | ||
} |
@@ -8,2 +8,3 @@ import { | ||
GetDocumentTypesGen, | ||
SourcePlugin, | ||
} from '@contentlayer/core' | ||
@@ -17,5 +18,5 @@ import { recRemoveUndefinedValues } from '@contentlayer/utils' | ||
export class ContentlayerClient { | ||
constructor(props?: { cache?: Cache; config?: Config }) { | ||
if (props?.config) { | ||
this.config = props.config | ||
constructor(props?: { cache?: Cache; source?: SourcePlugin }) { | ||
if (props?.source) { | ||
this.source = props.source | ||
} else { | ||
@@ -25,14 +26,5 @@ if (props?.cache) { | ||
} else { | ||
// this.cache = require(`${process.cwd()}/node_modules/.contentlayer/cache.json`) | ||
// needs to use `eval` otherwise can't import from `node_modules` | ||
eval(`delete require.cache[require.resolve(".contentlayer/cache.json")]`) | ||
this.cache = eval(`require(".contentlayer/cache.json")`) | ||
// if (process.env.NODE_ENV === 'development') { | ||
// import('fs').then((fs) => { | ||
// fs.watchFile(`${process.cwd()}/node_modules/.contentlayer/cache.json`, () => { | ||
// eval(`delete require.cache[require.resolve(".contentlayer/cache.json")]`) | ||
// this.cache = eval(`require(".contentlayer/cache.json")`) | ||
// }) | ||
// }) | ||
// } | ||
} | ||
@@ -43,11 +35,11 @@ } | ||
private cache: CacheGen | undefined | ||
private config: Config | undefined | ||
private source: Config | undefined | ||
async fetchData(): Promise<void> { | ||
if (this.config === undefined) { | ||
if (this.source === undefined) { | ||
throw new Error( | ||
`When running \`fetchData\`, you need to provide the \`config\` property when initializing the ContentlayerClient`, | ||
`When running \`fetchData\`, you need to provide the \`source\` property when initializing the ContentlayerClient`, | ||
) | ||
} | ||
const observable = this.config.source.fetchData({ | ||
const observable = this.source.fetchData({ | ||
watch: false, | ||
@@ -54,0 +46,0 @@ force: false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
636785
472
+ Added@contentlayer/core@0.0.2-17(transitive)
+ Added@contentlayer/utils@0.0.2-17(transitive)
+ Addedtype-fest@1.4.0(transitive)
- Removed@contentlayer/core@0.0.2-16(transitive)
- Removed@contentlayer/utils@0.0.2-16(transitive)
Updated@contentlayer/core@0.0.2-17
Updated@contentlayer/utils@0.0.2-17
Updatedrxjs@^7.0.1