Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tech preview sync #47

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 1 commit into from
Jun 22, 2023
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
Tech preview sync
  • Loading branch information
Ted Patrick committed Jun 22, 2023
commit 137fa91c3d0a1132c59c87e01679b433da7e811a
12 changes: 12 additions & 0 deletions 12 tech-preview/pyscript.core/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"browser": true,
"es2022": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {}
}
30 changes: 30 additions & 0 deletions 30 tech-preview/pyscript.core/.github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm run coverage --if-present
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions 8 tech-preview/pyscript.core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
coverage/
node_modules/
cjs/
!cjs/package.json
core.js
esm/worker/xworker.js
types/
19 changes: 19 additions & 0 deletions 19 tech-preview/pyscript.core/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.DS_Store
.nyc_output
.eslintrc.json
.github/
.travis.yml
.eslintrc.json
*.log
coverage/
micropython/
node_modules/
pyscript/
rollup/
test/
index.html
node.importmap
sw.js
tsconfig.json
cjs/worker/_template.js
esm/worker/_template.js
1 change: 1 addition & 0 deletions 1 tech-preview/pyscript.core/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=true
2 changes: 1 addition & 1 deletion 2 tech-preview/pyscript.core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This project requires some automatic artifact creation to:

* create a _Worker_ as a _Blob_ based on the same code used by this repo
* create automatically the list of runtimes available via the module
* create the `min.js` file used by most integration tests
* create the `core.js` file used by most integration tests
* create a sha256 version of the Blob content for CSP cases

Accordingly, to build latest project:
Expand Down
12 changes: 2 additions & 10 deletions 12 tech-preview/pyscript.core/cjs/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
const { getRuntimeID } = require("./loader.js");
const { io } = require("./interpreter/_utils.js");
const { addAllListeners } = require("./listeners.js");
const { Hook } = require("./worker/hooks.js");

const CUSTOM_SELECTORS = [];
exports.CUSTOM_SELECTORS = CUSTOM_SELECTORS;
Expand Down Expand Up @@ -66,18 +67,9 @@ const handleCustomType = (node) => {
onBeforeRunAsync,
onAfterRun,
onAfterRunAsync,
codeBeforeRunWorker,
codeBeforeRunWorkerAsync,
codeAfterRunWorker,
codeAfterRunWorkerAsync,
} = options;

const hooks = {
beforeRun: codeBeforeRunWorker?.(),
beforeRunAsync: codeBeforeRunWorkerAsync?.(),
afterRun: codeAfterRunWorker?.(),
afterRunAsync: codeAfterRunWorkerAsync?.(),
};
const hooks = new Hook(options);

