-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): prefix outputs and warn on non-prefixed outputs (#12470)
- Loading branch information
1 parent
74e898d
commit 834e2db
Showing
23 changed files
with
537 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; | ||
import type { Tree } from '../../generators/tree'; | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
readWorkspaceConfiguration, | ||
updateWorkspaceConfiguration, | ||
} from '../../generators/utils/project-configuration'; | ||
import { writeJson } from '../../generators/utils/json'; | ||
import prefixOutputs from './prefix-outputs'; | ||
import { validateOutputs } from 'nx/src/tasks-runner/utils'; | ||
|
||
describe('15.0.0 migration (prefix-outputs)', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should prefix project outputs', async () => { | ||
addProjectConfiguration(tree, 'proj', { | ||
root: 'proj', | ||
targets: { | ||
build: { | ||
executor: 'nx:run-commands', | ||
outputs: [ | ||
'dist', | ||
'dist/{projectRoot}', | ||
'dist/{projectRoot}/**/*.js', | ||
'proj/coverage', | ||
'./test-results', | ||
'{projectRoot}/build', | ||
'{options.outputDirectory}', | ||
], | ||
options: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
await prefixOutputs(tree); | ||
|
||
const updated = readProjectConfiguration(tree, 'proj'); | ||
|
||
expect(updated.targets.build.outputs).toEqual([ | ||
'{workspaceRoot}/dist', | ||
'{workspaceRoot}/dist/{projectRoot}', | ||
'{workspaceRoot}/dist/{projectRoot}/**/*.js', | ||
'{projectRoot}/coverage', | ||
'{projectRoot}/test-results', | ||
'{projectRoot}/build', | ||
'{options.outputDirectory}', | ||
]); | ||
|
||
expect(() => validateOutputs(updated.targets.build.outputs)).not.toThrow(); | ||
}); | ||
|
||
it('should prefix target default outputs', async () => { | ||
const workspace = readWorkspaceConfiguration(tree); | ||
updateWorkspaceConfiguration(tree, { | ||
...workspace, | ||
targetDefaults: { | ||
build: { | ||
outputs: ['dist', '{projectRoot}/build', '{options.outputPath}'], | ||
}, | ||
}, | ||
}); | ||
|
||
await prefixOutputs(tree); | ||
|
||
const updated = readWorkspaceConfiguration(tree); | ||
|
||
expect(updated.targetDefaults).toMatchInlineSnapshot(` | ||
Object { | ||
"build": Object { | ||
"outputs": Array [ | ||
"{workspaceRoot}/dist", | ||
"{projectRoot}/build", | ||
"{options.outputPath}", | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('should not error for package.json projects', async () => { | ||
writeJson(tree, 'proj/package.json', { | ||
name: 'proj', | ||
scripts: { | ||
build: 'echo', | ||
}, | ||
}); | ||
tree.delete('workspace.json'); | ||
|
||
await prefixOutputs(tree); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; | ||
import { | ||
getProjects, | ||
readWorkspaceConfiguration, | ||
updateProjectConfiguration, | ||
updateWorkspaceConfiguration, | ||
} from '../../generators/utils/project-configuration'; | ||
import { joinPathFragments } from '../../utils/path'; | ||
import { relative } from 'path'; | ||
import { | ||
transformLegacyOutputs, | ||
validateOutputs, | ||
} from 'nx/src/tasks-runner/utils'; | ||
|
||
export default async function (tree: Tree) { | ||
// If the workspace doesn't have a nx.json, don't make any changes | ||
if (!tree.exists('nx.json')) { | ||
return; | ||
} | ||
|
||
const workspaceConfiguration = readWorkspaceConfiguration(tree); | ||
|
||
for (const [projectName, project] of getProjects(tree)) { | ||
if (!project.targets) { | ||
continue; | ||
} | ||
|
||
for (const [_, target] of Object.entries(project.targets)) { | ||
if (!target.outputs) { | ||
continue; | ||
} | ||
|
||
try { | ||
validateOutputs(target.outputs); | ||
} catch (e) { | ||
target.outputs = transformLegacyOutputs(project.root, e); | ||
} | ||
} | ||
updateProjectConfiguration(tree, projectName, project); | ||
} | ||
|
||
if (workspaceConfiguration.targetDefaults) { | ||
for (const [_, target] of Object.entries( | ||
workspaceConfiguration.targetDefaults | ||
)) { | ||
if (!target.outputs) { | ||
continue; | ||
} | ||
|
||
target.outputs = target.outputs.map((output) => { | ||
return /^{[\s\S]+}/.test(output) | ||
? output | ||
: joinPathFragments('{workspaceRoot}', output); | ||
}); | ||
} | ||
|
||
updateWorkspaceConfiguration(tree, workspaceConfiguration); | ||
} | ||
|
||
await formatChangedFilesWithPrettierIfAvailable(tree); | ||
} |
Oops, something went wrong.
834e2db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app