Skip to content

Commit

Permalink
fix: fix TS module augmentation in plugins (close #132)
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed Jun 1, 2023
1 parent 7267c31 commit 253a017
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 71 deletions.
11 changes: 11 additions & 0 deletions fixup-dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ function fixupCssDefinitions(file) {
writeFile(`${file}.d.ts`, ["declare const styles: unknown;", "export default styles;"].join(os.EOL));
}

function fixupModuleAugmentation(file) {
editFile(file, (data) => {
const regex = /declare module "\.\.\/\.\.\/types.js"/g;
return data.replaceAll(regex, 'declare module "yet-another-react-lightbox"');
});
}

function fixup(watchMode) {
try {
fixupMainBundle(`${ROOT}/index.js`);
Expand All @@ -58,6 +65,10 @@ function fixup(watchMode) {
fixupCssDefinitions(file);
});

globSync(`${ROOT}/plugins/**/index.d.ts`).forEach((file) => {
fixupModuleAugmentation(file);
});

globSync(`${ROOT}/**/*-*.{js,d\\.ts}`).forEach((file) => {
// eslint-disable-next-line no-console
console.error(`Unexpected chunk: ${file}${os.EOL}`);
Expand Down
92 changes: 46 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"@vitejs/plugin-react": "^4.0.0",
"@vitest/coverage-c8": "^0.31.2",
"@vitest/ui": "^0.31.2",
"@vitest/coverage-c8": "^0.31.4",
"@vitest/ui": "^0.31.4",
"autoprefixer": "^10.4.14",
"chokidar": "^3.5.3",
"cssnano": "^6.0.1",
Expand Down Expand Up @@ -212,7 +212,7 @@
"sass": "^1.62.1",
"typescript": "^5.0.4",
"vite": "^4.3.9",
"vitest": "^0.31.2"
"vitest": "^0.31.4"
},
"keywords": [
"react",
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/captions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { Callback, PLUGIN_CAPTIONS, RenderFunction } from "../../index.js";
import { Captions } from "./Captions.js";

declare module "../../types.js" {
export type TextAlignment = "start" | "end" | "center";

// noinspection JSUnusedGlobalSymbols
interface GenericSlide {
/** slide title */
Expand All @@ -28,7 +26,7 @@ declare module "../../types.js" {
/** if `true`, show Captions Toggle button in the toolbar */
showToggle?: boolean;
/** description text alignment */
descriptionTextAlign?: TextAlignment;
descriptionTextAlign?: "start" | "end" | "center";
/** maximum number of lines to display in the description section */
descriptionMaxLines?: number;
};
Expand Down Expand Up @@ -57,7 +55,7 @@ declare module "../../types.js" {
}

/** Captions plugin ref */
export interface CaptionsRef {
interface CaptionsRef {
/** if `true`, captions are visible */
visible: boolean;
/** show captions */
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/download/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ declare module "../../types.js" {
iconDownload?: RenderFunction;
}

// noinspection JSUnusedGlobalSymbols
interface Callbacks {
/** a callback called on slide download */
download?: Callback<DownloadCallbackProps>;
Expand All @@ -44,11 +45,11 @@ declare module "../../types.js" {
[PLUGIN_DOWNLOAD]: null;
}

export interface DownloadCallbackProps {
interface DownloadCallbackProps {
index: number;
}

export interface DownloadFunctionProps {
interface DownloadFunctionProps {
slide: Slide;
saveAs: (source: string | Blob, name?: string) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/download/props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LightboxProps } from "../../types.js";
import { LightboxProps } from "../../index.js";

export const defaultDownloadProps = {
download: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/fullscreen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare module "../../types.js" {
}

/** Fullscreen plugin ref */
export interface FullscreenRef {
interface FullscreenRef {
/** current fullscreen status */
fullscreen: boolean;
/** if `true`, fullscreen features are not available */
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/share/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ declare module "../../types.js" {
iconShare?: RenderFunction;
}

// noinspection JSUnusedGlobalSymbols
interface Callbacks {
/** a callback called on slide share */
share?: Callback<ShareCallbackProps>;
}

// noinspection JSUnusedGlobalSymbols
interface ToolbarButtonKeys {
[PLUGIN_SHARE]: null;
}

export interface ShareCallbackProps {
interface ShareCallbackProps {
index: number;
}

export interface ShareFunctionProps {
interface ShareFunctionProps {
slide: Slide;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/share/props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LightboxProps } from "../../types.js";
import { LightboxProps } from "../../index.js";

export const defaultShareProps = {
share: undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/slideshow/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";

import { Callback, RenderFunction, PLUGIN_SLIDESHOW } from "../../index.js";
import { Callback, PLUGIN_SLIDESHOW, RenderFunction } from "../../index.js";
import { Slideshow } from "./Slideshow.js";

declare module "../../types.js" {
Expand Down Expand Up @@ -39,7 +39,7 @@ declare module "../../types.js" {
}

/** Slideshow plugin ref */
export interface SlideshowRef {
interface SlideshowRef {
/** current slideshow playback status */
playing: boolean;
/** if `true`, the slideshow playback is disabled */
Expand Down
Loading

0 comments on commit 253a017

Please sign in to comment.