dirac-lang 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-APWJJXNI.js → chunk-7OUYWIZV.js} +55 -14
- package/dist/{chunk-RGS2XK6T.js → chunk-OUMUIBK3.js} +1 -1
- package/dist/cli.js +2 -2
- package/dist/index.js +2 -2
- package/dist/{interpreter-UZDVASAW.js → interpreter-MTIIHIIQ.js} +1 -1
- package/dist/test-runner.js +1 -1
- package/package.json +1 -1
- package/src/tags/import.ts +73 -4
|
@@ -419,12 +419,12 @@ async function executeIf(session, element) {
|
|
|
419
419
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
420
420
|
if (condition) {
|
|
421
421
|
if (thenElement) {
|
|
422
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
422
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
423
423
|
await integrateChildren2(session, thenElement);
|
|
424
424
|
}
|
|
425
425
|
} else {
|
|
426
426
|
if (elseElement) {
|
|
427
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
427
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
428
428
|
await integrateChildren2(session, elseElement);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
@@ -437,7 +437,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
437
437
|
return await evaluateCondition(session, predicateElement);
|
|
438
438
|
}
|
|
439
439
|
const outputLengthBefore = session.output.length;
|
|
440
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
440
|
+
const { integrate: integrate2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
441
441
|
await integrate2(session, predicateElement);
|
|
442
442
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
443
443
|
const result = newOutputChunks.join("").trim();
|
|
@@ -460,11 +460,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
460
460
|
}
|
|
461
461
|
const outputLengthBefore = session.output.length;
|
|
462
462
|
const args = [];
|
|
463
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
463
|
+
const { integrate: integrate2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
464
464
|
for (const child of condElement.children) {
|
|
465
465
|
if (child.tag.toLowerCase() === "arg") {
|
|
466
466
|
const argOutputStart = session.output.length;
|
|
467
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
467
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
468
468
|
await integrateChildren2(session, child);
|
|
469
469
|
const newChunks = session.output.slice(argOutputStart);
|
|
470
470
|
const argValue = newChunks.join("");
|
|
@@ -937,15 +937,56 @@ ${diracCode}
|
|
|
937
937
|
}
|
|
938
938
|
|
|
939
939
|
// src/tags/import.ts
|
|
940
|
-
import { readFileSync } from "fs";
|
|
941
|
-
import { resolve, dirname as dirname2 } from "path";
|
|
940
|
+
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
941
|
+
import { resolve, dirname as dirname2, join } from "path";
|
|
942
|
+
function resolveImportPath(src, currentDir) {
|
|
943
|
+
if (src.startsWith("./") || src.startsWith("../") || src.startsWith("/")) {
|
|
944
|
+
const resolved2 = resolve(currentDir, src);
|
|
945
|
+
return resolved2.endsWith(".di") ? resolved2 : resolved2 + ".di";
|
|
946
|
+
}
|
|
947
|
+
let searchDir = currentDir;
|
|
948
|
+
while (true) {
|
|
949
|
+
const nodeModulesPath = join(searchDir, "node_modules", src);
|
|
950
|
+
if (existsSync2(nodeModulesPath)) {
|
|
951
|
+
const packageJsonPath = join(nodeModulesPath, "package.json");
|
|
952
|
+
if (existsSync2(packageJsonPath)) {
|
|
953
|
+
try {
|
|
954
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
955
|
+
const mainFile = packageJson.main || "lib/index.di";
|
|
956
|
+
const entryPath = join(nodeModulesPath, mainFile);
|
|
957
|
+
if (existsSync2(entryPath)) {
|
|
958
|
+
return entryPath;
|
|
959
|
+
}
|
|
960
|
+
} catch (err) {
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
const fallbacks = [
|
|
964
|
+
join(nodeModulesPath, "lib", "index.di"),
|
|
965
|
+
join(nodeModulesPath, "index.di")
|
|
966
|
+
];
|
|
967
|
+
for (const fallback of fallbacks) {
|
|
968
|
+
if (existsSync2(fallback)) {
|
|
969
|
+
return fallback;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
throw new Error(`Package "${src}" found but no entry point (.di file) available`);
|
|
973
|
+
}
|
|
974
|
+
const parentDir = dirname2(searchDir);
|
|
975
|
+
if (parentDir === searchDir) {
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
searchDir = parentDir;
|
|
979
|
+
}
|
|
980
|
+
const resolved = resolve(currentDir, src);
|
|
981
|
+
return resolved.endsWith(".di") ? resolved : resolved + ".di";
|
|
982
|
+
}
|
|
942
983
|
async function executeImport(session, element) {
|
|
943
984
|
const src = element.attributes.src;
|
|
944
985
|
if (!src) {
|
|
945
986
|
throw new Error("<import> requires src attribute");
|
|
946
987
|
}
|
|
947
988
|
const currentDir = session.currentFile ? dirname2(session.currentFile) : process.cwd();
|
|
948
|
-
const importPath =
|
|
989
|
+
const importPath = resolveImportPath(src, currentDir);
|
|
949
990
|
if (session.debug) {
|
|
950
991
|
console.error(`[IMPORT] Loading: ${importPath}`);
|
|
951
992
|
}
|
|
@@ -1282,7 +1323,7 @@ async function executeTagCheck(session, element) {
|
|
|
1282
1323
|
const executeTag = correctedTag || tagName;
|
|
1283
1324
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1284
1325
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1285
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1326
|
+
const { integrate: integrate2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
1286
1327
|
await integrate2(session, elementToExecute);
|
|
1287
1328
|
}
|
|
1288
1329
|
}
|
|
@@ -1291,7 +1332,7 @@ async function executeTagCheck(session, element) {
|
|
|
1291
1332
|
// src/tags/throw.ts
|
|
1292
1333
|
async function executeThrow(session, element) {
|
|
1293
1334
|
const exceptionName = element.attributes?.name || "exception";
|
|
1294
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1335
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
1295
1336
|
const exceptionDom = {
|
|
1296
1337
|
tag: "exception-content",
|
|
1297
1338
|
attributes: { name: exceptionName },
|
|
@@ -1304,7 +1345,7 @@ async function executeThrow(session, element) {
|
|
|
1304
1345
|
// src/tags/try.ts
|
|
1305
1346
|
async function executeTry(session, element) {
|
|
1306
1347
|
setExceptionBoundary(session);
|
|
1307
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1348
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
1308
1349
|
await integrateChildren2(session, element);
|
|
1309
1350
|
unsetExceptionBoundary(session);
|
|
1310
1351
|
}
|
|
@@ -1314,7 +1355,7 @@ async function executeCatch(session, element) {
|
|
|
1314
1355
|
const exceptionName = element.attributes?.name || "exception";
|
|
1315
1356
|
const caughtCount = lookupException(session, exceptionName);
|
|
1316
1357
|
if (caughtCount > 0) {
|
|
1317
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1358
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
1318
1359
|
await integrateChildren2(session, element);
|
|
1319
1360
|
}
|
|
1320
1361
|
flushCurrentException(session);
|
|
@@ -1323,7 +1364,7 @@ async function executeCatch(session, element) {
|
|
|
1323
1364
|
// src/tags/exception.ts
|
|
1324
1365
|
async function executeException(session, element) {
|
|
1325
1366
|
const exceptions = getCurrentExceptions(session);
|
|
1326
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1367
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
1327
1368
|
for (const exceptionDom of exceptions) {
|
|
1328
1369
|
await integrateChildren2(session, exceptionDom);
|
|
1329
1370
|
}
|
|
@@ -1463,7 +1504,7 @@ async function executeForeach(session, element) {
|
|
|
1463
1504
|
const parser2 = new DiracParser2();
|
|
1464
1505
|
try {
|
|
1465
1506
|
const fromElement = parser2.parse(fromAttr);
|
|
1466
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1507
|
+
const { integrate: integrate2 } = await import("./interpreter-MTIIHIIQ.js");
|
|
1467
1508
|
await integrate2(session, fromElement);
|
|
1468
1509
|
} catch (e) {
|
|
1469
1510
|
session.output = savedOutput;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-OUMUIBK3.js";
|
|
5
|
+
import "./chunk-7OUYWIZV.js";
|
|
6
6
|
import "./chunk-HRHAMPOB.js";
|
|
7
7
|
import "./chunk-E7PWEMZA.js";
|
|
8
8
|
import "./chunk-52ED23DR.js";
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-OUMUIBK3.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-7OUYWIZV.js";
|
|
9
9
|
import {
|
|
10
10
|
DiracParser
|
|
11
11
|
} from "./chunk-HRHAMPOB.js";
|
package/dist/test-runner.js
CHANGED
package/package.json
CHANGED
package/src/tags/import.ts
CHANGED
|
@@ -4,11 +4,80 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { DiracSession, DiracElement } from '../types/index.js';
|
|
7
|
-
import { readFileSync } from 'fs';
|
|
8
|
-
import { resolve, dirname } from 'path';
|
|
7
|
+
import { readFileSync, existsSync } from 'fs';
|
|
8
|
+
import { resolve, dirname, join } from 'path';
|
|
9
9
|
import { DiracParser } from '../runtime/parser.js';
|
|
10
10
|
import { integrate } from '../runtime/interpreter.js';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Resolve import path - supports relative paths and node_modules packages
|
|
14
|
+
* @param src - The import source (e.g., "./file.di" or "package-name")
|
|
15
|
+
* @param currentDir - Current directory context
|
|
16
|
+
* @returns Resolved absolute path
|
|
17
|
+
*/
|
|
18
|
+
function resolveImportPath(src: string, currentDir: string): string {
|
|
19
|
+
// If it starts with ./ or ../ or /, it's a relative/absolute path
|
|
20
|
+
if (src.startsWith('./') || src.startsWith('../') || src.startsWith('/')) {
|
|
21
|
+
const resolved = resolve(currentDir, src);
|
|
22
|
+
// Add .di extension if not present
|
|
23
|
+
return resolved.endsWith('.di') ? resolved : resolved + '.di';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Otherwise, try to resolve as a package from node_modules
|
|
27
|
+
// Walk up the directory tree looking for node_modules
|
|
28
|
+
let searchDir = currentDir;
|
|
29
|
+
|
|
30
|
+
while (true) {
|
|
31
|
+
const nodeModulesPath = join(searchDir, 'node_modules', src);
|
|
32
|
+
|
|
33
|
+
if (existsSync(nodeModulesPath)) {
|
|
34
|
+
// Found the package, now find the entry point
|
|
35
|
+
// Try to read package.json to get the "main" field
|
|
36
|
+
const packageJsonPath = join(nodeModulesPath, 'package.json');
|
|
37
|
+
|
|
38
|
+
if (existsSync(packageJsonPath)) {
|
|
39
|
+
try {
|
|
40
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
41
|
+
const mainFile = packageJson.main || 'lib/index.di';
|
|
42
|
+
const entryPath = join(nodeModulesPath, mainFile);
|
|
43
|
+
|
|
44
|
+
if (existsSync(entryPath)) {
|
|
45
|
+
return entryPath;
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
// If package.json parse fails, fall through to default
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Fallback: try common entry points
|
|
53
|
+
const fallbacks = [
|
|
54
|
+
join(nodeModulesPath, 'lib', 'index.di'),
|
|
55
|
+
join(nodeModulesPath, 'index.di'),
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
for (const fallback of fallbacks) {
|
|
59
|
+
if (existsSync(fallback)) {
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw new Error(`Package "${src}" found but no entry point (.di file) available`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Move up one directory
|
|
68
|
+
const parentDir = dirname(searchDir);
|
|
69
|
+
if (parentDir === searchDir) {
|
|
70
|
+
// Reached root, package not found
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
searchDir = parentDir;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Package not found in node_modules, treat as relative path with .di extension
|
|
77
|
+
const resolved = resolve(currentDir, src);
|
|
78
|
+
return resolved.endsWith('.di') ? resolved : resolved + '.di';
|
|
79
|
+
}
|
|
80
|
+
|
|
12
81
|
export async function executeImport(session: DiracSession, element: DiracElement): Promise<void> {
|
|
13
82
|
const src = element.attributes.src;
|
|
14
83
|
|
|
@@ -19,8 +88,8 @@ export async function executeImport(session: DiracSession, element: DiracElement
|
|
|
19
88
|
// Get the current file's directory (if available in session)
|
|
20
89
|
const currentDir = session.currentFile ? dirname(session.currentFile) : process.cwd();
|
|
21
90
|
|
|
22
|
-
// Resolve the import path
|
|
23
|
-
const importPath =
|
|
91
|
+
// Resolve the import path (handles both relative paths and node_modules packages)
|
|
92
|
+
const importPath = resolveImportPath(src, currentDir);
|
|
24
93
|
|
|
25
94
|
if (session.debug) {
|
|
26
95
|
console.error(`[IMPORT] Loading: ${importPath}`);
|