Skip to content

Commit

Permalink
Frontend bundler update nov 2024 (#3091)
Browse files Browse the repository at this point in the history
Co-authored-by: Panagiotis Georgakopoulos <[email protected]>
  • Loading branch information
fonsp and pankgeorg authored Nov 8, 2024
1 parent f5499e3 commit d7e44b6
Show file tree
Hide file tree
Showing 17 changed files with 2,510 additions and 10,872 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/Bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
# Do the actual bundling
- uses: actions/setup-node@v4
with:
node-version: 17.x
node-version: 22.x
cache: "npm"
cache-dependency-path: frontend-bundler/package-lock.json

Expand All @@ -60,7 +60,12 @@ jobs:
working-directory: frontend-bundler
run: |
(npm run build) || (npm run build) || (npm run build)
- name: List generated files
working-directory: frontend-dist
run: |
ls -lha
- name: Check for corrupt files
working-directory: frontend-dist
run: |
Expand Down
2 changes: 1 addition & 1 deletion frontend-bundler/.parcelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"..."
],
"reporters": [
"...",
"...",
"parcel-reporter-bundle-manifest"
]
}
13,252 changes: 2,421 additions & 10,831 deletions frontend-bundler/package-lock.json

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions frontend-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
"author": "",
"license": "ISC",
"dependencies": {
"@parcel/config-default": "^2.0.0",
"mkdirp": "^1.0.4",
"parcel": "^2.0.0",
"@parcel/config-default": "^2.11.0",
"mkdirp": "^3.0.1",
"parcel": "^2.11.0",
"parcel-reporter-bundle-manifest": "^1.0.0",
"parcel-resolver-like-a-browser": "file:../frontend-bundler/parcel-resolver-like-a-browser"
},
"engines": {
"node": ">=22 <23",
"npm": ">=10 <11"
},
"devDependencies": {
"@parcel/optimizer-data-url": "^2.0.0",
"@parcel/transformer-inline-string": "^2.0.0",
"@parcel/optimizer-blob-url": "^2.11.0",
"@parcel/optimizer-data-url": "^2.11.0",
"@plutojl/posthtml-crossorigin": "^1.0.0",
"@types/node": "^16.11.6",
"@types/node": "^22",
"posthtml": "^0.16.6",
"posthtml-sri": "^1.2.0"
"posthtml-sri": "^2.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let { Resolver } = require("@parcel/plugin")
let path = require("path")
let fetch = require("node-fetch")
let fs = require("fs/promises")
let mkdirp = require("mkdirp")
let { mkdirp } = require("mkdirp")
let { URL } = require("url")
let crypto = require("crypto")

Expand Down Expand Up @@ -86,16 +85,16 @@ module.exports = new Resolver({
}
// Can't directly use the value from the request, as parcel really wants a string,
// and converting binary assets into strings and then passing them doesn't work 🤷‍♀️.
let buffer = await response.buffer()
let buffer = await response.arrayBuffer()

const response_length = buffer.length
const response_length = buffer.byteLength

if (response_length === 0) {
throw new Error(`${specifier} returned an empty reponse.`)
}

await mkdirp(folder)
const write_result = await fs.writeFile(fullpath, buffer)
const write_result = await fs.writeFile(fullpath, Buffer.from(buffer))

// Verify that the file was written correctly:
if (write_result !== undefined || (await fs.readFile(fullpath)).length !== response_length) {
Expand Down
5 changes: 2 additions & 3 deletions frontend-bundler/parcel-resolver-like-a-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@parcel/node-resolver-core": "^2.0.0",
"@parcel/plugin": "^2.0.0",
"node-fetch": "^2.6.5"
"@parcel/node-resolver-core": "^3.3.0",
"@parcel/plugin": "^2.0.0"
}
}
25 changes: 19 additions & 6 deletions frontend/common/AudioRecording.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// @ts-ignore
import vmsg from "https://cdn.jsdelivr.net/npm/[email protected]/vmsg.js"
import vmsg from "https://cdn.jsdelivr.net/npm/[email protected]/vmsg.js" // when modifying, also modify the version number in all other files.
import { get_included_external_source } from "./external_source.js"

export const create_recorder = async () => {
const recorder = new vmsg.Recorder({
wasmURL: new URL("https://unpkg.com/[email protected]/vmsg.wasm", import.meta.url),
})
const create_recorder_mp3 = async () => {
const wasmURL = get_included_external_source("vmsg-wasm")?.href

if (!wasmURL) throw new Error("wasmURL not found")

const recorder = new vmsg.Recorder({ wasmURL })

return {
start: async () => {
Expand All @@ -20,8 +23,18 @@ export const create_recorder = async () => {
}
}

export const create_recorder = () => {
try {
return create_recorder_mp3()
} catch (e) {
console.error("Failed to create mp3 recorder", e)
}

return create_recorder_native()
}

// really nice but it can only record to audio/ogg or sometihng, nothing that works across all browsers
export const create_recorder_native = async () => {
const create_recorder_native = async () => {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })

let chunks = []
Expand Down
13 changes: 10 additions & 3 deletions frontend/common/SetupMathJax.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "https://cdn.jsdelivr.net/npm/[email protected]/index.js"
import { get_included_external_source } from "./external_source.js"

let setup_done = false

Expand Down Expand Up @@ -75,14 +76,20 @@ export const setup_mathjax = () => {
requestIdleCallback(
() => {
console.log("Loading mathjax!!")
const script = document.head.querySelector("#MathJax-script")
script?.addEventListener("load", () => {
const src = get_included_external_source("MathJax-script")
if (!src) throw new Error("Could not find mathjax source")

const script = document.createElement("script")
script.addEventListener("load", () => {
console.log("MathJax loaded!")
if (window["MathJax"]?.version !== "3.2.2") {
twowasloaded()
}
})
script.setAttribute("src", script.getAttribute("not-the-src-yet"))
script.crossOrigin = src.crossOrigin
script.integrity = src.integrity
script.src = src.href
document.head.append(script)
},
{ timeout: 2000 }
)
Expand Down
6 changes: 6 additions & 0 deletions frontend/common/external_source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Get a `<link rel="pluto-external-source">` element from editor.html.
* @param {String} id
* @returns {HTMLLinkElement?}
*/
export const get_included_external_source = (id) => document.head.querySelector(`link[rel='pluto-external-source'][id='${id}']`)
5 changes: 3 additions & 2 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { get_environment } from "../common/Environment.js"
import { ProcessStatus } from "../common/ProcessStatus.js"
import { SafePreviewUI } from "./SafePreviewUI.js"
import { open_pluto_popup } from "../common/open_pluto_popup.js"
import { get_included_external_source } from "../common/external_source.js"

// This is imported asynchronously - uncomment for development
// import environment from "../common/Environment.js"
Expand Down Expand Up @@ -257,8 +258,8 @@ const first_true_key = (obj) => {
* }}
*/

const url_logo_big = document.head.querySelector("link[rel='pluto-logo-big']")?.getAttribute("href") ?? ""
export const url_logo_small = document.head.querySelector("link[rel='pluto-logo-small']")?.getAttribute("href") ?? ""
const url_logo_big = get_included_external_source("pluto-logo-big")?.href
export const url_logo_small = get_included_external_source("pluto-logo-small")?.href

/**
* @typedef EditorProps
Expand Down
12 changes: 5 additions & 7 deletions frontend/components/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { useDebouncedTruth } from "./RunArea.js"
import { time_estimate, usePackageTimingData } from "../common/InstallTimeEstimate.js"
import { pretty_long_time } from "./EditOrRunButton.js"
import { useEventListener } from "../common/useEventListener.js"
import { get_included_external_source } from "../common/external_source.js"

// This funny thing is a way to tell parcel to bundle these files..
// Eventually I'll write a plugin that is able to parse html`...`, but this is it for now.
// https://parceljs.org/languages/javascript/#url-dependencies
export const arrow_up_circle_icon = new URL("https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/arrow-up-circle-outline.svg", import.meta.url)
export const document_text_icon = new URL("https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/document-text-outline.svg", import.meta.url)
export const help_circle_icon = new URL("https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/help-circle-outline.svg", import.meta.url)
export const open_icon = new URL("https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/open-outline.svg", import.meta.url)
export const arrow_up_circle_icon = get_included_external_source("arrow_up_circle_icon")?.href
export const document_text_icon = get_included_external_source("document_text_icon")?.href
export const help_circle_icon = get_included_external_source("help_circle_icon")?.href
export const open_icon = get_included_external_source("open_icon")?.href

/**
* @typedef PkgPopupDetails
Expand Down
6 changes: 4 additions & 2 deletions frontend/editor.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8";

@import url("https://cdn.jsdelivr.net/npm/[email protected]/dist/dialog-polyfill.css");

/* @import url("https://fonts.googleapis.com/css?family=Roboto+Mono:400,400i,500,700&display=swap&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext"); */
Expand Down Expand Up @@ -3765,9 +3767,9 @@ pluto-cell.hooked_up pluto-output {
}

.markdown-code-block-button::before {
background-image: url("https://unpkg.com/ionicons@7.1.0/dist/svg/copy-outline.svg");
background-image: url("https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/copy-outline.svg");
}

.markdown-code-block-copied-code-button::before {
background-image: url("https://unpkg.com/ionicons@7.1.0/dist/svg/checkmark-outline.svg");
background-image: url("https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/checkmark-outline.svg");
}
12 changes: 9 additions & 3 deletions frontend/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<link rel="icon" type="image/png" sizes="16x16" href="./img/favicon-16x16.png" />
<link rel="icon" type="image/png" sizes="32x32" href="./img/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="96x96" href="./img/favicon-96x96.png" />
<link rel="pluto-logo-big" href="./img/logo.svg" />
<link rel="pluto-logo-small" href="./img/favicon_unsaturated.svg" />
<link rel="pluto-external-source" id="pluto-logo-big" href="./img/logo.svg" />
<link rel="pluto-external-source" id="pluto-logo-small" href="./img/favicon_unsaturated.svg" />

<script defer>
console.log(
Expand All @@ -28,6 +28,12 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/iframeResizer.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/ansi_up.min.js" defer></script>

<link rel="pluto-external-source" id="vmsg-wasm" href="https://unpkg.com/[email protected]/vmsg.wasm">
<link rel="pluto-external-source" id="arrow_up_circle_icon" href="https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/arrow-up-circle-outline.svg">
<link rel="pluto-external-source" id="document_text_icon" href="https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/document-text-outline.svg">
<link rel="pluto-external-source" id="help_circle_icon" href="https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/help-circle-outline.svg">
<link rel="pluto-external-source" id="open_icon" href="https://cdn.jsdelivr.net/gh/ionic-team/[email protected]/src/svg/open-outline.svg">

<!-- This doesn't do anything unless activated, and it makes sure parcel bundles this -->
<script id="iframe-resizer-content-window-script" src="https://cdn.jsdelivr.net/npm/[email protected]/js/iframeResizer.contentWindow.min.js" crossorigin="anonymous" defer></script>

Expand All @@ -42,7 +48,7 @@
<script src="./warn_old_browsers.js"></script>

<!-- This script will be enabled by JS after the notebook has initialized to prevent taking up bandwidth during the initial load. -->
<script type="text/javascript" id="MathJax-script" integrity="sha384-4kE/rQ11E8xT9QgrCBTyvenkuPfQo8rXYQvJZuMgxyPOoUfpatjQPlgdv6V5yhUK" crossorigin="anonymous" not-the-src-yet="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg-full.js" async></script>
<link rel="pluto-external-source" id="MathJax-script" href="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg-full.js" type="text/javascript">

<meta name="pluto-insertion-spot-preload">
</head>
Expand Down
2 changes: 2 additions & 0 deletions frontend/error.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8";

* {
box-sizing: border-box;
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8";

@import url("https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/400.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/400-italic.css");

Expand Down
2 changes: 2 additions & 0 deletions frontend/treeview.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8";

@import url("https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/400.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/400-italic.css");
@import url("https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/700.css");
Expand Down
2 changes: 2 additions & 0 deletions frontend/welcome.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8";

@import url("https://cdn.jsdelivr.net/npm/[email protected]/inter-latin.css");

:root {
Expand Down

0 comments on commit d7e44b6

Please sign in to comment.