starlight-cli 1.0.5 → 1.0.7

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) {
@@ -2440,6 +2444,8 @@ const Lexer = __nccwpck_require__(211);
2440
2444
  const Parser = __nccwpck_require__(222);
2441
2445
  const Evaluator = __nccwpck_require__(112);
2442
2446
 
2447
+ const VERSION = '1.0.7';
2448
+
2443
2449
  const COLOR = {
2444
2450
  reset: '\x1b[0m',
2445
2451
  bold: '\x1b[1m',
@@ -2478,10 +2484,36 @@ function printSourceContext(code, line, column) {
2478
2484
  );
2479
2485
  }
2480
2486
 
2487
+
2481
2488
  const args = process.argv.slice(2);
2482
2489
 
2483
2490
  if (args.length === 0) {
2484
- return fatal('Usage: starlight <file.sl>');
2491
+ console.log(`
2492
+ Starlight Programming Language
2493
+
2494
+ Usage:
2495
+ starlight <file.sl> Run a Starlight program
2496
+ starlight -v Show version
2497
+ starlight --help Show help
2498
+ `);
2499
+ process.exit(0);
2500
+ }
2501
+
2502
+ if (args[0] === '-v' || args[0] === '--version') {
2503
+ console.log(`Starlight CLI v${VERSION}`);
2504
+ process.exit(0);
2505
+ }
2506
+
2507
+ if (args[0] === '--help') {
2508
+ console.log(`
2509
+ Starlight CLI Help
2510
+
2511
+ Commands:
2512
+ starlight file.sl Run a Starlight program
2513
+ starlight -v Show version
2514
+ starlight --help Show this help message
2515
+ `);
2516
+ process.exit(0);
2485
2517
  }
2486
2518
 
2487
2519
  const filePath = path.resolve(args[0]);
@@ -2497,6 +2529,7 @@ try {
2497
2529
  return fatal(`Failed to read file: ${err.message}`);
2498
2530
  }
2499
2531
 
2532
+
2500
2533
  let tokens;
2501
2534
  try {
2502
2535
  const lexer = new Lexer(code);
@@ -2549,6 +2582,7 @@ console.log(
2549
2582
  '\nProgram finished successfully.' +
2550
2583
  COLOR.reset
2551
2584
  );
2585
+
2552
2586
  waitAndExit(0);
2553
2587
 
2554
2588
  module.exports = __webpack_exports__;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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) {
package/src/starlight.js CHANGED
@@ -5,6 +5,8 @@ const Lexer = require('./lexer');
5
5
  const Parser = require('./parser');
6
6
  const Evaluator = require('./evaluator');
7
7
 
8
+ const VERSION = '1.0.7';
9
+
8
10
  const COLOR = {
9
11
  reset: '\x1b[0m',
10
12
  bold: '\x1b[1m',
@@ -43,10 +45,36 @@ function printSourceContext(code, line, column) {
43
45
  );
44
46
  }
45
47
 
48
+
46
49
  const args = process.argv.slice(2);
47
50
 
48
51
  if (args.length === 0) {
49
- return fatal('Usage: starlight <file.sl>');
52
+ console.log(`
53
+ Starlight Programming Language
54
+
55
+ Usage:
56
+ starlight <file.sl> Run a Starlight program
57
+ starlight -v Show version
58
+ starlight --help Show help
59
+ `);
60
+ process.exit(0);
61
+ }
62
+
63
+ if (args[0] === '-v' || args[0] === '--version') {
64
+ console.log(`Starlight CLI v${VERSION}`);
65
+ process.exit(0);
66
+ }
67
+
68
+ if (args[0] === '--help') {
69
+ console.log(`
70
+ Starlight CLI Help
71
+
72
+ Commands:
73
+ starlight file.sl Run a Starlight program
74
+ starlight -v Show version
75
+ starlight --help Show this help message
76
+ `);
77
+ process.exit(0);
50
78
  }
51
79
 
52
80
  const filePath = path.resolve(args[0]);
@@ -62,6 +90,7 @@ try {
62
90
  return fatal(`Failed to read file: ${err.message}`);
63
91
  }
64
92
 
93
+
65
94
  let tokens;
66
95
  try {
67
96
  const lexer = new Lexer(code);
@@ -114,4 +143,5 @@ console.log(
114
143
  '\nProgram finished successfully.' +
115
144
  COLOR.reset
116
145
  );
146
+
117
147
  waitAndExit(0);