Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Generating source map from command line? #84

Closed
hultqvist opened this issue Dec 7, 2017 · 4 comments
Closed

Generating source map from command line? #84

hultqvist opened this issue Dec 7, 2017 · 4 comments

Comments

@hultqvist
Copy link

Can a source map be generated when calling google-closure-compiler-js from the command line?

I can pass --createSourceMap true but can't find any map files generated.

So far I've been using the pipe output so I guess the map can't be sent there.
Using --jsOutputFile test.js gives the error: Unhandled flag: jsOutputFile.

@josecanciani
Copy link

josecanciani commented Dec 20, 2017

Could you resolve it? It seems it's not yet an option. Here's a quick script I wrote to compile it, replace your options as needed:

const closureCompiler = require('google-closure-compiler-js');
const fs = require('fs');

if (process.argv.length !== 4) {
    console.log(process.argv);
    console.log("Usage: node " + __filename + " inputFile outputFile");
    process.exit(1);
}

const inputPath = process.argv[2];
const outputPath = process.argv[3];

if (!fs.existsSync(inputPath)) {
    console.log('Input file does not exists: ' + inputPath);
    process.exit(1);
}

const src = fs.readFileSync(inputPath).toString();
const getErrorMessage = (e) => {
    return [
        'Compile error in file: ' + path,
        '- Type: ' + e.type,
        '- Line: ' + e.lineNo,
        '- Char : ' + e.charNo,
        '- Description: ' + e.description
    ].join('\n');
};

/**
* Use same options as defined in https://github.com/highcharts/highcharts/blob/master/gulpfile.js (search for "closureCompiler.compile")
*/
const out = closureCompiler.compile({
    compilationLevel: 'SIMPLE_OPTIMIZATIONS',
    jsCode: [{
        src: src
    }],
    languageIn: 'ES5',
    languageOut: 'ES5',
    createSourceMap: true
});

const errors = out.errors;
if (errors.length) {
    const msg = errors.map((e) => {
        return getErrorMessage(e);
    }).join('\n');
    console.log("Ooops, there was a compiler error\n");
    console.log(msg);
    process.exit(1);
}

fs.writeFileSync(outputPath, out.compiledCode);
fs.writeFileSync(outputPath + '.map', out.sourceMap);
process.exit(0);

@hultqvist
Copy link
Author

I'm afraid not.
Using the closure-compiler from a non javascript runtime I don't have access to those tools.
I ended up using the java version for now.

@martinsik
Copy link

martinsik commented Jan 1, 2018

I just stumbled upon the same problem. I added a PR #87 to fix. You can extract the source map with exorcist for example https://github.com/thlorenz/exorcist.

The jsOutputFile is used only by gulp and is then removed: https://github.com/google/closure-compiler-js/blob/master/lib/gulp.js#L95-L96

@ChadKillingsworth
Copy link
Contributor

The JS version does currently support filesystem operations. I'm looking at adding that, but its not currently an option.

The source map is created, but the consumer is responsible for writing out the file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants