-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathpublishPackages.ts
More file actions
52 lines (44 loc) · 1.72 KB
/
publishPackages.ts
File metadata and controls
52 lines (44 loc) · 1.72 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
/* eslint-disable no-console */
import { spawn } from 'child_process';
import { readFileSync } from 'fs';
import { globSync } from 'glob';
import * as path from 'path';
const repositoryRoot = path.resolve(__dirname, '../../..');
function npmPublish(tarballPath: string, npmrc: string): Promise<void> {
return new Promise((resolve, reject) => {
const child = spawn('npm', ['--userconfig', npmrc, 'publish', tarballPath], {
cwd: repositoryRoot,
stdio: 'inherit',
});
child.on('error', reject);
child.on('close', code => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Error publishing tarball ${tarballPath}`));
}
});
});
}
/**
* Publishes all built Sentry package tarballs to the local Verdaccio test registry.
* Uses async `npm publish` so an in-process Verdaccio can still handle HTTP on the event loop.
*/
export async function publishPackages(): Promise<void> {
const version = (JSON.parse(readFileSync(path.join(__dirname, '../package.json'), 'utf8')) as { version: string })
.version;
// Get absolute paths of all the packages we want to publish to the fake registry
// Only include the current versions, to avoid getting old tarballs published as well
const packageTarballPaths = globSync(`packages/*/sentry-*-${version}.tgz`, {
cwd: repositoryRoot,
absolute: true,
});
if (packageTarballPaths.length === 0) {
throw new Error(`No packages to publish for version ${version}, did you run "yarn build:tarballs"?`);
}
const npmrc = path.join(__dirname, '../test-registry.npmrc');
for (const tarballPath of packageTarballPaths) {
console.log(`Publishing tarball ${tarballPath} ...`);
await npmPublish(tarballPath, npmrc);
}
}