Skip to content

Commit

Permalink
Fix type definitions for moduleResolution nodenext
Browse files Browse the repository at this point in the history
When importing this library in a project using moduleResolution
nodenext, the types would give errors because the import paths were
missing the file extension which is required for moduleResolution
nodenext. Therefore we have to add .js to all imports of local files.

See developit/microbundle#1019 (comment)
and the issues that comment links to for some more detailed explanation
of this.

I also changed moduleResolution to nodenext in the tsconfig because when
it's set to node, typescript won't give errors for missing file
extensions which means they are easy to forget. With it set to nodenext,
you will get an error if an import is missing the file extension. As far
as I can see, changing this doesn't change the build output.

Depends on donmccurdy/property-graph#70 and
donmccurdy/KTX-Parse#55

Fixes #824
  • Loading branch information
trygveaa committed Feb 21, 2023
1 parent 51e7e0b commit 2e95b87
Show file tree
Hide file tree
Showing 149 changed files with 457 additions and 457 deletions.
16 changes: 8 additions & 8 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import sharp from 'sharp';
import { MeshoptEncoder, MeshoptSimplifier } from 'meshoptimizer';
import { Logger, NodeIO, PropertyType, VertexLayout, vec2 } from '@gltf-transform/core';
import { CenterOptions, InstanceOptions, PartitionOptions, PruneOptions, QUANTIZE_DEFAULTS, ResampleOptions, SequenceOptions, TEXTURE_RESIZE_DEFAULTS, TextureResizeFilter, UnweldOptions, WeldOptions, center, dedup, instance, metalRough, partition, prune, quantize, resample, sequence, tangents, unweld, weld, reorder, dequantize, unlit, meshopt, DRACO_DEFAULTS, draco, DracoOptions, simplify, SIMPLIFY_DEFAULTS, WELD_DEFAULTS, textureCompress, FlattenOptions, flatten, JOIN_DEFAULTS, join, JoinOptions, sparse, SparseOptions } from '@gltf-transform/functions';
import { inspect } from './inspect';
import { ETC1S_DEFAULTS, Filter, Mode, UASTC_DEFAULTS, ktxfix, merge, toktx, XMPOptions, xmp } from './transforms';
import { formatBytes, MICROMATCH_OPTIONS, underline, TableFormat } from './util';
import { Session } from './session';
import { ValidateOptions, validate } from './validate';
import { getConfig, loadConfig } from './config';
import { inspect } from './inspect.js';
import { ETC1S_DEFAULTS, Filter, Mode, UASTC_DEFAULTS, ktxfix, merge, toktx, XMPOptions, xmp } from './transforms/index.js';
import { formatBytes, MICROMATCH_OPTIONS, underline, TableFormat } from './util.js';
import { Session } from './session.js';
import { ValidateOptions, validate } from './validate.js';
import { getConfig, loadConfig } from './config.js';

const program = caporal.program;

Expand Down Expand Up @@ -1460,5 +1460,5 @@ program.disableGlobalOption('--quiet');
program.disableGlobalOption('--no-color');

export { program, programReady };
export * from './util';
export * from './transforms';
export * from './util.js';
export * from './transforms/index.js';
2 changes: 1 addition & 1 deletion packages/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
import { resolve } from 'path';
import draco3d from 'draco3dgltf';
import { MeshoptEncoder, MeshoptDecoder } from 'meshoptimizer';
import type { Session } from './session';
import type { Session } from './session.js';

interface Config {
extensions: (typeof Extension)[];
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
InspectTextureReport,
inspect as inspectDoc,
} from '@gltf-transform/functions';
import { formatBytes, formatHeader, formatLong, formatParagraph, formatTable, formatXMP, TableFormat } from './util';
import { formatBytes, formatHeader, formatLong, formatParagraph, formatTable, formatXMP, TableFormat } from './util.js';
import type { Packet } from '@gltf-transform/extensions';

type AnyPropertyReport =
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Document, NodeIO, Logger, FileUtils, Transform, Format, ILogger } from
import type { Packet, KHRXMP } from '@gltf-transform/extensions';
import { unpartition } from '@gltf-transform/functions';
import { Listr, ListrTask } from 'listr2';
import { dim, formatBytes, formatLong, XMPContext } from './util';
import { dim, formatBytes, formatLong, XMPContext } from './util.js';
import type caporal from '@caporal/core';

