Skip to content

Commit

Permalink
[types] Add .js extension to file imports (#333)
Browse files Browse the repository at this point in the history
* [types] Add `.js` extension to file imports

Fixes problems when `moduleResolution` in tsconfig.json is set to
NodeNext.

* [types] Add extensions to `import()` types

* [types] Add missing imports

Weirdly, TypeScript only complains about these imports when
`moduleResolution` is set to `NodeNext`. I guess that whatever the
default module resolution system is can infer that they're from the
augmented module, but that doesn't seem to work on `NodeNext`.
  • Loading branch information
MysteryBlokHed committed Oct 9, 2023
1 parent 08fce48 commit f71745c
Show file tree
Hide file tree
Showing 74 changed files with 183 additions and 182 deletions.
2 changes: 1 addition & 1 deletion types/dist/color.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src";
export { default } from "../src/index.js";
20 changes: 10 additions & 10 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Definitions by: Adam Thompson-Sharpe <https://github.com/MysteryBlokHed>
// Minimum TypeScript Version: 4.1
export { default } from "./dist/color";
export { default } from "./dist/color.js";
export type {
ColorConstructor,
ColorObject,
Expand All @@ -12,30 +12,30 @@ export type {
PlainColorObject,
SpaceAccessor,
ToColorPrototype,
} from "./src/color";
} from "./src/color.js";

export type { White } from "./src/adapt";
export type { White } from "./src/adapt.js";

export type { CAT } from "./src/CATs";
export type { CAT } from "./src/CATs.js";

export type { Display } from "./src/display";
export type { Display } from "./src/display.js";

export type {
Range,
RangeOptions,
MixOptions,
StepsOptions,
} from "./src/interpolation";
} from "./src/interpolation.js";

export type { Options as ParseOptions } from "./src/parse";
export type { Options as ParseOptions } from "./src/parse.js";

export type { RGBOptions } from "./src/rgbspace";
export type { RGBOptions } from "./src/rgbspace.js";

export type { Options as SerializeOptions } from "./src/serialize";
export type { Options as SerializeOptions } from "./src/serialize.js";

export type {
Format as SpaceFormat,
CoordMeta,
Ref,
Options as SpaceOptions,
} from "./src/space";
} from "./src/space.js";
2 changes: 1 addition & 1 deletion types/src/CATs.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { White } from "./adapt";
import { White } from "./adapt.js";

export interface CAT {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion types/src/chromaticity.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "./color";
import Color, { ColorObject } from "./color.js";

export function uv(color: Color | ColorObject): [number, number];

Expand Down
2 changes: 1 addition & 1 deletion types/src/clone.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { PlainColorObject } from "./color";
import { PlainColorObject } from "./color.js";

export default function clone(color: PlainColorObject): PlainColorObject;
12 changes: 6 additions & 6 deletions types/src/color.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WHITES } from "./adapt";
import defaults from "./defaults";
import hooks from "./hooks";
import * as util from "./util";
import ColorSpace from "./space";
import { WHITES } from "./adapt.js";
import defaults from "./defaults.js";
import hooks from "./hooks.js";
import * as util from "./util.js";
import ColorSpace from "./space.js";

import {
to,
Expand All @@ -17,7 +17,7 @@ import {
set,
setAll,
display,
} from "./index-fn";
} from "./index-fn.js";

export type Coords = [number, number, number];

Expand Down
4 changes: 2 additions & 2 deletions types/src/contrast.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColorTypes } from "./color";
import { Algorithms } from "./contrast/index";
import { ColorTypes } from "./color.js";
import { Algorithms } from "./contrast/index.js";

