Skip to content

Commit 6bbe81a

Browse files
committed
Improve the PDF.js version/commit information is exposed in the *built* files
To make it easier to tell which PDF.js version/commit that the *built* files correspond to, they have (since many years) included `pdfjsVersion` and `pdfjsBuild` constants with that information. As currently implemented this has a few shortcomings: - It requires manually adding the code, with its preprocessor statements, in all relevant files. - It requires ESLint disable statements, since it's obviously unused code. - Being unused, this code is removed in the minified builds. - This information would be more appropriate as comments, however Babel discards all comments during building. - It would be helpful to have this information at the top of the *built* files, however it's being moved during building. To address all of these issues, we'll instead utilize Webpack to insert the version/commit information as a comment placed just after license header.
1 parent 819671d commit 6bbe81a

10 files changed

+14
-59
lines changed

gulpfile.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ function createWebpackConfig(
302302
const licenseHeaderLibre = fs
303303
.readFileSync("./src/license_header_libre.js")
304304
.toString();
305+
const versionInfoHeader = [
306+
"/**",
307+
` * pdfjsVersion = ${versionInfo.version}`,
308+
` * pdfjsBuild = ${versionInfo.commit}`,
309+
" */",
310+
].join("\n");
305311
const enableSourceMaps =
306312
!bundleDefines.MOZCENTRAL &&
307313
!bundleDefines.CHROME &&
@@ -335,7 +341,10 @@ function createWebpackConfig(
335341
const plugins = [];
336342
if (!disableLicenseHeader) {
337343
plugins.push(
338-
new webpack2.BannerPlugin({ banner: licenseHeaderLibre, raw: true })
344+
new webpack2.BannerPlugin({
345+
banner: licenseHeaderLibre + "\n" + versionInfoHeader,
346+
raw: true,
347+
})
339348
);
340349
}
341350
plugins.push({
@@ -389,7 +398,7 @@ function createWebpackConfig(
389398
sequences: false,
390399
},
391400
format: {
392-
comments: /@lic|webpackIgnore|@vite-ignore/i,
401+
comments: /@lic|webpackIgnore|@vite-ignore|pdfjsVersion/i,
393402
},
394403
keep_classnames: true,
395404
keep_fnames: true,

src/pdf.image_decoders.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ import { Jbig2Error, Jbig2Image } from "./core/jbig2.js";
2222
import { JpegError, JpegImage } from "./core/jpg.js";
2323
import { JpxError, JpxImage } from "./core/jpx.js";
2424

25-
/* eslint-disable-next-line no-unused-vars */
26-
const pdfjsVersion =
27-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
28-
/* eslint-disable-next-line no-unused-vars */
29-
const pdfjsBuild =
30-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
31-
3225
globalThis.pdfjsImageDecoders = {
3326
getVerbosityLevel,
3427
Jbig2Error,

src/pdf.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,8 @@ import { TextLayer } from "./display/text_layer.js";
8181
import { TouchManager } from "./display/touch_manager.js";
8282
import { XfaLayer } from "./display/xfa_layer.js";
8383

84-
/* eslint-disable-next-line no-unused-vars */
85-
const pdfjsVersion =
86-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
87-
/* eslint-disable-next-line no-unused-vars */
88-
const pdfjsBuild =
89-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
90-
9184
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING || GENERIC")) {
92-
globalThis.pdfjsTestingUtils = {
85+
globalThis._pdfjsTestingUtils = {
9386
HighlightOutliner,
9487
};
9588
}

src/pdf.sandbox.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
import ModuleLoader from "../external/quickjs/quickjs-eval.js";
1717
import { SandboxSupportBase } from "./pdf.sandbox.external.js";
1818

19-
/* eslint-disable-next-line no-unused-vars */
20-
const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION");
21-
/* eslint-disable-next-line no-unused-vars */
22-
const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD");
23-
2419
class SandboxSupport extends SandboxSupportBase {
2520
exportValueToSandbox(val) {
2621
// The communication with the Quickjs sandbox is based on strings

src/pdf.scripting.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515

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

18-
/* eslint-disable-next-line no-unused-vars */
19-
const pdfjsVersion =
20-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
21-
/* eslint-disable-next-line no-unused-vars */
22-
const pdfjsBuild =
23-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
24-
2518
// To avoid problems with `export` statements in the QuickJS Javascript Engine,
2619
// we manually expose `pdfjsScripting` globally instead.
2720
globalThis.pdfjsScripting = { initSandbox };

src/pdf.worker.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515

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

18-
/* eslint-disable-next-line no-unused-vars */
19-
const pdfjsVersion =
20-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
21-
/* eslint-disable-next-line no-unused-vars */
22-
const pdfjsBuild =
23-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
24-
2518
globalThis.pdfjsWorker = {
2619
WorkerMessageHandler,
2720
};

test/driver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
/* globals pdfjsLib, pdfjsTestingUtils, pdfjsViewer */
15+
/* globals pdfjsLib, _pdfjsTestingUtils, pdfjsViewer */
1616

1717
const {
1818
AnnotationLayer,
@@ -26,7 +26,7 @@ const {
2626
TextLayer,
2727
XfaLayer,
2828
} = pdfjsLib;
29-
const { HighlightOutliner } = pdfjsTestingUtils;
29+
const { HighlightOutliner } = _pdfjsTestingUtils;
3030
const { GenericL10n, parseQueryString, SimpleLinkService } = pdfjsViewer;
3131

3232
const WAITING_TIME = 100; // ms

web/pdf_viewer.component.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
3939
import { TextLayerBuilder } from "./text_layer_builder.js";
4040
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
4141

42-
/* eslint-disable-next-line no-unused-vars */
43-
const pdfjsVersion =
44-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
45-
/* eslint-disable-next-line no-unused-vars */
46-
const pdfjsBuild =
47-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
48-
4942
globalThis.pdfjsViewer = {
5043
AnnotationLayerBuilder,
5144
DownloadManager,

web/viewer-geckoview.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ import { AppOptions } from "./app_options.js";
1818
import { LinkTarget } from "./pdf_link_service.js";
1919
import { PDFViewerApplication } from "./app.js";
2020

21-
/* eslint-disable-next-line no-unused-vars */
22-
const pdfjsVersion =
23-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
24-
/* eslint-disable-next-line no-unused-vars */
25-
const pdfjsBuild =
26-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
27-
2821
const AppConstants =
2922
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
3023
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }

web/viewer.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ import { AppOptions } from "./app_options.js";
1818
import { LinkTarget } from "./pdf_link_service.js";
1919
import { PDFViewerApplication } from "./app.js";
2020

21-
/* eslint-disable-next-line no-unused-vars */
22-
const pdfjsVersion =
23-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
24-
/* eslint-disable-next-line no-unused-vars */
25-
const pdfjsBuild =
26-
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
27-
2821
const AppConstants =
2922
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
3023
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }

0 commit comments

Comments
 (0)