Doesn't handle tsconfig.json with comments
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript, webpack
- Domain
- build-system
Research direction
Start by locating the source corresponding to lib/index.js and trace the two tsconfig.json reads shown in the issue. Review TypeScript's readConfigFile behavior and the supplied workaround, then verify that project-reference configs containing comments no longer produce a JSON parse error. Done means both alias-generation paths handle commented configs while preserving error handling.
Written by the indexing model from the issue text.
Description
The JSON parsing of tsconfig.json files doesn't seem to having comments in them, and errors with a JSON parse error.
Here's the patch I'm using to work around it (with patch-package):
diff --git a/node_modules/@microsoft/webpack-project-references-alias/lib/index.js b/node_modules/@microsoft/webpack-project-references-alias/lib/index.js
index f88fe3a..1d33585 100644
--- a/node_modules/@microsoft/webpack-project-references-alias/lib/index.js
+++ b/node_modules/@microsoft/webpack-project-references-alias/lib/index.js
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const functional_1 = require("./functional");
+const typescript = require("typescript");
+
function getAliasForProject(project) {
if (typeof project === "undefined") {
project = process.cwd();
@@ -33,7 +35,7 @@ const getReferencedProjectsRecursive = functional_1.memoize((tsConfigPath) => {
function getReferencedProjects(tsConfigPath) {
var _a;
const projectDir = path.dirname(tsConfigPath);
- const config = require(tsConfigPath);
+ const config = readConfigFile(tsConfigPath)
const references = (_a = config.references) === null || _a === void 0 ? void 0 : _a.map(o => o.path).map(p => path.join(projectDir, p)).map(resolveTsConfig);
return (references !== null && references !== void 0 ? references : []);
}
@@ -62,7 +64,7 @@ function tryGetPackageInfo(dir) {
}
function getAliasFor(tsConfigPath) {
const projectRootDir = path.dirname(tsConfigPath);
- const config = require(tsConfigPath);
+ const config = readConfigFile(tsConfigPath);
const hasExplicitOutDir = typeof config.compilerOptions.outDir !== "undefined";
const rootDir = path.join(projectRootDir, config.compilerOptions.rootDir || "");
const outDir = hasExplicitOutDir
@@ -82,3 +84,6 @@ function getAliasFor(tsConfigPath) {
alias[outDir] = rootDir;
return alias;
}
+function readConfigFile(tsConfigPath) {
+ return typescript.readConfigFile(tsConfigPath, path => fs.readFileSync(path, 'utf-8')).config
+}
It totally ignores errors which is naive, but good enough as a temporary workaround.
- Dominant language
- TypeScript
- Stars
- 23
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
ready
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
wheresrhys/totf#1214 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CodeChefVIT/ffcs#281 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
endora-commerce/endora-commerce#451 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
vetro-protocol/vetro-monorepo#1007 ·
Maintainers usually reply within 1 day