Skip to content

Commit 855abae

Browse files
committed
Changed how commands are executed to delegate executing over multiple bundles/tabs to Yarn
1 parent 49fdb9d commit 855abae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1055
-1164
lines changed

lib/buildtools/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@types/estree": "^1.0.0",
99
"@types/lodash": "^4.14.198",
1010
"@types/node": "^22.15.30",
11+
"@types/uglify-js": "^3",
1112
"typescript": "^5.8.2"
1213
},
1314
"exports": null,
@@ -26,6 +27,7 @@
2627
"jsonschema": "^1.5.0",
2728
"lodash": "^4.17.21",
2829
"typedoc": "^0.28.4",
30+
"uglify-js": "^3.19.3",
2931
"vitest": "^3.2.3"
3032
},
3133
"scripts": {

lib/buildtools/src/__tests__/utils.test.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { describe, expect, test } from 'vitest';
2-
import { compareSeverity, filterAsync, findSeverity, type Severity } from '../utils.js';
2+
import { Severity } from '../types.js';
3+
import { compareSeverity, filterAsync, findSeverity } from '../utils.js';
34

45
describe('test findSeverity', () => {
56
const cases: Severity[][] = [
6-
['success', 'success', 'success'],
7-
['warn', 'success', 'warn'],
8-
['warn', 'warn', 'warn'],
9-
['error', 'error', 'warn'],
10-
['error', 'error', 'success']
7+
[Severity.SUCCESS, Severity.SUCCESS, Severity.SUCCESS],
8+
[Severity.WARN, Severity.SUCCESS, Severity.WARN],
9+
[Severity.WARN, Severity.WARN, Severity.WARN],
10+
[Severity.ERROR, Severity.ERROR, Severity.WARN],
11+
[Severity.ERROR, Severity.ERROR, Severity.SUCCESS]
1112
];
1213

1314
test.each(cases)('Expecting %s', (expected, ...args) => {
@@ -17,15 +18,15 @@ describe('test findSeverity', () => {
1718

1819
describe('test compareSeverity', () => {
1920
const cases: [Severity, Severity, Severity][] = [
20-
['success', 'success', 'success'],
21-
['warn', 'success', 'warn'],
22-
['warn', 'warn', 'success'],
23-
['warn', 'warn', 'warn'],
24-
['error', 'success', 'error'],
25-
['error', 'warn', 'error'],
26-
['error', 'error', 'error'],
27-
['error', 'error', 'warn'],
28-
['error', 'error', 'success'],
21+
[Severity.SUCCESS, Severity.SUCCESS, Severity.SUCCESS],
22+
[Severity.WARN, Severity.SUCCESS, Severity.WARN],
23+
[Severity.WARN, Severity.WARN, Severity.SUCCESS],
24+
[Severity.WARN, Severity.WARN, Severity.WARN],
25+
[Severity.ERROR, Severity.SUCCESS, Severity.ERROR],
26+
[Severity.ERROR, Severity.WARN, Severity.ERROR],
27+
[Severity.ERROR, Severity.ERROR, Severity.ERROR],
28+
[Severity.ERROR, Severity.ERROR, Severity.WARN],
29+
[Severity.ERROR, Severity.ERROR, Severity.SUCCESS],
2930
];
3031

3132
test.each(cases)('Expecting %s', (expected, lhs, rhs) => {

lib/buildtools/src/build/manifest/__tests__/manifest.test.ts renamed to lib/buildtools/src/build/__tests__/manifest.test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import fs from 'fs/promises';
2-
import { ValidationError } from 'jsonschema';
32
import { describe, expect, it, test, vi } from 'vitest';
4-
import { expectIsError, expectIsSuccess, testMocksDir } from '../../../__tests__/fixtures.js';
5-
import { getBundleManifest, getBundleManifests, resolveAllBundles, resolveSingleBundle } from '../index.js';
6-
import { MissingTabError, type GetBundleManifestSuccess } from '../types.js';
3+
import { expectIsError, expectIsSuccess, testMocksDir } from '../../__tests__/fixtures.js';
4+
import { Severity } from '../../types.js';
5+
import { getBundleManifest, getBundleManifests, resolveAllBundles, resolveSingleBundle, type GetBundleManifestResult } from '../manifest.js';
76

8-
vi.mock(import('../../../getGitRoot.js'));
7+
vi.mock(import('../../getGitRoot.js'));
98

109
describe('Test bundle manifest schema validation succeeds', () => {
1110
const mockedReadFile = vi.spyOn(fs, 'readFile');
@@ -14,8 +13,8 @@ describe('Test bundle manifest schema validation succeeds', () => {
1413
mockedReadFile.mockResolvedValueOnce('{ "tabs": [] }');
1514
mockedReadFile.mockResolvedValueOnce('{ "version": "1.0.0" }');
1615

17-
const expected: GetBundleManifestSuccess = {
18-
severity: 'success',
16+
const expected: GetBundleManifestResult = {
17+
severity: Severity.SUCCESS,
1918
manifest: {
2019
tabs: [],
2120
version: '1.0.0'
@@ -31,8 +30,8 @@ describe('Test bundle manifest schema validation succeeds', () => {
3130
mockedReadFile.mockResolvedValueOnce('{ "tabs": ["tab0", "tab1"] }');
3231
mockedReadFile.mockResolvedValueOnce('{ "version": "1.0.0" }');
3332

34-
const expected: GetBundleManifestSuccess = {
35-
severity: 'success',
33+
const expected: GetBundleManifestResult = {
34+
severity: Severity.SUCCESS,
3635
manifest: {
3736
tabs: ['tab0', 'tab1'],
3837
version: '1.0.0'
@@ -48,8 +47,8 @@ describe('Test bundle manifest schema validation succeeds', () => {
4847
mockedReadFile.mockResolvedValueOnce('{ "tabs": ["tab0"] }');
4948
mockedReadFile.mockResolvedValueOnce('{}');
5049

51-
const expected: GetBundleManifestSuccess = {
52-
severity: 'success',
50+
const expected: GetBundleManifestResult = {
51+
severity: Severity.SUCCESS,
5352
manifest: {
5453
tabs: ['tab0']
5554
}
@@ -70,7 +69,7 @@ describe('Test bundle manifest schema validation succeeds', () => {
7069

7170
expect(result!.errors.length).toEqual(1);
7271
const [err] = result!.errors;
73-
expect(err).toBeInstanceOf(MissingTabError);
72+
expect(err).toEqual('Unknown tab tab2');
7473
});
7574

7675
test('Schema with additional properties', async () => {
@@ -83,7 +82,7 @@ describe('Test bundle manifest schema validation succeeds', () => {
8382

8483
expect(result!.errors.length).toEqual(1);
8584
const [err] = result!.errors;
86-
expect(err).toBeInstanceOf(ValidationError);
85+
expect(err).toMatchInlineSnapshot(`"instance is not allowed to have the additional property "unknown""`);
8786
});
8887

8988
test('Schema with invalid requires', async () => {
@@ -96,7 +95,7 @@ describe('Test bundle manifest schema validation succeeds', () => {
9695

9796
expect(result!.errors.length).toEqual(1);
9897
const [err] = result!.errors;
99-
expect(err).toBeInstanceOf(ValidationError);
98+
expect(err).toMatchInlineSnapshot(`"instance.requires is not one of enum values: 1,2,3,4"`);
10099
});
101100
});
102101

@@ -112,7 +111,6 @@ describe('Test getBundleManifests', () => {
112111

113112
const result = await getBundleManifests('/src/bundles');
114113
expectIsError(result.severity);
115-
expect(result.errors[0]).toBe(errorObject);
116114
});
117115
});
118116

@@ -141,7 +139,7 @@ describe('Test resolveSingleBundle', () => {
141139
const resolved = await resolveSingleBundle(path);
142140
expect(resolved).toMatchObject({
143141
severity: 'error',
144-
errors: [expect.any(Error)]
142+
errors: [expect.any(String)]
145143
});
146144

147145
const stats = await fs.stat(path);

lib/buildtools/src/build/all.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { LogLevel } from 'typedoc';
2+
import type { PrebuildOptions } from '../prebuild/index.js';
3+
import { runEslint, type LintResult } from '../prebuild/lint.js';
4+
import { runTsc, type TscResult } from '../prebuild/tsc.js';
5+
import { Severity, type BuildResult, type InputAsset } from '../types.js';
6+
import { compareSeverity } from '../utils.js';
7+
import { buildSingleBundleDocs } from './docs/index.js';
8+
import { buildBundle, buildTab } from './modules/index.js';
9+
10+
interface BuildAllPrebuildError {
11+
severity: Severity.ERROR
12+
13+
tsc: TscResult | undefined
14+
lint: LintResult | undefined
15+
}
16+
17+
interface BuildAllBundleResult {
18+
severity: Severity
19+
results: BuildResult
20+
docs: BuildResult
21+
22+
tsc: TscResult | undefined
23+
lint: LintResult | undefined
24+
}
25+
26+
interface BuildAllTabResult {
27+
severity: Severity
28+
results: BuildResult
29+
30+
tsc: TscResult | undefined
31+
lint: LintResult | undefined
32+
}
33+
34+
export type BuildAllResult = BuildAllPrebuildError | BuildAllBundleResult | BuildAllTabResult;
35+
36+
/**
37+
* For a bundle, builds both the bundle itself and its JSON documentation\
38+
* For a tab, build just the tab
39+
*/
40+
export async function buildAll(input: InputAsset, prebuild: PrebuildOptions, outDir: string, logLevel: LogLevel): Promise<BuildAllResult> {
41+
const [tscResult, lintResult] = await Promise.all([
42+
prebuild.tsc ? runTsc(input, true) : Promise.resolve(undefined),
43+
prebuild.lint ? runEslint(input, false, false) : Promise.resolve(undefined)
44+
]);
45+
46+
if (tscResult?.severity === Severity.ERROR || lintResult?.severity === Severity.ERROR) {
47+
return {
48+
severity: Severity.ERROR,
49+
lint: lintResult,
50+
tsc: tscResult
51+
};
52+
}
53+
54+
if (input.type === 'bundle') {
55+
const [bundleResult, docsResult] = await Promise.all([
56+
buildBundle(outDir, input),
57+
buildSingleBundleDocs(input, outDir, logLevel)
58+
]);
59+
60+
return {
61+
severity: compareSeverity(bundleResult.severity, docsResult.severity),
62+
results: bundleResult,
63+
docs: docsResult,
64+
lint: lintResult,
65+
tsc: tscResult,
66+
};
67+
} else {
68+
const tabResult = await buildTab(outDir, input);
69+
return {
70+
severity: tabResult.severity,
71+
results: tabResult,
72+
lint: lintResult,
73+
tsc: tscResult,
74+
};
75+
}
76+
}

lib/buildtools/src/build/buildUtils.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/buildtools/src/build/docs/__tests__/building.test.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)