Skip to content

Commit 3c928e7

Browse files
committed
trying to build workers with typescript but failing
1 parent 6473727 commit 3c928e7

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

pyscriptjs/rollup.config.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ if( !production ){
2121
copy_targets.targets.push({ src: 'build/*', dest: 'examples/build' })
2222
}
2323

24-
export default {
24+
25+
const pyscript_main = {
2526
input: "src/main.ts",
2627
output:[
2728
{
@@ -67,3 +68,17 @@ export default {
6768
clearScreen: false,
6869
},
6970
};
71+
72+
const worker = {
73+
input: "src/workers/worker_interpreter.ts",
74+
output: {
75+
file: "build/workers/worker_interpreter.js",
76+
format: "iife",
77+
sourcemap: true,
78+
inlineDynamicImports: true,
79+
name: "worker_interpreter",
80+
}
81+
};
82+
83+
84+
export default [pyscript_main, worker];

pyscriptjs/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ export class PyScriptApp {
153153

154154
const interpreter_cfg = this.config.interpreters[0];
155155

156+
const worker = new Worker("build/workers/worker_interpreter.js");
157+
156158
const remote_interpreter = new RemoteInterpreter(interpreter_cfg.src);
157159
const { port1, port2 } = new MessageChannel();
158160
port1.start();

pyscriptjs/src/workers/foo.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function foo(a: number, b: number): number {
2+
return a+b;
3+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"_version": "3.0.0",
4+
5+
"include": ["src/**/*"],
6+
"exclude": ["node_modules/*", "__sapper__/*", "public/*"],
7+
8+
"compilerOptions": {
9+
"moduleResolution": "node",
10+
"target": "ES2020",
11+
"module": "ES2020",
12+
"types": ["jest", "node"],
13+
"strict": false,
14+
"esModuleInterop": true,
15+
"skipLibCheck": true,
16+
"forceConsistentCasingInFileNames": true,
17+
"lib": [
18+
"es2017",
19+
"dom",
20+
"DOM.Iterable"
21+
]
22+
}
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// [!] Error: Could not resolve './foo' from src/workers/worker_interpreter.ts
2+
import { add } from './foo';
3+
4+
// this is what I would like to import
5+
//import { RemoteInterpreter } from '../remote_interpreter';
6+
7+
8+
console.log("hello from worker", add(30, 12));

pyscriptjs/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"_version": "3.0.0",
44

55
"include": ["src/**/*"],
6-
"exclude": ["node_modules/*", "__sapper__/*", "public/*"],
6+
"exclude": ["node_modules/*", "__sapper__/*", "public/*", "worker/*"],
7+
78
"compilerOptions": {
89
"moduleResolution": "node",
910
"target": "ES2020",

0 commit comments

Comments
 (0)