Skip to content

Commit

Permalink
fix: compatibility with dynamic import (#3006)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Oct 18, 2021
1 parent 5a51043 commit 6a9aac9
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 27 deletions.
8 changes: 1 addition & 7 deletions packages/webpack-cli/bin/cli.js
Expand Up @@ -2,12 +2,6 @@

"use strict";

const Module = require("module");

const originalModuleCompile = Module.prototype._compile;

require("v8-compile-cache");

const importLocal = require("import-local");
const runCLI = require("../lib/bootstrap");

Expand All @@ -20,4 +14,4 @@ if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) {

process.title = "webpack";

runCLI(process.argv, originalModuleCompile);
runCLI(process.argv);
4 changes: 1 addition & 3 deletions packages/webpack-cli/lib/bootstrap.js
@@ -1,12 +1,10 @@
const WebpackCLI = require("./webpack-cli");

const runCLI = async (args, originalModuleCompile) => {
const runCLI = async (args) => {
// Create a new instance of the CLI object
const cli = new WebpackCLI();

try {
cli._originalModuleCompile = originalModuleCompile;

await cli.run(args);
} catch (error) {
cli.logger.error(error);
Expand Down
15 changes: 0 additions & 15 deletions packages/webpack-cli/lib/webpack-cli.js
@@ -1,7 +1,6 @@
const fs = require("fs");
const path = require("path");
const { pathToFileURL } = require("url");
const Module = require("module");
const util = require("util");

const { program, Option } = require("commander");
Expand Down Expand Up @@ -244,21 +243,7 @@ class WebpackCLI {
try {
result = require(module);
} catch (error) {
let previousModuleCompile;

// TODO Workaround https://github.com/zertosh/v8-compile-cache/issues/30
if (this._originalModuleCompile) {
previousModuleCompile = Module.prototype._compile;

Module.prototype._compile = this._originalModuleCompile;
}

const dynamicImportLoader = require("./utils/dynamic-import-loader")();

if (this._originalModuleCompile) {
Module.prototype._compile = previousModuleCompile;
}

if (
(error.code === "ERR_REQUIRE_ESM" || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) &&
pathToFileURL &&
Expand Down
1 change: 0 additions & 1 deletion packages/webpack-cli/package.json
Expand Up @@ -40,7 +40,6 @@
"import-local": "^3.0.2",
"interpret": "^2.2.0",
"rechoir": "^0.7.0",
"v8-compile-cache": "^2.2.0",
"webpack-merge": "^5.7.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -10814,7 +10814,7 @@ uuid@^3.3.2, uuid@^3.3.3, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

v8-compile-cache@^2.0.3, v8-compile-cache@^2.2.0:
v8-compile-cache@^2.0.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
Expand Down

0 comments on commit 6a9aac9

Please sign in to comment.