Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native es6 modules instead of require js #1025

Merged
merged 74 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
b6e9825
Working but not fontawesome
Jaifroid Jun 18, 2023
0788a14
Now with fontawesome
Jaifroid Jun 18, 2023
9337018
Restore menu collapsing
Jaifroid Jun 18, 2023
032405c
Initial specification of SW files
Jaifroid Jun 18, 2023
d6f855e
Remove unneeded permissions
Jaifroid Jun 18, 2023
16ec547
Remove dependencies managed by NPM
Jaifroid Jun 18, 2023
a8b2c9c
Fix tests
Jaifroid Jun 18, 2023
bc24477
Make sure common-js can run
Jaifroid Jun 18, 2023
b449b7c
Add webpMachine loading
Jaifroid Jun 18, 2023
9393259
Fix test_pwa_server
Jaifroid Jun 18, 2023
63f5c72
Merge branch 'main' into Use-native-ES6-modules-instead-of-RequireJS
Jaifroid Jun 18, 2023
c429109
Add babel, rollup, vite configurations
Jaifroid Jun 19, 2023
91ceffd
Completely remove require.js
Jaifroid Jun 19, 2023
de31135
Miscellaneous
Jaifroid Jun 19, 2023
31d9963
Import jQuery directly
Jaifroid Jun 19, 2023
b4e5ab5
Package-lock and ignore
Jaifroid Jun 19, 2023
5bb4f77
Merge branch 'main' into Use-native-ES6-modules-instead-of-RequireJS
Jaifroid Jun 23, 2023
e3948eb
Merge branch 'main' into Use-native-ES6-modules-instead-of-RequireJS
Jaifroid Jun 24, 2023
f694201
Fix more ESLint issues
Jaifroid Jun 24, 2023
0b44354
Another attempt to make jQuery available globally
Jaifroid Jun 24, 2023
722da9b
Use NPM for Bootstrap and jQuery
Jaifroid Jun 25, 2023
261d1fa
Add rollup config to deal with bootstrap and jquery
Jaifroid Jun 25, 2023
7b9ee6f
Remove Sauce Labs tests
Jaifroid Jun 25, 2023
3779414
Remove unneeded require
Jaifroid Jun 25, 2023
f629fc8
Correct ESLint for nightwatch_runner
Jaifroid Jun 25, 2023
f8706a4
Remove vulnerabilities
Jaifroid Jun 25, 2023
191b119
Try upgrading nightwatch
Jaifroid Jun 25, 2023
c58b5db
Test running nightwatch on gha
Jaifroid Jun 26, 2023
c7fc63a
Fix ESLint issues
Jaifroid Jun 26, 2023
431418d
Try CI Unite tests with testcafe on gh-actions
Jaifroid Jun 26, 2023
dfa85a1
Add headless
Jaifroid Jun 26, 2023
1ec7feb
Remove nightwatch
Jaifroid Jun 26, 2023
967805b
Add test for all three browsers
Jaifroid Jun 26, 2023
7902c3c
Remove start-server-and-test
Jaifroid Jun 26, 2023
53c618a
Increase timeout for tests
Jaifroid Jun 26, 2023
08fcb01
Fix double-quoted strings
Jaifroid Jun 26, 2023
ba3dd4b
Add a build test and mac
Jaifroid Jun 26, 2023
512cd2b
Consolidate some tests
Jaifroid Jun 26, 2023
a0776f9
Try to fix Mac test
Jaifroid Jun 26, 2023
ad4b7e3
Try again with Safari
Jaifroid Jun 26, 2023
8aa988a
Update CI.yml
Jaifroid Jun 26, 2023
5b3af45
Disable mac and increase timeout
Jaifroid Jun 26, 2023
7c364df
Run unit tests in windows sequentially
Jaifroid Jun 26, 2023
6a23dd9
Lower version of fontawesome to support IE11
Jaifroid Jun 26, 2023
10aac0f
Add more robust dataURItoUint8Array converter
Jaifroid Jun 26, 2023
b541050
Update contribution guide
Jaifroid Jun 27, 2023
3f3f3a0
Finesse contributing guidelines
Jaifroid Jun 27, 2023
cb2ce04
Finesse contributing text and mention testing platform
Jaifroid Jun 27, 2023
fed154d
Fix image loading in IE11
Jaifroid Jul 1, 2023
3686d3e
Ensure dist has files needed to build apps
Jaifroid Jul 1, 2023
483c94d
Remove last of nightwatch
Jaifroid Jul 1, 2023
cffb3e9
Update publish-extension.yaml
Jaifroid Jul 1, 2023
cbc6520
Update publish-extension.yaml
Jaifroid Jul 1, 2023
82bc0d8
Add clearer information about support
Jaifroid Jul 1, 2023
8653ba0
Ensure the distribution version is published to docker
Jaifroid Jul 2, 2023
1119183
Add logic to build all apps from dist
Jaifroid Jul 2, 2023
5b5484f
Update Release.yml
Jaifroid Jul 2, 2023
0bfe732
Fix modifying appVersion
Jaifroid Jul 2, 2023
6d3ef31
Correct typo
Jaifroid Jul 2, 2023
ffaa79b
Build only minified version
Jaifroid Jul 2, 2023
b15e246
Remove .map files from bundles
Jaifroid Jul 2, 2023
a5143bd
Add some diagnostics
Jaifroid Jul 2, 2023
d498653
Don't overwrite manifest.json with ubuntu_touch version!
Jaifroid Jul 2, 2023
dad1b99
Add more diagnostics
Jaifroid Jul 2, 2023
728342b
Even more diagnostics
Jaifroid Jul 2, 2023
e63bd00
Don't install unneeded packages
Jaifroid Jul 2, 2023
839a826
Update package_firefox_extension.sh
Jaifroid Jul 2, 2023
336f86c
Final script cleanup
Jaifroid Jul 2, 2023
6e7dd90
Update README.md
Jaifroid Jul 2, 2023
47116eb
Fix regression caused by new loading method for webpHero
Jaifroid Jul 2, 2023
d8c6b0d
Add new packages to acknowledgements
Jaifroid Jul 2, 2023
b62334e
Remove packages no longer used
Jaifroid Jul 2, 2023
f86377d
Remove unused packages
Jaifroid Jul 2, 2023
8650815
Make sure both final lines are green
Jaifroid Jul 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,580 changes: 5,370 additions & 4,210 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"private": true,
"type": "module",
"scripts": {
"serve": "http-server .",
"test": "npm run test-unit-local",
Expand All @@ -12,6 +12,11 @@
"engines": {
"node": ">=10"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.4.0",
"bootstrap": "^4.6.2",
"jquery": "^3.7.0"
},
"devDependencies": {
"eslint": "^8.42.0",
"eslint-config-standard": "^17.1.0",
Expand All @@ -26,7 +31,6 @@
"karma-requirejs": "^1.1.0",
"karma-sauce-launcher": "^4.3.4",
"nightwatch": "1.7.13",
"qunit": "^2.13.0",
"requirejs": "2.3.3"
"qunit": "^2.13.0"
}
}
24 changes: 14 additions & 10 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,18 @@ <h3>Expert settings</h3>
</div>
</footer>
</section>

