stackmem 1.0.22 → 1.0.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.
Files changed (3) hide show
  1. package/dist/cli.js +14 -2
  2. package/package.json +1 -1
  3. package/src/cli.ts +15 -2
package/dist/cli.js CHANGED
@@ -2149,8 +2149,20 @@ async function main() {
2149
2149
  }
2150
2150
  // Guards the auto-run so importing this module (e.g. from a test file, to
2151
2151
  // reach exported helpers like trySeedMemory) doesn't also execute main()
2152
- // against the test runner's own argv.
2153
- const isMainModule = process.argv[1] != null && import.meta.url === pathToFileURL(process.argv[1]).href;
2152
+ // against the test runner's own argv. realpathSync matters here: the `cm`
2153
+ // bin is typically a symlink (npm link, or the global install this project
2154
+ // itself uses), and process.argv[1] preserves the symlink path as invoked
2155
+ // while import.meta.url resolves to the link's real target — comparing
2156
+ // them raw would never match, silently skipping main() entirely.
2157
+ function resolveMainModulePath(argvPath) {
2158
+ try {
2159
+ return pathToFileURL(nodeFs.realpathSync(argvPath)).href;
2160
+ }
2161
+ catch {
2162
+ return null;
2163
+ }
2164
+ }
2165
+ const isMainModule = process.argv[1] != null && import.meta.url === resolveMainModulePath(process.argv[1]);
2154
2166
  if (isMainModule) {
2155
2167
  main().catch((error) => {
2156
2168
  fail(error instanceof Error ? error.message : String(error));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stackmem",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/cli.ts CHANGED
@@ -2418,8 +2418,21 @@ async function main() {
2418
2418
 
2419
2419
  // Guards the auto-run so importing this module (e.g. from a test file, to
2420
2420
  // reach exported helpers like trySeedMemory) doesn't also execute main()
2421
- // against the test runner's own argv.
2422
- const isMainModule = process.argv[1] != null && import.meta.url === pathToFileURL(process.argv[1]).href;
2421
+ // against the test runner's own argv. realpathSync matters here: the `cm`
2422
+ // bin is typically a symlink (npm link, or the global install this project
2423
+ // itself uses), and process.argv[1] preserves the symlink path as invoked
2424
+ // while import.meta.url resolves to the link's real target — comparing
2425
+ // them raw would never match, silently skipping main() entirely.
2426
+ function resolveMainModulePath(argvPath: string): string | null {
2427
+ try {
2428
+ return pathToFileURL(nodeFs.realpathSync(argvPath)).href;
2429
+ } catch {
2430
+ return null;
2431
+ }
2432
+ }
2433
+
2434
+ const isMainModule =
2435
+ process.argv[1] != null && import.meta.url === resolveMainModulePath(process.argv[1]);
2423
2436
  if (isMainModule) {
2424
2437
  main().catch((error) => {
2425
2438
  fail(error instanceof Error ? error.message : String(error));