poe-code 7.0.0 → 7.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  import { type OutputStream } from "./output-stream.js";
2
3
  import type { ModuleRegistry } from "./modules/registry.js";
3
4
  type CliStream = OutputStream;
@@ -1,7 +1,8 @@
1
- import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
1
+ #!/usr/bin/env node
2
+ import { mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
2
3
  import path, { dirname, extname } from "node:path";
3
4
  import { formatWithOptions } from "node:util";
4
- import { pathToFileURL } from "node:url";
5
+ import { fileURLToPath } from "node:url";
5
6
  import { hasOwnErrorCode } from "./error-codes.js";
6
7
  import { formatInterpreterError } from "./error/format.js";
7
8
  import { replaceErrorStack } from "./error/shape.js";
@@ -548,8 +549,21 @@ class CliExitError extends Error {
548
549
  this.exitCode = exitCode;
549
550
  }
550
551
  }
551
- if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
552
- runCli(process.argv.slice(2)).then((exitCode) => {
553
- process.exitCode = exitCode;
554
- });
552
+ async function isDirectExecution(entryPoint) {
553
+ if (typeof entryPoint !== "string" || entryPoint.length === 0) {
554
+ return false;
555
+ }
556
+ try {
557
+ const [resolvedEntryPoint, resolvedModule] = await Promise.all([
558
+ realpath(path.resolve(entryPoint)),
559
+ realpath(fileURLToPath(import.meta.url))
560
+ ]);
561
+ return resolvedEntryPoint === resolvedModule;
562
+ }
563
+ catch {
564
+ return false;
565
+ }
566
+ }
567
+ if (await isDirectExecution(process.argv[1])) {
568
+ process.exitCode = await runCli(process.argv.slice(2));
555
569
  }