Skip to content

Commit

Permalink
fix(strapi): Use cached project graph for withNx (#197)
Browse files Browse the repository at this point in the history
This will also make it work when extending the project graph
  • Loading branch information
TriPSs authored Dec 13, 2023
2 parents 9f3c6de + afc270f commit a6dd48e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/strapi/src/with-nx.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { parseTargetString, workspaceRoot } from '@nx/devkit'
import { readCachedProjectGraph } from '@nx/workspace/src/core/project-graph'
import path from 'node:path'
import { FsTree } from 'nx/src/generators/tree'
import { getProjects } from 'nx/src/generators/utils/project-configuration'

export function withNx(config: any, webpack: any) {
const nxProject = process.env.NX_TASK_TARGET_PROJECT

if (!nxProject) {
throw new Error('Not running with NX?')
}
const projectGraph = readCachedProjectGraph()
const projectNode = projectGraph.nodes[nxProject]

const nxTree = new FsTree(workspaceRoot, false)
const projects = getProjects(nxTree)
const project = projects.get(nxProject)

if (!project) {
if (!projectNode) {
throw new Error(`Project "${nxProject}" not found!`)
}

const project = projectNode.data
const target = project.targets[process.env.NX_TASK_TARGET_TARGET]

const isServing = target.executor === '@nx-extend/strapi:serve'
@@ -37,7 +34,7 @@ export function withNx(config: any, webpack: any) {

if (!outputPath && options.buildTarget) {
const buildTarget = parseTargetString(options.buildTarget, readCachedProjectGraph())
outputPath = projects.get(buildTarget.project).targets[buildTarget.target].options.outputPath
outputPath = projectGraph.nodes[buildTarget.project].data.targets[buildTarget.target].options.outputPath
}

if (!outputPath) {

0 comments on commit a6dd48e

Please sign in to comment.