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

electrode-io / electrode-native / 7478

24 Oct 2025 12:58AM UTC coverage: 60.043% (-0.02%) from 60.065%
7478

push

Azure Pipelines

r0h0gg6
Merge pull request #1918 from electrode-io/cuid2-fix-2

Update yarn.lock

3821 of 7725 branches covered (49.46%)

Branch coverage included in aggregate %.

2 of 5 new or added lines in 1 file covered. (40.0%)

18 existing lines in 2 files now uncovered.

9945 of 15202 relevant lines covered (65.42%)

547.46 hits per line

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

69.03
/ern-core/src/Platform.ts
1
import config from './config';
24✔
2
import shell from './shell';
24✔
3
import log from './log';
24✔
4
import { NativePlatform } from './NativePlatform';
5
import { execSync } from 'child_process';
24✔
6
import fs from 'fs-extra';
24✔
7
import path from 'path';
24✔
8
import os from 'os';
24✔
9
import semver from 'semver';
24✔
10

11
const ROOT_DIRECTORY = () =>
24✔
12
  process.env.ERN_HOME || path.join(os.homedir(), '.ern');
178✔
13
// Name of ern local client NPM package
14
const ERN_LOCAL_CLI_PACKAGE = 'ern-local-cli';
24✔
15

16
export default class Platform {
24✔
17
  static get rootDirectory(): string {
18
    return ROOT_DIRECTORY();
178✔
19
  }
20

21
  static get packagesCacheDirectory(): string {
22
    return path.join(this.rootDirectory, 'packages-cache');
25✔
23
  }
24

25
  static get cauldronDirectory(): string {
26
    return path.join(this.rootDirectory, 'cauldron');
4✔
27
  }
28

29
  static get localCauldronsDirectory(): string {
30
    return path.join(this.rootDirectory, 'local-cauldrons');
1✔
31
  }
32

33
  static get masterManifestDirectory(): string {
34
    return path.join(this.rootDirectory, 'ern-master-manifest');
25✔
35
  }
36

37
  static get overrideManifestDirectory(): string {
38
    return path.join(this.rootDirectory, 'ern-override-manifest');
1✔
39
  }
40

41
  static get versionCacheDirectory(): string {
42
    return path.join(this.rootDirectory, 'versions');
25✔
43
  }
44

45
  static get containerPublishersCacheDirectory(): string {
46
    return path.join(this.rootDirectory, 'container-publishers-cache');
16✔
47
  }
48

49
  static get containerTransformersCacheDirectory(): string {
50
    return path.join(this.rootDirectory, 'container-transformers-cache');
16✔
51
  }
52

53
  static get containerGenDirectory(): string {
54
    return path.join(this.rootDirectory, 'containergen');
35✔
55
  }
56

57
  public static getContainerGenOutDirectory(platform: NativePlatform): string {
58
    return path.join(this.containerGenDirectory, 'out', platform);
19✔
59
  }
60

61
  static get latestVersion(): string {
62
    return this.versions.slice(-1)[0];
1✔
63
  }
64

65
  static get currentPlatformVersionPath(): string {
66
    return this.getPlatformVersionPath(this.currentVersion);
8✔
67
  }
68

69
  static get currentVersion(): string {
70
    return config.get('platformVersion', '1000.0.0');
109✔
71
  }
72

73
  public static isPlatformVersionAvailable(version: string) {
74
    return this.versions.includes('' + version);
7✔
75
  }
76

77
  public static getRootPlatformVersionPath(version: string) {
78
    return path.join(this.versionCacheDirectory, version);
14✔
79
  }
80

81
  public static isPlatformVersionInstalled(version: string) {
82
    return fs.pathExistsSync(this.getRootPlatformVersionPath(version));
8✔
83
  }
84

85
  public static getPlatformVersionPath(version: string) {
86
    return version === '1000.0.0'
10✔
87
      ? path.join(this.versionCacheDirectory, version)
10✔
88
      : path.join(this.versionCacheDirectory, version, 'node_modules');
89
  }
90

91
  // Return an array of versions (ex: [1,2,3,4,5])
92
  // representing all the available versions of the platform local cli
93
  public static get versions(): string[] {
94
    return JSON.parse(
10✔
95
      execSync(`npm info ${ERN_LOCAL_CLI_PACKAGE} versions --json`).toString(),
96
    ).sort(semver.compare);
97
  }
98

99
  // Install a given platform version
100
  public static installPlatform(version: string) {
101
    version = this.normalizeVersion(version);
5✔
102
    if (this.isPlatformVersionInstalled(version)) {
5!
103
      return log.warn(
×
104
        `Version ${version} of ern platform is already installed`,
105
      );
106
    }
107

108
    if (!this.isPlatformVersionAvailable(version)) {
5!
109
      throw new Error(`Version ${version} of ern platform is not available`);
×
110
    }
111

112
    const pathToVersion = this.getRootPlatformVersionPath(version);
4✔
113

114
    try {
4✔
115
      shell.mkdir(pathToVersion);
4✔
116
      shell.pushd(pathToVersion);
4✔
117
      if (this.isYarnInstalled()) {
4✔
118
        // Favor yarn if it is installed as it will greatly speed up install
119
        execSync(`yarn init --yes`, { cwd: pathToVersion });
2✔
120
        // Inject resolutions field into package.json
121
        const packageJsonPath = path.join(pathToVersion, 'package.json');
2✔
122
        if (fs.existsSync(packageJsonPath)) {
2!
NEW
123
          const packageJson = JSON.parse(
×
124
            fs.readFileSync(packageJsonPath, 'utf-8'),
125
          );
NEW
126
          packageJson.resolutions = {
×
127
            'path-loader': '1.0.10',
128
          };
NEW
129
          fs.writeFileSync(
×
130
            packageJsonPath,
131
            JSON.stringify(packageJson, null, 2),
132
          );
133
        }
134
        execSync(
2✔
135
          `yarn add ${ERN_LOCAL_CLI_PACKAGE}@${version} --exact --ignore-engines`,
136
          {
137
            cwd: pathToVersion,
138
          },
139
        );
140
      } else {
141
        execSync(`npm init --yes`, { cwd: pathToVersion });
2✔
142
        execSync(`npm install ${ERN_LOCAL_CLI_PACKAGE}@${version} --exact`, {
2✔
143
          cwd: pathToVersion,
144
        });
145
      }
146
    } catch (e) {
UNCOV
147
      log.error(
×
148
        'Something went wrong during installation. Performing clean up.',
149
      );
UNCOV
150
      shell.rm('-rf', pathToVersion);
×
UNCOV
151
      throw e;
×
152
    } finally {
153
      shell.popd();
4✔
154
    }
155
  }
156

157
  // Uninstall a given platform version
158
  public static uninstallPlatform(version: string) {
159
    if (!this.isPlatformVersionInstalled(version)) {
3✔
160
      return log.warn(`Version ${version} of ern platform is not installed`);
1✔
161
    }
162

163
    if (this.currentVersion === version) {
2✔
164
      return log.error(
1✔
165
        `Version ${version} is currently activated. Cannot uninstall`,
166
      );
167
    }
168

169
    shell.rm('-rf', this.getRootPlatformVersionPath(version));
1✔
170
  }
171

172
  // Switch to / activate a given version
173
  // If the version is not installed yet, it will install it beforehand, then
174
  // it will just update the config file with new activated version number
175
  public static switchToVersion(version: string) {
UNCOV
176
    version = this.normalizeVersion(version);
×
UNCOV
177
    if (version === this.currentVersion) {
×
UNCOV
178
      return log.info(`Already using ern v${version}`);
×
179
    }
180

UNCOV
181
    if (!this.isPlatformVersionInstalled(version)) {
×
UNCOV
182
      if (!this.isPlatformVersionAvailable(version)) {
×
UNCOV
183
        throw new Error(`Version ${version} of ern platform is not available`);
×
184
      }
UNCOV
185
      log.info(`ern v${version} is not installed yet. Installing now.`);
×
UNCOV
186
      this.installPlatform(version);
×
187
    }
188

UNCOV
189
    config.set('platformVersion', version);
×
190
    log.info(`ern v${version} is now activated.`);
×
191
  }
192

193
  public static normalizeVersion(version: string) {
194
    let result;
195
    if (version === 'latest') {
7✔
196
      result = Platform.versions.pop()!;
1✔
197
    } else {
198
      result = semver.valid(version);
6✔
199
      if (!result) {
6!
200
        throw new Error(`Cannot normalize invalid version : ${version}`);
×
201
      }
202
    }
203
    return result;
7✔
204
  }
205

206
  public static isYarnInstalled() {
207
    try {
4✔
208
      if (process.platform === 'win32') {
4!
UNCOV
209
        execSync('yarn --version > NUL 2>&1');
×
210
      } else {
211
        execSync('yarn --version 1>/dev/null 2>/dev/null');
4✔
212
      }
213
      return true;
2✔
214
    } catch (e) {
215
      return false;
2✔
216
    }
217
  }
218

219
  public static isCocoaPodsInstalled() {
UNCOV
220
    try {
×
UNCOV
221
      execSync('pod --version 1>/dev/null 2>/dev/null');
×
UNCOV
222
      return true;
×
223
    } catch (e) {
UNCOV
224
      return false;
×
225
    }
226
  }
227
}
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