Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}: {
containerVersion?: string
sourceMapOutput?: string
} = {}
) {
if (!descriptor.platform) {
throw new Error(`${descriptor} does not specify a platform`)
}
const platform = descriptor.platform
const outDir = Platform.getContainerGenOutDirectory(platform)
let cauldronContainerNewVersion
let cauldron
try {
cauldron = await getActiveCauldron()
// ================================================================
// Set new Container version
// ================================================================
if (containerVersion) {
cauldronContainerNewVersion = containerVersion
} else {
const detachContainerVersionFromRoot = await cauldron.getConfigForKey(
'detachContainerVersionFromRoot',
descriptor
)
cauldronContainerNewVersion = detachContainerVersionFromRoot
? await cauldron.getContainerVersion(descriptor)
: await cauldron.getTopLevelContainerVersion(descriptor)
if (cauldronContainerNewVersion) {
cauldronContainerNewVersion = semver.inc(
export async function getGitHubApi({
owner,
repo,
}: {
owner: string
repo: string
}) {
if (!process.env.ERN_GITHUB_TOKEN) {
throw new Error('ERN_GITHUB_TOKEN environment variable must be set')
}
const cauldron = await getActiveCauldron()
const gitHubConfig = await cauldron.getGitHubConfig()
const opts: any = {
auth: `token ${process.env.ERN_GITHUB_TOKEN}`,
}
if (gitHubConfig && gitHubConfig.baseUrl) {
opts.baseUrl = gitHubConfig.baseUrl
}
return new GitHubApi({
opts,
owner,
repo,
})
}
containerVersion?: string
forceFullGeneration?: boolean
publishUnmodifiedContainer?: boolean
} = {}
) {
if (!napDescriptor.platform) {
throw new Error(`${napDescriptor} does not specify a platform`)
}
const platform = napDescriptor.platform
let outDir = Platform.getContainerGenOutDirectory(platform)
let cauldronContainerNewVersion
let cauldron
try {
cauldron = await getActiveCauldron()
const currentContainerVersion = await cauldron.getContainerVersion(
napDescriptor
)
if (containerVersion) {
cauldronContainerNewVersion = containerVersion
} else {
const napVersion: CauldronNativeAppVersion = await cauldron.getDescriptor(
napDescriptor
)
cauldronContainerNewVersion = napVersion.detachContainerVersionFromRoot
? await cauldron.getContainerVersion(napDescriptor)
: await cauldron.getTopLevelContainerVersion(napDescriptor)
if (cauldronContainerNewVersion) {
cauldronContainerNewVersion = semver.inc(
static async napDescritorDoesNotExistsInCauldron (
napDescriptor: string,
extraErrorMessage: string = '') {
const cauldron = await getActiveCauldron()
const descriptor = NativeApplicationDescriptor.fromString(napDescriptor)
if (await cauldron.isDescriptorInCauldron(descriptor)) {
throw new Error(`${descriptor.toString()} descriptor exist in Cauldron.\n${extraErrorMessage}`)
}
}
static async dependencyIsInNativeApplicationVersionContainerWithDifferentVersion (
obj: string | Array | void,
napDescriptor: NativeApplicationDescriptor,
extraErrorMessage: string = '') {
if (!obj) return
const cauldron = await getActiveCauldron()
await this.dependencyIsInNativeApplicationVersionContainer(obj, napDescriptor)
const dependenciesStrings = obj instanceof Array ? obj : [ obj ]
for (const dependencyString of dependenciesStrings) {
const dependencyFromCauldron = await cauldron.getContainerNativeDependency(napDescriptor,
PackagePath.fromString(dependencyString).basePath)
if (dependencyFromCauldron && dependencyFromCauldron.version === PackagePath.fromString(dependencyString).version) {
throw new Error(`${PackagePath.fromString(dependencyString).basePath} is already at version ${dependencyFromCauldron.version || 'undefined'} in ${napDescriptor.toString()}.\n${extraErrorMessage}`)
}
}
}
public static async dependencyNotInNativeApplicationVersionContainer(
obj: string | PackagePath | Array | void,
napDescriptor: AppVersionDescriptor,
extraErrorMessage: string = ''
) {
if (!obj) {
return
}
const cauldron = await getActiveCauldron()
const dependencies = coreUtils.coerceToPackagePathArray(obj)
for (const dependency of dependencies) {
if (
await cauldron.isNativeDependencyInContainer(
napDescriptor,
dependency.basePath
)
) {
throw new Error(
`${
dependency.basePath
} dependency exists in ${napDescriptor.toString()}.\n${extraErrorMessage}`
)
}
}
}
}: {
baseComposite?: PackagePath
codePushIsMandatoryRelease?: boolean
codePushRolloutPercentage?: number
description?: string
disableDuplicateReleaseError?: boolean
force?: boolean
pathToYarnLock?: string
sourceMapOutput?: string
targetBinaryVersion?: string
} = {}
) {
let cauldron
try {
const codePushSdk = getCodePushSdk()
cauldron = await getActiveCauldron()
const plugins = await cauldron.getNativeDependencies(napDescriptor)
const compositeGenConfig = await cauldron.getCompositeGeneratorConfig(
napDescriptor
)
baseComposite = baseComposite ?? compositeGenConfig?.baseComposite
await cauldron.beginTransaction()
const codePushPlugin = _.find(
plugins,
p => p.basePath === 'react-native-code-push'
)
if (!codePushPlugin) {
throw new Error('react-native-code-push plugin is not in native app !')
}
const tmpWorkingDir = createTmpDir()
static async miniAppNotInNativeApplicationVersionContainer (
obj: string | Array | void,
napDescriptor: NativeApplicationDescriptor,
extraErrorMessage: string = '') {
if (!obj) return
const cauldron = await getActiveCauldron()
const miniAppsStrings = obj instanceof Array ? obj : [ obj ]
for (const miniAppString of miniAppsStrings) {
const basePathMiniAppString = PackagePath.fromString(miniAppString).basePath
if (await cauldron.isMiniAppInContainer(napDescriptor, basePathMiniAppString)) {
throw new Error(`${basePathMiniAppString} MiniApp exists in ${napDescriptor.toString()}.\n${extraErrorMessage}`)
}
}
}
export async function runCaudronBundleGen(
napDescriptor: AppVersionDescriptor,
{
baseComposite,
compositeDir,
outDir,
resolutions,
}: {
baseComposite?: PackagePath
compositeDir?: string
outDir: string
resolutions?: { [pkg: string]: string }
}
): Promise {
try {
const cauldron = await getActiveCauldron()
const compositeGenConfig = await cauldron.getCompositeGeneratorConfig(
napDescriptor
)
baseComposite =
baseComposite || (compositeGenConfig && compositeGenConfig.baseComposite)
const miniapps = await cauldron.getContainerMiniApps(napDescriptor)
const jsApiImpls = await cauldron.getContainerJsApiImpls(napDescriptor)
const containerGenConfig = await cauldron.getContainerGeneratorConfig(
napDescriptor
)
let pathToYarnLock
if (!containerGenConfig || !containerGenConfig.bypassYarnLock) {
pathToYarnLock = await cauldron.getPathToYarnLock(
napDescriptor,
constants.CONTAINER_YARN_KEY
)
export const commandHandler = async ({ alias }: { alias: string }) => {
cauldronRepositories.activate({ alias })
log.info(`${alias} Cauldron is now activated`)
}