From 633eb82d188474a700b2dc8edca3f3c5e15797fc Mon Sep 17 00:00:00 2001 From: Mats Jun Larsen Date: Tue, 28 Feb 2023 00:06:38 +0000 Subject: [PATCH] Transition to ECMAScript Modules (#4780) Makes the Compiler Explorer app, and all the tooling ESM compatible. Things that have been done: 1. The package.json has `type: module` now 2. All relative imports have a .js ending 3. All directory imports are now directory/index.js to comply with ESM standards 4. Dependency node-graceful is now imported into tree, because the package is broken under esm 5. Dependency p-queue has been bumped to 7.x with ESM support 6. Dependency profanities has been bumped to 3.x with ESM support 7. Webpack config is now both ESM and CommonJS compatible 8. Non-ESM compatible imports have been rewritten 9. ESLint configuration has been tweaked to not fail on .js imports 10. Mocha is now hacked together and ran with ts-node-esm 11. Webpack is now hacked together and ran with ts-node-esm 12. Webpack config is now ESM compatible, so that it can be used in the dev server 13. Cypress code still runs commonjs, and has been excluded from the tsconfig 14. All sinon mock tests have been commented out, because sinon module mocks do not work with ESModules (because ESModules are immutable) A lot of tests are now giving warnings/errors to stdout, yet still pass. Docenizer codegenerator scripts have been updated, but I did not re-run them, and instead just changed their code. --------- Co-authored-by: Matt Godbolt --- .eslintrc.yml | 2 + .gitignore | 2 +- .idea/codeStyles/Project.xml | 3 + .idea/jsLibraryMappings.xml | 6 - .idea/runConfigurations/app_js.xml | 5 - .mocharc-min.yml | 4 - .mocharc.yml | 4 - .nycrc.yml | 15 - .prettierignore | 3 +- .prettierrc.js => .prettierrc.cjs | 0 Makefile | 8 +- app.ts | 52 +- compiler-args-app.ts | 10 +- cypress/tsconfig.json | 12 + docs/AddingALanguage.md | 2 +- etc/scripts/build-dist-win.ps1 | 2 +- etc/scripts/build-dist.sh | 2 +- etc/scripts/docenizers/docenizer-6502.py | 2 +- etc/scripts/docenizers/docenizer-amd64.py | 2 +- etc/scripts/docenizers/docenizer-arm32.py | 2 +- etc/scripts/docenizers/docenizer-avr.py | 2 +- etc/scripts/docenizers/docenizer-evm.py | 2 +- etc/scripts/docenizers/docenizer-java.ts | 2 +- etc/scripts/docenizers/docenizer-llvm.ts | 2 +- etc/scripts/docenizers/docenizer-python.py | 2 +- etc/scripts/parsed-pug/package.json | 3 + .../{ => parsed-pug}/parsed_pug_file.js | 10 +- lib/{.eslintrc.js => .eslintrc.cjs} | 4 +- lib/asm-docs/_all.ts | 16 +- lib/asm-docs/amd64.ts | 4 +- lib/asm-docs/arm32.ts | 4 +- lib/asm-docs/avr.ts | 4 +- lib/asm-docs/evm.ts | 4 +- lib/asm-docs/generated/asm-docs-6502.ts | 2 +- lib/asm-docs/generated/asm-docs-amd64.ts | 2 +- lib/asm-docs/generated/asm-docs-arm32.ts | 2 +- lib/asm-docs/generated/asm-docs-avr.ts | 2 +- lib/asm-docs/generated/asm-docs-evm.ts | 2 +- lib/asm-docs/generated/asm-docs-java.ts | 2 +- lib/asm-docs/generated/asm-docs-llvm.ts | 2 +- lib/asm-docs/generated/asm-docs-python.ts | 2 +- lib/asm-docs/index.ts | 8 +- lib/asm-docs/java.ts | 4 +- lib/asm-docs/llvm.ts | 4 +- lib/asm-docs/mos6502.ts | 4 +- lib/asm-docs/python.ts | 4 +- lib/assert.ts | 4 +- lib/aws.ts | 6 +- lib/base-compiler.ts | 78 +- lib/buildenvsetup/_all.ts | 6 +- lib/buildenvsetup/base.ts | 6 +- lib/buildenvsetup/ceconan-rust.ts | 2 +- lib/buildenvsetup/ceconan.ts | 6 +- lib/buildenvsetup/cliconan.ts | 8 +- lib/buildenvsetup/index.ts | 8 +- lib/cache/base.interfaces.ts | 2 +- lib/cache/base.ts | 8 +- lib/cache/from-config.ts | 14 +- lib/cache/in-memory.ts | 4 +- lib/cache/multi.ts | 4 +- lib/cache/null.ts | 4 +- lib/cache/on-disk.ts | 6 +- lib/cache/s3.ts | 10 +- lib/cfg/cfg-parsers/base.ts | 4 +- lib/cfg/cfg-parsers/clang.ts | 6 +- lib/cfg/cfg-parsers/gcc.ts | 4 +- lib/cfg/cfg.ts | 16 +- lib/clientstate-normalizer.ts | 2 +- lib/compilation-env.ts | 18 +- lib/compilation-queue.ts | 2 +- lib/compiler-arguments.ts | 10 +- lib/compiler-finder.ts | 20 +- lib/compilers/_all.ts | 174 +- lib/compilers/ada.ts | 8 +- lib/compilers/analysis-tool.ts | 4 +- lib/compilers/argument-parsers.ts | 6 +- lib/compilers/assembly.ts | 14 +- lib/compilers/avrgcc6502.ts | 8 +- lib/compilers/beebasm.ts | 12 +- lib/compilers/carbon.ts | 16 +- lib/compilers/cc65.ts | 14 +- lib/compilers/circle.ts | 2 +- lib/compilers/circt.ts | 7 +- lib/compilers/cl430.ts | 6 +- lib/compilers/clang.ts | 14 +- lib/compilers/clangcl.ts | 8 +- lib/compilers/clean.ts | 12 +- lib/compilers/clspv.ts | 16 +- lib/compilers/cppfront.ts | 8 +- lib/compilers/cproc.ts | 2 +- lib/compilers/crystal.ts | 12 +- lib/compilers/dart.ts | 12 +- lib/compilers/default.ts | 2 +- lib/compilers/dmd.ts | 8 +- lib/compilers/dosbox-compiler.ts | 12 +- lib/compilers/dotnet.ts | 18 +- lib/compilers/ellcc.ts | 2 +- lib/compilers/erlang.ts | 6 +- lib/compilers/ewarm.ts | 8 +- lib/compilers/ewavr.ts | 8 +- lib/compilers/fake-for-test.ts | 5 +- lib/compilers/flang.ts | 4 +- lib/compilers/fortran.ts | 6 +- lib/compilers/gcc.ts | 2 +- lib/compilers/gccrs.ts | 2 +- lib/compilers/gm2.ts | 2 +- lib/compilers/golang.ts | 14 +- lib/compilers/haskell.ts | 8 +- lib/compilers/hlsl.ts | 4 +- lib/compilers/hook.ts | 12 +- lib/compilers/index.ts | 6 +- lib/compilers/ispc.ts | 12 +- lib/compilers/jakt.ts | 7 +- lib/compilers/java.ts | 16 +- lib/compilers/julia.ts | 14 +- lib/compilers/kotlin.ts | 8 +- lib/compilers/ldc.ts | 8 +- lib/compilers/llc.ts | 8 +- lib/compilers/llvm-mca.ts | 6 +- lib/compilers/llvm-mos.ts | 14 +- lib/compilers/mlir.ts | 8 +- lib/compilers/mrustc.ts | 8 +- lib/compilers/nasm.ts | 7 +- lib/compilers/nim.ts | 10 +- lib/compilers/nvcc.ts | 16 +- lib/compilers/ocaml.ts | 8 +- lib/compilers/opt.ts | 8 +- lib/compilers/osaca.ts | 6 +- lib/compilers/pascal-win.ts | 18 +- lib/compilers/pascal.ts | 16 +- lib/compilers/pony.ts | 8 +- lib/compilers/ppci.ts | 9 +- lib/compilers/ptxas.ts | 16 +- lib/compilers/python.ts | 12 +- lib/compilers/racket.ts | 10 +- lib/compilers/rga.ts | 24 +- lib/compilers/ruby.ts | 10 +- lib/compilers/rust.ts | 16 +- lib/compilers/rustc-cg-gcc.ts | 6 +- lib/compilers/scala.ts | 10 +- lib/compilers/sdcc.ts | 4 +- lib/compilers/solidity.ts | 6 +- lib/compilers/spirv.ts | 16 +- lib/compilers/swift.ts | 4 +- lib/compilers/tendra.ts | 4 +- lib/compilers/tinyc.ts | 6 +- lib/compilers/toit.ts | 10 +- lib/compilers/turboc.ts | 6 +- lib/compilers/typescript-native.ts | 10 +- lib/compilers/win32-vc.ts | 8 +- lib/compilers/win32-vc6.ts | 8 +- lib/compilers/win32.ts | 18 +- lib/compilers/wine-vc.ts | 16 +- lib/compilers/wsl-vc.ts | 10 +- lib/compilers/z88dk.ts | 18 +- lib/compilers/zig.ts | 10 +- lib/compilers/zigcc.ts | 6 +- lib/compilers/zigcxx.ts | 6 +- lib/demangler/_all.ts | 12 +- lib/demangler/base.ts | 20 +- lib/demangler/cpp.ts | 2 +- lib/demangler/default.ts | 2 +- lib/demangler/index.ts | 8 +- lib/demangler/llvm.ts | 14 +- lib/demangler/nvhpc.ts | 4 +- lib/demangler/pascal.ts | 8 +- lib/demangler/prefix-tree.ts | 2 +- lib/demangler/win32-llvm.ts | 6 +- lib/demangler/win32.ts | 12 +- lib/exec.ts | 10 +- lib/external-parsers/_all.ts | 2 +- lib/external-parsers/base.ts | 12 +- lib/external-parsers/ce-asm-parser.ts | 2 +- .../external-parser.interface.ts | 4 +- lib/external-parsers/index.ts | 6 +- lib/formatters/_all.ts | 8 +- lib/formatters/base.ts | 6 +- lib/formatters/clang-format.ts | 8 +- lib/formatters/dartformat.ts | 8 +- lib/formatters/gofmt.ts | 8 +- lib/formatters/index.ts | 14 +- lib/formatters/rustfmt.ts | 8 +- lib/handlers/api.ts | 30 +- lib/handlers/assembly-documentation.ts | 4 +- lib/handlers/compile.ts | 20 +- lib/handlers/formatting.ts | 8 +- lib/handlers/health-check.ts | 4 +- lib/handlers/noscript.ts | 17 +- lib/handlers/route-api.ts | 16 +- lib/handlers/site-templates.ts | 2 +- lib/handlers/source.ts | 2 +- lib/keyed-type.ts | 4 +- lib/languages.ts | 2 +- lib/llvm-ast.ts | 6 +- lib/llvm-ir.ts | 4 +- lib/llvm-opt-transformer.ts | 6 +- lib/mapfiles/map-file-delphi.ts | 2 +- lib/mapfiles/map-file-vs.ts | 2 +- lib/mapfiles/map-file.ts | 2 +- lib/node-graceful.ts | 167 ++ lib/objdumper/_all.ts | 10 +- lib/objdumper/binutils.ts | 2 +- lib/objdumper/da65.ts | 2 +- lib/objdumper/default.ts | 2 +- lib/objdumper/elftoolchain.ts | 2 +- lib/objdumper/index.ts | 8 +- lib/objdumper/llvm.ts | 2 +- lib/options-handler.ts | 16 +- lib/parsers/asm-parser-amdgpu.ts | 2 +- lib/parsers/asm-parser-beebasm.ts | 12 +- lib/parsers/asm-parser-cc65.ts | 6 +- lib/parsers/asm-parser-cpp.ts | 6 +- lib/parsers/asm-parser-crystal.ts | 2 +- lib/parsers/asm-parser-dart.ts | 12 +- lib/parsers/asm-parser-dotnet.ts | 4 +- lib/parsers/asm-parser-ewavr.ts | 16 +- lib/parsers/asm-parser-sass.ts | 4 +- lib/parsers/asm-parser-spirv.ts | 4 +- lib/parsers/asm-parser-turboc.ts | 10 +- lib/parsers/asm-parser-vc.ts | 16 +- lib/parsers/asm-parser-vc6.ts | 12 +- lib/parsers/asm-parser-z88dk.ts | 12 +- lib/parsers/asm-parser.interfaces.ts | 2 +- lib/parsers/asm-parser.ts | 16 +- lib/parsers/asm-raw.ts | 6 +- lib/parsers/asmregex.ts | 4 +- lib/parsers/llvm-pass-dump-parser.ts | 10 +- lib/pe32-support.ts | 2 +- lib/properties.ts | 8 +- lib/s3-handler.interfaces.ts | 6 +- lib/s3-handler.ts | 4 +- lib/shortener/_all.ts | 4 +- lib/shortener/base.ts | 2 +- lib/shortener/default.ts | 2 +- lib/shortener/index.ts | 8 +- lib/shortener/tinyurl.ts | 2 +- lib/sources/browser.ts | 2 +- lib/sources/builtin.ts | 4 +- lib/sources/index.ts | 4 +- lib/sponsors.ts | 2 +- lib/stacktrace.ts | 4 +- lib/storage/_all.ts | 8 +- lib/storage/base.ts | 13 +- lib/storage/index.ts | 8 +- lib/storage/local.ts | 4 +- lib/storage/null.ts | 2 +- lib/storage/remote.ts | 4 +- lib/storage/s3.ts | 10 +- lib/tooling/_all.ts | 30 +- lib/tooling/base-tool.interface.ts | 6 +- lib/tooling/base-tool.ts | 18 +- lib/tooling/clang-format-tool.ts | 6 +- lib/tooling/clang-query-tool.ts | 6 +- lib/tooling/clang-tidy-tool.ts | 6 +- lib/tooling/compiler-dropin-tool.ts | 10 +- lib/tooling/index.ts | 8 +- lib/tooling/llvm-cov-tool.ts | 4 +- lib/tooling/llvm-mca-tool.ts | 2 +- lib/tooling/microsoft-analysis-tool.ts | 14 +- lib/tooling/osaca-tool.ts | 6 +- lib/tooling/pahole-tool.ts | 2 +- lib/tooling/pvs-studio-tool.ts | 14 +- lib/tooling/readelf-tool.ts | 4 +- lib/tooling/rustfmt-tool.ts | 4 +- lib/tooling/strings-tool.ts | 4 +- lib/tooling/testing-tool.ts | 2 +- lib/tooling/x86to6502-tool.ts | 6 +- lib/tsconfig.json | 3 - lib/utils.ts | 4 +- lint-staged.config.mjs | 2 +- package-lock.json | 2097 +++-------------- package.json | 40 +- static/.eslint-ce-static.yml | 2 + static/{.eslintrc.js => .eslintrc.cjs} | 2 + static/analytics.ts | 2 +- static/ansi-to-html.ts | 6 +- static/api/api.ts | 4 +- static/api/formatting.interfaces.ts | 2 +- static/assert.ts | 6 +- static/colour.ts | 2 +- static/compiler-service.ts | 12 +- static/components.interfaces.ts | 8 +- static/components.ts | 6 +- static/download-service.ts | 2 +- static/event-hub.ts | 4 +- static/event-map.ts | 20 +- static/formatter-registry.ts | 10 +- static/global.ts | 4 +- static/graph-layout-core.ts | 2 +- static/history.ts | 4 +- static/hub.ts | 60 +- static/lib-utils.ts | 4 +- static/line-colouring.ts | 2 +- static/local.ts | 2 +- static/main.ts | 42 +- static/modes/cpp-for-opencl-mode.ts | 2 +- static/modes/cppcircle-mode.ts | 2 +- static/modes/cppfront-mode.ts | 2 +- static/modes/cppx-blue-mode.ts | 2 +- static/modes/cuda-mode.ts | 2 +- static/modes/mlir-mode.ts | 2 +- static/modes/openclc-mode.ts | 2 +- static/modes/ptx-mode.ts | 2 +- static/monaco-config.ts | 2 +- static/motd.ts | 4 +- static/multifile-service.ts | 6 +- static/noscript.ts | 4 +- static/options.interfaces.ts | 6 +- static/options.ts | 2 +- static/panes/ast-view.ts | 16 +- static/panes/cfg-view.ts | 20 +- static/panes/compiler.interfaces.ts | 2 +- static/panes/compiler.ts | 72 +- static/panes/conformance-view.interfaces.ts | 2 +- static/panes/conformance-view.ts | 36 +- static/panes/device-view.interfaces.ts | 4 +- static/panes/device-view.ts | 22 +- static/panes/diff.ts | 16 +- static/panes/editor.interfaces.ts | 2 +- static/panes/editor.ts | 40 +- static/panes/executor.interfaces.ts | 2 +- static/panes/executor.ts | 56 +- static/panes/flags-view.ts | 14 +- static/panes/gccdump-view.ts | 16 +- static/panes/gnatdebug-view.ts | 12 +- static/panes/gnatdebugtree-view.ts | 12 +- static/panes/haskellcmm-view.ts | 12 +- static/panes/haskellcore-view.ts | 12 +- static/panes/haskellstg-view.ts | 12 +- static/panes/ir-view.ts | 16 +- static/panes/llvm-opt-pipeline.ts | 20 +- static/panes/opt-view.ts | 12 +- static/panes/output.ts | 22 +- static/panes/pane.ts | 16 +- static/panes/pp-view.ts | 16 +- static/panes/rusthir-view.ts | 12 +- static/panes/rustmacroexp-view.ts | 12 +- static/panes/rustmir-view.ts | 12 +- static/panes/tool-input-view.ts | 12 +- static/panes/tool.ts | 26 +- static/panes/tree.ts | 26 +- static/presentation.ts | 2 +- static/rison.ts | 4 +- static/settings.ts | 20 +- static/sharing.ts | 10 +- static/tests/frontend-testing.ts | 2 +- static/tests/hello-world.ts | 2 +- static/tests/motd.ts | 4 +- static/themes.ts | 2 +- static/url.ts | 2 +- static/widgets/alert.ts | 4 +- static/widgets/compiler-picker.ts | 10 +- static/widgets/fontscale.ts | 6 +- static/widgets/history-widget.ts | 6 +- static/widgets/libs-widget.ts | 10 +- static/widgets/load-save.ts | 10 +- static/widgets/pane-renaming.ts | 2 +- static/widgets/site-templates-widget.ts | 6 +- static/widgets/timing-info-widget.ts | 6 +- test/_setup-log.ts | 2 +- test/analysis-tests.ts | 6 +- test/ansi-to-html-tests.ts | 2 +- test/asm-tests.ts | 8 +- test/aws-tests.ts | 4 +- test/base-compiler-tests.ts | 680 +++--- test/base-formatter-tests.ts | 2 +- test/cache-tests.ts | 20 +- test/cfg-tests.ts | 4 +- test/check-img.ts | 2 +- test/checks.ts | 8 +- test/compilation-env.ts | 6 +- test/compiler-finder-tests.ts | 8 +- test/compilers/argument-parsers-tests.js | 8 +- test/compilers/clang-tests.js | 16 +- test/compilers/hook-tests.js | 4 +- test/csp-tests.ts | 2 +- test/d-tests.ts | 8 +- test/demangler-tests.js | 12 +- test/exec-tests.ts | 6 +- test/filter-tests.js | 14 +- test/golang-tests.ts | 8 +- test/google-tests.ts | 2 +- test/handlers/api-tests.js | 6 +- test/handlers/asm-docs-tests.ts | 4 +- test/handlers/compile-tests.js | 6 +- test/handlers/health-check-tests.js | 6 +- test/handlers/site-templates-tests.ts | 2 +- test/handlers/source-tests.js | 4 +- test/instructionsets-tests.ts | 2 +- test/java-tests.ts | 12 +- test/lang-tests.ts | 4 +- test/llvm-ast-parser-tests.ts | 10 +- test/llvm-ir-parser-tests.ts | 6 +- test/llvm-ir-tests.ts | 6 +- test/llvm-pass-dump-parser-tests.ts | 4 +- test/map-file-tests.js | 6 +- test/nim-tests.ts | 8 +- test/options-handler.js | 10 +- test/packager-tests.js | 4 +- test/pascal-tests.js | 12 +- test/pe32-tests.js | 2 +- test/pp-output-test.ts | 10 +- test/ppci-tests.ts | 6 +- test/properties-test.ts | 6 +- test/rison.ts | 4 +- test/sponsors-test.ts | 8 +- test/statenormalisation-tests.ts | 6 +- test/storage/storage-s3-tests.ts | 6 +- test/storage/storage-tests.ts | 42 +- test/symbol-store-tests.ts | 4 +- test/tool-tests.ts | 4 +- test/unfurl-tests.ts | 4 +- test/utils-tests.ts | 6 +- test/utils.ts | 10 +- test/win-path-tests.ts | 8 +- tsconfig.backend.json | 4 +- tsconfig.frontend.json | 2 +- types/compilation/compilation.interfaces.ts | 14 +- .../llvm-opt-pipeline-output.interfaces.ts | 2 +- types/compiler-arguments.interfaces.ts | 2 +- types/compiler.interfaces.ts | 8 +- types/execution/execution.interfaces.ts | 2 +- .../assembly-documentation.interfaces.ts | 2 +- types/tool.interfaces.ts | 4 +- ...ack.config.esm.js => webpack.config.esm.ts | 12 +- 425 files changed, 2625 insertions(+), 3984 deletions(-) delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/runConfigurations/app_js.xml delete mode 100644 .nycrc.yml rename .prettierrc.js => .prettierrc.cjs (100%) create mode 100644 cypress/tsconfig.json create mode 100644 etc/scripts/parsed-pug/package.json rename etc/scripts/{ => parsed-pug}/parsed_pug_file.js (92%) rename lib/{.eslintrc.js => .eslintrc.cjs} (95%) create mode 100644 lib/node-graceful.ts delete mode 100644 lib/tsconfig.json rename static/{.eslintrc.js => .eslintrc.cjs} (97%) rename webpack.config.esm.js => webpack.config.esm.ts (95%) diff --git a/.eslintrc.yml b/.eslintrc.yml index b59038d9e..b4090af49 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -52,6 +52,7 @@ rules: import/no-self-import: error import/no-useless-path-segments: error import/no-webpack-loader-syntax: error + import/no-unresolved: off # Doesn't like .js files import/order: - error - alphabetize: @@ -121,6 +122,7 @@ rules: no-process-exit: off node/no-unsupported-features/es-syntax: off node/shebang: off + node/no-missing-import: off # Doesn't like .js imports of .interfaces.ts files promise/catch-or-return: error promise/no-new-statics: error promise/no-return-wrap: error diff --git a/.gitignore b/.gitignore index 6c803f89e..9e157b0af 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,9 @@ # build generated files /.node-bin /.npm-updated -/.nyc_output /node_modules /out +/coverage # generated from opcode docenzier.py scripts /asm-docs* diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index ef6ab7165..708c7dc4d 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -20,6 +20,9 @@ + +