const XWorker = function XWorker(...args) {
return Worker.apply(hooks, args);
Expand Down
8 changes: 2 additions & 6 deletions 8 tech-preview/pyscript.core/cjs/custom/pyscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,10 @@ document.head.appendChild(document.createElement("style")).textContent = `
env: "py-script",
interpreter: "pyodide",
codeBeforeRunWorker() {
const { codeBeforeRunWorker: set } = hooks;
const prefix = 'print("codeBeforeRunWorker")';
return [prefix].concat(...set).join("\n");
return [...hooks.codeBeforeRunWorker].join("\n");
},
codeAfterRunWorker() {
const { codeAfterRunWorker: set } = hooks;
const prefix = 'print("codeAfterRunWorker")';
return [prefix].concat(...set).join("\n");
return [...hooks.codeAfterRunWorker].join("\n");
},
onBeforeRun(pyodide, element) {
bootstrapNodeAndPlugins(pyodide, element, before, "onBeforeRun");
Expand Down
7 changes: 5 additions & 2 deletions 7 tech-preview/pyscript.core/cjs/worker/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const coincident = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c
const xworker = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require("./xworker.js"));
const { assign, defineProperties, absoluteURL } = require("../utils.js");
const { getText } = require("../fetch-utils.js");
const { Hook } = require("./hooks.js");

/**
* @typedef {Object} WorkerOptions custom configuration
Expand All @@ -22,7 +23,6 @@ module.exports = (...args) =>
function XWorker(url, options) {
const worker = xworker();
const { postMessage } = worker;
const hooks = this instanceof XWorker ? void 0 : this;
if (args.length) {
const [type, version] = args;
options = assign({}, options || { type, version });
Expand All @@ -31,7 +31,10 @@ module.exports = (...args) =>
if (options?.config) options.config = absoluteURL(options.config);
const bootstrap = fetch(url)
.then(getText)
.then((code) => postMessage.call(worker, { options, code, hooks }));
.then((code) => {
const hooks = this instanceof Hook ? this : void 0;
postMessage.call(worker, { options, code, hooks });
});
return defineProperties(worker, {
postMessage: {
value: (data, ...rest) =>
Expand Down
17 changes: 16 additions & 1 deletion 17 tech-preview/pyscript.core/cjs/worker/hooks.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
'use strict';
module.exports = new WeakMap();
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const workerHooks = [
["beforeRun", "codeBeforeRunWorker"],
["beforeRunAsync", "codeBeforeRunWorkerAsync"],
["afterRun", "codeAfterRunWorker"],
["afterRunAsync", "codeAfterRunWorkerAsync"],
];

class Hook {
constructor(fields) {
for (const [key, value] of workerHooks) this[key] = fields[value]?.();
}
}
exports.Hook = Hook
/* c8 ignore stop */
2 changes: 1 addition & 1 deletion 2 tech-preview/pyscript.core/core.js

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions 12 tech-preview/pyscript.core/esm/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { getRuntimeID } from "./loader.js";
import { io } from "./interpreter/_utils.js";
import { addAllListeners } from "./listeners.js";
import { Hook } from "./worker/hooks.js";

export const CUSTOM_SELECTORS = [];

Expand Down Expand Up @@ -64,18 +65,9 @@ export const handleCustomType = (node) => {
onBeforeRunAsync,
onAfterRun,
onAfterRunAsync,
codeBeforeRunWorker,
codeBeforeRunWorkerAsync,
codeAfterRunWorker,
codeAfterRunWorkerAsync,
} = options;

const hooks = {
beforeRun: codeBeforeRunWorker?.(),
beforeRunAsync: codeBeforeRunWorkerAsync?.(),
afterRun: codeAfterRunWorker?.(),
afterRunAsync: codeAfterRunWorkerAsync?.(),
};
const hooks = new Hook(options);

const XWorker = function XWorker(...args) {
return Worker.apply(hooks, args);
Expand Down
8 changes: 2 additions & 6 deletions 8 tech-preview/pyscript.core/esm/custom/pyscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ document.head.appendChild(document.createElement("style")).textContent = `
env: "py-script",
interpreter: "pyodide",
codeBeforeRunWorker() {
const { codeBeforeRunWorker: set } = hooks;
const prefix = 'print("codeBeforeRunWorker")';
return [prefix].concat(...set).join("\n");
return [...hooks.codeBeforeRunWorker].join("\n");
},
codeAfterRunWorker() {
const { codeAfterRunWorker: set } = hooks;
const prefix = 'print("codeAfterRunWorker")';
return [prefix].concat(...set).join("\n");
return [...hooks.codeAfterRunWorker].join("\n");
},
onBeforeRun(pyodide, element) {
bootstrapNodeAndPlugins(pyodide, element, before, "onBeforeRun");
Expand Down
7 changes: 5 additions & 2 deletions 7 tech-preview/pyscript.core/esm/worker/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import coincident from "coincident/window";
import xworker from "./xworker.js";
import { assign, defineProperties, absoluteURL } from "../utils.js";
import { getText } from "../fetch-utils.js";
import { Hook } from "./hooks.js";

/**
* @typedef {Object} WorkerOptions custom configuration
Expand All @@ -21,7 +22,6 @@ export default (...args) =>
function XWorker(url, options) {
const worker = xworker();
const { postMessage } = worker;
const hooks = this instanceof XWorker ? void 0 : this;
if (args.length) {
const [type, version] = args;
options = assign({}, options || { type, version });
Expand All @@ -30,7 +30,10 @@ export default (...args) =>
if (options?.config) options.config = absoluteURL(options.config);
const bootstrap = fetch(url)
.then(getText)
.then((code) => postMessage.call(worker, { options, code, hooks }));
.then((code) => {
const hooks = this instanceof Hook ? this : void 0;
postMessage.call(worker, { options, code, hooks });
});
return defineProperties(worker, {
postMessage: {
value: (data, ...rest) =>
Expand Down
15 changes: 15 additions & 0 deletions 15 tech-preview/pyscript.core/esm/worker/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const workerHooks = [
["beforeRun", "codeBeforeRunWorker"],
["beforeRunAsync", "codeBeforeRunWorkerAsync"],
["afterRun", "codeAfterRunWorker"],
["afterRunAsync", "codeAfterRunWorkerAsync"],
];

export class Hook {
constructor(fields) {
for (const [key, value] of workerHooks) this[key] = fields[value]?.();
}
}
/* c8 ignore stop */
6 changes: 5 additions & 1 deletion 6 tech-preview/pyscript.core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
<li><a href="./test/wasmoon.html">lua</a></li>
<li><a href="./test/async.html">async</a></li>
<li><a href="./test/worker/">worker</a></li>
<li><a href="./test/worker/input.html">worker w/ input</a></li>
<li><a href="./test/order.html">execution order</a></li>
<li><a href="./test/plugins/">plugins</a></li>
<li>
<a href="./test/plugins/py-script.html">plugins - PyScript</a>
<a href="./test/plugins/py-script.html">
custom tags: PyScript
</a>
</li>
</ul>
</body>
Expand Down
2 changes: 1 addition & 1 deletion 2 tech-preview/pyscript.core/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.