Skip to content

Commit 108a999

Browse files
authored
fix: isomorphic __dirname in CI (#454)
1 parent 3406956 commit 108a999

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scripts/bump-version.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import * as fs from 'node:fs';
22
import { glob } from 'glob';
33
import * as path from 'node:path';
44
import * as yaml from 'yaml';
5+
import { fileURLToPath } from 'node:url';
56

67
const excludes = ['packages/ide/vscode/package.json'];
78

9+
const _dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url));
10+
811
function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
912
const workspaceYaml = fs.readFileSync(workspaceFile, 'utf8');
1013
const workspace = yaml.parse(workspaceYaml) as { packages?: string[] };
@@ -23,7 +26,7 @@ function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
2326
}
2427

2528
// include root package.json
26-
files.add(path.resolve(__dirname, '../package.json'));
29+
files.add(path.resolve(_dirname, '../package.json'));
2730

2831
const result = Array.from(files).filter((f) => !excludes.some((e) => f.endsWith(e)));
2932
return result;
@@ -39,11 +42,11 @@ function incrementVersion(version: string): string {
3942
}
4043

4144
// find all package.json files in the workspace
42-
const workspaceFile = path.resolve(__dirname, '../pnpm-workspace.yaml');
45+
const workspaceFile = path.resolve(_dirname, '../pnpm-workspace.yaml');
4346
const packageFiles = getWorkspacePackageJsonFiles(workspaceFile);
4447

4548
// get version from root package.json
46-
const rootPackageJson = path.resolve(__dirname, '../package.json');
49+
const rootPackageJson = path.resolve(_dirname, '../package.json');
4750
const rootPkg = JSON.parse(fs.readFileSync(rootPackageJson, 'utf8')) as { version?: string };
4851
if (!rootPkg.version) throw new Error('No "version" key found in package.json');
4952
const rootVersion = rootPkg.version;

0 commit comments

Comments
 (0)