MCPcopy Create free account
hub / github.com/TanStack/query / rewriteDeclaration

Function rewriteDeclaration

packages/lit-query/scripts/write-cjs-package.mjs:48–73  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

46}
47
48function 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}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected