From 57394200a47754ae77c8ec57e95fefb3d0ff5cf6 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 24 Mar 2022 16:04:20 -0400 Subject: [PATCH 1/6] feat: add `` to @astrojs/prism/components --- packages/astro-prism/components/Prism.astro | 49 +++++++++++++++++++++ packages/astro-prism/components/index.js | 1 + packages/astro-prism/package.json | 7 ++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 packages/astro-prism/components/Prism.astro create mode 100644 packages/astro-prism/components/index.js diff --git a/packages/astro-prism/components/Prism.astro b/packages/astro-prism/components/Prism.astro new file mode 100644 index 000000000000..30955f706e6e --- /dev/null +++ b/packages/astro-prism/components/Prism.astro @@ -0,0 +1,49 @@ +--- +import Prism from 'prismjs'; +import { addAstro } from '../'; +import loadLanguages from 'prismjs/components/index.js'; + +export interface Props { + class?: string; + lang?: string; + code: string; +} + +const { class: className, lang, code } = Astro.props as Props; + +let classLanguage = `language-${lang}`; + +const languageMap = new Map([['ts', 'typescript']]); + +if (lang == null) { + console.warn('Prism.astro: No language provided.'); +} + +const ensureLoaded = (lang) => { + if (lang && !Prism.languages[lang]) { + loadLanguages([lang]); + } +}; + +if (languageMap.has(lang)) { + ensureLoaded(languageMap.get(lang)); +} else if (lang === 'astro') { + ensureLoaded('typescript'); + addAstro(Prism); +} else { + ensureLoaded('markup-templating'); // Prism expects this to exist for a number of other langs + ensureLoaded(lang); +} + +if (lang && !Prism.languages[lang]) { + console.warn(`Unable to load the language: ${lang}`); +} + +const grammar = Prism.languages[lang]; +let html = code; +if (grammar) { + html = Prism.highlight(code, grammar, lang); +} +--- + +
diff --git a/packages/astro-prism/components/index.js b/packages/astro-prism/components/index.js new file mode 100644 index 000000000000..41974a9d746b --- /dev/null +++ b/packages/astro-prism/components/index.js @@ -0,0 +1 @@ +export { default as Prism } from './Prism.astro'; \ No newline at end of file diff --git a/packages/astro-prism/package.json b/packages/astro-prism/package.json index ff58a88ba980..b99828abe662 100644 --- a/packages/astro-prism/package.json +++ b/packages/astro-prism/package.json @@ -13,8 +13,13 @@ "homepage": "https://astro.build", "main": "index.mjs", "scripts": {}, + "files": [ + "components" + ], "exports": { - ".": "./index.mjs" + ".": "./index.mjs", + "./components": "./components/index.js", + "./components/*": "./components/*" }, "types": "./index.d.ts", "keywords": [], From e63a0e686b5b5bfc143d3e15ccc82c96dc5b13c6 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 24 Mar 2022 16:09:38 -0400 Subject: [PATCH 2/6] feat: remove `` from astro/components --- packages/astro/components/Prism.astro | 49 --------------------------- packages/astro/components/index.js | 1 - 2 files changed, 50 deletions(-) delete mode 100644 packages/astro/components/Prism.astro diff --git a/packages/astro/components/Prism.astro b/packages/astro/components/Prism.astro deleted file mode 100644 index 5f92b1f667e4..000000000000 --- a/packages/astro/components/Prism.astro +++ /dev/null @@ -1,49 +0,0 @@ ---- -import Prism from 'prismjs'; -import { addAstro } from '@astrojs/prism'; -import loadLanguages from 'prismjs/components/index.js'; - -export interface Props { - class?: string; - lang?: string; - code: string; -} - -const { class: className, lang, code } = Astro.props as Props; - -let classLanguage = `language-${lang}`; - -const languageMap = new Map([['ts', 'typescript']]); - -if (lang == null) { - console.warn('Prism.astro: No language provided.'); -} - -const ensureLoaded = (lang) => { - if (lang && !Prism.languages[lang]) { - loadLanguages([lang]); - } -}; - -if (languageMap.has(lang)) { - ensureLoaded(languageMap.get(lang)); -} else if (lang === 'astro') { - ensureLoaded('typescript'); - addAstro(Prism); -} else { - ensureLoaded('markup-templating'); // Prism expects this to exist for a number of other langs - ensureLoaded(lang); -} - -if (lang && !Prism.languages[lang]) { - console.warn(`Unable to load the language: ${lang}`); -} - -const grammar = Prism.languages[lang]; -let html = code; -if (grammar) { - html = Prism.highlight(code, grammar, lang); -} ---- - -
diff --git a/packages/astro/components/index.js b/packages/astro/components/index.js index 8b19c7d1f2c3..b16d8983ac48 100644 --- a/packages/astro/components/index.js +++ b/packages/astro/components/index.js @@ -1,4 +1,3 @@ export { default as Code } from './Code.astro'; export { default as Debug } from './Debug.astro'; export { default as Markdown } from './Markdown.astro'; -export { default as Prism } from './Prism.astro'; From d3a080f4ffdc235025650c5ade31839d3b30db21 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 24 Mar 2022 16:10:38 -0400 Subject: [PATCH 3/6] refactor: point to index.mjs in import --- packages/astro-prism/components/Prism.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro-prism/components/Prism.astro b/packages/astro-prism/components/Prism.astro index 30955f706e6e..66794e2d574e 100644 --- a/packages/astro-prism/components/Prism.astro +++ b/packages/astro-prism/components/Prism.astro @@ -1,6 +1,6 @@ --- import Prism from 'prismjs'; -import { addAstro } from '../'; +import { addAstro } from '../index.mjs'; import loadLanguages from 'prismjs/components/index.js'; export interface Props { From 3c00415bffbe1642c23492a0fc591f39750d1c6e Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 24 Mar 2022 16:17:02 -0400 Subject: [PATCH 4/6] refactor: change exp to @astrojs/prism/component --- packages/astro-prism/{components => component}/Prism.astro | 0 packages/astro-prism/component/index.js | 3 +++ packages/astro-prism/components/index.js | 1 - packages/astro-prism/package.json | 3 +-- 4 files changed, 4 insertions(+), 3 deletions(-) rename packages/astro-prism/{components => component}/Prism.astro (100%) create mode 100644 packages/astro-prism/component/index.js delete mode 100644 packages/astro-prism/components/index.js diff --git a/packages/astro-prism/components/Prism.astro b/packages/astro-prism/component/Prism.astro similarity index 100% rename from packages/astro-prism/components/Prism.astro rename to packages/astro-prism/component/Prism.astro diff --git a/packages/astro-prism/component/index.js b/packages/astro-prism/component/index.js new file mode 100644 index 000000000000..590c9aad471c --- /dev/null +++ b/packages/astro-prism/component/index.js @@ -0,0 +1,3 @@ +import Prism from './Prism.astro'; + +export default Prism; \ No newline at end of file diff --git a/packages/astro-prism/components/index.js b/packages/astro-prism/components/index.js deleted file mode 100644 index 41974a9d746b..000000000000 --- a/packages/astro-prism/components/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as Prism } from './Prism.astro'; \ No newline at end of file diff --git a/packages/astro-prism/package.json b/packages/astro-prism/package.json index b99828abe662..3fa826f0dc64 100644 --- a/packages/astro-prism/package.json +++ b/packages/astro-prism/package.json @@ -18,8 +18,7 @@ ], "exports": { ".": "./index.mjs", - "./components": "./components/index.js", - "./components/*": "./components/*" + "./component": "./component/index.js" }, "types": "./index.d.ts", "keywords": [], From 0e2503f018eef82e66d5003d69181538fee1f0d2 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 24 Mar 2022 16:19:36 -0400 Subject: [PATCH 5/6] refactor: remove unecessary index.js --- packages/astro-prism/component/index.js | 3 --- packages/astro-prism/package.json | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 packages/astro-prism/component/index.js diff --git a/packages/astro-prism/component/index.js b/packages/astro-prism/component/index.js deleted file mode 100644 index 590c9aad471c..000000000000 --- a/packages/astro-prism/component/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Prism from './Prism.astro'; - -export default Prism; \ No newline at end of file diff --git a/packages/astro-prism/package.json b/packages/astro-prism/package.json index 3fa826f0dc64..3a37d82ec626 100644 --- a/packages/astro-prism/package.json +++ b/packages/astro-prism/package.json @@ -14,11 +14,11 @@ "main": "index.mjs", "scripts": {}, "files": [ - "components" + "component" ], "exports": { ".": "./index.mjs", - "./component": "./component/index.js" + "./component": "./component/Prism.astro" }, "types": "./index.d.ts", "keywords": [], From 9fa7127df35de7cb6bdf72c08b7cb8d218b4c87e Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 24 Mar 2022 16:52:26 -0400 Subject: [PATCH 6/6] chore: changeset --- .changeset/perfect-ravens-count.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/perfect-ravens-count.md diff --git a/.changeset/perfect-ravens-count.md b/.changeset/perfect-ravens-count.md new file mode 100644 index 000000000000..dfadbd49ab39 --- /dev/null +++ b/.changeset/perfect-ravens-count.md @@ -0,0 +1,6 @@ +--- +'astro': patch +'@astrojs/prism': patch +--- + +Move the built-in `Prism` component from `astro/components` to `@astrojs/prism/component`.