Skip to content

Commit b766f4b

Browse files
committed
add self context
1 parent 91e12fa commit b766f4b

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

lib/arraybuffer-loader.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
'use strict'
1+
"use strict";
22

3-
const loaderUtils = require('loader-utils')
3+
const loaderUtils = require("loader-utils");
44

55
module.exports = function (content) {
6-
if (this.cacheable) { this.cacheable() }
6+
if (this.cacheable) {
7+
this.cacheable();
8+
}
79

10+
const request = require.resolve("./to-array-buffer.js");
11+
12+
// loader-utils stringifyRequest was deprecated
813
const toArrayBufferPath =
9-
loaderUtils.stringifyRequest(this, require.resolve('./to-array-buffer.js'))
14+
this.utils && this.utils.contextify
15+
? JSON.stringify(
16+
this.utils.contextify(this.context || this.rootContext, request)
17+
)
18+
: loaderUtils.stringifyRequest(this, request);
1019

11-
const base64Data = content.toString('base64')
20+
const base64Data = content.toString("base64");
1221

1322
return `module.exports = require(${toArrayBufferPath})("${base64Data}")`;
14-
}
23+
};
1524

16-
module.exports.raw = true
25+
module.exports.raw = true;

lib/to-array-buffer.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
'use strict'
1+
"use strict";
22

33
module.exports = function (base64Data) {
4-
var isBrowser = typeof window !== 'undefined' && typeof window.atob === 'function'
5-
var binary = isBrowser ? window.atob(base64Data) : Buffer.from(base64Data, 'base64').toString('binary')
6-
var bytes = new Uint8Array(binary.length)
4+
var global =
5+
typeof window !== "undefined"
6+
? window
7+
: typeof self !== "undefined"
8+
? self
9+
: undefined;
10+
11+
var binary =
12+
global && typeof global.atob === "function"
13+
? global.atob(base64Data)
14+
: Buffer.from(base64Data, "base64").toString("binary");
15+
16+
var bytes = new Uint8Array(binary.length);
717

818
for (var i = 0; i < binary.length; ++i) {
9-
bytes[i] = binary.charCodeAt(i)
19+
bytes[i] = binary.charCodeAt(i);
1020
}
1121

12-
return bytes.buffer
13-
}
22+
return bytes.buffer;
23+
};

0 commit comments

Comments
 (0)