Skip to content

Commit

Permalink
fix: force no caching via addDependency hack
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Nov 30, 2021
1 parent 3e7cef2 commit 8981147
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ describe('loader', () => {
it('throws if async is not available', () => {
let caught = false;
try {
loader.call({ async: () => null, cacheable: () => {} });
loader.call({
async: () => null,
cacheable: jest.fn(),
addDependency: jest.fn(),
});
} catch (e) {
caught = true;
expect(e.message).toBe(
Expand All @@ -151,7 +155,8 @@ describe('loader', () => {
loader.call(
{
async: () => callback,
cacheable: () => {},
cacheable: jest.fn(),
addDependency: jest.fn(),
resourcePath: require.resolve('./__example-files__/simple.preval.ts'),
},
''
Expand All @@ -174,7 +179,8 @@ describe('loader', () => {
{
async: () => callback,
resource: 'test-resource',
cacheable: () => {},
cacheable: jest.fn(),
addDependency: jest.fn(),
resourcePath: require.resolve('./__example-files__/throws.preval.ts'),
},
''
Expand Down
10 changes: 10 additions & 0 deletions src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import path from 'path';
import type webpack from 'webpack';
import requireFromString from 'require-from-string';
// @ts-expect-error
Expand Down Expand Up @@ -140,6 +141,15 @@ const loader = function (

this.cacheable(false);

// TODO: add comment (this implementation will be refined later)
const depFileFilename = path.resolve(
__dirname,
'.next-plugin-preval-depfile'
);
fs.writeFileSync(depFileFilename, Math.random().toString());

this.addDependency(depFileFilename);

if (!callback) {
throw new PrevalError(
'Async was not supported by webpack. Please open an issue in next-plugin-preval.'
Expand Down

0 comments on commit 8981147

Please sign in to comment.