1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[api-minor] Load Node.js packages/polyfills with process.getBuiltinModule

This allows *synchronous* loading of Node.js modules and (indirectly) packages, thus simplifying the code a fair bit.
This commit is contained in:
Jonas Jenwald 2024-06-12 11:19:51 +02:00
parent 4f01cdef18
commit c7407230c1
7 changed files with 61 additions and 110 deletions

View file

@ -18,7 +18,6 @@ import {
setVerbosityLevel,
VerbosityLevel,
} from "../../src/shared/util.js";
import { NodePackages } from "../../src/display/node_utils.js";
// Sets longer timeout, similar to `jasmine-boot.js`.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
@ -30,9 +29,6 @@ if (!isNodeJS) {
);
}
// Ensure that all Node.js packages/polyfills have loaded.
await NodePackages.promise;
// Reduce the amount of console "spam", by ignoring `info`/`warn` calls,
// when running the unit-tests in Node.js/Travis.
setVerbosityLevel(VerbosityLevel.ERRORS);

View file

@ -24,11 +24,10 @@ if (!isNodeJS) {
);
}
const url = await __non_webpack_import__("url");
describe("node_stream", function () {
let tempServer = null;
const url = process.getBuiltinModule("url");
const cwdURL = url.pathToFileURL(process.cwd()) + "/";
const pdf = new URL("./test/pdfs/tracemonkey.pdf", cwdURL).href;
const pdfLength = 1016315;

View file

@ -20,13 +20,6 @@ import { fetchData as fetchDataDOM } from "../../src/display/display_utils.js";
import { fetchData as fetchDataNode } from "../../src/display/node_utils.js";
import { Ref } from "../../src/core/primitives.js";
let fs, http;
if (isNodeJS) {
// Native packages.
fs = await __non_webpack_import__("fs");
http = await __non_webpack_import__("http");
}
const TEST_PDFS_PATH = isNodeJS ? "./test/pdfs/" : "../pdfs/";
const CMAP_URL = isNodeJS ? "./external/bcmaps/" : "../../external/bcmaps/";
@ -132,6 +125,8 @@ function createIdFactory(pageIndex) {
function createTemporaryNodeServer() {
assert(isNodeJS, "Should only be used in Node.js environments.");
const fs = process.getBuiltinModule("fs"),
http = process.getBuiltinModule("http");
// Create http server to serve pdf data for tests.
const server = http
.createServer((request, response) => {