Skip to content

Commit

Permalink
♻️ Use node: imports for Node.js built-in modules
Browse files Browse the repository at this point in the history
Node.js supports importing built-in modules using `node:` URLs. These
imports are also supported by Deno and Bun. This commit updates all
imports of Node.js built-in modules to use `node:` URLs.
  • Loading branch information
ralfstx committed Dec 10, 2023
1 parent b990ed4 commit a5f131d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion examples/src/anchors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, writeFile } from 'fs/promises';
import { readFile, writeFile } from 'node:fs/promises';

import { makePdf } from 'pdfmkr';

const fontData = await readFile('./fonts/DejaVuSansCondensed.ttf');
Expand Down
3 changes: 2 additions & 1 deletion examples/src/graphics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, writeFile } from 'fs/promises';
import { readFile, writeFile } from 'node:fs/promises';

import { makePdf } from 'pdfmkr';

const fontData = await readFile('./fonts/DejaVuSansCondensed.ttf');
Expand Down
3 changes: 2 additions & 1 deletion examples/src/guides.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, writeFile } from 'fs/promises';
import { readFile, writeFile } from 'node:fs/promises';

import { makePdf } from 'pdfmkr';

const fontData = await readFile('./fonts/DejaVuSansCondensed.ttf');
Expand Down
3 changes: 2 additions & 1 deletion examples/src/images.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, writeFile } from 'fs/promises';
import { readFile, writeFile } from 'node:fs/promises';

import { makePdf } from 'pdfmkr';

const fontData = await readFile('./fonts/DejaVuSansCondensed.ttf');
Expand Down
3 changes: 2 additions & 1 deletion examples/src/text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, writeFile } from 'fs/promises';
import { readFile, writeFile } from 'node:fs/promises';

import { makePdf } from 'pdfmkr';

const fontData = await readFile('./fonts/DejaVuSansCondensed.ttf');
Expand Down
3 changes: 2 additions & 1 deletion src/api/make-pdf.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto from 'node:crypto';

import { describe, expect, it } from '@jest/globals';
import crypto from 'crypto';

import { makePdf } from './make-pdf.js';

Expand Down
11 changes: 6 additions & 5 deletions src/images.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import crypto from 'node:crypto';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';

import { describe, expect, it } from '@jest/globals';
import crypto from 'crypto';
import { readFileSync } from 'fs';
import { join } from 'path';

import { Image, readImages, registerImage } from './images.js';
import { fakePDFDocument, mkData } from './test/test-utils.js';
Expand Down Expand Up @@ -52,9 +53,9 @@ describe('images', () => {
});

describe('registerImage', () => {
it('embeds image in PDF document and attaches ref', () => {
it('embeds image in PDF document and attaches ref', async () => {
const doc = fakePDFDocument();
const data = readFileSync(join(__dirname, './test/resources/liberty.jpg'));
const data = await readFile(join(__dirname, './test/resources/liberty.jpg'));
const image: Image = { name: 'foo', format: 'jpeg', data, width: 100, height: 200 };

const pdfRef = registerImage(image, doc);
Expand Down
3 changes: 2 additions & 1 deletion src/render/render-document.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto from 'node:crypto';

import { describe, expect, it } from '@jest/globals';
import crypto from 'crypto';
import { PDFDict, PDFDocument, PDFHexString, PDFName, PDFStream, PDFString } from 'pdf-lib';

import { renderDocument } from './render-document.js';
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PDFContext, PDFDocument, PDFFont, PDFName, PDFPage, PDFRef } from 'pdf-lib';

import { Font, weightToNumber } from '../fonts.js';
import { Image } from '../images.js';
import { Frame } from '../frame.js';
import { Image } from '../images.js';
import { Page } from '../page.js';
import { TextAttrs, TextSpan } from '../read-block.js';

Expand Down

0 comments on commit a5f131d

Please sign in to comment.