From cc0ca097890f75f1f3e2806a5d16268994101916 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 31 Oct 2024 12:46:50 -0700 Subject: [PATCH] fix(type): Patch rollup-plugin-dts bug that broke prebundled zod https://github.com/Swatinem/rollup-plugin-dts/pull/323 Fixes #8277. Signed-off-by: Anders Kaseorg --- package.json | 3 ++- patches/rollup-plugin-dts.patch | 27 +++++++++++++++++++++++++++ pnpm-lock.yaml | 7 +++++-- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 patches/rollup-plugin-dts.patch diff --git a/package.json b/package.json index abbbf840ce8..8317670a12f 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,8 @@ "packageManager": "pnpm@9.12.3", "pnpm": { "patchedDependencies": { - "graceful-fs@4.2.10": "patches/graceful-fs@4.2.10.patch" + "graceful-fs@4.2.10": "patches/graceful-fs@4.2.10.patch", + "rollup-plugin-dts": "patches/rollup-plugin-dts.patch" } }, "lint-staged": { diff --git a/patches/rollup-plugin-dts.patch b/patches/rollup-plugin-dts.patch new file mode 100644 index 00000000000..24a76fdb09e --- /dev/null +++ b/patches/rollup-plugin-dts.patch @@ -0,0 +1,27 @@ +diff --git a/dist/rollup-plugin-dts.mjs b/dist/rollup-plugin-dts.mjs +index 4a9412285c48c37d03340a086c771f8e61fd82ac..c1b7d3b95979811b71b49a53aba4ca07901e2a9d 100644 +--- a/dist/rollup-plugin-dts.mjs ++++ b/dist/rollup-plugin-dts.mjs +@@ -351,6 +351,10 @@ class NamespaceFixer { + code += `type ${ns.name}_${exportedName}${typeParams.in} = ${localName}${typeParams.out};\n`; + code += `declare const ${ns.name}_${exportedName}: typeof ${localName};\n`; + } ++ else if (type === "namespace") { ++ // namespaces may contain both types and values ++ code += `import ${ns.name}_${exportedName} = ${localName};\n`; ++ } + else { + // functions and vars are just values + code += `declare const ${ns.name}_${exportedName}: typeof ${localName};\n`; +@@ -1404,6 +1408,11 @@ class Transformer { + } + convertImportDeclaration(node) { + if (ts.isImportEqualsDeclaration(node)) { ++ if (ts.isEntityName(node.moduleReference)) { ++ const scope = this.createDeclaration(node, node.name); ++ scope.pushReference(scope.convertEntityName(node.moduleReference)); ++ return; ++ } + // assume its like `import default` + if (!ts.isExternalModuleReference(node.moduleReference)) { + throw new UnsupportedSyntaxError(node, "ImportEquals should have a literal source."); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a24c990cd8d..3f46f834c43 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ patchedDependencies: graceful-fs@4.2.10: hash: ivtm2a2cfr5pomcfbedhmr5v2q path: patches/graceful-fs@4.2.10.patch + rollup-plugin-dts: + hash: ae3wyaqpjyjp5gck7zzwzn3cfq + path: patches/rollup-plugin-dts.patch importers: @@ -17075,7 +17078,7 @@ snapshots: dependencies: '@vercel/ncc': 0.38.1 rollup: 4.24.0 - rollup-plugin-dts: 6.1.0(rollup@4.24.0)(typescript@5.6.3) + rollup-plugin-dts: 6.1.0(patch_hash=ae3wyaqpjyjp5gck7zzwzn3cfq)(rollup@4.24.0)(typescript@5.6.3) transitivePeerDependencies: - typescript @@ -17933,7 +17936,7 @@ snapshots: robust-predicates@3.0.2: {} - rollup-plugin-dts@6.1.0(rollup@4.24.0)(typescript@5.6.3): + rollup-plugin-dts@6.1.0(patch_hash=ae3wyaqpjyjp5gck7zzwzn3cfq)(rollup@4.24.0)(typescript@5.6.3): dependencies: magic-string: 0.30.12 rollup: 4.24.0