Skip to content

Commit 633eb82

Browse files
Transition to ECMAScript Modules (compiler-explorer#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 <[email protected]>
1 parent 5fee0e2 commit 633eb82

File tree

425 files changed

+2710
-4069
lines changed

Some content is hidden

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

425 files changed

+2710
-4069
lines changed

.eslintrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ rules:
5252
import/no-self-import: error
5353
import/no-useless-path-segments: error
5454
import/no-webpack-loader-syntax: error
55+
import/no-unresolved: off # Doesn't like .js files
5556
import/order:
5657
- error
5758
- alphabetize:
@@ -121,6 +122,7 @@ rules:
121122
no-process-exit: off
122123
node/no-unsupported-features/es-syntax: off
123124
node/shebang: off
125+
node/no-missing-import: off # Doesn't like .js imports of .interfaces.ts files
124126
promise/catch-or-return: error
125127
promise/no-new-statics: error
126128
promise/no-return-wrap: error

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# build generated files
33
/.node-bin
44
/.npm-updated
5-
/.nyc_output
65
/node_modules
76
/out
7+
/coverage
88

99
# generated from opcode docenzier.py scripts
1010
/asm-docs*

.idea/codeStyles/Project.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/runConfigurations/app_js.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.mocharc-min.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
recursive: true
22
ignore: test/filter-tests.js
3-
require:
4-
- esm
5-
- ts-node/register
6-
- source-map-support/register

.mocharc.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
recursive: true
2-
require:
3-
- esm
4-
- ts-node/register
5-
- source-map-support/register

.nycrc.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# build generated files
55
/.node-bin
66
/.npm-updated
7-
/.nyc_output
87
/node_modules
98
/out
9+
/coverage
1010

1111
# generated from opcode docenzier.py scripts
1212
/asm-docs*
@@ -36,6 +36,7 @@ newrelic_agent.log
3636
etc
3737
examples
3838
out
39+
cypress
3940

4041
# Autogenerated files
4142
lib/asm-docs/generated/asm-docs-*
File renamed without changes.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ prebuild: prereqs
7777

7878
.PHONY: run-only
7979
run-only: node-installed ## Runs the site like it runs in production without building it
80-
env NODE_ENV=production $(NODE) $(NODE_ARGS) -r esm ./out/dist/app.js --webpackContent ./out/webpack/static $(EXTRA_ARGS)
80+
env NODE_ENV=production $(NODE) $(NODE_ARGS) ./out/dist/app.js --webpackContent ./out/webpack/static $(EXTRA_ARGS)
8181

8282
.PHONY: run
8383
run: ## Runs the site like it runs in production
@@ -86,15 +86,15 @@ run: ## Runs the site like it runs in production
8686

8787
.PHONY: dev
8888
dev: prereqs ## Runs the site as a developer; including live reload support and installation of git hooks
89-
./node_modules/.bin/supervisor -w app.ts,lib,etc/config,static/tsconfig.json -e 'js|ts|node|properties|yaml' -n exit --exec $(NODE) $(NODE_ARGS) -- -r esm -r ts-node/register ./app.ts $(EXTRA_ARGS)
89+
NODE_OPTIONS=$(NODE_ARGS) ./node_modules/.bin/supervisor -w app.ts,lib,etc/config,static/tsconfig.json -e 'js|ts|node|properties|yaml' -n exit --exec $(shell pwd)/node_modules/.bin/ts-node-esm -- ./app.ts $(EXTRA_ARGS)
9090

9191
.PHONY: gpu-dev
9292
gpu-dev: prereqs ## Runs the site as a developer; including live reload support and installation of git hooks
93-
./node_modules/.bin/supervisor -w app.ts,lib,etc/config,static/tsconfig.json -e 'js|ts|node|properties|yaml' -n exit --exec $(NODE) $(NODE_ARGS) -- -r esm -r ts-node/register ./app.ts --env gpu $(EXTRA_ARGS)
93+
NODE_OPTIONS=$(NODE_ARGS) ./node_modules/.bin/supervisor -w app.ts,lib,etc/config,static/tsconfig.json -e 'js|ts|node|properties|yaml' -n exit --exec $(shell pwd)/node_modules/.bin/ts-node-esm -- ./app.ts --env gpu $(EXTRA_ARGS)
9494

9595
.PHONY: debug
9696
debug: prereqs ## Runs the site as a developer with full debugging; including live reload support and installation of git hooks
97-
./node_modules/.bin/supervisor -w app.ts,lib,etc/config,static/tsconfig.json -e 'js|ts|node|properties|yaml' -n exit --inspect 9229 --exec $(NODE) $(NODE_ARGS) -- -r esm -r ts-node/register ./app.ts --debug $(EXTRA_ARGS)
97+
NODE_OPTIONS="$(NODE_ARGS) --inspect 9229" ./node_modules/.bin/supervisor -w app.ts,lib,etc/config,static/tsconfig.json -e 'js|ts|node|properties|yaml' -n exit --exec $(shell pwd)/node_modules/.bin/ts-node-esm -- ./app.ts --debug $(EXTRA_ARGS)
9898

9999
.PHONY:
100100
asm-docs:

app.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,34 @@ import systemdSocket from 'systemd-socket';
4343
import _ from 'underscore';
4444
import urljoin from 'url-join';
4545

46-
import * as aws from './lib/aws';
47-
import * as normalizer from './lib/clientstate-normalizer';
48-
import {ElementType} from './lib/common-utils';
49-
import {CompilationEnvironment} from './lib/compilation-env';
50-
import {CompilationQueue} from './lib/compilation-queue';
51-
import {CompilerFinder} from './lib/compiler-finder';
52-
// import { policy as csp } from './lib/csp';
53-
import {startWineInit} from './lib/exec';
54-
import {CompileHandler} from './lib/handlers/compile';
55-
import * as healthCheck from './lib/handlers/health-check';
56-
import {NoScriptHandler} from './lib/handlers/noscript';
57-
import {RouteAPI} from './lib/handlers/route-api';
58-
import {loadSiteTemplates} from './lib/handlers/site-templates';
59-
import {SourceHandler} from './lib/handlers/source';
60-
import {languages as allLanguages} from './lib/languages';
61-
import {logger, logToLoki, logToPapertrail, makeLogStream, suppressConsoleLog} from './lib/logger';
62-
import {setupMetricsServer} from './lib/metrics-server';
63-
import {ClientOptionsHandler} from './lib/options-handler';
64-
import * as props from './lib/properties';
65-
import {ShortLinkResolver} from './lib/shortener/google';
66-
import {sources} from './lib/sources';
67-
import {loadSponsorsFromString} from './lib/sponsors';
68-
import {getStorageTypeByKey} from './lib/storage';
69-
import * as utils from './lib/utils';
70-
import {Language, LanguageKey} from './types/languages.interfaces';
46+
import * as aws from './lib/aws.js';
47+
import * as normalizer from './lib/clientstate-normalizer.js';
48+
import {ElementType} from './lib/common-utils.js';
49+
import {CompilationEnvironment} from './lib/compilation-env.js';
50+
import {CompilationQueue} from './lib/compilation-queue.js';
51+
import {CompilerFinder} from './lib/compiler-finder.js';
52+
// import { policy as csp } from './lib/csp.js';
53+
import {startWineInit} from './lib/exec.js';
54+
import {CompileHandler} from './lib/handlers/compile.js';
55+
import * as healthCheck from './lib/handlers/health-check.js';
56+
import {NoScriptHandler} from './lib/handlers/noscript.js';
57+
import {RouteAPI} from './lib/handlers/route-api.js';
58+
import {loadSiteTemplates} from './lib/handlers/site-templates.js';
59+
import {SourceHandler} from './lib/handlers/source.js';
60+
import {languages as allLanguages} from './lib/languages.js';
61+
import {logger, logToLoki, logToPapertrail, makeLogStream, suppressConsoleLog} from './lib/logger.js';
62+
import {setupMetricsServer} from './lib/metrics-server.js';
63+
import {ClientOptionsHandler} from './lib/options-handler.js';
64+
import * as props from './lib/properties.js';
65+
import {ShortLinkResolver} from './lib/shortener/google.js';
66+
import {sources} from './lib/sources/index.js';
67+
import {loadSponsorsFromString} from './lib/sponsors.js';
68+
import {getStorageTypeByKey} from './lib/storage/index.js';
69+
import * as utils from './lib/utils.js';
70+
import type {Language, LanguageKey} from './types/languages.interfaces.js';
7171

7272
// Used by assert.ts
73-
global.ce_base_directory = __dirname; // eslint-disable-line unicorn/prefer-module
73+
global.ce_base_directory = new URL('.', import.meta.url);
7474

7575
// Parse arguments from command line 'node ./app.js args...'
7676
const opts = nopt({

compiler-args-app.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import nopt from 'nopt';
2929
import _ from 'underscore';
3030

31-
import {CompilerArguments} from './lib/compiler-arguments';
32-
import * as Parsers from './lib/compilers/argument-parsers';
33-
import {executeDirect} from './lib/exec';
34-
import {logger} from './lib/logger';
35-
import {padRight} from './lib/utils';
31+
import {CompilerArguments} from './lib/compiler-arguments.js';
32+
import * as Parsers from './lib/compilers/argument-parsers.js';
33+
import {executeDirect} from './lib/exec.js';
34+
import {logger} from './lib/logger.js';
35+
import {padRight} from './lib/utils.js';
3636

3737
const opts = nopt({
3838
parser: [String],

cypress/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"compilerOptions": {
4+
/* Module resolution */
5+
"target": "esnext",
6+
"module": "commonjs",
7+
"moduleResolution": "classic",
8+
/* Code generation */
9+
"typeRoots": ["../node_modules/@types"],
10+
"types": ["mocha", "chai", "chai-http"],
11+
}
12+
}

docs/AddingALanguage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you want to add a new language to the site, you should follow this steps:
1919

2020
- If the language is supported by Monaco Editor (You can find the list
2121
[here](https://github.com/microsoft/monaco-editor/tree/main/src/basic-languages)), you should add it to the list of
22-
languages inside the `MonacoEditorWebpackPlugin` config in `webpack.config.esm.js`
22+
languages inside the `MonacoEditorWebpackPlugin` config in `webpack.config.esm.ts`
2323
- If not, you should implement your own language mode; see `static/modes/asm-mode.js` as an example. Don't forget to
2424
_require_ your mode file in `static/modes/_all.ts`, in alphabetical order
2525
- `language-key` is how your language will be referred internally by the code. In the rest of this document, replace

etc/scripts/build-dist-win.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Add-Content -Path $env:GITHUB_OUTPUT -Value "branch=$BRANCH"
5454
Add-Content -Path $env:GITHUB_OUTPUT -Value "release_name=$RELEASE_NAME"
5555

5656
# Run to make sure we haven't just made something that won't work
57-
node -r esm ./app.js --version --dist
57+
../../node_modules/.bin/ts-node-esm ./app.js --version --dist
5858

5959
Remove-Item -Path "$ROOT/out/dist-bin" -Force -Recurse -ErrorAction Ignore
6060
New-Item -Path $ROOT -Name "out/dist-bin" -Force -ItemType "directory"

etc/scripts/build-dist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ echo "branch=${GITHUB_REF#refs/heads/}" >> "${GITHUB_OUTPUT}"
4545
echo "release_name=${RELEASE_NAME}" >> "${GITHUB_OUTPUT}"
4646

4747
# Run to make sure we haven't just made something that won't work
48-
node -r esm ./app.js --version --dist
48+
../../node_modules/.bin/ts-node-esm ./app.js --version --dist
4949

5050
rm -rf "${ROOT}/out/dist-bin"
5151
mkdir -p "${ROOT}/out/dist-bin"

etc/scripts/docenizers/docenizer-6502.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def parse_descriptions(line, line_num, cpu_type, instructions):
135135

136136

137137
def write_script(filename, instructions):
138-
script = ["import {AssemblyInstructionInfo} from '../base';",
138+
script = ["import {AssemblyInstructionInfo} from '../base.js';",
139139
"",
140140
"export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {",
141141
" if (!opcode) return;",

etc/scripts/docenizers/docenizer-amd64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def main():
354354
print(f"Writing {len(instructions)} instructions")
355355
with open(args.outputpath, 'w') as f:
356356
f.write("""
357-
import {AssemblyInstructionInfo} from '../base';
357+
import {AssemblyInstructionInfo} from '../base.js';
358358
359359
export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {
360360
if (!opcode) return;

etc/scripts/docenizers/docenizer-arm32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def docenizer():
179179
print("Writing {} instructions".format(len(instructions)))
180180
with open(args.outputpath, 'w') as f:
181181
f.write("""
182-
import {AssemblyInstructionInfo} from '../base';
182+
import {AssemblyInstructionInfo} from '../base.js';
183183
184184
export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {
185185
if (!opcode) return;

etc/scripts/docenizers/docenizer-avr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def process_description(desc):
8989
def write_script(filename, instructions):
9090
log_message(f"writing to {filename}...")
9191
with open(filename, "w") as script:
92-
script.write("import {AssemblyInstructionInfo} from '../base';\n")
92+
script.write("import {AssemblyInstructionInfo} from '../base.js';\n")
9393
script.write("\n")
9494
script.write("export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {\n")
9595
script.write(" if (!opcode) return;\n")

etc/scripts/docenizers/docenizer-evm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def main():
126126
print(f"Writing {len(instructions)} instructions")
127127
with open(args.outputpath, 'w') as f:
128128
f.write("""
129-
import {AssemblyInstructionInfo} from '../base';
129+
import {AssemblyInstructionInfo} from '../base.js';
130130
131131
export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {
132132
if (!opcode) return;

etc/scripts/docenizers/docenizer-java.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const main = async () => {
8787
.slice(1) // Drop 1 because the first is the "mne monic"
8888
.map(it => extract($(it), $))
8989
.flat();
90-
console.log('import {AssemblyInstructionInfo} from \'../base\';');
90+
console.log('import {AssemblyInstructionInfo} from \'../base.js\';');
9191
console.log('');
9292
console.log('export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {');
9393
console.log(' if (!opcode) return;');

etc/scripts/docenizers/docenizer-llvm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const $ = cheerio.load(contents);
4949
const names = getInstructionList($.root(), $);
5050
const info = names.map((x) => getInstructionInfo(x, $.root(), $));
5151

52-
console.log('import {AssemblyInstructionInfo} from \'../base\';');
52+
console.log('import {AssemblyInstructionInfo} from \'../base.js\';');
5353
console.log('');
5454
console.log('export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {');
5555
console.log(' if (!opcode) return;');

etc/scripts/docenizers/docenizer-python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def main():
114114
print(f"Writing {len(instructions)} instructions")
115115
with open(args.outputpath, 'w') as f:
116116
f.write("""
117-
import {AssemblyInstructionInfo} from '../base';
117+
import {AssemblyInstructionInfo} from '../base.js';
118118
119119
export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {
120120
if (!opcode) return;

etc/scripts/parsed-pug/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

etc/scripts/parsed_pug_file.js renamed to etc/scripts/parsed-pug/parsed_pug_file.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {execSync} from 'child_process';
2-
import {getHashDigest} from 'loader-utils';
3-
import * as pug from 'pug';
4-
import path from 'path';
1+
const { execSync } = require('child_process');
2+
const { getHashDigest } = require('loader-utils');
3+
const pug = require('pug');
4+
const path = require('path');
55

66
// If you edit either cookies.pug or privacy.pug be aware this will trigger a popup on the users' next visit.
77
// Knowing the last versions here helps us be aware when this happens. If you get an error here and you _haven't_
@@ -20,7 +20,7 @@ function _execGit(command) {
2020
return gitResult.toString();
2121
}
2222

23-
export default function(content) {
23+
module.exports = function(content) {
2424
const filePath = this.resourcePath;
2525
const filename = path.basename(filePath, '.pug');
2626
const options = this.getOptions();

lib/.eslintrc.js renamed to lib/.eslintrc.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ module.exports = {
5454
sourceType: 'module',
5555
ecmaVersion: 'latest',
5656
tsconfigRootDir: __dirname,
57-
project: './tsconfig.json',
57+
project: '../tsconfig.json',
5858
},
5959
rules: {
6060
'@typescript-eslint/no-empty-function': 'off',
6161
'@typescript-eslint/no-unused-vars': 'off',
6262
'@typescript-eslint/no-var-requires': 'error',
6363
'@typescript-eslint/no-explicit-any': 'off', // Too much js code still exists
6464
'@typescript-eslint/ban-ts-comment': 'error',
65+
'import/no-unresolved': 'off',
66+
'node/no-missing-imports': 'off',
6567
// TODO: Disabled for now
6668
//'@typescript-eslint/no-unnecessary-condition': 'error',
6769
//'@typescript-eslint/no-unnecessary-type-assertion': 'error',

lib/asm-docs/_all.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323
// POSSIBILITY OF SUCH DAMAGE.
2424

25-
export {Amd64DocumentationProvider} from './amd64';
26-
export {Arm32DocumentationProvider} from './arm32';
27-
export {AvrDocumentationProvider} from './avr';
28-
export {EvmDocumentationProvider} from './evm';
29-
export {JavaDocumentationProvider} from './java';
30-
export {LLVMDocumentationProvider} from './llvm';
31-
export {Mos6502DocumentationProvider} from './mos6502';
32-
export {PythonDocumentationProvider} from './python';
25+
export {Amd64DocumentationProvider} from './amd64.js';
26+
export {Arm32DocumentationProvider} from './arm32.js';
27+
export {AvrDocumentationProvider} from './avr.js';
28+
export {EvmDocumentationProvider} from './evm.js';
29+
export {JavaDocumentationProvider} from './java.js';
30+
export {LLVMDocumentationProvider} from './llvm.js';
31+
export {Mos6502DocumentationProvider} from './mos6502.js';
32+
export {PythonDocumentationProvider} from './python.js';

lib/asm-docs/amd64.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323
// POSSIBILITY OF SUCH DAMAGE.
2424

25-
import {AssemblyInstructionInfo, BaseAssemblyDocumentationProvider} from './base';
26-
import {getAsmOpcode} from './generated/asm-docs-amd64';
25+
import {AssemblyInstructionInfo, BaseAssemblyDocumentationProvider} from './base.js';
26+
import {getAsmOpcode} from './generated/asm-docs-amd64.js';
2727

2828
export class Amd64DocumentationProvider extends BaseAssemblyDocumentationProvider {
2929
private static readonly ATT_SUFFIX_REMOVER = /^([a-z]+)[blqw]$/i;

0 commit comments

Comments
 (0)