MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / parsePluginNpmPackage

Function parsePluginNpmPackage

shared-dom/src/plugin.ts:40–67  ·  view source on GitHub ↗
(blob: Blob)

Source from the content-addressed store, hash-verified

38}
39
40export async function parsePluginNpmPackage(blob: Blob) {
41 const reader = await getTarReader(blob)
42 const packageJsonText =
43 reader.getTextFile('package/package.json') ??
44 throwExp('`package/package.json` not found')
45 const packageJson = packageJsonValidator.parse(JSON.parse(packageJsonText))
46 let { main } = packageJson
47 if (main == null) {
48 main = 'package/index.js'
49 } else if (main.startsWith('./')) {
50 main = 'package' + main.substring(1)
51 } else if (main.startsWith('/')) {
52 main = 'package' + main
53 } else {
54 main = 'package/' + main
55 }
56 const script =
57 reader.getFileBlob(main, 'text/javascript') ??
58 throwExp(
59 `${main} not found. Is the 'main' in your 'package.json' correct? (We add the 'package' top level directory.)`,
60 )
61 return {
62 script,
63 name: packageJson.name,
64 version: packageJson.version,
65 dependencies: packageJson.pentivePluginDependencies,
66 }
67}

Callers 1

importPluginFunction · 0.90

Calls 5

throwExpFunction · 0.90
getTarReaderFunction · 0.85
getTextFileMethod · 0.80
getFileBlobMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected