Skip to content

Commit a40723f

Browse files
committed
feat: changes NX project.json detection to rely on the user config for their package path
1 parent 204bc37 commit a40723f

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

src/helpers/fixOutputDir.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const fixOutputDir = async function ({
1111
IS_LOCAL,
1212
netlifyConfig,
1313
workspaceType,
14+
packagePath,
1415
}) {
15-
const angularJson = getAngularJson({ failPlugin, siteRoot, workspaceType })
16+
const angularJson = getAngularJson({ failPlugin, siteRoot, workspaceType, packagePath })
1617
const project = getProject(angularJson, failBuild, workspaceType === 'nx')
1718

1819
const { outputPath } = workspaceType === 'nx' ? project.targets.build.options : project.architect.build.options

src/helpers/getAngularJson.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,24 @@ const { existsSync, readJsonSync } = require('fs-extra')
99
* @param {string} obj.siteRoot Root directory of an app
1010
* @param {(msg: string) => never} obj.failPlugin Function to fail the plugin
1111
* @param {'nx' | 'default'} obj.workspaceType Type of monorepo, dictates what json file to open
12+
* @param {string} obj.packagePath The path to the package directory
1213
*
1314
* @returns {any}
1415
*/
15-
const getAngularJson = function ({ failPlugin, siteRoot, workspaceType }) {
16+
const getAngularJson = function ({ failPlugin, siteRoot, workspaceType, packagePath }) {
1617
if (workspaceType === 'nx') {
17-
const selectedProject = process.env.ANGULAR_PROJECT
18-
19-
if (!selectedProject) {
18+
if ((packagePath ?? '').length === 0) {
2019
return failPlugin(
21-
`The ANGULAR_PROJECT environment variable is not set. This is needed to determine the project.json to load in an NX workspace`,
20+
`packagePath must be set to the location of the package.json being built when deploying an NX monorepo, e.g. "apps/{project-name}"`,
2221
)
2322
}
2423

25-
if (!existsSync(join(siteRoot, 'apps', selectedProject, 'project.json'))) {
26-
return failPlugin(`No project.json found in apps/${selectedProject}`)
24+
if (!existsSync(join(siteRoot, packagePath, 'project.json'))) {
25+
return failPlugin(`No project.json found in ${packagePath}`)
2726
}
2827

2928
try {
30-
return readJsonSync(join(siteRoot, 'apps', selectedProject, 'project.json'))
29+
return readJsonSync(join(siteRoot, packagePath, 'project.json'))
3130
} catch {
3231
return failPlugin(`Could not parse the contents of project.json`)
3332
}

src/helpers/serverModuleHelpers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,18 @@ const guessUsedEngine = function (serverModuleContents) {
9696
* @param {string} obj.siteRoot Root directory of an app
9797
* @param {(msg: string) => never} obj.failPlugin Function to fail the plugin
9898
* @param {'nx' | 'default'} obj.workspaceType The workspace type being parsed
99+
* @param {string} obj.packagePath The path to the package directory
99100
* * @param {(msg: string) => never} obj.failBuild Function to fail the build
100101
*
101102
* @returns {'AppEngine' | 'CommonEngine' | undefined}
102103
*/
103-
const fixServerTs = async function ({ angularVersion, siteRoot, failPlugin, failBuild, workspaceType }) {
104+
const fixServerTs = async function ({ angularVersion, siteRoot, failPlugin, failBuild, workspaceType, packagePath }) {
104105
if (!satisfies(angularVersion, '>=19.0.0-rc', { includePrerelease: true })) {
105106
// for pre-19 versions, we don't need to do anything
106107
return
107108
}
108109

109-
const angularJson = getAngularJson({ failPlugin, siteRoot, workspaceType })
110+
const angularJson = getAngularJson({ failPlugin, siteRoot, workspaceType, packagePath })
110111

111112
const project = getProject(angularJson, failBuild, workspaceType === 'nx')
112113
const build = workspaceType === 'nx' ? project.targets.build : project.architect.build

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ module.exports = {
3737
IS_LOCAL: constants.IS_LOCAL,
3838
netlifyConfig,
3939
workspaceType,
40+
packagePath: constants.PACKAGE_PATH,
4041
})
4142

42-
usedEngine = await fixServerTs({ angularVersion, siteRoot, failPlugin, failBuild, workspaceType })
43+
usedEngine = await fixServerTs({
44+
angularVersion,
45+
siteRoot,
46+
failPlugin,
47+
failBuild,
48+
workspaceType,
49+
packagePath: constants.PACKAGE_PATH,
50+
})
4351
},
4452
async onBuild({ utils, netlifyConfig, constants }) {
4553
await revertServerTsFix()
@@ -50,7 +58,7 @@ module.exports = {
5058
const { failBuild, failPlugin } = utils.build
5159

5260
const { siteRoot, workspaceType } = getAngularRoot({ failBuild, netlifyConfig, onBuild: true })
53-
const angularJson = getAngularJson({ failPlugin, siteRoot, workspaceType })
61+
const angularJson = getAngularJson({ failPlugin, siteRoot, workspaceType, packagePath: constants.PACKAGE_PATH })
5462

5563
const project = getProject(angularJson, failBuild, workspaceType === 'nx')
5664
const build = workspaceType === 'nx' ? project.targets.build : project.architect.build

0 commit comments

Comments
 (0)