From 32242aa2c3ef6bb151b5ba33bfa491412dcb04da Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Sat, 27 Jan 2024 13:48:56 +0800 Subject: [PATCH] Revert "Update Repository to Node 20" (#272) --- .github/workflows/pull-request.yml | 21 +- package.json | 273 +++++++++--------- .../build/modules/__tests__/bundle.test.ts | 3 +- scripts/src/build/modules/bundle.ts | 35 ++- yarn.lock | 45 +-- 5 files changed, 179 insertions(+), 198 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f2b04af8b..73716b82d 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,25 +10,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out source code - uses: actions/checkout@v4 - - - name: Check for package-lock.json - run: | - if [ -e package-lock.json ]; then - echo "package-lock.json found; please do not use NPM! This project uses Yarn!" - exit 1 - fi - exit 0 - - - name: Install dependencies (apt) - run: | - sudo apt-get install -y --no-install-recommends libxi-dev libgl1-mesa-dev + uses: actions/checkout@v2 - - name: Setup Node - uses: actions/setup-node@v4 + - name: Use Node.js 💻 + uses: actions/setup-node@v1 with: - node-version: 20 - cache: yarn + node-version: '16.x' - name: Install dependencies run: yarn install --frozen-lockfile diff --git a/package.json b/package.json index 85ce53a90..7b8f73f31 100644 --- a/package.json +++ b/package.json @@ -1,137 +1,136 @@ -{ - "private": true, - "name": "modules", - "version": "1.0.0", - "repository": "https://github.com/source-academy/modules.git", - "license": "Apache-2.0", - "scripts-info": { - "//NOTE": "Run `npm i npm-scripts-info -g` to install once globally, then run `npm-scripts-info` as needed to list these descriptions", - "create": "Interactively initialise a new bundle or tab from their templates", - "devserver": "Start the tab development server", - "devserver:lint": "Lint code related to the dev server", - "devserver:tsc": "Run tsc over dev server code", - "docs": "Build only documentation", - "lint": "Lint bundle and tab code", - "build": "Lint code, then build modules and documentation", - "build:help": "Show help for the build scripts", - "serve": "Start the HTTP server to serve all files in `build/`, with the same directory structure", - "scripts": "Run a script within the scripts directory", - "scripts:build": "Compile build scripts", - "scripts:lint": "Lint build script code", - "prepare": "Enable git hooks", - "test": "Run unit tests", - "test:watch": "Watch files for changes and rerun tests related to changed files", - "dev": "Build bundles and tabs only, then serve. Skips linting / type checking, does not build jsons and HTML docs. For rapid testing during development", - "watch": "Watch files for changes and rebuild on those changes", - "postinstall": "Install all patches to node_modules packages" - }, - "type": "module", - "scripts": { - "build": "yarn scripts build", - "build:help": "yarn scripts build --help", - "create": "yarn scripts create", - "dev": "yarn scripts build modules && yarn serve", - "docs": "yarn scripts build docs", - "lint": "yarn scripts lint", - "prepare": "husky install", - "postinstall": "patch-package && yarn scripts:build", - "scripts": "node --max-old-space-size=4096 scripts/bin.js", - "serve": "http-server --cors=* -c-1 -p 8022 ./build", - "test": "yarn scripts test", - "test:all": "yarn test && yarn scripts:test", - "test:watch": "yarn scripts test --watch", - "watch": "yarn scripts watch", - "devserver": "vite", - "devserver:lint": "yarn scripts devserver lint", - "devserver:tsc": "tsc --project devserver/tsconfig.json", - "scripts:all": "node scripts/scripts_manager.js", - "scripts:build": "node scripts/scripts_manager.js build", - "scripts:lint": "node scripts/scripts_manager.js lint", - "scripts:tsc": "tsc --project scripts/src/tsconfig.json", - "scripts:test": "node scripts/scripts_manager.js test" - }, - "devDependencies": { - "@types/dom-mediacapture-record": "^1.0.11", - "@types/eslint": "^8.4.10", - "@types/estree": "^1.0.0", - "@types/jest": "^27.4.1", - "@types/lodash": "^4.14.198", - "@types/node": "^20.8.9", - "@types/plotly.js-dist": "npm:@types/plotly.js", - "@types/react": "^18.2.0", - "@types/react-dom": "^18.2.0", - "@typescript-eslint/eslint-plugin": "^6.6.0", - "@typescript-eslint/parser": "^6.6.0", - "@vitejs/plugin-react": "^4.0.4", - "acorn": "^8.8.1", - "acorn-jsx": "^5.3.2", - "astring": "^1.8.4", - "chalk": "^5.0.1", - "commander": "^9.4.0", - "console-table-printer": "^2.11.1", - "cross-env": "^7.0.3", - "esbuild": "^0.18.20", - "eslint": "^8.21.0", - "eslint-config-airbnb": "^19.0.4", - "eslint-config-airbnb-typescript": "^17.0.0", - "eslint-import-resolver-typescript": "^2.7.1", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-jest": "^26.8.1", - "eslint-plugin-jsx-a11y": "^6.5.1", - "eslint-plugin-react": "^7.29.4", - "eslint-plugin-react-hooks": "^4.4.0", - "eslint-plugin-simple-import-sort": "^8.0.0", - "http-server": "^0.12.3", - "husky": "5", - "jest": "^29.4.1", - "jest-environment-jsdom": "^29.4.1", - "re-resizable": "^6.9.11", - "react-hotkeys": "^2.0.0", - "react-responsive": "^9.0.2", - "sass": "^1.66.1", - "ts-jest": "^29.1.1", - "typedoc": "^0.25.1", - "typescript": "5.0", - "vite": "^4.5.2", - "yarnhook": "^0.5.1" - }, - "dependencies": { - "@blueprintjs/core": "^4.20.2", - "@blueprintjs/icons": "^4.4.0", - "@blueprintjs/popover2": "^1.4.3", - "@box2d/core": "^0.10.0", - "@box2d/debug-draw": "^0.10.0", - "@jscad/modeling": "2.9.6", - "@jscad/regl-renderer": "^2.6.1", - "@jscad/stl-serializer": "^2.1.13", - "ace-builds": "^1.25.1", - "classnames": "^2.3.1", - "dayjs": "^1.10.4", - "gl-matrix": "^3.3.0", - "js-slang": "^1.0.20", - "lodash": "^4.17.21", - "patch-package": "^6.5.1", - "phaser": "^3.54.0", - "plotly.js-dist": "^2.17.1", - "postinstall-postinstall": "^2.1.0", - "react": "^18.2.0", - "react-ace": "^10.1.0", - "react-dom": "^18.2.0", - "regl": "^2.1.0", - "save-file": "^2.3.1", - "source-academy-utils": "^1.0.0", - "source-academy-wabt": "^1.0.4", - "tslib": "^2.3.1" - }, - "jest": { - "projects": [ - "src/jest.config.js", - "scripts/src/jest.config.js" - ] - }, - "resolutions": { - "@types/react": "^18.2.0", - "esbuild": "^0.18.20", - "**/gl": "^6.0.2" - } -} +{ + "private": true, + "name": "modules", + "version": "1.0.0", + "repository": "https://github.com/source-academy/modules.git", + "license": "Apache-2.0", + "scripts-info": { + "//NOTE": "Run `npm i npm-scripts-info -g` to install once globally, then run `npm-scripts-info` as needed to list these descriptions", + "create": "Interactively initialise a new bundle or tab from their templates", + "devserver": "Start the tab development server", + "devserver:lint": "Lint code related to the dev server", + "devserver:tsc": "Run tsc over dev server code", + "docs": "Build only documentation", + "lint": "Lint bundle and tab code", + "build": "Lint code, then build modules and documentation", + "build:help": "Show help for the build scripts", + "serve": "Start the HTTP server to serve all files in `build/`, with the same directory structure", + "scripts": "Run a script within the scripts directory", + "scripts:build": "Compile build scripts", + "scripts:lint": "Lint build script code", + "prepare": "Enable git hooks", + "test": "Run unit tests", + "test:watch": "Watch files for changes and rerun tests related to changed files", + "dev": "Build bundles and tabs only, then serve. Skips linting / type checking, does not build jsons and HTML docs. For rapid testing during development", + "watch": "Watch files for changes and rebuild on those changes", + "postinstall": "Install all patches to node_modules packages" + }, + "type": "module", + "scripts": { + "build": "yarn scripts build", + "build:help": "yarn scripts build --help", + "create": "yarn scripts create", + "dev": "yarn scripts build modules && yarn serve", + "docs": "yarn scripts build docs", + "lint": "yarn scripts lint", + "prepare": "husky install", + "postinstall": "patch-package && yarn scripts:build", + "scripts": "node --max-old-space-size=4096 scripts/bin.js", + "serve": "http-server --cors=* -c-1 -p 8022 ./build", + "test": "yarn scripts test", + "test:all": "yarn test && yarn scripts:test", + "test:watch": "yarn scripts test --watch", + "watch": "yarn scripts watch", + "devserver": "vite", + "devserver:lint": "yarn scripts devserver lint", + "devserver:tsc": "tsc --project devserver/tsconfig.json", + "scripts:all": "node scripts/scripts_manager.js", + "scripts:build": "node scripts/scripts_manager.js build", + "scripts:lint": "node scripts/scripts_manager.js lint", + "scripts:tsc": "tsc --project scripts/src/tsconfig.json", + "scripts:test": "node scripts/scripts_manager.js test" + }, + "devDependencies": { + "@types/dom-mediacapture-record": "^1.0.11", + "@types/eslint": "^8.4.10", + "@types/estree": "^1.0.0", + "@types/jest": "^27.4.1", + "@types/lodash": "^4.14.198", + "@types/node": "^20.8.9", + "@types/plotly.js-dist": "npm:@types/plotly.js", + "@types/react": "^18.2.0", + "@types/react-dom": "^18.2.0", + "@typescript-eslint/eslint-plugin": "^6.6.0", + "@typescript-eslint/parser": "^6.6.0", + "@vitejs/plugin-react": "^4.0.4", + "acorn": "^8.8.1", + "acorn-jsx": "^5.3.2", + "astring": "^1.8.4", + "chalk": "^5.0.1", + "commander": "^9.4.0", + "console-table-printer": "^2.11.1", + "cross-env": "^7.0.3", + "esbuild": "^0.18.20", + "eslint": "^8.21.0", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-airbnb-typescript": "^17.0.0", + "eslint-import-resolver-typescript": "^2.7.1", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-jest": "^26.8.1", + "eslint-plugin-jsx-a11y": "^6.5.1", + "eslint-plugin-react": "^7.29.4", + "eslint-plugin-react-hooks": "^4.4.0", + "eslint-plugin-simple-import-sort": "^8.0.0", + "http-server": "^0.12.3", + "husky": "5", + "jest": "^29.4.1", + "jest-environment-jsdom": "^29.4.1", + "re-resizable": "^6.9.11", + "react-hotkeys": "^2.0.0", + "react-responsive": "^9.0.2", + "sass": "^1.66.1", + "ts-jest": "^29.1.1", + "typedoc": "^0.25.1", + "typescript": "5.0", + "vite": "^4.5.2", + "yarnhook": "^0.5.1" + }, + "dependencies": { + "@blueprintjs/core": "^4.20.2", + "@blueprintjs/icons": "^4.4.0", + "@blueprintjs/popover2": "^1.4.3", + "@box2d/core": "^0.10.0", + "@box2d/debug-draw": "^0.10.0", + "@jscad/modeling": "2.9.6", + "@jscad/regl-renderer": "^2.6.1", + "@jscad/stl-serializer": "^2.1.13", + "ace-builds": "^1.25.1", + "classnames": "^2.3.1", + "dayjs": "^1.10.4", + "gl-matrix": "^3.3.0", + "js-slang": "^1.0.20", + "lodash": "^4.17.21", + "patch-package": "^6.5.1", + "phaser": "^3.54.0", + "plotly.js-dist": "^2.17.1", + "postinstall-postinstall": "^2.1.0", + "react": "^18.2.0", + "react-ace": "^10.1.0", + "react-dom": "^18.2.0", + "regl": "^2.1.0", + "save-file": "^2.3.1", + "source-academy-utils": "^1.0.0", + "source-academy-wabt": "^1.0.4", + "tslib": "^2.3.1" + }, + "jest": { + "projects": [ + "src/jest.config.js", + "scripts/src/jest.config.js" + ] + }, + "resolutions": { + "@types/react": "^18.2.0", + "esbuild": "^0.18.20" + } +} diff --git a/scripts/src/build/modules/__tests__/bundle.test.ts b/scripts/src/build/modules/__tests__/bundle.test.ts index 6945127c8..e3f0ff3f8 100644 --- a/scripts/src/build/modules/__tests__/bundle.test.ts +++ b/scripts/src/build/modules/__tests__/bundle.test.ts @@ -40,8 +40,7 @@ test('building a bundle', async () => { const call = (fs.writeFile as jest.MockedFunction).mock.calls[0]; expect(call[0]).toEqual('build/bundles/test0.js') - const removeExports = (call[1] as string).slice("export default".length, -1); - const bundleText = `(${removeExports})`; + const bundleText = `(${call[1]})`; const mockContext = { moduleContexts: { test0: { diff --git a/scripts/src/build/modules/bundle.ts b/scripts/src/build/modules/bundle.ts index b9dc657cd..af17469c2 100644 --- a/scripts/src/build/modules/bundle.ts +++ b/scripts/src/build/modules/bundle.ts @@ -8,7 +8,7 @@ import { import type { ArrowFunctionExpression, CallExpression, - ExportDefaultDeclaration, + ExpressionStatement, Identifier, Program, VariableDeclaration, @@ -36,21 +36,30 @@ export const outputBundle = async (name: string, bundleText: string, outDir: str const callExpression = varDeclarator.init as CallExpression; const moduleCode = callExpression.callee as ArrowFunctionExpression; - const output: ExportDefaultDeclaration = { - type: 'ExportDefaultDeclaration', - declaration: { - ...moduleCode, - params: [ - { - type: 'Identifier', - name: 'require', - } as Identifier, - ], + const output = { + type: 'ArrowFunctionExpression', + body: { + type: 'BlockStatement', + body: moduleCode.body.type === 'BlockStatement' + ? moduleCode.body.body + : [{ + type: 'ExpressionStatement', + expression: moduleCode.body, + } as ExpressionStatement], }, - }; + params: [ + { + type: 'Identifier', + name: 'require', + } as Identifier, + ], + } as ArrowFunctionExpression; + + let newCode = generate(output); + if (newCode.endsWith(';')) newCode = newCode.slice(0, -1); const outFile = `${outDir}/bundles/${name}.js`; - await fs.writeFile(outFile, generate(output)); + await fs.writeFile(outFile, newCode); const { size } = await fs.stat(outFile); return { severity: 'success', diff --git a/yarn.lock b/yarn.lock index 32ef966ac..1f93b5868 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3017,11 +3017,6 @@ expect@^29.4.3: jest-message-util "^29.4.3" jest-util "^29.4.3" -exponential-backoff@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/exponential-backoff/-/exponential-backoff-3.1.1.tgz#64ac7526fe341ab18a39016cd22c787d01e00bf6" - integrity sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw== - fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" @@ -3295,17 +3290,17 @@ gl-wiretap@^0.6.2: resolved "https://registry.yarnpkg.com/gl-wiretap/-/gl-wiretap-0.6.2.tgz#e4aa19622831088fbaa7e5a18d01768f7a3fb07c" integrity sha512-fxy1XGiPkfzK+T3XKDbY7yaqMBmozCGvAFyTwaZA3imeZH83w7Hr3r3bYlMRWIyzMI/lDUvUMM/92LE2OwqFyQ== -gl@^5.0.3, gl@^6.0.2: - version "6.0.2" - resolved "https://registry.yarnpkg.com/gl/-/gl-6.0.2.tgz#685579732a19075e3acf4684edb1270278e551c7" - integrity sha512-yBbfpChOtFvg5D+KtMaBFvj6yt3vUnheNAH+UrQH2TfDB8kr0tERdL0Tjhe0W7xJ6jR6ftQBluTZR9jXUnKe8g== +gl@^5.0.3: + version "5.0.3" + resolved "https://registry.yarnpkg.com/gl/-/gl-5.0.3.tgz#a10f37c50e48954348cc3e790b83313049bdbe1c" + integrity sha512-toWmb3Rgli5Wl9ygjZeglFBVLDYMOomy+rXlVZVDCoIRV+6mQE5nY4NgQgokYIc5oQzc1pvWY9lQJ0hGn61ZUg== dependencies: bindings "^1.5.0" bit-twiddle "^1.0.2" glsl-tokenizer "^2.1.5" - nan "^2.17.0" - node-abi "^3.26.0" - node-gyp "^9.2.0" + nan "^2.16.0" + node-abi "^3.22.0" + node-gyp "^9.0.0" prebuild-install "^7.1.1" glob-parent@^5.1.2, glob-parent@~5.1.2: @@ -4827,10 +4822,10 @@ ms@^2.0.0, ms@^2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -nan@^2.17.0: - version "2.18.0" - resolved "https://registry.yarnpkg.com/nan/-/nan-2.18.0.tgz#26a6faae7ffbeb293a39660e88a76b82e30b7554" - integrity sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w== +nan@^2.16.0: + version "2.17.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb" + integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ== nanoid@^3.3.6: version "3.3.6" @@ -4865,14 +4860,7 @@ no-case@^3.0.4: lower-case "^2.0.2" tslib "^2.0.3" -node-abi@^3.26.0: - version "3.54.0" - resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.54.0.tgz#f6386f7548817acac6434c6cba02999c9aebcc69" - integrity sha512-p7eGEiQil0YUV3ItH4/tBb781L5impVmmx2E9FRKF7d18XXzp4PGT2tdYMFY6wQqgxD0IwNZOiSJ0/K0fSi/OA== - dependencies: - semver "^7.3.5" - -node-abi@^3.3.0: +node-abi@^3.22.0, node-abi@^3.3.0: version "3.33.0" resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.33.0.tgz#8b23a0cec84e1c5f5411836de6a9b84bccf26e7f" integrity sha512-7GGVawqyHF4pfd0YFybhv/eM9JwTtPqx0mAanQ146O3FlSh3pA24zf9IRQTOsfTSqXTNzPSP5iagAJ94jjuVog== @@ -4884,13 +4872,12 @@ node-getopt@^0.3.2: resolved "https://registry.yarnpkg.com/node-getopt/-/node-getopt-0.3.2.tgz#57507cd22f6f69650aa99252304a842f1224e44c" integrity sha512-yqkmYrMbK1wPrfz7mgeYvA4tBperLg9FQ4S3Sau3nSAkpOA0x0zC8nQ1siBwozy1f4SE8vq2n1WKv99r+PCa1Q== -node-gyp@^9.2.0: - version "9.4.1" - resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-9.4.1.tgz#8a1023e0d6766ecb52764cc3a734b36ff275e185" - integrity sha512-OQkWKbjQKbGkMf/xqI1jjy3oCTgMKJac58G2+bjZb3fza6gW2YrCSdMQYaoTb70crvE//Gngr4f0AgVHmqHvBQ== +node-gyp@^9.0.0: + version "9.3.1" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-9.3.1.tgz#1e19f5f290afcc9c46973d68700cbd21a96192e4" + integrity sha512-4Q16ZCqq3g8awk6UplT7AuxQ35XN4R/yf/+wSAwcBUAjg7l58RTactWaP8fIDTi0FzI7YcVLujwExakZlfWkXg== dependencies: env-paths "^2.2.0" - exponential-backoff "^3.1.1" glob "^7.1.4" graceful-fs "^4.2.6" make-fetch-happen "^10.0.3"