Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit d994567

Browse files
committed
fix: do not register the plugin twice
1 parent a0237cc commit d994567

File tree

2 files changed

+0
-56
lines changed

2 files changed

+0
-56
lines changed

src/plugin.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/* eslint-disable consistent-return */
22
/* eslint-disable no-useless-escape */
3-
const path = require('path');
4-
5-
const { createFsFromVolume, Volume } = require('memfs');
6-
const webpack = require('webpack');
73

84
const installer = require('./installer');
95
const utils = require('./utils');
@@ -48,9 +44,6 @@ class NpmInstallPlugin {
4844
apply(compiler) {
4945
this.compiler = compiler;
5046

51-
// Recursively install missing dependencies so primary build doesn't fail
52-
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, this.preCompile.bind(this));
53-
5447
// Install externals that wouldn't normally be resolved
5548
if (Array.isArray(compiler.options.externals)) {
5649
compiler.options.externals.unshift(this.resolveExternal.bind(this));
@@ -97,28 +90,6 @@ class NpmInstallPlugin {
9790
}
9891
}
9992

100-
preCompile(compilation, next) {
101-
if (!this.preCompiler) {
102-
const { options } = this.compiler;
103-
const config = Object.assign(
104-
// Start with new config object
105-
{},
106-
// Inherit the current config
107-
options,
108-
{
109-
// Register plugin to install missing deps
110-
plugins: [new NpmInstallPlugin(this.options)],
111-
}
112-
);
113-
114-
this.preCompiler = webpack(config);
115-
this.preCompiler.outputFileSystem = createFsFromVolume(new Volume());
116-
this.preCompiler.outputFileSystem.join = path.join.bind(path);
117-
}
118-
119-
this.preCompiler.run(next);
120-
}
121-
12293
resolveExternal(context, request, callback) {
12394
// Only install direct dependencies, not sub-dependencies
12495
if (context.match('node_modules')) {

test/plugin.test.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,6 @@ describe('plugin', () => {
5656
});
5757
});
5858

59-
describe('.preCompile', () => {
60-
beforeEach(() => {
61-
this.run = jest
62-
.spyOn(webpack.Compiler.prototype, 'run')
63-
.mockImplementation((callback) => {
64-
callback();
65-
});
66-
});
67-
68-
afterEach(() => {
69-
this.run.mockRestore();
70-
});
71-
72-
it('should perform dryrun', (done) => {
73-
const compilation = {};
74-
75-
this.plugin.preCompile(
76-
compilation,
77-
// eslint-disable-next-line
78-
function () {
79-
expect(this.run).toHaveBeenCalled();
80-
done();
81-
}.bind(this)
82-
);
83-
});
84-
});
85-
8659
describe('.resolveExternal', () => {
8760
beforeEach(() => {
8861
this.resolve = jest

0 commit comments

Comments
 (0)