Skip to content

Commit c8c0168

Browse files
committed
Fix import resolution in ast-utils
Signed-off-by: Jonathan Stevens <jonathan.stevens@eventiva.co.uk>
1 parent 3162606 commit c8c0168

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/schema/src/utils/ast-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { isFromStdlib } from '@zenstackhq/sdk';
1919
import { AstNode, getDocument, LangiumDocuments, Mutable } from 'langium';
2020
import { URI, Utils } from 'vscode-uri';
2121
import { findNodeModulesFile } from './pkg-utils';
22+
import {isAbsolute} from 'node:path'
2223

2324
export function extractDataModelsWithAllowRules(model: Model): DataModel[] {
2425
return model.declarations.filter(
@@ -96,18 +97,17 @@ export function getDataModelFieldReference(expr: Expression): DataModelField | u
9697

9798
export function resolveImportUri(imp: ModelImport): URI | undefined {
9899
if (!imp.path) return undefined; // This will return true if imp.path is undefined, null, or an empty string ("").
99-
100+
100101
if (!imp.path.endsWith('.zmodel')) {
101102
imp.path += '.zmodel';
102103
}
103104

104105
if (
105106
!imp.path.startsWith('.') // Respect relative paths
106-
&& !imp.path.startsWith('/') // Respect absolute paths (Unix)
107-
&& !/^[a-zA-Z]:\\/.test(imp.path) // Respect absolute paths (Windows)
107+
&& !isAbsolute(imp.path) // Respect Absolute paths
108108
) {
109109
imp.path = findNodeModulesFile(imp.path) ?? imp.path;
110-
}
110+
}
111111

112112
const dirUri = Utils.dirname(getDocument(imp).uri);
113113
return Utils.resolvePath(dirUri, imp.path);

0 commit comments

Comments
 (0)