Skip to content

Commit

Permalink
Add support for the import map in the type generator
Browse files Browse the repository at this point in the history
The typescript compiler is now configured to know about the import map
to be able to resolve those imports and find the associated types.
As tsc outputs declaration files using the original module identifiers
and not the resolved ones, tsc-alias is used to post-process the
declaration files by resolving those paths.
  • Loading branch information
stof committed Aug 31, 2023
1 parent d0bee1b commit 53829fe
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 2 deletions.
10 changes: 9 additions & 1 deletion 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 @@ -1551,7 +1554,12 @@ gulp.task("types", function (done) {
console.log("### Generating TypeScript definitions using `tsc`");
exec(
`"node_modules/.bin/tsc" --outDir ${TYPES_DIR} --project .`,
done
function() {
exec(
`"node_modules/.bin/tsc-alias" --outDir ${TYPES_DIR}`,
done
)
}
);
});

Expand Down
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
13 changes: 12 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
"emitDeclarationOnly": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"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"],
"web-com": ["./web/genericcom"],
"web-print_service": ["./web/pdf_print_service"],
"pdfjs-lib": ["./src/pdf"]
}
},
"files": [
"src/pdf.js",
Expand Down

0 comments on commit 53829fe

Please sign in to comment.