-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
package.test.ts
73 lines (64 loc) · 2.18 KB
/
package.test.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
/// <reference types="node" />
import { readFileSync, readdirSync } from 'node:fs';
import { assert, describe, expect, it } from 'vitest';
import { scripts } from './package.json';
const SECOND = 1;
const isScoped = (name: string): boolean => name.startsWith('@');
const isUnscoped = (name: string): boolean => !name.startsWith('@');
const mapToScope = (name: string): string =>
name.substring(SECOND, name.indexOf('/'));
const isPublic = (value: unknown): boolean => {
assert(typeof value === 'object');
assert(value !== null);
if (!('private' in value)) {
return true;
}
return value.private !== true;
};
const mapToName = (value: unknown): string => {
assert(typeof value === 'object');
assert(value !== null);
assert('name' in value);
const { name } = value;
assert(typeof name === 'string');
return name;
};
const mapWorkspaceToPackage = (workspace: string): unknown => {
const path = `./packages/${workspace}/package.json`;
const contents: string = readFileSync(path).toString();
return JSON.parse(contents) as unknown;
};
const publicPackageNames: readonly string[] = readdirSync('packages')
.map(mapWorkspaceToPackage)
.filter(isPublic)
.map(mapToName);
describe('package.json', (): void => {
describe('scripts', (): void => {
describe('up', (): void => {
const { up } = scripts;
/**
* Since workspaces will exist locally and in the registry, we remove
* ambiguity by excluding them from the upgrade and relying on the local
* copy as the source of truth.
*/
it('should not upgrade workspaces', (): void => {
const scopes: readonly string[] = Array.from(
new Set(publicPackageNames.filter(isScoped).map(mapToScope)),
).sort();
const unscopedPackageNames: readonly string[] = [
...publicPackageNames.filter(isUnscoped),
'proposal-async-context',
].sort();
expect(up).toMatch(
[
`yarn up "@!(${scopes.join('|')})/*" "!(${unscopedPackageNames.join(
'|',
)})"`,
'yarn up --recursive "@*/*" "*"',
'yarn sdks vscode',
].join(' && '),
);
});
});
});
});