Skip to content

Commit 2cb54ec

Browse files
agoose77rowanc1
andauthored
🤖 Update our TS config and bundler versions (#2499)
Co-authored-by: Rowan Cockett <[email protected]>
1 parent afb68b1 commit 2cb54ec

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

.changeset/chilly-mugs-look.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'mystmd': minor
3+
'tsconfig': patch
4+
---
5+
6+
Target Node18

packages/myst-to-docx/src/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const plugin: Plugin<[Options], Root, VFile> = function (opts) {
1111
const state = new DocxSerializer(file, opts);
1212
state.renderChildren(node);
1313
const doc = createDocFromState(state);
14+
// @ts-expect-error document is not defined in node
1415
if (typeof document === 'undefined') {
1516
file.result = Packer.toBuffer(doc);
1617
} else {

packages/myst-to-docx/src/utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,20 @@ export function getImageWidth(width?: number | string, maxWidth = MAX_DOCX_IMAGE
8686
return (lineWidth / 100) * maxWidth;
8787
}
8888

89-
async function getImageDimensions(file: Blob | Buffer): Promise<{ width: number; height: number }> {
89+
/**
90+
* Get the dimensions of an image using the browser's `Image` object.
91+
* @param file - The image file.
92+
* @returns The dimensions of the image.
93+
* @note This is a browser only function, server side this function should return undefined
94+
* and the `buffer-image-size` package should be used to get the dimensions.
95+
*/
96+
async function getImageDimensions(
97+
file: Blob | Buffer,
98+
): Promise<{ width: number; height: number } | undefined> {
99+
// @ts-expect-error Image is not defined
100+
if (typeof Image === 'undefined') return undefined;
90101
return new Promise((resolve, reject) => {
102+
// @ts-expect-error Image not defined
91103
const img = new Image();
92104
// the following handler will fire after a successful loading of the image
93105
img.onload = () => {
@@ -120,7 +132,10 @@ export async function fetchImagesAsBuffers(
120132
const response = await fetch(image.url);
121133
const blob = await response.blob();
122134
const buffer = await blob.arrayBuffer();
123-
dimensions[image.url] = await getImageDimensions(blob);
135+
const dims = await getImageDimensions(blob);
136+
if (dims !== undefined) {
137+
dimensions[image.url] = dims;
138+
}
124139
buffers[image.url] = Buffer.from(buffer);
125140
}),
126141
);

packages/mystmd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"lint:format": "npm run copy:version; prettier --check \"src/**/*.ts\"",
3838
"test": "npm run link; npm run copy:version; vitest run",
3939
"test:watch": "npm run link; npm run copy:version; vitest watch",
40-
"build:cli": "esbuild src/index.ts --bundle --outfile=dist/myst.cjs --platform=node --external:fsevents --target=node14",
40+
"build:cli": "esbuild src/index.ts --bundle --outfile=dist/myst.cjs --platform=node --external:fsevents --target=node18",
4141
"build": "npm-run-all -l clean copy:version -p build:cli"
4242
},
4343
"devDependencies": {

packages/tsconfig/base.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
"composite": false,
66
"declaration": true,
77
"declarationMap": true,
8-
"target": "ES2019",
8+
"target": "es2022",
99
"esModuleInterop": true,
1010
"forceConsistentCasingInFileNames": true,
1111
"inlineSources": false,
1212
"isolatedModules": true,
13-
"module": "Node16",
14-
"moduleResolution": "Node16",
13+
"lib": ["es2022"],
14+
"module": "node18",
15+
"moduleResolution": "node16",
1516
"allowSyntheticDefaultImports": true,
1617
"noUnusedLocals": false,
1718
"noUnusedParameters": false,
1819
"preserveWatchOutput": true,
1920
"skipLibCheck": true,
2021
"strict": true,
21-
"lib": ["es2021", "DOM"],
2222
"typeRoots": [
2323
"./types",
2424
"./node_modules/@types",

0 commit comments

Comments
 (0)