starlight-cli 1.0.5 → 1.0.6

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/index.js CHANGED
@@ -1345,6 +1345,7 @@ const readlineSync = __nccwpck_require__(552);
1345
1345
  const fs = __nccwpck_require__(896);
1346
1346
  const Lexer = __nccwpck_require__(211);
1347
1347
  const Parser = __nccwpck_require__(222);
1348
+ const path = __nccwpck_require__(928);
1348
1349
 
1349
1350
  class ReturnValue {
1350
1351
  constructor(value) { this.value = value; }
@@ -1468,17 +1469,22 @@ this.global.define('str', arg => {
1468
1469
  }
1469
1470
  return result;
1470
1471
  }
1471
- evalImport(node, env) {
1472
- const path = node.path;
1472
+ evalImport(node, env) {
1473
+ const spec = node.path;
1473
1474
  let lib;
1474
1475
 
1475
1476
  try {
1476
- lib = require(path);
1477
+ const resolved = require.resolve(spec, {
1478
+ paths: [process.cwd()]
1479
+ });
1480
+ lib = require(resolved);
1477
1481
  } catch (e) {
1478
- const fullPath = path.endsWith('.sl') ? path : path + '.sl';
1482
+ const fullPath = path.isAbsolute(spec)
1483
+ ? spec
1484
+ : path.join(process.cwd(), spec.endsWith('.sl') ? spec : spec + '.sl');
1479
1485
 
1480
1486
  if (!fs.existsSync(fullPath)) {
1481
- throw new Error(`Import not found: ${path}`);
1487
+ throw new Error(`Import not found: ${spec}`);
1482
1488
  }
1483
1489
 
1484
1490
  const code = fs.readFileSync(fullPath, 'utf-8');
@@ -1493,30 +1499,28 @@ this.global.define('str', arg => {
1493
1499
  lib[key] = moduleEnv.store[key];
1494
1500
  }
1495
1501
 
1496
- // JS-style default export fallback
1497
1502
  lib.default = lib;
1498
1503
  }
1499
1504
 
1500
- for (const spec of node.specifiers) {
1501
- if (spec.type === 'DefaultImport') {
1502
- env.define(spec.local, lib.default ?? lib);
1505
+ for (const imp of node.specifiers) {
1506
+ if (imp.type === 'DefaultImport') {
1507
+ env.define(imp.local, lib.default ?? lib);
1503
1508
  }
1504
-
1505
- if (spec.type === 'NamespaceImport') {
1506
- env.define(spec.local, lib);
1509
+ if (imp.type === 'NamespaceImport') {
1510
+ env.define(imp.local, lib);
1507
1511
  }
1508
-
1509
- if (spec.type === 'NamedImport') {
1510
- if (!(spec.imported in lib)) {
1511
- throw new Error(`Module '${path}' has no export '${spec.imported}'`);
1512
+ if (imp.type === 'NamedImport') {
1513
+ if (!(imp.imported in lib)) {
1514
+ throw new Error(`Module '${spec}' has no export '${imp.imported}'`);
1512
1515
  }
1513
- env.define(spec.local, lib[spec.imported]);
1516
+ env.define(imp.local, lib[imp.imported]);
1514
1517
  }
1515
1518
  }
1516
1519
 
1517
1520
  return null;
1518
1521
  }
1519
1522
 
1523
+
1520
1524
  evalBlock(node, env) {
1521
1525
  let result = null;
1522
1526
  for (const stmt of node.body) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -2,6 +2,7 @@ const readlineSync = require('readline-sync');
2
2
  const fs = require('fs');
3
3
  const Lexer = require('./lexer');
4
4
  const Parser = require('./parser');
5
+ const path = require('path');
5
6
 
6
7
  class ReturnValue {
7
8
  constructor(value) { this.value = value; }
@@ -125,17 +126,22 @@ this.global.define('str', arg => {
125
126
  }
126
127
  return result;
127
128
  }
128
- evalImport(node, env) {
129
- const path = node.path;
129
+ evalImport(node, env) {
130
+ const spec = node.path;
130
131
  let lib;
131
132
 
132
133
  try {
133
- lib = require(path);
134
+ const resolved = require.resolve(spec, {
135
+ paths: [process.cwd()]
136
+ });
137
+ lib = require(resolved);
134
138
  } catch (e) {
135
- const fullPath = path.endsWith('.sl') ? path : path + '.sl';
139
+ const fullPath = path.isAbsolute(spec)
140
+ ? spec
141
+ : path.join(process.cwd(), spec.endsWith('.sl') ? spec : spec + '.sl');
136
142
 
137
143
  if (!fs.existsSync(fullPath)) {
138
- throw new Error(`Import not found: ${path}`);
144
+ throw new Error(`Import not found: ${spec}`);
139
145
  }
140
146
 
141
147
  const code = fs.readFileSync(fullPath, 'utf-8');
@@ -150,30 +156,28 @@ this.global.define('str', arg => {
150
156
  lib[key] = moduleEnv.store[key];
151
157
  }
152
158
 
153
- // JS-style default export fallback
154
159
  lib.default = lib;
155
160
  }
156
161
 
157
- for (const spec of node.specifiers) {
158
- if (spec.type === 'DefaultImport') {
159
- env.define(spec.local, lib.default ?? lib);
162
+ for (const imp of node.specifiers) {
163
+ if (imp.type === 'DefaultImport') {
164
+ env.define(imp.local, lib.default ?? lib);
160
165
  }
161
-
162
- if (spec.type === 'NamespaceImport') {
163
- env.define(spec.local, lib);
166
+ if (imp.type === 'NamespaceImport') {
167
+ env.define(imp.local, lib);
164
168
  }
165
-
166
- if (spec.type === 'NamedImport') {
167
- if (!(spec.imported in lib)) {
168
- throw new Error(`Module '${path}' has no export '${spec.imported}'`);
169
+ if (imp.type === 'NamedImport') {
170
+ if (!(imp.imported in lib)) {
171
+ throw new Error(`Module '${spec}' has no export '${imp.imported}'`);
169
172
  }
170
- env.define(spec.local, lib[spec.imported]);
173
+ env.define(imp.local, lib[imp.imported]);
171
174
  }
172
175
  }
173
176
 
174
177
  return null;
175
178
  }
176
179
 
180
+
177
181
  evalBlock(node, env) {
178
182
  let result = null;
179
183
  for (const stmt of node.body) {