Skip to content

Commit 4ce2a6a

Browse files
committed
Fix release version parsing
1 parent 0839d8e commit 4ce2a6a

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

scripts/release/npm_manifest.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,32 @@ export const CLI_TARGETS: readonly CliTarget[] = [
102102
},
103103
] as const;
104104

105-
export function parseVersion(root: string = ROOT): string {
106-
const cliSource = Deno.readTextFileSync(join(root, 'src', 'cli', 'cli.ts'));
107-
const match = cliSource.match(/export const VERSION = '([^']+)'/u);
105+
function parseVersionFromSource(
106+
sourceText: string,
107+
): string | null {
108+
const match = sourceText.match(/export const VERSION = ['"]([^'"]+)['"]/u);
108109
if (!match) {
109-
throw new Error('Could not find VERSION in src/cli/cli.ts.');
110+
return null;
110111
}
111112

112113
return match[1];
113114
}
115+
116+
export function parseVersion(root: string = ROOT): string {
117+
for (const relativePath of ['src/version.ts', 'src/cli/cli.ts']) {
118+
const filePath = join(root, relativePath);
119+
try {
120+
const sourceText = Deno.readTextFileSync(filePath);
121+
const version = parseVersionFromSource(sourceText);
122+
if (version) {
123+
return version;
124+
}
125+
} catch (error) {
126+
if (!(error instanceof Deno.errors.NotFound)) {
127+
throw error;
128+
}
129+
}
130+
}
131+
132+
throw new Error('Could not find VERSION in src/version.ts or src/cli/cli.ts.');
133+
}

0 commit comments

Comments
 (0)