@tokenoftrust/storefront-runner 3.10.4 → 3.10.5

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": "@tokenoftrust/storefront-runner",
3
- "version": "3.10.4",
3
+ "version": "3.10.5",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",
@@ -9,8 +9,9 @@
9
9
  import { readdirSync, readFileSync } from "node:fs";
10
10
  import { mkdir, writeFile } from "node:fs/promises";
11
11
  import { dirname, relative, resolve } from "node:path";
12
- import { fileURLToPath, pathToFileURL } from "node:url";
12
+ import { fileURLToPath } from "node:url";
13
13
 
14
+ import { isMainModule } from "../../../scripts/lib/is-main-module.mjs";
14
15
  const here = dirname(fileURLToPath(import.meta.url));
15
16
  const repoRoot = resolve(here, "../../..");
16
17
  export const OUTPUT_DIR = relative(repoRoot, resolve(here, "../schemas/managed-analytics/v1"));
@@ -92,6 +93,6 @@ async function write() {
92
93
  for (const [path, text] of files) await writeFile(resolve(repoRoot, path), text, "utf8");
93
94
  }
94
95
 
95
- if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
96
+ if (isMainModule(import.meta.url)) {
96
97
  await (process.argv.includes("--check") ? check() : write());
97
98
  }
@@ -43,6 +43,7 @@
43
43
  */
44
44
  import { execFileSync } from "node:child_process";
45
45
 
46
+ import { isMainModule } from "../lib/is-main-module.mjs";
46
47
  /** Umbrella branch this epic folds into. */
47
48
  export const DEFAULT_UMBRELLA = "feature/8500-storefront-integration";
48
49
 
@@ -493,6 +494,6 @@ function renderReport(r) {
493
494
  }
494
495
 
495
496
  // Run only when invoked directly (not when imported by the test).
496
- if (import.meta.url === `file://${process.argv[1]}`) {
497
+ if (isMainModule(import.meta.url)) {
497
498
  main();
498
499
  }
@@ -0,0 +1,20 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ /**
5
+ * Whether the module at `moduleUrl` is the script node was asked to run. Compared by real path on
6
+ * both sides: node reports `import.meta.url` resolved through symlinks but leaves `process.argv[1]`
7
+ * as typed, so a plain comparison is false whenever the script is reached through a symlink, and
8
+ * then main never runs and the process exits 0 having done nothing.
9
+ * @param {string} moduleUrl
10
+ * @param {string | undefined} [argv1]
11
+ * @returns {boolean}
12
+ */
13
+ export function isMainModule(moduleUrl, argv1 = process.argv[1]) {
14
+ if (!argv1) return false;
15
+ try {
16
+ return realpathSync(argv1) === realpathSync(fileURLToPath(moduleUrl));
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
@@ -26,6 +26,7 @@
26
26
  */
27
27
  import { readdirSync, readFileSync, statSync } from "node:fs";
28
28
  import { join, extname } from "node:path";
29
+ import { isMainModule } from "../lib/is-main-module.mjs";
29
30
  import { EMBED_PROVIDERS } from "../../packages/public-runtime/src/embed-catalog.mjs";
30
31
 
31
32
  /**
@@ -169,4 +170,4 @@ function main() {
169
170
  }
170
171
 
171
172
  // Only run main when invoked directly, not when imported by the parity test.
172
- if (import.meta.url === `file://${process.argv[1]}`) main();
173
+ if (isMainModule(import.meta.url)) main();
@@ -69,7 +69,8 @@ import {
69
69
  import { execFileSync } from "node:child_process";
70
70
  import { tmpdir } from "node:os";
71
71
  import { dirname, join, resolve, sep } from "node:path";
72
- import { fileURLToPath, pathToFileURL } from "node:url";
72
+ import { fileURLToPath } from "node:url";
73
+ import { isMainModule } from "../lib/is-main-module.mjs";
73
74
  import { tenantDirRelative } from "../lib/tenant-dirs.mjs";
74
75
  import { parseMappingTarget } from "../../agency-kit/tools/lib/tot-repo-mappings.mjs";
75
76
 
@@ -648,9 +649,7 @@ function main() {
648
649
  }
649
650
  }
650
651
 
651
- const invokedDirectly =
652
- process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
653
- if (invokedDirectly) {
652
+ if (isMainModule(import.meta.url)) {
654
653
  try {
655
654
  main();
656
655
  } catch (e) {
@@ -28,6 +28,7 @@
28
28
  import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
29
29
  import { dirname, resolve, join, relative } from "node:path";
30
30
  import { fileURLToPath } from "node:url";
31
+ import { isMainModule } from "../lib/is-main-module.mjs";
31
32
  import { KNOWN_EMBEDS, lintTenantEmbeds } from "./lint-embeds.mjs";
32
33
  import { listTenantDirIds, tenantDirSegments } from "../lib/tenant-dirs.mjs";
33
34
  import {
@@ -352,7 +353,6 @@ function validateThemeHeadings(theme, file) {
352
353
  return out;
353
354
  }
354
355
 
355
-
356
356
  const SUPPORTED_BLOCK_CONTRACTS = new Set(BLOCK_PALETTE_SUPPORTED_CONTRACTS);
357
357
  const KNOWN_BLOCKS = new Set([
358
358
  "hero",
@@ -1388,8 +1388,7 @@ function resolveTenantDir(argv) {
1388
1388
  return { dir: tenantDir(id), tenantId: id };
1389
1389
  }
1390
1390
 
1391
- const isMain = resolve(process.argv[1] || "") === resolve(fileURLToPath(import.meta.url));
1392
- if (isMain) {
1391
+ if (isMainModule(import.meta.url)) {
1393
1392
  const argv = process.argv.slice(2);
1394
1393
  const asJson = argv.includes("--json");
1395
1394
  const profileIndex = argv.indexOf("--profile");