-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathpackedTarballUtils.ts
More file actions
60 lines (51 loc) · 1.94 KB
/
packedTarballUtils.ts
File metadata and controls
60 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as path from 'path';
import * as fs from 'fs';
import { sync as globSync } from 'glob';
const E2E_TESTS_ROOT = path.resolve(__dirname, '..');
const REPOSITORY_ROOT = path.resolve(E2E_TESTS_ROOT, '../..');
/**
* Workspace @sentry and @sentry-internal packages that have a built tarball for the E2E version.
* @returns The names of the published Sentry tarball packages.
*/
export function getPublishedSentryTarballPackageNames(): string[] {
const version = getE2eTestsPackageVersion();
const names: string[] = [];
for (const packageJsonPath of globSync('packages/*/package.json', {
cwd: REPOSITORY_ROOT,
absolute: true,
})) {
const pkg = readJson<{ name?: string }>(packageJsonPath);
const name = pkg.name;
if (!name || (!name.startsWith('@sentry/') && !name.startsWith('@sentry-internal/'))) {
continue;
}
const packageDir = path.dirname(packageJsonPath);
const tarball = path.join(packageDir, versionedTarballFilename(name, version));
if (fs.existsSync(tarball)) {
names.push(name);
}
}
return names.sort();
}
/** Stable symlink name in `packed/` (no version segment). */
export function packedSymlinkFilename(packageName: string): string {
return `${npmPackBasename(packageName)}-packed.tgz`;
}
/**
* Versioned tarball filename produced by `npm pack` in a package directory.
*/
export function versionedTarballFilename(packageName: string, version: string): string {
return `${npmPackBasename(packageName)}-${version}.tgz`;
}
/**
* npm pack tarball basename (without version and .tgz), e.g. `@sentry/core` -> `sentry-core`.
*/
function npmPackBasename(packageName: string): string {
return packageName.replace(/^@/, '').replace(/\//g, '-');
}
function readJson<T>(filePath: string): T {
return JSON.parse(fs.readFileSync(filePath, 'utf8')) as T;
}
function getE2eTestsPackageVersion(): string {
return readJson<{ version: string }>(path.join(E2E_TESTS_ROOT, 'package.json')).version;
}