npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@com.xcodeclazz/compile-run-v2

v0.0.18

Published

- This library works as a wrapper over the compilers installed in your system. - It provides APIs to execute programs by spawning child processes. - It has built in supports for types. - It can work with async/await and promises. - It removes the code

Downloads

4

Readme

Compile-run-v2

  • This library works as a wrapper over the compilers installed in your system.
  • It provides APIs to execute programs by spawning child processes.
  • It has built in supports for types.
  • It can work with async/await and promises.
  • It removes the code files generted while executing

Supported Languages

  • Cpp
  • Java
  • Python
  • Node (Javascript)

Prerequisites

The following should be installed on your machine and be added to the path.

| Language | Software | | -------- | -------- | | Cpp | g++ | | Java | jdk | | Python | python | | Node | nodejs |

The library stores the source files for programs in the home directory in a folder named .compile-run-v2. Make sure you have permissions for this folder. It also removes them after it done with execution. So no cron job from you side 😁

Installation

You can install it by using npm like below.

npm install @com.xcodeclazz/compile-run-v2 --save  

Usage

It have 5 modules each for a language containing namely.

const {c, cpp, node, python, java} = require('compile-run-v2');

Each module have 3 functions :-

1. runSource

This enables you to directly execute a source code in a stored in a string. It takes source code as an argument with options and callback as optional arguments.

NOTE: Please provide package com.xcodeclazz; at the top of .java file in case you want to run java programm.


// Class name must be `Main` only. else it won'r work.
let src = `
package com.xcodeclazz;
import java.util.*;
public class Main {
    public static void main(String[] args) {
      System.out.println("Working");
    }
}`;

let code = java.runSource(src, {
  compilationPath: 'javac', // important
  executionPath: 'java', // important
  compileTimeout: 1000,
  stderrLimit: 1000,
  stdoutLimit: 1000,
  timeout: 1000,
  stdin: '10', // important
});

code.then(result => {
    console.log(result); // result
}).catch(err => {
    console.log(err);
});

2. runFile

This enables you to run a file and takes {name: str, content: str, main: bool} as an argument with options and callback as optional arguments. it basically creates the file for you. Don't have to provide file path here.

let src = `
package com.xcodeclazz;
public class Working {
    public static void main(String[] args) {
      System.out.println("Working");
    }
}`;

let code = java.runFile({ name: 'Working.java', content: src, main: true }, {
  compilationPath: 'javac', // important
  executionPath: 'java', // important
  compileTimeout: 1000,
  stderrLimit: 1000,
  stdoutLimit: 1000,
  timeout: 1000,
  stdin: '', // important
});

code.then(result => {
    console.log(result); // result
}).catch(err => {
    console.log(err);
});

3. runFiles

This enables you to run a file and takes [{name: str, content: str, main: bool}] as an argument with options and callback as optional arguments. it basically creates the files for you. Don't have to provide files path here.

let math = `def calc(x):\n\tprint(x + 2)`
let main = `import mymath\n\nmymath.calc(10)`;

let code = python.runFiles([
  { name: 'mymath.py', content: math, main: false }, 
  { name: 'main.py', content: main, main: true }
], {
  compilationPath: '',
  executionPath: 'python', // important
  compileTimeout: 1000,
  stderrLimit: 1000,
  stdoutLimit: 1000,
  timeout: 1000,
  stdin: '', // important
});

code.then(result => {
    console.log(result); // result
}).catch(err => {
    console.log(err);
});
let math = `def calc(x):\n\tprint(x + 2)`
let main = `import mymath\n\nmymath.calc(10)`;

let code = python.runFiles([
  { name: 'mymath.py', content: math, main: false }, 
  { name: 'main.py', content: main, main: true }
], {
  compilationPath: '',
  executionPath: 'python', // important
  compileTimeout: 1000,
  stderrLimit: 1000,
  stdoutLimit: 1000,
  timeout: 1000,
  stdin: '', // important
}, (result) => {
  console.log(result); // result
});

Result

Result is an object with the following keys:-

  1. stdout <string> - stdout of the program execution. For empty stdout an empty string is returned.
  2. stderr <string> - stderr of the program execution, compilation or if public class name is not found in provided source string(In java). For empty stderr empty string is returned.
  3. exitCode <number> - exit code of the program.
  4. cpuUsage <number> - CPU Time as calculated in microseconds.
  5. memoryUsage <number> - Memory Consumed in Bytes.
  6. signal <string|null> - Signal resulting, if any, resulting from the code execution.

Disclaimer :- We don't gaurantee accuracy of cpuUsage and memoryUsage.

Options

API's offer an compulsory options object which has following keys:-

  1. stdin <string> - Input/stdin you want to pass to the program.
  2. timeout <number> - timeout for program execution in milliseconds. Default is 3000 milliseconds.
  3. compileTimeout - timeout during compilation for c, cpp, java in milliseconds. Default is 3000 milliseconds. Would be ignored if passed for node or python
  4. compilationPath - path for the compiler for c, cpp and java i.e for gcc and javac respectively. These paths defined by you if provided else defaults would be used.
  5. executionPath - path for the command to execute the program used in java, python, nodejs i.e for java, python and node respectively. These paths defined by you if provided else defaults would be used.

Prebuild Docker Image

Just run this and start sending you code for compilation. That it! that's the purpose.

Comming Some