🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@isl-lang/import-resolver

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@isl-lang/import-resolver

ISL import resolution - resolves local module imports, detects cycles, and bundles multi-file specs

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
2
-75%
Maintainers
1
Weekly downloads
 
Created
Source

@isl-lang/import-resolver

ISL Import Resolution and Multi-File Bundling

Overview

The Import Resolver package provides functionality for resolving local module imports in ISL specifications, detecting cycles, and bundling multiple ISL files into a single AST.

Features

  • Local Module Imports: Resolve ./foo.isl and ../bar.isl style relative imports
  • Cycle Detection: Detect and report circular dependencies with clear error messages
  • Fragment Merging: Merge types, entities, behaviors, and other fragments from multiple files
  • Conflict Detection: Error on duplicate definitions (entities, types, behaviors with same name)
  • Stable Bundling: Produce deterministic bundled AST with canonical ordering
  • MVP Mode Toggle: Explicitly gate import resolution for single-file mode

Installation

npm install @isl-lang/import-resolver
# or
pnpm add @isl-lang/import-resolver

Quick Start

Multi-File Mode (Imports Enabled)

import { resolveAndBundle } from '@isl-lang/import-resolver';

const result = await resolveAndBundle('./main.isl', {
  basePath: './specs',
  enableImports: true,
});

if (result.success) {
  console.log('Bundled AST:', result.bundle);
} else {
  console.error('Errors:', result.errors);
}

Single-File Mode (MVP Mode)

import { parseSingleFile } from '@isl-lang/import-resolver';

const source = `
domain MyApp {
  version: "1.0.0"
  entity User { id: UUID }
}
`;

const result = parseSingleFile(source, 'spec.isl');

if (result.success) {
  console.log('Parsed AST:', result.bundle);
} else {
  // If the file has imports, this will fail with a clear error
  // explaining that single-file mode doesn't support imports
  console.error('Errors:', result.errors);
}

Import Rules

Supported Import Paths

Only relative paths are supported:

imports {
  User, Email from "./types.isl"       # Same directory
  Payment from "../billing/payment.isl" # Parent directory
  Config from "./config"                # Extension optional (.isl added)
}

Unsupported Import Paths

The following import paths will result in errors:

imports {
  User from "types.isl"           # ❌ Not relative (missing ./)
  User from "/absolute/path.isl"  # ❌ Absolute paths not allowed
  User from "@stdlib/auth"        # ❌ Package imports not yet supported
}

Import Items

Import specific symbols from a module:

imports {
  User from "./types.isl"                   # Single import
  User, Email, UserId from "./types.isl"    # Multiple imports
  User as AppUser from "./types.isl"        # Aliased import
}

Merge Semantics

What Gets Merged

When bundling multiple files, the following are merged:

Fragment TypeMerge Behavior
TypesDeduplicated by name (conflict if same name)
EntitiesDeduplicated by name (conflict if same name)
BehaviorsDeduplicated by name (conflict if same name)
InvariantsDeduplicated by name (conflict if same name)
PoliciesDeduplicated by name (conflict if same name)
ViewsDeduplicated by name (conflict if same name)
ScenariosAll merged (duplicates allowed)
ChaosAll merged (duplicates allowed)

Conflict Detection

By default, duplicate definitions result in errors:

[DUPLICATE_ENTITY] Duplicate entity "User" found:
  First defined in: types.isl (line 5)
  Also defined in: main.isl (line 10)

Each entity must have a unique name across all modules.

Shadowing Mode

If you need to override definitions, enable shadowing:

const result = await resolveAndBundle('./main.isl', {
  enableImports: true,
  allowShadowing: true,  // Last-write-wins
});

In shadowing mode:

  • Later definitions override earlier ones (in topological order)
  • Warnings are emitted for shadowed imports

Canonical Ordering

The bundled AST maintains canonical ordering for deterministic output:

  • Types: Sorted alphabetically by name
  • Entities: Sorted alphabetically by name
  • Behaviors: Sorted alphabetically by name
  • Invariants: Sorted alphabetically by name
  • Policies: Sorted alphabetically by name
  • Views: Sorted alphabetically by name
  • Scenarios: Sorted by behavior name
  • Chaos: Sorted by behavior name

Cycle Detection

Circular dependencies are detected and reported with clear paths:

[CIRCULAR_DEPENDENCY] Circular dependency detected:
  → /specs/a.isl
  → /specs/b.isl
  → /specs/c.isl
  → /specs/a.isl

Circular imports are not allowed.
Consider restructuring your modules to break the cycle.

Diamond Dependencies

Diamond dependencies (multiple paths to the same module) are allowed:

main.isl
├── a.isl
│   └── shared.isl
└── b.isl
    └── shared.isl

The shared module is only included once in the bundle.

MVP Mode Toggle

Checking for Imports

import { hasImports } from '@isl-lang/import-resolver';

const needsImportResolution = hasImports(source);
if (needsImportResolution) {
  // Use resolveAndBundle
} else {
  // Can use parseSingleFile
}

Single-File Mode Error

When imports are disabled and a file has imports:

[IMPORTS_DISABLED] Import resolution is disabled (single-file mode).
Cannot import "./types.isl".
To enable multi-file imports, set 'enableImports: true' in resolver options.
Note: Multi-file mode requires all imported modules to be available.

API Reference

resolveAndBundle(entryPoint, options)

Resolve imports and bundle into a single AST.

interface ResolveAndBundleOptions {
  basePath?: string;           // Base directory for imports
  enableImports?: boolean;     // Enable/disable import resolution
  allowShadowing?: boolean;    // Allow definition shadowing
  stripImports?: boolean;      // Remove import declarations from bundle
  bundleDomainName?: string;   // Custom domain name for bundle
  bundleVersion?: string;      // Custom version for bundle
  maxDepth?: number;           // Max import depth (default: 100)
}

parseSingleFile(source, filename)

Parse a single file without import resolution.

const result = parseSingleFile(source, 'spec.isl');
// Returns BundleResult

hasImports(source)

Check if source has import declarations.

const hasImports: boolean = hasImports(source);

validateImportPaths(source)

Validate import paths without resolution.

const { valid, errors } = validateImportPaths(source);

createVirtualFS(files, basePath)

Create a virtual file system for testing.

const vfs = createVirtualFS({
  'main.isl': 'domain Main { ... }',
  'types.isl': 'domain Types { ... }',
}, '/test');

Limitations

Current Limitations

  • Only relative paths: Package imports (@stdlib/auth) not yet supported
  • No glob imports: Cannot import { * } from "./module"
  • No re-exports: Cannot re-export from modules
  • No conditional imports: All imports are unconditional

Future Enhancements

  • Package/workspace imports
  • Glob imports (import * as Types from "./types")
  • Re-exports
  • Import aliases at module level
  • Lazy import resolution

Error Codes

CodeDescription
IMPORTS_DISABLEDImport resolution disabled but file has imports
MODULE_NOT_FOUNDImport target file not found
PARSE_ERRORFailed to parse imported module
READ_ERRORFailed to read file
CIRCULAR_DEPENDENCYCircular import detected
MAX_DEPTH_EXCEEDEDImport chain too deep
DUPLICATE_TYPEDuplicate type definition
DUPLICATE_ENTITYDuplicate entity definition
DUPLICATE_BEHAVIORDuplicate behavior definition
SYMBOL_NOT_FOUNDImported symbol not exported
INVALID_IMPORT_PATHImport path format invalid

Testing

# Run tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Run tests in watch mode
pnpm test:watch

License

MIT

Keywords

isl

FAQs

Package last updated on 12 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts