Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: update serialize-javascript
  • Loading branch information
alexander-akait committed Mar 3, 2026
commit 5d2092397c03e73ed231dc503e8272b1d103e4fc
23 changes: 22 additions & 1 deletion scripts/copy-serialize-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ const path = require("path");

/* eslint-disable no-console */

const randomBytesFallback = `
var g = typeof globalThis !== 'undefined' ? globalThis : global;
var crypto = g.crypto || {};

if (typeof crypto.getRandomValues !== 'function') {
var nodeCrypto = require('crypto');

crypto.getRandomValues = function(typedArray) {
var bytes = nodeCrypto.randomBytes(typedArray.byteLength);

new Uint8Array(
typedArray.buffer,
typedArray.byteOffset,
typedArray.byteLength
).set(bytes);

return typedArray;
};
}
`;

/**
* @param {string} src source path
* @param {string} dest destination path
Expand All @@ -14,7 +35,7 @@ async function copyIfChanged(src, dest) {

try {
srcContent = await fs.readFile(src, "utf8");
srcContent = `// @ts-nocheck\n${srcContent}`;
srcContent = `// @ts-nocheck\n${randomBytesFallback}${srcContent}`;
} catch (_err) {
srcContent = null;
}
Expand Down
21 changes: 21 additions & 0 deletions src/serialize-javascript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
// @ts-nocheck

var g = typeof globalThis !== 'undefined' ? globalThis : global;
var crypto = g.crypto || {};

if (typeof crypto.getRandomValues !== 'function') {
var nodeCrypto = require('crypto');

crypto.getRandomValues = function(typedArray) {
// Генерируем буфер случайных байтов нужной длины

Choose a reason for hiding this comment

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

this and following comments are not present in the scripts/copy-serialize-javascript.js, which is supposed to generate (prepend fallback to) this file.

this necessarily means lint:serialize-javascript will always fail, since it compares “fallback with comments + copied code” to “fallback without comments + copied code”, those are never equal.

comments are in russian for some reason, interesting!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

var bytes = nodeCrypto.randomBytes(typedArray.byteLength);

// Копируем байты в типизированный массив через Uint8Array View
new Uint8Array(
typedArray.buffer,
typedArray.byteOffset,
typedArray.byteLength
).set(bytes);

return typedArray;
};
}
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
Expand Down
Loading