Skip to content

build!: specify a minimum TypeScript version using typesVersions #9116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cuddly-apes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/app': minor
'firebase': minor
---

Specify a minimum TypeScript version using the `typesVersions` field. Shows an error message if below.
3 changes: 1 addition & 2 deletions packages/app-check/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
} from '@firebase/component';
import { AppCheckService } from '../src/factory';
import { AppCheck, CustomProvider } from '../src';
import { HeartbeatService } from '@firebase/app/dist/app/src/types';

export const FAKE_SITE_KEY = 'fake-site-key';

Expand Down Expand Up @@ -112,7 +111,7 @@ export function getFakeHeartbeatServiceProvider(
() =>
({
getHeartbeatsHeader: () => Promise.resolve(fakeLogString)
} as HeartbeatService),
} as any),
ComponentType.PRIVATE
)
);
Expand Down
5 changes: 5 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"browser": "dist/esm/index.esm2017.js",
"module": "dist/esm/index.esm2017.js",
"react-native": "dist/index.cjs.js",
"typesVersions": {
">=4.5.0": { "*": ["./dist/app/src/index.d.ts"] },
"<4.5.0": { "*": ["./dist/typescript-not-supported.d.ts"] }
},
"exports": {
".": {
"types": "./dist/app-public.d.ts",
Expand Down Expand Up @@ -49,6 +53,7 @@
"devDependencies": {
"@rollup/plugin-json": "6.1.0",
"rollup": "2.79.2",
"rollup-plugin-copy": "3.5.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.36.0",
"rollup-plugin-dts": "5.3.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/app/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import copy from 'rollup-plugin-copy';
import typescriptPlugin from 'rollup-plugin-typescript2';
import replace from 'rollup-plugin-replace';
import typescript from 'typescript';
Expand Down Expand Up @@ -53,6 +54,14 @@ const esmBuilds = [
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: [
...buildPlugins,
copy({
targets: [
{
src: './typescript-not-supported.d.ts',
dest: 'dist/'
}
]
}),
replace({
...generateBuildTargetReplaceConfig('esm', 2017),
'__RUNTIME_ENV__': ''
Expand Down
20 changes: 20 additions & 0 deletions packages/app/typescript-not-supported.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Empty typings file to log an error message for unsupported TS versions

'Typescript must be version 4.5 or greater.';
24 changes: 24 additions & 0 deletions scripts/docgen/docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const PREFERRED_PARAMS = [

let authApiReportOriginal: string;
let authApiConfigOriginal: string;
let appPkgOriginal: string;

yargs
.command(
Expand Down Expand Up @@ -119,6 +120,14 @@ function cleanup() {
authApiReportOriginal
);
}
// Restore original app/package.json
if (authApiConfigOriginal) {
console.log(`Restoring original app/package.json contents.`);
fs.writeFileSync(
`${projectRoot}/packages/app/package.json`,
appPkgOriginal
);
}
for (const excludedPackage of EXCLUDED_PACKAGES) {
if (fs.existsSync(`${projectRoot}/temp/${excludedPackage}.skip`)) {
console.log(
Expand Down Expand Up @@ -198,11 +207,26 @@ async function generateDocs(
`"mainEntryPointFilePath": "<projectFolder>/dist/esm2017/index.doc.d.ts"`
);

console.log(`Temporarily modifying packages/app/package.json for docgen.`);
// Remove typesVersions restriction just for docgen
appPkgOriginal = fs.readFileSync(
`${projectRoot}/packages/app/package.json`,
'utf8'
);
const appPkgModified = appPkgOriginal.replace(
`./dist/typescript-not-supported.d.ts`,
`./dist/app/src/index.d.ts`
);

try {
fs.writeFileSync(
`${projectRoot}/packages/auth/api-extractor.json`,
authApiConfigModified
);
fs.writeFileSync(
`${projectRoot}/packages/app/package.json`,
appPkgModified
);

if (skipBuild) {
await spawn('yarn', ['api-report'], {
Expand Down
Loading