How to use the ern-core.yarn.add function in ern-core

To help you get started, we’ve selected a few ern-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electrode-io / electrode-native / ern-container-gen / src / utils.ts View on Github external
path.join(outDir, 'package.json'),
      JSON.stringify(compositePackageJson, null, 2),
      'utf8'
    )

    // Now that the composite package.json is similar to the one used to generated yarn.lock
    // we can run yarn install to get back to the exact same dependency graph as the previously
    // generated composite
    await yarn.install()
    await runYarnUsingMiniAppDeltas(miniAppsDeltas)
  } else {
    // No yarn.lock path was provided, just add miniapps one by one
    log.debug('[generateMiniAppsComposite] no yarn lock provided')
    await yarn.init()
    for (const miniappPath of miniappsPaths) {
      await yarn.add(miniappPath)
    }

    const packageJsonPath = path.join(outDir, 'package.json')
    const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
    packageJson.scripts = {
      start: 'node node_modules/react-native/local-cli/cli.js start',
    }
    fs.writeFileSync(
      packageJsonPath,
      JSON.stringify(packageJson, null, 2),
      'utf8'
    )
  }

  for (const extraJsDependency of extraJsDependencies) {
    await yarn.add(extraJsDependency)
github electrode-io / electrode-native / ern-container-gen / src / utils.js View on Github external
export async function runYarnUsingMiniAppDeltas (miniAppsDeltas: Object) {
  // Now we can `yarn add` new MiniApps and `yarn upgrade` the ones that have new versions
  if (miniAppsDeltas.new) {
    for (const m of miniAppsDeltas.new) {
      log.debug(`Adding new MiniApp ${m.toString()}`)
      await yarn.add(m)
    }
  }

  if (miniAppsDeltas.upgraded) {
    for (const m of miniAppsDeltas.upgraded) {
      log.debug(`Upgrading MiniApp ${m.toString()}`)
      await yarn.upgrade(m)
    }
  }
}
github electrode-io / electrode-native / ern-composite-gen / src / miniAppsDeltasUtils.ts View on Github external
export async function runYarnUsingMiniAppDeltas(
  miniAppsDeltas: MiniAppsDeltas
) {
  //
  // Now we can `yarn add` for new MiniApps
  if (miniAppsDeltas.new) {
    for (const newMiniAppVersion of miniAppsDeltas.new) {
      log.debug(`Adding new MiniApp ${newMiniAppVersion.toString()}`)
      await kax
        .task(`Adding ${newMiniAppVersion}`)
        .run(yarn.add(newMiniAppVersion))
    }
  }

  // !!! TODO !!!
  // We run `yarn upgrade` here but that might not be the safest solution
  // as `yarn upgrade` will run a full upgrade of all dependencies of the
  // MiniApp, transitively, which might not be desired.
  // Indeed if we want to be as close to the yarn.lock as possible, running
  // `yarn add` for upgraded dependencies will only upgrade the MiniApp
  // version but will leave its dependency graph untouched, based
  // on yarn.lock.
  // It might be better to given more control to the MiniApp team on
  // dependency control.
  if (miniAppsDeltas.upgraded) {
    for (const upgradedMiniAppVersion of miniAppsDeltas.upgraded) {
      log.debug(`Upgrading MiniApp ${upgradedMiniAppVersion.toString()}`)
github electrode-io / electrode-native / ern-container-gen / src / utils.ts View on Github external
for (const extraJsDependency of extraJsDependencies) {
    await yarn.add(extraJsDependency)
  }

  let entryIndexJsContent = ''

  compositePackageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
  for (const dependency of Object.keys(compositePackageJson.dependencies)) {
    entryIndexJsContent += `import '${dependency}'\n`
  }

  if (jsApiImplDependencies) {
    log.debug('Adding imports for JS API implementations.')
    for (const apiImpl of jsApiImplDependencies) {
      await yarn.add(apiImpl)
      entryIndexJsContent += `import '${apiImpl.basePath}'\n`
    }
  }

  await runAfterJsCompositeGenerationScript(outDir)

  log.debug('Removing .babelrc files from all modules')
  shell.rm('-rf', path.join('node_modules', '**', '.babelrc'))

  log.debug('Creating top level composite .babelrc')
  const compositeBabelRc = { presets: ['react-native'], plugins: [] }

  // Ugly hacky way of handling module-resolver babel plugin
  // At least it has some guarantees to make it safer but its just a temporary
  // solution until we figure out a more proper way of handling this plugin
  log.debug('Taking care of potential Babel plugins used by MiniApps')
github electrode-io / electrode-native / ern-container-gen / src / utils.ts View on Github external
export async function runYarnUsingMiniAppDeltas(miniAppsDeltas: any) {
  // Now we can `yarn add` new MiniApps and `yarn upgrade` the ones that have new versions
  if (miniAppsDeltas.new) {
    for (const m of miniAppsDeltas.new) {
      log.debug(`Adding new MiniApp ${m.toString()}`)
      await yarn.add(m)
    }
  }

  if (miniAppsDeltas.upgraded) {
    for (const m of miniAppsDeltas.upgraded) {
      log.debug(`Upgrading MiniApp ${m.toString()}`)
      await yarn.upgrade(m)
    }
  }
}
github electrode-io / electrode-native / ern-container-gen / src / utils.js View on Github external
for (const extraJsDependency of extraJsDependencies) {
    await yarn.add(extraJsDependency)
  }

  let entryIndexJsContent = ''

  compositePackageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
  for (const dependency of Object.keys(compositePackageJson.dependencies)) {
    entryIndexJsContent += `import '${dependency}'\n`
  }

  if (jsApiImplDependencies) {
    log.debug('Adding imports for JS API implementations.')
    for (const apiImpl of jsApiImplDependencies) {
      await yarn.add(apiImpl)
      entryIndexJsContent += `import '${apiImpl.basePath}'\n`
    }
  }

  await runAfterJsCompositeGenerationScript(outDir)

  log.debug('Removing .babelrc files from all modules')
  shell.rm('-rf', path.join('node_modules', '**', '.babelrc'))

  log.debug('Creating top level composite .babelrc')
  const compositeBabelRc = { 'presets': ['react-native'], 'plugins': [] }

  // Ugly hacky way of handling module-resolver babel plugin
  // At least it has some guarantees to make it safer but its just a temporary
  // solution until we figure out a more proper way of handling this plugin
  log.debug('Taking care of potential Babel plugins used by MiniApps')
github electrode-io / electrode-native / ern-local-cli / src / commands / list / dependencies.ts View on Github external
}) => {
  if (manifestId) {
    await logErrorAndExitIfNotSatisfied({
      manifestIdExists: {
        id: manifestId,
      },
    })
  }

  let pathToModule = process.cwd()
  if (module) {
    pathToModule = createTmpDir()
    shell.pushd(pathToModule)
    try {
      await yarn.init()
      await yarn.add(PackagePath.fromString(module))
    } finally {
      shell.popd()
    }
  }
  const dependencies = await findNativeDependencies(
    path.join(pathToModule, 'node_modules'),
    { manifestId }
  )

  if (json) {
    process.stdout.write(JSON.stringify(dependencies))
  } else {
    console.log(chalk.bold.yellow('Native dependencies :'))
    logDependencies(dependencies.apis, 'APIs')
    logDependencies(dependencies.nativeApisImpl, 'Native API Implementations')
    logDependencies(
github electrode-io / electrode-native / ern-api-impl-gen / src / generators / ApiImplGen.js View on Github external
async spinAndDownload (dependency: PackagePath) {
    await spin(`Downloading ${dependency.toString()}`, yarn.add(dependency))
  }
github electrode-io / electrode-native / ern-container-gen / src / utils.ts View on Github external
}

    const packageJsonPath = path.join(outDir, 'package.json')
    const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
    packageJson.scripts = {
      start: 'node node_modules/react-native/local-cli/cli.js start',
    }
    fs.writeFileSync(
      packageJsonPath,
      JSON.stringify(packageJson, null, 2),
      'utf8'
    )
  }

  for (const extraJsDependency of extraJsDependencies) {
    await yarn.add(extraJsDependency)
  }

  let entryIndexJsContent = ''

  compositePackageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
  for (const dependency of Object.keys(compositePackageJson.dependencies)) {
    entryIndexJsContent += `import '${dependency}'\n`
  }

  if (jsApiImplDependencies) {
    log.debug('Adding imports for JS API implementations.')
    for (const apiImpl of jsApiImplDependencies) {
      await yarn.add(apiImpl)
      entryIndexJsContent += `import '${apiImpl.basePath}'\n`
    }
  }