/**
* @param options Algorithm to use as well as any other options to pass to the contrast function
Expand Down
2 changes: 1 addition & 1 deletion types/src/contrast/APCA.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorTypes } from "../color";
import { ColorTypes } from "../color.js";
export default function (
background: ColorTypes,
forgeround: ColorTypes
Expand Down
2 changes: 1 addition & 1 deletion types/src/contrast/Lstar.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorTypes } from "../color";
import { ColorTypes } from "../color.js";
export default function (
background: ColorTypes,
forgeround: ColorTypes
Expand Down
2 changes: 1 addition & 1 deletion types/src/contrast/Michelson.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorTypes } from "../color";
import { ColorTypes } from "../color.js";
export default function (
background: ColorTypes,
forgeround: ColorTypes
Expand Down
2 changes: 1 addition & 1 deletion types/src/contrast/WCAG21.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorTypes } from "../color";
import { ColorTypes } from "../color.js";
export default function (
background: ColorTypes,
forgeround: ColorTypes
Expand Down
2 changes: 1 addition & 1 deletion types/src/contrast/Weber.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorTypes } from "../color";
import { ColorTypes } from "../color.js";
export default function (
background: ColorTypes,
forgeround: ColorTypes
Expand Down
2 changes: 1 addition & 1 deletion types/src/contrast/deltaPhi.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorTypes } from "../color";
import { ColorTypes } from "../color.js";
export default function (
background: ColorTypes,
forgeround: ColorTypes
Expand Down
19 changes: 10 additions & 9 deletions types/src/contrast/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export type Algorithms = keyof typeof import(".") extends `contrast${infer Alg}`
? Alg
: string;
export type Algorithms =
keyof typeof import("./index.js") extends `contrast${infer Alg}`
? Alg
: string;

export { default as contrastWCAG21 } from "./WCAG21";
export { default as contrastAPCA } from "./APCA";
export { default as contrastMichelson } from "./Michelson";
export { default as contrastWeber } from "./Weber";
export { default as contrastLstar } from "./Lstar";
export { default as contrastDeltaPhi } from "./deltaPhi";
export { default as contrastWCAG21 } from "./WCAG21.js";
export { default as contrastAPCA } from "./APCA.js";
export { default as contrastMichelson } from "./Michelson.js";
export { default as contrastWeber } from "./Weber.js";
export { default as contrastLstar } from "./Lstar.js";
export { default as contrastDeltaPhi } from "./deltaPhi.js";
4 changes: 2 additions & 2 deletions types/src/deltaE.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColorTypes } from "./color";
import { Methods } from "./deltaE/index";
import { ColorTypes } from "./color.js";
import { Methods } from "./deltaE/index.js";

/**
* @param options deltaE method to use as well as any other options to pass to the deltaE function
Expand Down
2 changes: 1 addition & 1 deletion types/src/deltaE/deltaE2000.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "../color";
import Color, { ColorObject } from "../color.js";

export default function (
color: Color | ColorObject,
Expand Down
2 changes: 1 addition & 1 deletion types/src/deltaE/deltaE76.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "../color";
import Color, { ColorObject } from "../color.js";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
Expand Down
2 changes: 1 addition & 1 deletion types/src/deltaE/deltaECMC.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "../color";
import Color, { ColorObject } from "../color.js";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject,
Expand Down
2 changes: 1 addition & 1 deletion types/src/deltaE/deltaEITP.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "../color";
import Color, { ColorObject } from "../color.js";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
Expand Down
2 changes: 1 addition & 1 deletion types/src/deltaE/deltaEJz.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "../color";
import Color, { ColorObject } from "../color.js";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
Expand Down
2 changes: 1 addition & 1 deletion types/src/deltaE/deltaEOK.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "../color";
import Color, { ColorObject } from "../color.js";
export default function (
color: Color | ColorObject,
sample: Color | ColorObject
Expand Down
14 changes: 7 additions & 7 deletions types/src/deltaE/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { default as deltaE76 } from "./deltaE76";
export { default as deltaECMC } from "./deltaECMC";
export { default as deltaE2000 } from "./deltaE2000";
export { default as deltaEJz } from "./deltaEJz";
export { default as deltaEITP } from "./deltaEITP";
export { default as deltaEOK } from "./deltaEOK";
export { default as deltaE76 } from "./deltaE76.js";
export { default as deltaECMC } from "./deltaECMC.js";
export { default as deltaE2000 } from "./deltaE2000.js";
export { default as deltaEJz } from "./deltaEJz.js";
export { default as deltaEITP } from "./deltaEITP.js";
export { default as deltaEOK } from "./deltaEOK.js";

declare const deltaEMethods: Omit<typeof import("./index"), "default">;
declare const deltaEMethods: Omit<typeof import("./index.js"), "default">;
export default deltaEMethods;

export type Methods = keyof typeof deltaEMethods extends `deltaE${infer Method}`
Expand Down
4 changes: 2 additions & 2 deletions types/src/display.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlainColorObject, ColorTypes } from "./color";
import ColorSpace from "./space";
import { PlainColorObject, ColorTypes } from "./color.js";
import ColorSpace from "./space.js";

export type Display = string & { color: PlainColorObject };

Expand Down
4 changes: 2 additions & 2 deletions types/src/distance.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Color, { ColorObject } from "./color";
import ColorSpace from "./space";
import Color, { ColorObject } from "./color.js";
import ColorSpace from "./space.js";

export default function distance(
color1: Color | ColorObject,
Expand Down
2 changes: 1 addition & 1 deletion types/src/equals.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ColorTypes } from "./color";
import { ColorTypes } from "./color.js";

export default function equals(color1: ColorTypes, color2: ColorTypes): boolean;
4 changes: 2 additions & 2 deletions types/src/get.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "./color";
import { Ref } from "./space";
import Color, { ColorObject } from "./color.js";
import { Ref } from "./space.js";

export default function get(color: Color | ColorObject, prop: Ref): number;
4 changes: 2 additions & 2 deletions types/src/getAll.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Color, { ColorObject } from "./color";
import ColorSpace from "./space";
import Color, { ColorObject } from "./color.js";
import ColorSpace from "./space.js";

export default function getAll(
color: Color | ColorObject,
Expand Down
2 changes: 1 addition & 1 deletion types/src/getColor.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { PlainColorObject, ColorTypes } from "./color";
import { PlainColorObject, ColorTypes } from "./color.js";

export default function getColor(color: ColorTypes): PlainColorObject;
4 changes: 2 additions & 2 deletions types/src/inGamut.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColorTypes } from "./color";
import ColorSpace from "./space";
import { ColorTypes } from "./color.js";
import ColorSpace from "./space.js";

export default function inGamut(
color: ColorTypes,
Expand Down
56 changes: 28 additions & 28 deletions types/src/index-fn.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
export { default as ColorSpace } from "./space";
export { default as RGBColorSpace } from "./rgbspace";
export { default as hooks, Hooks } from "./hooks";
export { default as defaults } from "./defaults";
export { default as getColor } from "./getColor";
export { default as get } from "./get";
export { default as getAll } from "./getAll";
export { default as set } from "./set";
export { default as setAll } from "./setAll";
export { default as parse } from "./parse";
export { default as to } from "./to";
export { default as serialize } from "./serialize";
export { default as display } from "./display";
export { default as inGamut } from "./inGamut";
export { default as toGamut } from "./toGamut";
export { default as distance } from "./distance";
export { default as equals } from "./equals";
export { default as contrast } from "./contrast";
export { default as clone } from "./clone";
export { getLuminance, setLuminance } from "./luminance";
export { uv, xy } from "./chromaticity";
export { default as deltaE } from "./deltaE";
export { mix, steps, range, isRange } from "./interpolation";
export { default as ColorSpace } from "./space.js";
export { default as RGBColorSpace } from "./rgbspace.js";
export { default as hooks, Hooks } from "./hooks.js";
export { default as defaults } from "./defaults.js";
export { default as getColor } from "./getColor.js";
export { default as get } from "./get.js";
export { default as getAll } from "./getAll.js";
export { default as set } from "./set.js";
export { default as setAll } from "./setAll.js";
export { default as parse } from "./parse.js";
export { default as to } from "./to.js";
export { default as serialize } from "./serialize.js";
export { default as display } from "./display.js";
export { default as inGamut } from "./inGamut.js";
export { default as toGamut } from "./toGamut.js";
export { default as distance } from "./distance.js";
export { default as equals } from "./equals.js";
export { default as contrast } from "./contrast.js";
export { default as clone } from "./clone.js";
export { getLuminance, setLuminance } from "./luminance.js";
export { uv, xy } from "./chromaticity.js";
export { default as deltaE } from "./deltaE.js";
export { mix, steps, range, isRange } from "./interpolation.js";

export * from "./contrast/index";
export * from "./deltaE/index";
export { default as deltaEMethods } from "./deltaE/index";
export * from "./variations";
export * from "./spaces/index-fn";
export * from "./contrast/index.js";
export * from "./deltaE/index.js";
export { default as deltaEMethods } from "./deltaE/index.js";
export * from "./variations.js";
export * from "./spaces/index-fn.js";
18 changes: 9 additions & 9 deletions types/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { uv, xy } from "./chromaticity";
import Color from "./color";
import contrast from "./contrast";
import { uv, xy } from "./chromaticity.js";
import Color, { ColorTypes, ToColorPrototype } from "./color.js";
import contrast from "./contrast.js";
import {
contrastWCAG21,
contrastAPCA,
contrastMichelson,
contrastWeber,
contrastLstar,
contrastDeltaPhi,
} from "./contrast/index";
import deltaE from "./deltaE";
} from "./contrast/index.js";
import deltaE from "./deltaE.js";
import deltaEMethods, {
deltaE76,
deltaECMC,
deltaE2000,
deltaEJz,
deltaEITP,
deltaEOK,
} from "./deltaE/index";
import { range, Range, MixOptions, StepsOptions } from "./interpolation";
import { getLuminance } from "./luminance";
import { lighten, darken } from "./variations";
} from "./deltaE/index.js";
import { range, Range, MixOptions, StepsOptions } from "./interpolation.js";
import { getLuminance } from "./luminance.js";
import { lighten, darken } from "./variations.js";

// Augment existing Color object
declare module "./color" {
Expand Down
6 changes: 3 additions & 3 deletions types/src/interpolation.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Color, { ColorTypes, PlainColorObject } from "./color";
import ColorSpace from "./space";
import { Methods } from "./deltaE/index";
import Color, { ColorTypes, PlainColorObject } from "./color.js";
import ColorSpace from "./space.js";
import { Methods } from "./deltaE/index.js";

export type Range = ((percentage: number) => Color) & {
rangeArgs: { colors: [Color, Color]; options: Record<string, any> };
Expand Down
2 changes: 1 addition & 1 deletion types/src/luminance.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Color, { ColorObject } from "./color";
import Color, { ColorObject } from "./color.js";

export function getLuminance(color: Color | ColorObject): number;

Expand Down
2 changes: 1 addition & 1 deletion types/src/parse.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorConstructor } from "./color";
import { ColorConstructor } from "./color.js";

export interface Options {
meta?: object | undefined;
Expand Down
2 changes: 1 addition & 1 deletion types/src/rgbspace.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ColorSpace, { Options } from "./space";
import ColorSpace, { Options } from "./space.js";

export interface RGBOptions extends Options {
toXYZ_M?: number[][] | undefined;
Expand Down
4 changes: 2 additions & 2 deletions types/src/serialize.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColorTypes } from "./color";
import { Format } from "./space";
import { ColorTypes } from "./color.js";
import { Format } from "./space.js";

export interface Options {
precision?: number | undefined;
Expand Down

0 comments on commit f71745c

Please sign in to comment.