Skip to content

build: enable strict null checks for release scripts #16542

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

Merged
Merged
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
1 change: 1 addition & 0 deletions tools/release/base-release-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class BaseReleaseTask {
}

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

/** Verifies that the local branch is up to date with the given publish branch. */
Expand Down
1 change: 1 addition & 0 deletions tools/release/npm/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function npmPublish(packagePath: string, distTag: string): string | null
if (result.status !== 0) {
return result.stderr.toString();
}
return null;
}

/** Log out of npm. */
Expand Down
4 changes: 2 additions & 2 deletions tools/release/prompt/new-version-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function promptForNewVersion(currentVersion: Version): Promise<Vers
type: 'list',
name: 'prereleaseLabel',
message: 'Please select a pre-release label:',
choices: allowedPrereleaseChoices,
choices: allowedPrereleaseChoices!,
when: ({isPrerelease, proposedVersion}) =>
// Only prompt for selecting a pre-release label if the current release is a pre-release,
// or the existing pre-release label should be changed.
Expand All @@ -75,7 +75,7 @@ export async function promptForNewVersion(currentVersion: Version): Promise<Vers
// prompt answers.
const newVersion = answers.proposedVersion === 'new-prerelease-label' ?
currentVersion.clone() :
parseVersionName(answers.proposedVersion);
parseVersionName(answers.proposedVersion)!;

if (answers.prereleaseLabel) {
newVersion.prereleaseLabel = answers.prereleaseLabel;
Expand Down
7 changes: 5 additions & 2 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ class PublishReleaseTask extends BaseReleaseTask {
this.releaseOutputPath = join(projectDir, 'dist/releases');

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

if (!this.currentVersion) {
const parsedVersion = parseVersionName(this.packageJson.version);
if (!parsedVersion) {
console.error(red(`Cannot parse current version in ${italic('package.json')}. Please ` +
`make sure "${this.packageJson.version}" is a valid Semver version.`));
process.exit(1);
return;
}
this.currentVersion = parsedVersion;
}

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

const {releaseNotes, releaseTitle} = extractedReleaseNotes;
Expand Down
2 changes: 1 addition & 1 deletion tools/release/release-output/output-validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function checkReleaseBundle(bundlePath: string): string[] {
export function checkTypeDefinitionFile(filePath: string): string[] {
const baseDir = dirname(filePath);
const fileContent = readFileSync(filePath, 'utf8');
const failures = [];
const failures: string[] = [];

const sourceFile = ts.createSourceFile(filePath, fileContent, ts.ScriptTarget.Latest, true);
const nodeQueue = [...sourceFile.getChildren()];
Expand Down
3 changes: 2 additions & 1 deletion tools/release/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"lib": ["es2016"],
"types": ["node"]
"types": ["node"],
"strictNullChecks": true
}
}
2 changes: 1 addition & 1 deletion tools/release/version-name/create-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function createNewVersion(currentVersion: Version, releaseType: ReleaseTy
const newVersion = currentVersion.clone();

if (releaseType === 'bump-prerelease') {
newVersion.prereleaseNumber++;
newVersion.prereleaseNumber!++;
} else {
// For all other release types, the pre-release label and number should be removed
// because the new version is not another pre-release.
Expand Down
4 changes: 2 additions & 2 deletions tools/release/version-name/publish-branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export function getAllowedPublishBranches(version: Version): string[] {
// branch than "master". This can happen if major changes have been merged into "master"
// and non-major changes are cherry-picked into a separate branch (e.g. 7.x)
return ['master', `${version.major}.x`];
} else if (versionType === 'patch') {
return [`${version.major}.${version.minor}.x`];
}

return [`${version.major}.${version.minor}.x`];
}

/** Determines the type of the specified Semver version. */
Expand Down