<commit_before>'use strict'

const CompileCache = require('../../src/compile-cache')
const fs = require('fs-extra')
const glob = require('glob')
const path = require('path')

const CONFIG = require('../config')
const backupNodeModules = require('./backup-node-modules')
const runApmInstall = require('./run-apm-install')

require('colors')


module.exports = function () {
  console.log(`Transpiling packages with custom transpiler configurations in ${CONFIG.intermediateAppPath}`)
  for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) {
    const rootPackagePath = path.join(CONFIG.repositoryRootPath, 'node_modules', packageName)
    const intermediatePackagePath = path.join(CONFIG.intermediateAppPath, 'node_modules', packageName)

    const metadataPath = path.join(intermediatePackagePath, 'package.json')
    const metadata = require(metadataPath)

    if (metadata.atomTranspilers) {
      console.log(' transpiling for package '.cyan + packageName.cyan)
      const rootPackageBackup = backupNodeModules(rootPackagePath)
      const intermediatePackageBackup = backupNodeModules(intermediatePackagePath)

      // Run `apm install` in the *root* pacakge's path, so we get devDeps w/o apm's weird caching
      // Then copy this folder into the intermediate package's path so we can run the transpilation in-line.
      runApmInstall(rootPackagePath)
      if (fs.existsSync(intermediatePackageBackup.nodeModulesPath)) {
        fs.removeSync(intermediatePackageBackup.nodeModulesPath)
      }
      fs.copySync(rootPackageBackup.nodeModulesPath, intermediatePackageBackup.nodeModulesPath)

      CompileCache.addTranspilerConfigForPath(intermediatePackagePath, metadata.name, metadata, metadata.atomTranspilers)
      for (let config of metadata.atomTranspilers) {
        const pathsToCompile = glob.sync(path.join(intermediatePackagePath, config.glob), {nodir: true})
        pathsToCompile.forEach(transpilePath)
      }

      CompileCache.removeTranspilerConfigForPath(intermediatePackagePath)
      rootPackageBackup.restore()
      intermediatePackageBackup.restore()
    }
  }
}

function transpilePath (path) {
  fs.writeFileSync(path, CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath))
}
<commit_msg>Remove `atomTransilers` from package.json after transpiling in-place<commit_after>'use strict'

const CompileCache = require('../../src/compile-cache')
const fs = require('fs-extra')
const glob = require('glob')
const path = require('path')

const CONFIG = require('../config')
const backupNodeModules = require('./backup-node-modules')
const runApmInstall = require('./run-apm-install')

require('colors')


module.exports = function () {
  console.log(`Transpiling packages with custom transpiler configurations in ${CONFIG.intermediateAppPath}`)
  for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) {
    const rootPackagePath = path.join(CONFIG.repositoryRootPath, 'node_modules', packageName)
    const intermediatePackagePath = path.join(CONFIG.intermediateAppPath, 'node_modules', packageName)

    const metadataPath = path.join(intermediatePackagePath, 'package.json')
    const metadata = require(metadataPath)

    if (metadata.atomTranspilers) {
      console.log(' transpiling for package '.cyan + packageName.cyan)
      const rootPackageBackup = backupNodeModules(rootPackagePath)
      const intermediatePackageBackup = backupNodeModules(intermediatePackagePath)

      // Run `apm install` in the *root* pacakge's path, so we get devDeps w/o apm's weird caching
      // Then copy this folder into the intermediate package's path so we can run the transpilation in-line.
      runApmInstall(rootPackagePath)
      if (fs.existsSync(intermediatePackageBackup.nodeModulesPath)) {
        fs.removeSync(intermediatePackageBackup.nodeModulesPath)
      }
      fs.copySync(rootPackageBackup.nodeModulesPath, intermediatePackageBackup.nodeModulesPath)

      CompileCache.addTranspilerConfigForPath(intermediatePackagePath, metadata.name, metadata, metadata.atomTranspilers)
      for (let config of metadata.atomTranspilers) {
        const pathsToCompile = glob.sync(path.join(intermediatePackagePath, config.glob), {nodir: true})
        pathsToCompile.forEach(transpilePath)
      }

      // Now that we've transpiled everything in-place, we no longer want Atom to try to transpile
      // the same files when they're being required.
      delete metadata.atomTranspilers
      fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, '  '), 'utf8')

      CompileCache.removeTranspilerConfigForPath(intermediatePackagePath)
      rootPackageBackup.restore()
      intermediatePackageBackup.restore()
    }
  }
}

function transpilePath (path) {
  fs.writeFileSync(path, CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath))
}

{'fraction_non_alphanumeric': 0.09766190771777364, 'fraction_numerical': 0.0002069108214359611, 'mean_word_length': 4.713947990543735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1563049', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1331, 'n_words': 300}