microsoft / webpack-project-references-alias Goto Github PK
View Code? Open in Web Editor NEWProvide alias to redirect import to project references to source files.
License: MIT License
Provide alias to redirect import to project references to source files.
License: MIT License
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.