Skip to content

Commit 99af061

Browse files
committed
fix: remove xxhash dependency and use node:crypto
1 parent 9105501 commit 99af061

4 files changed

Lines changed: 38 additions & 50 deletions

File tree

package-lock.json

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rollup-plugin-html/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
"html-minifier-terser": "^7.1.0",
5050
"lightningcss": "^1.24.0",
5151
"parse5": "^6.0.1",
52-
"picomatch": "^2.2.2",
53-
"xxhash-wasm": "^1.1.0"
52+
"picomatch": "^2.2.2"
5453
},
5554
"devDependencies": {
5655
"@prettier/sync": "^0.6.1",

packages/rollup-plugin-html/src/output/emitAssets.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { createHash } from 'node:crypto';
12
import { PluginContext } from 'rollup';
23
import path from 'path';
34
import { bundleAsync, transform } from 'lightningcss';
45
import fs from 'fs';
5-
import xxhash from 'xxhash-wasm';
66

77
import { InputAsset, InputData } from '../input/InputData';
88
import { createAssetPicomatchMatcher } from '../assets/utils.js';
@@ -42,8 +42,6 @@ export async function emitAssets(
4242
inputs: InputData[],
4343
options: RollupPluginHTMLOptions,
4444
) {
45-
const { create64 } = await xxhash();
46-
4745
const extractAssets = options.extractAssets ?? true;
4846
const bundleCss = options.bundleCss ?? true;
4947
const minifyCss = options.minifyCss ?? false;
@@ -158,13 +156,11 @@ export async function emitAssets(
158156
assetInCss.ref = ref;
159157
assetInCss.outputPath = this.getFileName(ref);
160158
if (!extractAssetsLegacyCss) {
161-
assetInCss.hash = create64()
159+
assetInCss.hash = createHash('sha256')
162160
.update(transformedContent)
163161
.update('\0')
164162
.update(assetInCss.outputPath)
165-
.digest()
166-
.toString(16)
167-
.padStart(16, '0');
163+
.digest('hex');
168164
}
169165
}
170166

packages/rollup-plugin-html/test/rollup-plugin-html.test.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,20 +2123,20 @@ describe('rollup-plugin-html', () => {
21232123
expect(assets).to.have.keys([
21242124
'assets/font-normal-Cht9ZB76.woff2',
21252125
'assets/font-bold-eQjSonqH.woff2',
2126-
'assets/styles-CecXjwpw.css',
2126+
'assets/styles-BRQfqhN6.css',
21272127
'index.html',
21282128
]);
21292129

21302130
expect(assets['index.html']).to.equal(html`
21312131
<html>
21322132
<head>
2133-
<link rel="stylesheet" href="assets/styles-CecXjwpw.css" />
2133+
<link rel="stylesheet" href="assets/styles-BRQfqhN6.css" />
21342134
</head>
21352135
<body></body>
21362136
</html>
21372137
`);
21382138

2139-
expect(assets['assets/styles-CecXjwpw.css']).to.equal(css`
2139+
expect(assets['assets/styles-BRQfqhN6.css']).to.equal(css`
21402140
@font-face {
21412141
font-family: Font;
21422142
src: url('font-normal-Cht9ZB76.woff2') format('woff2');
@@ -2288,20 +2288,20 @@ describe('rollup-plugin-html', () => {
22882288
expect(assets).to.have.keys([
22892289
'assets/font-normal-Cht9ZB76.woff2',
22902290
'assets/font-bold-eQjSonqH.woff2',
2291-
'assets/styles-CecXjwpw.css',
2291+
'assets/styles-BRQfqhN6.css',
22922292
'index.html',
22932293
]);
22942294

22952295
expect(assets['index.html']).to.equal(html`
22962296
<html>
22972297
<head>
2298-
<link rel="stylesheet" href="assets/styles-CecXjwpw.css" />
2298+
<link rel="stylesheet" href="assets/styles-BRQfqhN6.css" />
22992299
</head>
23002300
<body></body>
23012301
</html>
23022302
`);
23032303

2304-
expect(assets['assets/styles-CecXjwpw.css']).to.equal(css`
2304+
expect(assets['assets/styles-BRQfqhN6.css']).to.equal(css`
23052305
@font-face {
23062306
font-family: Font;
23072307
src: url('font-normal-Cht9ZB76.woff2') format('woff2');
@@ -2453,22 +2453,22 @@ describe('rollup-plugin-html', () => {
24532453

24542454
expect(assets).to.have.keys([
24552455
'assets/font-normal-Cht9ZB76.woff2',
2456-
'assets/styles-a-rwPD8h6c.css',
2457-
'assets/styles-b-DbSntrij.css',
2456+
'assets/styles-a-CKKhzbId.css',
2457+
'assets/styles-b-DdUNHRx0.css',
24582458
'index.html',
24592459
]);
24602460

24612461
expect(assets['index.html']).to.equal(html`
24622462
<html>
24632463
<head>
2464-
<link rel="stylesheet" href="assets/styles-a-rwPD8h6c.css" />
2465-
<link rel="stylesheet" href="assets/styles-b-DbSntrij.css" />
2464+
<link rel="stylesheet" href="assets/styles-a-CKKhzbId.css" />
2465+
<link rel="stylesheet" href="assets/styles-b-DdUNHRx0.css" />
24662466
</head>
24672467
<body></body>
24682468
</html>
24692469
`);
24702470

2471-
expect(assets['assets/styles-a-rwPD8h6c.css']).to.equal(css`
2471+
expect(assets['assets/styles-a-CKKhzbId.css']).to.equal(css`
24722472
@font-face {
24732473
font-family: Font;
24742474
src: url('font-normal-Cht9ZB76.woff2') format('woff2');
@@ -2478,7 +2478,7 @@ describe('rollup-plugin-html', () => {
24782478
}
24792479
`);
24802480

2481-
expect(assets['assets/styles-b-DbSntrij.css']).to.equal(css`
2481+
expect(assets['assets/styles-b-DdUNHRx0.css']).to.equal(css`
24822482
@font-face {
24832483
font-family: Font2;
24842484
src: url('font-normal-Cht9ZB76.woff2') format('woff2');
@@ -2565,20 +2565,20 @@ describe('rollup-plugin-html', () => {
25652565
'assets/star-CXig10q7.png',
25662566
'assets/star-CwhgM_z4.svg',
25672567
'assets/star-CKbh5mKn.webp',
2568-
'assets/styles-BDpW-xH8.css',
2568+
'assets/styles-DgHxUupJ.css',
25692569
'index.html',
25702570
]);
25712571

25722572
expect(assets['index.html']).to.equal(html`
25732573
<html>
25742574
<head>
2575-
<link rel="stylesheet" href="assets/styles-BDpW-xH8.css" />
2575+
<link rel="stylesheet" href="assets/styles-DgHxUupJ.css" />
25762576
</head>
25772577
<body></body>
25782578
</html>
25792579
`);
25802580

2581-
expect(assets['assets/styles-BDpW-xH8.css']).to.equal(css`
2581+
expect(assets['assets/styles-DgHxUupJ.css']).to.equal(css`
25822582
#a {
25832583
background-image: url('star-D_LO5feX.avif');
25842584
}
@@ -2814,7 +2814,7 @@ describe('rollup-plugin-html', () => {
28142814
expect(assets).to.have.keys([
28152815
'assets/image-a-XOCPHCrV.png',
28162816
'assets/image-b-BgQHKcRn.png',
2817-
'assets/styles-ChLnYIUS.css',
2817+
'assets/styles-pLj9D-P3.css',
28182818
'assets/webmanifest-BkrOR1WG.json',
28192819
'index.html',
28202820
]);
@@ -2827,7 +2827,7 @@ describe('rollup-plugin-html', () => {
28272827
<link rel="manifest" href="assets/webmanifest-BkrOR1WG.json" />
28282828
<link rel="mask-icon" href="./image-a.svg" color="#3f93ce" />
28292829
<link rel="mask-icon" href="image-b.svg" color="#3f93ce" />
2830-
<link rel="stylesheet" href="assets/styles-ChLnYIUS.css" />
2830+
<link rel="stylesheet" href="assets/styles-pLj9D-P3.css" />
28312831
<link rel="stylesheet" href="./foo/x.css" />
28322832
<link rel="stylesheet" href="foo/bar/y.css" />
28332833
</head>
@@ -2840,7 +2840,7 @@ describe('rollup-plugin-html', () => {
28402840
</html>
28412841
`);
28422842
2843-
expect(assets['assets/styles-ChLnYIUS.css']).to.equal(css`
2843+
expect(assets['assets/styles-pLj9D-P3.css']).to.equal(css`
28442844
#a1 {
28452845
background-image: url('image-a-XOCPHCrV.png');
28462846
}
@@ -3044,17 +3044,17 @@ describe('rollup-plugin-html', () => {
30443044

30453045
expect(assets).to.have.keys([
30463046
'static/font.immutable.C5MNjX-h.woff2',
3047-
'static/global.immutable.CMNZTtZG.css',
3047+
'static/global.immutable.BRYeVgdd.css',
30483048
'static/image.immutable.7xJLr_7N.png',
3049-
'static/styles.immutable.A_CLU19q.css',
3049+
'static/styles.immutable.exe7_Vpw.css',
30503050
'index.html',
30513051
]);
30523052

30533053
expect(assets['index.html']).to.equal(html`
30543054
<html>
30553055
<head>
3056-
<link rel="stylesheet" href="static/global.immutable.CMNZTtZG.css" />
3057-
<link rel="stylesheet" href="static/styles.immutable.A_CLU19q.css" />
3056+
<link rel="stylesheet" href="static/global.immutable.BRYeVgdd.css" />
3057+
<link rel="stylesheet" href="static/styles.immutable.exe7_Vpw.css" />
30583058
<link
30593059
rel="preload"
30603060
href="static/font.immutable.C5MNjX-h.woff2"
@@ -3068,7 +3068,7 @@ describe('rollup-plugin-html', () => {
30683068
</html>
30693069
`);
30703070

3071-
expect(assets['static/global.immutable.CMNZTtZG.css']).to.equal(css`
3071+
expect(assets['static/global.immutable.BRYeVgdd.css']).to.equal(css`
30723072
@font-face {
30733073
font-family: Font;
30743074
src: url('font.immutable.C5MNjX-h.woff2') format('woff2');
@@ -3078,7 +3078,7 @@ describe('rollup-plugin-html', () => {
30783078
}
30793079
`);
30803080

3081-
expect(assets['static/styles.immutable.A_CLU19q.css']).to.equal(css`
3081+
expect(assets['static/styles.immutable.exe7_Vpw.css']).to.equal(css`
30823082
#a {
30833083
background-image: url('image.immutable.7xJLr_7N.png');
30843084
}
@@ -3157,17 +3157,17 @@ describe('rollup-plugin-html', () => {
31573157

31583158
expect(assets).to.have.keys([
31593159
'fonts/font.immutable.C5MNjX-h.woff2',
3160-
'styles/global.immutable.D9Em-vEE.css',
3160+
'styles/global.immutable.CIo7MOhV.css',
31613161
'images/image.immutable.7xJLr_7N.png',
3162-
'styles/styles.immutable.Boq6Yn2f.css',
3162+
'styles/styles.immutable.BxCpevuY.css',
31633163
'index.html',
31643164
]);
31653165

31663166
expect(assets['index.html']).to.equal(html`
31673167
<html>
31683168
<head>
3169-
<link rel="stylesheet" href="/static/styles/global.immutable.D9Em-vEE.css" />
3170-
<link rel="stylesheet" href="/static/styles/styles.immutable.Boq6Yn2f.css" />
3169+
<link rel="stylesheet" href="/static/styles/global.immutable.CIo7MOhV.css" />
3170+
<link rel="stylesheet" href="/static/styles/styles.immutable.BxCpevuY.css" />
31713171
<link
31723172
rel="preload"
31733173
href="/static/fonts/font.immutable.C5MNjX-h.woff2"
@@ -3181,7 +3181,7 @@ describe('rollup-plugin-html', () => {
31813181
</html>
31823182
`);
31833183

3184-
expect(assets['styles/global.immutable.D9Em-vEE.css']).to.equal(css`
3184+
expect(assets['styles/global.immutable.CIo7MOhV.css']).to.equal(css`
31853185
@font-face {
31863186
font-family: Font;
31873187
src: url('/static/fonts/font.immutable.C5MNjX-h.woff2') format('woff2');
@@ -3191,7 +3191,7 @@ describe('rollup-plugin-html', () => {
31913191
}
31923192
`);
31933193

3194-
expect(assets['styles/styles.immutable.Boq6Yn2f.css']).to.equal(css`
3194+
expect(assets['styles/styles.immutable.BxCpevuY.css']).to.equal(css`
31953195
#a {
31963196
background-image: url('/static/images/image.immutable.7xJLr_7N.png');
31973197
}
@@ -3357,7 +3357,7 @@ describe('rollup-plugin-html', () => {
33573357

33583358
expect(assets).to.have.keys([
33593359
'assets/bg-image-B8JuQo5R.png',
3360-
'assets/styles-BxLNtjaG.css',
3360+
'assets/styles-Brz3za0w.css',
33613361
'index.html',
33623362
]);
33633363

@@ -3419,8 +3419,8 @@ describe('rollup-plugin-html', () => {
34193419

34203420
expect(assets).to.have.keys([
34213421
'assets/filters-BNeK3QVf.svg',
3422-
'assets/design-system-32qJiweK.css',
3423-
'assets/styles-l1gnljqF.css',
3422+
'assets/design-system-DznFRd92.css',
3423+
'assets/styles-CWG_g22Q.css',
34243424
'index.html',
34253425
]);
34263426

0 commit comments

Comments
 (0)