Skip to content

Commit

Permalink
[api-minor] Produce non-translated/non-polyfilled builds by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffleupagus committed Oct 21, 2019
1 parent 96c675d commit 7a201ce
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 33 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Feel free to stop by #pdfjs on irc.mozilla.org for questions or guidance.

### 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

Expand Down
2 changes: 1 addition & 1 deletion examples/node/getinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//

// 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
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
Expand Down
2 changes: 1 addition & 1 deletion examples/node/pdf2png/pdf2png.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
var pdfURL = '../../../web/compressed.tracemonkey-pldi-09.pdf';
Expand Down
2 changes: 1 addition & 1 deletion examples/node/pdf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var stream = require('stream');
require('./domstubs.js').setStubs(global);

// 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
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
Expand Down
3 changes: 3 additions & 0 deletions external/dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ parsing and rendering PDFs.
This is a pre-built version of the PDF.js source code. It is automatically
generated by the build scripts.

For usage with older browsers/environments, without support for modern features
such as e.g. `ReadableStream`, please refer to the `es5` folder.

See https://github.com/mozilla/pdf.js for learning and contributing.
139 changes: 111 additions & 28 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ var EXTENSION_SRC_DIR = 'extensions/';
var BASELINE_DIR = BUILD_DIR + 'baseline/';
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/';
var GENERIC_DIR = BUILD_DIR + 'generic/';
var GENERIC_ES5_DIR = BUILD_DIR + 'generic-es5/';
var COMPONENTS_DIR = BUILD_DIR + 'components/';
var COMPONENTS_ES5_DIR = BUILD_DIR + 'components-es5/';
var IMAGE_DECODERS_DIR = BUILD_DIR + 'image_decoders';
var DEFAULT_PREFERENCES_DIR = BUILD_DIR + 'default_preferences/';
var MINIFIED_DIR = BUILD_DIR + 'minified/';
Expand Down Expand Up @@ -88,6 +90,7 @@ var AUTOPREFIXER_CONFIG = {

var DEFINES = {
PRODUCTION: true,
SKIP_BABEL: true,
TESTING: false,
// The main build targets:
GENERIC: false,
Expand All @@ -97,7 +100,6 @@ var DEFINES = {
MINIFIED: false,
COMPONENTS: false,
LIB: false,
SKIP_BABEL: false,
IMAGE_DECODERS: false,
};

Expand Down Expand Up @@ -157,8 +159,7 @@ function createWebpackConfig(defines, output) {
fs.readFileSync('./src/license_header_libre.js').toString();
var enableSourceMaps = !bundleDefines.FIREFOX && !bundleDefines.MOZCENTRAL &&
!bundleDefines.CHROME && !bundleDefines.TESTING;
var skipBabel = bundleDefines.SKIP_BABEL ||
process.env['SKIP_BABEL'] === 'true';
var skipBabel = bundleDefines.SKIP_BABEL;

// Required to expose e.g., the `window` object.
output.globalObject = 'this';
Expand Down Expand Up @@ -668,8 +669,8 @@ function preprocessHTML(source, defines) {
return createStringSource(source.substr(i + 1), out);
}

// Builds the generic production viewer that should be compatible with most
// modern HTML5 browsers.
// Builds the generic production viewer that is only compatible with up-to-date
// HTML5 browsers, which implements modern ECMAScript features.
gulp.task('generic', gulp.series('buildnumber', 'default_preferences', 'locale',
function() {
console.log();
Expand Down Expand Up @@ -704,6 +705,40 @@ gulp.task('generic', gulp.series('buildnumber', 'default_preferences', 'locale',
]);
}));

// 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, });

rimraf.sync(GENERIC_ES5_DIR);

return merge([
createBundle(defines).pipe(gulp.dest(GENERIC_ES5_DIR + 'build')),
createWebBundle(defines).pipe(gulp.dest(GENERIC_ES5_DIR + 'web')),
gulp.src(COMMON_WEB_FILES, { base: 'web/', })
.pipe(gulp.dest(GENERIC_ES5_DIR + 'web')),
gulp.src('LICENSE').pipe(gulp.dest(GENERIC_ES5_DIR)),
gulp.src([
'web/locale/*/viewer.properties',
'web/locale/locale.properties'
], { base: 'web/', }).pipe(gulp.dest(GENERIC_ES5_DIR + 'web')),
gulp.src(['external/bcmaps/*.bcmap', 'external/bcmaps/LICENSE'],
{ base: 'external/bcmaps', })
.pipe(gulp.dest(GENERIC_ES5_DIR + 'web/cmaps')),
preprocessHTML('web/viewer.html', defines)
.pipe(gulp.dest(GENERIC_ES5_DIR + 'web')),
preprocessCSS('web/viewer.css', 'generic', defines, true)
.pipe(postcss([autoprefixer(AUTOPREFIXER_CONFIG)]))
.pipe(gulp.dest(GENERIC_ES5_DIR + 'web')),

gulp.src('web/compressed.tracemonkey-pldi-09.pdf')
.pipe(gulp.dest(GENERIC_ES5_DIR + 'web')),
]);
}));

