Move the isNodeJS-helper into the src/shared/util.js file

With the changes in the previous patch the `isNodeJS`-helper no longer needs to live in its own file, which helps get rid of a closure in the *built* files.
This commit is contained in:
Jonas Jenwald 2023-07-17 16:33:06 +02:00
parent 67303b16f1
commit 3a886e7264
19 changed files with 34 additions and 48 deletions

View File

@ -19,6 +19,7 @@ import {
getVerbosityLevel, getVerbosityLevel,
info, info,
InvalidPDFException, InvalidPDFException,
isNodeJS,
MissingPDFException, MissingPDFException,
PasswordException, PasswordException,
PromiseCapability, PromiseCapability,
@ -39,7 +40,6 @@ import { LocalPdfManager, NetworkPdfManager } from "./pdf_manager.js";
import { AnnotationFactory } from "./annotation.js"; import { AnnotationFactory } from "./annotation.js";
import { clearGlobalCaches } from "./cleanup_helper.js"; import { clearGlobalCaches } from "./cleanup_helper.js";
import { incrementalUpdate } from "./writer.js"; import { incrementalUpdate } from "./writer.js";
import { isNodeJS } from "../shared/is_node.js";
import { MessageHandler } from "../shared/message_handler.js"; import { MessageHandler } from "../shared/message_handler.js";
import { PDFWorkerStream } from "./worker_stream.js"; import { PDFWorkerStream } from "./worker_stream.js";

View File

@ -25,6 +25,7 @@ import {
info, info,
InvalidPDFException, InvalidPDFException,
isArrayBuffer, isArrayBuffer,
isNodeJS,
MAX_IMAGE_SIZE_TO_CACHE, MAX_IMAGE_SIZE_TO_CACHE,
MissingPDFException, MissingPDFException,
PasswordException, PasswordException,
@ -59,7 +60,6 @@ import {
import { FontFaceObject, FontLoader } from "./font_loader.js"; import { FontFaceObject, FontLoader } from "./font_loader.js";
import { CanvasGraphics } from "./canvas.js"; import { CanvasGraphics } from "./canvas.js";
import { GlobalWorkerOptions } from "./worker_options.js"; import { GlobalWorkerOptions } from "./worker_options.js";
import { isNodeJS } from "../shared/is_node.js";
import { MessageHandler } from "../shared/message_handler.js"; import { MessageHandler } from "../shared/message_handler.js";
import { Metadata } from "./metadata.js"; import { Metadata } from "./metadata.js";
import { OptionalContentConfig } from "./optional_content_config.js"; import { OptionalContentConfig } from "./optional_content_config.js";

View File

@ -19,6 +19,7 @@ import {
IDENTITY_MATRIX, IDENTITY_MATRIX,
ImageKind, ImageKind,
info, info,
isNodeJS,
OPS, OPS,
shadow, shadow,
TextRenderingMode, TextRenderingMode,
@ -37,7 +38,6 @@ import {
TilingPattern, TilingPattern,
} from "./pattern_helper.js"; } from "./pattern_helper.js";
import { convertBlackAndWhiteToRGBA } from "../shared/image_utils.js"; import { convertBlackAndWhiteToRGBA } from "../shared/image_utils.js";
import { isNodeJS } from "../shared/is_node.js";
// <canvas> contexts store most of the state we need natively. // <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here. // However, PDF needs a bit more state, which we store here.

View File

@ -17,12 +17,12 @@ import {
assert, assert,
bytesToString, bytesToString,
FeatureTest, FeatureTest,
isNodeJS,
shadow, shadow,
string32, string32,
unreachable, unreachable,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
import { isNodeJS } from "../shared/is_node.js";
class FontLoader { class FontLoader {
#systemFonts = new Set(); #systemFonts = new Set();

View File

@ -20,7 +20,7 @@ import {
BaseFilterFactory, BaseFilterFactory,
BaseStandardFontDataFactory, BaseStandardFontDataFactory,
} from "./base_factory.js"; } from "./base_factory.js";
import { isNodeJS } from "../shared/is_node.js"; import { isNodeJS } from "../shared/util.js";
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error( throw new Error(

View File

@ -19,12 +19,12 @@ import {
FONT_IDENTITY_MATRIX, FONT_IDENTITY_MATRIX,
IDENTITY_MATRIX, IDENTITY_MATRIX,
ImageKind, ImageKind,
isNodeJS,
OPS, OPS,
TextRenderingMode, TextRenderingMode,
Util, Util,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
import { isNodeJS } from "../shared/is_node.js";
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) { if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
throw new Error( throw new Error(

View File

@ -1,28 +0,0 @@
/* Copyright 2018 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals process */
// NW.js / Electron is a browser context, but copies some Node.js objects; see
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
// https://www.electronjs.org/docs/api/process#processversionselectron-readonly
// https://www.electronjs.org/docs/api/process#processtype-readonly
const isNodeJS =
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
typeof process === "object" &&
process + "" === "[object process]" &&
!process.versions.nw &&
!(process.versions.electron && process.type && process.type !== "browser");
export { isNodeJS };

View File

@ -12,6 +12,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals process */
// NW.js / Electron is a browser context, but copies some Node.js objects; see
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
// https://www.electronjs.org/docs/api/process#processversionselectron-readonly
// https://www.electronjs.org/docs/api/process#processtype-readonly
const isNodeJS =
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
typeof process === "object" &&
process + "" === "[object process]" &&
!process.versions.nw &&
!(process.versions.electron && process.type && process.type !== "browser");
const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
@ -1056,6 +1068,7 @@ export {
InvalidPDFException, InvalidPDFException,
isArrayBuffer, isArrayBuffer,
isArrayEqual, isArrayEqual,
isNodeJS,
LINE_DESCENT_FACTOR, LINE_DESCENT_FACTOR,
LINE_FACTOR, LINE_FACTOR,
MAX_IMAGE_SIZE_TO_CACHE, MAX_IMAGE_SIZE_TO_CACHE,

View File

@ -19,6 +19,7 @@ import {
AnnotationType, AnnotationType,
ImageKind, ImageKind,
InvalidPDFException, InvalidPDFException,
isNodeJS,
MissingPDFException, MissingPDFException,
objectSize, objectSize,
OPS, OPS,
@ -53,7 +54,6 @@ import {
import { AutoPrintRegExp } from "../../web/ui_utils.js"; import { AutoPrintRegExp } from "../../web/ui_utils.js";
import { GlobalImageCache } from "../../src/core/image_utils.js"; import { GlobalImageCache } from "../../src/core/image_utils.js";
import { GlobalWorkerOptions } from "../../src/display/worker_options.js"; import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
import { isNodeJS } from "../../src/shared/is_node.js";
import { Metadata } from "../../src/display/metadata.js"; import { Metadata } from "../../src/display/metadata.js";
describe("api", function () { describe("api", function () {

View File

@ -13,8 +13,11 @@
* limitations under the License. * limitations under the License.
*/ */
import { setVerbosityLevel, VerbosityLevel } from "../../src/shared/util.js"; import {
import { isNodeJS } from "../../src/shared/is_node.js"; isNodeJS,
setVerbosityLevel,
VerbosityLevel,
} from "../../src/shared/util.js";
// Sets longer timeout, similar to `jasmine-boot.js`. // Sets longer timeout, similar to `jasmine-boot.js`.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

View File

@ -16,7 +16,7 @@
import { buildGetDocumentParams } from "./test_utils.js"; import { buildGetDocumentParams } from "./test_utils.js";
import { getDocument } from "../../src/display/api.js"; import { getDocument } from "../../src/display/api.js";
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
import { SVGGraphics } from "../../src/display/svg.js"; import { SVGGraphics } from "../../src/display/svg.js";
const XLINK_NS = "http://www.w3.org/1999/xlink"; const XLINK_NS = "http://www.w3.org/1999/xlink";

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { bytesToString, isNodeJS } from "../../src/shared/util.js";
import { import {
DOMCanvasFactory, DOMCanvasFactory,
DOMSVGFactory, DOMSVGFactory,
@ -21,8 +22,6 @@ import {
isValidFetchUrl, isValidFetchUrl,
PDFDateString, PDFDateString,
} from "../../src/display/display_utils.js"; } from "../../src/display/display_utils.js";
import { bytesToString } from "../../src/shared/util.js";
import { isNodeJS } from "../../src/shared/is_node.js";
describe("display_utils", function () { describe("display_utils", function () {
describe("DOMCanvasFactory", function () { describe("DOMCanvasFactory", function () {

View File

@ -18,7 +18,7 @@ import {
waitOnEventOrTimeout, waitOnEventOrTimeout,
WaitOnType, WaitOnType,
} from "../../web/event_utils.js"; } from "../../web/event_utils.js";
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
describe("event_utils", function () { describe("event_utils", function () {
describe("EventBus", function () { describe("EventBus", function () {

View File

@ -41,7 +41,7 @@
"use strict"; "use strict";
import { GlobalWorkerOptions } from "pdfjs/display/worker_options.js"; import { GlobalWorkerOptions } from "pdfjs/display/worker_options.js";
import { isNodeJS } from "pdfjs/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
import { TestReporter } from "./testreporter.js"; import { TestReporter } from "./testreporter.js";
async function initializePDFJS(callback) { async function initializePDFJS(callback) {

View File

@ -14,8 +14,7 @@
*/ */
/* globals __non_webpack_require__ */ /* globals __non_webpack_require__ */
import { AbortException } from "../../src/shared/util.js"; import { AbortException, isNodeJS } from "../../src/shared/util.js";
import { isNodeJS } from "../../src/shared/is_node.js";
import { PDFNodeStream } from "../../src/display/node_stream.js"; import { PDFNodeStream } from "../../src/display/node_stream.js";
// Ensure that these tests only run in Node.js environments. // Ensure that these tests only run in Node.js environments.

View File

@ -17,7 +17,7 @@ import { FindState, PDFFindController } from "../../web/pdf_find_controller.js";
import { buildGetDocumentParams } from "./test_utils.js"; import { buildGetDocumentParams } from "./test_utils.js";
import { EventBus } from "../../web/event_utils.js"; import { EventBus } from "../../web/event_utils.js";
import { getDocument } from "../../src/display/api.js"; import { getDocument } from "../../src/display/api.js";
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
import { SimpleLinkService } from "../../web/pdf_link_service.js"; import { SimpleLinkService } from "../../web/pdf_link_service.js";
const tracemonkeyFileName = "tracemonkey.pdf"; const tracemonkeyFileName = "tracemonkey.pdf";

View File

@ -15,7 +15,7 @@
import { NullStream, StringStream } from "../../src/core/stream.js"; import { NullStream, StringStream } from "../../src/core/stream.js";
import { Page, PDFDocument } from "../../src/core/document.js"; import { Page, PDFDocument } from "../../src/core/document.js";
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
import { Ref } from "../../src/core/primitives.js"; import { Ref } from "../../src/core/primitives.js";
const TEST_PDFS_PATH = isNodeJS ? "./test/pdfs/" : "../pdfs/"; const TEST_PDFS_PATH = isNodeJS ? "./test/pdfs/" : "../pdfs/";

View File

@ -19,7 +19,7 @@ import {
} from "../../src/display/text_layer.js"; } from "../../src/display/text_layer.js";
import { buildGetDocumentParams } from "./test_utils.js"; import { buildGetDocumentParams } from "./test_utils.js";
import { getDocument } from "../../src/display/api.js"; import { getDocument } from "../../src/display/api.js";
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
describe("textLayer", function () { describe("textLayer", function () {
it("creates textLayer from ReadableStream", async function () { it("creates textLayer from ReadableStream", async function () {

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/util.js";
import { XFAFactory } from "../../src/core/xfa/factory.js"; import { XFAFactory } from "../../src/core/xfa/factory.js";
describe("XFAFactory", function () { describe("XFAFactory", function () {