{"record":{"id":"68f83bdfc9db94da","repo":"microsoft/typescript-go","slug":"publishing-as-typescript-requires-a-version-befo","errorCode":null,"errorMessage":"Publishing as 'typescript' requires a version before selecting an npm tag.","messagePattern":"Publishing as 'typescript' requires a version before selecting an npm tag\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Herebyfile.mjs","lineNumber":1235,"sourceCode":"        throw new Error(\"Failed to extract version from version.go\");\r\n    }\r\n\r\n    let version = match[1];\r\n    if (options.setPrerelease) {\r\n        version += `-${options.setPrerelease}`;\r\n    }\r\n    else if (match[2]) {\r\n        version += match[2];\r\n    }\r\n\r\n    return version;\r\n});\r\n\r\nfunction getPublishTag() {\r\n    if (publishAsTypescript) {\r\n        const version = getVersion();\r\n        if (!version) {\r\n            throw new Error(\"Publishing as 'typescript' requires a version before selecting an npm tag.\");\r\n        }\r\n        const match = version.match(/-(dev|beta|rc)(?:[.-]|$)/);\r\n        if (match?.[1]) return match[1] === \"dev\" ? \"next\" : match[1];\r\n        if (version === nativePreviewReleaseVersion) return \"latest\";\r\n        throw new Error(`Refusing to publish 'typescript' with the latest tag from non-release version ${version}.`);\r\n    }\r\n    return \"latest\";\r\n}\r\n\r\nconst extensionDir = path.resolve(\"./_extension\");\r\nconst nightlyExtensionDir = path.resolve(\"./_extension-nightly\");\r\nconst builtNpm = path.resolve(\"./built/npm\");\r\nconst builtVsix = path.resolve(\"./built/vsix\");\r\nconst builtPublishedPlatformPackages = path.resolve(\"./built/published-platform-packages\");\r\nconst builtSignTmp = path.resolve(\"./built/sign-tmp\");\r\nconst publishedTypeScriptAliasPackageName = \"@typescript/bundled-typescript\";\r\nconst releasePackageEnv = { COREPACK_ENABLE_STRICT: \"0\" };\r\n\r","sourceCodeStart":1217,"sourceCodeEnd":1253,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/Herebyfile.mjs#L1217-L1253","documentation":"getPublishTag() requires a non-empty version before choosing an npm dist-tag when publishing as 'typescript'. With the current getVersion() (which either returns the hardcoded nativePreviewReleaseVersion or throws on parse failure), an empty version is effectively unreachable; this is a defensive invariant against future refactors.","triggerScenarios":"Only if getVersion() is changed to return an empty string, e.g. nativePreviewReleaseVersion set to \"\" (falsy, bypasses the constant path) while version.go parsing is skipped or altered.","commonSituations":"Refactoring getVersion/getPublishTag; setting nativePreviewReleaseVersion to an empty string instead of undefined.","solutions":["Set nativePreviewReleaseVersion to a full semver string or leave it undefined","Keep getVersion() throwing on parse failure rather than returning empty values"],"exampleFix":"// before\nconst nativePreviewReleaseVersion = \"\";\n\n// after\nconst nativePreviewReleaseVersion = undefined;","handlingStrategy":"validation","validationCode":"const v = getVersion();\nif (typeof v !== \"string\" || v.length === 0) {\n  throw new Error(\"getVersion() must return a non-empty semver string\");\n}","typeGuard":"/** @param {unknown} v @returns {v is string} */\nfunction isNonEmptyVersion(v) { return typeof v === \"string\" && v.length > 0; }","tryCatchPattern":null,"preventionTips":["Set nativePreviewReleaseVersion to a full semver string or leave it undefined, never \"\"","Keep getVersion() throwing on parse failure instead of returning empty"],"tags":["release","invariant","npm","publishing"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}