electron-userland / electron-compilers

DEPRECATED: Compiler implementations for electron-compile
35 stars 55 forks source link

Different cache folder for different envs #76

Closed fasterthanlime closed 7 years ago

fasterthanlime commented 7 years ago

This issue applies both to electron-compile and electron-compilers, sorry

Reading through a bunch of code right now to find out if a different $TEMP/compileCache_${hash} will get generated if NODE_ENV changes, and.. it doesn't like it does?

Here's the default cache directory code:

export function calculateDefaultCompileCacheDirectory() {
  let tmpDir = process.env.TEMP || process.env.TMPDIR || '/tmp';
  let hash = require('crypto').createHash('md5').update(process.execPath).digest('hex');

  let cacheDir = path.join(tmpDir, `compileCache_${hash}`);
  mkdirp.sync(cacheDir);

  d(`Using default cache directory: ${cacheDir}`);
  return cacheDir;
}

The problem is:

You can probably reproduce the problem easily if you use electron-compile with a .babelrc like:

{
  "env": {
    "production": {
      "presets": ["es2016-node5", "react"],
      "sourceMaps": false
    },
    "development": {
      "presets": ["es2016-node5", "react"],
      "sourceMaps": "inline"
    }
  }
}

run it once with NODE_ENV=production, then again with NODE_ENV=development, I'm 80% confident you'd end up not seeing sourceMaps still.


Here's my proposal for electron-compile:

Tangentially, here's what I've got planned for electron-compilers:

Let me know if any of that sounds bad @paulcbetts & others so I can adjust plans accordingly!

fasterthanlime commented 7 years ago

Additional notes on istanbul@0.4.5 being deprecated: it only became clear to me after spending a day investigating, but: the acorn-based istanbul is pretty dead.

The new istanbul is heavily marketed as nyc (its command-line interface), it's pretty much everything https://istanbul.js.org/ talks about - but there's actual libs underneath, conveniently stashed in this monorepo.

The new instrumenter is based on babel, which makes a bunch of sense:

Quick size comparison:

Legacy istanbul

istanbul-only ツ npm i --save istanbul

+ istanbul@0.4.5
added 60 packages in 5.097s
 istanbul-only ツ du -ch node_modules | tail -1
9.4M    total

babel-plugin-istanbul

babel-plugin ツ npm i --save babel-plugin-istanbul

+ babel-plugin-istanbul@4.1.4
added 107 packages in 8.772s
 babel-plugin ツ du -ch node_modules | tail -1
18M     total

N.B: size of the instrument+coverage+babel plug-in only:

babel-plugin ツ du -ch node_modules/istanbul-lib-* node_modules/babel-plugin-istanbul | tail -1
164K    total

TL;DR istanbul is now babel-based, it kinda blows if you're not already using babel, but I don't think electron-compile{,rs} should keep using istanbul@0.4.5

fasterthanlime commented 7 years ago

All done in:

Works great for me (typescript+babel, inline source maps):

coverage-demo

fasterthanlime commented 7 years ago

Closing in favor of both PRs.