From d6a7ccc98fe7488665a087c59584c962e75365f1 Mon Sep 17 00:00:00 2001 From: "Dinh Truong (SlncTrZ)" <46520299+SlncTrZ@users.noreply.github.com> Date: Sat, 9 May 2026 14:15:50 +0700 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20resolve=20#572=20=E2=80=94=20Conside?= =?UTF-8?q?r=20not=20parsing/stringifying=20cached=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #572 Signed-off-by: Dinh Truong (SlncTrZ) <46520299+SlncTrZ@users.noreply.github.com> --- src/schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/schema.json b/src/schema.json index 13ee9fb6..e74bf26b 100644 --- a/src/schema.json +++ b/src/schema.json @@ -20,6 +20,10 @@ "type": "boolean", "default": true }, + "cacheRaw": { + "type": "boolean", + "default": false + }, "customize": { "anyOf": [ { From 0048c5899b8fbd4f76b03200be02f69bb3cfeabf Mon Sep 17 00:00:00 2001 From: "Dinh Truong (SlncTrZ)" <46520299+SlncTrZ@users.noreply.github.com> Date: Sat, 9 May 2026 14:15:52 +0700 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20resolve=20#572=20=E2=80=94=20Conside?= =?UTF-8?q?r=20not=20parsing/stringifying=20cached=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #572 Signed-off-by: Dinh Truong (SlncTrZ) <46520299+SlncTrZ@users.noreply.github.com> --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index 78f980b5..5a291136 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ * @property {string} [cacheDirectory] Directory to store cached files. * @property {string} [cacheIdentifier] Unique identifier to bust cache. * @property {boolean} [cacheCompression] Whether to compress cached files. + * @property {boolean} [cacheRaw] Whether to use raw v8 serialization for cache files. * @property {string} [customize] The absolute path of a file that exports a BabelLoaderWrapper. * @property {Array} [metadataSubscribers] Names of subscribers registered in the loader context. */ @@ -55,6 +56,7 @@ if (/^6\./.test(babel.version)) { const { version } = require("../package.json"); const cache = require("./cache"); +const v8 = require("v8"); const transform = require("./transform"); const injectCaller = require("./injectCaller"); const schema = require("./schema.json"); From 78b89b1df668fa0febae45b029c8363cc02a3623 Mon Sep 17 00:00:00 2001 From: "Dinh Truong (SlncTrZ)" <46520299+SlncTrZ@users.noreply.github.com> Date: Sat, 9 May 2026 14:15:53 +0700 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20resolve=20#572=20=E2=80=94=20Conside?= =?UTF-8?q?r=20not=20parsing/stringifying=20cached=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #572 Signed-off-by: Dinh Truong (SlncTrZ) <46520299+SlncTrZ@users.noreply.github.com> --- src/cache.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cache.js b/src/cache.js index 5a158ee8..7653879c 100644 --- a/src/cache.js +++ b/src/cache.js @@ -13,6 +13,7 @@ const path = require("path"); const zlib = require("zlib"); const { promisify } = require("util"); const { readFile, writeFile, mkdir } = require("fs/promises"); +const v8 = require("v8"); const { sync: findUpSync } = require("find-up"); const { env } = process; const transform = require("./transform"); @@ -50,10 +51,13 @@ const gzip = promisify(zlib.gzip); * @param {string} filename * @param {boolean} compress */ -const read = async function (filename, compress) { +const read = async function (filename, compress, raw) { const data = await readFile(filename + (compress ? ".gz" : "")); const content = compress ? await gunzip(data) : data; + if (raw) { + return v8.deserialize(content); + } return JSON.parse(content.toString()); }; @@ -64,11 +68,16 @@ const read = async function (filename, compress) { * @param {boolean} compress * @param {any} result */ -const write = async function (filename, compress, result) { - const content = JSON.stringify(result); - - const data = compress ? await gzip(content) : content; - return await writeFile(filename + (compress ? ".gz" : ""), data); +const write = async function (filename, compress, result, raw) { + let data; + if (raw) { + data = v8.serialize(result); + } else { + const content = JSON.stringify(result); + data = compress ? await gzip(content) : content; + } + const path = filename + (compress && !raw ? ".gz" : ""); + return await writeFile(path, data); }; /**