mirror of
https://github.com/emn178/js-sha256.git
synced 2026-08-12 20:32:16 +08:00
fix recognize environment is node when use browserfs #53
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix uploading coverage to coveralls #52
|
- Fix uploading coverage to coveralls #52
|
||||||
|
- fix recognize environment is node when use browserfs #53
|
||||||
|
|
||||||
## v0.11.1 / 2025-05-24
|
## v0.11.1 / 2025-05-24
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -29,7 +29,7 @@ var sha256$1 = {exports: {}};
|
|||||||
WINDOW = false;
|
WINDOW = false;
|
||||||
}
|
}
|
||||||
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
||||||
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node && process.type != 'renderer';
|
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && !WINDOW && typeof process === 'object' && process.versions && process.versions.node && process.type != 'renderer';
|
||||||
if (NODE_JS) {
|
if (NODE_JS) {
|
||||||
root = commonjsGlobal;
|
root = commonjsGlobal;
|
||||||
} else if (WEB_WORKER) {
|
} else if (WEB_WORKER) {
|
||||||
|
|||||||
+5
-4
@@ -5,10 +5,11 @@ const disableNodeJs = {
|
|||||||
name: 'disable-node-js',
|
name: 'disable-node-js',
|
||||||
transform(code, id) {
|
transform(code, id) {
|
||||||
if (id.endsWith('/src/sha256.js')) {
|
if (id.endsWith('/src/sha256.js')) {
|
||||||
return code.replace(
|
const nodeJsDeclaration = /^\s*var NODE_JS = .*;$/m;
|
||||||
"var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node && process.type != 'renderer';",
|
if (!nodeJsDeclaration.test(code)) {
|
||||||
'var NODE_JS = false;'
|
this.error('Could not find the NODE_JS declaration');
|
||||||
);
|
}
|
||||||
|
return code.replace(nodeJsDeclaration, ' var NODE_JS = false;');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,6 +36,23 @@ function runWindowTest() {
|
|||||||
unset();
|
unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runBrowserWithProcessPolyfillTest() {
|
||||||
|
var Module = require('module');
|
||||||
|
var originalRequire = Module.prototype.require;
|
||||||
|
window = global;
|
||||||
|
Module.prototype.require = function (id) {
|
||||||
|
if (id === 'crypto' || id === 'buffer') {
|
||||||
|
throw new Error('Node.js module loaded in browser environment');
|
||||||
|
}
|
||||||
|
return originalRequire.apply(this, arguments);
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
runCommonJsTest();
|
||||||
|
} finally {
|
||||||
|
Module.prototype.require = originalRequire;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Node.js env
|
// Node.js env
|
||||||
BUFFER = true;
|
BUFFER = true;
|
||||||
runCommonJsTest();
|
runCommonJsTest();
|
||||||
@@ -44,6 +61,9 @@ runCommonJsTest();
|
|||||||
JS_SHA256_NO_BUFFER_FROM = true
|
JS_SHA256_NO_BUFFER_FROM = true
|
||||||
runCommonJsTest();
|
runCommonJsTest();
|
||||||
|
|
||||||
|
// browser env with a Node.js process polyfill
|
||||||
|
runBrowserWithProcessPolyfillTest();
|
||||||
|
|
||||||
// Webpack browser env
|
// Webpack browser env
|
||||||
JS_SHA256_NO_NODE_JS = true;
|
JS_SHA256_NO_NODE_JS = true;
|
||||||
window = global;
|
window = global;
|
||||||
|
|||||||
Reference in New Issue
Block a user