Reduce the usage of require statements in code-paths not protected by pre-processor and/or run-time checks

This replaces some additional `require`/`exports` usage with standard `import`/`export` statements instead.
Hence another, small, part in the effort to reduce the reliance on SystemJS-specific functionality in the development viewer.
This commit is contained in:
Jonas Jenwald 2020-05-14 15:55:11 +02:00
parent 8b9492a5c4
commit ec0ab91a2b
4 changed files with 17 additions and 12 deletions

View File

@ -678,7 +678,7 @@ function isMessagePort(maybePort) {
); );
} }
// Worker thread (and not node.js)? // Worker thread (and not Node.js)?
if ( if (
typeof window === "undefined" && typeof window === "undefined" &&
!isNodeJS && !isNodeJS &&

View File

@ -13,10 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { isNodeJS } from "../shared/is_node.js";
const compatibilityParams = Object.create(null); const compatibilityParams = Object.create(null);
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
const { isNodeJS } = require("../shared/is_node.js");
const userAgent = const userAgent =
(typeof navigator !== "undefined" && navigator.userAgent) || ""; (typeof navigator !== "undefined" && navigator.userAgent) || "";
const isIE = /Trident/.test(userAgent); const isIE = /Trident/.test(userAgent);
@ -41,5 +41,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
} }
})(); })();
} }
const apiCompatibilityParams = Object.freeze(compatibilityParams);
exports.apiCompatibilityParams = Object.freeze(compatibilityParams); export { apiCompatibilityParams };

View File

@ -14,6 +14,8 @@
*/ */
/* eslint no-var: error */ /* eslint no-var: error */
import { isNodeJS } from "./is_node.js";
// Skip compatibility checks for modern builds and if we already ran the module. // Skip compatibility checks for modern builds and if we already ran the module.
if ( if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) && (typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) &&
@ -27,8 +29,6 @@ if (
} }
globalThis._pdfjsCompatibilityChecked = true; globalThis._pdfjsCompatibilityChecked = true;
const { isNodeJS } = require("./is_node.js");
const hasDOM = typeof window === "object" && typeof document === "object"; const hasDOM = typeof window === "object" && typeof document === "object";
const userAgent = const userAgent =
(typeof navigator !== "undefined" && navigator.userAgent) || ""; (typeof navigator !== "undefined" && navigator.userAgent) || "";
@ -248,15 +248,18 @@ if (
// Support: IE // Support: IE
(function checkURL() { (function checkURL() {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
// The current image decoders don't use the `URL` constructor, so it // Prevent "require is not a function" errors in development mode,
// doesn't need to be polyfilled for the IMAGE_DECODERS build target. // since the `URL` constructor should be available in modern browers.
return; return;
} } else if (!PDFJSDev.test("GENERIC")) {
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
// The `URL` constructor is assumed to be available in the extension // The `URL` constructor is assumed to be available in the extension
// builds. // builds.
return; return;
} else if (PDFJSDev.test("IMAGE_DECODERS")) {
// The current image decoders don't use the `URL` constructor, so it
// doesn't need to be polyfilled for the IMAGE_DECODERS build target.
return;
} }
globalThis.URL = require("core-js/web/url.js"); globalThis.URL = require("core-js/web/url.js");
})(); })();

View File

@ -35,5 +35,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
} }
})(); })();
} }
const viewerCompatibilityParams = Object.freeze(compatibilityParams);
exports.viewerCompatibilityParams = Object.freeze(compatibilityParams); export { viewerCompatibilityParams };