Lines 241-281javascript
244 async export(toolId) {
245 const tool = await findInstalledTool(toolId, this.toolsRoot);
247 const files = await readDirectoryFiles(tool.directory);
248 if (files.length > 256) throw new Error("That tool contains more than 256 files.");
249 const expandedBytes = files.reduce((total, file) => total + Buffer.byteLength(file.content, "base64"), 0);
250 if (expandedBytes > maximumExpandedBytes) throw new Error("That tool is larger than the 20 MB archive limit.");
251 const data = Buffer.from(JSON.stringify({ format: "scriptforge-tool", formatVersion: 1, files }));
252 if (data.byteLength > maximumArchiveBytes) throw new Error("The exported .forge file would be larger than 25 MB.");
254 filename: `${tool.manifest.id}.forge`,
258 async delete(toolId) {
259 if (this.reservedIds.has(toolId)) return "bundled";
260 return await deleteInstalledTool(toolId, this.toolsRoot) ? "deleted" : "not-found";
263 if (data.byteLength > maximumArchiveBytes) throw new Error("That .forge file is larger than 25 MB.");
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/cli.jsView on unpkg · L261 264 const parsed = parseArchive(data);
265 const paths = /* @__PURE__ */ new Set();
266 const decoded = parsed.files.map((file) => {
267 if (paths.has(file.path)) throw new Error(`The archive contains duplicate path ${file.path}.`);
268 paths.add(file.path);
269 return { path: file.path, data: decodeBase64(file.content) };
271 const expandedBytes = decoded.reduce((total, file) => total + file.data.byteLength, 0);
272 if (expandedBytes > maximumExpandedBytes) throw new Error("The expanded tool is larger than 20 MB.");
273 const manifestFile = decoded.find((file) => file.path === "tool.json");
274 if (!manifestFile) throw new Error("The archive is missing tool.json.");
275 const manifest = parseManifest(manifestFile.data);
276 validateRequiredFiles(manifest, paths);
277 if (this.reservedIds.has(manifest.id)) throw new Error("A bundled tool already uses that identifier.");
278 const destination = join2(this.toolsRoot, manifest.id);
279 if (await lstat2(destination).catch(() => void 0)) throw new Error("A tool with that name is already installed.");
280 await mkdir2(this.toolsRoot, { recursive: true });
281 const temporary = join2(this.toolsRoot, `.import-${manifest.id}-${randomUUID2()}`);