Skip to content

Commit 9544284

Browse files
Use generated .d.ts files
1 parent 73ea558 commit 9544284

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/firestore/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": "The Cloud Firestore component of the Firebase JS SDK.",
88
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
99
"scripts": {
10-
"prebuild": "tsc -d --downlevelIteration --declarationDir dist/lib --emitDeclarationOnly && tsc -m es2015 --moduleResolution node scripts/*.ts ",
10+
"prebuild": "tsc -m es2015 --moduleResolution node scripts/*.ts ",
1111
"build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js",
1212
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
1313
"build:console": "node tools/console.build.js",

packages/firestore/scripts/extract-api.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ function extractIdentifiersFromNodeAndChildren(
3232
);
3333
}
3434

35+
function extractTypeDeclaration(fileName: string): string {
36+
const compilerOptions = { declaration: true,
37+
emitDeclarationOnly: true}
38+
let dtsSource : string;
39+
const host = ts.createCompilerHost( compilerOptions);
40+
host.writeFile = (fileName: string, contents: string) => dtsSource = contents;
41+
const program = ts.createProgram([fileName], compilerOptions, host);
42+
program.emit()
43+
return dtsSource!;
44+
}
45+
3546
/**
3647
* Traverses TypeScript type definition files and returns the list of referenced
3748
* identifiers.
@@ -41,11 +52,16 @@ export function extractPublicIdentifiers(filePaths: string[]): Set<string> {
4152

4253
for (const filePath of filePaths) {
4354
const contents = fs.readFileSync(filePath, { encoding: 'UTF-8' });
44-
const sourceFile = ts.createSourceFile(
55+
let sourceFile = ts.createSourceFile(
4556
filePath,
4657
contents,
4758
ts.ScriptTarget.ES2015
4859
);
60+
61+
if (!sourceFile.isDeclarationFile) {
62+
const dtsSource = extractTypeDeclaration(filePath);
63+
sourceFile = ts.createSourceFile(filePath.replace(".ts", ".d.ts"), dtsSource, ts.ScriptTarget.ES2015);
64+
}
4965

5066
const identifiers = new Set<string>();
5167
ts.forEachChild(sourceFile, (childNode: ts.Node) =>

0 commit comments

Comments
 (0)