/** Helper class for managing a CLI command session. */
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/transforms/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './ktxfix';
export * from './merge';
export * from './toktx';
export * from './xmp';
export * from './ktxfix.js';
export * from './merge.js';
export * from './toktx.js';
export * from './xmp.js';
2 changes: 1 addition & 1 deletion packages/cli/src/transforms/ktxfix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { KHR_DF_PRIMARIES_BT709, KHR_DF_PRIMARIES_UNSPECIFIED, read, write } from 'ktx-parse';
import type { Document, Transform } from '@gltf-transform/core';
import { MICROMATCH_OPTIONS } from '../util';
import { MICROMATCH_OPTIONS } from '../util.js';
import { listTextureSlots } from '@gltf-transform/functions';
import micromatch from 'micromatch';

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/transforms/toktx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pLimit from 'p-limit';
import { Document, FileUtils, ILogger, ImageUtils, TextureChannel, Transform, vec2, uuid } from '@gltf-transform/core';
import { KHRTextureBasisu } from '@gltf-transform/extensions';
import { createTransform, getTextureChannelMask, listTextureSlots } from '@gltf-transform/functions';
import { spawn, commandExists, formatBytes, waitExit, MICROMATCH_OPTIONS } from '../util';
import { spawn, commandExists, formatBytes, waitExit, MICROMATCH_OPTIONS } from '../util.js';

tmp.setGracefulCleanup();

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/transforms/xmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import languageTags from 'language-tags';
import validateSPDX from 'spdx-correct';
import fs from 'fs/promises';
import path from 'path';
import { formatXMP, XMPContext } from '../util';
import { formatXMP, XMPContext } from '../util.js';

const DEFAULT_LANG = 'en-US';

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import validator from 'gltf-validator';
import type { ILogger } from '@gltf-transform/core';
import { formatHeader, formatTable, TableFormat } from './util';
import { formatHeader, formatTable, TableFormat } from './util.js';

export interface ValidateOptions {
limit: number;
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @module core */

export { Document, Transform, TransformContext } from './document';
export { JSONDocument } from './json-document';
export { Extension } from './extension';
export { Document, Transform, TransformContext } from './document.js';
export { JSONDocument } from './json-document.js';
export { Extension } from './extension.js';
export {
Accessor,
Animation,
Expand All @@ -25,9 +25,9 @@ export {
Texture,
TextureInfo,
COPY_IDENTITY,
} from './properties';
} from './properties/index.js';
export { Graph, GraphEdge } from 'property-graph';
export { DenoIO, PlatformIO, NodeIO, WebIO, ReaderContext, WriterContext } from './io';
export { DenoIO, PlatformIO, NodeIO, WebIO, ReaderContext, WriterContext } from './io/index.js';
export {
BufferUtils,
ColorUtils,
Expand All @@ -41,7 +41,7 @@ export {
getBounds,
bounds,
uuid,
} from './utils';
} from './utils/index.js';
export {
TypedArray,
TypedArrayConstructor,
Expand All @@ -59,5 +59,5 @@ export {
bbox,
GLB_BUFFER,
VERSION,
} from './constants';
export { GLTF } from './types/gltf';
} from './constants.js';
export { GLTF } from './types/gltf.js';
8 changes: 4 additions & 4 deletions packages/core/src/document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PropertyType } from './constants';
import type { Extension } from './extension';
import { PropertyType } from './constants.js';
import type { Extension } from './extension.js';
import { Graph } from 'property-graph';
import {
Accessor,
Expand All @@ -18,8 +18,8 @@ import {
Scene,
Skin,
Texture,
} from './properties';
import { ILogger, Logger } from './utils';
} from './properties/index.js';
import { ILogger, Logger } from './utils/index.js';

