Skip to content

Commit

Permalink
Fix Markdoc cloudflare errors (#7351)
Browse files Browse the repository at this point in the history
* fix: move `node:` libs out of utils

* fix: node -> default

* chore: remove kleur from markdoc ex (why was this there??)

* chore: lock

* chore: changeset
  • Loading branch information
bholmesdev authored Jun 10, 2023
1 parent 491c2db commit a30f2f3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-colts-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---

Fix cloudflare build errors for a bad "./config" entrypoint and "node:crypto" getting included unexpectedly.
3 changes: 1 addition & 2 deletions examples/with-markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"dependencies": {
"@astrojs/markdoc": "^0.3.0",
"astro": "^2.5.6",
"kleur": "^4.1.5"
"astro": "^2.6.2"
}
}
6 changes: 3 additions & 3 deletions packages/integrations/markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"exports": {
"./prism": {
"types": "./dist/extensions/prism.d.ts",
"node": "./dist/extensions/prism.js"
"default": "./dist/extensions/prism.js"
},
"./shiki": {
"types": "./dist/extensions/shiki.d.ts",
"node": "./dist/extensions/shiki.js"
"default": "./dist/extensions/shiki.js"
},
"./config": {
"types": "./dist/config.d.ts",
"node": "./dist/config.js"
"default": "./dist/config.js"
},
".": "./dist/index.js",
"./components": "./components/index.ts",
Expand Down
17 changes: 16 additions & 1 deletion packages/integrations/markdoc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Markdoc from '@markdoc/markdoc';
import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro';
import fs from 'node:fs';
import { fileURLToPath, pathToFileURL } from 'node:url';
import crypto from 'node:crypto';
import {
createNameHash,
hasContentFlag,
isValidUrl,
MarkdocError,
Expand Down Expand Up @@ -292,3 +292,18 @@ function shouldOptimizeImage(src: string) {
// Optimize anything that is NOT external or an absolute path to `public/`
return !isValidUrl(src) && !src.startsWith('/');
}

/**
* Create build hash for manual Rollup chunks.
* @see 'packages/astro/src/core/build/plugins/plugin-css.ts'
*/
function createNameHash(baseId: string, hashIds: string[]): string {
const baseName = baseId ? path.parse(baseId).name : 'index';
const hash = crypto.createHash('sha256');
for (const id of hashIds) {
hash.update(id, 'utf-8');
}
const h = hash.digest('hex').slice(0, 8);
const proposedName = baseName + '.' + h;
return proposedName;
}
17 changes: 0 additions & 17 deletions packages/integrations/markdoc/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import matter from 'gray-matter';
import crypto from 'node:crypto';
import path from 'node:path';
import type { ErrorPayload as ViteErrorPayload } from 'vite';

/**
Expand Down Expand Up @@ -112,18 +110,3 @@ export function hasContentFlag(viteId: string, flag: string): boolean {
const flags = new URLSearchParams(viteId.split('?')[1] ?? '');
return flags.has(flag);
}

/**
* Create build hash for manual Rollup chunks.
* @see 'packages/astro/src/core/build/plugins/plugin-css.ts'
*/
export function createNameHash(baseId: string, hashIds: string[]): string {
const baseName = baseId ? path.parse(baseId).name : 'index';
const hash = crypto.createHash('sha256');
for (const id of hashIds) {
hash.update(id, 'utf-8');
}
const h = hash.digest('hex').slice(0, 8);
const proposedName = baseName + '.' + h;
return proposedName;
}
31 changes: 5 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a30f2f3

Please sign in to comment.