Code Monkey home page Code Monkey logo

webpack-project-references-alias's Issues

Doesn't handle tsconfig.json with comments

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.