Skip to content

Commit

Permalink
feat: add nx 13 support in dep-graph patchers (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokub committed May 16, 2022
1 parent e303227 commit 746e4ea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
21 changes: 17 additions & 4 deletions libs/nuxt/patch-nx-dep-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ const path = require('path');
* @see https://github.com/nrwl/nx/issues/2960
*/
function patchNxDepGraph() {
const filePath = path.join(
process.env.INIT_CWD || '',
'node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js'
);
try {
const filePath = getFilePath();
const fileContent = fs.readFileSync(filePath).toString('utf-8');
const replacement = "extension !== '.ts' && extension !== '.vue'";
if (fileContent.includes(replacement)) {
Expand All @@ -26,4 +23,20 @@ function patchNxDepGraph() {
}
}

function getFilePath() {
const possiblePaths = [
'node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js', // for Nx >= 13.10.3
'node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js', // for older versions of Nx
];

for (const p of possiblePaths) {
const fullPath = path.join(process.env.INIT_CWD || '', p);
if (fs.existsSync(fullPath)) {
return fullPath;
}
}

throw new Error("Could not find Nx's dep-graph builder in node_modules");
}

patchNxDepGraph();
21 changes: 17 additions & 4 deletions libs/vite/patch-nx-dep-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ const path = require('path');
* @see https://github.com/nrwl/nx/issues/2960
*/
function patchNxDepGraph() {
const filePath = path.join(
process.env.INIT_CWD || '',
'node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js'
);
try {
const filePath = getFilePath();
const fileContent = fs.readFileSync(filePath).toString('utf-8');
const replacement = "extension !== '.ts' && extension !== '.vue'";
if (fileContent.includes(replacement)) {
Expand All @@ -26,4 +23,20 @@ function patchNxDepGraph() {
}
}

function getFilePath() {
const possiblePaths = [
'node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js', // for Nx >= 13.10.3
'node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js', // for older versions of Nx
];

for (const p of possiblePaths) {
const fullPath = path.join(process.env.INIT_CWD || '', p);
if (fs.existsSync(fullPath)) {
return fullPath;
}
}

throw new Error("Could not find Nx's dep-graph builder in node_modules");
}

patchNxDepGraph();
21 changes: 17 additions & 4 deletions libs/vue/patch-nx-dep-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ const path = require('path');
* @see https://github.com/nrwl/nx/issues/2960
*/
function patchNxDepGraph() {
const filePath = path.join(
process.env.INIT_CWD || '',
'node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js'
);
try {
const filePath = getFilePath();
const fileContent = fs.readFileSync(filePath).toString('utf-8');
const replacement = "extension !== '.ts' && extension !== '.vue'";
if (fileContent.includes(replacement)) {
Expand All @@ -26,4 +23,20 @@ function patchNxDepGraph() {
}
}

function getFilePath() {
const possiblePaths = [
'node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js', // for Nx >= 13.10.3
'node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js', // for older versions of Nx
];

for (const p of possiblePaths) {
const fullPath = path.join(process.env.INIT_CWD || '', p);
if (fs.existsSync(fullPath)) {
return fullPath;
}
}

throw new Error("Could not find Nx's dep-graph builder in node_modules");
}

patchNxDepGraph();

0 comments on commit 746e4ea

Please sign in to comment.