Skip to content

Commit f2ccd5e

Browse files
authored
Update Repository to Node 20 (#271)
* Update bundles to use default export syntax * Update packages for node 20 * Update workflow * Fix formatting * Remove unnecessary type * Update CI to work with gl * Update test to work with export default syntax
1 parent b3c0db8 commit f2ccd5e

File tree

5 files changed

+198
-179
lines changed

5 files changed

+198
-179
lines changed

.github/workflows/pull-request.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Check out source code
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v4
14+
15+
- name: Check for package-lock.json
16+
run: |
17+
if [ -e package-lock.json ]; then
18+
echo "package-lock.json found; please do not use NPM! This project uses Yarn!"
19+
exit 1
20+
fi
21+
exit 0
22+
23+
- name: Install dependencies (apt)
24+
run: |
25+
sudo apt-get install -y --no-install-recommends libxi-dev libgl1-mesa-dev
1426
15-
- name: Use Node.js 💻
16-
uses: actions/setup-node@v1
27+
- name: Setup Node
28+
uses: actions/setup-node@v4
1729
with:
18-
node-version: '16.x'
30+
node-version: 20
31+
cache: yarn
1932

2033
- name: Install dependencies
2134
run: yarn install --frozen-lockfile

package.json

Lines changed: 137 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,137 @@
1-
{
2-
"private": true,
3-
"name": "modules",
4-
"version": "1.0.0",
5-
"repository": "https://github.com/source-academy/modules.git",
6-
"license": "Apache-2.0",
7-
"scripts-info": {
8-
"//NOTE": "Run `npm i npm-scripts-info -g` to install once globally, then run `npm-scripts-info` as needed to list these descriptions",
9-
"create": "Interactively initialise a new bundle or tab from their templates",
10-
"devserver": "Start the tab development server",
11-
"devserver:lint": "Lint code related to the dev server",
12-
"devserver:tsc": "Run tsc over dev server code",
13-
"docs": "Build only documentation",
14-
"lint": "Lint bundle and tab code",
15-
"build": "Lint code, then build modules and documentation",
16-
"build:help": "Show help for the build scripts",
17-
"serve": "Start the HTTP server to serve all files in `build/`, with the same directory structure",
18-
"scripts": "Run a script within the scripts directory",
19-
"scripts:build": "Compile build scripts",
20-
"scripts:lint": "Lint build script code",
21-
"prepare": "Enable git hooks",
22-
"test": "Run unit tests",
23-
"test:watch": "Watch files for changes and rerun tests related to changed files",
24-
"dev": "Build bundles and tabs only, then serve. Skips linting / type checking, does not build jsons and HTML docs. For rapid testing during development",
25-
"watch": "Watch files for changes and rebuild on those changes",
26-
"postinstall": "Install all patches to node_modules packages"
27-
},
28-
"type": "module",
29-
"scripts": {
30-
"build": "yarn scripts build",
31-
"build:help": "yarn scripts build --help",
32-
"create": "yarn scripts create",
33-
"dev": "yarn scripts build modules && yarn serve",
34-
"docs": "yarn scripts build docs",
35-
"lint": "yarn scripts lint",
36-
"prepare": "husky install",
37-
"postinstall": "patch-package && yarn scripts:build",
38-
"scripts": "node --max-old-space-size=4096 scripts/bin.js",
39-
"serve": "http-server --cors=* -c-1 -p 8022 ./build",
40-
"test": "yarn scripts test",
41-
"test:all": "yarn test && yarn scripts:test",
42-
"test:watch": "yarn scripts test --watch",
43-
"watch": "yarn scripts watch",
44-
"devserver": "vite",
45-
"devserver:lint": "yarn scripts devserver lint",
46-
"devserver:tsc": "tsc --project devserver/tsconfig.json",
47-
"scripts:all": "node scripts/scripts_manager.js",
48-
"scripts:build": "node scripts/scripts_manager.js build",
49-
"scripts:lint": "node scripts/scripts_manager.js lint",
50-
"scripts:tsc": "tsc --project scripts/src/tsconfig.json",
51-
"scripts:test": "node scripts/scripts_manager.js test"
52-
},
53-
"devDependencies": {
54-
"@types/dom-mediacapture-record": "^1.0.11",
55-
"@types/eslint": "^8.4.10",
56-
"@types/estree": "^1.0.0",
57-
"@types/jest": "^27.4.1",
58-
"@types/lodash": "^4.14.198",
59-
"@types/node": "^20.8.9",
60-
"@types/plotly.js-dist": "npm:@types/plotly.js",
61-
"@types/react": "^18.2.0",
62-
"@types/react-dom": "^18.2.0",
63-
"@typescript-eslint/eslint-plugin": "^6.6.0",
64-
"@typescript-eslint/parser": "^6.6.0",
65-
"@vitejs/plugin-react": "^4.0.4",
66-
"acorn": "^8.8.1",
67-
"acorn-jsx": "^5.3.2",
68-
"astring": "^1.8.4",
69-
"chalk": "^5.0.1",
70-
"commander": "^9.4.0",
71-
"console-table-printer": "^2.11.1",
72-
"cross-env": "^7.0.3",
73-
"esbuild": "^0.18.20",
74-
"eslint": "^8.21.0",
75-
"eslint-config-airbnb": "^19.0.4",
76-
"eslint-config-airbnb-typescript": "^17.0.0",
77-
"eslint-import-resolver-typescript": "^2.7.1",
78-
"eslint-plugin-import": "^2.26.0",
79-
"eslint-plugin-jest": "^26.8.1",
80-
"eslint-plugin-jsx-a11y": "^6.5.1",
81-
"eslint-plugin-react": "^7.29.4",
82-
"eslint-plugin-react-hooks": "^4.4.0",
83-
"eslint-plugin-simple-import-sort": "^8.0.0",
84-
"http-server": "^0.12.3",
85-
"husky": "5",
86-
"jest": "^29.4.1",
87-
"jest-environment-jsdom": "^29.4.1",
88-
"re-resizable": "^6.9.11",
89-
"react-hotkeys": "^2.0.0",
90-
"react-responsive": "^9.0.2",
91-
"sass": "^1.66.1",
92-
"ts-jest": "^29.1.1",
93-
"typedoc": "^0.25.1",
94-
"typescript": "5.0",
95-
"vite": "^4.5.2",
96-
"yarnhook": "^0.5.1"
97-
},
98-
"dependencies": {
99-
"@blueprintjs/core": "^4.20.2",
100-
"@blueprintjs/icons": "^4.4.0",
101-
"@blueprintjs/popover2": "^1.4.3",
102-
"@box2d/core": "^0.10.0",
103-
"@box2d/debug-draw": "^0.10.0",
104-
"@jscad/modeling": "2.9.6",
105-
"@jscad/regl-renderer": "^2.6.1",
106-
"@jscad/stl-serializer": "^2.1.13",
107-
"ace-builds": "^1.25.1",
108-
"classnames": "^2.3.1",
109-
"dayjs": "^1.10.4",
110-
"gl-matrix": "^3.3.0",
111-
"js-slang": "^1.0.20",
112-
"lodash": "^4.17.21",
113-
"patch-package": "^6.5.1",
114-
"phaser": "^3.54.0",
115-
"plotly.js-dist": "^2.17.1",
116-
"postinstall-postinstall": "^2.1.0",
117-
"react": "^18.2.0",
118-
"react-ace": "^10.1.0",
119-
"react-dom": "^18.2.0",
120-
"regl": "^2.1.0",
121-
"save-file": "^2.3.1",
122-
"source-academy-utils": "^1.0.0",
123-
"source-academy-wabt": "^1.0.4",
124-
"tslib": "^2.3.1"
125-
},
126-
"jest": {
127-
"projects": [
128-
"src/jest.config.js",
129-
"scripts/src/jest.config.js"
130-
]
131-
},
132-
"resolutions": {
133-
"@types/react": "^18.2.0",
134-
"esbuild": "^0.18.20"
135-
}
136-
}
1+
{
2+
"private": true,
3+
"name": "modules",
4+
"version": "1.0.0",
5+
"repository": "https://github.com/source-academy/modules.git",
6+
"license": "Apache-2.0",
7+
"scripts-info": {
8+
"//NOTE": "Run `npm i npm-scripts-info -g` to install once globally, then run `npm-scripts-info` as needed to list these descriptions",
9+
"create": "Interactively initialise a new bundle or tab from their templates",
10+
"devserver": "Start the tab development server",
11+
"devserver:lint": "Lint code related to the dev server",
12+
"devserver:tsc": "Run tsc over dev server code",
13+
"docs": "Build only documentation",
14+
"lint": "Lint bundle and tab code",
15+
"build": "Lint code, then build modules and documentation",
16+
"build:help": "Show help for the build scripts",
17+
"serve": "Start the HTTP server to serve all files in `build/`, with the same directory structure",
18+
"scripts": "Run a script within the scripts directory",
19+
"scripts:build": "Compile build scripts",
20+
"scripts:lint": "Lint build script code",
21+
"prepare": "Enable git hooks",
22+
"test": "Run unit tests",
23+
"test:watch": "Watch files for changes and rerun tests related to changed files",
24+
"dev": "Build bundles and tabs only, then serve. Skips linting / type checking, does not build jsons and HTML docs. For rapid testing during development",
25+
"watch": "Watch files for changes and rebuild on those changes",
26+
"postinstall": "Install all patches to node_modules packages"
27+
},
28+
"type": "module",
29+
"scripts": {
30+
"build": "yarn scripts build",
31+
"build:help": "yarn scripts build --help",
32+
"create": "yarn scripts create",
33+
"dev": "yarn scripts build modules && yarn serve",
34+
"docs": "yarn scripts build docs",
35+
"lint": "yarn scripts lint",
36+
"prepare": "husky install",
37+
"postinstall": "patch-package && yarn scripts:build",
38+
"scripts": "node --max-old-space-size=4096 scripts/bin.js",
39+
"serve": "http-server --cors=* -c-1 -p 8022 ./build",
40+
"test": "yarn scripts test",
41+
"test:all": "yarn test && yarn scripts:test",
42+
"test:watch": "yarn scripts test --watch",
43+
"watch": "yarn scripts watch",
44+
"devserver": "vite",
45+
"devserver:lint": "yarn scripts devserver lint",
46+
"devserver:tsc": "tsc --project devserver/tsconfig.json",
47+
"scripts:all": "node scripts/scripts_manager.js",
48+
"scripts:build": "node scripts/scripts_manager.js build",
49+
"scripts:lint": "node scripts/scripts_manager.js lint",
50+
"scripts:tsc": "tsc --project scripts/src/tsconfig.json",
51+
"scripts:test": "node scripts/scripts_manager.js test"
52+
},
53+
"devDependencies": {
54+
"@types/dom-mediacapture-record": "^1.0.11",
55+
"@types/eslint": "^8.4.10",
56+
"@types/estree": "^1.0.0",
57+
"@types/jest": "^27.4.1",
58+
"@types/lodash": "^4.14.198",
59+
"@types/node": "^20.8.9",
60+
"@types/plotly.js-dist": "npm:@types/plotly.js",
61+
"@types/react": "^18.2.0",
62+
"@types/react-dom": "^18.2.0",
63+
"@typescript-eslint/eslint-plugin": "^6.6.0",
64+
"@typescript-eslint/parser": "^6.6.0",
65+
"@vitejs/plugin-react": "^4.0.4",
66+
"acorn": "^8.8.1",
67+
"acorn-jsx": "^5.3.2",
68+
"astring": "^1.8.4",
69+
"chalk": "^5.0.1",
70+
"commander": "^9.4.0",
71+
"console-table-printer": "^2.11.1",
72+
"cross-env": "^7.0.3",
73+
"esbuild": "^0.18.20",
74+
"eslint": "^8.21.0",
75+
"eslint-config-airbnb": "^19.0.4",
76+
"eslint-config-airbnb-typescript": "^17.0.0",
77+
"eslint-import-resolver-typescript": "^2.7.1",
78+
"eslint-plugin-import": "^2.26.0",
79+
"eslint-plugin-jest": "^26.8.1",
80+
"eslint-plugin-jsx-a11y": "^6.5.1",
81+
"eslint-plugin-react": "^7.29.4",
82+
"eslint-plugin-react-hooks": "^4.4.0",
83+
"eslint-plugin-simple-import-sort": "^8.0.0",
84+
"http-server": "^0.12.3",
85+
"husky": "5",
86+
"jest": "^29.4.1",
87+
"jest-environment-jsdom": "^29.4.1",
88+
"re-resizable": "^6.9.11",
89+
"react-hotkeys": "^2.0.0",
90+
"react-responsive": "^9.0.2",
91+
"sass": "^1.66.1",
92+
"ts-jest": "^29.1.1",
93+
"typedoc": "^0.25.1",
94+
"typescript": "5.0",
95+
"vite": "^4.5.2",
96+
"yarnhook": "^0.5.1"
97+
},
98+
"dependencies": {
99+
"@blueprintjs/core": "^4.20.2",
100+
"@blueprintjs/icons": "^4.4.0",
101+
"@blueprintjs/popover2": "^1.4.3",
102+
"@box2d/core": "^0.10.0",
103+
"@box2d/debug-draw": "^0.10.0",
104+
"@jscad/modeling": "2.9.6",
105+
"@jscad/regl-renderer": "^2.6.1",
106+
"@jscad/stl-serializer": "^2.1.13",
107+
"ace-builds": "^1.25.1",
108+
"classnames": "^2.3.1",
109+
"dayjs": "^1.10.4",
110+
"gl-matrix": "^3.3.0",
111+
"js-slang": "^1.0.20",
112+
"lodash": "^4.17.21",
113+
"patch-package": "^6.5.1",
114+
"phaser": "^3.54.0",
115+
"plotly.js-dist": "^2.17.1",
116+
"postinstall-postinstall": "^2.1.0",
117+
"react": "^18.2.0",
118+
"react-ace": "^10.1.0",
119+
"react-dom": "^18.2.0",
120+
"regl": "^2.1.0",
121+
"save-file": "^2.3.1",
122+
"source-academy-utils": "^1.0.0",
123+
"source-academy-wabt": "^1.0.4",
124+
"tslib": "^2.3.1"
125+
},
126+
"jest": {
127+
"projects": [
128+
"src/jest.config.js",
129+
"scripts/src/jest.config.js"
130+
]
131+
},
132+
"resolutions": {
133+
"@types/react": "^18.2.0",
134+
"esbuild": "^0.18.20",
135+
"**/gl": "^6.0.2"
136+
}
137+
}

scripts/src/build/modules/__tests__/bundle.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ test('building a bundle', async () => {
4040
const call = (fs.writeFile as jest.MockedFunction<typeof fs.writeFile>).mock.calls[0];
4141

4242
expect(call[0]).toEqual('build/bundles/test0.js')
43-
const bundleText = `(${call[1]})`;
43+
const removeExports = (call[1] as string).slice("export default".length, -1);
44+
const bundleText = `(${removeExports})`;
4445
const mockContext = {
4546
moduleContexts: {
4647
test0: {

scripts/src/build/modules/bundle.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import type {
99
ArrowFunctionExpression,
1010
CallExpression,
11-
ExpressionStatement,
11+
ExportDefaultDeclaration,
1212
Identifier,
1313
Program,
1414
VariableDeclaration,
@@ -36,30 +36,21 @@ export const outputBundle = async (name: string, bundleText: string, outDir: str
3636
const callExpression = varDeclarator.init as CallExpression;
3737
const moduleCode = callExpression.callee as ArrowFunctionExpression;
3838

39-
const output = {
40-
type: 'ArrowFunctionExpression',
41-
body: {
42-
type: 'BlockStatement',
43-
body: moduleCode.body.type === 'BlockStatement'
44-
? moduleCode.body.body
45-
: [{
46-
type: 'ExpressionStatement',
47-
expression: moduleCode.body,
48-
} as ExpressionStatement],
39+
const output: ExportDefaultDeclaration = {
40+
type: 'ExportDefaultDeclaration',
41+
declaration: {
42+
...moduleCode,
43+
params: [
44+
{
45+
type: 'Identifier',
46+
name: 'require',
47+
} as Identifier,
48+
],
4949
},
50-
params: [
51-
{
52-
type: 'Identifier',
53-
name: 'require',
54-
} as Identifier,
55-
],
56-
} as ArrowFunctionExpression;
57-
58-
let newCode = generate(output);
59-
if (newCode.endsWith(';')) newCode = newCode.slice(0, -1);
50+
};
6051

6152
const outFile = `${outDir}/bundles/${name}.js`;
62-
await fs.writeFile(outFile, newCode);
53+
await fs.writeFile(outFile, generate(output));
6354
const { size } = await fs.stat(outFile);
6455
return {
6556
severity: 'success',

0 commit comments

Comments
 (0)