From 61ed77cfb4baf530c2814066ab2c9cbdd42e4328 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Fri, 10 Nov 2023 17:27:04 +0900 Subject: [PATCH] Rename *.d.ts to *.d.mts. Close #17241 Add a type test for legacy. - https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution --- .../dist/legacy/build/{pdf.d.ts => pdf.d.mts} | 0 external/dist/legacy/web/pdf_viewer.d.mts | 1 + external/dist/legacy/web/pdf_viewer.d.ts | 1 - external/dist/web/pdf_viewer.d.mts | 1 + external/dist/web/pdf_viewer.d.ts | 1 - gulpfile.mjs | 10 ++++---- test/types/legacy.ts | 23 +++++++++++++++++++ test/types/{main.ts => modern.ts} | 2 +- test/types/package.json | 6 +++++ test/types/tsconfig.json | 8 +++---- 10 files changed, 41 insertions(+), 12 deletions(-) rename external/dist/legacy/build/{pdf.d.ts => pdf.d.mts} (100%) create mode 100644 external/dist/legacy/web/pdf_viewer.d.mts delete mode 100644 external/dist/legacy/web/pdf_viewer.d.ts create mode 100644 external/dist/web/pdf_viewer.d.mts delete mode 100644 external/dist/web/pdf_viewer.d.ts create mode 100644 test/types/legacy.ts rename test/types/{main.ts => modern.ts} (90%) create mode 100644 test/types/package.json diff --git a/external/dist/legacy/build/pdf.d.ts b/external/dist/legacy/build/pdf.d.mts similarity index 100% rename from external/dist/legacy/build/pdf.d.ts rename to external/dist/legacy/build/pdf.d.mts diff --git a/external/dist/legacy/web/pdf_viewer.d.mts b/external/dist/legacy/web/pdf_viewer.d.mts new file mode 100644 index 000000000..7c2b79fba --- /dev/null +++ b/external/dist/legacy/web/pdf_viewer.d.mts @@ -0,0 +1 @@ +export * from "../../types/web/pdf_viewer.component.js"; diff --git a/external/dist/legacy/web/pdf_viewer.d.ts b/external/dist/legacy/web/pdf_viewer.d.ts deleted file mode 100644 index 68c686d1b..000000000 --- a/external/dist/legacy/web/pdf_viewer.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "../../types/web/pdf_viewer.component"; diff --git a/external/dist/web/pdf_viewer.d.mts b/external/dist/web/pdf_viewer.d.mts new file mode 100644 index 000000000..0350ce49b --- /dev/null +++ b/external/dist/web/pdf_viewer.d.mts @@ -0,0 +1 @@ +export * from "../types/web/pdf_viewer.component.js"; diff --git a/external/dist/web/pdf_viewer.d.ts b/external/dist/web/pdf_viewer.d.ts deleted file mode 100644 index 181142b65..000000000 --- a/external/dist/web/pdf_viewer.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "../types/web/pdf_viewer.component"; diff --git a/gulpfile.mjs b/gulpfile.mjs index 2de6f1f8b..c86696d5f 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -1846,11 +1846,11 @@ gulp.task( return merge([ packageJson().pipe(gulp.dest(TYPESTEST_DIR)), gulp - .src([ - GENERIC_DIR + "build/pdf.mjs", - GENERIC_DIR + "build/pdf.worker.mjs", - ]) - .pipe(gulp.dest(TYPESTEST_DIR + "build/")), + .src("external/dist/**/*", { + base: "external/dist", + removeBOM: false, + }) + .pipe(gulp.dest(TYPESTEST_DIR)), gulp .src(TYPES_DIR + "**/*", { base: TYPES_DIR }) .pipe(gulp.dest(TYPESTEST_DIR + "types/")), diff --git a/test/types/legacy.ts b/test/types/legacy.ts new file mode 100644 index 000000000..5a09b683d --- /dev/null +++ b/test/types/legacy.ts @@ -0,0 +1,23 @@ +import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs"; +import { EventBus } from "pdfjs-dist/legacy/web/pdf_viewer.mjs"; + +class MainTest { + eventBus: EventBus; + task: ReturnType | undefined; + + constructor(public file: string) { + this.eventBus = new EventBus(); + } + + loadPdf() { + this.task = getDocument("file://" + this.file); + return this.task.promise; + } +} + +// This is actually never called, as the test only consists in compiling the file. +// The compilation will crawl through all files and make sure that the types are consistent. +const mt = new MainTest("../pdfs/basicapi.pdf"); +mt.loadPdf().then(() => { + console.log("loaded"); +}); diff --git a/test/types/main.ts b/test/types/modern.ts similarity index 90% rename from test/types/main.ts rename to test/types/modern.ts index e0b30eb5d..06b892c91 100644 --- a/test/types/main.ts +++ b/test/types/modern.ts @@ -1,5 +1,5 @@ import { getDocument } from "pdfjs-dist"; -import { EventBus } from "pdfjs-dist/web/pdf_viewer.component"; +import { EventBus } from "pdfjs-dist/web/pdf_viewer.mjs"; class MainTest { eventBus: EventBus; diff --git a/test/types/package.json b/test/types/package.json new file mode 100644 index 000000000..bfd9e4181 --- /dev/null +++ b/test/types/package.json @@ -0,0 +1,6 @@ +{ + "type": "module", + "dependencies": { + "pdfjs-dist": "../../build/typestest/" + } +} diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json index 532627c64..7413876b9 100644 --- a/test/types/tsconfig.json +++ b/test/types/tsconfig.json @@ -3,7 +3,7 @@ "outDir": "../../build/tmp", "sourceMap": true, "declaration": false, - "moduleResolution": "node", + "moduleResolution": "node10", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "ESNext", @@ -17,10 +17,10 @@ ], "paths": { "pdfjs-dist": ["../../build/typestest"], - "pdfjs-dist/*": ["../../build/typestest/types/*"] + "pdfjs-dist/*": ["../../build/typestest/*"] } }, - "files": [ - "main.ts" + "exclude": [ + "node_modules" ] }