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

Commit dd95bff

Browse filesBrowse files
author
Ted Patrick
authored
Tech preview sync (#47)
1 parent 853b251 commit dd95bff
Copy full SHA for dd95bff

28 files changed

+3899
-55
lines changed
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2022": true
5+
},
6+
"extends": "eslint:recommended",
7+
"parserOptions": {
8+
"ecmaVersion": 12,
9+
"sourceType": "module"
10+
},
11+
"rules": {}
12+
}
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 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
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: build
5+
6+
on: [push, pull_request]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [20]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
cache: "npm"
23+
- run: npm ci
24+
- run: npm run build --if-present
25+
- run: npm test
26+
- run: npm run coverage --if-present
27+
- name: Coveralls
28+
uses: coverallsapp/github-action@master
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}

‎tech-preview/pyscript.core/.gitignore

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
coverage/
3+
node_modules/
4+
cjs/
5+
!cjs/package.json
6+
core.js
7+
esm/worker/xworker.js
8+
types/

‎tech-preview/pyscript.core/.npmignore

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.DS_Store
2+
.nyc_output
3+
.eslintrc.json
4+
.github/
5+
.travis.yml
6+
.eslintrc.json
7+
*.log
8+
coverage/
9+
micropython/
10+
node_modules/
11+
pyscript/
12+
rollup/
13+
test/
14+
index.html
15+
node.importmap
16+
sw.js
17+
tsconfig.json
18+
cjs/worker/_template.js
19+
esm/worker/_template.js

‎tech-preview/pyscript.core/.npmrc

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=true

‎tech-preview/pyscript.core/README.md

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This project requires some automatic artifact creation to:
1919

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

2525
Accordingly, to build latest project:

‎tech-preview/pyscript.core/cjs/custom.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/cjs/custom.js
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
const { getRuntimeID } = require("./loader.js");
1313
const { io } = require("./interpreter/_utils.js");
1414
const { addAllListeners } = require("./listeners.js");
15+
const { Hook } = require("./worker/hooks.js");
1516

1617
const CUSTOM_SELECTORS = [];
1718
exports.CUSTOM_SELECTORS = CUSTOM_SELECTORS;
@@ -66,18 +67,9 @@ const handleCustomType = (node) => {
6667
onBeforeRunAsync,
6768
onAfterRun,
6869
onAfterRunAsync,
69-
codeBeforeRunWorker,
70-
codeBeforeRunWorkerAsync,
71-
codeAfterRunWorker,
72-
codeAfterRunWorkerAsync,
7370
} = options;
7471

75-
const hooks = {
76-
beforeRun: codeBeforeRunWorker?.(),
77-
beforeRunAsync: codeBeforeRunWorkerAsync?.(),
78-
afterRun: codeAfterRunWorker?.(),
79-
afterRunAsync: codeAfterRunWorkerAsync?.(),
80-
};
72+
const hooks = new Hook(options);
8173

