Skip to content

Commit 75bfbfe

Browse files
committed
fix: add workaround for hds-core cookie consent
HDS 6.0.2 ships cookieConsent.ts but not cookieConsent.js at the path required by hds-react, causing build failures. Add fix-hds-shim script that creates a compatible shim from cookieConsent.css. The shim uses an ES module-shaped export and avoids Node built-ins so webpack/browser bundling works. Refs: LINK-2463
1 parent 188c3d1 commit 75bfbfe

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ Run tests and generate coverage report
161161
Generates `public/env-config.js` (and in test mode `public/test-env-config.js`) from runtime environment variables.
162162
This is run automatically by `pnpm dev`, `pnpm start`, `pnpm test`, and `pnpm test:coverage`, but can also be run manually when needed.
163163

164+
### `pnpm fix-hds-shim`
165+
166+
Workaround for a packaging issue in `hds-core@6.x`: generates a missing `cookieConsent.js` file that `hds-react` expects but the package does not ship.
167+
This is run automatically by `pnpm dev` and `pnpm build`. Run it manually if you encounter a `MODULE_NOT_FOUND` error for `hds-core/lib/components/cookie-consent/cookieConsent` after installing dependencies.
168+
Can be removed once HDS publishes a fixed release.
169+
164170
## Debugging
165171

166172
### Debugging project in VS Code

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"pnpm": ">=11.1.3"
99
},
1010
"scripts": {
11-
"dev": "pnpm update-runtime-env && next dev -p 3001",
12-
"build": "next build",
11+
"dev": "pnpm fix-hds-shim && pnpm update-runtime-env && next dev -p 3001",
12+
"build": "pnpm fix-hds-shim && next build",
1313
"start": "pnpm update-runtime-env && next start -p 3001",
1414
"lint": "eslint .",
1515
"prepare": "husky",
@@ -19,7 +19,8 @@
1919
"test:e2e:ci": "playwright test",
2020
"test:e2e:start": "playwright test",
2121
"test:e2e:record": "playwright codegen https://linkedregistrations.dev.hel.ninja/",
22-
"update-runtime-env": "node scripts/update-runtime-env.js . ./public"
22+
"update-runtime-env": "node scripts/update-runtime-env.js . ./public",
23+
"fix-hds-shim": "node scripts/fix-hds-core-cookie-consent.js"
2324
},
2425
"dependencies": {
2526
"@juggle/resize-observer": "^3.4.0",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable no-console */
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const targetDir = path.join(
6+
process.cwd(),
7+
'node_modules',
8+
'hds-core',
9+
'lib',
10+
'components',
11+
'cookie-consent'
12+
);
13+
14+
const targetFile = path.join(targetDir, 'cookieConsent.js');
15+
const cssFile = path.join(targetDir, 'cookieConsent.css');
16+
17+
if (!fs.existsSync(targetDir)) {
18+
console.error(
19+
'[fix-hds-core-cookie-consent] Failed: hds-core cookie-consent directory not found.'
20+
);
21+
process.exit(1);
22+
}
23+
if (!fs.existsSync(cssFile)) {
24+
console.error(
25+
'[fix-hds-core-cookie-consent] Failed: cookieConsent.css not found; cannot create shim.'
26+
);
27+
process.exit(1);
28+
}
29+
30+
const cssContent = fs.readFileSync(cssFile, 'utf8');
31+
const shimContent = `'use strict';\n\nconst css = ${JSON.stringify(cssContent)};\n\nmodule.exports = { __esModule: true, default: css };\n`;
32+
33+
if (!fs.existsSync(targetFile)) {
34+
fs.writeFileSync(targetFile, shimContent, 'utf8');
35+
console.log(
36+
'[fix-hds-core-cookie-consent] Created cookieConsent.js shim for hds-react compatibility.'
37+
);
38+
} else {
39+
const currentContent = fs.readFileSync(targetFile, 'utf8');
40+
41+
if (currentContent !== shimContent) {
42+
fs.writeFileSync(targetFile, shimContent, 'utf8');
43+
console.log(
44+
'[fix-hds-core-cookie-consent] Updated cookieConsent.js shim for hds-react compatibility.'
45+
);
46+
} else {
47+
console.log(
48+
'[fix-hds-core-cookie-consent] cookieConsent.js shim already up to date.'
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)