Skip to content

Commit

Permalink
fix: provide readme and changelog url of extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Feb 16, 2024
1 parent 8342ce5 commit a82ec3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/rollup-extension-directory-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default function plugin ({
try {
const resources = await getExtensionResources(manifest, fs, id)

const resourcePaths = resources.map(r => r.path)
const readmePath = resourcePaths.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0]
const changelogPath = resourcePaths.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0]

function generateFileRegistrationInstruction (filePath: string, importPath: string, mimeType?: string) {
return `registerFileUrl('${filePath}', new URL('${importPath}', import.meta.url).toString()${mimeType != null ? `, '${mimeType}'` : ''})`
}
Expand All @@ -63,7 +67,7 @@ export default function plugin ({
import manifest from '${manifestPath}'
import { registerExtension } from 'vscode/extensions'
const { registerFileUrl, whenReady } = registerExtension(manifest)
const { registerFileUrl, whenReady } = registerExtension(manifest, undefined, ${JSON.stringify({ system: true, readmePath, changelogPath })})
${resources.map(resource => {
const lines: string[] = resource.extensionPaths.map(extensionPath =>
generateFileRegistrationInstruction(extensionPath, path.resolve(id, resource.path), resource.mimeType)
Expand Down
6 changes: 5 additions & 1 deletion src/rollup-vsix-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export default function plugin ({

const resources = await getExtensionResources(manifest, <typeof nodeFs><unknown>vsixFS, '/')

const resourcePaths = resources.map(r => r.path)
const readmePath = resourcePaths.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0]
const changelogPath = resourcePaths.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0]

const pathMapping = (await Promise.all(resources.map(async resource => {
const assetPath = getVsixPath(resource.path)
let url: string
Expand All @@ -109,7 +113,7 @@ import { registerExtension } from 'vscode/extensions'
const manifest = ${JSON.stringify(manifest)}
const { registerFileUrl, whenReady } = registerExtension(manifest)
const { registerFileUrl, whenReady } = registerExtension(manifest, undefined, ${JSON.stringify({ system: true, readmePath, changelogPath })})
${pathMapping.map(({ pathInExtension, url, mimeType }) => (`
registerFileUrl('${pathInExtension}', ${url}${mimeType != null ? `, '${mimeType}'` : ''})`)).join('\n')}
Expand Down

0 comments on commit a82ec3d

Please sign in to comment.