| 46 | } |
| 47 | |
| 48 | function rewriteDeclaration(source) { |
| 49 | return source |
| 50 | .replace(/^\/\/# sourceMappingURL=.*$\n?/gm, '') |
| 51 | .replace(/(['"])(\.\.?\/[^'"]+)\.js\1/g, '$1$2.cjs$1') |
| 52 | .replace(esmImportTypeRegex, (match, specifiers, quote, packageName) => { |
| 53 | if (!esmOnlyPackages.has(packageName)) { |
| 54 | return match |
| 55 | } |
| 56 | |
| 57 | return `import type {${specifiers}} from ${quote}${packageName}${quote} with { "resolution-mode": "import" };` |
| 58 | }) |
| 59 | .replace(esmValueImportRegex, (match, specifiers, quote, packageName) => { |
| 60 | if (!esmOnlyPackages.has(packageName)) { |
| 61 | return match |
| 62 | } |
| 63 | |
| 64 | return `import type {${specifiers}} from ${quote}${packageName}${quote} with { "resolution-mode": "import" };` |
| 65 | }) |
| 66 | .replace(importTypeExpressionRegex, (match, quote, packageName) => { |
| 67 | if (packageName !== 'lit-html') { |
| 68 | return match |
| 69 | } |
| 70 | |
| 71 | return `import(${quote}${packageName}${quote}, { with: { "resolution-mode": "import" } })` |
| 72 | }) |
| 73 | } |