Skip to content

Improve how the PDF.js version/commit information is exposed in the *built* files #19956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ function createWebpackConfig(
const licenseHeaderLibre = fs
.readFileSync("./src/license_header_libre.js")
.toString();
const versionInfoHeader = [
"/**",
` * pdfjsVersion = ${versionInfo.version}`,
` * pdfjsBuild = ${versionInfo.commit}`,
" */",
].join("\n");
const enableSourceMaps =
!bundleDefines.MOZCENTRAL &&
!bundleDefines.CHROME &&
Expand Down Expand Up @@ -335,7 +341,10 @@ function createWebpackConfig(
const plugins = [];
if (!disableLicenseHeader) {
plugins.push(
new webpack2.BannerPlugin({ banner: licenseHeaderLibre, raw: true })
new webpack2.BannerPlugin({
banner: licenseHeaderLibre + "\n" + versionInfoHeader,
raw: true,
})
);
}
plugins.push({
Expand Down Expand Up @@ -389,7 +398,7 @@ function createWebpackConfig(
sequences: false,
},
format: {
comments: /@lic|webpackIgnore|@vite-ignore/i,
comments: /@lic|webpackIgnore|@vite-ignore|pdfjsVersion/i,
},
keep_classnames: true,
keep_fnames: true,
Expand Down
7 changes: 0 additions & 7 deletions src/pdf.image_decoders.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ import { Jbig2Error, Jbig2Image } from "./core/jbig2.js";
import { JpegError, JpegImage } from "./core/jpg.js";
import { JpxError, JpxImage } from "./core/jpx.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

globalThis.pdfjsImageDecoders = {
getVerbosityLevel,
Jbig2Error,
Expand Down
9 changes: 1 addition & 8 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ import { TextLayer } from "./display/text_layer.js";
import { TouchManager } from "./display/touch_manager.js";
import { XfaLayer } from "./display/xfa_layer.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING || GENERIC")) {
globalThis.pdfjsTestingUtils = {
globalThis._pdfjsTestingUtils = {
HighlightOutliner,
};
}
Expand Down
5 changes: 0 additions & 5 deletions src/pdf.sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
import ModuleLoader from "../external/quickjs/quickjs-eval.js";
import { SandboxSupportBase } from "./pdf.sandbox.external.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION");
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD");

class SandboxSupport extends SandboxSupportBase {
exportValueToSandbox(val) {
// The communication with the Quickjs sandbox is based on strings
Expand Down
7 changes: 0 additions & 7 deletions src/pdf.scripting.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

import { initSandbox } from "./scripting_api/initialization.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

// To avoid problems with `export` statements in the QuickJS Javascript Engine,
// we manually expose `pdfjsScripting` globally instead.
globalThis.pdfjsScripting = { initSandbox };
7 changes: 0 additions & 7 deletions src/pdf.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

import { WorkerMessageHandler } from "./core/worker.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

globalThis.pdfjsWorker = {
WorkerMessageHandler,
};
Expand Down
4 changes: 2 additions & 2 deletions test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals pdfjsLib, pdfjsTestingUtils, pdfjsViewer */
/* globals pdfjsLib, _pdfjsTestingUtils, pdfjsViewer */

const {
AnnotationLayer,
Expand All @@ -26,7 +26,7 @@ const {
TextLayer,
XfaLayer,
} = pdfjsLib;
const { HighlightOutliner } = pdfjsTestingUtils;
const { HighlightOutliner } = _pdfjsTestingUtils;
const { GenericL10n, parseQueryString, SimpleLinkService } = pdfjsViewer;

const WAITING_TIME = 100; // ms
Expand Down
7 changes: 0 additions & 7 deletions web/pdf_viewer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
import { TextLayerBuilder } from "./text_layer_builder.js";
import { XfaLayerBuilder } from "./xfa_layer_builder.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

globalThis.pdfjsViewer = {
AnnotationLayerBuilder,
DownloadManager,
Expand Down
7 changes: 0 additions & 7 deletions web/viewer-geckoview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import { AppOptions } from "./app_options.js";
import { LinkTarget } from "./pdf_link_service.js";
import { PDFViewerApplication } from "./app.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

const AppConstants =
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
Expand Down
7 changes: 0 additions & 7 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import { AppOptions } from "./app_options.js";
import { LinkTarget } from "./pdf_link_service.js";
import { PDFViewerApplication } from "./app.js";

/* eslint-disable-next-line no-unused-vars */
const pdfjsVersion =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild =
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;

const AppConstants =
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
Expand Down