From 746e4eab384d4f2968a6abb9cf27061348c8debc Mon Sep 17 00:00:00 2001 From: Boris K Date: Mon, 16 May 2022 22:57:46 +0200 Subject: [PATCH] feat: add nx 13 support in dep-graph patchers (#249) --- libs/nuxt/patch-nx-dep-graph.js | 21 +++++++++++++++++---- libs/vite/patch-nx-dep-graph.js | 21 +++++++++++++++++---- libs/vue/patch-nx-dep-graph.js | 21 +++++++++++++++++---- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/libs/nuxt/patch-nx-dep-graph.js b/libs/nuxt/patch-nx-dep-graph.js index c9d5d80c..b0f144b8 100644 --- a/libs/nuxt/patch-nx-dep-graph.js +++ b/libs/nuxt/patch-nx-dep-graph.js @@ -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)) { @@ -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(); diff --git a/libs/vite/patch-nx-dep-graph.js b/libs/vite/patch-nx-dep-graph.js index c9d5d80c..b0f144b8 100644 --- a/libs/vite/patch-nx-dep-graph.js +++ b/libs/vite/patch-nx-dep-graph.js @@ -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)) { @@ -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(); diff --git a/libs/vue/patch-nx-dep-graph.js b/libs/vue/patch-nx-dep-graph.js index c9d5d80c..b0f144b8 100644 --- a/libs/vue/patch-nx-dep-graph.js +++ b/libs/vue/patch-nx-dep-graph.js @@ -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)) { @@ -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();