Skip to content

Commit

Permalink
[ADD] Library to the rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabhg71 committed Oct 6, 2023
1 parent 1aa0d95 commit fad28f8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"prebuild-min": "del-cli dist",
"build-min": "rollup --config --file dist/www/js/bundle.min.js --environment BUILD:production",
"prebuild-src": "del-cli dist",
"build-src": "rollup --config --file dist/www/js/bundle.js",
"build-src": "rollup --config",
"del-dist": "del-cli dist",
"test": "testcafe all ./tests/unit/initTestCafe.js --app \"http-server --silent -p 8080 .\"",
"test-unit-browsers": "testcafe firefox:headless,chrome:headless,edge:headless ./tests/unit/initTestCafe.js --app \"http-server --silent -p 8080 .\"",
Expand Down
25 changes: 20 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@ import copy from 'rollup-plugin-copy';
import terser from '@rollup/plugin-terser';
// import styles from "@ironkinoko/rollup-plugin-styles";

/** @type {import('rollup').RollupOptions} */
const config = {
// The entry point for the bundler
input: 'www/js/app.js',
output: {
format: 'iife',
name: 'KiwixJSBundle'
// input: ['www/js/app.js', 'www/js/lib/library.js'],
input: {
bundle: 'www/js/app.js',
library: 'www/js/lib/library.js'
},
output: [
{
dir: 'dist/www/js',
// file: 'bundle.js',
format: 'umd',
name: 'KiwixJSBundle'
},
{
dir: 'dist/www/js',
// file: 'library.js',
format: 'umd',
name: 'LibraryJSBundle'
}
],
treeshake: 'recommended',
plugins: [
babel({
Expand All @@ -39,7 +54,7 @@ const config = {
}),
copy({
targets: [{
src: ['www/js/lib/*dec-wasm.wasm', 'www/js/lib/library.js', 'www/js/lib/libzim-asm.js', 'www/js/lib/libzim-wasm.*', 'www/js/lib/webpHeroBundle*',
src: ['www/js/lib/*dec-wasm.wasm', 'www/js/lib/libzim-asm.js', 'www/js/lib/libzim-wasm.*', 'www/js/lib/webpHeroBundle*',
'node_modules/bootstrap/dist/js/bootstrap.bundle.min.*', 'node_modules/jquery/dist/jquery.slim.min.*', '!www/js/lib/libzim-wasm.dev*'],
dest: 'dist/www/js'
},
Expand Down
12 changes: 8 additions & 4 deletions www/js/lib/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ function resizeFrame (height) {
iframe.style.height = height - 20 + 'px'
}

const script = `document.getElementsByTagName('a').addEventListener('click', function (e) {

Check notice on line 14 in www/js/lib/library.js

View check run for this annotation

codefactor.io / CodeFactor

www/js/lib/library.js#L14

'script' is assigned a value but never used. (no-unused-vars)
e.preventDefault();
})`
function setIframeUrl () {
// const libraryURl = urls.libraryUrl
// const fallbackLibraryURl = urls.altLibraryUrl
const libraryURl = LIB_URL.libraryUrl
const fallbackLibraryURl = LIB_URL.altLibraryUrl
const iframe = document.getElementById('libraryIframe')

if (!libraryURl && !fallbackLibraryURl && iframe.getElementsByTagName('body')[0]) return
if (!libraryURl || !fallbackLibraryURl || !iframe) return

let isOptionalChainSupported = true // if not supported, that means the browser is too old
let isParentWindowSupported = true // if not supported, that means it's chrome extension
Expand All @@ -35,18 +38,19 @@ function setIframeUrl () {
}

console.log(iframe);
if (isOptionalChainSupported && isParentWindowSupported && false) {
if (isOptionalChainSupported && isParentWindowSupported) {
iframe.setAttribute('src', libraryURl)

Check warning

Code scanning / CodeQL

Client-side cross-site scripting Medium

Cross-site scripting vulnerability due to
user-provided value
.

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.
console.log('library loaded');
} else {
const xhr = new XMLHttpRequest();

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

The
URL
of this request depends on a
user-provided value
.
console.log(xhr, fallbackLibraryURl);
// iframe.setAttribute('src', fallbackLibraryURl)
// console.log(xhr, fallbackLibraryURl);
xhr.open('GET', fallbackLibraryURl);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
iframe.setAttribute('srcdoc', xhr.responseText)
document.getElementsByTagName('body')[0].innerHTML = xhr.responseText
} else {
throw new Error('Failed to get content from');
}
Expand Down

0 comments on commit fad28f8

Please sign in to comment.