Skip to content

Commit dc81e48

Browse files
committed
2 parents 130729b + 9ca1e99 commit dc81e48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5049
-2446
lines changed

.github/workflows/pages-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
deploy:
10-
runs-on: ubuntu-18.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout 🛎️
1313
uses: actions/checkout@v2

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
test:
99
name: Verify all tests pass and build success
10-
runs-on: ubuntu-18.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- name: Check out source code
1313
uses: actions/checkout@v2

modules.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
{
2+
"painter": {
3+
"tabs": [
4+
"Painter"
5+
]
6+
},
7+
"unity_academy": {
8+
"tabs": [
9+
"UnityAcademy"
10+
]
11+
},
12+
"plotly": {
13+
"tabs": [
14+
"Plotly"
15+
]
16+
},
217
"repeat": {
318
"tabs": [
419
"Repeat"
@@ -67,5 +82,8 @@
6782
"tabs": [
6883
"Repl"
6984
]
85+
},
86+
"remote_execution": {
87+
"tabs": []
7088
}
7189
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@types/jest": "^27.4.1",
4949
"@types/lodash": "^4.14.191",
5050
"@types/node": "^17.0.23",
51+
"@types/plotly.js-dist": "npm:@types/plotly.js",
5152
"@types/react": "^17.0.43",
5253
"@typescript-eslint/eslint-plugin": "^5.47.1",
5354
"@typescript-eslint/parser": "^5.47.1",
@@ -91,10 +92,11 @@
9192
"classnames": "^2.3.1",
9293
"dayjs": "^1.10.4",
9394
"gl-matrix": "^3.3.0",
94-
"js-slang": "^0.5.38",
95+
"js-slang": "^1.0.20",
9596
"lodash": "^4.17.21",
9697
"patch-package": "^6.5.1",
9798
"phaser": "^3.54.0",
99+
"plotly.js-dist": "^2.17.1",
98100
"postinstall-postinstall": "^2.1.0",
99101
"react": "^17.0.2",
100102
"react-ace": "^10.1.0",

scripts/bin/build/dev.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import chalk from 'chalk';
22
import { context as esbuild } from 'esbuild';
33
import { buildHtml, buildJsons, initTypedoc, logHtmlResult } from './docs/index.js';
4-
import { reduceBundleOutputFiles } from './modules/bundle.js';
5-
import { esbuildOptions } from './modules/moduleUtils.js';
6-
import { reduceTabOutputFiles } from './modules/tab.js';
4+
import { bundleOptions, reduceBundleOutputFiles } from './modules/bundle.js';
5+
import { reduceTabOutputFiles, tabOptions } from './modules/tab.js';
76
import { bundleNameExpander, copyManifest, createBuildCommand, createBuildDirs, divideAndRound, logResult, retrieveBundlesAndTabs, tabNameExpander, } from './buildUtils.js';
87
/**
98
* Wait until the user presses 'ctrl+c' on the keyboard
@@ -21,11 +20,10 @@ const waitForQuit = () => new Promise((resolve, reject) => {
2120
process.stdin.on('error', reject);
2221
});
2322
const getBundleContext = ({ srcDir, outDir }, bundles, app) => esbuild({
24-
...esbuildOptions,
23+
...bundleOptions,
2524
outbase: outDir,
2625
outdir: outDir,
2726
entryPoints: bundles.map(bundleNameExpander(srcDir)),
28-
external: ['js-slang/moduleHelpers'],
2927
plugins: [{
3028
name: 'Bundle Compiler',
3129
async setup(pluginBuild) {
@@ -56,11 +54,11 @@ const getBundleContext = ({ srcDir, outDir }, bundles, app) => esbuild({
5654
}],
5755
});
5856
const getTabContext = ({ srcDir, outDir }, tabs) => esbuild({
59-
...esbuildOptions,
57+
...tabOptions,
6058
outbase: outDir,
6159
outdir: outDir,
6260
entryPoints: tabs.map(tabNameExpander(srcDir)),
63-
external: ['react', 'react-dom'],
61+
external: ['react*', 'react-dom'],
6462
plugins: [{
6563
name: 'Tab Compiler',
6664
setup(pluginBuild) {

scripts/bin/build/docs/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const getBuildHtmlCommand = () => new Command('html')
6262
bundles,
6363
tabs: [],
6464
});
65-
logTscResults(tscResult, opts.srcDir);
65+
logTscResults(tscResult);
6666
if (tscResult.result.severity === 'error')
6767
process.exit(1);
6868
}

scripts/bin/build/docs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const getBuildDocsCommand = () => createBuildCommand('docs', true)
1919
bundles,
2020
tabs: [],
2121
});
22-
logTscResults(tscResult, srcDir);
22+
logTscResults(tscResult);
2323
if (tscResult.result.severity === 'error')
2424
process.exit(1);
2525
}

scripts/bin/build/docs/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const getJsonCommand = () => createBuildCommand('jsons', false)
159159
bundles,
160160
tabs: [],
161161
});
162-
logTscResults(tscResult, srcDir);
162+
logTscResults(tscResult);
163163
if (tscResult.result.severity === 'error')
164164
process.exit(1);
165165
}

scripts/bin/build/modules/bundle.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { parse } from 'acorn';
22
import { generate } from 'astring';
3-
import { build as esbuild } from 'esbuild';
3+
import { build as esbuild, } from 'esbuild';
44
import fs from 'fs/promises';
55
import pathlib from 'path';
66
import { bundleNameExpander } from '../buildUtils.js';
7-
import { esbuildOptions, requireCreator } from './moduleUtils.js';
8-
const HELPER_NAME = 'moduleHelpers';
7+
import { esbuildOptions } from './moduleUtils.js';
98
export const outputBundle = async (name, bundleText, outDir) => {
109
try {
1110
const parsed = parse(bundleText, { ecmaVersion: 6 });
@@ -21,25 +20,20 @@ export const outputBundle = async (name, bundleText, outDir) => {
2120
const callExpression = varDeclarator.init;
2221
const moduleCode = callExpression.callee;
2322
const output = {
24-
type: 'FunctionExpression',
23+
type: 'ArrowFunctionExpression',
2524
body: {
2625
type: 'BlockStatement',
27-
body: [
28-
requireCreator({
29-
'js-slang/moduleHelpers': HELPER_NAME,
30-
}),
31-
...(moduleCode.body.type === 'BlockStatement'
32-
? moduleCode.body.body
33-
: [{
34-
type: 'ExpressionStatement',
35-
expression: moduleCode.body,
36-
}]),
37-
],
26+
body: moduleCode.body.type === 'BlockStatement'
27+
? moduleCode.body.body
28+
: [{
29+
type: 'ExpressionStatement',
30+
expression: moduleCode.body,
31+
}],
3832
},
3933
params: [
4034
{
4135
type: 'Identifier',
42-
name: HELPER_NAME,
36+
name: 'require',
4337
},
4438
],
4539
};
@@ -62,13 +56,17 @@ export const outputBundle = async (name, bundleText, outDir) => {
6256
};
6357
}
6458
};
59+
export const bundleOptions = {
60+
...esbuildOptions,
61+
external: ['js-slang*'],
62+
};
6563
export const buildBundles = async (bundles, { srcDir, outDir }) => {
64+
const nameExpander = bundleNameExpander(srcDir);
6665
const { outputFiles } = await esbuild({
67-
...esbuildOptions,
68-
entryPoints: bundles.map(bundleNameExpander(srcDir)),
66+
...bundleOptions,
67+
entryPoints: bundles.map(nameExpander),
6968
outbase: outDir,
7069
outdir: outDir,
71-
external: ['js-slang/moduleHelpers'],
7270
});
7371
return outputFiles;
7472
};

scripts/bin/build/modules/tab.js

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,32 @@
11
import { parse } from 'acorn';
22
import { generate } from 'astring';
33
import chalk from 'chalk';
4-
import { build as esbuild } from 'esbuild';
4+
import { build as esbuild, } from 'esbuild';
55
import fs from 'fs/promises';
6-
import uniq from 'lodash/uniq.js';
76
import pathlib from 'path';
87
import { printList } from '../../scriptUtils.js';
98
import { copyManifest, createBuildCommand, exitOnError, logResult, retrieveTabs, tabNameExpander, } from '../buildUtils.js';
109
import { prebuild } from '../prebuild/index.js';
11-
import { esbuildOptions, requireCreator } from './moduleUtils.js';
12-
/**
13-
* Imports that are provided at runtime
14-
*/
15-
const externals = {
16-
'react': '_react',
17-
'react-dom': 'ReactDOM',
18-
};
10+
import { esbuildOptions } from './moduleUtils.js';
1911
const outputTab = async (tabName, text, outDir) => {
2012
try {
2113
const parsed = parse(text, { ecmaVersion: 6 });
2214
const declStatement = parsed.body[1];
2315
const newTab = {
24-
type: 'ExpressionStatement',
25-
expression: {
26-
type: 'FunctionExpression',
27-
params: uniq(Object.values(externals))
28-
.map((name) => ({
29-
type: 'Identifier',
30-
name,
31-
})),
32-
body: {
33-
type: 'BlockStatement',
34-
body: [
35-
requireCreator(externals),
36-
{
37-
type: 'ReturnStatement',
38-
argument: {
39-
type: 'MemberExpression',
40-
object: declStatement.declarations[0].init,
41-
property: {
42-
type: 'Literal',
43-
value: 'default',
44-
},
45-
computed: true,
46-
},
47-
},
48-
],
16+
type: 'ArrowFunctionExpression',
17+
body: {
18+
type: 'MemberExpression',
19+
object: declStatement.declarations[0].init,
20+
property: {
21+
type: 'Literal',
22+
value: 'default',
4923
},
24+
computed: true,
5025
},
26+
params: [{
27+
type: 'Identifier',
28+
name: 'require',
29+
}],
5130
};
5231
let newCode = generate(newTab);
5332
if (newCode.endsWith(';'))
@@ -67,14 +46,18 @@ const outputTab = async (tabName, text, outDir) => {
6746
};
6847
}
6948
};
49+
export const tabOptions = {
50+
...esbuildOptions,
51+
jsx: 'automatic',
52+
external: ['react', 'react-dom', 'react/jsx-runtime'],
53+
};
7054
export const buildTabs = async (tabs, { srcDir, outDir }) => {
55+
const nameExpander = tabNameExpander(srcDir);
7156
const { outputFiles } = await esbuild({
72-
...esbuildOptions,
73-
entryPoints: tabs.map(tabNameExpander(srcDir)),
57+
...tabOptions,
58+
entryPoints: tabs.map(nameExpander),
7459
outbase: outDir,
7560
outdir: outDir,
76-
external: Object.keys(externals),
77-
jsx: 'transform',
7861
});
7962
return outputFiles;
8063
};

scripts/bin/build/prebuild/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const prebuildInternal = async (opts, assets) => {
4343
export const prebuild = async (opts, assets) => {
4444
const { lintResult, tscResult } = await prebuildInternal(opts, assets);
4545
logLintResult(lintResult);
46-
logTscResults(tscResult, opts.srcDir);
46+
logTscResults(tscResult);
4747
exitOnError([], lintResult?.result, tscResult?.result);
4848
if (lintResult?.result.severity === 'error' || tscResult?.result.severity === 'error') {
4949
throw new Error('Exiting for jest');

scripts/bin/build/prebuild/tsc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const runTsc = wrapWithTimer((async (srcDir, { bundles, tabs }) => {
6666
results: diagnostics,
6767
};
6868
}));
69-
export const logTscResults = (input, srcDir) => {
69+
export const logTscResults = (input) => {
7070
if (!input)
7171
return;
7272
const { elapsed, result: { severity, results, error } } = input;
@@ -76,7 +76,7 @@ export const logTscResults = (input, srcDir) => {
7676
}
7777
const diagStr = ts.formatDiagnosticsWithColorAndContext(results, {
7878
getNewLine: () => '\n',
79-
getCurrentDirectory: () => srcDir,
79+
getCurrentDirectory: () => pathlib.resolve('.'),
8080
getCanonicalFileName: (name) => pathlib.basename(name),
8181
});
8282
if (severity === 'error') {
@@ -96,7 +96,7 @@ const getTscCommand = () => new Command('typecheck')
9696
.action(async ({ modules, tabs, manifest, srcDir }) => {
9797
const assets = await retrieveBundlesAndTabs(manifest, modules, tabs);
9898
const tscResults = await runTsc(srcDir, assets);
99-
logTscResults(tscResults, srcDir);
99+
logTscResults(tscResults);
100100
exitOnError([], tscResults.result);
101101
});
102102
export default getTscCommand;

scripts/src/build/dev.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { context as esbuild } from 'esbuild';
33
import type { Application } from 'typedoc';
44

55
import { buildHtml, buildJsons, initTypedoc, logHtmlResult } from './docs/index.js';
6-
import { reduceBundleOutputFiles } from './modules/bundle.js';
7-
import { esbuildOptions } from './modules/moduleUtils.js';
8-
import { reduceTabOutputFiles } from './modules/tab.js';
6+
import { bundleOptions, reduceBundleOutputFiles } from './modules/bundle.js';
7+
import { reduceTabOutputFiles, tabOptions } from './modules/tab.js';
98
import {
109
bundleNameExpander,
1110
copyManifest,
@@ -36,11 +35,10 @@ const waitForQuit = () => new Promise<void>((resolve, reject) => {
3635

3736
type ContextOptions = Record<'srcDir' | 'outDir', string>;
3837
const getBundleContext = ({ srcDir, outDir }: ContextOptions, bundles: string[], app?: Application) => esbuild({
39-
...esbuildOptions,
38+
...bundleOptions,
4039
outbase: outDir,
4140
outdir: outDir,
4241
entryPoints: bundles.map(bundleNameExpander(srcDir)),
43-
external: ['js-slang/moduleHelpers'],
4442
plugins: [{
4543
name: 'Bundle Compiler',
4644
async setup(pluginBuild) {
@@ -75,11 +73,11 @@ const getBundleContext = ({ srcDir, outDir }: ContextOptions, bundles: string[],
7573
});
7674

7775
const getTabContext = ({ srcDir, outDir }: ContextOptions, tabs: string[]) => esbuild({
78-
...esbuildOptions,
76+
...tabOptions,
7977
outbase: outDir,
8078
outdir: outDir,
8179
entryPoints: tabs.map(tabNameExpander(srcDir)),
82-
external: ['react', 'react-dom'],
80+
external: ['react*', 'react-dom'],
8381
plugins: [{
8482
name: 'Tab Compiler',
8583
setup(pluginBuild) {

scripts/src/build/docs/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const getBuildHtmlCommand = () => new Command('html')
7979
bundles,
8080
tabs: [],
8181
});
82-
logTscResults(tscResult, opts.srcDir);
82+
logTscResults(tscResult);
8383
if (tscResult.result.severity === 'error') process.exit(1);
8484
}
8585

scripts/src/build/docs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getBuildDocsCommand = () => createBuildCommand('docs', true)
2424
bundles,
2525
tabs: [],
2626
});
27-
logTscResults(tscResult, srcDir);
27+
logTscResults(tscResult);
2828
if (tscResult.result.severity === 'error') process.exit(1);
2929
}
3030

scripts/src/build/docs/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const getJsonCommand = () => createBuildCommand('jsons', false)
212212
bundles,
213213
tabs: [],
214214
});
215-
logTscResults(tscResult, srcDir);
215+
logTscResults(tscResult);
216216
if (tscResult.result.severity === 'error') process.exit(1);
217217
}
218218

0 commit comments

Comments
 (0)