Skip to content

Added polyscript/service-worker as workaround for missing sabayon #2334

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

Merged
merged 5 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,329 changes: 1,117 additions & 212 deletions core/package-lock.json

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.6.46",
"version": "0.6.51",
"type": "module",
"description": "PyScript",
"module": "./index.js",
Expand Down Expand Up @@ -35,6 +35,9 @@
"./storage": {
"import": "./dist/storage.js"
},
"./service-worker": {
"import": "./dist/service-worker.js"
},
"./package.json": "./package.json"
},
"scripts": {
Expand Down Expand Up @@ -64,35 +67,35 @@
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",
"@webreflection/idb-map": "^0.3.2",
"@webreflection/utils": "^0.1.0",
"add-promise-listener": "^0.1.3",
"basic-devtools": "^0.1.6",
"polyscript": "^0.17.8",
"sabayon": "^0.7.2",
"polyscript": "^0.17.15",
"sticky-module": "^0.1.1",
"to-json-callback": "^0.1.1",
"type-checked-collections": "^0.1.7"
},
"devDependencies": {
"@codemirror/commands": "^6.8.1",
"@codemirror/lang-python": "^6.1.7",
"@codemirror/lang-python": "^6.2.0",
"@codemirror/language": "^6.11.0",
"@codemirror/state": "^6.5.2",
"@codemirror/view": "^6.36.5",
"@codemirror/view": "^6.36.7",
"@playwright/test": "^1.52.0",
"@rollup/plugin-commonjs": "^28.0.3",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-terser": "^0.4.4",
"@webreflection/toml-j0.4": "^1.1.3",
"@webreflection/toml-j0.4": "^1.1.4",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-web-links": "^0.11.0",
"@xterm/xterm": "^5.5.0",
"bun": "^1.2.10",
"bun": "^1.2.12",
"chokidar": "^4.0.3",
"codedent": "^0.1.2",
"codemirror": "^6.0.1",
"eslint": "^9.25.1",
"eslint": "^9.26.0",
"flatted": "^3.3.3",
"rollup": "^4.40.0",
"rollup": "^4.40.2",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
"static-handler": "^0.5.3",
Expand Down
11 changes: 11 additions & 0 deletions core/rollup/core.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ export default [
sourcemap: true,
},
},
{
input: "./src/service-worker.js",
plugins: plugins.concat(
process.env.NO_MIN
? [nodeResolve(), commonjs()]
: [nodeResolve(), commonjs(), terser()],
),
output: {
file: "./dist/service-worker.js",
},
},
];
3 changes: 2 additions & 1 deletion core/src/all-done.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import withResolvers from "@webreflection/utils/with-resolvers";
import TYPES from "./types.js";

const waitForIt = [];

for (const [TYPE] of TYPES) {
const selectors = [`script[type="${TYPE}"]`, `${TYPE}-script`];
for (const element of document.querySelectorAll(selectors.join(","))) {
const { promise, resolve } = Promise.withResolvers();
const { promise, resolve } = withResolvers();
waitForIt.push(promise);
element.addEventListener(`${TYPE}:done`, resolve, { once: true });
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import "./zero-redirect.js";
import stickyModule from "sticky-module";
import "@ungap/with-resolvers";
import withResolvers from "@webreflection/utils/with-resolvers";

import {
INVALID_CONTENT,
Expand Down Expand Up @@ -328,7 +328,7 @@ for (const [TYPE, interpreter] of TYPES) {
class extends HTMLElement {
constructor() {
assign(super(), {
_wrap: Promise.withResolvers(),
_wrap: withResolvers(),
srcCode: "",
executed: false,
});
Expand Down
3 changes: 2 additions & 1 deletion core/src/fs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import IDBMap from "@webreflection/idb-map";
import withResolvers from "@webreflection/utils/with-resolvers";
import { assign } from "polyscript/exports";
import { $$ } from "basic-devtools";

Expand Down Expand Up @@ -26,7 +27,7 @@ export const getFileSystemDirectoryHandle = async (options) => {
);
}

const { promise, resolve, reject } = Promise.withResolvers();
const { promise, resolve, reject } = withResolvers();

const how = { id: "pyscript", mode: "readwrite", ...options };
if (options.hint) how.startIn = options.hint;
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/py-editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// PyScript py-editor plugin
import withResolvers from "@webreflection/utils/with-resolvers";
import { Hook, XWorker, dedent, defineProperties } from "polyscript/exports";
import { TYPES, offline_interpreter, relative_url, stdlib } from "../core.js";
import { notify } from "./error.js";
Expand Down Expand Up @@ -99,7 +100,7 @@ async function execute({ currentTarget }) {
}

const { sync } = xworker;
const { promise, resolve } = Promise.withResolvers();
const { promise, resolve } = withResolvers();
envs.set(env, promise);
sync.revoke = () => {
URL.revokeObjectURL(srcLink);
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/py-terminal/mpy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// PyScript pyodide terminal plugin
import withResolvers from "@webreflection/utils/with-resolvers";
import { defineProperties } from "polyscript/exports";
import { hooks, inputFailure } from "../../core.js";

Expand Down Expand Up @@ -146,7 +147,7 @@ export default async (element) => {
// frees the worker on \r
sync.pyterminal_read = (buffer) => {
terminal.write(buffer);
promisedChunks = Promise.withResolvers();
promisedChunks = withResolvers();
return promisedChunks.promise;
};

Expand Down
1 change: 1 addition & 0 deletions core/src/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "polyscript/service-worker";
6 changes: 3 additions & 3 deletions core/src/storage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ArrayBuffer, TypedArray } from "sabayon/shared";
import IDBMapSync from "@webreflection/idb-map/sync";
import { parse, stringify } from "flatted";

const { isView } = ArrayBuffer;

const to_idb = (value) => {
if (value == null) return stringify(["null", 0]);
/* eslint-disable no-fallthrough */
switch (typeof value) {
case "object": {
if (value instanceof TypedArray)
return stringify(["memoryview", [...value]]);
if (isView(value)) return stringify(["memoryview", [...value]]);
if (value instanceof ArrayBuffer)
return stringify(["bytearray", [...new Uint8Array(value)]]);
}
Expand Down
Loading