Skip to content

Commit

Permalink
Merge pull request #16890 from stof/fix_type_generator
Browse files Browse the repository at this point in the history
[Type-definitions] Fix type generator to support import maps
  • Loading branch information
Snuffleupagus authored Sep 1, 2023
2 parents b5c8849 + 46f2c58 commit 87ea2ed
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 14 deletions.
23 changes: 9 additions & 14 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ function createWebpackConfig(
viewerAlias["web-com"] = "web/chromecom.js";
viewerAlias["web-print_service"] = "web/pdf_print_service.js";
} else if (bundleDefines.GENERIC) {
// Aliases defined here must also be replicated in the paths section of
// the tsconfig.json file for the type generation to work.
// In the tsconfig.json files, the .js extension must be omitted.
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
libraryAlias["display-l10n_utils"] = "web/l10n_utils.js";
libraryAlias["display-network"] = "src/display/network.js";
Expand Down Expand Up @@ -1549,20 +1552,11 @@ gulp.task("jsdoc", function (done) {

gulp.task("types", function (done) {
console.log("### Generating TypeScript definitions using `tsc`");
const args = [
"target ESNext",
"allowJS",
"declaration",
`outDir ${TYPES_DIR}`,
"strict",
"esModuleInterop",
"forceConsistentCasingInFileNames",
"emitDeclarationOnly",
"moduleResolution node",
].join(" --");
exec(
`"node_modules/.bin/tsc" --${args} src/pdf.js web/pdf_viewer.component.js`,
done
`"node_modules/.bin/tsc" --outDir ${TYPES_DIR} --project .`,
function () {
exec(`"node_modules/.bin/tsc-alias" --outDir ${TYPES_DIR}`, done);
}
);
});

Expand Down Expand Up @@ -2475,6 +2469,7 @@ gulp.task(
"ci-test",
gulp.series(
gulp.parallel("lint", "externaltest", "unittestcli"),
"lint-chromium"
"lint-chromium",
"typestest"
)
);
256 changes: 256 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"stylelint-prettier": "^4.0.2",
"terser": "^5.19.2",
"through2": "^4.0.2",
"tsc-alias": "^1.8.7",
"ttest": "^4.0.0",
"typescript": "^5.1.6",
"typogr": "^0.6.8",
Expand Down
25 changes: 25 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ESNext",
"allowJs": true,
"declaration": true,
"strict": true,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"paths": {
"display-fetch_stream": ["./src/display/fetch_stream"],
"display-l10n_utils": ["./web/l10n_utils"],
"display-network": ["./src/display/network"],
"display-node_stream": ["./src/display/node_stream"],
"display-node_utils": ["./src/display/node_utils"],
"display-svg": ["./src/display/svg"],
"pdfjs-lib": ["./src/pdf"]
}
},
"files": [
"src/pdf.js",
"web/pdf_viewer.component.js"
]
}

0 comments on commit 87ea2ed

Please sign in to comment.