Skip to content

Commit 245cff2

Browse files
committed
Updated to support deno
1 parent 2353300 commit 245cff2

17 files changed

+37
-33
lines changed

cli/detectPDFType.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'fs';
1+
import fs from 'node:fs';
22
import scribe from '../scribe.js';
33

44
/**
@@ -30,5 +30,4 @@ export const detectPDFType = async (pdfFile, outputPath) => {
3030
console.log('PDF Type:', type);
3131

3232
mupdfScheduler.scheduler.terminate();
33-
3433
};

cli/extract.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
33
import scribe from '../scribe.js';
44

55
/**

cli/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Code for adding visualization to OCR output
22
// Use: `node addOverlay.js [PDF file] [OCR data file] [output directory]`
33

4-
import fs from 'fs';
5-
import path from 'path';
4+
import fs from 'node:fs';
5+
import path from 'node:path';
66

77
import scribe from '../scribe.js';
88

cli/require.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// While we will switch everything to worker modules eventually, Firefox still does not support them:
33
// https://developer.mozilla.org/en-US/docs/Web/API/Worker#browser_compatibility
44
// Therefore, we use a dynamic import statement to run the following code only in the Node.js version.
5-
const { createRequire } = await import('module');
5+
const { createRequire } = await import('node:module');
66
globalThis.require = createRequire(import.meta.url);
77
globalThis.__dirname = import.meta.url;

js/canvasAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class ca {
8080
} else {
8181
const dummyCanvas = await ca.dummyCanvasPromise;
8282

83-
const fs = await import('fs');
83+
const fs = await import('node:fs');
8484
const fontBuffer = typeof fontObj.src === 'string' ? fs.readFileSync(fontObj.src) : fontObj.src;
8585

8686
dummyCanvas.loadFont(fontBuffer, {

js/containers/fontContainer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ if (typeof process === 'object') {
1212
// @ts-ignore
1313
globalThis.self = globalThis;
1414
// @ts-ignore
15-
const { createRequire } = await import('module');
15+
const { createRequire } = await import('node:module');
1616
globalThis.require = createRequire(import.meta.url);
17-
const { fileURLToPath } = await import('url');
18-
const { dirname } = await import('path');
17+
const { fileURLToPath } = await import('node:url');
18+
const { dirname } = await import('node:path');
1919
globalThis.__dirname = dirname(fileURLToPath(import.meta.url));
2020
}
2121

js/fontContainerMain.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export async function loadBuiltInFontsRaw(glyphSet = 'latin') {
122122
gothicBoldItalic = fetch(new URL('../fonts/all/URWGothicBook-BoldItalic.woff', import.meta.url)).then((res) => res.arrayBuffer());
123123
}
124124
} else {
125-
const { readFile } = await import('fs/promises');
125+
const { readFile } = await import('node:fs/promises');
126126
carlitoNormal = readFile(new URL('../fonts/all/Carlito-Regular.woff', import.meta.url)).then((res) => res.buffer);
127127
carlitoItalic = readFile(new URL('../fonts/all/Carlito-Italic.woff', import.meta.url)).then((res) => res.buffer);
128128
carlitoBold = readFile(new URL('../fonts/all/Carlito-Bold.woff', import.meta.url)).then((res) => res.buffer);
@@ -212,7 +212,7 @@ export async function loadChiSimFont() {
212212
if (typeof process === 'undefined') {
213213
chiSimSrc = fetch(new URL('../fonts/NotoSansSC-Regular.ttf', import.meta.url)).then((res) => res.arrayBuffer());
214214
} else {
215-
const { readFile } = await import('fs/promises');
215+
const { readFile } = await import('node:fs/promises');
216216
chiSimSrc = readFile(new URL('../fonts/NotoSansSC-Regular.ttf', import.meta.url)).then((res) => res.buffer);
217217
}
218218

js/generalWorkerMain.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function initGeneralWorker() {
1212
if (typeof process === 'undefined') {
1313
worker = new Worker(new URL('./worker/generalWorker.js', import.meta.url), { type: 'module' });
1414
} else {
15-
const WorkerNode = (await import('worker_threads')).Worker;
15+
const WorkerNode = (await import('node:worker_threads')).Worker;
1616
worker = new WorkerNode(new URL('./worker/generalWorker.js', import.meta.url));
1717
}
1818

@@ -240,7 +240,7 @@ export class gs {
240240
} else if (typeof process === 'undefined') {
241241
workerN = Math.min(Math.round((globalThis.navigator.hardwareConcurrency || 8) / 2), 6);
242242
} else {
243-
const cpuN = Math.floor((await import('os')).cpus().length / 2);
243+
const cpuN = Math.floor((await import('node:os')).cpus().length / 2);
244244
workerN = Math.min(cpuN - 1, 8);
245245
}
246246

js/import/nodeAdapter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
33

44
// Note: Node.js 20 added a File class in the `buffer` module in Node.js 20.0.0,
55
// so this class can eventually be replaced with that.

js/utils/miscUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function countSubstringOccurrences(string, subString, allowOverlapping, c
321321
*/
322322
export const saveAs = async (content, fileName) => {
323323
if (typeof process !== 'undefined') {
324-
const { promises: fsPromises } = await import('fs');
324+
const { promises: fsPromises } = await import('node:fs');
325325
await fsPromises.writeFile(fileName, content);
326326
return;
327327
}

0 commit comments

Comments
 (0)