Always include Promise polyfill for legacy browsers

It is now used by our general code and not just by the conversion
routines, so we need to make sure it is always included for the
old browsers.
This commit is contained in:
Pierre Ossman 2019-11-11 13:36:30 +01:00 committed by Lauri Kasanen
parent d6d875ef3b
commit 23871b42d1
2 changed files with 25 additions and 16 deletions

View File

@ -30,10 +30,13 @@ const no_copy_files = new Set([
// skip these -- they don't belong in the processed application // skip these -- they don't belong in the processed application
path.join(paths.vendor, 'sinon.js'), path.join(paths.vendor, 'sinon.js'),
path.join(paths.vendor, 'browser-es-module-loader'), path.join(paths.vendor, 'browser-es-module-loader'),
path.join(paths.vendor, 'promise.js'),
path.join(paths.app, 'images', 'icons', 'Makefile'), path.join(paths.app, 'images', 'icons', 'Makefile'),
]); ]);
const only_legacy_scripts = new Set([
path.join(paths.vendor, 'promise.js'),
]);
const no_transform_files = new Set([ const no_transform_files = new Set([
// don't transform this -- we want it imported as-is to properly catch loading errors // don't transform this -- we want it imported as-is to properly catch loading errors
path.join(paths.app, 'error-handler.js'), path.join(paths.app, 'error-handler.js'),
@ -174,6 +177,7 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
const helper = helpers[import_format]; const helper = helpers[import_format];
const outFiles = []; const outFiles = [];
const legacyFiles = [];
const handleDir = (js_only, vendor_rewrite, in_path_base, filename) => Promise.resolve() const handleDir = (js_only, vendor_rewrite, in_path_base, filename) => Promise.resolve()
.then(() => { .then(() => {
@ -196,6 +200,15 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
}); });
} }
if (only_legacy_scripts.has(filename)) {
legacyFiles.push(legacy_path);
return ensureDir(path.dirname(legacy_path))
.then(() => {
console.log(`Writing ${legacy_path}`);
return copy(filename, legacy_path);
});
}
return Promise.resolve() return Promise.resolve()
.then(() => { .then(() => {
if (only_legacy) { if (only_legacy) {
@ -243,10 +256,6 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
}); });
}); });
if (with_app_dir && helper && helper.noCopyOverride) {
helper.noCopyOverride(paths, no_copy_files);
}
Promise.resolve() Promise.resolve()
.then(() => { .then(() => {
const handler = handleDir.bind(null, true, false, in_path || paths.main); const handler = handleDir.bind(null, true, false, in_path || paths.main);
@ -275,8 +284,16 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
console.log(`Writing ${out_app_path}`); console.log(`Writing ${out_app_path}`);
return helper.appWriter(out_path_base, legacy_path_base, out_app_path) return helper.appWriter(out_path_base, legacy_path_base, out_app_path)
.then((extra_scripts) => { .then((extra_scripts) => {
const rel_app_path = path.relative(out_path_base, out_app_path); let legacy_scripts = extra_scripts;
const legacy_scripts = extra_scripts.concat([rel_app_path]);
legacyFiles.forEach((file) => {
let rel_file_path = path.relative(out_path_base, file);
legacy_scripts.push(rel_file_path);
});
let rel_app_path = path.relative(out_path_base, out_app_path);
legacy_scripts.push(rel_app_path);
transform_html(legacy_scripts, only_legacy); transform_html(legacy_scripts, only_legacy);
}) })
.then(() => { .then(() => {

View File

@ -31,7 +31,6 @@ module.exports = {
return [ require_path ]; return [ require_path ];
}); });
}, },
noCopyOverride: () => {},
}, },
'commonjs': { 'commonjs': {
optionsOverride: (opts) => { optionsOverride: (opts) => {
@ -45,7 +44,6 @@ module.exports = {
.then(buf => writeFile(out_path, buf)) .then(buf => writeFile(out_path, buf))
.then(() => []); .then(() => []);
}, },
noCopyOverride: () => {},
removeModules: true, removeModules: true,
}, },
'systemjs': { 'systemjs': {
@ -55,17 +53,11 @@ module.exports = {
return writeFile(out_path, `SystemJS.import("${ui_path}");`) return writeFile(out_path, `SystemJS.import("${ui_path}");`)
.then(() => { .then(() => {
console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`); console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
// FIXME: Should probably be in the legacy directory
const promise_path = path.relative(base_out_path,
path.join(base_out_path, 'vendor', 'promise.js'));
const systemjs_path = path.relative(base_out_path, const systemjs_path = path.relative(base_out_path,
path.join(script_base_path, 'system-production.js')); path.join(script_base_path, 'system-production.js'));
return [ promise_path, systemjs_path ]; return [ systemjs_path ];
}); });
}, },
noCopyOverride: (paths, no_copy_files) => {
no_copy_files.delete(path.join(paths.vendor, 'promise.js'));
},
}, },
'umd': { 'umd': {
optionsOverride: (opts) => { optionsOverride: (opts) => {