[api-minor] Produce non-translated/non-polyfilled builds by default

This commit is contained in:
Jonas Jenwald 2019-10-14 21:19:31 +02:00
parent cd3f2d49e6
commit c97c778f8f
9 changed files with 177 additions and 99 deletions

View File

@ -23,7 +23,9 @@ Feel free to stop by #pdfjs on irc.mozilla.org for questions or guidance.
### Online demo ### Online demo
+ https://mozilla.github.io/pdf.js/web/viewer.html + Modern browsers: https://mozilla.github.io/pdf.js/web/viewer.html
+ Older browsers: https://mozilla.github.io/pdf.js/es5/web/viewer.html
### Browser Extensions ### Browser Extensions

View File

@ -38,20 +38,38 @@ Before downloading PDF.js please take a moment to understand the different layer
## Download ## Download
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-4">
<h3>Prebuilt</h3> <h3>Prebuilt</h3>
<p> <p>
Includes the generic build of PDF.js and the viewer. Includes the generic build of PDF.js and the viewer.
</p> </p>
<!--
<span class="GROUP_CLASS">
<a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a>
<a type="button" class="btn btn-warning HIDDEN_CLASS" href="https://github.com/mozilla/pdf.js/releases/download/vBETA_VERSION/pdfjs-BETA_VERSION-dist.zip">Beta (vBETA_VERSION)</a>
</span>
-->
</div>
<div class="col-md-4">
<h3>Prebuilt (ES5-compatible)</h3>
<p>
Includes the generic build of PDF.js and the viewer.
</p>
<!--
<span class="GROUP_CLASS">
<a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-es5-dist.zip">Stable (vSTABLE_VERSION)</a>
<a type="button" class="btn btn-warning HIDDEN_CLASS" href="https://github.com/mozilla/pdf.js/releases/download/vBETA_VERSION/pdfjs-BETA_VERSION-es5-dist.zip">Beta (vBETA_VERSION)</a>
</span>
-->
<span class="GROUP_CLASS"> <span class="GROUP_CLASS">
<a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a> <a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a>
<a type="button" class="btn btn-warning HIDDEN_CLASS" href="https://github.com/mozilla/pdf.js/releases/download/vBETA_VERSION/pdfjs-BETA_VERSION-dist.zip">Beta (vBETA_VERSION)</a> <a type="button" class="btn btn-warning HIDDEN_CLASS" href="https://github.com/mozilla/pdf.js/releases/download/vBETA_VERSION/pdfjs-BETA_VERSION-dist.zip">Beta (vBETA_VERSION)</a>
</span> </span>
</div> </div>
<div class="col-md-6"> <div class="col-md-4">
<h3>Source</h3> <h3>Source</h3>
To get a local copy of the current code, clone it using git: To get a local copy of the current code, clone it using git:
<pre><code>$ git clone git://github.com/mozilla/pdf.js.git <pre><code>$ git clone https://github.com/mozilla/pdf.js.git
$ cd pdf.js $ cd pdf.js
</code></pre> </code></pre>
</div> </div>

View File

@ -8,7 +8,7 @@
// //
// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. // Run `gulp dist-install` to generate 'pdfjs-dist' npm package files.
var pdfjsLib = require("pdfjs-dist"); var pdfjsLib = require("pdfjs-dist/es5/build/pdf.js");
// Loading file from file system into typed array // Loading file from file system into typed array
var pdfPath = process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf"; var pdfPath = process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf";

View File

@ -48,7 +48,7 @@ NodeCanvasFactory.prototype = {
}, },
}; };
var pdfjsLib = require("pdfjs-dist"); var pdfjsLib = require("pdfjs-dist/es5/build/pdf.js");
// Relative path of the PDF file. // Relative path of the PDF file.
var pdfURL = "../../../web/compressed.tracemonkey-pldi-09.pdf"; var pdfURL = "../../../web/compressed.tracemonkey-pldi-09.pdf";

View File

@ -14,7 +14,7 @@ var stream = require("stream");
require("./domstubs.js").setStubs(global); require("./domstubs.js").setStubs(global);
// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. // Run `gulp dist-install` to generate 'pdfjs-dist' npm package files.
var pdfjsLib = require("pdfjs-dist"); var pdfjsLib = require("pdfjs-dist/es5/build/pdf.js");
// Loading file from file system into typed array // Loading file from file system into typed array
var pdfPath = process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf"; var pdfPath = process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf";

View File

