Skip to content

Commit 74794d4

Browse files
devversionjelbourn
authored andcommitted
build: enable strict null checks for release scripts (#16542)
1 parent 6aa418d commit 74794d4

File tree

8 files changed

+15
-9
lines changed

8 files changed

+15
-9
lines changed

tools/release/base-release-task.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class BaseReleaseTask {
4646
}
4747

4848
console.log(green(` ✓ Switched to the "${italic(defaultPublishBranch)}" branch.`));
49+
return defaultPublishBranch;
4950
}
5051

5152
/** Verifies that the local branch is up to date with the given publish branch. */

tools/release/npm/npm-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function npmPublish(packagePath: string, distTag: string): string | null
4141
if (result.status !== 0) {
4242
return result.stderr.toString();
4343
}
44+
return null;
4445
}
4546

4647
/** Log out of npm. */

tools/release/prompt/new-version-prompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function promptForNewVersion(currentVersion: Version): Promise<Vers
6363
type: 'list',
6464
name: 'prereleaseLabel',
6565
message: 'Please select a pre-release label:',
66-
choices: allowedPrereleaseChoices,
66+
choices: allowedPrereleaseChoices!,
6767
when: ({isPrerelease, proposedVersion}) =>
6868
// Only prompt for selecting a pre-release label if the current release is a pre-release,
6969
// or the existing pre-release label should be changed.
@@ -75,7 +75,7 @@ export async function promptForNewVersion(currentVersion: Version): Promise<Vers
7575
// prompt answers.
7676
const newVersion = answers.proposedVersion === 'new-prerelease-label' ?
7777
currentVersion.clone() :
78-
parseVersionName(answers.proposedVersion);
78+
parseVersionName(answers.proposedVersion)!;
7979

8080
if (answers.prereleaseLabel) {
8181
newVersion.prereleaseLabel = answers.prereleaseLabel;

tools/release/publish-release.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ class PublishReleaseTask extends BaseReleaseTask {
5353
this.releaseOutputPath = join(projectDir, 'dist/releases');
5454

5555
this.packageJson = JSON.parse(readFileSync(this.packageJsonPath, 'utf-8'));
56-
this.currentVersion = parseVersionName(this.packageJson.version);
5756

58-
if (!this.currentVersion) {
57+
const parsedVersion = parseVersionName(this.packageJson.version);
58+
if (!parsedVersion) {
5959
console.error(red(`Cannot parse current version in ${italic('package.json')}. Please ` +
6060
`make sure "${this.packageJson.version}" is a valid Semver version.`));
6161
process.exit(1);
62+
return;
6263
}
64+
this.currentVersion = parsedVersion;
6365
}
6466

6567
async run() {
@@ -108,6 +110,7 @@ class PublishReleaseTask extends BaseReleaseTask {
108110
if (!extractedReleaseNotes) {
109111
console.error(red(` ✘ Could not find release notes in the changelog.`));
110112
process.exit(1);
113+
return;
111114
}
112115

113116
const {releaseNotes, releaseTitle} = extractedReleaseNotes;

tools/release/release-output/output-validations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function checkReleaseBundle(bundlePath: string): string[] {
3737
export function checkTypeDefinitionFile(filePath: string): string[] {
3838
const baseDir = dirname(filePath);
3939
const fileContent = readFileSync(filePath, 'utf8');
40-
const failures = [];
40+
const failures: string[] = [];
4141

4242
const sourceFile = ts.createSourceFile(filePath, fileContent, ts.ScriptTarget.Latest, true);
4343
const nodeQueue = [...sourceFile.getChildren()];

tools/release/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"lib": ["es2016"],
4-
"types": ["node"]
4+
"types": ["node"],
5+
"strictNullChecks": true
56
}
67
}

tools/release/version-name/create-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function createNewVersion(currentVersion: Version, releaseType: ReleaseTy
1111
const newVersion = currentVersion.clone();
1212

1313
if (releaseType === 'bump-prerelease') {
14-
newVersion.prereleaseNumber++;
14+
newVersion.prereleaseNumber!++;
1515
} else {
1616
// For all other release types, the pre-release label and number should be removed
1717
// because the new version is not another pre-release.

tools/release/version-name/publish-branches.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export function getAllowedPublishBranches(version: Version): string[] {
1313
// branch than "master". This can happen if major changes have been merged into "master"
1414
// and non-major changes are cherry-picked into a separate branch (e.g. 7.x)
1515
return ['master', `${version.major}.x`];
16-
} else if (versionType === 'patch') {
17-
return [`${version.major}.${version.minor}.x`];
1816
}
17+
18+
return [`${version.major}.${version.minor}.x`];
1919
}
2020

2121
/** Determines the type of the specified Semver version. */

0 commit comments

Comments
 (0)