@capgo/cli 4.12.1 → 4.12.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "4.12.1",
3
+ "version": "4.12.3-beta.0",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "author": "github.com/riderx",
6
6
  "license": "Apache 2.0",
@@ -61,7 +61,6 @@
61
61
  "ky": "^1.3.0",
62
62
  "logsnag": "1.0.0",
63
63
  "mime": "^4.0.3",
64
- "node-dir": "^0.1.17",
65
64
  "open": "^10.1.0",
66
65
  "prettyjson": "^1.2.5",
67
66
  "semver": "^7.6.2",
@@ -72,7 +71,6 @@
72
71
  "@types/adm-zip": "0.5.5",
73
72
  "@types/mime": "^4.0.0",
74
73
  "@types/node": "^20.14.7",
75
- "@types/node-dir": "^0.0.37",
76
74
  "@types/npmcli__ci-detect": "^2.0.3",
77
75
  "@types/prettyjson": "^0.0.33",
78
76
  "@types/prompt-sync": "^4.2.3",
@@ -343,7 +343,8 @@ async function uploadBundleToCapgoCloud(supabase: SupabaseType, appid: string, b
343
343
 
344
344
  async function setVersionInChannel(
345
345
  supabase: SupabaseType,
346
- options: Options,
346
+ apikey: string,
347
+ displayBundleUrl: boolean,
347
348
  bundle: string,
348
349
  channel: string,
349
350
  userId: string,
@@ -353,7 +354,7 @@ async function setVersionInChannel(
353
354
  permissions: OrganizationPerm,
354
355
  ) {
355
356
  const { data: versionId } = await supabase
356
- .rpc('get_app_versions', { apikey: options.apikey, name_version: bundle, appid })
357
+ .rpc('get_app_versions', { apikey, name_version: bundle, appid })
357
358
  .single()
358
359
 
359
360
  if (versionId && hasOrganizationPerm(permissions, OrganizationPerm.write)) {
@@ -375,7 +376,7 @@ async function setVersionInChannel(
375
376
  else if (data?.id)
376
377
  p.log.info(`Link device to this bundle to try it: ${bundleUrl}`)
377
378
 
378
- if (options.bundleUrl) {
379
+ if (displayBundleUrl) {
379
380
  p.log.info(`Bundle url: ${bundleUrl}`)
380
381
  }
381
382
  else if (!versionId) {
@@ -436,7 +437,7 @@ export async function uploadBundle(preAppid: string, options: Options, shouldExi
436
437
 
437
438
  // Now if it does exist we will fetch the org id
438
439
  const orgId = await getOrganizationId(supabase, appid)
439
- await checkPlanValid(supabase, orgId, options.apikey, appid, true)
440
+ await checkPlanValid(supabase, orgId, apikey, appid, true)
440
441
  await checkTrial(supabase, orgId, localConfig)
441
442
  const { nativePackages, minUpdateVersion } = await verifyCompatibility(supabase, pm, options, channel, appid, bundle)
442
443
  await checkVersionExists(supabase, appid, bundle)
@@ -488,7 +489,7 @@ export async function uploadBundle(preAppid: string, options: Options, shouldExi
488
489
  }
489
490
  }
490
491
 
491
- await setVersionInChannel(supabase, options, bundle, channel, userId, orgId, appid, localConfig, permissions)
492
+ await setVersionInChannel(supabase, apikey, !!options.bundleUrl, bundle, channel, userId, orgId, appid, localConfig, permissions)
492
493
 
493
494
  await snag.track({
494
495
  channel: 'app',
@@ -507,9 +508,9 @@ export async function uploadBundle(preAppid: string, options: Options, shouldExi
507
508
  return true
508
509
  }
509
510
 
510
- export async function uploadCommand(apikey: string, options: Options) {
511
+ export async function uploadCommand(appid: string, options: Options) {
511
512
  try {
512
- await uploadBundle(apikey, options, true)
513
+ await uploadBundle(appid, options, true)
513
514
  }
514
515
  catch (error) {
515
516
  p.log.error(formatError(error))
@@ -517,11 +518,11 @@ export async function uploadCommand(apikey: string, options: Options) {
517
518
  }
518
519
  }
519
520
 
520
- export async function uploadDeprecatedCommand(apikey: string, options: Options) {
521
+ export async function uploadDeprecatedCommand(appid: string, options: Options) {
521
522
  const pm = getPMAndCommand()
522
523
  p.log.warn(`⚠️ This command is deprecated, use "${pm.runner} @capgo/cli bundle upload" instead ⚠️`)
523
524
  try {
524
- await uploadBundle(apikey, options, true)
525
+ await uploadBundle(appid, options, true)
525
526
  }
526
527
  catch (error) {
527
528
  p.log.error(formatError(error))
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
1
+ import { existsSync, readFileSync, readdir, readdirSync, statSync } from 'node:fs'
2
2
  import { homedir, platform as osPlatform } from 'node:os'
3
3
  import { join, resolve, sep } from 'node:path'
4
4
  import process from 'node:process'
@@ -11,7 +11,6 @@ import prettyjson from 'prettyjson'
11
11
  import { LogSnag } from 'logsnag'
12
12
  import * as p from '@clack/prompts'
13
13
  import ky from 'ky'
14
- import { promiseFiles } from 'node-dir'
15
14
  import { findRootSync } from '@manypkg/find-root'
16
15
  import type { InstallCommand, PackageManagerRunner, PackageManagerType } from '@capgo/find-package-manager'
17
16
  import { findInstallCommand, findPackageManagerRunner, findPackageManagerType } from '@capgo/find-package-manager'
@@ -840,16 +839,33 @@ export function getPMAndCommand() {
840
839
  return { pm, command: pmCommand, installCommand: `${pm} ${pmCommand}`, runner: pmRunner }
841
840
  }
842
841
 
842
+ function readDirRecursively(dir: string): string[] {
843
+ const entries = readdirSync(dir, { withFileTypes: true })
844
+ const files = entries.flatMap((entry) => {
845
+ const fullPath = join(dir, entry.name)
846
+ if (entry.isDirectory()) {
847
+ return readDirRecursively(fullPath)
848
+ }
849
+ else {
850
+ // Use relative path to avoid issues with long paths on Windows
851
+ return fullPath.split(`node_modules${sep}`)[1] || fullPath
852
+ }
853
+ })
854
+ return files
855
+ }
856
+
843
857
  export async function getLocalDepenencies() {
844
858
  const dir = findRootSync(process.cwd())
845
- if (!existsSync('./package.json')) {
859
+ const packageJsonPath = join(process.cwd(), 'package.json')
860
+
861
+ if (!existsSync(packageJsonPath)) {
846
862
  p.log.error('Missing package.json, you need to be in a capacitor project')
847
863
  program.error('')
848
864
  }
849
865
 
850
866
  let packageJson
851
867
  try {
852
- packageJson = JSON.parse(readFileSync('./package.json', 'utf8'))
868
+ packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
853
869
  }
854
870
  catch (err) {
855
871
  p.log.error('Invalid package.json, JSON parsing failed')
@@ -870,7 +886,8 @@ export async function getLocalDepenencies() {
870
886
  }
871
887
  }
872
888
 
873
- if (!existsSync('./node_modules/')) {
889
+ const nodeModulesPath = join(process.cwd(), 'node_modules')
890
+ if (!existsSync(nodeModulesPath)) {
874
891
  const pm = findPackageManagerType(dir.rootDir, 'npm')
875
892
  const installCmd = findInstallCommand(pm)
876
893
  p.log.error(`Missing node_modules folder, please run ${pm} ${installCmd}`)
@@ -880,9 +897,9 @@ export async function getLocalDepenencies() {
880
897
  let anyInvalid = false
881
898
 
882
899
  const dependenciesObject = await Promise.all(Object.entries(dependencies as Record<string, string>)
883
-
884
900
  .map(async ([key, value]) => {
885
- const dependencyFolderExists = existsSync(`./node_modules/${key}`)
901
+ const dependencyFolderPath = join(nodeModulesPath, key)
902
+ const dependencyFolderExists = existsSync(dependencyFolderPath)
886
903
 
887
904
  if (!dependencyFolderExists) {
888
905
  anyInvalid = true
@@ -893,16 +910,15 @@ export async function getLocalDepenencies() {
893
910
  }
894
911
 
895
912
  let hasNativeFiles = false
896
- await promiseFiles(`./node_modules/${key}`)
897
- .then((files) => {
898
- if (files.find(fileName => nativeFileRegex.test(fileName)))
899
- hasNativeFiles = true
900
- })
901
- .catch((error) => {
902
- p.log.error(`Error reading node_modulses files for ${key} package`)
903
- console.error(error)
904
- program.error('')
905
- })
913
+ try {
914
+ const files = readDirRecursively(dependencyFolderPath)
915
+ hasNativeFiles = files.some(fileName => nativeFileRegex.test(fileName))
916
+ }
917
+ catch (error) {
918
+ p.log.error(`Error reading node_modules files for ${key} package`)
919
+ console.error(error)
920
+ program.error('')
921
+ }
906
922
 
907
923
  return {
908
924
  name: key,