Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions src/plugin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* eslint-disable consistent-return */
/* eslint-disable no-useless-escape */
const path = require('path');

const { createFsFromVolume, Volume } = require('memfs');
const webpack = require('webpack');

const installer = require('./installer');
const utils = require('./utils');
Expand Down Expand Up @@ -48,9 +44,6 @@ class NpmInstallPlugin {
apply(compiler) {
this.compiler = compiler;

// Recursively install missing dependencies so primary build doesn't fail
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, this.preCompile.bind(this));

// Install externals that wouldn't normally be resolved
if (Array.isArray(compiler.options.externals)) {
compiler.options.externals.unshift(this.resolveExternal.bind(this));
Expand Down Expand Up @@ -97,28 +90,6 @@ class NpmInstallPlugin {
}
}

preCompile(compilation, next) {
if (!this.preCompiler) {
const { options } = this.compiler;
const config = Object.assign(
// Start with new config object
{},
// Inherit the current config
options,
{
// Register plugin to install missing deps
plugins: [new NpmInstallPlugin(this.options)],
}
);

this.preCompiler = webpack(config);
this.preCompiler.outputFileSystem = createFsFromVolume(new Volume());
this.preCompiler.outputFileSystem.join = path.join.bind(path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep it otherwise webpack serve will not work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify(maybe I misunderstood), how will webpack serve get affected?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use webpack server we use memory memory fs so install packages will not work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this is unused for some reason 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't have test with webpack-dev-server, we need to add them

}

this.preCompiler.run(next);
}

resolveExternal(context, request, callback) {
// Only install direct dependencies, not sub-dependencies
if (context.match('node_modules')) {
Expand Down
27 changes: 0 additions & 27 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,6 @@ describe('plugin', () => {
});
});

describe('.preCompile', () => {
beforeEach(() => {
this.run = jest
.spyOn(webpack.Compiler.prototype, 'run')
.mockImplementation((callback) => {
callback();
});
});

afterEach(() => {
this.run.mockRestore();
});

it('should perform dryrun', (done) => {
const compilation = {};

this.plugin.preCompile(
compilation,
// eslint-disable-next-line
function () {
expect(this.run).toHaveBeenCalled();
done();
}.bind(this)
);
});
});

describe('.resolveExternal', () => {
beforeEach(() => {
this.resolve = jest
Expand Down