Skip to content

Commit

Permalink
Add support for JavaScript(Node.js)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinesedfan authored and agrawal-d committed Nov 22, 2023
1 parent b0a4ea3 commit fe9e279
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enter testcases.
- Go
- Python
- Java
- JavaScript (Node.js)

## Contributing

Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@
"default": "javac",
"description": "Command used to compile java files."
},
"cph.language.javascript.SubmissionCompiler": {
"type": "string",
"default": "Node.js 12.16.3",
"enum": [
"Node.js 12.16.3"
],
"description": "The compiler chosen in the drop down during Codeforces submission for Node.js"
},
"cph.language.javascript.Command": {
"type": "string",
"default": "node",
"description": "Command used to compile .js files."
},
"cph.general.firstTime": {
"title": "Show welcome message",
"type": "boolean",
Expand All @@ -232,7 +245,7 @@
},
"cph.general.menuChoices": {
"type": "string",
"default": "cpp java python c rust",
"default": "cpp java javascript python c rust",
"description": "Space separated languages, in top to bottom order, shown in menu when a problem is imported via Competitive Companion. Example 'java python' would show java on top, followed by python."
},
"cph.general.useShortCodeForcesName": {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getBinSaveLocation = (srcPath: string): string => {
};

/**
* Get the complete lsit of required arguments to be passed to the compiler.
* Get the complete list of required arguments to be passed to the compiler.
* Loads additional args from preferences if available.
*
* @param language The Language object for the source code
Expand Down
7 changes: 5 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
python: 'py',
rust: 'rs',
java: 'java',
javascript: 'js',
go: 'go',
},
compilers: {
Expand All @@ -20,6 +21,7 @@ export default {
python: 'python',
rust: 'rustc',
java: 'javac',
javascript: 'node',
go: 'go',
},
compilerToId: {
Expand All @@ -33,6 +35,7 @@ export default {
'Clang++17 Diagnostics': 52,
'Java 11.0.6': 60,
'Java 1.8.0_241': 36,
'Node.js 12.16.3': 55,
'PyPy 3.6 (7.2.0)': 41,
'Python 3.7.2': 31,
'PyPy 2.7 (7.2.0)': 40,
Expand All @@ -41,6 +44,6 @@ export default {
'Go 1.19.5': 32,
'Rust 1.66.0 (2021)': 75,
},
supportedExtensions: ['py', 'cpp', 'rs', 'c', 'java', 'go'],
skipCompile: ['py'],
supportedExtensions: ['py', 'cpp', 'rs', 'c', 'java', 'js', 'go'],
skipCompile: ['py', 'js'],
};
8 changes: 8 additions & 0 deletions src/executions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export const runTestCase = (
);
break;
}
case 'javascript': {
process = spawn(
language.compiler,
[binPath, ...language.args],
// spawnOpts, // `spawnOpts.env` will make PATH be empty, then can't find `node` command
);
break;
}
case 'java': {
const args: string[] = [];
if (onlineJudgeEnv) {
Expand Down
7 changes: 7 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export const getRustCommand = (): string =>
getPreference('language.rust.Command') || 'rustc';
export const getJavaCommand = (): string =>
getPreference('language.java.Command') || 'javac';
export const getJavaScriptCommand = (): string =>
getPreference('language.javascript.Command') || 'node';
export const getGoCommand = (): string =>
getPreference('language.go.Command') || 'go';

Expand All @@ -114,6 +116,11 @@ export const getLanguageId = (srcPath: string): number => {
compiler = getPreference('language.java.SubmissionCompiler');
break;
}

case '.js': {
compiler = getPreference('language.javascript.SubmissionCompiler');
break;
}

case '.c': {
compiler = getPreference('language.c.SubmissionCompiler');
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type prefSection =
| 'language.java.Args'
| 'language.java.SubmissionCompiler'
| 'language.java.Command'
| 'language.javascript.SubmissionCompiler'
| 'language.javascript.Command'
| 'language.python.Args'
| 'language.python.SubmissionCompiler'
| 'language.python.Command'
Expand All @@ -37,7 +39,7 @@ export type Language = {
skipCompile: boolean;
};

export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'go';
export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'javascript' | 'go';

export type TestCase = {
input: string;
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getPythonCommand,
getRustCommand,
getJavaCommand,
getJavaScriptCommand,
getGoCommand,
} from './preferences';
import { Language, Problem } from './types';
Expand Down Expand Up @@ -81,6 +82,14 @@ export const getLanguage = (srcPath: string): Language => {
skipCompile: false,
};
}
case 'javascript': {
return {
name: langName,
args: [],
compiler: getJavaScriptCommand(),
skipCompile: true,
};
}
case 'go': {
return {
name: langName,
Expand Down

0 comments on commit fe9e279

Please sign in to comment.