Skip to content

Commit dc3f2c4

Browse files
committed
Try wrapping the ESM stuff
1 parent 128aa68 commit dc3f2c4

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

lib/nanoid-wrapper.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { customAlphabet } from 'nanoid';
2+
3+
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
4+
const generate = customAlphabet(alphabet, 5);
5+
6+
export function generateId() {
7+
return generate();
8+
}

lib/svgdom-wrapper.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Pure ESM file
2+
import { createSVGWindow } from 'svgdom';
3+
4+
export function makeWindow() {
5+
const window = createSVGWindow();
6+
return window;
7+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
34+
"typeRoots": ["./types/*"], /* Specify multiple folders that act like './node_modules/@types'. */
3535
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
3636
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
3737
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */

types/types.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// types.d.ts
2+
declare module '../lib/svgdom-wrapper.mjs' {
3+
import type { Window } from 'svgdom';
4+
export function makeWindow(): Window;
5+
}
6+
7+
declare module '../lib/nanoid-wrapper.mjs' {
8+
export function generateId(): string;
9+
}

utils/thumbnails.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ type SamplerEntry = {
5151
completed: ReservoirSampler<GameRec>;
5252
}
5353

54-
async function makeIdGenerator() {
55-
// Dynamically import nanoid
56-
const { customAlphabet } = await import('nanoid');
57-
58-
// Create a generator with your custom alphabet
59-
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
60-
const length = 5;
61-
62-
const generate = customAlphabet(alphabet, length);
63-
64-
return generate;
65-
}
66-
6754
export const handler: Handler = async (event: any, context?: any) => {
6855
await (i18n
6956
.init({
@@ -309,10 +296,11 @@ export const handler: Handler = async (event: any, context?: any) => {
309296
["light", contextLight],
310297
["dark", contextDark],
311298
]);
312-
const generateId = await makeIdGenerator();
313-
const svgdom = await import('svgdom');
314-
const { createSVGWindow } = svgdom;
315-
const window = createSVGWindow();
299+
// Dynamically import the ESM wrapper
300+
const { makeWindow } = await import('../lib/svgdom-wrapper.mjs');
301+
// Example: generate an ID using nanoid wrapper
302+
const { generateId } = await import('../lib/nanoid-wrapper.mjs');
303+
const window = makeWindow();
316304
const document = window.document;
317305

318306
// register window and document

0 commit comments

Comments
 (0)