export interface TransformContext {
stack: string[];
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { GraphEdgeEvent, GraphEvent, GraphNodeEvent } from 'property-graph';
import type { PropertyType } from './constants';
import type { Document } from './document';
import type { ReaderContext, WriterContext } from './io';
import { ExtensionProperty } from './properties';
import type { PropertyType } from './constants.js';
import type { Document } from './document.js';
import type { ReaderContext, WriterContext } from './io/index.js';
import { ExtensionProperty } from './properties/index.js';

/**
* # Extension
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/io/deno-io.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlatformIO } from './platform-io';
import { PlatformIO } from './platform-io.js';

interface Path {
resolve(base: string, path: string): string;
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/io/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { NodeIO } from './node-io';
export { DenoIO } from './deno-io';
export { PlatformIO } from './platform-io';
export { WebIO } from './web-io';
export { ReaderOptions } from './reader';
export { WriterOptions } from './writer';
export { ReaderContext } from './reader-context';
export { WriterContext } from './writer-context';
export { NodeIO } from './node-io.js';
export { DenoIO } from './deno-io.js';
export { PlatformIO } from './platform-io.js';
export { WebIO } from './web-io.js';
export { ReaderOptions } from './reader.js';
export { WriterOptions } from './writer.js';
export { ReaderContext } from './reader-context.js';
export { WriterContext } from './writer-context.js';
10 changes: 5 additions & 5 deletions packages/core/src/io/node-io.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Format } from '../constants';
import type { Document } from '../document';
import { FileUtils } from '../utils/';
import { PlatformIO } from './platform-io';
import { HTTPUtils } from '../utils';
import { Format } from '../constants.js';
import type { Document } from '../document.js';
import { FileUtils } from '../utils/index.js';
import { PlatformIO } from './platform-io.js';
import { HTTPUtils } from '../utils/index.js';

/**
* # NodeIO
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/io/platform-io.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Format, GLB_BUFFER, VertexLayout } from '../constants';
import type { Document } from '../document';
import type { Extension } from '../extension';
import type { JSONDocument } from '../json-document';
import type { GLTF } from '../types/gltf';
import { BufferUtils, FileUtils, HTTPUtils, ILogger, Logger, uuid } from '../utils/';
import { GLTFReader } from './reader';
import { GLTFWriter, WriterOptions } from './writer';
import { Format, GLB_BUFFER, VertexLayout } from '../constants.js';
import type { Document } from '../document.js';
import type { Extension } from '../extension.js';
import type { JSONDocument } from '../json-document.js';
import type { GLTF } from '../types/gltf.js';
import { BufferUtils, FileUtils, HTTPUtils, ILogger, Logger, uuid } from '../utils/index.js';
import { GLTFReader } from './reader.js';
import { GLTFWriter, WriterOptions } from './writer.js';

enum ChunkType {
JSON = 0x4e4f534a,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/io/reader-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JSONDocument } from '../json-document';
import type { JSONDocument } from '../json-document.js';
import type {
Accessor,
Animation,
Expand All @@ -11,8 +11,8 @@ import type {
Skin,
Texture,
TextureInfo,
} from '../properties';
import type { GLTF } from '../types/gltf';
} from '../properties/index.js';
import type { GLTF } from '../types/gltf.js';

/**
* Model class providing glTF-Transform objects representing each definition in the glTF file, used
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/io/reader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GLB_BUFFER, PropertyType, TypedArray, mat4, vec3, vec4, ComponentTypeToTypedArray } from '../constants';
import { Document } from '../document';
import type { Extension } from '../extension';
import type { JSONDocument } from '../json-document';
import { Accessor, AnimationSampler, Camera } from '../properties';
import type { GLTF } from '../types/gltf';
import { BufferUtils, FileUtils, ILogger, ImageUtils, Logger, MathUtils } from '../utils';
import { ReaderContext } from './reader-context';
import { GLB_BUFFER, PropertyType, TypedArray, mat4, vec3, vec4, ComponentTypeToTypedArray } from '../constants.js';
import { Document } from '../document.js';
import type { Extension } from '../extension.js';
import type { JSONDocument } from '../json-document.js';
import { Accessor, AnimationSampler, Camera } from '../properties/index.js';
import type { GLTF } from '../types/gltf.js';
import { BufferUtils, FileUtils, ILogger, ImageUtils, Logger, MathUtils } from '../utils/index.js';
import { ReaderContext } from './reader-context.js';

export interface ReaderOptions {
logger?: ILogger;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/io/web-io.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PlatformIO } from './platform-io';
import { HTTPUtils } from '../utils';
import { Format } from '../constants';
import { PlatformIO } from './platform-io.js';
import { HTTPUtils } from '../utils/index.js';
import { Format } from '../constants.js';

/**
* # WebIO
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/io/writer-context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BufferViewUsage, Format, PropertyType } from '../constants';
import type { Document } from '../document';
import type { JSONDocument } from '../json-document';
import { BufferViewUsage, Format, PropertyType } from '../constants.js';
import type { Document } from '../document.js';
import type { JSONDocument } from '../json-document.js';
import type {
Accessor,
Animation,
Expand All @@ -14,10 +14,10 @@ import type {
Skin,
Texture,
TextureInfo,
} from '../properties';
import type { GLTF } from '../types/gltf';
import { ILogger, ImageUtils } from '../utils';
import type { WriterOptions } from './writer';
} from '../properties/index.js';
import type { GLTF } from '../types/gltf.js';
import { ILogger, ImageUtils } from '../utils/index.js';
import type { WriterOptions } from './writer.js';

type PropertyDef = GLTF.IScene | GLTF.INode | GLTF.IMaterial | GLTF.ISkin | GLTF.ITexture;

Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/io/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
TypedArray,
VERSION,
VertexLayout,
} from '../constants';
import type { Document } from '../document';
import type { Extension } from '../extension';
} from '../constants.js';
import type { Document } from '../document.js';
import type { Extension } from '../extension.js';
import type { GraphEdge } from 'property-graph';
import type { JSONDocument } from '../json-document';
import { Accessor, AnimationSampler, Camera, Material, Property } from '../properties';
import type { GLTF } from '../types/gltf';
import { BufferUtils, Logger, MathUtils } from '../utils';
import { WriterContext } from './writer-context';
import type { JSONDocument } from '../json-document.js';
import { Accessor, AnimationSampler, Camera, Material, Property } from '../properties/index.js';
import type { GLTF } from '../types/gltf.js';
import { BufferUtils, Logger, MathUtils } from '../utils/index.js';
import { WriterContext } from './writer-context.js';

const { BufferViewUsage } = WriterContext;
const { UNSIGNED_INT, UNSIGNED_SHORT, UNSIGNED_BYTE } = Accessor.ComponentType;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/json-document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GLTF } from './types/gltf';
import type { GLTF } from './types/gltf.js';

/**
* # JSONDocument
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/properties/accessor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Nullable, PropertyType, TypedArray } from '../constants';
import type { GLTF } from '../types/gltf';
import { MathUtils } from '../utils';
import type { Buffer } from './buffer';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property';
import { COPY_IDENTITY } from './property';
import { Nullable, PropertyType, TypedArray } from '../constants.js';
import type { GLTF } from '../types/gltf.js';
import { MathUtils } from '../utils/index.js';
import type { Buffer } from './buffer.js';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';
import { COPY_IDENTITY } from './property.js';

interface IAccessor extends IExtensibleProperty {
array: TypedArray | null;
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/properties/animation-channel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Nullable, PropertyType } from '../constants';
import type { GLTF } from '../types/gltf';
import type { AnimationSampler } from './animation-sampler';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property';
import type { Node } from './node';
import { Nullable, PropertyType } from '../constants.js';
import type { GLTF } from '../types/gltf.js';
import type { AnimationSampler } from './animation-sampler.js';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';
import type { Node } from './node.js';

interface IAnimationChannel extends IExtensibleProperty {
targetPath: GLTF.AnimationChannelTargetPath | null;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/properties/animation-sampler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BufferViewUsage, Nullable, PropertyType } from '../constants';
import type { GLTF } from '../types/gltf';
import type { Accessor } from './accessor';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property';
import { BufferViewUsage, Nullable, PropertyType } from '../constants.js';
import type { GLTF } from '../types/gltf.js';
import type { Accessor } from './accessor.js';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';

interface IAnimationSampler extends IExtensibleProperty {
interpolation: GLTF.AnimationSamplerInterpolation;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/properties/animation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Nullable, PropertyType } from '../constants';
import type { AnimationChannel } from './animation-channel';
import type { AnimationSampler } from './animation-sampler';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property';
import { Nullable, PropertyType } from '../constants.js';
import type { AnimationChannel } from './animation-channel.js';
import type { AnimationSampler } from './animation-sampler.js';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';

interface IAnimation extends IExtensibleProperty {
channels: AnimationChannel[];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/properties/buffer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Nullable, PropertyType } from '../constants';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property';
import { Nullable, PropertyType } from '../constants.js';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';

interface IBuffer extends IExtensibleProperty {
uri: string;
Expand Down
Loading

0 comments on commit 2e95b87

Please sign in to comment.