8274
const XWorker = function XWorker(...args) {
8375
return Worker.apply(hooks, args);

‎tech-preview/pyscript.core/cjs/custom/pyscript.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/cjs/custom/pyscript.js
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ document.head.appendChild(document.createElement("style")).textContent = `
9191
env: "py-script",
9292
interpreter: "pyodide",
9393
codeBeforeRunWorker() {
94-
const { codeBeforeRunWorker: set } = hooks;
95-
const prefix = 'print("codeBeforeRunWorker")';
96-
return [prefix].concat(...set).join("\n");
94+
return [...hooks.codeBeforeRunWorker].join("\n");
9795
},
9896
codeAfterRunWorker() {
99-
const { codeAfterRunWorker: set } = hooks;
100-
const prefix = 'print("codeAfterRunWorker")';
101-
return [prefix].concat(...set).join("\n");
97+
return [...hooks.codeAfterRunWorker].join("\n");
10298
},
10399
onBeforeRun(pyodide, element) {
104100
bootstrapNodeAndPlugins(pyodide, element, before, "onBeforeRun");

‎tech-preview/pyscript.core/cjs/worker/class.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/cjs/worker/class.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const coincident = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c
44
const xworker = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require("./xworker.js"));
55
const { assign, defineProperties, absoluteURL } = require("../utils.js");
66
const { getText } = require("../fetch-utils.js");
7+
const { Hook } = require("./hooks.js");
78

89
/**
910
* @typedef {Object} WorkerOptions custom configuration
@@ -22,7 +23,6 @@ module.exports = (...args) =>
2223
function XWorker(url, options) {
2324
const worker = xworker();
2425
const { postMessage } = worker;
25-
const hooks = this instanceof XWorker ? void 0 : this;
2626
if (args.length) {
2727
const [type, version] = args;
2828
options = assign({}, options || { type, version });
@@ -31,7 +31,10 @@ module.exports = (...args) =>
3131
if (options?.config) options.config = absoluteURL(options.config);
3232
const bootstrap = fetch(url)
3333
.then(getText)
34-
.then((code) => postMessage.call(worker, { options, code, hooks }));
34+
.then((code) => {
35+
const hooks = this instanceof Hook ? this : void 0;
36+
postMessage.call(worker, { options, code, hooks });
37+
});
3538
return defineProperties(worker, {
3639
postMessage: {
3740
value: (data, ...rest) =>
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
'use strict';
2-
module.exports = new WeakMap();
2+
// REQUIRES INTEGRATION TEST
3+
/* c8 ignore start */
4+
const workerHooks = [
5+
["beforeRun", "codeBeforeRunWorker"],
6+
["beforeRunAsync", "codeBeforeRunWorkerAsync"],
7+
["afterRun", "codeAfterRunWorker"],
8+
["afterRunAsync", "codeAfterRunWorkerAsync"],
9+
];
10+
11+
class Hook {
12+
constructor(fields) {
13+
for (const [key, value] of workerHooks) this[key] = fields[value]?.();
14+
}
15+
}
16+
exports.Hook = Hook
17+
/* c8 ignore stop */

‎tech-preview/pyscript.core/core.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/core.js
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tech-preview/pyscript.core/esm/custom.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/esm/custom.js
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { getRuntimeID } from "./loader.js";
1212
import { io } from "./interpreter/_utils.js";
1313
import { addAllListeners } from "./listeners.js";
14+
import { Hook } from "./worker/hooks.js";
1415

1516
export const CUSTOM_SELECTORS = [];
1617

@@ -64,18 +65,9 @@ export const handleCustomType = (node) => {
6465
onBeforeRunAsync,
6566
onAfterRun,
6667
onAfterRunAsync,
67-
codeBeforeRunWorker,
68-
codeBeforeRunWorkerAsync,
69-
codeAfterRunWorker,
70-
codeAfterRunWorkerAsync,
7168
} = options;
7269

73-
const hooks = {
74-
beforeRun: codeBeforeRunWorker?.(),
75-
beforeRunAsync: codeBeforeRunWorkerAsync?.(),
76-
afterRun: codeAfterRunWorker?.(),
77-
afterRunAsync: codeAfterRunWorkerAsync?.(),
78-
};
70+
const hooks = new Hook(options);
7971

8072
const XWorker = function XWorker(...args) {
8173
return Worker.apply(hooks, args);

‎tech-preview/pyscript.core/esm/custom/pyscript.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/esm/custom/pyscript.js
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,10 @@ document.head.appendChild(document.createElement("style")).textContent = `
9090
env: "py-script",
9191
interpreter: "pyodide",
9292
codeBeforeRunWorker() {
93-
const { codeBeforeRunWorker: set } = hooks;
94-
const prefix = 'print("codeBeforeRunWorker")';
95-
return [prefix].concat(...set).join("\n");
93+
return [...hooks.codeBeforeRunWorker].join("\n");
9694
},
9795
codeAfterRunWorker() {
98-
const { codeAfterRunWorker: set } = hooks;
99-
const prefix = 'print("codeAfterRunWorker")';
100-
return [prefix].concat(...set).join("\n");
96+
return [...hooks.codeAfterRunWorker].join("\n");
10197
},
10298
onBeforeRun(pyodide, element) {
10399
bootstrapNodeAndPlugins(pyodide, element, before, "onBeforeRun");

‎tech-preview/pyscript.core/esm/worker/class.js

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/esm/worker/class.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import coincident from "coincident/window";
33
import xworker from "./xworker.js";
44
import { assign, defineProperties, absoluteURL } from "../utils.js";
55
import { getText } from "../fetch-utils.js";
6+
import { Hook } from "./hooks.js";
67

78
/**
89
* @typedef {Object} WorkerOptions custom configuration
@@ -21,7 +22,6 @@ export default (...args) =>
2122
function XWorker(url, options) {
2223
const worker = xworker();
2324
const { postMessage } = worker;
24-
const hooks = this instanceof XWorker ? void 0 : this;
2525
if (args.length) {
2626
const [type, version] = args;
2727
options = assign({}, options || { type, version });
@@ -30,7 +30,10 @@ export default (...args) =>
3030
if (options?.config) options.config = absoluteURL(options.config);
3131
const bootstrap = fetch(url)
3232
.then(getText)
33-
.then((code) => postMessage.call(worker, { options, code, hooks }));
33+
.then((code) => {
34+
const hooks = this instanceof Hook ? this : void 0;
35+
postMessage.call(worker, { options, code, hooks });
36+
});
3437
return defineProperties(worker, {
3538
postMessage: {
3639
value: (data, ...rest) =>
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// REQUIRES INTEGRATION TEST
2+
/* c8 ignore start */
3+
const workerHooks = [
4+
["beforeRun", "codeBeforeRunWorker"],
5+
["beforeRunAsync", "codeBeforeRunWorkerAsync"],
6+
["afterRun", "codeAfterRunWorker"],
7+
["afterRunAsync", "codeAfterRunWorkerAsync"],
8+
];
9+
10+
export class Hook {
11+
constructor(fields) {
12+
for (const [key, value] of workerHooks) this[key] = fields[value]?.();
13+
}
14+
}
15+
/* c8 ignore stop */

‎tech-preview/pyscript.core/index.html

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/index.html
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828
<li><a href="./test/wasmoon.html">lua</a></li>
2929
<li><a href="./test/async.html">async</a></li>
3030
<li><a href="./test/worker/">worker</a></li>
31+
<li><a href="./test/worker/input.html">worker w/ input</a></li>
32+
<li><a href="./test/order.html">execution order</a></li>
3133
<li><a href="./test/plugins/">plugins</a></li>
3234
<li>
33-
<a href="./test/plugins/py-script.html">plugins - PyScript</a>
35+
<a href="./test/plugins/py-script.html">
36+
custom tags: PyScript
37+
</a>
3438
</li>
3539
</ul>
3640
</body>

‎tech-preview/pyscript.core/node_modules/.package-lock.json

Copy file name to clipboardExpand all lines: tech-preview/pyscript.core/node_modules/.package-lock.json
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.