Skip to content

Commit 8a3987b

Browse files
committed
Keep rootDir as commonjs.
1 parent 2d77496 commit 8a3987b

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

build/commands/lib/config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,13 @@ import os from 'os'
99
import path from 'path'
1010
import fs from 'fs'
1111
import assert from 'assert'
12+
import rootDir from './rootDir.cjs'
1213
import EnvConfig from './envConfig.js'
1314
import Log from './logging.js'
1415
import util from './util.js'
1516

16-
let dirName = import.meta.dirname
17-
// Use fs.realpathSync to normalize the path(__dirname could be c:\.. or C:\..).
18-
if (process.platform === 'win32') {
19-
dirName = fs.realpathSync.native(dirName)
20-
}
21-
const rootDir = path.resolve(dirName, '..', '..', '..', '..', '..')
2217
const braveCoreDir = path.join(rootDir, 'src', 'brave')
2318

24-
if (rootDir.includes(' ')) {
25-
Log.error(`Root directory contains spaces, this is not supported: ${rootDir}`)
26-
process.exit(1)
27-
}
28-
2919
const envConfig = new EnvConfig(braveCoreDir)
3020

3121
const getEnvConfig = (keyPath, defaultValue = undefined) => {

build/commands/lib/rootDir.cjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2026 The Brave Authors. All rights reserved.
2+
// This Source Code Form is subject to the terms of the Mozilla Public
3+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
// You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
// This is a CommonJS module so we can use __dirname to resolve the root
7+
// directory. The rest of the codebase is ESM, which would require
8+
// import.meta.dirname for this, but that isn't supported by Jest.
9+
10+
const fs = require('fs')
11+
const path = require('path')
12+
13+
let dirName = __dirname
14+
// Use fs.realpathSync to normalize the path(__dirname could be c:\.. or C:\..).
15+
if (process.platform === 'win32') {
16+
dirName = fs.realpathSync.native(dirName)
17+
}
18+
19+
const rootDir = path.resolve(dirName, '..', '..', '..', '..', '..')
20+
if (rootDir.includes(' ')) {
21+
console.error(
22+
`Root directory contains spaces, this is not supported: ${rootDir}`,
23+
)
24+
process.exit(1)
25+
}
26+
27+
module.exports = rootDir

0 commit comments

Comments
 (0)