From 803d2e6cc717556dcfed00d52574587e972ebc70 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Jun 2024 17:02:26 +0200 Subject: [PATCH] fix(config): add back md4 monkey-patch for wider ecosystem (#27865) --- packages/config/src/options.js | 11 +++++++++++ packages/config/test/config/index.test.js | 1 + packages/config/test/options.test.js | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/config/src/options.js b/packages/config/src/options.js index 7af27fb161..0e5365d343 100644 --- a/packages/config/src/options.js +++ b/packages/config/src/options.js @@ -520,6 +520,17 @@ export function getNuxtConfig (_options) { options.build.indicator = false } + // Monkey patch crypto.createHash in dev/build to upgrade hashing fnction + if (parseInt(process.versions.node.slice(0, 2)) > 16 && !options.buildModules.some(m => m.name === 'patchMD4')) { + options.buildModules.push(function patchMD4 () { + const crypto = require('crypto') + const _createHash = crypto.createHash + crypto.createHash = function (algorithm, options) { + return _createHash(algorithm === 'md4' ? 'md5' : algorithm, options) + } + }) + } + // Components Module if (!options._start && getPKG('@nuxt/components')) { options._modules.push('@nuxt/components') diff --git a/packages/config/test/config/index.test.js b/packages/config/test/config/index.test.js index dc177953c5..8fd43da57e 100644 --- a/packages/config/test/config/index.test.js +++ b/packages/config/test/config/index.test.js @@ -24,6 +24,7 @@ describe('config', () => { UNIX_SOCKET: '/var/run/nuxt.sock' } const config = getDefaultNuxtConfig({ env }) + config.buildModules = config.buildModules.filter(p => p.name !== 'patchMD4') expect(config).toMatchSnapshot() }) }) diff --git a/packages/config/test/options.test.js b/packages/config/test/options.test.js index 696d9e37c5..ea577782ff 100644 --- a/packages/config/test/options.test.js +++ b/packages/config/test/options.test.js @@ -34,6 +34,7 @@ describe('config: options', () => { } } }) + config.buildModules = config.buildModules.filter(p => p.name !== 'patchMD4') expect(config).toMatchSnapshot() process.cwd.mockRestore() @@ -297,7 +298,7 @@ describe('config: options', () => { const config = getNuxtConfig({ devModules: ['foo'], buildModules: ['bar'] }) expect(consola.warn).toHaveBeenCalledWith('`devModules` has been renamed to `buildModules` and will be removed in Nuxt 3.') expect(config.devModules).toBe(undefined) - expect(config.buildModules).toEqual(['bar', 'foo']) + expect(config.buildModules.filter(p => p.name !== 'patchMD4')).toEqual(['bar', 'foo']) }) test('should deprecate build.extractCSS.allChunks', () => {