Skip to content

Commit 5fb6ebe

Browse files
committed
Custom replacer plugin to remove declare module block from global.d.ts
1 parent d175049 commit 5fb6ebe

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

packages/firestore/rollup.config.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ const browserPlugins = [
5959
terser(util.manglePrivatePropertiesOptions)
6060
];
6161

62+
// TODO - update the implementation to match all content in the declare module block.
63+
function declareModuleReplacePlugin() {
64+
// The regex we created earlier
65+
const moduleToReplace =
66+
/declare module '\.\/\S+' \{\s+interface Firestore \{\s+pipeline\(\): PipelineSource<Pipeline>;\s+}\s*}/gm;
67+
68+
// What to replace it with (an empty string to remove it)
69+
const replacement =
70+
'interface Firestore {pipeline(): PipelineSource<Pipeline>;}';
71+
72+
return {
73+
name: 'declare-module-replace',
74+
generateBundle(options, bundle) {
75+
const outputFileName = 'global_index.d.ts';
76+
if (!bundle[outputFileName]) {
77+
console.warn(
78+
`[regexReplacePlugin] File not found in bundle: ${outputFileName}`
79+
);
80+
return;
81+
}
82+
83+
const chunk = bundle[outputFileName];
84+
if (chunk.type === 'chunk') {
85+
chunk.code = chunk.code.replace(moduleToReplace, replacement);
86+
}
87+
}
88+
};
89+
}
90+
6291
const allBuilds = [
6392
// Intermediate Node ESM build without build target reporting
6493
// this is an intermediate build used to generate the actual esm and cjs builds
@@ -222,7 +251,9 @@ const allBuilds = [
222251
plugins: [
223252
dts({
224253
respectExternal: true
225-
})
254+
}),
255+
256+
declareModuleReplacePlugin()
226257
]
227258
}
228259
];

packages/firestore/src/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
// This file supports a special internal build that includes the entire
1919
// Firestore classic and pipeline api surface in one bundle.
2020

21+
import * as pipelines from './api_pipelines';
2122
export * from './api';
22-
import * as pipelines from '../pipelines/pipelines';
2323
export { pipelines };

0 commit comments

Comments
 (0)