Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit f05b878

Browse files
[release patch] Updated dependencies
- Updated esbuild and std - Replaced SHA256 in std/hash/mod.ts into Web Crypto in std/crypto
1 parent d6e761c commit f05b878

File tree

4 files changed

+66
-71
lines changed

4 files changed

+66
-71
lines changed

deno.lock

Lines changed: 44 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * as esbuild from 'https://deno.land/x/esbuild@v0.17.18/mod.js';
2-
export { posix } from 'https://deno.land/std@0.186.0/path/mod.ts';
3-
export * as fs from 'https://deno.land/std@0.186.0/fs/mod.ts';
4-
export * as sha256 from 'https://deno.land/std@0.119.0/hash/sha256.ts';
5-
export * as asserts from 'https://deno.land/std@0.186.0/testing/asserts.ts';
1+
export * as esbuild from 'https://deno.land/x/esbuild@v0.17.19/mod.js';
2+
export { posix } from 'https://deno.land/std@0.189.0/path/mod.ts';
3+
export * as fs from 'https://deno.land/std@0.189.0/fs/mod.ts';
4+
export { crypto } from 'https://deno.land/std@0.189.0/crypto/mod.ts';
5+
export * as asserts from 'https://deno.land/std@0.189.0/testing/asserts.ts';

mod.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { esbuild, posix, sha256 } from './deps.ts';
1+
import { esbuild, posix, crypto } from './deps.ts';
22
import type { Importmap } from './src/importmap.ts';
33
import type { LockMap } from './src/types.ts';
44
import ImportmapResolver from './src/importmap.ts';
@@ -247,10 +247,13 @@ function esbuildCachePlugin(options: Options): esbuild.Plugin {
247247

248248
try {
249249
const contents = await Deno.readFile(pluginData.cachePath);
250-
const hashContext = new sha256.Sha256();
251-
const contentsHash = hashContext.update(contents).toString();
250+
const hashArrayBuffer = await crypto.subtle.digest('SHA-256', contents);
251+
const hashView = new Uint8Array(hashArrayBuffer);
252+
const hashHexString = Array.from(hashView)
253+
.map((b) => b.toString(16).padStart(2, '0'))
254+
.join('');
252255

253-
if (contentsHash !== pluginData.fileHash) {
256+
if (hashHexString !== pluginData.fileHash) {
254257
return {
255258
errors: [{ text: `Outdated cache detected for ${args.path}` }],
256259
};

src/http.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sha256 } from "../deps.ts";
1+
import { crypto } from "../deps.ts";
22
import ImportmapResolver from "./importmap.ts";
33

44
const resolveImport = function(
@@ -34,9 +34,15 @@ const resolveImport = function(
3434
const toCacheURL = function(url: URL, cacheRoot: URL) {
3535
const protocol = url.protocol.slice(0, -1);
3636
const hostname = url.hostname;
37-
const hashContext = new sha256.Sha256();
38-
const pathHash = hashContext.update(url.pathname).toString();
39-
const path = ['deps', protocol, hostname, pathHash].join('/');
37+
// calculate hash of pathname
38+
const pathCodeArray = [...url.pathname].map(char => char.charCodeAt(0));
39+
const pathArray = new Uint8Array(pathCodeArray);
40+
const pathHashArray = crypto.subtle.digestSync('SHA-256', pathArray);
41+
const pathHashView = new Uint8Array(pathHashArray);
42+
const pathHashHexString = Array.from(pathHashView)
43+
.map((b) => b.toString(16).padStart(2, '0'))
44+
.join('');
45+
const path = ['deps', protocol, hostname, pathHashHexString].join('/');
4046

4147
return new URL(path, cacheRoot);
4248
}

0 commit comments

Comments
 (0)