Skip to content

Commit c261503

Browse files
committed
'bump'
1 parent e624a7d commit c261503

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dequanto",
3-
"version": "0.1.30",
3+
"version": "0.1.31",
44
"author": {
55
"name": "Alex Kit",
66
"email": "alex.kit@atmajs.com"

src/utils/$dependency.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,18 @@ export namespace $dependency {
1515
//#endif
1616
}
1717

18+
export function dirname () {
19+
if (typeof __dirname === 'undefined') {
20+
return __dirname;
21+
}
22+
//#if (CJS)
23+
throw new Error('__dirname is not defined in CommonJS environment');
24+
//#endif
25+
26+
//#if (ESM)
27+
// @ts-ignore: Conditional import
28+
return import.meta.dirname;
29+
//#endif
30+
}
1831
}
1932

src/utils/$path.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { class_Uri } from 'atma-utils';
22
import { $config } from './$config';
33
import { env } from 'atma-io';
4+
import { $dependency } from './$dependency';
45

56
export namespace $path {
67
let root: string = null;
@@ -80,11 +81,12 @@ export namespace $path {
8081
return class_Uri.combine('file://' + cwd, base);
8182
}
8283

83-
let uri = new class_Uri('file://' + __dirname + '/');
84+
let dirname = $dependency.dirname();
85+
let uri = new class_Uri('file://' + dirname + '/');
8486
while (true) {
8587
let dir = getDirName(uri.path);
8688
if (!dir || dir === '/') {
87-
throw new Error(`Root path not resolved: ${__dirname}`);
89+
throw new Error(`Root path not resolved: ${dirname}`);
8890
}
8991
if (dir === 'lib' || dir === 'src') {
9092
uri = uri.cdUp();

0 commit comments

Comments
 (0)