@epic-web/workshop-app 4.16.2 → 4.16.3

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.
@@ -21,7 +21,7 @@ import "@total-typescript/ts-reset";
21
21
  import { execaCommand, execa } from "execa";
22
22
  import { glob } from "glob";
23
23
  import { isGitIgnored, globby } from "globby";
24
- import "chokidar";
24
+ import chokidar from "chokidar";
25
25
  import closeWithGrace from "close-with-grace";
26
26
  import fs$1 from "fs";
27
27
  import { remarkCodeBlocksShiki } from "@kentcdodds/md-temp";
@@ -585,6 +585,27 @@ function uniqueUsers(users) {
585
585
  });
586
586
  }
587
587
  let watcher = global.__change_tracker_watcher__;
588
+ function getWatcher() {
589
+ if (process.env.EPICSHOP_DEPLOYED ?? process.env.EPICSHOP_DISABLE_WATCHER === "true") {
590
+ return null;
591
+ }
592
+ if (watcher) return watcher;
593
+ const workshopRoot2 = process.env.EPICSHOP_CONTEXT_CWD ?? process.cwd();
594
+ watcher = chokidar.watch(workshopRoot2, {
595
+ ignoreInitial: true,
596
+ ignored: [
597
+ "**/.git/**",
598
+ "**/node_modules/**",
599
+ "**/build/**",
600
+ "**/public/build/**",
601
+ "**/playwright-report/**",
602
+ "**/dist/**",
603
+ "**/.cache/**"
604
+ ]
605
+ });
606
+ global.__change_tracker_watcher__ = watcher;
607
+ return watcher;
608
+ }
588
609
  function getOptionalWatcher() {
589
610
  return watcher;
590
611
  }
@@ -1152,12 +1173,22 @@ async function queuedBundleMDX(...args) {
1152
1173
  const result = await queue.add(() => bundleMDX(...args));
1153
1174
  return result;
1154
1175
  }
1155
- z$1.object({
1176
+ const schema = z$1.object({
1156
1177
  NODE_ENV: z$1.enum(["production", "development", "test"]).default("development"),
1157
1178
  EPICSHOP_GITHUB_REPO: z$1.string(),
1158
1179
  EPICSHOP_GITHUB_ROOT: z$1.string(),
1159
1180
  EPICSHOP_CONTEXT_CWD: z$1.string()
1160
1181
  });
1182
+ function init$1() {
1183
+ const parsed = schema.safeParse(process.env);
1184
+ if (!parsed.success) {
1185
+ console.error(
1186
+ "❌ Invalid environment variables:",
1187
+ parsed.error.flatten().fieldErrors
1188
+ );
1189
+ throw new Error("Invalid environment variables");
1190
+ }
1191
+ }
1161
1192
  function getEnv() {
1162
1193
  return {
1163
1194
  MODE: process.env.NODE_ENV,
@@ -1451,6 +1482,7 @@ async function getPkgProp(fullPath, prop, defaultValue) {
1451
1482
  }
1452
1483
  return value ?? defaultValue;
1453
1484
  }
1485
+ let initialized = false;
1454
1486
  const workshopRoot = getWorkshopRoot();
1455
1487
  let packageJson;
1456
1488
  try {
@@ -1591,16 +1623,57 @@ function exists(file) {
1591
1623
  () => false
1592
1624
  );
1593
1625
  }
1594
- function firstToExist(...files) {
1595
- return Promise.all(files.map(exists)).then((results) => {
1596
- const index = results.findIndex(Boolean);
1597
- return index === -1 ? null : files[index];
1598
- });
1626
+ async function firstToExist(...files) {
1627
+ const results = await Promise.all(files.map(exists));
1628
+ const index = results.findIndex(Boolean);
1629
+ return index === -1 ? null : files[index];
1599
1630
  }
1600
1631
  const modifiedTimes = remember(
1601
1632
  "modified_times",
1602
1633
  () => /* @__PURE__ */ new Map()
1603
1634
  );
1635
+ function init() {
1636
+ var _a2;
1637
+ if (initialized) return;
1638
+ initialized = true;
1639
+ try {
1640
+ const { epicshop } = packageJson;
1641
+ let root, repo;
1642
+ if (epicshop.githubRepo) {
1643
+ repo = epicshop.githubRepo;
1644
+ root = `${repo.replace(/\/$/, "")}/tree/main`;
1645
+ } else if (epicshop.githubRoot) {
1646
+ root = epicshop.githubRoot.replace(/\/$/, "");
1647
+ repo = root.replace(/\/(blob|tree)\/.*$/, "");
1648
+ } else {
1649
+ throw new Error(
1650
+ `Please set the URL of your GitHub repo in the "epicshop.githubRepo" property of the package.json.`
1651
+ );
1652
+ }
1653
+ if (!root.includes("/blob/") && !root.includes("/tree/")) {
1654
+ root = `${root.replace(/\/$/, "")}/tree/main`;
1655
+ }
1656
+ process.env.EPICSHOP_GITHUB_REPO = repo;
1657
+ process.env.EPICSHOP_GITHUB_ROOT = root;
1658
+ } catch (error) {
1659
+ throw new Error(
1660
+ `Could not set the EPICSHOP_GITHUB_ROOT environment variable. Please set it to the URL of your GitHub repo in the "epicshop.githubRoot" property of the package.json.`,
1661
+ { cause: error }
1662
+ );
1663
+ }
1664
+ init$1();
1665
+ global.ENV = getEnv();
1666
+ async function handleFileChanges(event, filePath) {
1667
+ const apps = await getApps();
1668
+ for (const app of apps) {
1669
+ if (filePath.startsWith(app.fullPath)) {
1670
+ modifiedTimes.set(app.fullPath, Date.now());
1671
+ break;
1672
+ }
1673
+ }
1674
+ }
1675
+ (_a2 = getWatcher()) == null ? void 0 : _a2.on("all", handleFileChanges);
1676
+ }
1604
1677
  function getForceFresh$1(cacheEntry) {
1605
1678
  if (!cacheEntry) return true;
1606
1679
  const latestModifiedTime = Math.max(...Array.from(modifiedTimes.values()));
@@ -1713,6 +1786,7 @@ async function getApps({
1713
1786
  request,
1714
1787
  forceFresh
1715
1788
  } = {}) {
1789
+ if (!initialized) init();
1716
1790
  const key = "apps";
1717
1791
  const apps = await cachified({
1718
1792
  key,
@@ -3779,10 +3853,10 @@ const toastSessionStorage = createCookieSessionStorage({
3779
3853
  secure: process.env.NODE_ENV === "production"
3780
3854
  }
3781
3855
  });
3782
- async function redirectWithToast(url, toast2, init) {
3856
+ async function redirectWithToast(url, toast2, init2) {
3783
3857
  return redirect(url, {
3784
- ...init,
3785
- headers: combineHeaders(init == null ? void 0 : init.headers, await createToastHeaders(toast2))
3858
+ ...init2,
3859
+ headers: combineHeaders(init2 == null ? void 0 : init2.headers, await createToastHeaders(toast2))
3786
3860
  });
3787
3861
  }
3788
3862
  async function createToastHeaders(optionalToast) {