Skip to content

Commit

Permalink
Merge pull request #92 from cameronmoreau/poc/package-breakup
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethcassel authored Oct 7, 2021
2 parents 82b2a06 + 3734578 commit e9b5cf2
Show file tree
Hide file tree
Showing 32 changed files with 14,395 additions and 1,588 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/*
packages/**/lib/*
example-nextjs
4 changes: 2 additions & 2 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: Install Modules
run: yarn

- name: Run the Build
run: yarn build
- name: Bootstrap and run the Build
run: yarn bootstrap --no-ci

# Runs the tests
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
/example-nextjs/.next

/lib
/packages/**/lib

.eslintcache
yarn-*.log*
4 changes: 3 additions & 1 deletion example-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"next-themes": "^0.0.15",
"react": "17.0.2",
"react-dom": "17.0.2",
"run-wasm": "link:.."
"@run-wasm/run-wasm": "link:../packages/run-wasm",
"@run-wasm/ts": "link:../packages/run-wasm-ts",
"@run-wasm/python": "link:../packages/run-wasm-python"
},
"devDependencies": {
"@types/react": "17.0.21",
Expand Down
2 changes: 1 addition & 1 deletion example-nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { createPythonClient, RunWasm } from 'run-wasm'
import { createPythonClient } from '@run-wasm/python'
import Editor from '@monaco-editor/react'
import Script from 'next/script'
import GithubButton from '../components/GithubButton'
Expand Down
2 changes: 1 addition & 1 deletion example-nextjs/pages/matplotlib.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { createPythonClient, RunWasm } from 'run-wasm'
import { createPythonClient } from '@run-wasm/python'
import Editor from '@monaco-editor/react'
import Script from 'next/script'
import Navbar from '../components/Navbar'
Expand Down
2 changes: 1 addition & 1 deletion example-nextjs/pages/ts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { createTSClient } from 'run-wasm'
import { createTSClient } from '@run-wasm/ts'
import Editor from '@monaco-editor/react'
import Script from 'next/script'
import Navbar from '../components/Navbar'
Expand Down
16 changes: 12 additions & 4 deletions example-nextjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@run-wasm/python@link:../packages/run-wasm-python":
version "0.0.0"
uid ""

"@run-wasm/run-wasm@link:../packages/run-wasm":
version "0.0.0"
uid ""

"@run-wasm/ts@link:../packages/run-wasm-ts":
version "0.0.0"
uid ""

"@rushstack/eslint-patch@^1.0.6":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.0.6.tgz#023d72a5c4531b4ce204528971700a78a85a0c50"
Expand Down Expand Up @@ -3092,10 +3104,6 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

"run-wasm@link:..":
version "0.0.0"
uid ""

safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
Expand Down
4 changes: 4 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packages": ["packages/*"],
"version": "0.0.0"
}
33 changes: 10 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,47 @@
"name": "run-wasm",
"version": "0.0.1",
"description": "Run WASM based code executions in the browser easily",
"private": true,
"keywords": [
"wasm",
"editor",
"react",
"code execution"
],
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts",
"repository": "https://github.com/slipHQ/wasm-run.git",
"author": "Kenneth Cassel <kennethcassel@gmail.com>",
"license": "Apache-2.0",
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
},
"devDependencies": {
"@commitlint/cli": "12.1.1",
"@commitlint/config-conventional": "12.1.1",
"@types/jest": "^27.0.2",
"@types/react": "^17.0.21",
"@types/react-dom": "^17.0.9",
"all-contributors-cli": "^6.20.0",
"babel-eslint": "^10.1.0",
"eslint": "7.25.0",
"eslint-config-galex": "2.15.2",
"eslint-config-next": "^11.0.0",
"husky": "^7.0.0",
"jest": "^27.2.2",
"lerna": "^4.0.0",
"lint-staged": ">=10",
"prettier": "2.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
},
"scripts": {
"build": "yarn build:esm && yarn build:cjs",
"check-types": "tsc",
"bootstrap": "lerna bootstrap",
"build": "lerna run build",
"build:esm": "lerna run build:esm",
"build:cjs": "lerna run build:cjs",
"test": "lerna run test",
"check-types": "lerna run check-types",
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn",
"format": "prettier --write --list-different --ignore-path .gitignore .",
"lint": "eslint --cache . --ignore-path .gitignore --ignore-pattern 'lib/*'",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn",
"prepare": "husky install",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"test": "jest"
"contributors:generate": "all-contributors generate"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "yarn lint",
"*.{js,jsx,ts,tsx,css,json,md}": "yarn format"
},
"dependencies": {
"pyodide": "^0.18.0"
}
}
55 changes: 55 additions & 0 deletions packages/run-wasm-python/package-lock.json

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

20 changes: 20 additions & 0 deletions packages/run-wasm-python/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@run-wasm/python",
"version": "1.0.0",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts",
"devDependencies": {
"typescript": "^4.4.3"
},
"scripts": {
"prepare": "npm run build",
"check-types": "tsc",
"build": "yarn build:esm && yarn build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs"
},
"dependencies": {
"pyodide": "^0.18.0"
}
}
39 changes: 39 additions & 0 deletions packages/run-wasm-python/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

export class PythonClient {
// <- [reference](https://stackoverflow.com/a/59571016/1375972)
// We redirect stdout to an IO string buffer so that it can be read later
private readonly setStdoutToOutput = `
import sys
import io
sys.stdout = io.StringIO()
`

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public constructor(protected pyodide: any) {
pyodide.runPython(this.setStdoutToOutput)
}

public async run({ code }: { code: string }): Promise<string> {
await this.loadPackages(code)
const output: string = this.pyodide.runPython(code) ?? ''
// Prepend the value of stdout before returning
const stdout: string = this.pyodide.runPython('sys.stdout.getvalue()')
console.log(stdout + output)
return stdout + output
}

private loadPackages(code: string): Promise<any> {
if (typeof this.pyodide.loadPackagesFromImports === 'function') {
console.log('Loading Python dependencies from code')
return this.pyodide.loadPackagesFromImports(code)
}
return this.pyodide.loadPackage([])
}
}

const createPythonClient = (pyodide: string): PythonClient => {
return new PythonClient(pyodide)
}

export { createPythonClient }
7 changes: 7 additions & 0 deletions packages/run-wasm-python/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": ["./src"]
}
46 changes: 46 additions & 0 deletions packages/run-wasm-python/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


base-64@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/base-64/-/base-64-1.0.0.tgz#09d0f2084e32a3fd08c2475b973788eee6ae8f4a"
integrity sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg==

node-fetch@^2.6.1:
version "2.6.5"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd"
integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==
dependencies:
whatwg-url "^5.0.0"

pyodide@^0.18.0:
version "0.18.1"
resolved "https://registry.yarnpkg.com/pyodide/-/pyodide-0.18.1.tgz#9b987de7dc30de261aeabea64052bb7ab3f1fef7"
integrity sha512-QgkdYXu0nkWoJ5Ein2GAgpsT6gfuRCdmiR5C3JSTUEyHnMY0MqU0hx7hpD0/ZVXNSalG7ytVQ+9SgCL2RtVcqg==
dependencies:
base-64 "^1.0.0"
node-fetch "^2.6.1"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

typescript@^4.4.3:
version "4.4.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324"
integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createTSClient } from '../src'
import { TSClient } from '../src/RunWasmClient'
import { createTSClient, TSClient } from '../src'

describe('createTSClient', () => {
it('should return an instance of TSClient', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/run-wasm-ts/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const base = require('../../jest.config')

module.exports = base
Loading

1 comment on commit e9b5cf2

@vercel
Copy link

@vercel vercel bot commented on e9b5cf2 Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.