<!-- Using require.js, a module system for javascript, include the
js files. This loads "init.js", which in turn can load other
files, all handled by require.js:
https://requirejs.org/docs/api.html#jsfiles -->
<script type="text/javascript"
data-main="js/init.js"
src="js/lib/require.js">
</script>
</body>
<script type="importmap">
{
"imports": {
"bootstrap": "../node_modules/bootstrap/dist/js/bootstrap.bundle.js",
"jquery": "../node_modules/jquery/dist/jquery.slim.min.js",
"fontawesome": "../node_modules/@fortawesome/fontawesome-free/js/all.js"
}
}
</script>
<script type="text/javascript" src="js/init.js"></script>
<script type="module" defer src="js/app.js"></script>
<!-- <script type="module" src="js/lib/jquery-3.7.0.slim.min.js"></script>
<script type="text/javascript" src="js/lib/bootstrap.bundle.js"></script> -->
</body>
</html>
4,008 changes: 2,007 additions & 2,001 deletions www/js/app.js

Large diffs are not rendered by default.

41 changes: 5 additions & 36 deletions www/js/init.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* init.js : Configuration for the library require.js
* This file handles the dependencies between javascript libraries
/*!
* init.js : Configuration for the app
* This file sets the app's main parameters and variables
*
* Copyright 2013-2020 Mossroy and contributors
* Copyright 2013-2023 Mossroy, Jaifroid and contributors
* License GPL v3:
*
* This file is part of Kiwix.
Expand All @@ -20,9 +20,8 @@
* You should have received a copy of the GNU General Public License
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
*/
'use strict';

/* global requirejs */
'use strict';

/**
* A global parameter object for storing variables that need to be remembered between page loads,
Expand All @@ -45,36 +44,6 @@ if (/PWA_launch=/.test(window.location.search)) {
if (match[1] === 'success') localStorage.setItem(params.keyPrefix + 'defaultModeChangeAlertDisplayed', true);
console.warn('Launch of PWA has been registered as "' + match[1] + '" by the extension. Exiting local code.');
} else {
require.config({
baseUrl: 'js/lib',
paths: {
jquery: 'jquery-3.7.0.slim.min',
bootstrap: 'bootstrap.bundle',
webpHeroBundle: 'webpHeroBundle_0.0.2',
fontawesome: 'fontawesome/fontawesome',
'fontawesome-solid': 'fontawesome/solid'
},
shim: {
jquery: {
exports: '$'
},
bootstrap: {
deps: ['jquery', 'fontawesome', 'fontawesome-solid']
},
webpHeroBundle: ''
}
});

var req = ['bootstrap']; // Baseline Require array

// Add polyfills to the Require array only if needed
if (!('Promise' in self)) req.push('promisePolyfill');
if (!('from' in Array)) req.push('arrayFromPolyfill');

requirejs(req, function () {
requirejs(['../app']);
});

// Test if WebP is natively supported, and if not, set webpMachine to true. The value of webpMachine
// will determine whether the WebP Polyfills will be loaded (currently only used in uiUtil.js)
var webpMachine = false;
Expand Down
133 changes: 58 additions & 75 deletions www/js/lib/abstractFilesystemAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,84 +26,67 @@
*/

