Skip to content

Commit

Permalink
fix: configureProjectRoot error in browser environment (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell authored Dec 27, 2023
1 parent 22d2663 commit 12ded0b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": true
"source.fixAll.eslint": "explicit",
"source.organizeImports": "explicit"
},
"jest.jestCommandLine": "npm run test --",
"jest.autoRun": {},
Expand Down
25 changes: 13 additions & 12 deletions docs/code/classes/types_config.UpdatableConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Updatable AlgoKit config

#### Defined in

[src/types/config.ts:82](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L82)
[src/types/config.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L77)

## Properties

Expand All @@ -58,7 +58,7 @@ Updatable AlgoKit config

#### Defined in

[src/types/config.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L29)
[src/types/config.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L24)

## Accessors

Expand All @@ -76,7 +76,7 @@ Readonly.debug

#### Defined in

[src/types/config.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L35)
[src/types/config.ts:30](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L30)

___

Expand All @@ -94,7 +94,7 @@ Readonly.logger

#### Defined in

[src/types/config.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L31)
[src/types/config.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L26)

___

Expand All @@ -112,7 +112,7 @@ Readonly.maxSearchDepth

#### Defined in

[src/types/config.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L51)
[src/types/config.ts:46](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L46)

___

Expand All @@ -130,7 +130,7 @@ Readonly.projectRoot

#### Defined in

[src/types/config.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L39)
[src/types/config.ts:34](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L34)

___

Expand All @@ -148,7 +148,7 @@ Readonly.traceAll

#### Defined in

[src/types/config.ts:43](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L43)
[src/types/config.ts:38](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L38)

___

Expand All @@ -166,7 +166,7 @@ Readonly.traceBufferSizeMb

#### Defined in

[src/types/config.ts:47](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L47)
[src/types/config.ts:42](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L42)

## Methods

Expand All @@ -188,7 +188,7 @@ Update the AlgoKit configuration with your own configuration settings

#### Defined in

[src/types/config.ts:112](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L112)
[src/types/config.ts:118](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L118)

___

Expand All @@ -197,14 +197,15 @@ ___
**configureProjectRoot**(): `void`

Configures the project root by searching for a specific file within a depth limit.
This is only supported in a Node environment.

#### Returns

`void`

#### Defined in

[src/types/config.ts:97](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L97)
[src/types/config.ts:93](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L93)

___

Expand All @@ -228,7 +229,7 @@ The requested logger

#### Defined in

[src/types/config.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L60)
[src/types/config.ts:55](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L55)

___

Expand All @@ -250,4 +251,4 @@ Temporarily run with debug set to true.

#### Defined in

[src/types/config.ts:72](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L72)
[src/types/config.ts:67](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L67)
12 changes: 6 additions & 6 deletions docs/code/interfaces/types_config.Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Whether or not debug mode is enabled

#### Defined in

[src/types/config.ts:16](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L16)
[src/types/config.ts:11](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L11)

___

Expand All @@ -39,7 +39,7 @@ Logger

#### Defined in

[src/types/config.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L14)
[src/types/config.ts:9](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L9)

___

Expand All @@ -51,7 +51,7 @@ The maximum depth to search for a specific file

#### Defined in

[src/types/config.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L24)
[src/types/config.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L19)

___

Expand All @@ -63,7 +63,7 @@ The path to the project root directory

#### Defined in

[src/types/config.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L18)
[src/types/config.ts:13](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L13)

___

Expand All @@ -75,7 +75,7 @@ Indicates whether to trace all operations

#### Defined in

[src/types/config.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L20)
[src/types/config.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L15)

___

Expand All @@ -87,4 +87,4 @@ The size of the trace buffer in megabytes

#### Defined in

[src/types/config.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L22)
[src/types/config.ts:17](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L17)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@
"@semantic-release/github"
]
}
}
}
16 changes: 11 additions & 5 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { Logger, consoleLogger, nullLogger } from './logging'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unreachable code error
// eslint-disable-next-line no-restricted-syntax
const _dirname = typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url))

/** The AlgoKit configuration type */
export interface Config {
/** Logger */
Expand Down Expand Up @@ -93,8 +88,19 @@ export class UpdatableConfig implements Readonly<Config> {

/**
* Configures the project root by searching for a specific file within a depth limit.
* This is only supported in a Node environment.
*/
private configureProjectRoot() {
// fileURLToPath and dirname is only available in Node, hence the check
const _dirname =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unreachable code error
// eslint-disable-next-line no-restricted-syntax
typeof __dirname !== 'undefined' ? __dirname : fileURLToPath && dirname ? dirname(fileURLToPath(import.meta.url)) : undefined
if (!_dirname) {
return
}

let currentPath = resolve(_dirname)
for (let i = 0; i < this.config.maxSearchDepth; i++) {
if (existsSync(`${currentPath}/.algokit.toml`)) {
Expand Down

0 comments on commit 12ded0b

Please sign in to comment.