@epic-web/workshop-utils 6.15.1 → 6.15.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.
- package/dist/esm/apps.server.d.ts +244 -244
- package/dist/esm/apps.server.d.ts.map +1 -1
- package/dist/esm/apps.server.js +3 -6
- package/dist/esm/apps.server.js.map +1 -1
- package/dist/esm/cache.server.d.ts +33 -27
- package/dist/esm/cache.server.d.ts.map +1 -1
- package/dist/esm/cache.server.js +4 -1
- package/dist/esm/cache.server.js.map +1 -1
- package/dist/esm/compile-mdx.server.d.ts +1 -0
- package/dist/esm/compile-mdx.server.d.ts.map +1 -1
- package/dist/esm/compile-mdx.server.js +1 -0
- package/dist/esm/compile-mdx.server.js.map +1 -1
- package/dist/esm/config.server.d.ts +6 -7
- package/dist/esm/config.server.d.ts.map +1 -1
- package/dist/esm/config.server.js +4 -3
- package/dist/esm/config.server.js.map +1 -1
- package/dist/esm/db.server.d.ts +1 -0
- package/dist/esm/db.server.d.ts.map +1 -1
- package/dist/esm/db.server.js +1 -0
- package/dist/esm/db.server.js.map +1 -1
- package/dist/esm/diff.server.d.ts.map +1 -1
- package/dist/esm/diff.server.js +7 -5
- package/dist/esm/diff.server.js.map +1 -1
- package/dist/esm/env.server.d.ts +1 -0
- package/dist/esm/env.server.d.ts.map +1 -1
- package/dist/esm/env.server.js +1 -0
- package/dist/esm/env.server.js.map +1 -1
- package/dist/esm/epic-api.server.d.ts +2 -2
- package/dist/esm/epic-api.server.d.ts.map +1 -1
- package/dist/esm/epic-api.server.js +2 -0
- package/dist/esm/epic-api.server.js.map +1 -1
- package/dist/esm/git.server.d.ts +1 -0
- package/dist/esm/git.server.d.ts.map +1 -1
- package/dist/esm/git.server.js +1 -0
- package/dist/esm/git.server.js.map +1 -1
- package/dist/esm/init-env.d.ts +16 -0
- package/dist/esm/init-env.d.ts.map +1 -0
- package/dist/esm/init-env.js +6 -0
- package/dist/esm/init-env.js.map +1 -0
- package/dist/esm/modified-time.server.d.ts +1 -0
- package/dist/esm/modified-time.server.d.ts.map +1 -1
- package/dist/esm/modified-time.server.js +1 -0
- package/dist/esm/modified-time.server.js.map +1 -1
- package/dist/esm/notifications.server.d.ts +3 -3
- package/dist/esm/notifications.server.d.ts.map +1 -1
- package/dist/esm/notifications.server.js +2 -0
- package/dist/esm/notifications.server.js.map +1 -1
- package/dist/esm/playwright.server.d.ts +1 -0
- package/dist/esm/playwright.server.d.ts.map +1 -1
- package/dist/esm/playwright.server.js +1 -0
- package/dist/esm/playwright.server.js.map +1 -1
- package/dist/esm/process-manager.server.d.ts +1 -0
- package/dist/esm/process-manager.server.d.ts.map +1 -1
- package/dist/esm/process-manager.server.js +1 -0
- package/dist/esm/process-manager.server.js.map +1 -1
- package/dist/esm/request-context.server.d.ts +1 -0
- package/dist/esm/request-context.server.d.ts.map +1 -1
- package/dist/esm/request-context.server.js +1 -0
- package/dist/esm/request-context.server.js.map +1 -1
- package/dist/esm/timing.server.d.ts +1 -0
- package/dist/esm/timing.server.d.ts.map +1 -1
- package/dist/esm/timing.server.js +1 -0
- package/dist/esm/timing.server.js.map +1 -1
- package/dist/esm/user.server.d.ts.map +1 -1
- package/dist/esm/user.server.js +2 -0
- package/dist/esm/user.server.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/esm/utils.js +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/utils.server.d.ts +1 -0
- package/dist/esm/utils.server.d.ts.map +1 -1
- package/dist/esm/utils.server.js +1 -0
- package/dist/esm/utils.server.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as C from '@epic-web/cachified';
|
|
2
2
|
import { type Timings } from './timing.server.js';
|
|
3
3
|
export declare const solutionAppCache: C.Cache<{
|
|
4
|
-
title: string;
|
|
5
|
-
type: "solution";
|
|
6
|
-
name: string;
|
|
7
4
|
test: {
|
|
8
5
|
type: "browser";
|
|
9
6
|
pathname: string;
|
|
@@ -14,6 +11,9 @@ export declare const solutionAppCache: C.Cache<{
|
|
|
14
11
|
} | {
|
|
15
12
|
type: "none";
|
|
16
13
|
};
|
|
14
|
+
type: "solution";
|
|
15
|
+
title: string;
|
|
16
|
+
name: string;
|
|
17
17
|
fullPath: string;
|
|
18
18
|
dev: {
|
|
19
19
|
type: "browser";
|
|
@@ -35,9 +35,6 @@ export declare const solutionAppCache: C.Cache<{
|
|
|
35
35
|
epicVideoEmbeds?: string[] | undefined;
|
|
36
36
|
}>;
|
|
37
37
|
export declare const problemAppCache: C.Cache<{
|
|
38
|
-
title: string;
|
|
39
|
-
type: "problem";
|
|
40
|
-
name: string;
|
|
41
38
|
test: {
|
|
42
39
|
type: "browser";
|
|
43
40
|
pathname: string;
|
|
@@ -48,6 +45,9 @@ export declare const problemAppCache: C.Cache<{
|
|
|
48
45
|
} | {
|
|
49
46
|
type: "none";
|
|
50
47
|
};
|
|
48
|
+
type: "problem";
|
|
49
|
+
title: string;
|
|
50
|
+
name: string;
|
|
51
51
|
fullPath: string;
|
|
52
52
|
dev: {
|
|
53
53
|
type: "browser";
|
|
@@ -69,9 +69,6 @@ export declare const problemAppCache: C.Cache<{
|
|
|
69
69
|
epicVideoEmbeds?: string[] | undefined;
|
|
70
70
|
}>;
|
|
71
71
|
export declare const exampleAppCache: C.Cache<{
|
|
72
|
-
title: string;
|
|
73
|
-
type: "example";
|
|
74
|
-
name: string;
|
|
75
72
|
test: {
|
|
76
73
|
type: "browser";
|
|
77
74
|
pathname: string;
|
|
@@ -82,6 +79,9 @@ export declare const exampleAppCache: C.Cache<{
|
|
|
82
79
|
} | {
|
|
83
80
|
type: "none";
|
|
84
81
|
};
|
|
82
|
+
type: "example";
|
|
83
|
+
title: string;
|
|
84
|
+
name: string;
|
|
85
85
|
fullPath: string;
|
|
86
86
|
dev: {
|
|
87
87
|
type: "browser";
|
|
@@ -100,9 +100,6 @@ export declare const exampleAppCache: C.Cache<{
|
|
|
100
100
|
epicVideoEmbeds?: string[] | undefined;
|
|
101
101
|
}>;
|
|
102
102
|
export declare const playgroundAppCache: C.Cache<{
|
|
103
|
-
title: string;
|
|
104
|
-
type: "playground";
|
|
105
|
-
name: string;
|
|
106
103
|
test: {
|
|
107
104
|
type: "browser";
|
|
108
105
|
pathname: string;
|
|
@@ -113,6 +110,9 @@ export declare const playgroundAppCache: C.Cache<{
|
|
|
113
110
|
} | {
|
|
114
111
|
type: "none";
|
|
115
112
|
};
|
|
113
|
+
type: "playground";
|
|
114
|
+
title: string;
|
|
115
|
+
name: string;
|
|
116
116
|
fullPath: string;
|
|
117
117
|
dev: {
|
|
118
118
|
type: "browser";
|
|
@@ -133,9 +133,6 @@ export declare const playgroundAppCache: C.Cache<{
|
|
|
133
133
|
epicVideoEmbeds?: string[] | undefined;
|
|
134
134
|
}>;
|
|
135
135
|
export declare const appsCache: C.Cache<{
|
|
136
|
-
title: string;
|
|
137
|
-
type: "solution";
|
|
138
|
-
name: string;
|
|
139
136
|
test: {
|
|
140
137
|
type: "browser";
|
|
141
138
|
pathname: string;
|
|
@@ -146,6 +143,9 @@ export declare const appsCache: C.Cache<{
|
|
|
146
143
|
} | {
|
|
147
144
|
type: "none";
|
|
148
145
|
};
|
|
146
|
+
type: "solution";
|
|
147
|
+
title: string;
|
|
148
|
+
name: string;
|
|
149
149
|
fullPath: string;
|
|
150
150
|
dev: {
|
|
151
151
|
type: "browser";
|
|
@@ -166,9 +166,6 @@ export declare const appsCache: C.Cache<{
|
|
|
166
166
|
instructionsCode?: string | undefined;
|
|
167
167
|
epicVideoEmbeds?: string[] | undefined;
|
|
168
168
|
} | {
|
|
169
|
-
title: string;
|
|
170
|
-
type: "problem";
|
|
171
|
-
name: string;
|
|
172
169
|
test: {
|
|
173
170
|
type: "browser";
|
|
174
171
|
pathname: string;
|
|
@@ -179,6 +176,9 @@ export declare const appsCache: C.Cache<{
|
|
|
179
176
|
} | {
|
|
180
177
|
type: "none";
|
|
181
178
|
};
|
|
179
|
+
type: "problem";
|
|
180
|
+
title: string;
|
|
181
|
+
name: string;
|
|
182
182
|
fullPath: string;
|
|
183
183
|
dev: {
|
|
184
184
|
type: "browser";
|
|
@@ -199,9 +199,6 @@ export declare const appsCache: C.Cache<{
|
|
|
199
199
|
instructionsCode?: string | undefined;
|
|
200
200
|
epicVideoEmbeds?: string[] | undefined;
|
|
201
201
|
} | {
|
|
202
|
-
title: string;
|
|
203
|
-
type: "example";
|
|
204
|
-
name: string;
|
|
205
202
|
test: {
|
|
206
203
|
type: "browser";
|
|
207
204
|
pathname: string;
|
|
@@ -212,6 +209,9 @@ export declare const appsCache: C.Cache<{
|
|
|
212
209
|
} | {
|
|
213
210
|
type: "none";
|
|
214
211
|
};
|
|
212
|
+
type: "example";
|
|
213
|
+
title: string;
|
|
214
|
+
name: string;
|
|
215
215
|
fullPath: string;
|
|
216
216
|
dev: {
|
|
217
217
|
type: "browser";
|
|
@@ -229,9 +229,6 @@ export declare const appsCache: C.Cache<{
|
|
|
229
229
|
instructionsCode?: string | undefined;
|
|
230
230
|
epicVideoEmbeds?: string[] | undefined;
|
|
231
231
|
} | {
|
|
232
|
-
title: string;
|
|
233
|
-
type: "playground";
|
|
234
|
-
name: string;
|
|
235
232
|
test: {
|
|
236
233
|
type: "browser";
|
|
237
234
|
pathname: string;
|
|
@@ -242,6 +239,9 @@ export declare const appsCache: C.Cache<{
|
|
|
242
239
|
} | {
|
|
243
240
|
type: "none";
|
|
244
241
|
};
|
|
242
|
+
type: "playground";
|
|
243
|
+
title: string;
|
|
244
|
+
name: string;
|
|
245
245
|
fullPath: string;
|
|
246
246
|
dev: {
|
|
247
247
|
type: "browser";
|
|
@@ -263,6 +263,12 @@ export declare const appsCache: C.Cache<{
|
|
|
263
263
|
}>;
|
|
264
264
|
export declare const diffCodeCache: C.Cache<string>;
|
|
265
265
|
export declare const diffFilesCache: C.Cache<string>;
|
|
266
|
+
export declare const copyUnignoredFilesCache: {
|
|
267
|
+
name: string;
|
|
268
|
+
set: (key: string, value: C.CacheEntry<string>) => C.CacheEntry<string>;
|
|
269
|
+
get: (key: string) => C.CacheEntry<string> | undefined;
|
|
270
|
+
delete: (key: string) => boolean;
|
|
271
|
+
};
|
|
266
272
|
export declare const compiledMarkdownCache: C.Cache<string>;
|
|
267
273
|
export declare const compiledCodeCache: C.Cache<string>;
|
|
268
274
|
export declare const ogCache: {
|
|
@@ -313,8 +319,8 @@ export declare const notificationsCache: {
|
|
|
313
319
|
name: string;
|
|
314
320
|
set: (key: string, value: C.CacheEntry<{
|
|
315
321
|
message: string;
|
|
316
|
-
title: string;
|
|
317
322
|
type: "info" | "warning" | "danger";
|
|
323
|
+
title: string;
|
|
318
324
|
id: string;
|
|
319
325
|
expiresAt: Date | null;
|
|
320
326
|
link?: string | undefined;
|
|
@@ -324,8 +330,8 @@ export declare const notificationsCache: {
|
|
|
324
330
|
}[] | undefined;
|
|
325
331
|
}[]>) => C.CacheEntry<{
|
|
326
332
|
message: string;
|
|
327
|
-
title: string;
|
|
328
333
|
type: "info" | "warning" | "danger";
|
|
334
|
+
title: string;
|
|
329
335
|
id: string;
|
|
330
336
|
expiresAt: Date | null;
|
|
331
337
|
link?: string | undefined;
|
|
@@ -336,8 +342,8 @@ export declare const notificationsCache: {
|
|
|
336
342
|
}[]>;
|
|
337
343
|
get: (key: string) => C.CacheEntry<{
|
|
338
344
|
message: string;
|
|
339
|
-
title: string;
|
|
340
345
|
type: "info" | "warning" | "danger";
|
|
346
|
+
title: string;
|
|
341
347
|
id: string;
|
|
342
348
|
expiresAt: Date | null;
|
|
343
349
|
link?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.server.d.ts","sourceRoot":"","sources":["../../src/cache.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.server.d.ts","sourceRoot":"","sources":["../../src/cache.server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,CAAC,MAAM,qBAAqB,CAAA;AAcxC,OA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AkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAC+B,CAAA;AAC9D,eAAO,MAAM,mBAAmB;;;;;CAE/B,CAAA;AAID,eAAO,MAAM,OAAO,kBAAkC,CAAA;AAuDtD,wBAAsB,sBAAsB,iCAE3C;AAED,wBAAsB,WAAW,8BAUhC;AAED,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM;;;;;EAsB9D;AAED,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,2BA4GhE;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,EACtC,OAAO,EACP,OAAO,EACP,GAAG,EACH,SAA2E,EAC3E,oBAAoB,EACpB,GAAG,OAAO,EACV,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,GAAG;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oBAAoB,CAAC,EAAE,KAAK,CAAA;CAC5B,GAAG,OAAO,CAAC,KAAK,CAAC,CAwBjB;AAED,wBAAsB,gBAAgB,CAAC,EACtC,UAAU,EACV,OAAO,EACP,GAAG,GACH,EAAE;IACF,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;CACZ,oBAaA"}
|
package/dist/esm/cache.server.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// eslint-disable-next-line import/order -- this must be first
|
|
2
|
+
import { ENV } from './init-env.js';
|
|
1
3
|
import os from 'os';
|
|
2
4
|
import path from 'path';
|
|
3
5
|
import * as C from '@epic-web/cachified';
|
|
@@ -15,6 +17,7 @@ export const playgroundAppCache = makeSingletonFsCache('PlaygroundAppCache');
|
|
|
15
17
|
export const appsCache = makeSingletonFsCache('AppsCache');
|
|
16
18
|
export const diffCodeCache = makeSingletonFsCache('DiffCodeCache');
|
|
17
19
|
export const diffFilesCache = makeSingletonFsCache('DiffFilesCache');
|
|
20
|
+
export const copyUnignoredFilesCache = makeSingletonCache('CopyUnignoredFilesCache');
|
|
18
21
|
export const compiledMarkdownCache = makeSingletonFsCache('CompiledMarkdownCache');
|
|
19
22
|
export const compiledCodeCache = makeSingletonFsCache('CompiledCodeCache');
|
|
20
23
|
export const ogCache = makeSingletonCache('OgCache');
|
|
@@ -105,7 +108,7 @@ export function makeSingletonCache(name) {
|
|
|
105
108
|
}
|
|
106
109
|
export function makeSingletonFsCache(name) {
|
|
107
110
|
return remember(name, () => {
|
|
108
|
-
const cacheDir = path.join(os.homedir(), '.epicshop', 'cache',
|
|
111
|
+
const cacheDir = path.join(os.homedir(), '.epicshop', 'cache', ENV.EPICSHOP_WORKSHOP_INSTANCE_ID, name);
|
|
109
112
|
const fsCache = {
|
|
110
113
|
name: `Filesystem cache (${name})`,
|
|
111
114
|
async get(key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.server.js","sourceRoot":"","sources":["../../src/cache.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,CAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,GAAG,MAAM,SAAS,CAAA;AASzB,OAAO,EAAE,uBAAuB,EAAgB,MAAM,oBAAoB,CAAA;AAC1E,OAAO,E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;QACP,GAAG;KACH,CAAC,CAAA;IACF,OAAO,CAAC,CAAC,SAAS,CACjB;QACC,GAAG,OAAO;QACV,GAAG;QACH,UAAU;KACV,EACD,CAAC,CAAC,cAAc,CACf,uBAAuB,CAAC,OAAO,EAAE,SAAS,CAAC,EAC3C,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAChE,CACD,CAAA;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EACtC,UAAU,EACV,OAAO,EACP,GAAG,GAKH;IACA,IAAI,OAAO,UAAU,KAAK,SAAS;QAAE,OAAO,UAAU,CAAA;IACtD,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,GAAG,EAAE,CAAC;QAC3C,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAC1B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAC7B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACtC,CAAC","sourcesContent":["import os from 'os'\nimport path from 'path'\nimport * as C from '@epic-web/cachified'\nimport { verboseReporter, type CacheEntry } from '@epic-web/cachified'\nimport { remember } from '@epic-web/remember'\nimport fsExtra from 'fs-extra'\nimport { LRUCache } from 'lru-cache'\nimport md5 from 'md5-hex'\nimport {\n\ttype App,\n\ttype ExampleApp,\n\ttype PlaygroundApp,\n\ttype ProblemApp,\n\ttype SolutionApp,\n} from './apps.server.js'\nimport { type Notification } from './notifications.server.js'\nimport { cachifiedTimingReporter, type Timings } from './timing.server.js'\nimport { checkConnectionCached } from './utils.server.js'\n\nexport const solutionAppCache =\n\tmakeSingletonFsCache<SolutionApp>('SolutionAppCache')\nexport const problemAppCache =\n\tmakeSingletonFsCache<ProblemApp>('ProblemAppCache')\nexport const exampleAppCache =\n\tmakeSingletonFsCache<ExampleApp>('ExampleAppCache')\nexport const playgroundAppCache =\n\tmakeSingletonFsCache<PlaygroundApp>('PlaygroundAppCache')\nexport const appsCache = makeSingletonFsCache<App>('AppsCache')\nexport const diffCodeCache = makeSingletonFsCache<string>('DiffCodeCache')\nexport const diffFilesCache = makeSingletonFsCache<string>('DiffFilesCache')\nexport const compiledMarkdownCache = makeSingletonFsCache<string>(\n\t'CompiledMarkdownCache',\n)\nexport const compiledCodeCache =\n\tmakeSingletonFsCache<string>('CompiledCodeCache')\nexport const ogCache = makeSingletonCache<string>('OgCache')\nexport const compiledInstructionMarkdownCache = makeSingletonFsCache<{\n\tcode: string\n\ttitle: string | null\n\tepicVideoEmbeds: Array<string>\n}>('CompiledInstructionMarkdownCache')\nexport const dirModifiedTimeCache = makeSingletonCache<number>(\n\t'DirModifiedTimeCache',\n)\nexport const connectionCache = makeSingletonCache<boolean>('ConnectionCache')\nexport const checkForUpdatesCache = makeSingletonCache<{\n\tupdatesAvailable: boolean\n\tlocalCommit: string\n\tremoteCommit: string\n\tdiffLink: string | null\n}>('CheckForUpdatesCache')\nexport const notificationsCache =\n\tmakeSingletonCache<Array<Notification>>('NotificationsCache')\nexport const directoryEmptyCache = makeSingletonCache<boolean>(\n\t'DirectoryEmptyCache',\n)\n\nconst cacheDir = path.join(os.homedir(), '.epicshop', 'cache')\n\nexport const fsCache = makeSingletonFsCache('FsCache')\n\nasync function readJsonFilesInDirectory(\n\tdir: string,\n): Promise<Record<string, any>> {\n\tconst files = await fsExtra.readdir(dir)\n\tconst entries = await Promise.all(\n\t\tfiles.map(async (file) => {\n\t\t\tconst filePath = path.join(dir, file)\n\t\t\tconst stats = await fsExtra.stat(filePath)\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\tconst subEntries = await readJsonFilesInDirectory(filePath)\n\t\t\t\treturn [file, subEntries]\n\t\t\t} else {\n\t\t\t\tconst maxRetries = 2\n\t\t\t\tconst baseDelay = 25 // shorter delay for directory listing\n\n\t\t\t\tfor (let attempt = 0; attempt <= maxRetries; attempt++) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst data = await fsExtra.readJSON(filePath)\n\t\t\t\t\t\treturn [file, data]\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t// Handle JSON parsing errors (could be race condition or corruption)\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof SyntaxError &&\n\t\t\t\t\t\t\terror.message.includes('JSON')\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// If this is a retry attempt, it might be a race condition\n\t\t\t\t\t\t\tif (attempt < maxRetries) {\n\t\t\t\t\t\t\t\tconst delay = baseDelay * Math.pow(2, attempt)\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`JSON parsing error on attempt ${attempt + 1}/${maxRetries + 1} for directory listing ${filePath}, retrying in ${delay}ms...`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delay))\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Final attempt failed, skip the file\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`Skipping corrupted JSON file in directory listing after ${attempt + 1} attempts: ${filePath}`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn [file, null]\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// This should never be reached, but just in case\n\t\t\t\treturn [file, null]\n\t\t\t}\n\t\t}),\n\t)\n\treturn Object.fromEntries(entries)\n}\n\nexport async function getAllFileCacheEntries() {\n\treturn readJsonFilesInDirectory(cacheDir)\n}\n\nexport async function deleteCache() {\n\tif (process.env.EPICSHOP_DEPLOYED) return null\n\n\ttry {\n\t\tif (await fsExtra.exists(cacheDir)) {\n\t\t\tawait fsExtra.remove(cacheDir)\n\t\t}\n\t} catch (error) {\n\t\tconsole.error(`Error deleting the cache in ${cacheDir}`, error)\n\t}\n}\n\nexport function makeSingletonCache<CacheEntryType>(name: string) {\n\treturn remember(name, () => {\n\t\tconst lruInstance = new LRUCache<string, CacheEntry<CacheEntryType>>({\n\t\t\tmax: 1000,\n\t\t})\n\n\t\tconst lru = {\n\t\t\tname,\n\t\t\tset: (key, value) => {\n\t\t\t\tconst ttl = C.totalTtl(value.metadata)\n\t\t\t\tlruInstance.set(key, value, {\n\t\t\t\t\tttl: ttl === Infinity ? undefined : ttl,\n\t\t\t\t\tstart: value.metadata.createdTime,\n\t\t\t\t})\n\t\t\t\treturn value\n\t\t\t},\n\t\t\tget: (key) => lruInstance.get(key),\n\t\t\tdelete: (key) => lruInstance.delete(key),\n\t\t} satisfies C.Cache<CacheEntryType>\n\n\t\treturn lru\n\t})\n}\n\nexport function makeSingletonFsCache<CacheEntryType>(name: string) {\n\treturn remember(name, () => {\n\t\tconst cacheDir = path.join(\n\t\t\tos.homedir(),\n\t\t\t'.epicshop',\n\t\t\t'cache',\n\t\t\tprocess.env.EPICSHOP_WORKSHOP_INSTANCE_ID,\n\t\t\tname,\n\t\t)\n\n\t\tconst fsCache: C.Cache<CacheEntryType> = {\n\t\t\tname: `Filesystem cache (${name})`,\n\t\t\tasync get(key) {\n\t\t\t\tconst filePath = path.join(cacheDir, md5(key))\n\t\t\t\tconst maxRetries = 3\n\t\t\t\tconst baseDelay = 10\n\n\t\t\t\tfor (let attempt = 0; attempt <= maxRetries; attempt++) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst data = await fsExtra.readJSON(filePath)\n\t\t\t\t\t\tif (data.entry) return data.entry\n\t\t\t\t\t\treturn null\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof Error &&\n\t\t\t\t\t\t\t'code' in error &&\n\t\t\t\t\t\t\terror.code === 'ENOENT'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Handle JSON parsing errors (could be race condition or corruption)\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof SyntaxError &&\n\t\t\t\t\t\t\terror.message.includes('JSON')\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// If this is a retry attempt, it might be a race condition\n\t\t\t\t\t\t\tif (attempt < maxRetries) {\n\t\t\t\t\t\t\t\tconst delay = baseDelay * Math.pow(2, attempt) // exponential backoff\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`JSON parsing error on attempt ${attempt + 1}/${maxRetries + 1} for ${filePath}, retrying in ${delay}ms...`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delay))\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Final attempt failed, treat as corrupted file\n\t\t\t\t\t\t\t// Log to Sentry if available\n\t\t\t\t\t\t\tif (process.env.SENTRY_DSN && process.env.EPICSHOP_IS_PUBLISHED) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst Sentry = await import('@sentry/react-router')\n\t\t\t\t\t\t\t\t\tSentry.captureException(error, {\n\t\t\t\t\t\t\t\t\t\ttags: {\n\t\t\t\t\t\t\t\t\t\t\terror_type: 'corrupted_cache_file',\n\t\t\t\t\t\t\t\t\t\t\tcache_name: name,\n\t\t\t\t\t\t\t\t\t\t\tcache_key: key,\n\t\t\t\t\t\t\t\t\t\t\tretry_attempts: attempt.toString(),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\textra: {\n\t\t\t\t\t\t\t\t\t\t\tfilePath,\n\t\t\t\t\t\t\t\t\t\t\terrorMessage: error.message,\n\t\t\t\t\t\t\t\t\t\t\tcacheName: name,\n\t\t\t\t\t\t\t\t\t\t\tcacheKey: key,\n\t\t\t\t\t\t\t\t\t\t\tretryAttempts: attempt,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t} catch (sentryError) {\n\t\t\t\t\t\t\t\t\tconsole.error('Failed to log to Sentry:', sentryError)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Delete the corrupted file\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait fsExtra.remove(filePath)\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`Deleted corrupted cache file after ${attempt + 1} attempts: ${filePath}`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t} catch (deleteError) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t`Failed to delete corrupted cache file ${filePath}:`,\n\t\t\t\t\t\t\t\t\tdeleteError,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// For other errors, don't retry\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// This should never be reached, but just in case\n\t\t\t\treturn null\n\t\t\t},\n\t\t\tasync set(key, entry) {\n\t\t\t\tconst filePath = path.join(cacheDir, md5(key))\n\t\t\t\tawait fsExtra.ensureDir(path.dirname(filePath))\n\t\t\t\tawait fsExtra.writeJSON(filePath, { key, entry })\n\t\t\t},\n\t\t\tasync delete(key) {\n\t\t\t\tconst filePath = path.join(cacheDir, md5(key))\n\t\t\t\tawait fsExtra.remove(filePath)\n\t\t\t},\n\t\t}\n\n\t\treturn fsCache\n\t})\n}\n\n/**\n * This wraps @epic-web/cachified to add a few handy features:\n *\n * 1. Automatic timing for timing headers\n * 2. Automatic force refresh based on the request and enhancement of forceFresh\n * to support comma-separated keys to force\n * 3. Offline fallback support. If a fallback is given and we are detected to be\n * offline, then the cached value is used regardless of whether it's expired and\n * if one is not present then the given fallback will be used.\n */\nexport async function cachified<Value>({\n\trequest,\n\ttimings,\n\tkey,\n\ttimingKey = key.length > 18 ? `${key.slice(0, 7)}...${key.slice(-8)}` : key,\n\tofflineFallbackValue,\n\t...options\n}: Omit<C.CachifiedOptions<Value>, 'forceFresh'> & {\n\trequest?: Request\n\ttimings?: Timings\n\tforceFresh?: boolean | string\n\ttimingKey?: string\n\tofflineFallbackValue?: Value\n}): Promise<Value> {\n\tif (offlineFallbackValue !== undefined) {\n\t\tconst isOnline = await checkConnectionCached({ request, timings })\n\t\tif (!isOnline) {\n\t\t\tconst cacheEntry = await options.cache.get(key)\n\t\t\treturn cacheEntry?.value ?? offlineFallbackValue\n\t\t}\n\t}\n\tconst forceFresh = await shouldForceFresh({\n\t\tforceFresh: options.forceFresh,\n\t\trequest,\n\t\tkey,\n\t})\n\treturn C.cachified(\n\t\t{\n\t\t\t...options,\n\t\t\tkey,\n\t\t\tforceFresh,\n\t\t},\n\t\tC.mergeReporters(\n\t\t\tcachifiedTimingReporter(timings, timingKey),\n\t\t\tprocess.env.EPICSHOP_DEBUG_CACHE ? verboseReporter() : undefined,\n\t\t),\n\t)\n}\n\nexport async function shouldForceFresh({\n\tforceFresh,\n\trequest,\n\tkey,\n}: {\n\tforceFresh?: boolean | string\n\trequest?: Request\n\tkey?: string\n}) {\n\tif (typeof forceFresh === 'boolean') return forceFresh\n\tif (typeof forceFresh === 'string' && key) {\n\t\treturn forceFresh.split(',').includes(key)\n\t}\n\n\tif (!request) return false\n\tconst fresh = new URL(request.url).searchParams.get('fresh')\n\tif (typeof fresh !== 'string') return false\n\tif (fresh === '') return true\n\tif (!key) return false\n\n\treturn fresh.split(',').includes(key)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cache.server.js","sourceRoot":"","sources":["../../src/cache.server.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAEnC,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,CAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,GAAG,MAAM,SAAS,CAAA;AASzB,OAAO,EAAE,uBAAuB,EAAgB,MAAM,oBAAoB,CAAA;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,MAAM,CAAC,MAAM,gBAAgB,GAC5B,oBAAoB,CAAc,kBAAkB,CAAC,CAAA;AACtD,MAAM,CAAC,MAAM,eAAe,GAC3B,oBAAoB,CAAa,iBAAiB,CAAC,CAAA;AACpD,MAAM,CAAC,MAAM,eAAe,GAC3B,oBAAoB,CAAa,iBAAiB,CAAC,CAAA;AACpD,MAAM,CAAC,MAAM,kBAAkB,GAC9B,oBAAoB,CAAgB,oBAAoB,CAAC,CAAA;AAC1D,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAM,WAAW,CAAC,CAAA;AAC/D,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAS,eAAe,CAAC,CAAA;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAS,gBAAgB,CAAC,CAAA;AAC5E,MAAM,C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3C,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAC1B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAC7B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACtC,CAAC","sourcesContent":["// eslint-disable-next-line import/order -- this must be first\nimport { ENV } from './init-env.js'\n\nimport os from 'os'\nimport path from 'path'\nimport * as C from '@epic-web/cachified'\nimport { verboseReporter, type CacheEntry } from '@epic-web/cachified'\nimport { remember } from '@epic-web/remember'\nimport fsExtra from 'fs-extra'\nimport { LRUCache } from 'lru-cache'\nimport md5 from 'md5-hex'\nimport {\n\ttype App,\n\ttype ExampleApp,\n\ttype PlaygroundApp,\n\ttype ProblemApp,\n\ttype SolutionApp,\n} from './apps.server.js'\nimport { type Notification } from './notifications.server.js'\nimport { cachifiedTimingReporter, type Timings } from './timing.server.js'\nimport { checkConnectionCached } from './utils.server.js'\n\nexport const solutionAppCache =\n\tmakeSingletonFsCache<SolutionApp>('SolutionAppCache')\nexport const problemAppCache =\n\tmakeSingletonFsCache<ProblemApp>('ProblemAppCache')\nexport const exampleAppCache =\n\tmakeSingletonFsCache<ExampleApp>('ExampleAppCache')\nexport const playgroundAppCache =\n\tmakeSingletonFsCache<PlaygroundApp>('PlaygroundAppCache')\nexport const appsCache = makeSingletonFsCache<App>('AppsCache')\nexport const diffCodeCache = makeSingletonFsCache<string>('DiffCodeCache')\nexport const diffFilesCache = makeSingletonFsCache<string>('DiffFilesCache')\nexport const copyUnignoredFilesCache = makeSingletonCache<string>(\n\t'CopyUnignoredFilesCache',\n)\nexport const compiledMarkdownCache = makeSingletonFsCache<string>(\n\t'CompiledMarkdownCache',\n)\nexport const compiledCodeCache =\n\tmakeSingletonFsCache<string>('CompiledCodeCache')\nexport const ogCache = makeSingletonCache<string>('OgCache')\nexport const compiledInstructionMarkdownCache = makeSingletonFsCache<{\n\tcode: string\n\ttitle: string | null\n\tepicVideoEmbeds: Array<string>\n}>('CompiledInstructionMarkdownCache')\nexport const dirModifiedTimeCache = makeSingletonCache<number>(\n\t'DirModifiedTimeCache',\n)\nexport const connectionCache = makeSingletonCache<boolean>('ConnectionCache')\nexport const checkForUpdatesCache = makeSingletonCache<{\n\tupdatesAvailable: boolean\n\tlocalCommit: string\n\tremoteCommit: string\n\tdiffLink: string | null\n}>('CheckForUpdatesCache')\nexport const notificationsCache =\n\tmakeSingletonCache<Array<Notification>>('NotificationsCache')\nexport const directoryEmptyCache = makeSingletonCache<boolean>(\n\t'DirectoryEmptyCache',\n)\n\nconst cacheDir = path.join(os.homedir(), '.epicshop', 'cache')\n\nexport const fsCache = makeSingletonFsCache('FsCache')\n\nasync function readJsonFilesInDirectory(\n\tdir: string,\n): Promise<Record<string, any>> {\n\tconst files = await fsExtra.readdir(dir)\n\tconst entries = await Promise.all(\n\t\tfiles.map(async (file) => {\n\t\t\tconst filePath = path.join(dir, file)\n\t\t\tconst stats = await fsExtra.stat(filePath)\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\tconst subEntries = await readJsonFilesInDirectory(filePath)\n\t\t\t\treturn [file, subEntries]\n\t\t\t} else {\n\t\t\t\tconst maxRetries = 2\n\t\t\t\tconst baseDelay = 25 // shorter delay for directory listing\n\n\t\t\t\tfor (let attempt = 0; attempt <= maxRetries; attempt++) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst data = await fsExtra.readJSON(filePath)\n\t\t\t\t\t\treturn [file, data]\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t// Handle JSON parsing errors (could be race condition or corruption)\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof SyntaxError &&\n\t\t\t\t\t\t\terror.message.includes('JSON')\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// If this is a retry attempt, it might be a race condition\n\t\t\t\t\t\t\tif (attempt < maxRetries) {\n\t\t\t\t\t\t\t\tconst delay = baseDelay * Math.pow(2, attempt)\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`JSON parsing error on attempt ${attempt + 1}/${maxRetries + 1} for directory listing ${filePath}, retrying in ${delay}ms...`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delay))\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Final attempt failed, skip the file\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`Skipping corrupted JSON file in directory listing after ${attempt + 1} attempts: ${filePath}`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn [file, null]\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// This should never be reached, but just in case\n\t\t\t\treturn [file, null]\n\t\t\t}\n\t\t}),\n\t)\n\treturn Object.fromEntries(entries)\n}\n\nexport async function getAllFileCacheEntries() {\n\treturn readJsonFilesInDirectory(cacheDir)\n}\n\nexport async function deleteCache() {\n\tif (process.env.EPICSHOP_DEPLOYED) return null\n\n\ttry {\n\t\tif (await fsExtra.exists(cacheDir)) {\n\t\t\tawait fsExtra.remove(cacheDir)\n\t\t}\n\t} catch (error) {\n\t\tconsole.error(`Error deleting the cache in ${cacheDir}`, error)\n\t}\n}\n\nexport function makeSingletonCache<CacheEntryType>(name: string) {\n\treturn remember(name, () => {\n\t\tconst lruInstance = new LRUCache<string, CacheEntry<CacheEntryType>>({\n\t\t\tmax: 1000,\n\t\t})\n\n\t\tconst lru = {\n\t\t\tname,\n\t\t\tset: (key, value) => {\n\t\t\t\tconst ttl = C.totalTtl(value.metadata)\n\t\t\t\tlruInstance.set(key, value, {\n\t\t\t\t\tttl: ttl === Infinity ? undefined : ttl,\n\t\t\t\t\tstart: value.metadata.createdTime,\n\t\t\t\t})\n\t\t\t\treturn value\n\t\t\t},\n\t\t\tget: (key) => lruInstance.get(key),\n\t\t\tdelete: (key) => lruInstance.delete(key),\n\t\t} satisfies C.Cache<CacheEntryType>\n\n\t\treturn lru\n\t})\n}\n\nexport function makeSingletonFsCache<CacheEntryType>(name: string) {\n\treturn remember(name, () => {\n\t\tconst cacheDir = path.join(\n\t\t\tos.homedir(),\n\t\t\t'.epicshop',\n\t\t\t'cache',\n\t\t\tENV.EPICSHOP_WORKSHOP_INSTANCE_ID,\n\t\t\tname,\n\t\t)\n\n\t\tconst fsCache: C.Cache<CacheEntryType> = {\n\t\t\tname: `Filesystem cache (${name})`,\n\t\t\tasync get(key) {\n\t\t\t\tconst filePath = path.join(cacheDir, md5(key))\n\t\t\t\tconst maxRetries = 3\n\t\t\t\tconst baseDelay = 10\n\n\t\t\t\tfor (let attempt = 0; attempt <= maxRetries; attempt++) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst data = await fsExtra.readJSON(filePath)\n\t\t\t\t\t\tif (data.entry) return data.entry\n\t\t\t\t\t\treturn null\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof Error &&\n\t\t\t\t\t\t\t'code' in error &&\n\t\t\t\t\t\t\terror.code === 'ENOENT'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Handle JSON parsing errors (could be race condition or corruption)\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof SyntaxError &&\n\t\t\t\t\t\t\terror.message.includes('JSON')\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// If this is a retry attempt, it might be a race condition\n\t\t\t\t\t\t\tif (attempt < maxRetries) {\n\t\t\t\t\t\t\t\tconst delay = baseDelay * Math.pow(2, attempt) // exponential backoff\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`JSON parsing error on attempt ${attempt + 1}/${maxRetries + 1} for ${filePath}, retrying in ${delay}ms...`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delay))\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Final attempt failed, treat as corrupted file\n\t\t\t\t\t\t\t// Log to Sentry if available\n\t\t\t\t\t\t\tif (process.env.SENTRY_DSN && process.env.EPICSHOP_IS_PUBLISHED) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst Sentry = await import('@sentry/react-router')\n\t\t\t\t\t\t\t\t\tSentry.captureException(error, {\n\t\t\t\t\t\t\t\t\t\ttags: {\n\t\t\t\t\t\t\t\t\t\t\terror_type: 'corrupted_cache_file',\n\t\t\t\t\t\t\t\t\t\t\tcache_name: name,\n\t\t\t\t\t\t\t\t\t\t\tcache_key: key,\n\t\t\t\t\t\t\t\t\t\t\tretry_attempts: attempt.toString(),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\textra: {\n\t\t\t\t\t\t\t\t\t\t\tfilePath,\n\t\t\t\t\t\t\t\t\t\t\terrorMessage: error.message,\n\t\t\t\t\t\t\t\t\t\t\tcacheName: name,\n\t\t\t\t\t\t\t\t\t\t\tcacheKey: key,\n\t\t\t\t\t\t\t\t\t\t\tretryAttempts: attempt,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t} catch (sentryError) {\n\t\t\t\t\t\t\t\t\tconsole.error('Failed to log to Sentry:', sentryError)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Delete the corrupted file\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait fsExtra.remove(filePath)\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`Deleted corrupted cache file after ${attempt + 1} attempts: ${filePath}`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t} catch (deleteError) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t`Failed to delete corrupted cache file ${filePath}:`,\n\t\t\t\t\t\t\t\t\tdeleteError,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// For other errors, don't retry\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// This should never be reached, but just in case\n\t\t\t\treturn null\n\t\t\t},\n\t\t\tasync set(key, entry) {\n\t\t\t\tconst filePath = path.join(cacheDir, md5(key))\n\t\t\t\tawait fsExtra.ensureDir(path.dirname(filePath))\n\t\t\t\tawait fsExtra.writeJSON(filePath, { key, entry })\n\t\t\t},\n\t\t\tasync delete(key) {\n\t\t\t\tconst filePath = path.join(cacheDir, md5(key))\n\t\t\t\tawait fsExtra.remove(filePath)\n\t\t\t},\n\t\t}\n\n\t\treturn fsCache\n\t})\n}\n\n/**\n * This wraps @epic-web/cachified to add a few handy features:\n *\n * 1. Automatic timing for timing headers\n * 2. Automatic force refresh based on the request and enhancement of forceFresh\n * to support comma-separated keys to force\n * 3. Offline fallback support. If a fallback is given and we are detected to be\n * offline, then the cached value is used regardless of whether it's expired and\n * if one is not present then the given fallback will be used.\n */\nexport async function cachified<Value>({\n\trequest,\n\ttimings,\n\tkey,\n\ttimingKey = key.length > 18 ? `${key.slice(0, 7)}...${key.slice(-8)}` : key,\n\tofflineFallbackValue,\n\t...options\n}: Omit<C.CachifiedOptions<Value>, 'forceFresh'> & {\n\trequest?: Request\n\ttimings?: Timings\n\tforceFresh?: boolean | string\n\ttimingKey?: string\n\tofflineFallbackValue?: Value\n}): Promise<Value> {\n\tif (offlineFallbackValue !== undefined) {\n\t\tconst isOnline = await checkConnectionCached({ request, timings })\n\t\tif (!isOnline) {\n\t\t\tconst cacheEntry = await options.cache.get(key)\n\t\t\treturn cacheEntry?.value ?? offlineFallbackValue\n\t\t}\n\t}\n\tconst forceFresh = await shouldForceFresh({\n\t\tforceFresh: options.forceFresh,\n\t\trequest,\n\t\tkey,\n\t})\n\treturn C.cachified(\n\t\t{\n\t\t\t...options,\n\t\t\tkey,\n\t\t\tforceFresh,\n\t\t},\n\t\tC.mergeReporters(\n\t\t\tcachifiedTimingReporter(timings, timingKey),\n\t\t\tprocess.env.EPICSHOP_DEBUG_CACHE ? verboseReporter() : undefined,\n\t\t),\n\t)\n}\n\nexport async function shouldForceFresh({\n\tforceFresh,\n\trequest,\n\tkey,\n}: {\n\tforceFresh?: boolean | string\n\trequest?: Request\n\tkey?: string\n}) {\n\tif (typeof forceFresh === 'boolean') return forceFresh\n\tif (typeof forceFresh === 'string' && key) {\n\t\treturn forceFresh.split(',').includes(key)\n\t}\n\n\tif (!request) return false\n\tconst fresh = new URL(request.url).searchParams.get('fresh')\n\tif (typeof fresh !== 'string') return false\n\tif (fresh === '') return true\n\tif (!key) return false\n\n\treturn fresh.split(',').includes(key)\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-mdx.server.d.ts","sourceRoot":"","sources":["../../src/compile-mdx.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile-mdx.server.d.ts","sourceRoot":"","sources":["../../src/compile-mdx.server.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAsBtB,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAA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IAAkC;IACnE,MAAM,KAAK,GAAG,MAAM,QAAQ,EAAE,CAAA;IAC9B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IACxD,OAAO,MAAM,CAAA;AACd,CAAC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { rehypeCodeBlocksShiki } from '@kentcdodds/md-temp'\nimport { type Element, type Root as HastRoot } from 'hast'\nimport lz from 'lz-string'\nimport { type Root as MdastRoot } from 'mdast'\nimport { type MdxJsxFlowElement } from 'mdast-util-mdx-jsx'\nimport { bundleMDX } from 'mdx-bundler'\nimport PQueue from 'p-queue'\nimport rehypeAutolinkHeadings from 'rehype-autolink-headings'\nimport emoji from 'remark-emoji'\nimport gfm from 'remark-gfm'\nimport { type PluggableList } from 'unified'\nimport { visit } from 'unist-util-visit'\nimport {\n\tcachified,\n\tcompiledInstructionMarkdownCache,\n\tcompiledMarkdownCache,\n\tshouldForceFresh,\n} from './cache.server.js'\nimport { type Timings } from './timing.server.js'\nimport { checkConnectionCached } from './utils.server.js'\n\nfunction remarkMermaidCodeToSvg() {\n\treturn async (tree: MdastRoot) => {\n\t\tconst promises: Array<Promise<void>> = []\n\t\tvisit(tree, 'code', (node, index, parent) => {\n\t\t\tif (node.lang === 'mermaid' && parent && typeof index === 'number') {\n\t\t\t\tconst promise = (async () => {\n\t\t\t\t\tconst isConnected = await checkConnectionCached()\n\t\t\t\t\tif (isConnected) {\n\t\t\t\t\t\tconst compressed = lz.compressToEncodedURIComponent(node.value)\n\t\t\t\t\t\tconst url = `https://mermaid-to-svg.kentcdodds.workers.dev/svg?mermaid=${compressed}`\n\n\t\t\t\t\t\tconst timeout = AbortSignal.timeout(5000)\n\t\t\t\t\t\tconst svgResponse = await fetch(url, { signal: timeout }).catch(\n\t\t\t\t\t\t\t() => null,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (svgResponse?.ok) {\n\t\t\t\t\t\t\tconst svgText = await svgResponse.text()\n\t\t\t\t\t\t\tif (svgText) {\n\t\t\t\t\t\t\t\tparent.children[index] = {\n\t\t\t\t\t\t\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\t\t\t\t\t\t\tname: 'div',\n\t\t\t\t\t\t\t\t\tattributes: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttype: 'mdxJsxAttribute',\n\t\t\t\t\t\t\t\t\t\t\tname: 'className',\n\t\t\t\t\t\t\t\t\t\t\tvalue: 'mermaid not-prose',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttype: 'mdxJsxAttribute',\n\t\t\t\t\t\t\t\t\t\t\tname: 'dangerouslySetInnerHTML',\n\t\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'mdxJsxAttributeValueExpression',\n\t\t\t\t\t\t\t\t\t\t\t\tvalue: `{__html: ${JSON.stringify(svgText)}}`,\n\t\t\t\t\t\t\t\t\t\t\t\t// This hack brought to you by this: https://github.com/syntax-tree/hast-util-to-estree/blob/e5ccb97e9f42bba90359ea6d0f83a11d74e0dad6/lib/handlers/mdx-expression.js#L35-L38\n\t\t\t\t\t\t\t\t\t\t\t\t// no idea why we're required to have estree here, but I'm pretty sure someone is supposed to add it automatically for us and it just never happens...\n\t\t\t\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\t\t\t\testree: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Program',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsourceType: 'script',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'ExpressionStatement',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\texpression: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'ObjectExpression',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tproperties: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Property',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmethod: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tshorthand: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcomputed: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkind: 'init',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Identifier',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname: '__html',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: svgText,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t\t\t} satisfies MdxJsxFlowElement\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tparent.children[index] = {\n\t\t\t\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\t\t\t\tname: 'Mermaid',\n\t\t\t\t\t\tattributes: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'mdxJsxAttribute',\n\t\t\t\t\t\t\t\tname: 'code',\n\t\t\t\t\t\t\t\tvalue: node.value,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t} satisfies MdxJsxFlowElement\n\t\t\t\t})()\n\t\t\t\tpromises.push(promise)\n\t\t\t}\n\t\t})\n\t\tawait Promise.all(promises)\n\t}\n}\n\nfunction trimCodeBlocks() {\n\treturn async function transformer(tree: HastRoot) {\n\t\tvisit(tree, 'element', (preNode: Element) => {\n\t\t\tif (preNode.tagName !== 'pre' || !preNode.children.length) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst codeNode = preNode.children[0]\n\t\t\tif (\n\t\t\t\t!codeNode ||\n\t\t\t\tcodeNode.type !== 'element' ||\n\t\t\t\tcodeNode.tagName !== 'code'\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst [codeStringNode] = codeNode.children\n\t\t\tif (!codeStringNode) return\n\n\t\t\tif (codeStringNode.type !== 'text') {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`trimCodeBlocks: Unexpected: codeStringNode type is not \"text\": ${codeStringNode.type}`,\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcodeStringNode.value = codeStringNode.value.trimEnd()\n\t\t})\n\t}\n}\n\nfunction removePreContainerDivs() {\n\treturn async function preContainerDivsTransformer(tree: HastRoot) {\n\t\tvisit(\n\t\t\ttree,\n\t\t\t{ type: 'element', tagName: 'pre' },\n\t\t\tfunction visitor(node, index, parent) {\n\t\t\t\tif (parent?.type !== 'element') return\n\t\t\t\tif (parent.tagName !== 'div') return\n\t\t\t\tif (parent.children.length !== 1 && index === 0) return\n\t\t\t\tObject.assign(parent, node)\n\t\t\t},\n\t\t)\n\t}\n}\n\nconst rehypePlugins = [\n\t[rehypeAutolinkHeadings, { behavior: 'wrap' }],\n\ttrimCodeBlocks,\n\trehypeCodeBlocksShiki,\n\tremovePreContainerDivs,\n] satisfies PluggableList\n\nconst verboseLog =\n\tprocess.env.EPICSHOP_VERBOSE_LOG === 'true' ? console.log : () => {}\n\nexport async function compileMdx(\n\tfile: string,\n\t{\n\t\trequest,\n\t\ttimings,\n\t\tforceFresh,\n\t}: {\n\t\trequest?: Request\n\t\ttimings?: Timings\n\t\tforceFresh?: boolean\n\t} = {},\n) {\n\tconst stat = await fs.promises\n\t\t.stat(file)\n\t\t.catch((error: unknown) => ({ error }))\n\tif ('error' in stat) {\n\t\tthrow new Error(`File stat cannot be read: ${stat.error}`)\n\t}\n\n\tconst key = `file:${file}`\n\tforceFresh = await shouldForceFresh({ forceFresh, request, key })\n\n\tconst existingCacheEntry = await compiledInstructionMarkdownCache.get(key)\n\tif (!forceFresh && existingCacheEntry) {\n\t\tforceFresh = stat.mtimeMs > existingCacheEntry.metadata.createdTime\n\t}\n\n\treturn cachified({\n\t\tkey,\n\t\tcache: compiledInstructionMarkdownCache,\n\t\trequest,\n\t\ttimings,\n\t\tforceFresh,\n\t\tgetFreshValue: () => compileMdxImpl(file),\n\t})\n}\n\nasync function compileMdxImpl(file: string): Promise<{\n\tcode: string\n\ttitle: string | null\n\tepicVideoEmbeds: Array<string>\n}> {\n\tlet title: string | null = null\n\tconst epicVideoEmbeds: Array<string> = []\n\n\ttry {\n\t\tverboseLog(`Compiling ${file}`)\n\t\tconst bundleResult = await queuedBundleMDX({\n\t\t\tfile,\n\t\t\tcwd: path.dirname(file),\n\t\t\tmdxOptions(options) {\n\t\t\t\toptions.remarkPlugins = [\n\t\t\t\t\t...(options.remarkPlugins ?? []),\n\t\t\t\t\tgfm,\n\t\t\t\t\tremarkMermaidCodeToSvg,\n\t\t\t\t\t() => (tree: MdastRoot) => {\n\t\t\t\t\t\tvisit(tree, 'heading', (node) => {\n\t\t\t\t\t\t\tif (title) return\n\t\t\t\t\t\t\tif (node.depth === 1) {\n\t\t\t\t\t\t\t\tvisit(node, 'text', (textNode) => {\n\t\t\t\t\t\t\t\t\ttitle = textNode.value.trim()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\ttitle = title ? title.replace(/^\\d+\\. /, '').trim() : null\n\t\t\t\t\t},\n\t\t\t\t\t() => (tree: MdastRoot) => {\n\t\t\t\t\t\tvisit(tree, 'mdxJsxFlowElement', (jsxEl) => {\n\t\t\t\t\t\t\tif (jsxEl.name !== 'EpicVideo') return\n\t\t\t\t\t\t\tconst urlAttr = jsxEl.attributes.find(\n\t\t\t\t\t\t\t\t(a) => a.type === 'mdxJsxAttribute' && a.name === 'url',\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (!urlAttr) return\n\t\t\t\t\t\t\tlet url = urlAttr.value\n\t\t\t\t\t\t\tif (typeof url !== 'string') return\n\t\t\t\t\t\t\tif (url.endsWith('/')) url = url.slice(0, -1)\n\t\t\t\t\t\t\tepicVideoEmbeds.push(url)\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\temoji,\n\t\t\t\t]\n\t\t\t\toptions.rehypePlugins = [\n\t\t\t\t\t...(options.rehypePlugins ?? []),\n\t\t\t\t\t...rehypePlugins,\n\t\t\t\t]\n\t\t\t\toptions.mdxExtensions = ['.mdx', '.md']\n\t\t\t\toptions.format = 'mdx'\n\t\t\t\toptions.development = false\n\t\t\t\treturn options\n\t\t\t},\n\t\t})\n\t\tif (!bundleResult) throw new Error(`Timeout for file: ${file}`)\n\n\t\tconst result = { code: bundleResult.code, title, epicVideoEmbeds }\n\t\treturn result\n\t} catch (error: unknown) {\n\t\tconsole.error(`Compilation error for file: `, file, error)\n\t\tthrow error\n\t} finally {\n\t\tverboseLog(`Successfully compiled ${file}`)\n\t}\n}\n\nexport async function compileMarkdownString(markdownString: string) {\n\treturn cachified({\n\t\tkey: markdownString,\n\t\tcache: compiledMarkdownCache,\n\t\tttl: 1000 * 60 * 60 * 24,\n\t\tgetFreshValue: async () => {\n\t\t\ttry {\n\t\t\t\tverboseLog(`Compiling string`, markdownString)\n\t\t\t\tconst result = await queuedBundleMDX({\n\t\t\t\t\tsource: markdownString,\n\t\t\t\t\tmdxOptions(options) {\n\t\t\t\t\t\toptions.rehypePlugins = [\n\t\t\t\t\t\t\t...(options.rehypePlugins ?? []),\n\t\t\t\t\t\t\t...rehypePlugins,\n\t\t\t\t\t\t]\n\t\t\t\t\t\toptions.development = false\n\t\t\t\t\t\treturn options\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tif (!result) throw new Error(`Timed out compiling markdown string`)\n\n\t\t\t\treturn result.code\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconsole.error(`Compilation error for code: `, markdownString, error)\n\t\t\t\tthrow error\n\t\t\t} finally {\n\t\t\t\tverboseLog(`Successfully compiled string`, markdownString)\n\t\t\t}\n\t\t},\n\t})\n}\n\nlet _queue: PQueue | null = null\nasync function getQueue() {\n\tif (_queue) return _queue\n\n\t_queue = new PQueue({\n\t\tconcurrency: 1,\n\t\tthrowOnTimeout: true,\n\t\ttimeout: 1000 * 60,\n\t})\n\treturn _queue\n}\n\n// We have to use a queue because we can't run more than one of these at a time\n// or we'll hit an out of memory error because esbuild uses a lot of memory...\nasync function queuedBundleMDX(...args: Parameters<typeof bundleMDX>) {\n\tconst queue = await getQueue()\n\tconst result = await queue.add(() => bundleMDX(...args))\n\treturn result\n}\n"]}
|
|
1
|
+
{"version":3,"file":"compile-mdx.server.js","sourceRoot":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yBAChB,CAAA;wBACD,OAAO,CAAC,WAAW,GAAG,KAAK,CAAA;wBAC3B,OAAO,OAAO,CAAA;oBACf,CAAC;iBACD,CAAC,CAAA;gBACF,IAAI,CAAC,MAAM;oBAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;gBAEnE,OAAO,MAAM,CAAC,IAAI,CAAA;YACnB,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,cAAc,EAAE,KAAK,CAAC,CAAA;gBACpE,MAAM,KAAK,CAAA;YACZ,CAAC;oBAAS,CAAC;gBACV,UAAU,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;YAC3D,CAAC;QACF,CAAC;KACD,CAAC,CAAA;AACH,CAAC;AAED,IAAI,MAAM,GAAkB,IAAI,CAAA;AAChC,KAAK,UAAU,QAAQ;IACtB,IAAI,MAAM;QAAE,OAAO,MAAM,CAAA;IAEzB,MAAM,GAAG,IAAI,MAAM,CAAC;QACnB,WAAW,EAAE,CAAC;QACd,cAAc,EAAE,IAAI;QACpB,OAAO,EAAE,IAAI,GAAG,EAAE;KAClB,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACd,CAAC;AAED,+EAA+E;AAC/E,8EAA8E;AAC9E,KAAK,UAAU,eAAe,CAAC,GAAG,IAAkC;IACnE,MAAM,KAAK,GAAG,MAAM,QAAQ,EAAE,CAAA;IAC9B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IACxD,OAAO,MAAM,CAAA;AACd,CAAC","sourcesContent":["import './init-env.js'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { rehypeCodeBlocksShiki } from '@kentcdodds/md-temp'\nimport { type Element, type Root as HastRoot } from 'hast'\nimport lz from 'lz-string'\nimport { type Root as MdastRoot } from 'mdast'\nimport { type MdxJsxFlowElement } from 'mdast-util-mdx-jsx'\nimport { bundleMDX } from 'mdx-bundler'\nimport PQueue from 'p-queue'\nimport rehypeAutolinkHeadings from 'rehype-autolink-headings'\nimport emoji from 'remark-emoji'\nimport gfm from 'remark-gfm'\nimport { type PluggableList } from 'unified'\nimport { visit } from 'unist-util-visit'\nimport {\n\tcachified,\n\tcompiledInstructionMarkdownCache,\n\tcompiledMarkdownCache,\n\tshouldForceFresh,\n} from './cache.server.js'\nimport { type Timings } from './timing.server.js'\nimport { checkConnectionCached } from './utils.server.js'\n\nfunction remarkMermaidCodeToSvg() {\n\treturn async (tree: MdastRoot) => {\n\t\tconst promises: Array<Promise<void>> = []\n\t\tvisit(tree, 'code', (node, index, parent) => {\n\t\t\tif (node.lang === 'mermaid' && parent && typeof index === 'number') {\n\t\t\t\tconst promise = (async () => {\n\t\t\t\t\tconst isConnected = await checkConnectionCached()\n\t\t\t\t\tif (isConnected) {\n\t\t\t\t\t\tconst compressed = lz.compressToEncodedURIComponent(node.value)\n\t\t\t\t\t\tconst url = `https://mermaid-to-svg.kentcdodds.workers.dev/svg?mermaid=${compressed}`\n\n\t\t\t\t\t\tconst timeout = AbortSignal.timeout(5000)\n\t\t\t\t\t\tconst svgResponse = await fetch(url, { signal: timeout }).catch(\n\t\t\t\t\t\t\t() => null,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (svgResponse?.ok) {\n\t\t\t\t\t\t\tconst svgText = await svgResponse.text()\n\t\t\t\t\t\t\tif (svgText) {\n\t\t\t\t\t\t\t\tparent.children[index] = {\n\t\t\t\t\t\t\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\t\t\t\t\t\t\tname: 'div',\n\t\t\t\t\t\t\t\t\tattributes: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttype: 'mdxJsxAttribute',\n\t\t\t\t\t\t\t\t\t\t\tname: 'className',\n\t\t\t\t\t\t\t\t\t\t\tvalue: 'mermaid not-prose',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttype: 'mdxJsxAttribute',\n\t\t\t\t\t\t\t\t\t\t\tname: 'dangerouslySetInnerHTML',\n\t\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: 'mdxJsxAttributeValueExpression',\n\t\t\t\t\t\t\t\t\t\t\t\tvalue: `{__html: ${JSON.stringify(svgText)}}`,\n\t\t\t\t\t\t\t\t\t\t\t\t// This hack brought to you by this: https://github.com/syntax-tree/hast-util-to-estree/blob/e5ccb97e9f42bba90359ea6d0f83a11d74e0dad6/lib/handlers/mdx-expression.js#L35-L38\n\t\t\t\t\t\t\t\t\t\t\t\t// no idea why we're required to have estree here, but I'm pretty sure someone is supposed to add it automatically for us and it just never happens...\n\t\t\t\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\t\t\t\testree: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Program',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsourceType: 'script',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'ExpressionStatement',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\texpression: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'ObjectExpression',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tproperties: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Property',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmethod: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tshorthand: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcomputed: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkind: 'init',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Identifier',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname: '__html',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: svgText,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t\t\t} satisfies MdxJsxFlowElement\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tparent.children[index] = {\n\t\t\t\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\t\t\t\tname: 'Mermaid',\n\t\t\t\t\t\tattributes: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'mdxJsxAttribute',\n\t\t\t\t\t\t\t\tname: 'code',\n\t\t\t\t\t\t\t\tvalue: node.value,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t} satisfies MdxJsxFlowElement\n\t\t\t\t})()\n\t\t\t\tpromises.push(promise)\n\t\t\t}\n\t\t})\n\t\tawait Promise.all(promises)\n\t}\n}\n\nfunction trimCodeBlocks() {\n\treturn async function transformer(tree: HastRoot) {\n\t\tvisit(tree, 'element', (preNode: Element) => {\n\t\t\tif (preNode.tagName !== 'pre' || !preNode.children.length) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst codeNode = preNode.children[0]\n\t\t\tif (\n\t\t\t\t!codeNode ||\n\t\t\t\tcodeNode.type !== 'element' ||\n\t\t\t\tcodeNode.tagName !== 'code'\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst [codeStringNode] = codeNode.children\n\t\t\tif (!codeStringNode) return\n\n\t\t\tif (codeStringNode.type !== 'text') {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`trimCodeBlocks: Unexpected: codeStringNode type is not \"text\": ${codeStringNode.type}`,\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcodeStringNode.value = codeStringNode.value.trimEnd()\n\t\t})\n\t}\n}\n\nfunction removePreContainerDivs() {\n\treturn async function preContainerDivsTransformer(tree: HastRoot) {\n\t\tvisit(\n\t\t\ttree,\n\t\t\t{ type: 'element', tagName: 'pre' },\n\t\t\tfunction visitor(node, index, parent) {\n\t\t\t\tif (parent?.type !== 'element') return\n\t\t\t\tif (parent.tagName !== 'div') return\n\t\t\t\tif (parent.children.length !== 1 && index === 0) return\n\t\t\t\tObject.assign(parent, node)\n\t\t\t},\n\t\t)\n\t}\n}\n\nconst rehypePlugins = [\n\t[rehypeAutolinkHeadings, { behavior: 'wrap' }],\n\ttrimCodeBlocks,\n\trehypeCodeBlocksShiki,\n\tremovePreContainerDivs,\n] satisfies PluggableList\n\nconst verboseLog =\n\tprocess.env.EPICSHOP_VERBOSE_LOG === 'true' ? console.log : () => {}\n\nexport async function compileMdx(\n\tfile: string,\n\t{\n\t\trequest,\n\t\ttimings,\n\t\tforceFresh,\n\t}: {\n\t\trequest?: Request\n\t\ttimings?: Timings\n\t\tforceFresh?: boolean\n\t} = {},\n) {\n\tconst stat = await fs.promises\n\t\t.stat(file)\n\t\t.catch((error: unknown) => ({ error }))\n\tif ('error' in stat) {\n\t\tthrow new Error(`File stat cannot be read: ${stat.error}`)\n\t}\n\n\tconst key = `file:${file}`\n\tforceFresh = await shouldForceFresh({ forceFresh, request, key })\n\n\tconst existingCacheEntry = await compiledInstructionMarkdownCache.get(key)\n\tif (!forceFresh && existingCacheEntry) {\n\t\tforceFresh = stat.mtimeMs > existingCacheEntry.metadata.createdTime\n\t}\n\n\treturn cachified({\n\t\tkey,\n\t\tcache: compiledInstructionMarkdownCache,\n\t\trequest,\n\t\ttimings,\n\t\tforceFresh,\n\t\tgetFreshValue: () => compileMdxImpl(file),\n\t})\n}\n\nasync function compileMdxImpl(file: string): Promise<{\n\tcode: string\n\ttitle: string | null\n\tepicVideoEmbeds: Array<string>\n}> {\n\tlet title: string | null = null\n\tconst epicVideoEmbeds: Array<string> = []\n\n\ttry {\n\t\tverboseLog(`Compiling ${file}`)\n\t\tconst bundleResult = await queuedBundleMDX({\n\t\t\tfile,\n\t\t\tcwd: path.dirname(file),\n\t\t\tmdxOptions(options) {\n\t\t\t\toptions.remarkPlugins = [\n\t\t\t\t\t...(options.remarkPlugins ?? []),\n\t\t\t\t\tgfm,\n\t\t\t\t\tremarkMermaidCodeToSvg,\n\t\t\t\t\t() => (tree: MdastRoot) => {\n\t\t\t\t\t\tvisit(tree, 'heading', (node) => {\n\t\t\t\t\t\t\tif (title) return\n\t\t\t\t\t\t\tif (node.depth === 1) {\n\t\t\t\t\t\t\t\tvisit(node, 'text', (textNode) => {\n\t\t\t\t\t\t\t\t\ttitle = textNode.value.trim()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\ttitle = title ? title.replace(/^\\d+\\. /, '').trim() : null\n\t\t\t\t\t},\n\t\t\t\t\t() => (tree: MdastRoot) => {\n\t\t\t\t\t\tvisit(tree, 'mdxJsxFlowElement', (jsxEl) => {\n\t\t\t\t\t\t\tif (jsxEl.name !== 'EpicVideo') return\n\t\t\t\t\t\t\tconst urlAttr = jsxEl.attributes.find(\n\t\t\t\t\t\t\t\t(a) => a.type === 'mdxJsxAttribute' && a.name === 'url',\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (!urlAttr) return\n\t\t\t\t\t\t\tlet url = urlAttr.value\n\t\t\t\t\t\t\tif (typeof url !== 'string') return\n\t\t\t\t\t\t\tif (url.endsWith('/')) url = url.slice(0, -1)\n\t\t\t\t\t\t\tepicVideoEmbeds.push(url)\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\temoji,\n\t\t\t\t]\n\t\t\t\toptions.rehypePlugins = [\n\t\t\t\t\t...(options.rehypePlugins ?? []),\n\t\t\t\t\t...rehypePlugins,\n\t\t\t\t]\n\t\t\t\toptions.mdxExtensions = ['.mdx', '.md']\n\t\t\t\toptions.format = 'mdx'\n\t\t\t\toptions.development = false\n\t\t\t\treturn options\n\t\t\t},\n\t\t})\n\t\tif (!bundleResult) throw new Error(`Timeout for file: ${file}`)\n\n\t\tconst result = { code: bundleResult.code, title, epicVideoEmbeds }\n\t\treturn result\n\t} catch (error: unknown) {\n\t\tconsole.error(`Compilation error for file: `, file, error)\n\t\tthrow error\n\t} finally {\n\t\tverboseLog(`Successfully compiled ${file}`)\n\t}\n}\n\nexport async function compileMarkdownString(markdownString: string) {\n\treturn cachified({\n\t\tkey: markdownString,\n\t\tcache: compiledMarkdownCache,\n\t\tttl: 1000 * 60 * 60 * 24,\n\t\tgetFreshValue: async () => {\n\t\t\ttry {\n\t\t\t\tverboseLog(`Compiling string`, markdownString)\n\t\t\t\tconst result = await queuedBundleMDX({\n\t\t\t\t\tsource: markdownString,\n\t\t\t\t\tmdxOptions(options) {\n\t\t\t\t\t\toptions.rehypePlugins = [\n\t\t\t\t\t\t\t...(options.rehypePlugins ?? []),\n\t\t\t\t\t\t\t...rehypePlugins,\n\t\t\t\t\t\t]\n\t\t\t\t\t\toptions.development = false\n\t\t\t\t\t\treturn options\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tif (!result) throw new Error(`Timed out compiling markdown string`)\n\n\t\t\t\treturn result.code\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconsole.error(`Compilation error for code: `, markdownString, error)\n\t\t\t\tthrow error\n\t\t\t} finally {\n\t\t\t\tverboseLog(`Successfully compiled string`, markdownString)\n\t\t\t}\n\t\t},\n\t})\n}\n\nlet _queue: PQueue | null = null\nasync function getQueue() {\n\tif (_queue) return _queue\n\n\t_queue = new PQueue({\n\t\tconcurrency: 1,\n\t\tthrowOnTimeout: true,\n\t\ttimeout: 1000 * 60,\n\t})\n\treturn _queue\n}\n\n// We have to use a queue because we can't run more than one of these at a time\n// or we'll hit an out of memory error because esbuild uses a lot of memory...\nasync function queuedBundleMDX(...args: Parameters<typeof bundleMDX>) {\n\tconst queue = await getQueue()\n\tconst result = await queue.add(() => bundleMDX(...args))\n\treturn result\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const getWorkshopRoot: () => string;
|
|
3
2
|
export declare const StackBlitzConfigSchema: z.ZodObject<{
|
|
4
3
|
title: z.ZodOptional<z.ZodString>;
|
|
5
4
|
startScript: z.ZodOptional<z.ZodString>;
|
|
@@ -134,15 +133,15 @@ declare const WorkshopConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
134
133
|
expiresAt: z.ZodNullable<z.ZodDate>;
|
|
135
134
|
}, "strip", z.ZodTypeAny, {
|
|
136
135
|
message: string;
|
|
137
|
-
title: string;
|
|
138
136
|
type: "info" | "warning" | "danger";
|
|
137
|
+
title: string;
|
|
139
138
|
id: string;
|
|
140
139
|
expiresAt: Date | null;
|
|
141
140
|
link?: string | undefined;
|
|
142
141
|
}, {
|
|
143
142
|
message: string;
|
|
144
|
-
title: string;
|
|
145
143
|
type: "info" | "warning" | "danger";
|
|
144
|
+
title: string;
|
|
146
145
|
id: string;
|
|
147
146
|
expiresAt: Date | null;
|
|
148
147
|
link?: string | undefined;
|
|
@@ -171,8 +170,8 @@ declare const WorkshopConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
171
170
|
initialRoute: string;
|
|
172
171
|
notifications: {
|
|
173
172
|
message: string;
|
|
174
|
-
title: string;
|
|
175
173
|
type: "info" | "warning" | "danger";
|
|
174
|
+
title: string;
|
|
176
175
|
id: string;
|
|
177
176
|
expiresAt: Date | null;
|
|
178
177
|
link?: string | undefined;
|
|
@@ -245,8 +244,8 @@ declare const WorkshopConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
245
244
|
initialRoute?: string | undefined;
|
|
246
245
|
notifications?: {
|
|
247
246
|
message: string;
|
|
248
|
-
title: string;
|
|
249
247
|
type: "info" | "warning" | "danger";
|
|
248
|
+
title: string;
|
|
250
249
|
id: string;
|
|
251
250
|
expiresAt: Date | null;
|
|
252
251
|
link?: string | undefined;
|
|
@@ -275,8 +274,8 @@ declare const WorkshopConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
275
274
|
initialRoute: string;
|
|
276
275
|
notifications: {
|
|
277
276
|
message: string;
|
|
278
|
-
title: string;
|
|
279
277
|
type: "info" | "warning" | "danger";
|
|
278
|
+
title: string;
|
|
280
279
|
id: string;
|
|
281
280
|
expiresAt: Date | null;
|
|
282
281
|
link?: string | undefined;
|
|
@@ -349,8 +348,8 @@ declare const WorkshopConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
349
348
|
initialRoute?: string | undefined;
|
|
350
349
|
notifications?: {
|
|
351
350
|
message: string;
|
|
352
|
-
title: string;
|
|
353
351
|
type: "info" | "warning" | "danger";
|
|
352
|
+
title: string;
|
|
354
353
|
id: string;
|
|
355
354
|
expiresAt: Date | null;
|
|
356
355
|
link?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.server.d.ts","sourceRoot":"","sources":["../../src/config.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.server.d.ts","sourceRoot":"","sources":["../../src/config.server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;EAcjC,CAAA;AAUF,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkFvB,CAAA;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAiCjE;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,UAE1C;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAqClD;AAED,wBAAsB,gBAAgB,CAAC,EACtC,QAAQ,EACR,KAAK,EACL,IAAI,GACJ,EAAE;IACF,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACZ,0BA0EA;AAED,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;GA0ElD"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// eslint-disable-next-line import/order -- this must be first
|
|
2
|
+
import { ENV } from './init-env.js';
|
|
1
3
|
import fs from 'node:fs';
|
|
2
4
|
import path from 'node:path';
|
|
3
5
|
import { z } from 'zod';
|
|
4
6
|
import { handleGitHubRepoAndRoot } from './utils.js';
|
|
5
|
-
|
|
6
|
-
const getRootPkgJsonPath = () => path.join(getWorkshopRoot(), 'package.json');
|
|
7
|
+
const getRootPkgJsonPath = () => path.join(ENV.EPICSHOP_CONTEXT_CWD, 'package.json');
|
|
7
8
|
export const StackBlitzConfigSchema = z.object({
|
|
8
9
|
// we default this to `${exerciseTitle} (${type})`
|
|
9
10
|
title: z.string().optional(),
|
|
@@ -211,7 +212,7 @@ export async function getStackBlitzUrl({ fullPath, title, type, }) {
|
|
|
211
212
|
};
|
|
212
213
|
}
|
|
213
214
|
const params = new URLSearchParams(stackBlitzConfig);
|
|
214
|
-
const relativePath = fullPath.replace(`${
|
|
215
|
+
const relativePath = fullPath.replace(`${ENV.EPICSHOP_CONTEXT_CWD}${path.sep}`, '');
|
|
215
216
|
const stackBlitzUrl = new URL(`/github${githubPart}/${relativePath}?${params}`, 'https://stackblitz.com');
|
|
216
217
|
return stackBlitzUrl.toString();
|
|
217
218
|
}
|