summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/big-years-type.md5
-rw-r--r--packages/astro/package.json1
-rw-r--r--packages/astro/src/@types/shorthash.d.ts5
-rw-r--r--packages/astro/src/core/create-vite.ts1
-rw-r--r--packages/astro/src/runtime/server/index.ts4
-rw-r--r--packages/astro/src/runtime/server/shorthash.ts67
-rw-r--r--pnpm-lock.yaml6
7 files changed, 74 insertions, 15 deletions
diff --git a/.changeset/big-years-type.md b/.changeset/big-years-type.md
new file mode 100644
index 000000000..bb68c4c23
--- /dev/null
+++ b/.changeset/big-years-type.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Internal: removed `shorthash`
diff --git a/packages/astro/package.json b/packages/astro/package.json
index c53ecfee2..6ee6b2ee8 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -122,7 +122,6 @@
"rollup": "^2.70.2",
"semver": "^7.3.7",
"shiki": "^0.10.1",
- "shorthash": "^0.0.2",
"sirv": "^2.0.2",
"slash": "^4.0.0",
"sourcemap-codec": "^1.4.8",
diff --git a/packages/astro/src/@types/shorthash.d.ts b/packages/astro/src/@types/shorthash.d.ts
deleted file mode 100644
index 8dc53e6ef..000000000
--- a/packages/astro/src/@types/shorthash.d.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-declare module 'shorthash' {
- function unique(string: string): string;
-
- export default { unique };
-}
diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts
index acb97c5f4..01a8e486b 100644
--- a/packages/astro/src/core/create-vite.ts
+++ b/packages/astro/src/core/create-vite.ts
@@ -24,7 +24,6 @@ const ALWAYS_EXTERNAL = new Set([
'node-fetch',
'prismjs',
'shiki',
- 'shorthash',
'unified',
'whatwg-url',
]);
diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts
index f888a4852..c9df2e62b 100644
--- a/packages/astro/src/runtime/server/index.ts
+++ b/packages/astro/src/runtime/server/index.ts
@@ -1,4 +1,3 @@
-import shorthash from 'shorthash';
import type {
AstroComponentMetadata,
AstroGlobalPartial,
@@ -11,6 +10,7 @@ import type {
import { escapeHTML, HTMLString, markHTMLString } from './escape.js';
import { extractDirectives, generateHydrateScript, serializeProps } from './hydration.js';
import { serializeListValue } from './util.js';
+import { shorthash } from './shorthash.js';
export { markHTMLString, markHTMLString as unescapeHTML } from './escape.js';
export type { Metadata } from './metadata';
@@ -300,7 +300,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
}
// Include componentExport name, componentUrl, and props in hash to dedupe identical islands
- const astroId = shorthash.unique(
+ const astroId = shorthash(
`<!--${metadata.componentExport!.value}:${metadata.componentUrl}-->\n${html}\n${serializeProps(
props
)}`
diff --git a/packages/astro/src/runtime/server/shorthash.ts b/packages/astro/src/runtime/server/shorthash.ts
new file mode 100644
index 000000000..99a691ac4
--- /dev/null
+++ b/packages/astro/src/runtime/server/shorthash.ts
@@ -0,0 +1,67 @@
+/**
+ * shortdash - https://github.com/bibig/node-shorthash
+ *
+ * @license
+ *
+ * (The MIT License)
+ *
+ * Copyright (c) 2013 Bibig <bibig@me.com>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+const dictionary = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY';
+const binary = dictionary.length;
+
+// refer to: http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
+function bitwise(str: string) {
+ let hash = 0;
+ if (str.length === 0) return hash;
+ for (let i = 0; i < str.length; i++) {
+ const ch = str.charCodeAt(i);
+ hash = (hash << 5) - hash + ch;
+ hash = hash & hash; // Convert to 32bit integer
+ }
+ return hash;
+}
+
+export function shorthash(text: string) {
+ let num: number;
+ let result = '';
+
+ let integer = bitwise(text);
+ const sign = integer < 0 ? 'Z' : ''; // It it's negative, start with Z, which isn't in the dictionary
+
+ integer = Math.abs(integer);
+
+ while (integer >= binary) {
+ num = integer % binary;
+ integer = Math.floor(integer / binary);
+ result = dictionary[num] + result;
+ }
+
+ if (integer > 0) {
+ result = dictionary[integer] + result;
+ }
+
+ return sign + result;
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 18f908f2c..92c0483be 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -530,7 +530,6 @@ importers:
sass: ^1.50.1
semver: ^7.3.7
shiki: ^0.10.1
- shorthash: ^0.0.2
sirv: ^2.0.2
slash: ^4.0.0
sourcemap-codec: ^1.4.8
@@ -590,7 +589,6 @@ importers:
rollup: 2.70.2
semver: 7.3.7
shiki: 0.10.1
- shorthash: 0.0.2
sirv: 2.0.2
slash: 4.0.0
sourcemap-codec: 1.4.8
@@ -9271,10 +9269,6 @@ packages:
vscode-textmate: 5.2.0
dev: false
- /shorthash/0.0.2:
- resolution: {integrity: sha1-WbJo7sveWQOLMNogK8+93rLEpOs=}
- dev: false
-
/side-channel/1.0.4:
resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==}
dependencies: