Skip to content

Commit

Permalink
feat: node_modules flag
Browse files Browse the repository at this point in the history
  • Loading branch information
WcaleNieWolny committed Nov 12, 2024
1 parent 8715e35 commit 6131cea
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/bundle/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Options extends OptionsBase {
channel?: string
text?: boolean
packageJson?: string
nodeModules?: string
}

export async function checkCompatibilityCommand(appId: string, options: Options) {
Expand Down Expand Up @@ -46,7 +47,7 @@ export async function checkCompatibilityCommand(appId: string, options: Options)
// const nativePackages = Array.from(hashedLocalDependencies, ([name, value]) => ({ name, version: value.version }))
// await supabase.from('app_versions').update({ native_packages: nativePackages }).eq('id', '9654')

const { finalCompatibility } = await checkCompatibility(supabase, appId, channel, options.packageJson)
const { finalCompatibility } = await checkCompatibility(supabase, appId, channel, options.packageJson, options.nodeModules)

const t = new Table()
t.headers = ['Package', 'Local version', 'Remote version', 'Compatible']
Expand Down
5 changes: 3 additions & 2 deletions src/bundle/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface Options extends OptionsBase {
encryptedChecksum?: string
packageJson?: string
dryRun?: boolean
nodeModules?: string
}

type SupabaseType = Awaited<ReturnType<typeof createSupabaseClient>>
Expand Down Expand Up @@ -148,7 +149,7 @@ async function verifyCompatibility(supabase: SupabaseType, pm: pmType, options:
const {
finalCompatibility: finalCompatibilityWithChannel,
localDependencies: localDependenciesWithChannel,
} = await checkCompatibility(supabase, appid, channel, options.packageJson)
} = await checkCompatibility(supabase, appid, channel, options.packageJson, options.nodeModules)

finalCompatibility = finalCompatibilityWithChannel
localDependencies = localDependenciesWithChannel
Expand Down Expand Up @@ -184,7 +185,7 @@ async function verifyCompatibility(supabase: SupabaseType, pm: pmType, options:
}
else if (!ignoreMetadataCheck) {
log.warn(`Channel ${channel} is new or it's your first upload with compatibility check, it will be ignored this time`)
localDependencies = await getLocalDepenencies(options.packageJson)
localDependencies = await getLocalDepenencies(options.packageJson, options.nodeModules)

if (autoMinUpdateVersion) {
minUpdateVersion = bundle
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ bundle
.option('--package-json <packageJson>', 'A path to package.json. Usefull for monorepos')
.option('--auto-set-bundle', 'Set the bundle in capacitor.config.json')
.option('--dry-run', 'Dry run the upload process')
.option('--node-modules <nodeModules>', 'A path to node_modules. Usefull for monorepos')

bundle
.command('compatibility [appId]')
Expand All @@ -164,6 +165,7 @@ bundle
.option('-c, --channel <channel>', 'channel to check the compatibility with')
.option('--text', 'output text instead of emojis')
.option('--package-json <packageJson>', 'A path to package.json. Usefull for monorepos')
.option('--node-modules <nodeModules>', 'A path to node_modules. Usefull for monorepos')

bundle
.command('delete [bundleId] [appId]')
Expand Down
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ function readDirRecursively(dir: string): string[] {
return files
}

export async function getLocalDepenencies(packageJsonPath: string | undefined) {
export async function getLocalDepenencies(packageJsonPath: string | undefined, nodeModules: string | undefined) {
// const dir = findRoot(cwd())
// const packageJsonPath = join(dir, PACKNAME)

Expand Down Expand Up @@ -1070,11 +1070,11 @@ export async function getLocalDepenencies(packageJsonPath: string | undefined) {
}
}

const nodeModulesPath = join(cwd(), 'node_modules')
const nodeModulesPath = !nodeModules ? join(cwd(), 'node_modules') : nodeModules
if (!existsSync(nodeModulesPath)) {
const pm = findPackageManagerType(dir, 'npm')
const installCmd = findInstallCommand(pm)
log.error(`Missing node_modules folder, please run ${pm} ${installCmd}`)
log.error(`Missing node_modules folder at ${nodeModulesPath}, please run ${pm} ${installCmd}`)
program.error('')
}

Expand Down Expand Up @@ -1221,8 +1221,8 @@ interface Compatibility {
remoteVersion: string | undefined
}

export async function checkCompatibility(supabase: SupabaseClient<Database>, appId: string, channel: string, packageJsonPath: string | undefined) {
const dependenciesObject = await getLocalDepenencies(packageJsonPath)
export async function checkCompatibility(supabase: SupabaseClient<Database>, appId: string, channel: string, packageJsonPath: string | undefined, nodeModules: string | undefined) {
const dependenciesObject = await getLocalDepenencies(packageJsonPath, nodeModules)
const mappedRemoteNativePackages = await getRemoteDepenencies(supabase, appId, channel)

const finalDepenencies: Compatibility[] = dependenciesObject
Expand Down

0 comments on commit 6131cea

Please sign in to comment.