Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
}
}
}
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()}`)
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')
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)
}
}
}
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')
}) => {
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(
async spinAndDownload (dependency: PackagePath) {
await spin(`Downloading ${dependency.toString()}`, yarn.add(dependency))
}
}
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`
}
}