• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

electrode-io / electrode-native / 7581

24 Apr 2026 09:20AM UTC coverage: 56.608% (-11.2%) from 67.856%
7581

push

Azure Pipelines

web-flow
Merge pull request #1924 from electrode-io/npm-security-audit-fix

3600 of 7762 branches covered (46.38%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1659 existing lines in 112 files now uncovered.

9425 of 15247 relevant lines covered (61.82%)

523.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.0
/ern-core/src/BaseMiniApp.ts
1
import { PackagePath } from './PackagePath';
11✔
2
import { readPackageJsonSync } from './packageJsonFileUtils';
11✔
3
import { tagOneLine } from './tagoneline';
11✔
4
import { PackageManager } from './PackageManager';
11✔
5
import * as utils from './utils';
11✔
6
import fs from 'fs';
11✔
7
import path from 'path';
11✔
8
import log from './log';
11✔
9
import _ from 'lodash';
11✔
10
import Platform from './Platform';
11✔
11

12
export class BaseMiniApp {
11✔
13
  public readonly path: string;
14
  public readonly packageJson: any;
15
  public readonly packagePath: PackagePath;
16

17
  constructor({
18
    miniAppPath,
19
    packagePath,
20
  }: {
21
    miniAppPath: string;
22
    packagePath: PackagePath;
23
  }) {
24
    this.path = miniAppPath;
4✔
25

26
    const packageJsonPath = path.join(miniAppPath, 'package.json');
4✔
27
    if (!fs.existsSync(packageJsonPath)) {
4!
28
      throw new Error(`This command should be run at the root of a mini-app`);
×
29
    }
30

31
    const packageJson = readPackageJsonSync(miniAppPath);
4✔
32
    if (packageJson.ernPlatformVersion) {
4!
33
      // TO REMOVE IN ERN 0.5.0
34
      log.warn(`
×
35
=================================================================
36
ernPlatformVersion will be deprecated soon
37
Please replace
38
  "ernPlatformVersion" : "${packageJson.ernPlatformVersion}"
39
with
40
  "ern" : { "version" : "${packageJson.ernPlatformVersion}" }
41
in the package.json of ${packageJson.name} MiniApp
42
=================================================================`);
43
    } else if (!packageJson.ern) {
4!
44
      throw new Error(
×
45
        tagOneLine`No ern section found in ${packageJson.name} package.json. Are you sure this is a MiniApp ?`,
46
      );
47
    }
48

49
    this.packageJson = packageJson;
4✔
50
    this.packagePath = packagePath;
4✔
51
  }
52

53
  get name(): string {
UNCOV
54
    return (
×
55
      this.packageJson.ern?.miniAppName ??
×
56
      this.packageJson.ern?.moduleName ??
×
57
      this.getUnscopedModuleName(this.packageJson.name)
58
    );
59
  }
60

61
  public getUnscopedModuleName(moduleName: string): string {
62
    const npmScopeModuleRe = /(@.*)\/(.*)/;
×
63
    return npmScopeModuleRe.test(moduleName)
×
64
      ? npmScopeModuleRe.exec(moduleName)![2]
×
65
      : moduleName;
66
  }
67

68
  get normalizedName(): string {
UNCOV
69
    return this.name.replace(/-/g, '');
×
70
  }
71

72
  get pascalCaseName(): string {
UNCOV
73
    return `${this.normalizedName
×
74
      .charAt(0)
75
      .toUpperCase()}${this.normalizedName.slice(1)}`;
76
  }
77

78
  get scope(): string | void {
79
    const scopeCapture = /^@(.*)\//.exec(this.packageJson.name);
×
80
    if (scopeCapture) {
×
81
      return scopeCapture[1];
×
82
    }
83
  }
84

85
  get version(): string {
86
    return this.packageJson.version;
×
87
  }
88

89
  get platformVersion(): string {
90
    return this.packageJson.ern?.version ?? this.packageJson.ernPlatformVersion;
×
91
  }
92

93
  get packageDescriptor(): string {
94
    return `${this.packageJson.name}@${this.packageJson.version}`;
×
95
  }
96

97
  get packageManager(): PackageManager {
98
    // Use ern.packageManager value from package.json if set
UNCOV
99
    const ernPackageManager = this.packageJson.ern.packageManager;
×
UNCOV
100
    if (ernPackageManager) {
×
UNCOV
101
      if (ernPackageManager === 'npm') {
×
102
        return PackageManager.npm();
×
UNCOV
103
      } else if (ernPackageManager === 'yarn') {
×
UNCOV
104
        return PackageManager.yarn();
×
105
      } else {
106
        throw new Error(
×
107
          `Invalid ern.packageManager value in package.json : ${ernPackageManager}.
108
Should be either yarn or npm`,
109
        );
110
      }
111
    }
112
    // Otherwise favor yarn if it is installed
113
    else if (Platform.isYarnInstalled()) {
×
114
      return PackageManager.yarn();
×
115
    }
116
    // Finally fallback to npm
117
    else {
118
      return PackageManager.npm();
×
119
    }
120
  }
121

122
  public async isPublishedToNpm(): Promise<boolean> {
123
    return utils.isPublishedToNpm(
×
124
      PackagePath.fromString(
125
        `${this.packageJson.name}@${this.packageJson.version}`,
126
      ),
127
    );
128
  }
129

130
  public getPackageJsonDependencies(): PackagePath[] {
131
    return _.map(this.packageJson.dependencies, (val: string, key: string) =>
×
132
      PackagePath.fromString(`${key}@${val}`),
×
133
    );
134
  }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc