@epic-web/workshop-utils 0.0.0-semantically-released

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 (79) hide show
  1. package/README.md +3 -0
  2. package/dist/esm/apps.server.d.ts +4205 -0
  3. package/dist/esm/apps.server.d.ts.map +1 -0
  4. package/dist/esm/apps.server.js +1198 -0
  5. package/dist/esm/apps.server.js.map +1 -0
  6. package/dist/esm/cache.server.d.ts +940 -0
  7. package/dist/esm/cache.server.d.ts.map +1 -0
  8. package/dist/esm/cache.server.js +161 -0
  9. package/dist/esm/cache.server.js.map +1 -0
  10. package/dist/esm/compile-mdx.server.d.ts +12 -0
  11. package/dist/esm/compile-mdx.server.d.ts.map +1 -0
  12. package/dist/esm/compile-mdx.server.js +285 -0
  13. package/dist/esm/compile-mdx.server.js.map +1 -0
  14. package/dist/esm/config.server.d.ts +348 -0
  15. package/dist/esm/config.server.d.ts.map +1 -0
  16. package/dist/esm/config.server.js +231 -0
  17. package/dist/esm/config.server.js.map +1 -0
  18. package/dist/esm/db.server.d.ts +463 -0
  19. package/dist/esm/db.server.d.ts.map +1 -0
  20. package/dist/esm/db.server.js +260 -0
  21. package/dist/esm/db.server.js.map +1 -0
  22. package/dist/esm/diff.server.d.ts +18 -0
  23. package/dist/esm/diff.server.d.ts.map +1 -0
  24. package/dist/esm/diff.server.js +437 -0
  25. package/dist/esm/diff.server.js.map +1 -0
  26. package/dist/esm/env.server.d.ts +61 -0
  27. package/dist/esm/env.server.d.ts.map +1 -0
  28. package/dist/esm/env.server.js +42 -0
  29. package/dist/esm/env.server.js.map +1 -0
  30. package/dist/esm/epic-api.server.d.ts +227 -0
  31. package/dist/esm/epic-api.server.d.ts.map +1 -0
  32. package/dist/esm/epic-api.server.js +529 -0
  33. package/dist/esm/epic-api.server.js.map +1 -0
  34. package/dist/esm/git.server.d.ts +49 -0
  35. package/dist/esm/git.server.d.ts.map +1 -0
  36. package/dist/esm/git.server.js +135 -0
  37. package/dist/esm/git.server.js.map +1 -0
  38. package/dist/esm/iframe-sync.d.ts +10 -0
  39. package/dist/esm/iframe-sync.d.ts.map +1 -0
  40. package/dist/esm/iframe-sync.js +97 -0
  41. package/dist/esm/iframe-sync.js.map +1 -0
  42. package/dist/esm/modified-time.server.d.ts +7 -0
  43. package/dist/esm/modified-time.server.d.ts.map +1 -0
  44. package/dist/esm/modified-time.server.js +80 -0
  45. package/dist/esm/modified-time.server.js.map +1 -0
  46. package/dist/esm/notifications.server.d.ts +56 -0
  47. package/dist/esm/notifications.server.d.ts.map +1 -0
  48. package/dist/esm/notifications.server.js +65 -0
  49. package/dist/esm/notifications.server.js.map +1 -0
  50. package/dist/esm/package.json +3 -0
  51. package/dist/esm/playwright.server.d.ts +6 -0
  52. package/dist/esm/playwright.server.d.ts.map +1 -0
  53. package/dist/esm/playwright.server.js +95 -0
  54. package/dist/esm/playwright.server.js.map +1 -0
  55. package/dist/esm/process-manager.server.d.ts +77 -0
  56. package/dist/esm/process-manager.server.d.ts.map +1 -0
  57. package/dist/esm/process-manager.server.js +266 -0
  58. package/dist/esm/process-manager.server.js.map +1 -0
  59. package/dist/esm/test.d.ts +16 -0
  60. package/dist/esm/test.d.ts.map +1 -0
  61. package/dist/esm/test.js +56 -0
  62. package/dist/esm/test.js.map +1 -0
  63. package/dist/esm/timing.server.d.ts +20 -0
  64. package/dist/esm/timing.server.d.ts.map +1 -0
  65. package/dist/esm/timing.server.js +88 -0
  66. package/dist/esm/timing.server.js.map +1 -0
  67. package/dist/esm/user.server.d.ts +17 -0
  68. package/dist/esm/user.server.d.ts.map +1 -0
  69. package/dist/esm/user.server.js +38 -0
  70. package/dist/esm/user.server.js.map +1 -0
  71. package/dist/esm/utils.d.ts +2 -0
  72. package/dist/esm/utils.d.ts.map +1 -0
  73. package/dist/esm/utils.js +13 -0
  74. package/dist/esm/utils.js.map +1 -0
  75. package/dist/esm/utils.server.d.ts +9 -0
  76. package/dist/esm/utils.server.d.ts.map +1 -0
  77. package/dist/esm/utils.server.js +45 -0
  78. package/dist/esm/utils.server.js.map +1 -0
  79. package/package.json +221 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright.server.js","sourceRoot":"","sources":["../../src/playwright.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,UAAU,MAAM,aAAa,CAAA;AACpC,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEzD,MAAM,CAAC,KAAK,UAAU,qBAAqB;IAC1C,MAAM,IAAI,GAAG,CAAC,MAAM,OAAO,EAAE,CAAC;SAC5B,MAAM,CAAC,aAAa,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC9B,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAA;QAC5C,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,IAAI,CAAA;QAC7B,OAAO,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC1C,OAAO;gBACN,IAAI,EAAE,GAAG,QAAQ,GAAG,QAAQ,EAAE;gBAC9B,QAAQ;aACR,CAAA;QACF,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAA;AACpC,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAC9B,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,E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B,CAAC,CAAC,EAC5D,EAAE,OAAO,EAAE,MAAM,EAAE,CACnB,CAAA;gBACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;oBACjC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,EAAE;wBAC/D,OAAO,EAAE,MAAM;qBACf,CAAC;oBACF,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;wBAClD,OAAO,EAAE,MAAM;qBACf,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;wBAClB,MAAM,MAAM,CAAA;oBACb,CAAC,CAAC;iBACF,CAAC,CAAA;gBACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;YACzC,CAAC,CAAC,CAAA;QACH,CAAC;IACF,CAAC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { expect, test } from '@playwright/test'\nimport crossSpawn from 'cross-spawn'\nimport z from 'zod'\nimport { getApps, isSolutionApp } from './apps.server.js'\n\nexport async function getInBrowserTestPages() {\n\tconst apps = (await getApps())\n\t\t.filter(isSolutionApp)\n\t\t.filter((a) => a.test.type === 'browser')\n\tconst pages = apps.map((app) => {\n\t\tif (app.test.type !== 'browser') return null\n\t\tconst { pathname } = app.test\n\t\treturn app.test.testFiles.map((testFile) => {\n\t\t\treturn {\n\t\t\t\tpath: `${pathname}${testFile}`,\n\t\t\t\ttestFile,\n\t\t\t}\n\t\t})\n\t})\n\treturn pages.filter(Boolean).flat()\n}\n\nconst sleep = (time: number) =>\n\tnew Promise((resolve) => setTimeout(resolve, time))\n\nasync function waitFor<ReturnValue>(\n\tcb: () => ReturnValue | Promise<ReturnValue> | undefined | null,\n\t{ timeout = 1000, interval = 30 } = {},\n) {\n\tconst timeEnd = Date.now() + timeout\n\tlet lastError: unknown | null = null\n\twhile (Date.now() < timeEnd) {\n\t\ttry {\n\t\t\tconst result = await cb()\n\t\t\tif (result) return result\n\t\t} catch (error) {\n\t\t\tlastError = error\n\t\t}\n\t\tawait sleep(interval)\n\t}\n\tthrow lastError || new Error(`waitFor timed out after ${timeout}ms`)\n}\n\nexport function setupInBrowserTests() {\n\t// doing this because playwright needs the tests to be registered synchoronously\n\tconst code = `import('@epic-web/workshop-utils/playwright.server').then(({ getInBrowserTestPages }) => getInBrowserTestPages().then(r => console.log(JSON.stringify(r)))).catch(e => {console.error(e);throw e;})`\n\tconst result = crossSpawn.sync('node', ['--eval', code], {\n\t\tencoding: 'utf-8',\n\t})\n\tif (result.status !== 0) {\n\t\tconsole.error(result.output.join('\\n'))\n\t\tthrow new Error(\n\t\t\t`Failed to get in-browser test pages. Status: ${result.status}.`,\n\t\t)\n\t}\n\tconst testPages = z\n\t\t.array(z.object({ path: z.string() }))\n\t\t.parse(JSON.parse(result.stdout))\n\n\ttest.describe.parallel('in-browser tests', () => {\n\t\tfor (const testPage of testPages) {\n\t\t\ttest(testPage.path, async ({ page }) => {\n\t\t\t\tconst errors: Array<string> = []\n\t\t\t\tconst logs: Array<string> = []\n\t\t\t\tconst infos: Array<string> = []\n\t\t\t\tpage.on('console', (message) => {\n\t\t\t\t\tswitch (message.type()) {\n\t\t\t\t\t\tcase 'error': {\n\t\t\t\t\t\t\terrors.push(message.text())\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'log': {\n\t\t\t\t\t\t\tlogs.push(message.text())\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'info': {\n\t\t\t\t\t\t\tinfos.push(message.text())\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\tawait page.goto(testPage.path)\n\t\t\t\tawait page.waitForLoadState()\n\t\t\t\tawait waitFor(\n\t\t\t\t\t() => infos.find((info) => info.includes('status: pending')),\n\t\t\t\t\t{ timeout: 10_000 },\n\t\t\t\t)\n\t\t\t\tconst result = await Promise.race([\n\t\t\t\t\twaitFor(() => logs.find((log) => log.includes('status: pass')), {\n\t\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t\t}),\n\t\t\t\t\twaitFor(() => (errors.length > 0 ? errors : null), {\n\t\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t\t}).then((errors) => {\n\t\t\t\t\t\tthrow errors\n\t\t\t\t\t}),\n\t\t\t\t])\n\t\t\t\texpect(result).toContain('status: pass')\n\t\t\t})\n\t\t}\n\t})\n}\n"]}
@@ -0,0 +1,77 @@
1
+ import { type ChildProcess } from 'child_process';
2
+ import closeWithGrace from 'close-with-grace';
3
+ import { type App } from './apps.server.js';
4
+ type DevProcessesMap = Map<string, {
5
+ color: (typeof colors)[number];
6
+ process: ChildProcess;
7
+ port: number;
8
+ }>;
9
+ type OutputLine = {
10
+ type: 'stdout' | 'stderr';
11
+ content: string;
12
+ timestamp: number;
13
+ };
14
+ type TestProcessEntry = {
15
+ process: ChildProcess | null;
16
+ output: Array<OutputLine>;
17
+ exitCode?: number | null;
18
+ };
19
+ type TestProcessesMap = Map<string, TestProcessEntry>;
20
+ declare global {
21
+ var __process_dev_close_with_grace_return__: ReturnType<typeof closeWithGrace>, __process_test_close_with_grace_return__: ReturnType<typeof closeWithGrace>;
22
+ }
23
+ declare const colors: readonly ["blue", "green", "yellow", "red", "magenta", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright"];
24
+ export declare function runAppDev(app: App): Promise<{
25
+ readonly status: "process-running";
26
+ readonly running: true;
27
+ readonly error?: undefined;
28
+ readonly portNumber?: undefined;
29
+ } | {
30
+ readonly status: "error";
31
+ readonly error: "no-server";
32
+ readonly running?: undefined;
33
+ readonly portNumber?: undefined;
34
+ } | {
35
+ readonly status: "port-unavailable";
36
+ readonly running: false;
37
+ readonly portNumber: number;
38
+ readonly error?: undefined;
39
+ } | {
40
+ readonly status: "process-started";
41
+ readonly running: true;
42
+ readonly error?: undefined;
43
+ readonly portNumber?: undefined;
44
+ }>;
45
+ export declare function runAppTests(app: App): Promise<import("child_process").ChildProcessByStdio<null, import("stream").Readable, import("stream").Readable> | {
46
+ readonly status: "error";
47
+ readonly error: "no-test";
48
+ }>;
49
+ export declare function waitOnApp(app: App): Promise<{
50
+ readonly status: "success";
51
+ readonly error?: undefined;
52
+ } | {
53
+ readonly status: "error";
54
+ readonly error: string;
55
+ } | null>;
56
+ export declare function isPortAvailable(port: number | string): Promise<boolean>;
57
+ export declare function isAppRunning(app: {
58
+ name: string;
59
+ }): Promise<boolean>;
60
+ export declare function isTestRunning(app: {
61
+ name: string;
62
+ }): boolean;
63
+ export declare function getTestProcessEntry(app: {
64
+ name: string;
65
+ }): TestProcessEntry | undefined;
66
+ export declare function clearTestProcessEntry(app: {
67
+ name: string;
68
+ }): boolean;
69
+ export declare function getProcesses(): {
70
+ devProcesses: DevProcessesMap;
71
+ testProcesses: TestProcessesMap;
72
+ };
73
+ export declare function closeProcess(key: string): Promise<void>;
74
+ export declare function stopPort(port: string | number): Promise<void>;
75
+ export declare function waitForPortToBeAvailable(port: string | number): Promise<void>;
76
+ export {};
77
+ //# sourceMappingURL=process-manager.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-manager.server.d.ts","sourceRoot":"","sources":["../../src/process-manager.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAIxD,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAG7C,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAO3C,KAAK,eAAe,GAAG,GAAG,CACzB,MAAM,EACN;IACC,KAAK,EAAE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AAgB,qBAAqB,CAAC,GAAG,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,WAE1D;AAED,wBAAgB,YAAY;;;EAE3B;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,iBAoB7C;AAID,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,iBAInD;AAED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,iBAWnE"}
@@ -0,0 +1,266 @@
1
+ import { spawn } from 'child_process';
2
+ import net from 'node:net';
3
+ import { remember } from '@epic-web/remember';
4
+ import chalk from 'chalk';
5
+ import closeWithGrace from 'close-with-grace';
6
+ import findProcess from 'find-process';
7
+ import fkill from 'fkill';
8
+ import { getErrorMessage } from './utils.js';
9
+ const isDeployed = process.env.EPICSHOP_DEPLOYED === 'true' ||
10
+ process.env.EPICSHOP_DEPLOYED === '1';
11
+ const devProcesses = remember('dev_processes', getDevProcessesMap);
12
+ const testProcesses = remember('test_processes', getTestProcessesMap);
13
+ function getDevProcessesMap() {
14
+ const procs = new Map();
15
+ global.__process_dev_close_with_grace_return__?.uninstall();
16
+ global.__process_dev_close_with_grace_return__ = closeWithGrace(async () => {
17
+ for (const [name, proc] of procs.entries()) {
18
+ console.log('closing', name);
19
+ proc.process.kill();
20
+ }
21
+ });
22
+ return procs;
23
+ }
24
+ function getTestProcessesMap() {
25
+ const procs = new Map();
26
+ global.__process_test_close_with_grace_return__?.uninstall();
27
+ global.__process_test_close_with_grace_return__ = closeWithGrace(async () => {
28
+ for (const [id, proc] of procs.entries()) {
29
+ if (proc.process) {
30
+ console.log('closing', id);
31
+ proc.process.kill();
32
+ }
33
+ }
34
+ });
35
+ return procs;
36
+ }
37
+ const colors = [
38
+ 'blue',
39
+ 'green',
40
+ 'yellow',
41
+ 'red',
42
+ 'magenta',
43
+ 'redBright',
44
+ 'greenBright',
45
+ 'yellowBright',
46
+ 'blueBright',
47
+ 'magentaBright',
48
+ ];
49
+ export async function runAppDev(app) {
50
+ if (isDeployed)
51
+ throw new Error('cannot run apps in deployed mode');
52
+ const key = app.name;
53
+ // if the app is already running, don't start it again
54
+ if (devProcesses.has(key)) {
55
+ return { status: 'process-running', running: true };
56
+ }
57
+ if (app.dev.type !== 'script') {
58
+ return { status: 'error', error: 'no-server' };
59
+ }
60
+ const { portNumber } = app.dev;
61
+ if (!(await isPortAvailable(portNumber))) {
62
+ return { status: 'port-unavailable', running: false, portNumber };
63
+ }
64
+ const availableColors = colors.filter((color) => Array.from(devProcesses.values()).every((p) => p.color !== color));
65
+ const color = availableColors[devProcesses.size % availableColors.length] ?? 'blue';
66
+ const appProcess = spawn('npm', ['run', 'dev', '--silent'], {
67
+ cwd: app.fullPath,
68
+ shell: true,
69
+ stdio: ['ignore', 'pipe', 'pipe'],
70
+ env: {
71
+ ...process.env,
72
+ // TODO: support specifying the env
73
+ NODE_ENV: 'development',
74
+ // TODO: support specifying the port
75
+ PORT: String(portNumber),
76
+ APP_SERVER_PORT: String(portNumber),
77
+ // let it pick a random port...
78
+ REMIX_DEV_SERVER_WS_PORT: '',
79
+ },
80
+ });
81
+ const prefix = chalk[color](`[${app.name.replace(/^exercises\./, '')}:${portNumber}]`);
82
+ function handleStdOutData(data) {
83
+ console.log(data
84
+ .toString('utf-8')
85
+ .split('\n')
86
+ .map((line) => `${prefix} ${line}`)
87
+ .join('\n'));
88
+ }
89
+ appProcess.stdout.on('data', handleStdOutData);
90
+ function handleStdErrData(data) {
91
+ console.error(data
92
+ .toString('utf-8')
93
+ .split('\n')
94
+ .map((line) => `${prefix} ${line}`)
95
+ .join('\n'));
96
+ }
97
+ appProcess.stderr.on('data', handleStdErrData);
98
+ devProcesses.set(key, { color, process: appProcess, port: portNumber });
99
+ appProcess.on('exit', (code) => {
100
+ appProcess.stdout.off('data', handleStdOutData);
101
+ appProcess.stderr.off('data', handleStdErrData);
102
+ console.log(`${prefix} exited (${code})`);
103
+ devProcesses.delete(key);
104
+ });
105
+ return { status: 'process-started', running: true };
106
+ }
107
+ export async function runAppTests(app) {
108
+ if (isDeployed)
109
+ throw new Error('cannot run tests in deployed mode');
110
+ const key = app.name;
111
+ if (app.test.type !== 'script') {
112
+ return { status: 'error', error: 'no-test' };
113
+ }
114
+ const testProcess = spawn('npm', ['run', 'test', '--silent'], {
115
+ cwd: app.fullPath,
116
+ shell: true,
117
+ stdio: ['ignore', 'pipe', 'pipe'],
118
+ env: {
119
+ ...process.env,
120
+ // TODO: support specifying the env
121
+ NODE_ENV: 'development',
122
+ // TODO: support specifying the port
123
+ PORT: app.dev.type === 'script' ? String(app.dev.portNumber) : undefined,
124
+ APP_SERVER_PORT: app.dev.type === 'script' ? String(app.dev.portNumber) : undefined,
125
+ // let it pick a random port...
126
+ REMIX_DEV_SERVER_WS_PORT: '',
127
+ },
128
+ });
129
+ const output = [];
130
+ const entry = { process: testProcess, output };
131
+ function handleStdOutData(data) {
132
+ output.push({
133
+ type: 'stdout',
134
+ content: data.toString('utf-8'),
135
+ timestamp: Date.now(),
136
+ });
137
+ }
138
+ testProcess.stdout.on('data', handleStdOutData);
139
+ function handleStdErrData(data) {
140
+ output.push({
141
+ type: 'stderr',
142
+ content: data.toString('utf-8'),
143
+ timestamp: Date.now(),
144
+ });
145
+ }
146
+ testProcess.stderr.on('data', handleStdErrData);
147
+ testProcess.on('exit', (code) => {
148
+ testProcess.stdout.off('data', handleStdOutData);
149
+ testProcess.stderr.off('data', handleStdErrData);
150
+ entry.process = null;
151
+ entry.exitCode = code;
152
+ });
153
+ testProcesses.set(key, entry);
154
+ return testProcess;
155
+ }
156
+ export async function waitOnApp(app) {
157
+ if (app.dev.type === 'script') {
158
+ const startTime = Date.now();
159
+ const retryInterval = 100;
160
+ const timeout = 20_000;
161
+ let lastError;
162
+ while (Date.now() - startTime < timeout) {
163
+ try {
164
+ await fetch(`http://localhost:${app.dev.portNumber}`, {
165
+ method: 'HEAD',
166
+ headers: { Accept: '*/*' },
167
+ });
168
+ return { status: 'success' };
169
+ }
170
+ catch (error) {
171
+ lastError = error;
172
+ await new Promise((resolve) => setTimeout(resolve, retryInterval));
173
+ }
174
+ }
175
+ return { status: 'error', error: getErrorMessage(lastError) };
176
+ }
177
+ return null;
178
+ }
179
+ export function isPortAvailable(port) {
180
+ return new Promise((resolve) => {
181
+ const server = net.createServer();
182
+ server.unref();
183
+ server.on('error', () => resolve(false));
184
+ server.listen(Number(port), () => {
185
+ server.close(() => {
186
+ resolve(true);
187
+ });
188
+ });
189
+ });
190
+ }
191
+ export async function isAppRunning(app) {
192
+ try {
193
+ const devProcess = devProcesses.get(app.name);
194
+ if (!devProcess?.process.pid)
195
+ return false;
196
+ const found = await findProcess('pid', devProcess.process.pid);
197
+ return found.length > 0;
198
+ }
199
+ catch {
200
+ return false;
201
+ }
202
+ }
203
+ export function isTestRunning(app) {
204
+ try {
205
+ const testProcess = testProcesses.get(app.name);
206
+ if (!testProcess)
207
+ return false;
208
+ if (testProcess.process === null)
209
+ return false;
210
+ testProcess.process.kill(0);
211
+ return true;
212
+ }
213
+ catch {
214
+ return false;
215
+ }
216
+ }
217
+ export function getTestProcessEntry(app) {
218
+ return testProcesses.get(app.name);
219
+ }
220
+ export function clearTestProcessEntry(app) {
221
+ return testProcesses.delete(app.name);
222
+ }
223
+ export function getProcesses() {
224
+ return { devProcesses, testProcesses };
225
+ }
226
+ export async function closeProcess(key) {
227
+ if (isDeployed)
228
+ throw new Error('cannot close processes in deployed mode');
229
+ const proc = devProcesses.get(key);
230
+ if (proc) {
231
+ const exitedPromise = new Promise((resolve) => proc.process.on('exit', resolve));
232
+ if (process.platform === 'win32') {
233
+ const { execa } = await import('execa');
234
+ await execa('taskkill', ['/pid', String(proc.process.pid), '/f', '/t']);
235
+ }
236
+ else {
237
+ proc.process.kill();
238
+ }
239
+ await Promise.race([
240
+ new Promise((resolve) => setTimeout(resolve, 500)),
241
+ exitedPromise,
242
+ ]);
243
+ await stopPort(proc.port); // just in case 🤷‍♂️
244
+ devProcesses.delete(key);
245
+ }
246
+ }
247
+ const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t));
248
+ export async function stopPort(port) {
249
+ if (isDeployed)
250
+ throw new Error('cannot stop ports in deployed mode');
251
+ await fkill(`:${port}`, { force: true, silent: true });
252
+ await waitForPortToBeAvailable(port);
253
+ }
254
+ export async function waitForPortToBeAvailable(port) {
255
+ // wait for the port to become available again
256
+ const timeout = Date.now() + 10_000;
257
+ let portAvailable = false;
258
+ do {
259
+ portAvailable = await isPortAvailable(port);
260
+ await sleep(100);
261
+ } while (!portAvailable && Date.now() < timeout);
262
+ if (!portAvailable) {
263
+ console.error('Timed out waiting for the port to become available');
264
+ }
265
+ }
266
+ //# sourceMappingURL=process-manager.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-manager.server.js","sourceRoot":"","sources":["../../src/process-manager.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAA;AACxD,OAAO,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,UAAU,GACf,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM;IACxC,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,GAAG,CAAA;AA+BtC,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAA;AAClE,MAAM,aAAa,GAAG,QAAQ,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAA;AAErE,SAAS,kBAAkB;IAC1B,MAAM,KAAK,GAAoB,IAAI,GAAG,EAAE,CAAA;IAExC,MAAM,CAAC,uC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D,IAAI,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACrE,MAAM,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IACtD,MAAM,wBAAwB,CAAC,IAAI,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,IAAqB;IACnE,8CAA8C;IAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAA;IACnC,IAAI,aAAa,GAAG,KAAK,CAAA;IACzB,GAAG,CAAC;QACH,aAAa,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAA;QAC3C,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;IACjB,CAAC,QAAQ,CAAC,aAAa,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAC;IAChD,IAAI,CAAC,aAAa,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACpE,CAAC;AACF,CAAC","sourcesContent":["import { spawn, type ChildProcess } from 'child_process'\nimport net from 'node:net'\nimport { remember } from '@epic-web/remember'\nimport chalk from 'chalk'\nimport closeWithGrace from 'close-with-grace'\nimport findProcess from 'find-process'\nimport fkill from 'fkill'\nimport { type App } from './apps.server.js'\nimport { getErrorMessage } from './utils.js'\n\nconst isDeployed =\n\tprocess.env.EPICSHOP_DEPLOYED === 'true' ||\n\tprocess.env.EPICSHOP_DEPLOYED === '1'\n\ntype DevProcessesMap = Map<\n\tstring,\n\t{\n\t\tcolor: (typeof colors)[number]\n\t\tprocess: ChildProcess\n\t\tport: number\n\t}\n>\n\ntype OutputLine = {\n\ttype: 'stdout' | 'stderr'\n\tcontent: string\n\ttimestamp: number\n}\n\ntype TestProcessEntry = {\n\tprocess: ChildProcess | null\n\toutput: Array<OutputLine>\n\texitCode?: number | null\n}\n\ntype TestProcessesMap = Map<string, TestProcessEntry>\ndeclare global {\n\tvar __process_dev_close_with_grace_return__: ReturnType<\n\t\t\ttypeof closeWithGrace\n\t\t>,\n\t\t__process_test_close_with_grace_return__: ReturnType<typeof closeWithGrace>\n}\n\nconst devProcesses = remember('dev_processes', getDevProcessesMap)\nconst testProcesses = remember('test_processes', getTestProcessesMap)\n\nfunction getDevProcessesMap() {\n\tconst procs: DevProcessesMap = new Map()\n\n\tglobal.__process_dev_close_with_grace_return__?.uninstall()\n\n\tglobal.__process_dev_close_with_grace_return__ = closeWithGrace(async () => {\n\t\tfor (const [name, proc] of procs.entries()) {\n\t\t\tconsole.log('closing', name)\n\t\t\tproc.process.kill()\n\t\t}\n\t})\n\treturn procs\n}\n\nfunction getTestProcessesMap() {\n\tconst procs: TestProcessesMap = new Map()\n\n\tglobal.__process_test_close_with_grace_return__?.uninstall()\n\n\tglobal.__process_test_close_with_grace_return__ = closeWithGrace(async () => {\n\t\tfor (const [id, proc] of procs.entries()) {\n\t\t\tif (proc.process) {\n\t\t\t\tconsole.log('closing', id)\n\t\t\t\tproc.process.kill()\n\t\t\t}\n\t\t}\n\t})\n\treturn procs\n}\n\nconst colors = [\n\t'blue',\n\t'green',\n\t'yellow',\n\t'red',\n\t'magenta',\n\t'redBright',\n\t'greenBright',\n\t'yellowBright',\n\t'blueBright',\n\t'magentaBright',\n] as const\n\nexport async function runAppDev(app: App) {\n\tif (isDeployed) throw new Error('cannot run apps in deployed mode')\n\tconst key = app.name\n\t// if the app is already running, don't start it again\n\tif (devProcesses.has(key)) {\n\t\treturn { status: 'process-running', running: true } as const\n\t}\n\n\tif (app.dev.type !== 'script') {\n\t\treturn { status: 'error', error: 'no-server' } as const\n\t}\n\n\tconst { portNumber } = app.dev\n\tif (!(await isPortAvailable(portNumber))) {\n\t\treturn { status: 'port-unavailable', running: false, portNumber } as const\n\t}\n\tconst availableColors = colors.filter((color) =>\n\t\tArray.from(devProcesses.values()).every((p) => p.color !== color),\n\t)\n\tconst color =\n\t\tavailableColors[devProcesses.size % availableColors.length] ?? 'blue'\n\tconst appProcess = spawn('npm', ['run', 'dev', '--silent'], {\n\t\tcwd: app.fullPath,\n\t\tshell: true,\n\t\tstdio: ['ignore', 'pipe', 'pipe'],\n\t\tenv: {\n\t\t\t...process.env,\n\t\t\t// TODO: support specifying the env\n\t\t\tNODE_ENV: 'development',\n\t\t\t// TODO: support specifying the port\n\t\t\tPORT: String(portNumber),\n\t\t\tAPP_SERVER_PORT: String(portNumber),\n\t\t\t// let it pick a random port...\n\t\t\tREMIX_DEV_SERVER_WS_PORT: '',\n\t\t},\n\t})\n\tconst prefix = chalk[color](\n\t\t`[${app.name.replace(/^exercises\\./, '')}:${portNumber}]`,\n\t)\n\tfunction handleStdOutData(data: Buffer) {\n\t\tconsole.log(\n\t\t\tdata\n\t\t\t\t.toString('utf-8')\n\t\t\t\t.split('\\n')\n\t\t\t\t.map((line) => `${prefix} ${line}`)\n\t\t\t\t.join('\\n'),\n\t\t)\n\t}\n\tappProcess.stdout.on('data', handleStdOutData)\n\tfunction handleStdErrData(data: Buffer) {\n\t\tconsole.error(\n\t\t\tdata\n\t\t\t\t.toString('utf-8')\n\t\t\t\t.split('\\n')\n\t\t\t\t.map((line) => `${prefix} ${line}`)\n\t\t\t\t.join('\\n'),\n\t\t)\n\t}\n\tappProcess.stderr.on('data', handleStdErrData)\n\tdevProcesses.set(key, { color, process: appProcess, port: portNumber })\n\tappProcess.on('exit', (code) => {\n\t\tappProcess.stdout.off('data', handleStdOutData)\n\t\tappProcess.stderr.off('data', handleStdErrData)\n\t\tconsole.log(`${prefix} exited (${code})`)\n\t\tdevProcesses.delete(key)\n\t})\n\n\treturn { status: 'process-started', running: true } as const\n}\n\nexport async function runAppTests(app: App) {\n\tif (isDeployed) throw new Error('cannot run tests in deployed mode')\n\tconst key = app.name\n\n\tif (app.test.type !== 'script') {\n\t\treturn { status: 'error', error: 'no-test' } as const\n\t}\n\n\tconst testProcess = spawn('npm', ['run', 'test', '--silent'], {\n\t\tcwd: app.fullPath,\n\t\tshell: true,\n\t\tstdio: ['ignore', 'pipe', 'pipe'],\n\t\tenv: {\n\t\t\t...process.env,\n\t\t\t// TODO: support specifying the env\n\t\t\tNODE_ENV: 'development',\n\t\t\t// TODO: support specifying the port\n\t\t\tPORT: app.dev.type === 'script' ? String(app.dev.portNumber) : undefined,\n\t\t\tAPP_SERVER_PORT:\n\t\t\t\tapp.dev.type === 'script' ? String(app.dev.portNumber) : undefined,\n\t\t\t// let it pick a random port...\n\t\t\tREMIX_DEV_SERVER_WS_PORT: '',\n\t\t},\n\t})\n\tconst output: Array<OutputLine> = []\n\tconst entry: TestProcessEntry = { process: testProcess, output }\n\tfunction handleStdOutData(data: Buffer) {\n\t\toutput.push({\n\t\t\ttype: 'stdout',\n\t\t\tcontent: data.toString('utf-8'),\n\t\t\ttimestamp: Date.now(),\n\t\t})\n\t}\n\ttestProcess.stdout.on('data', handleStdOutData)\n\tfunction handleStdErrData(data: Buffer) {\n\t\toutput.push({\n\t\t\ttype: 'stderr',\n\t\t\tcontent: data.toString('utf-8'),\n\t\t\ttimestamp: Date.now(),\n\t\t})\n\t}\n\ttestProcess.stderr.on('data', handleStdErrData)\n\ttestProcess.on('exit', (code) => {\n\t\ttestProcess.stdout.off('data', handleStdOutData)\n\t\ttestProcess.stderr.off('data', handleStdErrData)\n\t\tentry.process = null\n\t\tentry.exitCode = code\n\t})\n\ttestProcesses.set(key, entry)\n\treturn testProcess\n}\n\nexport async function waitOnApp(app: App) {\n\tif (app.dev.type === 'script') {\n\t\tconst startTime = Date.now()\n\n\t\tconst retryInterval = 100\n\t\tconst timeout = 20_000\n\t\tlet lastError: unknown\n\t\twhile (Date.now() - startTime < timeout) {\n\t\t\ttry {\n\t\t\t\tawait fetch(`http://localhost:${app.dev.portNumber}`, {\n\t\t\t\t\tmethod: 'HEAD',\n\t\t\t\t\theaders: { Accept: '*/*' },\n\t\t\t\t})\n\t\t\t\treturn { status: 'success' } as const\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, retryInterval))\n\t\t\t}\n\t\t}\n\n\t\treturn { status: 'error', error: getErrorMessage(lastError) } as const\n\t}\n\treturn null\n}\n\nexport function isPortAvailable(port: number | string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst server = net.createServer()\n\t\tserver.unref()\n\t\tserver.on('error', () => resolve(false))\n\n\t\tserver.listen(Number(port), () => {\n\t\t\tserver.close(() => {\n\t\t\t\tresolve(true)\n\t\t\t})\n\t\t})\n\t})\n}\n\nexport async function isAppRunning(app: { name: string }) {\n\ttry {\n\t\tconst devProcess = devProcesses.get(app.name)\n\t\tif (!devProcess?.process.pid) return false\n\t\tconst found = await findProcess('pid', devProcess.process.pid)\n\t\treturn found.length > 0\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport function isTestRunning(app: { name: string }) {\n\ttry {\n\t\tconst testProcess = testProcesses.get(app.name)\n\t\tif (!testProcess) return false\n\t\tif (testProcess.process === null) return false\n\t\ttestProcess.process.kill(0)\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport function getTestProcessEntry(app: { name: string }) {\n\treturn testProcesses.get(app.name)\n}\n\nexport function clearTestProcessEntry(app: { name: string }) {\n\treturn testProcesses.delete(app.name)\n}\n\nexport function getProcesses() {\n\treturn { devProcesses, testProcesses }\n}\n\nexport async function closeProcess(key: string) {\n\tif (isDeployed) throw new Error('cannot close processes in deployed mode')\n\tconst proc = devProcesses.get(key)\n\tif (proc) {\n\t\tconst exitedPromise = new Promise((resolve) =>\n\t\t\tproc.process.on('exit', resolve),\n\t\t)\n\t\tif (process.platform === 'win32') {\n\t\t\tconst { execa } = await import('execa')\n\t\t\tawait execa('taskkill', ['/pid', String(proc.process.pid), '/f', '/t'])\n\t\t} else {\n\t\t\tproc.process.kill()\n\t\t}\n\t\tawait Promise.race([\n\t\t\tnew Promise((resolve) => setTimeout(resolve, 500)),\n\t\t\texitedPromise,\n\t\t])\n\t\tawait stopPort(proc.port) // just in case 🤷‍♂️\n\t\tdevProcesses.delete(key)\n\t}\n}\n\nconst sleep = (t: number) => new Promise((resolve) => setTimeout(resolve, t))\n\nexport async function stopPort(port: string | number) {\n\tif (isDeployed) throw new Error('cannot stop ports in deployed mode')\n\tawait fkill(`:${port}`, { force: true, silent: true })\n\tawait waitForPortToBeAvailable(port)\n}\n\nexport async function waitForPortToBeAvailable(port: string | number) {\n\t// wait for the port to become available again\n\tconst timeout = Date.now() + 10_000\n\tlet portAvailable = false\n\tdo {\n\t\tportAvailable = await isPortAvailable(port)\n\t\tawait sleep(100)\n\t} while (!portAvailable && Date.now() < timeout)\n\tif (!portAvailable) {\n\t\tconsole.error('Timed out waiting for the port to become available')\n\t}\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import * as dtl from '@testing-library/dom';
2
+ import * as matchers from '@testing-library/jest-dom/matchers';
3
+ import { type ExpectStatic } from '@vitest/expect';
4
+ declare module '@vitest/expect' {
5
+ interface JestAssertion<T = any> extends matchers.TestingLibraryMatchers<ReturnType<typeof expect.stringContaining>, T> {
6
+ }
7
+ }
8
+ export declare const expect: ExpectStatic;
9
+ export { dtl };
10
+ export declare function testStep<ReturnValue>(title: string | ((result: {
11
+ type: 'fail';
12
+ error: Error;
13
+ } | {
14
+ type: 'pass';
15
+ }) => string), get: (() => ReturnValue) | (() => Promise<ReturnValue>)): Promise<ReturnValue>;
16
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAA;AAC9D,OAAO,EAIN,KAAK,YAAY,EACjB,MAAM,gBAAgB,CAAA;AAiBvB,OAAO,QAAQ,gBAAgB,CAAC;IAC/B,UAAU,aAAa,CAAC,CAAC,GAAG,GAAG,CAC9B,SAAQ,QAAQ,CAAC,sBAAsB,CACtC,UAAU,CAAC,OAAO,MAAM,CAAC,gBAAgB,CAAC,EAC1C,CAAC,CACD;KAAG;CACL;AAOD,eAAO,MAAM,MAAM,EAAkB,YAAY,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,CAAA;AAWd,wBAAsB,QAAQ,CAAC,WAAW,EACzC,KAAK,EACF,MAAM,GACN,CAAC,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,CAAC,EAC1E,GAAG,EAAE,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,GACrD,OAAO,CAAC,WAAW,CAAC,CAmCtB"}
@@ -0,0 +1,56 @@
1
+ import * as dtl from '@testing-library/dom';
2
+ import * as matchers from '@testing-library/jest-dom/matchers';
3
+ import { JestAsymmetricMatchers, JestChaiExpect, JestExtend, } from '@vitest/expect';
4
+ import * as chai from 'chai';
5
+ import chaiDOM from 'chai-dom';
6
+ // allows using expect.extend instead of chai.use to extend plugins
7
+ chai.use(JestExtend);
8
+ // adds all jest matchers to expect
9
+ chai.use(JestChaiExpect);
10
+ // adds asymmetric matchers like stringContaining, objectContaining
11
+ chai.use(JestAsymmetricMatchers);
12
+ chai.use(chaiDOM);
13
+ chai.expect.extend(chai.expect, matchers);
14
+ // in the browser logging out the element is not necessary
15
+ dtl.configure({
16
+ getElementError: (message) => new Error(message ?? 'Unknown error'),
17
+ });
18
+ export const expect = chai.expect;
19
+ export { dtl };
20
+ function isError(maybeError) {
21
+ return (maybeError &&
22
+ typeof maybeError === 'object' &&
23
+ 'message' in maybeError &&
24
+ typeof maybeError.message === 'string');
25
+ }
26
+ export async function testStep(title, get) {
27
+ try {
28
+ const result = await get();
29
+ const titleString = typeof title === 'function' ? title({ type: 'pass' }) : title;
30
+ if (window.parent === window) {
31
+ console.log(`✅ ${titleString}`);
32
+ }
33
+ else {
34
+ window.parent.postMessage({
35
+ type: 'epicshop:test-step-update',
36
+ status: 'pass',
37
+ title: titleString,
38
+ timestamp: Date.now(),
39
+ }, '*');
40
+ }
41
+ return result;
42
+ }
43
+ catch (caughtError) {
44
+ const error = isError(caughtError)
45
+ ? caughtError
46
+ : new Error(typeof caughtError === 'string' ? caughtError : 'Unknown error', { cause: caughtError });
47
+ const titleString = typeof title === 'function' ? title({ type: 'fail', error }) : title;
48
+ if (window.parent === window) {
49
+ console.error(`❌ ${titleString}`);
50
+ console.error(error.message);
51
+ }
52
+ error.message = `${titleString}${error.message ? `\n\n${error.message}` : ''}`;
53
+ throw error;
54
+ }
55
+ }
56
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAA;AAC9D,OAAO,EACN,sBAAsB,EACtB,cAAc,EACd,UAAU,GAEV,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,OAAO,MAAM,UAAU,CAAA;AAE9B,mEAAmE;AACnE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;AACpB,mCAAmC;AACnC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;AACxB,mEAAmE;AACnE,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AAEhC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAKhB;AAAC,IAAI,CAAC,MAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAS5D,0DAA0D;AAC1D,GAAG,CAAC,SAAS,CAAC;IACb,eAAe,EAAE,CAAC,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,KAAK,EAAE,WAAW,EAAE,CACtB,CAAA;QACH,MAAM,WAAW,GAChB,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QACrE,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,WAAW,EAAE,CAAC,CAAA;YACjC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;QACD,KAAK,CAAC,OAAO,GAAG,GAAG,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;QAC9E,MAAM,KAAK,CAAA;IACZ,CAAC;AACF,CAAC","sourcesContent":["import * as dtl from '@testing-library/dom'\nimport * as matchers from '@testing-library/jest-dom/matchers'\nimport {\n\tJestAsymmetricMatchers,\n\tJestChaiExpect,\n\tJestExtend,\n\ttype ExpectStatic,\n} from '@vitest/expect'\nimport * as chai from 'chai'\nimport chaiDOM from 'chai-dom'\n\n// allows using expect.extend instead of chai.use to extend plugins\nchai.use(JestExtend)\n// adds all jest matchers to expect\nchai.use(JestChaiExpect)\n// adds asymmetric matchers like stringContaining, objectContaining\nchai.use(JestAsymmetricMatchers)\n\nchai.use(chaiDOM)\n\n// @ts-expect-error weird typescript nonsense\n// I *think* vitest is using the extend API wrong or something 🤷‍♂️\n// this works though so...\n;(chai.expect as ExpectStatic).extend(chai.expect, matchers)\ndeclare module '@vitest/expect' {\n\tinterface JestAssertion<T = any>\n\t\textends matchers.TestingLibraryMatchers<\n\t\t\tReturnType<typeof expect.stringContaining>,\n\t\t\tT\n\t\t> {}\n}\n\n// in the browser logging out the element is not necessary\ndtl.configure({\n\tgetElementError: (message) => new Error(message ?? 'Unknown error'),\n})\n\nexport const expect = chai.expect as ExpectStatic\nexport { dtl }\n\nfunction isError(maybeError: any): maybeError is Error {\n\treturn (\n\t\tmaybeError &&\n\t\ttypeof maybeError === 'object' &&\n\t\t'message' in maybeError &&\n\t\ttypeof maybeError.message === 'string'\n\t)\n}\n\nexport async function testStep<ReturnValue>(\n\ttitle:\n\t\t| string\n\t\t| ((result: { type: 'fail'; error: Error } | { type: 'pass' }) => string),\n\tget: (() => ReturnValue) | (() => Promise<ReturnValue>),\n): Promise<ReturnValue> {\n\ttry {\n\t\tconst result = await get()\n\t\tconst titleString =\n\t\t\ttypeof title === 'function' ? title({ type: 'pass' }) : title\n\t\tif (window.parent === window) {\n\t\t\tconsole.log(`✅ ${titleString}`)\n\t\t} else {\n\t\t\twindow.parent.postMessage(\n\t\t\t\t{\n\t\t\t\t\ttype: 'epicshop:test-step-update',\n\t\t\t\t\tstatus: 'pass',\n\t\t\t\t\ttitle: titleString,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t},\n\t\t\t\t'*',\n\t\t\t)\n\t\t}\n\t\treturn result\n\t} catch (caughtError: unknown) {\n\t\tconst error = isError(caughtError)\n\t\t\t? caughtError\n\t\t\t: new Error(\n\t\t\t\t\ttypeof caughtError === 'string' ? caughtError : 'Unknown error',\n\t\t\t\t\t{ cause: caughtError },\n\t\t\t\t)\n\t\tconst titleString =\n\t\t\ttypeof title === 'function' ? title({ type: 'fail', error }) : title\n\t\tif (window.parent === window) {\n\t\t\tconsole.error(`❌ ${titleString}`)\n\t\t\tconsole.error(error.message)\n\t\t}\n\t\terror.message = `${titleString}${error.message ? `\\n\\n${error.message}` : ''}`\n\t\tthrow error\n\t}\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { type CreateReporter } from '@epic-web/cachified';
2
+ export type Timings = Record<string, Array<{
3
+ desc?: string;
4
+ } & ({
5
+ time: number;
6
+ start?: never;
7
+ } | {
8
+ time?: never;
9
+ start: number;
10
+ })>>;
11
+ export declare function makeTimings(type: string, desc?: string): Timings;
12
+ export declare function time<ReturnType>(fn: Promise<ReturnType> | (() => ReturnType | Promise<ReturnType>), { type, desc, timings, }: {
13
+ type: string;
14
+ desc?: string;
15
+ timings?: Timings;
16
+ }): Promise<ReturnType>;
17
+ export declare function getServerTimeHeader(timings?: Timings): string;
18
+ export declare function combineServerTimings(headers1: Headers, headers2: Headers): string;
19
+ export declare function cachifiedTimingReporter<Value>(timings?: Timings, timingKey?: string): undefined | CreateReporter<Value>;
20
+ //# sourceMappingURL=timing.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.server.d.ts","sourceRoot":"","sources":["../../src/timing.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,MAAM,MAAM,OAAO,GAAG,MAAM,CAC3B,MAAM,EACN,KAAK,CACJ;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,CACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC/B;IAAE,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CACjC,CACD,CACD,CAAA;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,WAWtD;AAgBD,wBAAsB,IAAI,CAAC,UAAU,EACpC,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,EAClE,EACC,IAAI,EACJ,IAAI,EACJ,OAAO,GACP,EAAE;IACF,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,GACC,OAAO,CAAC,UAAU,CAAC,CASrB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,OAAO,UAuBpD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,UAIxE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAC5C,OAAO,CAAC,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,MAAM,GAChB,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,CA6BnC"}
@@ -0,0 +1,88 @@
1
+ export function makeTimings(type, desc) {
2
+ const timings = {
3
+ [type]: [{ desc, start: performance.now() }],
4
+ };
5
+ Object.defineProperty(timings, 'toString', {
6
+ value() {
7
+ return getServerTimeHeader(timings);
8
+ },
9
+ enumerable: false,
10
+ });
11
+ return timings;
12
+ }
13
+ function createTimer(type, desc) {
14
+ const start = performance.now();
15
+ return {
16
+ end(timings) {
17
+ let timingType = timings[type];
18
+ if (!timingType) {
19
+ timingType = timings[type] = [];
20
+ }
21
+ timingType.push({ desc, time: performance.now() - start });
22
+ },
23
+ };
24
+ }
25
+ export async function time(fn, { type, desc, timings, }) {
26
+ const timer = createTimer(type, desc);
27
+ const promise = typeof fn === 'function' ? fn() : fn;
28
+ if (!timings)
29
+ return promise;
30
+ const result = await promise;
31
+ timer.end(timings);
32
+ return result;
33
+ }
34
+ export function getServerTimeHeader(timings) {
35
+ if (!timings)
36
+ return '';
37
+ return Object.entries(timings)
38
+ .map(([key, timingInfos]) => {
39
+ const dur = timingInfos
40
+ .reduce((acc, timingInfo) => {
41
+ const time = timingInfo.time ?? performance.now() - timingInfo.start;
42
+ return acc + time;
43
+ }, 0)
44
+ .toFixed(1);
45
+ const desc = timingInfos
46
+ .map((t) => t.desc)
47
+ .filter(Boolean)
48
+ .join(' & ');
49
+ return [
50
+ key.replaceAll(/(:| |@|=|;|,|\/|\\|\{|\})/g, '_'),
51
+ desc ? `desc=${JSON.stringify(desc)}` : null,
52
+ `dur=${dur}`,
53
+ ]
54
+ .filter(Boolean)
55
+ .join(';');
56
+ })
57
+ .join(',');
58
+ }
59
+ export function combineServerTimings(headers1, headers2) {
60
+ const newHeaders = new Headers(headers1);
61
+ newHeaders.append('Server-Timing', headers2.get('Server-Timing') ?? '');
62
+ return newHeaders.get('Server-Timing') ?? '';
63
+ }
64
+ export function cachifiedTimingReporter(timings, timingKey) {
65
+ if (!timings)
66
+ return;
67
+ return ({ key }) => {
68
+ timingKey = timingKey ?? key;
69
+ const cacheRetrievalTimer = createTimer(`cache:${timingKey}`, `${timingKey} cache retrieval`);
70
+ let getFreshValueTimer;
71
+ return (event) => {
72
+ switch (event.name) {
73
+ case 'getFreshValueStart':
74
+ getFreshValueTimer = createTimer(`getFreshValue:${timingKey}`, `request forced to wait for a fresh ${timingKey} value`);
75
+ break;
76
+ case 'getFreshValueSuccess':
77
+ getFreshValueTimer?.end(timings);
78
+ break;
79
+ case 'done':
80
+ cacheRetrievalTimer.end(timings);
81
+ break;
82
+ default:
83
+ break;
84
+ }
85
+ };
86
+ };
87
+ }
88
+ //# sourceMappingURL=timing.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.server.js","sourceRoot":"","sources":["../../src/timing.server.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAa;IACtD,MAAM,OAAO,GAAY;QACxB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,EAAE,EAAE,CAAC;KAC5C,CAAA;IACD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;QAC1C,KAAK;YACJ,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAA;QACpC,CAAC;QACD,UAAU,EAAE,KAAK;KACjB,CAAC,CAAA;IACF,OAAO,OAAO,CAAA;AACf,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAa;IAC/C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;IAC/B,OAAO;QACN,GAAG,CAAC,OAAgB;YACnB,IAAI,UAAU,GA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AiB,SAAS,EAAE,EAC5B,sCAAsC,SAAS,QAAQ,CACvD,CAAA;oBACD,MAAK;gBACN,KAAK,sBAAsB;oBAC1B,kBAAkB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;oBAChC,MAAK;gBACN,KAAK,MAAM;oBACV,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;oBAChC,MAAK;gBACN;oBACC,MAAK;YACP,CAAC;QACF,CAAC,CAAA;IACF,CAAC,CAAA;AACF,CAAC","sourcesContent":["import { type CreateReporter } from '@epic-web/cachified'\n\nexport type Timings = Record<\n\tstring,\n\tArray<\n\t\t{ desc?: string } & (\n\t\t\t| { time: number; start?: never }\n\t\t\t| { time?: never; start: number }\n\t\t)\n\t>\n>\n\nexport function makeTimings(type: string, desc?: string) {\n\tconst timings: Timings = {\n\t\t[type]: [{ desc, start: performance.now() }],\n\t}\n\tObject.defineProperty(timings, 'toString', {\n\t\tvalue() {\n\t\t\treturn getServerTimeHeader(timings)\n\t\t},\n\t\tenumerable: false,\n\t})\n\treturn timings\n}\n\nfunction createTimer(type: string, desc?: string) {\n\tconst start = performance.now()\n\treturn {\n\t\tend(timings: Timings) {\n\t\t\tlet timingType = timings[type]\n\n\t\t\tif (!timingType) {\n\t\t\t\ttimingType = timings[type] = []\n\t\t\t}\n\t\t\ttimingType.push({ desc, time: performance.now() - start })\n\t\t},\n\t}\n}\n\nexport async function time<ReturnType>(\n\tfn: Promise<ReturnType> | (() => ReturnType | Promise<ReturnType>),\n\t{\n\t\ttype,\n\t\tdesc,\n\t\ttimings,\n\t}: {\n\t\ttype: string\n\t\tdesc?: string\n\t\ttimings?: Timings\n\t},\n): Promise<ReturnType> {\n\tconst timer = createTimer(type, desc)\n\tconst promise = typeof fn === 'function' ? fn() : fn\n\tif (!timings) return promise\n\n\tconst result = await promise\n\n\ttimer.end(timings)\n\treturn result\n}\n\nexport function getServerTimeHeader(timings?: Timings) {\n\tif (!timings) return ''\n\treturn Object.entries(timings)\n\t\t.map(([key, timingInfos]) => {\n\t\t\tconst dur = timingInfos\n\t\t\t\t.reduce((acc, timingInfo) => {\n\t\t\t\t\tconst time = timingInfo.time ?? performance.now() - timingInfo.start\n\t\t\t\t\treturn acc + time\n\t\t\t\t}, 0)\n\t\t\t\t.toFixed(1)\n\t\t\tconst desc = timingInfos\n\t\t\t\t.map((t) => t.desc)\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' & ')\n\t\t\treturn [\n\t\t\t\tkey.replaceAll(/(:| |@|=|;|,|\\/|\\\\|\\{|\\})/g, '_'),\n\t\t\t\tdesc ? `desc=${JSON.stringify(desc)}` : null,\n\t\t\t\t`dur=${dur}`,\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(';')\n\t\t})\n\t\t.join(',')\n}\n\nexport function combineServerTimings(headers1: Headers, headers2: Headers) {\n\tconst newHeaders = new Headers(headers1)\n\tnewHeaders.append('Server-Timing', headers2.get('Server-Timing') ?? '')\n\treturn newHeaders.get('Server-Timing') ?? ''\n}\n\nexport function cachifiedTimingReporter<Value>(\n\ttimings?: Timings,\n\ttimingKey?: string,\n): undefined | CreateReporter<Value> {\n\tif (!timings) return\n\n\treturn ({ key }) => {\n\t\ttimingKey = timingKey ?? key\n\t\tconst cacheRetrievalTimer = createTimer(\n\t\t\t`cache:${timingKey}`,\n\t\t\t`${timingKey} cache retrieval`,\n\t\t)\n\t\tlet getFreshValueTimer: ReturnType<typeof createTimer> | undefined\n\t\treturn (event) => {\n\t\t\tswitch (event.name) {\n\t\t\t\tcase 'getFreshValueStart':\n\t\t\t\t\tgetFreshValueTimer = createTimer(\n\t\t\t\t\t\t`getFreshValue:${timingKey}`,\n\t\t\t\t\t\t`request forced to wait for a fresh ${timingKey} value`,\n\t\t\t\t\t)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'getFreshValueSuccess':\n\t\t\t\t\tgetFreshValueTimer?.end(timings)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'done':\n\t\t\t\t\tcacheRetrievalTimer.end(timings)\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,17 @@
1
+ export declare function getUserId({ request }: {
2
+ request: Request;
3
+ }): Promise<{
4
+ readonly id: string;
5
+ readonly type: "cookie.clientId";
6
+ } | {
7
+ readonly id: string;
8
+ readonly type: "cookie.randomId";
9
+ } | {
10
+ readonly id: string;
11
+ readonly type: "db.authInfo";
12
+ } | {
13
+ readonly id: string;
14
+ readonly type: "db.clientId";
15
+ }>;
16
+ export declare function getSetClientIdCookieHeader(clientId: string): string;
17
+ //# sourceMappingURL=user.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.server.d.ts","sourceRoot":"","sources":["../../src/user.server.ts"],"names":[],"mappings":"AAIA,wBAAsB,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE;;;;;;;;;;;;GAiChE;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,UAE1D"}