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.
  • Loading branch information
trygveaa committed Feb 21, 2023
1 parent b00bcf1 commit b9b9b2f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "./dist/ktx-parse.cjs",
"module": "./dist/ktx-parse.esm.js",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/ktx-parse.cjs",
"default": "./dist/ktx-parse.modern.js"
},
Expand Down
2 changes: 1 addition & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
KHR_DF_VERSION,
KHR_SUPERCOMPRESSION_NONE,
VK_FORMAT_UNDEFINED,
} from './constants';
} from './constants.js';

/**
* Represents an unpacked KTX 2.0 texture container. Data for individual mip levels are stored in
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './container';
export * from './constants';
export * from './read';
export * from './write';
export * from './container.js';
export * from './constants.js';
export * from './read.js';
export * from './write.js';
10 changes: 5 additions & 5 deletions src/read.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BufferReader } from './buffer-reader';
import { KHR_DF_SAMPLE_DATATYPE_SIGNED } from './constants';
import { KTX2_ID } from './constants-internal';
import { KTX2Container, KTX2DataFormatDescriptorBasicFormat } from './container';
import { decodeText } from './util';
import { BufferReader } from './buffer-reader.js';
import { KHR_DF_SAMPLE_DATATYPE_SIGNED } from './constants.js';
import { KTX2_ID } from './constants-internal.js';
import { KTX2Container, KTX2DataFormatDescriptorBasicFormat } from './container.js';
import { decodeText } from './util.js';

/**
* Parses a KTX 2.0 file, returning an unpacked {@link KTX2Container} instance with all associated
Expand Down
8 changes: 4 additions & 4 deletions src/write.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HEADER_BYTE_LENGTH, KTX2_ID, KTX_WRITER, NUL } from './constants-internal';
import { KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT, KHR_DF_SAMPLE_DATATYPE_SIGNED } from './constants';
import { KTX2Container } from './container';
import { concat, encodeText } from './util';
import { HEADER_BYTE_LENGTH, KTX2_ID, KTX_WRITER, NUL } from './constants-internal.js';
import { KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT, KHR_DF_SAMPLE_DATATYPE_SIGNED } from './constants.js';
import { KTX2Container } from './container.js';
import { concat, encodeText } from './util.js';

interface WriteOptions {
keepWriter?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"paths": {
"ktx-parse": ["./"]
},
"moduleResolution": "node",
"moduleResolution": "nodenext",
"lib": ["es2020", "dom"],
"target": "es2020",
"module": "es2020",
Expand Down

0 comments on commit b9b9b2f

Please sign in to comment.