Improve how 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 the license header.
This commit is contained in:
parent
819671d42f
commit
97a42486f5
13
gulpfile.mjs
13
gulpfile.mjs
@ -302,6 +302,12 @@ function createWebpackConfig(
|
|||||||
const licenseHeaderLibre = fs
|
const licenseHeaderLibre = fs
|
||||||
.readFileSync("./src/license_header_libre.js")
|
.readFileSync("./src/license_header_libre.js")
|
||||||
.toString();
|
.toString();
|
||||||
|
const versionInfoHeader = [
|
||||||
|
"/**",
|
||||||
|
` * pdfjsVersion = ${versionInfo.version}`,
|
||||||
|
` * pdfjsBuild = ${versionInfo.commit}`,
|
||||||
|
" */",
|
||||||
|
].join("\n");
|
||||||
const enableSourceMaps =
|
const enableSourceMaps =
|
||||||
!bundleDefines.MOZCENTRAL &&
|
!bundleDefines.MOZCENTRAL &&
|
||||||
!bundleDefines.CHROME &&
|
!bundleDefines.CHROME &&
|
||||||
@ -335,7 +341,10 @@ function createWebpackConfig(
|
|||||||
const plugins = [];
|
const plugins = [];
|
||||||
if (!disableLicenseHeader) {
|
if (!disableLicenseHeader) {
|
||||||
plugins.push(
|
plugins.push(
|
||||||
new webpack2.BannerPlugin({ banner: licenseHeaderLibre, raw: true })
|
new webpack2.BannerPlugin({
|
||||||
|
banner: licenseHeaderLibre + "\n" + versionInfoHeader,
|
||||||
|
raw: true,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
plugins.push({
|
plugins.push({
|
||||||
@ -389,7 +398,7 @@ function createWebpackConfig(
|
|||||||
sequences: false,
|
sequences: false,
|
||||||
},
|
},
|
||||||
format: {
|
format: {
|
||||||
comments: /@lic|webpackIgnore|@vite-ignore/i,
|
comments: /@lic|webpackIgnore|@vite-ignore|pdfjsVersion/i,
|
||||||
},
|
},
|
||||||
keep_classnames: true,
|
keep_classnames: true,
|
||||||
keep_fnames: true,
|
keep_fnames: true,
|
||||||
|
|||||||
@ -22,13 +22,6 @@ import { Jbig2Error, Jbig2Image } from "./core/jbig2.js";
|
|||||||
import { JpegError, JpegImage } from "./core/jpg.js";
|
import { JpegError, JpegImage } from "./core/jpg.js";
|
||||||
import { JpxError, JpxImage } from "./core/jpx.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 = {
|
globalThis.pdfjsImageDecoders = {
|
||||||
getVerbosityLevel,
|
getVerbosityLevel,
|
||||||
Jbig2Error,
|
Jbig2Error,
|
||||||
|
|||||||
@ -81,15 +81,8 @@ import { TextLayer } from "./display/text_layer.js";
|
|||||||
import { TouchManager } from "./display/touch_manager.js";
|
import { TouchManager } from "./display/touch_manager.js";
|
||||||
import { XfaLayer } from "./display/xfa_layer.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")) {
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING || GENERIC")) {
|
||||||
globalThis.pdfjsTestingUtils = {
|
globalThis._pdfjsTestingUtils = {
|
||||||
HighlightOutliner,
|
HighlightOutliner,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,6 @@
|
|||||||
import ModuleLoader from "../external/quickjs/quickjs-eval.js";
|
import ModuleLoader from "../external/quickjs/quickjs-eval.js";
|
||||||
import { SandboxSupportBase } from "./pdf.sandbox.external.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 {
|
class SandboxSupport extends SandboxSupportBase {
|
||||||
exportValueToSandbox(val) {
|
exportValueToSandbox(val) {
|
||||||
// The communication with the Quickjs sandbox is based on strings
|
// The communication with the Quickjs sandbox is based on strings
|
||||||
|
|||||||
@ -15,13 +15,6 @@
|
|||||||
|
|
||||||
import { initSandbox } from "./scripting_api/initialization.js";
|
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,
|
// To avoid problems with `export` statements in the QuickJS Javascript Engine,
|
||||||
// we manually expose `pdfjsScripting` globally instead.
|
// we manually expose `pdfjsScripting` globally instead.
|
||||||
globalThis.pdfjsScripting = { initSandbox };
|
globalThis.pdfjsScripting = { initSandbox };
|
||||||
|
|||||||
7
src/pdf.worker.js
vendored
7
src/pdf.worker.js
vendored
@ -15,13 +15,6 @@
|
|||||||
|
|
||||||
import { WorkerMessageHandler } from "./core/worker.js";
|
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 = {
|
globalThis.pdfjsWorker = {
|
||||||
WorkerMessageHandler,
|
WorkerMessageHandler,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
* 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 pdfjsLib, pdfjsTestingUtils, pdfjsViewer */
|
/* globals pdfjsLib, _pdfjsTestingUtils, pdfjsViewer */
|
||||||
|
|
||||||
const {
|
const {
|
||||||
AnnotationLayer,
|
AnnotationLayer,
|
||||||
@ -26,7 +26,7 @@ const {
|
|||||||
TextLayer,
|
TextLayer,
|
||||||
XfaLayer,
|
XfaLayer,
|
||||||
} = pdfjsLib;
|
} = pdfjsLib;
|
||||||
const { HighlightOutliner } = pdfjsTestingUtils;
|
const { HighlightOutliner } = _pdfjsTestingUtils;
|
||||||
const { GenericL10n, parseQueryString, SimpleLinkService } = pdfjsViewer;
|
const { GenericL10n, parseQueryString, SimpleLinkService } = pdfjsViewer;
|
||||||
|
|
||||||
const WAITING_TIME = 100; // ms
|
const WAITING_TIME = 100; // ms
|
||||||
|
|||||||
@ -39,13 +39,6 @@ import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
|
|||||||
import { TextLayerBuilder } from "./text_layer_builder.js";
|
import { TextLayerBuilder } from "./text_layer_builder.js";
|
||||||
import { XfaLayerBuilder } from "./xfa_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 = {
|
globalThis.pdfjsViewer = {
|
||||||
AnnotationLayerBuilder,
|
AnnotationLayerBuilder,
|
||||||
DownloadManager,
|
DownloadManager,
|
||||||
|
|||||||
@ -18,13 +18,6 @@ import { AppOptions } from "./app_options.js";
|
|||||||
import { LinkTarget } from "./pdf_link_service.js";
|
import { LinkTarget } from "./pdf_link_service.js";
|
||||||
import { PDFViewerApplication } from "./app.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 =
|
const AppConstants =
|
||||||
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
||||||
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
|
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
|
||||||
|
|||||||
@ -18,13 +18,6 @@ import { AppOptions } from "./app_options.js";
|
|||||||
import { LinkTarget } from "./pdf_link_service.js";
|
import { LinkTarget } from "./pdf_link_service.js";
|
||||||
import { PDFViewerApplication } from "./app.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 =
|
const AppConstants =
|
||||||
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
||||||
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
|
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user