gulp.task('components', gulp.series('buildnumber', function () {
console.log();
console.log('### Creating generic components');
Expand All @@ -729,6 +764,30 @@ gulp.task('components', gulp.series('buildnumber', function () {
]);
}));

gulp.task('components-es5', gulp.series('buildnumber', function () {
console.log();
console.log('### Creating generic (ES5) components');
var defines = builder.merge(DEFINES, { COMPONENTS: true, GENERIC: true,
SKIP_BABEL: false, });

rimraf.sync(COMPONENTS_ES5_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(COMPONENTS_ES5_DIR)),
gulp.src(COMPONENTS_IMAGES).pipe(gulp.dest(COMPONENTS_ES5_DIR + 'images')),
preprocessCSS('web/pdf_viewer.css', 'components', defines, true)
.pipe(postcss([autoprefixer(AUTOPREFIXER_CONFIG)]))
.pipe(gulp.dest(COMPONENTS_ES5_DIR)),
]);
}));

gulp.task('image_decoders', gulp.series('buildnumber', function() {
console.log();
console.log('### Creating image decoders');
Expand Down Expand Up @@ -840,7 +899,7 @@ gulp.task('mozcentral-pre', gulp.series('buildnumber', 'default_preferences',
function() {
console.log();
console.log('### Building mozilla-central extension');
var defines = builder.merge(DEFINES, { MOZCENTRAL: true, SKIP_BABEL: true, });
var defines = builder.merge(DEFINES, { MOZCENTRAL: true, });

var MOZCENTRAL_DIR = BUILD_DIR + 'mozcentral/',
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + 'browser/extensions/pdfjs/',
Expand Down Expand Up @@ -891,7 +950,7 @@ gulp.task('chromium-pre', gulp.series('buildnumber', 'default_preferences',
'locale', function() {
console.log();
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/',
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + '/content/';
Expand Down Expand Up @@ -973,7 +1032,7 @@ gulp.task('lib', gulp.series('buildnumber', 'default_preferences', function() {
};
}
function preprocess(content) {
var skipBabel = process.env['SKIP_BABEL'] === 'true' ||
var skipBabel = bundleDefines.SKIP_BABEL ||
/\/\*\s*no-babel-preset\s*\*\//.test(content);
content = preprocessor2.preprocessPDFJSCode(ctx, content);
content = babel.transform(content, {
Expand All @@ -997,16 +1056,17 @@ gulp.task('lib', gulp.series('buildnumber', 'default_preferences', function() {
}
var babel = require('@babel/core');
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 = {
rootPath: __dirname,
saveComments: false,
defines: builder.merge(DEFINES, {
GENERIC: true,
LIB: true,
BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit,
TESTING: process.env['TESTING'] === 'true',
}),
defines: bundleDefines,
map: {
'pdfjs-lib': '../pdf',
},
Expand All @@ -1030,25 +1090,34 @@ gulp.task('lib', gulp.series('buildnumber', 'default_preferences', function() {
.pipe(gulp.dest('build/lib/'));
}));

gulp.task('publish', gulp.series('generic', function (done) {
gulp.task('publish', gulp.series('generic', 'generic-es5', function(done) {
var version = JSON.parse(
fs.readFileSync(BUILD_DIR + 'version.json').toString()).version;

config.stableVersion = config.betaVersion;
config.betaVersion = version;

createStringSource(CONFIG_FILE, JSON.stringify(config, null, 2))
.pipe(gulp.dest('.'))
.on('end', function () {
var targetName = 'pdfjs-' + version + '-dist.zip';
gulp.src(BUILD_DIR + 'generic/**')
var targetName = 'pdfjs-' + version + '-dist.zip';
var targetNameES5 = 'pdfjs-' + version + '-es5-dist.zip';

return merge([
createStringSource(CONFIG_FILE, JSON.stringify(config, null, 2))
.pipe(gulp.dest('.')),

gulp.src(GENERIC_DIR + '**')
.pipe(zip(targetName))
.pipe(gulp.dest(BUILD_DIR))
.on('end', function () {
.on('end', function() {
console.log('Built distribution file: ' + targetName);
done();
});
});
}),

gulp.src(GENERIC_ES5_DIR + '**')
.pipe(zip(targetNameES5))
.pipe(gulp.dest(BUILD_DIR))
.on('end', function() {
console.log('Built distribution file: ' + targetNameES5);
}),
]);
}));

gulp.task('testing-pre', function(done) {
Expand Down Expand Up @@ -1222,6 +1291,9 @@ gulp.task('gh-pages-prepare', function () {
return merge([
vfs.src(GENERIC_DIR + '**/*', { base: GENERIC_DIR, stripBOM: false, })
.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.src('test/features/**/*', { base: 'test/', })
.pipe(gulp.dest(GH_PAGES_DIR)),
gulp.src(JSDOC_BUILD_DIR + '**/*', { base: JSDOC_BUILD_DIR, })
Expand Down Expand Up @@ -1274,10 +1346,12 @@ gulp.task('gh-pages-git', function (done) {
done();
});

gulp.task('web', gulp.series('generic', 'jsdoc', 'gh-pages-prepare',
'wintersmith', 'gh-pages-git'));
gulp.task('web', gulp.series('generic', 'generic-es5', 'jsdoc',
'gh-pages-prepare', 'wintersmith',
'gh-pages-git'));

gulp.task('dist-pre', gulp.series('generic', 'components', 'image_decoders',
gulp.task('dist-pre', gulp.series('generic', 'generic-es5', 'components',
'components-es5', 'image_decoders',
'lib', 'minified', function() {
var VERSION = getVersionJSON().version;

Expand Down Expand Up @@ -1361,6 +1435,13 @@ gulp.task('dist-pre', gulp.series('generic', 'components', 'image_decoders',
GENERIC_DIR + 'build/pdf.worker.js.map',
SRC_DIR + 'pdf.worker.entry.js',
]).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.src(MINIFIED_DIR + 'build/pdf.js')
.pipe(rename('pdf.min.js'))
.pipe(gulp.dest(DIST_DIR + 'build/')),
Expand All @@ -1372,6 +1453,8 @@ gulp.task('dist-pre', gulp.series('generic', 'components', 'image_decoders',
.pipe(gulp.dest(DIST_DIR + 'image_decoders/')),
gulp.src(COMPONENTS_DIR + '**/*', { base: COMPONENTS_DIR, })
.pipe(gulp.dest(DIST_DIR + 'web/')),
gulp.src(COMPONENTS_ES5_DIR + '**/*', { base: COMPONENTS_ES5_DIR, })
.pipe(gulp.dest(DIST_DIR + 'es5/web/')),
gulp.src(IMAGE_DECODERS_DIR + '**/*', { base: IMAGE_DECODERS_DIR, })
.pipe(gulp.dest(DIST_DIR + 'image_decoders')),
gulp.src(LIB_DIR + '**/*', { base: LIB_DIR, })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"yargs": "^11.1.1"
},
"scripts": {
"test": "env SKIP_BABEL=true gulp lint unittestcli externaltest"
"test": "gulp lint unittestcli externaltest"
},
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions test/unit/clitests_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { setVerbosityLevel, VerbosityLevel } from '../../src/shared/util';
import globalScope from '../../src/shared/global_scope';
import isNodeJS from '../../src/shared/is_node';
import { PDFNodeStream } from '../../src/display/node_stream';
import { setPDFNetworkStreamFactory } from '../../src/display/api';
Expand All @@ -32,3 +33,9 @@ setVerbosityLevel(VerbosityLevel.ERRORS);
setPDFNetworkStreamFactory(function(params) {
return new PDFNodeStream(params);
});

// Ensure that `ReadableStream` is always available.
if (typeof ReadableStream === 'undefined') {
globalScope.ReadableStream =
require('web-streams-polyfill/dist/ponyfill').ReadableStream;
}

0 comments on commit 7a201ce

Please sign in to comment.