@ -7,4 +7,8 @@ parsing and rendering PDFs.
This is a pre-built version of the PDF.js source code. It is automatically This is a pre-built version of the PDF.js source code. It is automatically
generated by the build scripts. generated by the build scripts.
For usage with older browsers/environments, without support for modern features
such as e.g. `async`/`await`, `Promise`, and `ReadableStream`,
please refer to the `es5` folder.
See https://github.com/mozilla/pdf.js for learning and contributing. See https://github.com/mozilla/pdf.js for learning and contributing.

View File

@ -51,7 +51,9 @@ var EXTENSION_SRC_DIR = "extensions/";
var BASELINE_DIR = BUILD_DIR + "baseline/"; var BASELINE_DIR = BUILD_DIR + "baseline/";
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + "mozcentral.baseline/"; var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + "mozcentral.baseline/";
var GENERIC_DIR = BUILD_DIR + "generic/"; var GENERIC_DIR = BUILD_DIR + "generic/";
var GENERIC_ES5_DIR = BUILD_DIR + "generic-es5/";
var COMPONENTS_DIR = BUILD_DIR + "components/"; var COMPONENTS_DIR = BUILD_DIR + "components/";
var COMPONENTS_ES5_DIR = BUILD_DIR + "components-es5/";
var IMAGE_DECODERS_DIR = BUILD_DIR + "image_decoders"; var IMAGE_DECODERS_DIR = BUILD_DIR + "image_decoders";
var DEFAULT_PREFERENCES_DIR = BUILD_DIR + "default_preferences/"; var DEFAULT_PREFERENCES_DIR = BUILD_DIR + "default_preferences/";
var MINIFIED_DIR = BUILD_DIR + "minified/"; var MINIFIED_DIR = BUILD_DIR + "minified/";
@ -90,6 +92,7 @@ var CSS_VARIABLES_CONFIG = {
var DEFINES = { var DEFINES = {
PRODUCTION: true, PRODUCTION: true,
SKIP_BABEL: true,
TESTING: false, TESTING: false,
// The main build targets: // The main build targets:
GENERIC: false, GENERIC: false,
@ -98,7 +101,6 @@ var DEFINES = {
MINIFIED: false, MINIFIED: false,
COMPONENTS: false, COMPONENTS: false,
LIB: false, LIB: false,
SKIP_BABEL: false,
IMAGE_DECODERS: false, IMAGE_DECODERS: false,
}; };
@ -180,8 +182,7 @@ function createWebpackConfig(defines, output) {
!bundleDefines.MOZCENTRAL && !bundleDefines.MOZCENTRAL &&
!bundleDefines.CHROME && !bundleDefines.CHROME &&
!bundleDefines.TESTING; !bundleDefines.TESTING;
var skipBabel = var skipBabel = bundleDefines.SKIP_BABEL;
bundleDefines.SKIP_BABEL || process.env["SKIP_BABEL"] === "true";
// Required to expose e.g., the `window` object. // Required to expose e.g., the `window` object.
output.globalObject = "this"; output.globalObject = "this";
@ -737,8 +738,43 @@ function preprocessHTML(source, defines) {
return createStringSource(source.substr(i + 1), out); return createStringSource(source.substr(i + 1), out);
} }
// Builds the generic production viewer that should be compatible with most function buildGeneric(defines, dir) {
// modern HTML5 browsers. rimraf.sync(dir);
return merge([
createBundle(defines).pipe(gulp.dest(dir + "build")),
createWebBundle(defines).pipe(gulp.dest(dir + "web")),
gulp.src(COMMON_WEB_FILES, { base: "web/" }).pipe(gulp.dest(dir + "web")),
gulp.src("LICENSE").pipe(gulp.dest(dir)),
gulp
.src(["web/locale/*/viewer.properties", "web/locale/locale.properties"], {
base: "web/",
})
.pipe(gulp.dest(dir + "web")),
gulp
.src(["external/bcmaps/*.bcmap", "external/bcmaps/LICENSE"], {
base: "external/bcmaps",
})
.pipe(gulp.dest(dir + "web/cmaps")),
preprocessHTML("web/viewer.html", defines).pipe(gulp.dest(dir + "web")),
preprocessCSS("web/viewer.css", "generic", defines, true)
.pipe(
postcss([
cssvariables(CSS_VARIABLES_CONFIG),
calc(),
autoprefixer(AUTOPREFIXER_CONFIG),
])
)
.pipe(gulp.dest(dir + "web")),
gulp
.src("web/compressed.tracemonkey-pldi-09.pdf")
.pipe(gulp.dest(dir + "web")),
]);
}
// Builds the generic production viewer that is only compatible with up-to-date
// HTML5 browsers, which implement modern ECMAScript features.
gulp.task( gulp.task(
"generic", "generic",
gulp.series("buildnumber", "default_preferences", "locale", function() { gulp.series("buildnumber", "default_preferences", "locale", function() {
@ -746,46 +782,48 @@ gulp.task(
console.log("### Creating generic viewer"); console.log("### Creating generic viewer");
var defines = builder.merge(DEFINES, { GENERIC: true }); var defines = builder.merge(DEFINES, { GENERIC: true });
rimraf.sync(GENERIC_DIR); return buildGeneric(defines, GENERIC_DIR);
return merge([
createBundle(defines).pipe(gulp.dest(GENERIC_DIR + "build")),
createWebBundle(defines).pipe(gulp.dest(GENERIC_DIR + "web")),
gulp
.src(COMMON_WEB_FILES, { base: "web/" })
.pipe(gulp.dest(GENERIC_DIR + "web")),
gulp.src("LICENSE").pipe(gulp.dest(GENERIC_DIR)),
gulp
.src(
["web/locale/*/viewer.properties", "web/locale/locale.properties"],
{ base: "web/" }
)
.pipe(gulp.dest(GENERIC_DIR + "web")),
gulp
.src(["external/bcmaps/*.bcmap", "external/bcmaps/LICENSE"], {
base: "external/bcmaps",
})
.pipe(gulp.dest(GENERIC_DIR + "web/cmaps")),
preprocessHTML("web/viewer.html", defines).pipe(
gulp.dest(GENERIC_DIR + "web")
),
preprocessCSS("web/viewer.css", "generic", defines, true)
.pipe(
postcss([
cssvariables(CSS_VARIABLES_CONFIG),
calc(),
autoprefixer(AUTOPREFIXER_CONFIG),
])
)
.pipe(gulp.dest(GENERIC_DIR + "web")),
gulp
.src("web/compressed.tracemonkey-pldi-09.pdf")
.pipe(gulp.dest(GENERIC_DIR + "web")),
]);
}) })
); );
// Builds the generic production viewer that should be compatible with most
// older HTML5 browsers.
gulp.task(
"generic-es5",
gulp.series("buildnumber", "default_preferences", "locale", function() {
console.log();
console.log("### Creating generic (ES5) viewer");
var defines = builder.merge(DEFINES, { GENERIC: true, SKIP_BABEL: false });
return buildGeneric(defines, GENERIC_ES5_DIR);
})
);
function buildComponents(defines, dir) {
rimraf.sync(dir);
var COMPONENTS_IMAGES = [
"web/images/annotation-*.svg",
"web/images/loading-icon.gif",
"web/images/shadow.png",
"web/images/texture.png",
];
return merge([
createComponentsBundle(defines).pipe(gulp.dest(dir)),
gulp.src(COMPONENTS_IMAGES).pipe(gulp.dest(dir + "images")),
preprocessCSS("web/pdf_viewer.css", "components", defines, true)
.pipe(
postcss([
cssvariables(CSS_VARIABLES_CONFIG),
calc(),
autoprefixer(AUTOPREFIXER_CONFIG),
])
)
.pipe(gulp.dest(dir)),
]);
}
gulp.task( gulp.task(
"components", "components",
gulp.series("buildnumber", function() { gulp.series("buildnumber", function() {
@ -793,28 +831,22 @@ gulp.task(
console.log("### Creating generic components"); console.log("### Creating generic components");
var defines = builder.merge(DEFINES, { COMPONENTS: true, GENERIC: true }); var defines = builder.merge(DEFINES, { COMPONENTS: true, GENERIC: true });
rimraf.sync(COMPONENTS_DIR); return buildComponents(defines, COMPONENTS_DIR);
})
);
var COMPONENTS_IMAGES = [ gulp.task(
"web/images/annotation-*.svg", "components-es5",
"web/images/loading-icon.gif", gulp.series("buildnumber", function() {
"web/images/shadow.png", console.log();
"web/images/texture.png", console.log("### Creating generic (ES5) components");
]; var defines = builder.merge(DEFINES, {
COMPONENTS: true,
GENERIC: true,
SKIP_BABEL: false,
});
return merge([ return buildComponents(defines, COMPONENTS_ES5_DIR);
createComponentsBundle(defines).pipe(gulp.dest(COMPONENTS_DIR)),
gulp.src(COMPONENTS_IMAGES).pipe(gulp.dest(COMPONENTS_DIR + "images")),
preprocessCSS("web/pdf_viewer.css", "components", defines, true)
.pipe(
postcss([
cssvariables(CSS_VARIABLES_CONFIG),
calc(),
autoprefixer(AUTOPREFIXER_CONFIG),
])
)
.pipe(gulp.dest(COMPONENTS_DIR)),
]);
}) })
); );
@ -981,10 +1013,7 @@ gulp.task(
gulp.series("buildnumber", "default_preferences", function() { gulp.series("buildnumber", "default_preferences", function() {
console.log(); console.log();
console.log("### Building mozilla-central extension"); console.log("### Building mozilla-central extension");
var defines = builder.merge(DEFINES, { var defines = builder.merge(DEFINES, { MOZCENTRAL: true });
MOZCENTRAL: true,
SKIP_BABEL: true,
});
var MOZCENTRAL_DIR = BUILD_DIR + "mozcentral/", var MOZCENTRAL_DIR = BUILD_DIR + "mozcentral/",
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + "browser/extensions/pdfjs/", MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + "browser/extensions/pdfjs/",
@ -1045,7 +1074,7 @@ gulp.task(
gulp.series("buildnumber", "default_preferences", "locale", function() { gulp.series("buildnumber", "default_preferences", "locale", function() {
console.log(); console.log();
console.log("### Building Chromium extension"); console.log("### Building Chromium extension");
var defines = builder.merge(DEFINES, { CHROME: true }); var defines = builder.merge(DEFINES, { CHROME: true, SKIP_BABEL: false });
var CHROME_BUILD_DIR = BUILD_DIR + "/chromium/", var CHROME_BUILD_DIR = BUILD_DIR + "/chromium/",
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + "/content/"; CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + "/content/";
@ -1144,7 +1173,7 @@ gulp.task(
} }
function preprocess(content) { function preprocess(content) {
var skipBabel = var skipBabel =
process.env["SKIP_BABEL"] === "true" || bundleDefines.SKIP_BABEL ||
/\/\*\s*no-babel-preset\s*\*\//.test(content); /\/\*\s*no-babel-preset\s*\*\//.test(content);
content = preprocessor2.preprocessPDFJSCode(ctx, content); content = preprocessor2.preprocessPDFJSCode(ctx, content);
content = babel.transform(content, { content = babel.transform(content, {
@ -1173,16 +1202,17 @@ gulp.task(
} }
var babel = require("@babel/core"); var babel = require("@babel/core");
var versionInfo = getVersionJSON(); var versionInfo = getVersionJSON();
var bundleDefines = builder.merge(DEFINES, {
GENERIC: true,
LIB: true,
BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit,
TESTING: process.env["TESTING"] === "true",
});
var ctx = { var ctx = {
rootPath: __dirname, rootPath: __dirname,
saveComments: false, saveComments: false,
defines: builder.merge(DEFINES, { defines: bundleDefines,
GENERIC: true,
LIB: true,
BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit,
TESTING: process.env["TESTING"] === "true",
}),
map: { map: {
"pdfjs-lib": "../pdf", "pdfjs-lib": "../pdf",
}, },
@ -1211,9 +1241,19 @@ gulp.task(
}) })
); );
function compressPublish(targetName, dir) {
return gulp
.src(dir + "**")
.pipe(zip(targetName))
.pipe(gulp.dest(BUILD_DIR))
.on("end", function() {
console.log("Built distribution file: " + targetName);
});
}
gulp.task( gulp.task(
"publish", "publish",
gulp.series("generic", function(done) { gulp.series("generic", "generic-es5", function(done) {
var version = JSON.parse( var version = JSON.parse(
fs.readFileSync(BUILD_DIR + "version.json").toString() fs.readFileSync(BUILD_DIR + "version.json").toString()
).version; ).version;
@ -1221,19 +1261,13 @@ gulp.task(
config.stableVersion = config.betaVersion; config.stableVersion = config.betaVersion;
config.betaVersion = version; config.betaVersion = version;
createStringSource(CONFIG_FILE, JSON.stringify(config, null, 2)) return merge([
.pipe(gulp.dest(".")) createStringSource(CONFIG_FILE, JSON.stringify(config, null, 2)).pipe(
.on("end", function() { gulp.dest(".")
var targetName = "pdfjs-" + version + "-dist.zip"; ),
gulp compressPublish("pdfjs-" + version + "-dist.zip", GENERIC_DIR),
.src(BUILD_DIR + "generic/**") compressPublish("pdfjs-" + version + "-es5-dist.zip", GENERIC_ES5_DIR),
.pipe(zip(targetName)) ]);
.pipe(gulp.dest(BUILD_DIR))
.on("end", function() {
console.log("Built distribution file: " + targetName);
done();
});
});
}) })
); );
@ -1446,6 +1480,9 @@ gulp.task("gh-pages-prepare", function() {
vfs vfs
.src(GENERIC_DIR + "**/*", { base: GENERIC_DIR, stripBOM: false }) .src(GENERIC_DIR + "**/*", { base: GENERIC_DIR, stripBOM: false })
.pipe(gulp.dest(GH_PAGES_DIR)), .pipe(gulp.dest(GH_PAGES_DIR)),
vfs
.src(GENERIC_ES5_DIR + "**/*", { base: GENERIC_ES5_DIR, stripBOM: false })
.pipe(gulp.dest(GH_PAGES_DIR + "es5/")),
gulp gulp
.src("test/features/**/*", { base: "test/" }) .src("test/features/**/*", { base: "test/" })
.pipe(gulp.dest(GH_PAGES_DIR)), .pipe(gulp.dest(GH_PAGES_DIR)),
@ -1524,6 +1561,7 @@ gulp.task(
"web", "web",
gulp.series( gulp.series(
"generic", "generic",
"generic-es5",
"jsdoc", "jsdoc",
"gh-pages-prepare", "gh-pages-prepare",
"wintersmith", "wintersmith",
@ -1535,7 +1573,9 @@ gulp.task(
"dist-pre", "dist-pre",
gulp.series( gulp.series(
"generic", "generic",
"generic-es5",
"components", "components",
"components-es5",
"image_decoders", "image_decoders",
"lib", "lib",
"minified", "minified",
@ -1617,6 +1657,15 @@ gulp.task(
SRC_DIR + "pdf.worker.entry.js", SRC_DIR + "pdf.worker.entry.js",
]) ])
.pipe(gulp.dest(DIST_DIR + "build/")), .pipe(gulp.dest(DIST_DIR + "build/")),
gulp
.src([
GENERIC_ES5_DIR + "build/pdf.js",
GENERIC_ES5_DIR + "build/pdf.js.map",
GENERIC_ES5_DIR + "build/pdf.worker.js",
GENERIC_ES5_DIR + "build/pdf.worker.js.map",
SRC_DIR + "pdf.worker.entry.js",
])
.pipe(gulp.dest(DIST_DIR + "es5/build/")),
gulp gulp
.src(MINIFIED_DIR + "build/pdf.js") .src(MINIFIED_DIR + "build/pdf.js")
.pipe(rename("pdf.min.js")) .pipe(rename("pdf.min.js"))
@ -1632,6 +1681,9 @@ gulp.task(
gulp gulp
.src(COMPONENTS_DIR + "**/*", { base: COMPONENTS_DIR }) .src(COMPONENTS_DIR + "**/*", { base: COMPONENTS_DIR })
.pipe(gulp.dest(DIST_DIR + "web/")), .pipe(gulp.dest(DIST_DIR + "web/")),
gulp
.src(COMPONENTS_ES5_DIR + "**/*", { base: COMPONENTS_ES5_DIR })
.pipe(gulp.dest(DIST_DIR + "es5/web/")),
gulp gulp
.src(IMAGE_DECODERS_DIR + "**/*", { base: IMAGE_DECODERS_DIR }) .src(IMAGE_DECODERS_DIR + "**/*", { base: IMAGE_DECODERS_DIR })
.pipe(gulp.dest(DIST_DIR + "image_decoders")), .pipe(gulp.dest(DIST_DIR + "image_decoders")),

View File

@ -55,7 +55,7 @@
"yargs": "^11.1.1" "yargs": "^11.1.1"
}, },
"scripts": { "scripts": {
"test": "env SKIP_BABEL=true gulp npm-test" "test": "gulp npm-test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -14,9 +14,11 @@
*/ */
/* eslint no-var: error */ /* eslint no-var: error */
// Skip compatibility checks for modern builds and if we already ran the module. // Skip compatibility checks for modern builds (unless we're running the
// unit-tests in Node.js/Travis) and if we already ran the module.
if ( if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) && (typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!SKIP_BABEL || (LIB && TESTING)")) &&
(typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked) (typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked)
) { ) {
// Provides support for globalThis in legacy browsers. // Provides support for globalThis in legacy browsers.