Skip to content

Commit d4c8f7a

Browse files
committed
chore(build): Clean up build, types, tests
1 parent 856431d commit d4c8f7a

File tree

166 files changed

+351
-267
lines changed

Some content is hidden

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

166 files changed

+351
-267
lines changed

biome.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"noUselessElse": "off",
2222
"useEnumInitializers": "off",
2323
"useExponentiationOperator": "off",
24-
"useImportType": "off",
2524
"useNodejsImportProtocol": "off",
2625
"useNumberNamespace": "off",
2726
"useSingleVarDeclarator": "off",

packages/cli/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { promises as fs, readFileSync } from 'fs';
22
import { URL } from 'url';
3-
import { Logger, NodeIO, PropertyType, type Transform, VertexLayout, type vec2 } from '@gltf-transform/core';
3+
import { type Logger, NodeIO, PropertyType, type Transform, VertexLayout, type vec2 } from '@gltf-transform/core';
44
import {
55
type CenterOptions,
66
DRACO_DEFAULTS,

packages/cli/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Extension, NodeIO } from '@gltf-transform/core';
33
import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
44
import draco3d from 'draco3dgltf';
55
import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
6-
import { program } from './program.js';
6+
import type { program } from './program.js';
77
import type { Session } from './session.js';
88

99
interface Config {

packages/cli/src/inspect.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ import {
99
type InspectTextureReport,
1010
inspect as inspectDoc,
1111
} from '@gltf-transform/functions';
12-
import { TableFormat, formatBytes, formatHeader, formatLong, formatParagraph, formatTable, formatXMP } from './util.js';
12+
import {
13+
TableFormat,
14+
formatBytes,
15+
formatHeader,
16+
formatLong,
17+
formatParagraph,
18+
formatTable,
19+
formatXMP,
20+
log,
21+
} from './util.js';
1322

1423
type AnyPropertyReport =
1524
| InspectSceneReport
@@ -27,8 +36,8 @@ export async function inspect(
2736
// Summary (does not require parsing).
2837
const extensionsUsed = jsonDoc.json.extensionsUsed || [];
2938
const extensionsRequired = jsonDoc.json.extensionsRequired || [];
30-
console.log(formatHeader('overview'));
31-
console.log(
39+
log(formatHeader('overview'));
40+
log(
3241
(await formatTable(
3342
format,
3443
['key', 'value'],
@@ -53,8 +62,8 @@ export async function inspect(
5362
// XMP report.
5463
const rootPacket = document.getRoot().getExtension('KHR_xmp_json_ld') as Packet | null;
5564
if (rootPacket && rootPacket.listProperties().length > 0) {
56-
console.log(formatHeader('metadata'));
57-
console.log(
65+
log(formatHeader('metadata'));
66+
log(
5867
(await formatTable(
5968
format,
6069
['key', 'value'],
@@ -80,9 +89,9 @@ async function reportSection(
8089
) {
8190
const properties = section.properties;
8291

83-
console.log(formatHeader(type));
92+
log(formatHeader(type));
8493
if (!properties.length) {
85-
console.log(`No ${type} found.\n`);
94+
log(`No ${type} found.\n`);
8695
return;
8796
}
8897

@@ -92,12 +101,12 @@ async function reportSection(
92101
const header = Object.keys(formattedRecords[0]);
93102
const rows = formattedRecords.map((p: Record<string, string>) => Object.values(p));
94103
const footnotes = format !== TableFormat.CSV ? getFootnotes(type, rows, header) : [];
95-
console.log(await formatTable(format, header, rows));
96-
if (footnotes.length) console.log('\n' + footnotes.join('\n'));
104+
log(await formatTable(format, header, rows));
105+
if (footnotes.length) log('\n' + footnotes.join('\n'));
97106
if (section.warnings) {
98107
section.warnings.forEach((warning) => logger.warn(formatParagraph(warning)));
99108
}
100-
console.log('\n');
109+
log('\n');
101110
}
102111

103112
function formatPropertyReport(property: AnyPropertyReport, index: number, format: TableFormat): Record<string, string> {

packages/cli/src/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
type Validator as CaporalValidator,
3-
Command,
3+
type Command,
44
type ParsedOption,
55
type Logger as WinstonLogger,
66
program as _program,

packages/cli/src/session.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Document, FileUtils, Format, NodeIO, type Transform, Verbosity } from '@gltf-transform/core';
1+
import { Document, FileUtils, Format, type NodeIO, type Transform, Verbosity } from '@gltf-transform/core';
22
import type { KHRXMP, Packet } from '@gltf-transform/extensions';
33
import { unpartition } from '@gltf-transform/functions';
44
import { Listr, type ListrTask } from 'listr2';
55
import { performance } from 'perf_hooks'; // global in Node.js v16+
6-
import { Logger } from './program.js';
6+
import type { Logger } from './program.js';
77
import { XMPContext, dim, formatBytes, formatLong } from './util.js';
88

99
/** Helper class for managing a CLI command session. */
@@ -67,7 +67,11 @@ export class Session {
6767

6868
// Disable signal listeners so Ctrl+C works. Note that 'simple' and 'default'
6969
// renderers have different capability to display errors and warnings.
70-
await new Listr(tasks, { renderer: 'default', registerSignalListeners: false }).run();
70+
await new Listr(tasks, {
71+
renderer: 'default',
72+
registerSignalListeners: false,
73+
silentRendererCondition: process.env.NODE_ENV === 'test',
74+
}).run();
7175
console.log('');
7276

7377
logger.setVerbosity(prevLevel);

packages/cli/src/transforms/ktxdecompress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs, { rm } from 'fs/promises';
44
import pLimit from 'p-limit';
55
import tmp from 'tmp';
66

7-
import { Document, FileUtils, ImageUtils, type Transform, uuid } from '@gltf-transform/core';
7+
import { type Document, FileUtils, ImageUtils, type Transform, uuid } from '@gltf-transform/core';
88
import { KHRTextureBasisu } from '@gltf-transform/extensions';
99
import { createTransform } from '@gltf-transform/functions';
1010
import { formatBytes, spawn, waitExit } from '../util.js';

packages/cli/src/transforms/merge.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import fs from 'fs';
22
import {
3-
Buffer,
4-
Document,
3+
type Buffer,
4+
type Document,
55
FileUtils,
66
ImageUtils,
7-
NodeIO,
7+
type NodeIO,
88
PropertyType,
9-
Texture,
9+
type Texture,
1010
type Transform,
1111
} from '@gltf-transform/core';
1212
import { dedup, mergeDocuments, unpartition } from '@gltf-transform/functions';

packages/cli/src/transforms/toktx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import tmp from 'tmp';
88

99
import {
1010
BufferUtils,
11-
Document,
11+
type Document,
1212
FileUtils,
1313
type ILogger,
1414
ImageUtils,
15-
Texture,
15+
type Texture,
1616
TextureChannel,
1717
type Transform,
1818
uuid,

packages/cli/src/transforms/xmp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import type { Document, ILogger, Transform } from '@gltf-transform/core';
3-
import { KHRXMP, Packet } from '@gltf-transform/extensions';
3+
import { KHRXMP, type Packet } from '@gltf-transform/extensions';
44
import fs from 'fs/promises';
55
import languageTags from 'language-tags';
66
import prompts, { type PromptObject } from 'prompts';

packages/cli/src/util.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export let spawn: typeof _spawn = _spawn;
3333
export let commandExists = (cmd: string): Promise<string | boolean> => _commandExists(cmd).catch(() => false);
3434
export let waitExit: typeof _waitExit = _waitExit;
3535

36+
export let log: typeof console.log = console.log;
37+
3638
export function mockSpawn(_spawn: unknown): void {
3739
spawn = _spawn as typeof spawn;
3840
}
@@ -65,6 +67,10 @@ export async function _waitExit(process: ChildProcess): Promise<[unknown, string
6567
return [status, stdout, stderr];
6668
}
6769

70+
export function mockConsoleLog(_log: (...data: unknown[]) => void): void {
71+
log = _log;
72+
}
73+
6874
// Formatting.
6975

7076
const _longFormatter = new Intl.NumberFormat(undefined, { maximumFractionDigits: 0 });

packages/cli/src/validate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
33
import type { ILogger } from '@gltf-transform/core';
4-
import { TableFormat, formatHeader, formatTable } from './util.js';
4+
import { TableFormat, formatHeader, formatTable, log } from './util.js';
55

66
export interface ValidateOptions {
77
limit: number;
@@ -64,12 +64,12 @@ async function printTable(
6464
logger: ILogger,
6565
format: TableFormat,
6666
): Promise<void> {
67-
console.log(formatHeader(header));
67+
log(formatHeader(header));
6868
const messages = report.issues.messages.filter((msg) => msg.severity === severity);
6969
if (messages.length) {
70-
console.log(await formatTable(format, HEADER, messages.map(Object.values)));
70+
log(await formatTable(format, HEADER, messages.map(Object.values)));
7171
} else {
7272
logger.info(`No ${header}s found.`);
7373
}
74-
console.log('\n');
74+
log('\n');
7575
}

packages/cli/test/cli.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path, { dirname } from 'path';
33
import { fileURLToPath } from 'url';
4-
import { program, programReady } from '@gltf-transform/cli';
4+
import { mockConsoleLog, program, programReady } from '@gltf-transform/cli';
55
import { Document, FileUtils, NodeIO } from '@gltf-transform/core';
66
import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
77
import test from 'ava';
@@ -78,6 +78,8 @@ test('optimize', async (t) => {
7878
});
7979

8080
test('validate', async (t) => {
81+
mockConsoleLog(() => {});
82+
8183
await programReady;
8284
const io = new NodeIO();
8385
const input = tmp.tmpNameSync({ postfix: '.glb' });
@@ -93,6 +95,8 @@ test('validate', async (t) => {
9395
});
9496

9597
test('inspect', async (t) => {
98+
mockConsoleLog(() => {});
99+
96100
await programReady;
97101
const io = new NodeIO();
98102
const input = tmp.tmpNameSync({ postfix: '.glb' });

packages/cli/test/ktxfix.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path, { dirname } from 'path';
33
import { fileURLToPath } from 'url';
44
import { ktxfix } from '@gltf-transform/cli';
5-
import { Document, Texture } from '@gltf-transform/core';
5+
import { Document, type Texture } from '@gltf-transform/core';
66
import { logger } from '@gltf-transform/test-utils';
77
import test from 'ava';
88
import { KHR_DF_PRIMARIES_BT709, KHR_DF_PRIMARIES_UNSPECIFIED, read } from 'ktx-parse';

packages/cli/test/toktx.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ChildProcess } from 'child_process';
22
import { Mode, mockCommandExists, mockSpawn, mockWaitExit, toktx } from '@gltf-transform/cli';
3-
import { Document, TextureChannel, vec2 } from '@gltf-transform/core';
3+
import { Document, TextureChannel, type vec2 } from '@gltf-transform/core';
44
import { KHRMaterialsClearcoat } from '@gltf-transform/extensions';
55
import { logger } from '@gltf-transform/test-utils';
66
import test from 'ava';

packages/core/src/io/writer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import type { Document } from '../document.js';
1111
import type { Extension } from '../extension.js';
1212
import type { JSONDocument } from '../json-document.js';
13-
import { Accessor, AnimationSampler, Camera, Material } from '../properties/index.js';
13+
import { Accessor, type AnimationSampler, Camera, Material } from '../properties/index.js';
1414
import type { GLTF } from '../types/gltf.js';
1515
import { BufferUtils, Logger, MathUtils } from '../utils/index.js';
1616
import { WriterContext } from './writer-context.js';

packages/core/src/properties/primitive-target.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RefMap } from 'property-graph';
22
import { BufferViewUsage, type Nullable, PropertyType } from '../constants.js';
3-
import { Accessor } from './accessor.js';
3+
import type { Accessor } from './accessor.js';
44
import type { IExtensibleProperty } from './extensible-property.js';
55
import { Property } from './property.js';
66

packages/core/src/properties/primitive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RefMap, RefSet } from 'property-graph';
22
import { BufferViewUsage, type Nullable, PropertyType } from '../constants.js';
33
import type { GLTF } from '../types/gltf.js';
4-
import { Accessor } from './accessor.js';
4+
import type { Accessor } from './accessor.js';
55
import { ExtensibleProperty, type IExtensibleProperty } from './extensible-property.js';
66
import type { Material } from './material.js';
77
import type { PrimitiveTarget } from './primitive-target.js';

packages/core/src/properties/property.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
$attributes,
33
$immutableKeys,
4-
Graph,
4+
type Graph,
55
GraphEdge,
66
GraphNode,
77
type Literal,

packages/core/src/properties/root.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { ExtensionProperty } from './extension-property.js';
1111
import { Material } from './material.js';
1212
import { Mesh } from './mesh.js';
1313
import { Node } from './node.js';
14-
import { COPY_IDENTITY, Property } from './property.js';
14+
import { COPY_IDENTITY, type Property } from './property.js';
1515
import { Scene } from './scene.js';
1616
import { Skin } from './skin.js';
1717
import { Texture } from './texture.js';

packages/core/test/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, Extension, ExtensionProperty, PropertyType, WriterContext } from '@gltf-transform/core';
1+
import { Document, Extension, ExtensionProperty, PropertyType, type WriterContext } from '@gltf-transform/core';
22
import { cloneDocument } from '@gltf-transform/functions';
33
import { createPlatformIO } from '@gltf-transform/test-utils';
44
import test from 'ava';

packages/core/test/io/platform-io.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import { BufferUtils, Document, Format, GLB_BUFFER, GLTF, JSONDocument } from '@gltf-transform/core';
2+
import { BufferUtils, Document, Format, GLB_BUFFER, type GLTF, type JSONDocument } from '@gltf-transform/core';
33
import { createPlatformIO, logger, resolve } from '@gltf-transform/test-utils';
44
import test from 'ava';
55

packages/core/test/properties/accessor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Accessor, Document, GLTF, TypedArray } from '@gltf-transform/core';
1+
import { Accessor, Document, type GLTF, type TypedArray } from '@gltf-transform/core';
22
import { createPlatformIO, round } from '@gltf-transform/test-utils';
33
import test from 'ava';
44

packages/core/test/properties/material.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Document, Format, Property, PropertyType, Texture, TextureChannel, TextureInfo } from '@gltf-transform/core';
1+
import {
2+
Document,
3+
Format,
4+
type Property,
5+
PropertyType,
6+
type Texture,
7+
TextureChannel,
8+
TextureInfo,
9+
} from '@gltf-transform/core';
210
import { createPlatformIO } from '@gltf-transform/test-utils';
311
import test from 'ava';
412

packages/core/test/properties/mesh.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Accessor, Document, GLTF, Primitive, Property, VertexLayout } from '@gltf-transform/core';
1+
import { Accessor, Document, type GLTF, Primitive, type Property, VertexLayout } from '@gltf-transform/core';
22
import { createPlatformIO } from '@gltf-transform/test-utils';
33
import test from 'ava';
44

packages/core/test/properties/node.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, MathUtils, mat4, vec3, vec4 } from '@gltf-transform/core';
1+
import { Document, MathUtils, type mat4, type vec3, type vec4 } from '@gltf-transform/core';
22
import { cloneDocument } from '@gltf-transform/functions';
33
import { createPlatformIO } from '@gltf-transform/test-utils';
44
import test from 'ava';

packages/core/test/properties/primitive-target.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, Property } from '@gltf-transform/core';
1+
import { Document, type Property } from '@gltf-transform/core';
22
import test from 'ava';
33

44
const toType = (p: Property): string => p.propertyType;

packages/core/test/properties/property.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, vec3 } from '@gltf-transform/core';
1+
import { Document, type vec3 } from '@gltf-transform/core';
22
import test from 'ava';
33

44
test('equals', async (t) => {

packages/core/test/properties/root.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, JSONDocument } from '@gltf-transform/core';
1+
import { Document, type JSONDocument } from '@gltf-transform/core';
22
import { cloneDocument } from '@gltf-transform/functions';
33
import { createPlatformIO } from '@gltf-transform/test-utils';
44
import test from 'ava';

packages/core/test/properties/scene.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, Property } from '@gltf-transform/core';
1+
import { Document, type Property } from '@gltf-transform/core';
22
import { createPlatformIO } from '@gltf-transform/test-utils';
33
import test from 'ava';
44

packages/core/test/properties/texture.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document, Format, JSONDocument, TextureInfo } from '@gltf-transform/core';
1+
import { Document, Format, type JSONDocument, TextureInfo } from '@gltf-transform/core';
22
import { createPlatformIO } from '@gltf-transform/test-utils';
33
import test from 'ava';
44

packages/docs/src/lib/server/model/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { dirname, resolve } from 'node:path';
22
import { fileURLToPath } from 'node:url';
3-
import { Encoder, GD, Parser, createPrefixSort } from '@greendoc/parse';
3+
import { Encoder, type GD, Parser, createPrefixSort } from '@greendoc/parse';
44
import he from 'he';
55
import { Project } from 'ts-morph';
66

0 commit comments

Comments
 (0)