Skip to content

Commit e2da9d5

Browse files
committed
better browser bundling support
1 parent bca7065 commit e2da9d5

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

lib/CachedInputFileSystem.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/** @typedef {import("./Resolver").FileSystem} FileSystem */
99
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
1010

11+
const nextTick = require("process").nextTick;
12+
1113
const dirname = path => {
1214
let idx = path.length - 1;
1315
while (idx >= 0) {
@@ -175,8 +177,8 @@ class CacheBackend {
175177
// Check in cache
176178
let cacheEntry = this._data.get(path);
177179
if (cacheEntry !== undefined) {
178-
if (cacheEntry.err) return process.nextTick(callback, cacheEntry.err);
179-
return process.nextTick(callback, null, cacheEntry.result);
180+
if (cacheEntry.err) return nextTick(callback, cacheEntry.err);
181+
return nextTick(callback, null, cacheEntry.result);
180182
}
181183

182184
// Check if there is already the same operation running

lib/ResolverFactory.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"use strict";
77

8+
const versions = require("process").versions;
89
const Resolver = require("./Resolver");
910
const { getType, PathType } = require("./util/path");
1011

@@ -112,7 +113,7 @@ const UseFilePlugin = require("./UseFilePlugin");
112113
function processPnpApiOption(option) {
113114
if (
114115
option === undefined &&
115-
/** @type {NodeJS.ProcessVersions & {pnp: string}} */ (process.versions).pnp
116+
/** @type {NodeJS.ProcessVersions & {pnp: string}} */ (versions).pnp
116117
) {
117118
// @ts-ignore
118119
return require("pnpapi"); // eslint-disable-line node/no-missing-require

lib/util/process-browser.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
6+
"use strict";
7+
8+
exports.process = {
9+
versions: {},
10+
nextTick(fn) {
11+
const args = Array.prototype.slice.call(arguments, 1);
12+
Promise.resolve().then(function () {
13+
fn.apply(null, args);
14+
});
15+
}
16+
};

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"types.d.ts",
99
"LICENSE"
1010
],
11+
"browser": {
12+
"pnpapi": false,
13+
"process": "./lib/util/process-browser.js"
14+
},
1115
"dependencies": {
1216
"graceful-fs": "^4.2.4",
1317
"tapable": "^2.0.0"

0 commit comments

Comments
 (0)