mirror of
https://github.com/novnc/noVNC.git
synced 2025-04-18 23:44:01 +03:00
Remove legacy conversion of modules
We no longer support Internet Explorer so we can now require that browsers support modules. Some conversion to commonjs still remains for nodejs.
This commit is contained in:
parent
c01eb5e74d
commit
890cff921d
@ -42,12 +42,6 @@ licenses (all MPL 2.0 compatible):
|
||||
|
||||
vendor/pako/ : MIT
|
||||
|
||||
vendor/browser-es-module-loader/src/ : MIT
|
||||
|
||||
vendor/browser-es-module-loader/dist/ : Various BSD style licenses
|
||||
|
||||
vendor/promise.js : MIT
|
||||
|
||||
Any other files not mentioned above are typically marked with
|
||||
a copyright/license header at the top of the file. The default noVNC
|
||||
license is MPL-2.0.
|
||||
|
@ -31,16 +31,13 @@ module.exports = (config) => {
|
||||
|
||||
// list of files / patterns to load in the browser (loaded in order)
|
||||
files: [
|
||||
{ pattern: 'app/localization.js', included: false },
|
||||
{ pattern: 'app/webutil.js', included: false },
|
||||
{ pattern: 'core/**/*.js', included: false },
|
||||
{ pattern: 'vendor/pako/**/*.js', included: false },
|
||||
{ pattern: 'vendor/browser-es-module-loader/dist/*.js*', included: false },
|
||||
{ pattern: 'tests/test.*.js', included: false },
|
||||
{ pattern: 'tests/fake.*.js', included: false },
|
||||
{ pattern: 'tests/assertions.js', included: false },
|
||||
'vendor/promise.js',
|
||||
'tests/karma-test-main.js',
|
||||
{ pattern: 'app/localization.js', included: false, type: 'module' },
|
||||
{ pattern: 'app/webutil.js', included: false, type: 'module' },
|
||||
{ pattern: 'core/**/*.js', included: false, type: 'module' },
|
||||
{ pattern: 'vendor/pako/**/*.js', included: false, type: 'module' },
|
||||
{ pattern: 'tests/test.*.js', type: 'module' },
|
||||
{ pattern: 'tests/fake.*.js', included: false, type: 'module' },
|
||||
{ pattern: 'tests/assertions.js', type: 'module' },
|
||||
],
|
||||
|
||||
client: {
|
||||
|
@ -21,7 +21,7 @@
|
||||
"scripts": {
|
||||
"lint": "eslint app core po/po2js po/xgettext-html tests utils",
|
||||
"test": "karma start karma.conf.js",
|
||||
"prepublish": "node ./utils/use_require.js --as commonjs --clean"
|
||||
"prepublish": "node ./utils/use_require.js --clean"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -42,10 +42,7 @@
|
||||
"devDependencies": {
|
||||
"@babel/core": "*",
|
||||
"@babel/plugin-syntax-dynamic-import": "*",
|
||||
"@babel/plugin-transform-modules-amd": "*",
|
||||
"@babel/plugin-transform-modules-commonjs": "*",
|
||||
"@babel/plugin-transform-modules-systemjs": "*",
|
||||
"@babel/plugin-transform-modules-umd": "*",
|
||||
"@babel/preset-env": "*",
|
||||
"@babel/cli": "*",
|
||||
"babel-plugin-import-redirect": "*",
|
||||
|
@ -1,48 +0,0 @@
|
||||
const TEST_REGEXP = /test\..*\.js/;
|
||||
const allTestFiles = [];
|
||||
const extraFiles = ['/base/tests/assertions.js'];
|
||||
|
||||
Object.keys(window.__karma__.files).forEach(function (file) {
|
||||
if (TEST_REGEXP.test(file)) {
|
||||
// TODO: normalize?
|
||||
allTestFiles.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
// Stub out mocha's start function so we can run it once we're done loading
|
||||
mocha.origRun = mocha.run;
|
||||
mocha.run = function () {};
|
||||
|
||||
let script;
|
||||
|
||||
// Script to import all our tests
|
||||
script = document.createElement("script");
|
||||
script.type = "module";
|
||||
script.text = "";
|
||||
let allModules = allTestFiles.concat(extraFiles);
|
||||
allModules.forEach(function (file) {
|
||||
script.text += "import \"" + file + "\";\n";
|
||||
});
|
||||
script.text += "\nmocha.origRun();\n";
|
||||
document.body.appendChild(script);
|
||||
|
||||
// Fallback code for browsers that don't support modules (IE)
|
||||
script = document.createElement("script");
|
||||
script.type = "module";
|
||||
script.text = "window._noVNC_has_module_support = true;\n";
|
||||
document.body.appendChild(script);
|
||||
|
||||
function fallback() {
|
||||
if (!window._noVNC_has_module_support) {
|
||||
/* eslint-disable no-console */
|
||||
if (console) {
|
||||
console.log("No module support detected. Loading fallback...");
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
let loader = document.createElement("script");
|
||||
loader.src = "base/vendor/browser-es-module-loader/dist/browser-es-module-loader.js";
|
||||
document.body.appendChild(loader);
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(fallback, 500);
|
@ -2,21 +2,6 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>VNC Playback</title>
|
||||
<!-- promise polyfills promises for IE11 -->
|
||||
<script src="../vendor/promise.js"></script>
|
||||
<!-- ES2015/ES6 modules polyfill -->
|
||||
<script type="module">
|
||||
window._noVNC_has_module_support = true;
|
||||
</script>
|
||||
<script>
|
||||
window.addEventListener("load", function() {
|
||||
if (window._noVNC_has_module_support) return;
|
||||
var loader = document.createElement("script");
|
||||
loader.src = "../vendor/browser-es-module-loader/dist/browser-es-module-loader.js";
|
||||
document.head.appendChild(loader);
|
||||
});
|
||||
</script>
|
||||
<!-- actual script modules -->
|
||||
<script type="module" src="./playback-ui.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
@ -37,7 +22,5 @@
|
||||
<div id="VNC_screen">
|
||||
<div id="VNC_status">Loading</div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="./playback-ui.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -6,13 +6,8 @@ const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const babel = require('@babel/core');
|
||||
|
||||
const SUPPORTED_FORMATS = new Set(['amd', 'commonjs', 'systemjs', 'umd']);
|
||||
|
||||
program
|
||||
.option('--as [format]', `output files using various import formats instead of ES6 import and export. Supports ${Array.from(SUPPORTED_FORMATS)}.`)
|
||||
.option('-m, --with-source-maps [type]', 'output source maps when not generating a bundled app (type may be empty for external source maps, inline for inline source maps, or both) ')
|
||||
.option('--with-app', 'process app files as well as core files')
|
||||
.option('--only-legacy', 'only output legacy files (no ES6 modules) for the app')
|
||||
.option('--clean', 'clear the lib folder before building')
|
||||
.parse(process.argv);
|
||||
|
||||
@ -20,30 +15,10 @@ program
|
||||
const paths = {
|
||||
main: path.resolve(__dirname, '..'),
|
||||
core: path.resolve(__dirname, '..', 'core'),
|
||||
app: path.resolve(__dirname, '..', 'app'),
|
||||
vendor: path.resolve(__dirname, '..', 'vendor'),
|
||||
outDirBase: path.resolve(__dirname, '..', 'build'),
|
||||
libDirBase: path.resolve(__dirname, '..', 'lib'),
|
||||
};
|
||||
|
||||
const noCopyFiles = new Set([
|
||||
// skip these -- they don't belong in the processed application
|
||||
path.join(paths.vendor, 'sinon.js'),
|
||||
path.join(paths.vendor, 'browser-es-module-loader'),
|
||||
path.join(paths.app, 'images', 'icons', 'Makefile'),
|
||||
]);
|
||||
|
||||
const onlyLegacyScripts = new Set([
|
||||
path.join(paths.vendor, 'promise.js'),
|
||||
]);
|
||||
|
||||
const noTransformFiles = new Set([
|
||||
// don't transform this -- we want it imported as-is to properly catch loading errors
|
||||
path.join(paths.app, 'error-handler.js'),
|
||||
]);
|
||||
|
||||
noCopyFiles.forEach(file => noTransformFiles.add(file));
|
||||
|
||||
// util.promisify requires Node.js 8.x, so we have our own
|
||||
function promisify(original) {
|
||||
return function promiseWrap() {
|
||||
@ -57,16 +32,12 @@ function promisify(original) {
|
||||
};
|
||||
}
|
||||
|
||||
const readFile = promisify(fs.readFile);
|
||||
const writeFile = promisify(fs.writeFile);
|
||||
|
||||
const readdir = promisify(fs.readdir);
|
||||
const lstat = promisify(fs.lstat);
|
||||
|
||||
const copy = promisify(fse.copy);
|
||||
const unlink = promisify(fse.unlink);
|
||||
const ensureDir = promisify(fse.ensureDir);
|
||||
const rmdir = promisify(fse.rmdir);
|
||||
|
||||
const babelTransformFile = promisify(babel.transformFile);
|
||||
|
||||
@ -87,157 +58,57 @@ function walkDir(basePath, cb, filter) {
|
||||
});
|
||||
}
|
||||
|
||||
function transformHtml(legacyScripts, onlyLegacy) {
|
||||
// write out the modified vnc.html file that works with the bundle
|
||||
const srcHtmlPath = path.resolve(__dirname, '..', 'vnc.html');
|
||||
const outHtmlPath = path.resolve(paths.outDirBase, 'vnc.html');
|
||||
return readFile(srcHtmlPath)
|
||||
.then((contentsRaw) => {
|
||||
let contents = contentsRaw.toString();
|
||||
|
||||
const startMarker = '<!-- begin scripts -->\n';
|
||||
const endMarker = '<!-- end scripts -->';
|
||||
const startInd = contents.indexOf(startMarker) + startMarker.length;
|
||||
const endInd = contents.indexOf(endMarker, startInd);
|
||||
|
||||
let newScript = '';
|
||||
|
||||
if (onlyLegacy) {
|
||||
// Only legacy version, so include things directly
|
||||
for (let i = 0;i < legacyScripts.length;i++) {
|
||||
newScript += ` <script src="${legacyScripts[i]}"></script>\n`;
|
||||
}
|
||||
} else {
|
||||
// Otherwise include both modules and legacy fallbacks
|
||||
newScript += ' <script type="module" crossorigin="anonymous" src="app/ui.js"></script>\n';
|
||||
for (let i = 0;i < legacyScripts.length;i++) {
|
||||
newScript += ` <script nomodule src="${legacyScripts[i]}"></script>\n`;
|
||||
}
|
||||
}
|
||||
|
||||
contents = contents.slice(0, startInd) + `${newScript}\n` + contents.slice(endInd);
|
||||
|
||||
return contents;
|
||||
})
|
||||
.then((contents) => {
|
||||
console.log(`Writing ${outHtmlPath}`);
|
||||
return writeFile(outHtmlPath, contents);
|
||||
});
|
||||
}
|
||||
|
||||
function makeLibFiles(importFormat, sourceMaps, withAppDir, onlyLegacy) {
|
||||
if (!importFormat) {
|
||||
throw new Error("you must specify an import format to generate compiled noVNC libraries");
|
||||
} else if (!SUPPORTED_FORMATS.has(importFormat)) {
|
||||
throw new Error(`unsupported output format "${importFormat}" for import/export -- only ${Array.from(SUPPORTED_FORMATS)} are supported`);
|
||||
}
|
||||
|
||||
function makeLibFiles(sourceMaps) {
|
||||
// NB: we need to make a copy of babelOpts, since babel sets some defaults on it
|
||||
const babelOpts = () => ({
|
||||
plugins: [],
|
||||
presets: [
|
||||
[ '@babel/preset-env',
|
||||
{ targets: 'ie >= 11',
|
||||
modules: importFormat } ]
|
||||
{ modules: 'commonjs' } ]
|
||||
],
|
||||
ast: false,
|
||||
sourceMaps: sourceMaps,
|
||||
});
|
||||
|
||||
// No point in duplicate files without the app, so force only converted files
|
||||
if (!withAppDir) {
|
||||
onlyLegacy = true;
|
||||
}
|
||||
|
||||
let inPath;
|
||||
let outPathBase;
|
||||
if (withAppDir) {
|
||||
outPathBase = paths.outDirBase;
|
||||
inPath = paths.main;
|
||||
} else {
|
||||
outPathBase = paths.libDirBase;
|
||||
}
|
||||
const legacyPathBase = onlyLegacy ? outPathBase : path.join(outPathBase, 'legacy');
|
||||
|
||||
fse.ensureDirSync(outPathBase);
|
||||
|
||||
const helpers = require('./use_require_helpers');
|
||||
const helper = helpers[importFormat];
|
||||
fse.ensureDirSync(paths.libDirBase);
|
||||
|
||||
const outFiles = [];
|
||||
const legacyFiles = [];
|
||||
|
||||
const handleDir = (jsOnly, vendorRewrite, inPathBase, filename) => Promise.resolve()
|
||||
const handleDir = (vendorRewrite, inPathBase, filename) => Promise.resolve()
|
||||
.then(() => {
|
||||
const outPath = path.join(outPathBase, path.relative(inPathBase, filename));
|
||||
const legacyPath = path.join(legacyPathBase, path.relative(inPathBase, filename));
|
||||
const outPath = path.join(paths.libDirBase, path.relative(inPathBase, filename));
|
||||
|
||||
if (path.extname(filename) !== '.js') {
|
||||
if (!jsOnly) {
|
||||
console.log(`Writing ${outPath}`);
|
||||
return copy(filename, outPath);
|
||||
}
|
||||
return; // skip non-javascript files
|
||||
}
|
||||
|
||||
if (noTransformFiles.has(filename)) {
|
||||
return ensureDir(path.dirname(outPath))
|
||||
.then(() => {
|
||||
console.log(`Writing ${outPath}`);
|
||||
return copy(filename, outPath);
|
||||
});
|
||||
}
|
||||
|
||||
if (onlyLegacyScripts.has(filename)) {
|
||||
legacyFiles.push(legacyPath);
|
||||
return ensureDir(path.dirname(legacyPath))
|
||||
.then(() => {
|
||||
console.log(`Writing ${legacyPath}`);
|
||||
return copy(filename, legacyPath);
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
if (onlyLegacy) {
|
||||
return;
|
||||
}
|
||||
return ensureDir(path.dirname(outPath))
|
||||
.then(() => {
|
||||
console.log(`Writing ${outPath}`);
|
||||
return copy(filename, outPath);
|
||||
});
|
||||
})
|
||||
.then(() => ensureDir(path.dirname(legacyPath)))
|
||||
.then(() => ensureDir(path.dirname(outPath)))
|
||||
.then(() => {
|
||||
const opts = babelOpts();
|
||||
if (helper && helpers.optionsOverride) {
|
||||
helper.optionsOverride(opts);
|
||||
}
|
||||
// Adjust for the fact that we move the core files relative
|
||||
// to the vendor directory
|
||||
if (vendorRewrite) {
|
||||
opts.plugins.push(["import-redirect",
|
||||
{"root": legacyPathBase,
|
||||
{"root": paths.libDirBase,
|
||||
"redirect": { "vendor/(.+)": "./vendor/$1"}}]);
|
||||
}
|
||||
|
||||
return babelTransformFile(filename, opts)
|
||||
.then((res) => {
|
||||
console.log(`Writing ${legacyPath}`);
|
||||
console.log(`Writing ${outPath}`);
|
||||
const {map} = res;
|
||||
let {code} = res;
|
||||
if (sourceMaps === true) {
|
||||
// append URL for external source map
|
||||
code += `\n//# sourceMappingURL=${path.basename(legacyPath)}.map\n`;
|
||||
code += `\n//# sourceMappingURL=${path.basename(outPath)}.map\n`;
|
||||
}
|
||||
outFiles.push(`${legacyPath}`);
|
||||
return writeFile(legacyPath, code)
|
||||
outFiles.push(`${outPath}`);
|
||||
return writeFile(outPath, code)
|
||||
.then(() => {
|
||||
if (sourceMaps === true || sourceMaps === 'both') {
|
||||
console.log(` and ${legacyPath}.map`);
|
||||
outFiles.push(`${legacyPath}.map`);
|
||||
return writeFile(`${legacyPath}.map`, JSON.stringify(map));
|
||||
console.log(` and ${outPath}.map`);
|
||||
outFiles.push(`${outPath}.map`);
|
||||
return writeFile(`${outPath}.map`, JSON.stringify(map));
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -246,64 +117,12 @@ function makeLibFiles(importFormat, sourceMaps, withAppDir, onlyLegacy) {
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
const handler = handleDir.bind(null, true, false, inPath || paths.main);
|
||||
const filter = (filename, stats) => !noCopyFiles.has(filename);
|
||||
return walkDir(paths.vendor, handler, filter);
|
||||
const handler = handleDir.bind(null, false, paths.main);
|
||||
return walkDir(paths.vendor, handler);
|
||||
})
|
||||
.then(() => {
|
||||
const handler = handleDir.bind(null, true, !inPath, inPath || paths.core);
|
||||
const filter = (filename, stats) => !noCopyFiles.has(filename);
|
||||
return walkDir(paths.core, handler, filter);
|
||||
})
|
||||
.then(() => {
|
||||
if (!withAppDir) return;
|
||||
const handler = handleDir.bind(null, false, false, inPath);
|
||||
const filter = (filename, stats) => !noCopyFiles.has(filename);
|
||||
return walkDir(paths.app, handler, filter);
|
||||
})
|
||||
.then(() => {
|
||||
if (!withAppDir) return;
|
||||
|
||||
if (!helper || !helper.appWriter) {
|
||||
throw new Error(`Unable to generate app for the ${importFormat} format!`);
|
||||
}
|
||||
|
||||
const outAppPath = path.join(legacyPathBase, 'app.js');
|
||||
console.log(`Writing ${outAppPath}`);
|
||||
return helper.appWriter(outPathBase, legacyPathBase, outAppPath)
|
||||
.then((extraScripts) => {
|
||||
let legacyScripts = [];
|
||||
|
||||
legacyFiles.forEach((file) => {
|
||||
let relFilePath = path.relative(outPathBase, file);
|
||||
legacyScripts.push(relFilePath);
|
||||
});
|
||||
|
||||
legacyScripts = legacyScripts.concat(extraScripts);
|
||||
|
||||
let relAppPath = path.relative(outPathBase, outAppPath);
|
||||
legacyScripts.push(relAppPath);
|
||||
|
||||
transformHtml(legacyScripts, onlyLegacy);
|
||||
})
|
||||
.then(() => {
|
||||
if (!helper.removeModules) return;
|
||||
console.log(`Cleaning up temporary files...`);
|
||||
return Promise.all(outFiles.map((filepath) => {
|
||||
unlink(filepath)
|
||||
.then(() => {
|
||||
// Try to clean up any empty directories if
|
||||
// this was the last file in there
|
||||
const rmdirR = dir =>
|
||||
rmdir(dir)
|
||||
.then(() => rmdirR(path.dirname(dir)))
|
||||
.catch(() => {
|
||||
// Assume the error was ENOTEMPTY and ignore it
|
||||
});
|
||||
return rmdirR(path.dirname(filepath));
|
||||
});
|
||||
}));
|
||||
});
|
||||
const handler = handleDir.bind(null, true, paths.core);
|
||||
return walkDir(paths.core, handler);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Failure converting modules: ${err}`);
|
||||
@ -314,9 +133,6 @@ function makeLibFiles(importFormat, sourceMaps, withAppDir, onlyLegacy) {
|
||||
if (program.clean) {
|
||||
console.log(`Removing ${paths.libDirBase}`);
|
||||
fse.removeSync(paths.libDirBase);
|
||||
|
||||
console.log(`Removing ${paths.outDirBase}`);
|
||||
fse.removeSync(paths.outDirBase);
|
||||
}
|
||||
|
||||
makeLibFiles(program.as, program.withSourceMaps, program.withApp, program.onlyLegacy);
|
||||
makeLibFiles(program.withSourceMaps);
|
||||
|
@ -1,60 +0,0 @@
|
||||
// writes helpers require for vnc.html (they should output app.js)
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// util.promisify requires Node.js 8.x, so we have our own
|
||||
function promisify(original) {
|
||||
return function promiseWrap() {
|
||||
const args = Array.prototype.slice.call(arguments);
|
||||
return new Promise((resolve, reject) => {
|
||||
original.apply(this, args.concat((err, value) => {
|
||||
if (err) return reject(err);
|
||||
resolve(value);
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const writeFile = promisify(fs.writeFile);
|
||||
|
||||
module.exports = {
|
||||
'amd': {
|
||||
appWriter: (baseOutPath, scriptBasePath, outPath) => {
|
||||
// setup for requirejs
|
||||
const uiPath = path.relative(baseOutPath,
|
||||
path.join(scriptBasePath, 'app', 'ui'));
|
||||
return writeFile(outPath, `requirejs(["${uiPath}"], function (ui) {});`)
|
||||
.then(() => {
|
||||
console.log(`Please place RequireJS in ${path.join(scriptBasePath, 'require.js')}`);
|
||||
const requirePath = path.relative(baseOutPath,
|
||||
path.join(scriptBasePath, 'require.js'));
|
||||
return [ requirePath ];
|
||||
});
|
||||
},
|
||||
},
|
||||
'commonjs': {
|
||||
appWriter: (baseOutPath, scriptBasePath, outPath) => {
|
||||
const browserify = require('browserify');
|
||||
const b = browserify(path.join(scriptBasePath, 'app/ui.js'), {});
|
||||
return promisify(b.bundle).call(b)
|
||||
.then(buf => writeFile(outPath, buf))
|
||||
.then(() => []);
|
||||
},
|
||||
removeModules: true,
|
||||
},
|
||||
'systemjs': {
|
||||
appWriter: (baseOutPath, scriptBasePath, outPath) => {
|
||||
const uiPath = path.relative(baseOutPath,
|
||||
path.join(scriptBasePath, 'app', 'ui.js'));
|
||||
return writeFile(outPath, `SystemJS.import("${uiPath}");`)
|
||||
.then(() => {
|
||||
console.log(`Please place SystemJS in ${path.join(scriptBasePath, 'system-production.js')}`);
|
||||
const systemjsPath = path.relative(baseOutPath,
|
||||
path.join(scriptBasePath, 'system-production.js'));
|
||||
return [ systemjsPath ];
|
||||
});
|
||||
},
|
||||
},
|
||||
'umd': {
|
||||
},
|
||||
};
|
15
vendor/browser-es-module-loader/README.md
vendored
15
vendor/browser-es-module-loader/README.md
vendored
@ -1,15 +0,0 @@
|
||||
Custom Browser ES Module Loader
|
||||
===============================
|
||||
|
||||
This is a module loader using babel and the ES Module Loader polyfill.
|
||||
It's based heavily on
|
||||
https://github.com/ModuleLoader/browser-es-module-loader, but uses
|
||||
WebWorkers to compile the modules in the background.
|
||||
|
||||
To generate, run `npx rollup -c` in this directory, and then run
|
||||
`./genworker.js`.
|
||||
|
||||
LICENSE
|
||||
-------
|
||||
|
||||
MIT
|
121458
vendor/browser-es-module-loader/dist/babel-worker.js
vendored
121458
vendor/browser-es-module-loader/dist/babel-worker.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
13
vendor/browser-es-module-loader/genworker.js
vendored
13
vendor/browser-es-module-loader/genworker.js
vendored
@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require("fs");
|
||||
var browserify = require("browserify");
|
||||
|
||||
browserify("src/babel-worker.js")
|
||||
.transform("babelify", {
|
||||
presets: [ [ "@babel/preset-env", { targets: "ie >= 11" } ] ],
|
||||
global: true,
|
||||
ignore: [ "../../node_modules/core-js" ]
|
||||
})
|
||||
.bundle()
|
||||
.pipe(fs.createWriteStream("dist/babel-worker.js"));
|
15
vendor/browser-es-module-loader/rollup.config.js
vendored
15
vendor/browser-es-module-loader/rollup.config.js
vendored
@ -1,15 +0,0 @@
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
|
||||
export default {
|
||||
input: 'src/browser-es-module-loader.js',
|
||||
output: {
|
||||
file: 'dist/browser-es-module-loader.js',
|
||||
format: 'umd',
|
||||
name: 'BrowserESModuleLoader',
|
||||
sourcemap: true,
|
||||
},
|
||||
|
||||
plugins: [
|
||||
nodeResolve(),
|
||||
],
|
||||
};
|
@ -1,23 +0,0 @@
|
||||
// Polyfills needed for Babel to function
|
||||
require("core-js");
|
||||
|
||||
var babelTransform = require('@babel/core').transform;
|
||||
var babelTransformDynamicImport = require('@babel/plugin-syntax-dynamic-import');
|
||||
var babelTransformModulesSystemJS = require('@babel/plugin-transform-modules-systemjs');
|
||||
var babelPresetEnv = require('@babel/preset-env');
|
||||
|
||||
self.onmessage = function (evt) {
|
||||
// transform source with Babel
|
||||
var output = babelTransform(evt.data.source, {
|
||||
compact: false,
|
||||
filename: evt.data.key + '!transpiled',
|
||||
sourceFileName: evt.data.key,
|
||||
moduleIds: false,
|
||||
sourceMaps: 'inline',
|
||||
babelrc: false,
|
||||
plugins: [babelTransformDynamicImport, babelTransformModulesSystemJS],
|
||||
presets: [ [ babelPresetEnv, { targets: 'ie >= 11' } ] ],
|
||||
});
|
||||
|
||||
self.postMessage({key: evt.data.key, code: output.code, source: evt.data.source});
|
||||
};
|
@ -1,279 +0,0 @@
|
||||
import RegisterLoader from 'es-module-loader/core/register-loader.js';
|
||||
|
||||
import { baseURI, global, isBrowser } from 'es-module-loader/core/common.js';
|
||||
import { resolveIfNotPlain } from 'es-module-loader/core/resolve.js';
|
||||
|
||||
var loader;
|
||||
|
||||
// <script type="module"> support
|
||||
var anonSources = {};
|
||||
if (typeof document != 'undefined' && document.getElementsByTagName) {
|
||||
var handleError = function(err) {
|
||||
// dispatch an error event so that we can display in errors in browsers
|
||||
// that don't yet support unhandledrejection
|
||||
if (window.onunhandledrejection === undefined) {
|
||||
try {
|
||||
var evt = new Event('error');
|
||||
} catch (_eventError) {
|
||||
var evt = document.createEvent('Event');
|
||||
evt.initEvent('error', true, true);
|
||||
}
|
||||
evt.message = err.message;
|
||||
if (err.fileName) {
|
||||
evt.filename = err.fileName;
|
||||
evt.lineno = err.lineNumber;
|
||||
evt.colno = err.columnNumber;
|
||||
} else if (err.sourceURL) {
|
||||
evt.filename = err.sourceURL;
|
||||
evt.lineno = err.line;
|
||||
evt.colno = err.column;
|
||||
}
|
||||
evt.error = err;
|
||||
window.dispatchEvent(evt);
|
||||
}
|
||||
|
||||
// throw so it still shows up in the console
|
||||
throw err;
|
||||
}
|
||||
|
||||
var ready = function() {
|
||||
document.removeEventListener('DOMContentLoaded', ready, false );
|
||||
|
||||
var anonCnt = 0;
|
||||
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
var script = scripts[i];
|
||||
if (script.type == 'module' && !script.loaded) {
|
||||
script.loaded = true;
|
||||
if (script.src) {
|
||||
loader.import(script.src).catch(handleError);
|
||||
}
|
||||
// anonymous modules supported via a custom naming scheme and registry
|
||||
else {
|
||||
var uri = './<anon' + ++anonCnt + '>.js';
|
||||
if (script.id !== ""){
|
||||
uri = "./" + script.id;
|
||||
}
|
||||
|
||||
var anonName = resolveIfNotPlain(uri, baseURI);
|
||||
anonSources[anonName] = script.innerHTML;
|
||||
loader.import(anonName).catch(handleError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// simple DOM ready
|
||||
if (document.readyState !== 'loading')
|
||||
setTimeout(ready);
|
||||
else
|
||||
document.addEventListener('DOMContentLoaded', ready, false);
|
||||
}
|
||||
|
||||
function BrowserESModuleLoader(baseKey) {
|
||||
if (baseKey)
|
||||
this.baseKey = resolveIfNotPlain(baseKey, baseURI) || resolveIfNotPlain('./' + baseKey, baseURI);
|
||||
|
||||
RegisterLoader.call(this);
|
||||
|
||||
var loader = this;
|
||||
|
||||
// ensure System.register is available
|
||||
global.System = global.System || {};
|
||||
if (typeof global.System.register == 'function')
|
||||
var prevRegister = global.System.register;
|
||||
global.System.register = function() {
|
||||
loader.register.apply(loader, arguments);
|
||||
if (prevRegister)
|
||||
prevRegister.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
BrowserESModuleLoader.prototype = Object.create(RegisterLoader.prototype);
|
||||
|
||||
// normalize is never given a relative name like "./x", that part is already handled
|
||||
BrowserESModuleLoader.prototype[RegisterLoader.resolve] = function(key, parent) {
|
||||
var resolved = RegisterLoader.prototype[RegisterLoader.resolve].call(this, key, parent || this.baseKey) || key;
|
||||
if (!resolved)
|
||||
throw new RangeError('ES module loader does not resolve plain module names, resolving "' + key + '" to ' + parent);
|
||||
|
||||
return resolved;
|
||||
};
|
||||
|
||||
function xhrFetch(url, resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var load = function(source) {
|
||||
resolve(xhr.responseText);
|
||||
}
|
||||
var error = function() {
|
||||
reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url));
|
||||
}
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
// in Chrome on file:/// URLs, status is 0
|
||||
if (xhr.status == 0) {
|
||||
if (xhr.responseText) {
|
||||
load();
|
||||
}
|
||||
else {
|
||||
// when responseText is empty, wait for load or error event
|
||||
// to inform if it is a 404 or empty file
|
||||
xhr.addEventListener('error', error);
|
||||
xhr.addEventListener('load', load);
|
||||
}
|
||||
}
|
||||
else if (xhr.status === 200) {
|
||||
load();
|
||||
}
|
||||
else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.open("GET", url, true);
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
var WorkerPool = function (script, size) {
|
||||
var current = document.currentScript;
|
||||
// IE doesn't support currentScript
|
||||
if (!current) {
|
||||
// Find an entry with out basename
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
if (scripts[i].src.indexOf("browser-es-module-loader.js") !== -1) {
|
||||
current = scripts[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!current)
|
||||
throw Error("Could not find own <script> element");
|
||||
}
|
||||
script = current.src.substr(0, current.src.lastIndexOf("/")) + "/" + script;
|
||||
this._workers = new Array(size);
|
||||
this._ind = 0;
|
||||
this._size = size;
|
||||
this._jobs = 0;
|
||||
this.onmessage = undefined;
|
||||
this._stopTimeout = undefined;
|
||||
for (var i = 0; i < size; i++) {
|
||||
var wrkr = new Worker(script);
|
||||
wrkr._count = 0;
|
||||
wrkr._ind = i;
|
||||
wrkr.onmessage = this._onmessage.bind(this, wrkr);
|
||||
wrkr.onerror = this._onerror.bind(this);
|
||||
this._workers[i] = wrkr;
|
||||
}
|
||||
|
||||
this._checkJobs();
|
||||
};
|
||||
WorkerPool.prototype = {
|
||||
postMessage: function (msg) {
|
||||
if (this._stopTimeout !== undefined) {
|
||||
clearTimeout(this._stopTimeout);
|
||||
this._stopTimeout = undefined;
|
||||
}
|
||||
var wrkr = this._workers[this._ind % this._size];
|
||||
wrkr._count++;
|
||||
this._jobs++;
|
||||
wrkr.postMessage(msg);
|
||||
this._ind++;
|
||||
},
|
||||
|
||||
_onmessage: function (wrkr, evt) {
|
||||
wrkr._count--;
|
||||
this._jobs--;
|
||||
this.onmessage(evt, wrkr);
|
||||
this._checkJobs();
|
||||
},
|
||||
|
||||
_onerror: function(err) {
|
||||
try {
|
||||
var evt = new Event('error');
|
||||
} catch (_eventError) {
|
||||
var evt = document.createEvent('Event');
|
||||
evt.initEvent('error', true, true);
|
||||
}
|
||||
evt.message = err.message;
|
||||
evt.filename = err.filename;
|
||||
evt.lineno = err.lineno;
|
||||
evt.colno = err.colno;
|
||||
evt.error = err.error;
|
||||
window.dispatchEvent(evt);
|
||||
},
|
||||
|
||||
_checkJobs: function () {
|
||||
if (this._jobs === 0 && this._stopTimeout === undefined) {
|
||||
// wait for 2s of inactivity before stopping (that should be enough for local loading)
|
||||
this._stopTimeout = setTimeout(this._stop.bind(this), 2000);
|
||||
}
|
||||
},
|
||||
|
||||
_stop: function () {
|
||||
this._workers.forEach(function(wrkr) {
|
||||
wrkr.terminate();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var promiseMap = new Map();
|
||||
var babelWorker = new WorkerPool('babel-worker.js', 3);
|
||||
babelWorker.onmessage = function (evt) {
|
||||
var promFuncs = promiseMap.get(evt.data.key);
|
||||
promFuncs.resolve(evt.data);
|
||||
promiseMap.delete(evt.data.key);
|
||||
};
|
||||
|
||||
// instantiate just needs to run System.register
|
||||
// so we fetch the source, convert into the Babel System module format, then evaluate it
|
||||
BrowserESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, processAnonRegister) {
|
||||
var loader = this;
|
||||
|
||||
// load as ES with Babel converting into System.register
|
||||
return new Promise(function(resolve, reject) {
|
||||
// anonymous module
|
||||
if (anonSources[key]) {
|
||||
resolve(anonSources[key])
|
||||
anonSources[key] = undefined;
|
||||
}
|
||||
// otherwise we fetch
|
||||
else {
|
||||
xhrFetch(key, resolve, reject);
|
||||
}
|
||||
})
|
||||
.then(function(source) {
|
||||
// check our cache first
|
||||
var cacheEntry = localStorage.getItem(key);
|
||||
if (cacheEntry) {
|
||||
cacheEntry = JSON.parse(cacheEntry);
|
||||
// TODO: store a hash instead
|
||||
if (cacheEntry.source === source) {
|
||||
return Promise.resolve({key: key, code: cacheEntry.code, source: cacheEntry.source});
|
||||
}
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
promiseMap.set(key, {resolve: resolve, reject: reject});
|
||||
babelWorker.postMessage({key: key, source: source});
|
||||
});
|
||||
}).then(function (data) {
|
||||
// evaluate without require, exports and module variables
|
||||
// we leave module in for now to allow module.require access
|
||||
try {
|
||||
var cacheEntry = JSON.stringify({source: data.source, code: data.code});
|
||||
localStorage.setItem(key, cacheEntry);
|
||||
} catch (e) {
|
||||
if (window.console) {
|
||||
window.console.warn('Unable to cache transpiled version of ' + key + ': ' + e);
|
||||
}
|
||||
}
|
||||
(0, eval)(data.code + '\n//# sourceURL=' + data.key + '!transpiled');
|
||||
processAnonRegister();
|
||||
});
|
||||
};
|
||||
|
||||
// create a default loader instance in the browser
|
||||
if (isBrowser)
|
||||
loader = new BrowserESModuleLoader();
|
||||
|
||||
export default BrowserESModuleLoader;
|
255
vendor/promise.js
vendored
255
vendor/promise.js
vendored
@ -1,255 +0,0 @@
|
||||
/* Copyright (c) 2014 Taylor Hakes
|
||||
* Copyright (c) 2014 Forbes Lindesay
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
(function (root) {
|
||||
|
||||
// Store setTimeout reference so promise-polyfill will be unaffected by
|
||||
// other code modifying setTimeout (like sinon.useFakeTimers())
|
||||
var setTimeoutFunc = setTimeout;
|
||||
|
||||
function noop() {}
|
||||
|
||||
// Polyfill for Function.prototype.bind
|
||||
function bind(fn, thisArg) {
|
||||
return function () {
|
||||
fn.apply(thisArg, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new');
|
||||
if (typeof fn !== 'function') throw new TypeError('not a function');
|
||||
this._state = 0;
|
||||
this._handled = false;
|
||||
this._value = undefined;
|
||||
this._deferreds = [];
|
||||
|
||||
doResolve(fn, this);
|
||||
}
|
||||
|
||||
function handle(self, deferred) {
|
||||
while (self._state === 3) {
|
||||
self = self._value;
|
||||
}
|
||||
if (self._state === 0) {
|
||||
self._deferreds.push(deferred);
|
||||
return;
|
||||
}
|
||||
self._handled = true;
|
||||
Promise._immediateFn(function () {
|
||||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
|
||||
return;
|
||||
}
|
||||
var ret;
|
||||
try {
|
||||
ret = cb(self._value);
|
||||
} catch (e) {
|
||||
reject(deferred.promise, e);
|
||||
return;
|
||||
}
|
||||
resolve(deferred.promise, ret);
|
||||
});
|
||||
}
|
||||
|
||||
function resolve(self, newValue) {
|
||||
try {
|
||||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
|
||||
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
||||
var then = newValue.then;
|
||||
if (newValue instanceof Promise) {
|
||||
self._state = 3;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
return;
|
||||
} else if (typeof then === 'function') {
|
||||
doResolve(bind(then, newValue), self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self._state = 1;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
} catch (e) {
|
||||
reject(self, e);
|
||||
}
|
||||
}
|
||||
|
||||
function reject(self, newValue) {
|
||||
self._state = 2;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
}
|
||||
|
||||
function finale(self) {
|
||||
if (self._state === 2 && self._deferreds.length === 0) {
|
||||
Promise._immediateFn(function() {
|
||||
if (!self._handled) {
|
||||
Promise._unhandledRejectionFn(self._value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0, len = self._deferreds.length; i < len; i++) {
|
||||
handle(self, self._deferreds[i]);
|
||||
}
|
||||
self._deferreds = null;
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, promise) {
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, self) {
|
||||
var done = false;
|
||||
try {
|
||||
fn(function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
resolve(self, value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(self, reason);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(self, ex);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
||||
|
||||
Promise.prototype.then = function (onFulfilled, onRejected) {
|
||||
var prom = new (this.constructor)(noop);
|
||||
|
||||
handle(this, new Handler(onFulfilled, onRejected, prom));
|
||||
return prom;
|
||||
};
|
||||
|
||||
Promise.all = function (arr) {
|
||||
var args = Array.prototype.slice.call(arr);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
|
||||
function res(i, val) {
|
||||
try {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
then.call(val, function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.resolve = function (value) {
|
||||
if (value && typeof value === 'object' && value.constructor === Promise) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
resolve(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
for (var i = 0, len = values.length; i < len; i++) {
|
||||
values[i].then(resolve, reject);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Use polyfill for setImmediate for performance gains
|
||||
Promise._immediateFn = (typeof setImmediate === 'function' && function (fn) { setImmediate(fn); }) ||
|
||||
function (fn) {
|
||||
setTimeoutFunc(fn, 0);
|
||||
};
|
||||
|
||||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
|
||||
if (typeof console !== 'undefined' && console) {
|
||||
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the immediate function to execute callbacks
|
||||
* @param fn {function} Function to execute
|
||||
* @deprecated
|
||||
*/
|
||||
Promise._setImmediateFn = function _setImmediateFn(fn) {
|
||||
Promise._immediateFn = fn;
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the function to execute on unhandled rejection
|
||||
* @param {function} fn Function to execute on unhandled rejection
|
||||
* @deprecated
|
||||
*/
|
||||
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
|
||||
Promise._unhandledRejectionFn = fn;
|
||||
};
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = Promise;
|
||||
} else if (!root.Promise) {
|
||||
root.Promise = Promise;
|
||||
}
|
||||
|
||||
})(this);
|
9
vnc.html
9
vnc.html
@ -54,17 +54,8 @@
|
||||
<!-- Stylesheets -->
|
||||
<link rel="stylesheet" href="app/styles/base.css">
|
||||
|
||||
<!-- this is included as a normal file in order to catch script-loading errors as well -->
|
||||
<script src="app/error-handler.js"></script>
|
||||
|
||||
<!-- begin scripts -->
|
||||
<!-- promise polyfills promises for IE11 -->
|
||||
<script src="vendor/promise.js"></script>
|
||||
<!-- ES2015/ES6 modules polyfill -->
|
||||
<script nomodule src="vendor/browser-es-module-loader/dist/browser-es-module-loader.js"></script>
|
||||
<!-- actual script modules -->
|
||||
<script type="module" crossorigin="anonymous" src="app/ui.js"></script>
|
||||
<!-- end scripts -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -61,13 +61,6 @@
|
||||
|
||||
</style>
|
||||
|
||||
<!-- Promise polyfill for IE11 -->
|
||||
<script src="vendor/promise.js"></script>
|
||||
|
||||
<!-- ES2015/ES6 modules polyfill -->
|
||||
<script nomodule src="vendor/browser-es-module-loader/dist/browser-es-module-loader.js"></script>
|
||||
|
||||
<!-- actual script modules -->
|
||||
<script type="module" crossorigin="anonymous">
|
||||
// RFB holds the API to connect and communicate with a VNC server
|
||||
import RFB from './core/rfb.js';
|
||||
|
Loading…
x
Reference in New Issue
Block a user