source-academy / js-slang

Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python
https://source-academy.github.io/source/
Apache License 2.0
70 stars 104 forks source link

Remove Synchronous Module Loading #1637

Closed leeyi45 closed 7 months ago

leeyi45 commented 7 months ago

This PR will officially deprecate and remove any synchronous module loading code. All module code is completely asynchronous.

The main idea is to leverage the native import() functions that browsers provide. However this is not available in Jest or NodeJS, so it is necessary to detect the environment and switches to using require when not running in the browser.

And even then, though Jest will have no problems with it, some testing has shown that NodeJS will refuse to load JSON files over the web (i.e trying to import http://localhost:8022/modules.json throws MODULE_NOT_FOUND), so JSON files are still loaded using fetch.

This does introduce complexity into how our tests are written (and perhaps in some other areas that I cannot foresee), so maybe it would be best to simply use the fetch then eval method, but why not use import() where we can?

This is fairly low priority, so it doesn't really need to merged ahead of anything else

Will close #1348

coveralls commented 7 months ago

Pull Request Test Coverage Report for Build 8580048012

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/cse-machine/interpreter.ts 1 2 50.0%
src/name-extractor/index.ts 28 29 96.55%
src/utils/misc.ts 3 4 75.0%
src/modules/loader/index.ts 16 18 88.89%
src/runner/sourceRunner.ts 4 6 66.67%
src/modules/loader/loaders.ts 54 62 87.1%
src/stepper/stepper.ts 4 16 25.0%
<!-- Total: 282 309 91.26% -->
Files with Coverage Reduction New Missed Lines %
src/utils/statementSeqTransform.ts 1 14.29%
src/modules/utils.ts 1 88.24%
src/cse-machine/utils.ts 1 89.61%
src/modules/errors.ts 2 75.71%
src/validator/validator.ts 2 95.21%
src/cse-machine/interpreter.ts 7 91.59%
<!-- Total: 14 -->
Totals Coverage Status
Change from base Build 8549384100: 0.05%
Covered Lines: 10615
Relevant Lines: 12638

💛 - Coveralls