diff --git a/source/node.ts b/source/node.ts index c341ff7..3ea81e4 100644 --- a/source/node.ts +++ b/source/node.ts @@ -47,6 +47,7 @@ type NormalisedEntity = E extends any export class NodeManager { private createNode: NodePluginArgs['actions']['createNode']; private deleteNode: NodePluginArgs['actions']['deleteNode']; + private touchNode: NodePluginArgs['actions']['touchNode']; private createNodeId: NodePluginArgs['createNodeId']; private createContentDigest: NodePluginArgs['createContentDigest']; private cache: NodePluginArgs['cache']; @@ -59,7 +60,7 @@ export class NodeManager { constructor(args: NodePluginArgs) { /* eslint-disable @typescript-eslint/unbound-method */ const { - actions: { createNode, deleteNode }, + actions: { createNode, deleteNode, touchNode }, cache, createContentDigest, createNodeId, @@ -70,6 +71,7 @@ export class NodeManager { this.cache = cache; this.createNode = createNode; this.deleteNode = deleteNode; + this.touchNode = touchNode; this.createNodeId = createNodeId; this.createContentDigest = createContentDigest; this.reporter = reporter; @@ -101,7 +103,13 @@ export class NodeManager { */ private addNodes(added: NormalisedEntity[]): void { for (const entity of added) { - this.createNode(this.nodifyEntity(entity)); + const node = this.nodifyEntity(entity); + + // make sure that the node will remain in the cache + this.touchNode(node); + + // create the node + this.createNode(node); } // don't be noisy if there's nothing new happen diff --git a/spec/node.spec.ts b/spec/node.spec.ts index 9f31b0d..409c370 100644 --- a/spec/node.spec.ts +++ b/spec/node.spec.ts @@ -202,11 +202,12 @@ describe('cl:NodeManager', () => { it('always keep gatsby synced', async () => { const createNode = jest.fn(); const deleteNode = jest.fn(); + const touchNode = jest.fn(); const createContentDigest = jest.fn(hashFn); const createNodeId = jest.fn((id) => id); const manager = new NodeManager({ - actions: { createNode, deleteNode }, + actions: { createNode, deleteNode, touchNode }, cache: caching({ store: 'memory', ttl: 0 }), createContentDigest, createNodeId,