'use strict';
function StorageFirefoxOS(storage) {
this._storage = storage;
this.storageName = storage.storageName;
}
/**
* Access the given file.
* @param {String} path absolute path to the file
* @return {Promise} Promise which is resolved with a HTML5 file object and
* rejected with an error message.
*/
StorageFirefoxOS.prototype.get = function (path) {
var that = this;
return new Promise(function (resolve, reject) {
var request = that._storage.get(path);
request.onsuccess = function () { resolve(this.result); };
request.onerror = function () { reject(this.error.name); };
});
};

/* global define */

define([], function () {
/**
* Storage implemented by Firefox OS
*
* @typedef StorageFirefoxOS
* @property {DeviceStorage} _storage DeviceStorage
* @property {String} storageName Name of the storage
*/

/**
* Creates an abstraction layer around the FirefoxOS storage.
* @param storage FirefoxOS DeviceStorage object
*/
function StorageFirefoxOS (storage) {
this._storage = storage;
this.storageName = storage.storageName;
};
/**
* Access the given file.
* @param {String} path absolute path to the file
* @return {Promise} Promise which is resolved with a HTML5 file object and
* rejected with an error message.
*/
StorageFirefoxOS.prototype.get = function (path) {
var that = this;
return new Promise(function (resolve, reject) {
var request = that._storage.get(path);
request.onsuccess = function () { resolve(this.result); };
request.onerror = function () { reject(this.error.name); };
});
};

// We try to match both a standalone ZIM file (.zim) or
// the first file of a split ZIM files collection (.zimaa)
var regexpZIMFileName = /\.zim(aa)?$/i;
// We try to match both a standalone ZIM file (.zim) or
// the first file of a split ZIM files collection (.zimaa)
var regexpZIMFileName = /\.zim(aa)?$/i;

/**
* Searches for archive files or directories.
* @return {Promise} Promise which is resolved with an array of
* paths and rejected with an error message.
*/
StorageFirefoxOS.prototype.scanForArchives = function () {
var that = this;
return new Promise(function (resolve, reject) {
var directories = [];
var cursor = that._storage.enumerate();
cursor.onerror = function () {
reject(cursor.error);
};
cursor.onsuccess = function () {
if (!cursor.result) {
resolve(directories);
return;
}
var file = cursor.result;
/**
* Searches for archive files or directories.
* @return {Promise} Promise which is resolved with an array of
* paths and rejected with an error message.
*/
StorageFirefoxOS.prototype.scanForArchives = function () {
var that = this;
return new Promise(function (resolve, reject) {
var directories = [];
var cursor = that._storage.enumerate();
cursor.onerror = function () {
reject(cursor.error);
};
cursor.onsuccess = function () {
if (!cursor.result) {
resolve(directories);
return;
}
var file = cursor.result;

if (regexpZIMFileName.test(file.name)) {
directories.push(file.name);
}
if (regexpZIMFileName.test(file.name)) {
directories.push(file.name);
}

cursor.continue();
};
});
};
cursor.continue();
};
});
};

/**
* Browse a path through DeviceStorage API
* @param path Path where to look for files
* @return {DOMCursor} Cursor of files found in given path
*/
StorageFirefoxOS.prototype.enumerate = function (path) {
return this._storage.enumerate();
};
/**
* Browse a path through DeviceStorage API
* @param path Path where to look for files
* @return {DOMCursor} Cursor of files found in given path
*/
StorageFirefoxOS.prototype.enumerate = function (path) {
return this._storage.enumerate();
};

return {
StorageFirefoxOS: StorageFirefoxOS
};
});
export default {
StorageFirefoxOS: StorageFirefoxOS
};
12 changes: 7 additions & 5 deletions www/js/lib/arrayFromPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

var arNew = [],
k = [], // used for convert Set to an Array
i = 0;
i = 0,
v;

//if you do not need a Set object support then
//you can comment or delete the following if statement
Expand All @@ -21,11 +22,12 @@
arr = k;
}

for (; i < arr.length; i++)
for (; i < (arr.length || arr.size); i++) {
v = typeof arr[i] !== 'undefined' ? arr[i] : arr.get ? arr.get(i) : null;
arNew[i] = callbackFn ?
callbackFn.call(thisArg, arr[i], i, arr) :
arr[i];

callbackFn.call(thisArg, v, i, arr) : v;
}
return arNew;
}
//You could also use it without the following line, but it is not recommended because native function is faster.
Expand Down
Loading