Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function publishContainer(conf: ContainerPublisherConfig) {
// Duplicate the directory containing generated Container to a temporary
// directory, and pass this temporary directory to the publisher.
// This is done because Container generation and publication are
// clearly distinct (separation of concerns), we don't want the publisher
// to update the Container generated code for its publication needs.
// It also ensures that this function can be called multiple times
// with different publishers for the same Container (idempotent).
// Otherwise, if publication changes were made to the original Container
// path, it would be much harder to use a different publisher for the
// same Container.
const publicationWorkingDir = createTmpDir()
shell.cp(
'-Rf',
path.join(conf.containerPath, '{.*,*}'),
publicationWorkingDir
)
conf.containerPath = publicationWorkingDir
conf.ernVersion = Platform.currentVersion
const publisher = await getPublisher(conf.publisher)
if (!publisher.platforms.includes(conf.platform)) {
throw new Error(
`The ${publisher.name} publisher does not support publication of ${
conf.platform
} Containers`
)
}: {
module?: string
manifestId?: string
json?: boolean
}) => {
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 {
public async injectJavaScriptCoreEngine(config: ContainerGeneratorConfig) {
const jscVersion =
(config.androidConfig && config.androidConfig.jscVersion) ||
android.DEFAULT_JSC_VERSION
const jscVariant =
(config.androidConfig && config.androidConfig.jscVariant) ||
android.DEFAULT_JSC_VARIANT
const workingDir = createTmpDir()
try {
shell.pushd(workingDir)
await yarn.init()
await yarn.add(PackagePath.fromString(`jsc-android@${jscVersion}.0.0`))
const jscVersionPath = path.resolve(
`./node_modules/jsc-android/dist/org/webkit/${jscVariant}/r${jscVersion}`
)
const jscAARPath = path.join(
jscVersionPath,
`${jscVariant}-r${jscVersion}.aar`
)
return new Promise((resolve, reject) => {
const unzipper = new DecompressZip(jscAARPath)
const unzipOutDir = createTmpDir()
const containerJniLibsPath = path.join(
config.outDir,
public async injectHermesEngine(config: ContainerGeneratorConfig) {
const hermesVersion =
(config.androidConfig && config.androidConfig.hermesVersion) ||
android.DEFAULT_HERMES_VERSION
const workingDir = createTmpDir()
try {
shell.pushd(workingDir)
await yarn.init()
await yarn.add(PackagePath.fromString(`hermes-engine@${hermesVersion}`))
const hermesAarPath = path.resolve(
`./node_modules/hermes-engine/android/hermes-release.aar`
)
return new Promise((resolve, reject) => {
const unzipper = new DecompressZip(hermesAarPath)
const unzipOutDir = createTmpDir()
const containerJniLibsPath = path.join(
config.outDir,
'lib/src/main/jniLibs'
)
const unzippedJniPath = path.join(unzipOutDir, 'jni')
unzipper.on('error', err => reject(err))
napDescriptor,
constants.CONTAINER_YARN_KEY
)
} else {
log.debug(
'Bypassing yarn.lock usage as bypassYarnLock flag is set in Cauldron config'
)
}
if (!napDescriptor.platform) {
throw new Error(`${napDescriptor} does not specify a platform`)
}
return kax.task('Bundling MiniApps').run(
bundleMiniApps(
miniapps,
compositeDir || createTmpDir(),
outDir,
napDescriptor.platform,
{
baseComposite,
jsApiImplDependencies: jsApiImpls,
pathToYarnLock: pathToYarnLock || undefined,
resolutions,
}
)
)
} catch (e) {
log.error(`runCauldronBundleGen failed: ${e}`)
throw e
}
}
public async publish({
containerPath,
containerVersion,
url,
}: {
containerPath: string
containerVersion: string
url?: string
}) {
const workingGitDir = createTmpDir()
if (!url) {
throw new Error('url is required')
}
try {
shell.pushd(workingGitDir)
const git = gitCli()
log.debug(`Cloning git repository(${url}) to ${workingGitDir}`)
await gitCli().cloneAsync(url, '.')
shell.rm('-rf', `${workingGitDir}/*`)
shell.cp('-Rf', path.join(containerPath, '{.*,*}'), workingGitDir)
await git.addAsync('./*')
await git.commitAsync(`Container v${containerVersion}`)
await git.tagAsync([`v${containerVersion}`])
await git.pushAsync('origin', 'master')
const compositeDir = createTmpDir()
await kax.task('Generating Composite').run(
generateComposite({
baseComposite,
extraJsDependencies,
jsApiImplDependencies: jsApiImpls,
miniApps: miniapps!,
outDir: compositeDir,
pathToYarnLock,
resolutions,
})
)
for (const curPlatform of platforms) {
const outDir = createTmpDir()
const bundlePath = path.join(outDir, 'index.bundle')
const sourceMapPath = path.join(outDir, 'index.map')
await kax.task(`Bundling MiniApps for ${curPlatform}`).run(
bundleMiniAppsFromComposite({
bundleOutput: bundlePath,
compositeDir,
dev: !prod,
outDir,
platform: curPlatform,
sourceMapOutput: path.join(outDir, 'index.map'),
})
)
const bundleId = await kax
.task(`Uploading ${curPlatform} bundle`)
.run(
engine.upload({ bundlePath, platform: curPlatform, sourceMapPath })
)
} else {
log.debug(
'Bypassing yarn.lock usage as bypassYarnLock flag is set in config'
)
}
const compositeGenConfig = await cauldron.getCompositeGeneratorConfig(
descriptor
)
baseComposite =
baseComposite ||
(compositeGenConfig && compositeGenConfig.baseComposite)
resolutions = compositeGenConfig && compositeGenConfig.resolutions
}
const compositeDir = createTmpDir()
await kax.task('Generating Composite').run(
generateComposite({
baseComposite,
extraJsDependencies,
jsApiImplDependencies: jsApiImpls,
miniApps: miniapps!,
outDir: compositeDir,
pathToYarnLock,
resolutions,
})
)
for (const curPlatform of platforms) {
const outDir = createTmpDir()
const bundlePath = path.join(outDir, 'index.bundle')
const sourceMapPath = path.join(outDir, 'index.map')
constructor({ storePath }: { storePath?: string } = {}) {
this.storePath = storePath || createTmpDir()
this.transactionPending = false
}
return new Promise((resolve, reject) => {
const unzipper = new DecompressZip(jscAARPath)
const unzipOutDir = createTmpDir()
const containerJniLibsPath = path.join(
config.outDir,
'lib/src/main/jniLibs'
)
const unzippedJniPath = path.join(unzipOutDir, 'jni')
unzipper.on('error', err => reject(err))
unzipper.on('extract', () => {
shell.cp('-Rf', unzippedJniPath, containerJniLibsPath)
resolve()
})
unzipper.extract({ path: unzipOutDir })
})
} finally {