UNPKG

bob-the-bundler

Version:
38 lines (37 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rewriteExports = void 0; function rewriteExports(exports, distDir) { const newExports = { ...exports }; for (const [key, value] of Object.entries(newExports)) { if (!value) continue; let newValue = value; if (typeof newValue === "string") { newValue = newValue.replace(`${distDir}/`, ""); } else if (typeof newValue === "object" && newValue != null) { function transformValue(value) { if (value == null) { return undefined; } if (typeof value === "object") { const newValue = {}; for (const [key, path] of Object.entries(value)) { newValue[key] = path.replace(`${distDir}/`, ""); } return newValue; } return value.replace(`${distDir}/`, ""); } newValue = { require: transformValue(newValue.require), import: transformValue(newValue.import), default: transformValue(newValue.import), }; } newExports[key.replace(`${distDir}/`, "")] = newValue; } return newExports; } exports.rewriteExports = rewriteExports;