fix(core): remove leading ./ when normalizing root project outputs
This commit is contained in:
parent
7daa2eb380
commit
40b39b2e64
@ -40,7 +40,7 @@ Here's the `project.json` file for your `shared-ui` project:
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "shared/ui/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -157,7 +157,7 @@ Here are the outputs defined for the `shared-ui` project:
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "shared/ui/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -24,7 +24,7 @@ Here's the `project.json` file for your `common-ui` project:
|
||||
"targets": {
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/common-ui/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -89,7 +89,7 @@ Outputs are defined for every target in your workspace:
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/products/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -14215,7 +14215,7 @@
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "graph/ui-graph/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -11,9 +11,7 @@ describe('Jest root projects', () => {
|
||||
|
||||
it('should test root level app projects', async () => {
|
||||
runCLI(`generate @nrwl/angular:app ${myapp} --rootProject=true`);
|
||||
|
||||
const rootProjectTestResults = await runCLIAsync(`test ${myapp}`);
|
||||
|
||||
expect(rootProjectTestResults.combinedOutput).toContain(
|
||||
'Test Suites: 1 passed, 1 total'
|
||||
);
|
||||
|
||||
@ -331,7 +331,7 @@ describe('Nx Affected and Graph Tests', () => {
|
||||
target: 'test',
|
||||
},
|
||||
command: `${runNx} run ${myapp}:test`,
|
||||
outputs: [`coverage/apps/${myapp}`],
|
||||
outputs: [`coverage/${myapp}`],
|
||||
});
|
||||
compareTwoArrays(resWithTarget.projects, [myapp]);
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "graph/ui-graph/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -214,7 +214,7 @@ Object {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -385,7 +385,7 @@ Object {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@ -222,7 +222,7 @@ Object {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -393,7 +393,7 @@ Object {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@ -117,7 +117,7 @@ Object {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
@ -74,7 +74,7 @@ describe('jestProject', () => {
|
||||
const lib1 = readProjectConfiguration(tree, 'lib1');
|
||||
expect(lib1.targets.test).toEqual({
|
||||
executor: '@nrwl/jest:jest',
|
||||
outputs: ['{workspaceRoot}/coverage/{projectRoot}'],
|
||||
outputs: ['{workspaceRoot}/coverage/{projectName}'],
|
||||
options: {
|
||||
jestConfig: 'libs/lib1/jest.config.ts',
|
||||
passWithNoTests: true,
|
||||
|
||||
@ -12,7 +12,7 @@ export function updateWorkspace(tree: Tree, options: JestProjectSchema) {
|
||||
projectConfig.targets.test = {
|
||||
executor: '@nrwl/jest:jest',
|
||||
outputs: [
|
||||
joinPathFragments('{workspaceRoot}', 'coverage', '{projectRoot}'),
|
||||
joinPathFragments('{workspaceRoot}', 'coverage', '{projectName}'),
|
||||
],
|
||||
options: {
|
||||
jestConfig: joinPathFragments(
|
||||
|
||||
@ -87,7 +87,7 @@ describe('@nrwl/linter:workspace-rules-project', () => {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@ -34,7 +34,7 @@ describe('lib', () => {
|
||||
});
|
||||
expect(workspaceJson.projects[libFileName].architect.test).toEqual({
|
||||
builder: '@nrwl/jest:jest',
|
||||
outputs: [`{workspaceRoot}/coverage/{projectRoot}`],
|
||||
outputs: [`{workspaceRoot}/coverage/{projectName}`],
|
||||
options: {
|
||||
jestConfig: `libs/${libFileName}/jest.config.ts`,
|
||||
passWithNoTests: true,
|
||||
|
||||
@ -38,7 +38,7 @@ describe('lib', () => {
|
||||
});
|
||||
expect(workspaceJson.projects['my-lib'].architect.test).toEqual({
|
||||
builder: '@nrwl/jest:jest',
|
||||
outputs: ['{workspaceRoot}/coverage/{projectRoot}'],
|
||||
outputs: ['{workspaceRoot}/coverage/{projectName}'],
|
||||
options: {
|
||||
jestConfig: 'libs/my-lib/jest.config.ts',
|
||||
passWithNoTests: true,
|
||||
|
||||
@ -80,7 +80,7 @@ describe('NxPlugin Plugin Generator', () => {
|
||||
});
|
||||
expect(project.targets.test).toEqual({
|
||||
executor: '@nrwl/jest:jest',
|
||||
outputs: ['{workspaceRoot}/coverage/{projectRoot}'],
|
||||
outputs: ['{workspaceRoot}/coverage/{projectName}'],
|
||||
options: {
|
||||
jestConfig: 'libs/my-plugin/jest.config.ts',
|
||||
passWithNoTests: true,
|
||||
|
||||
@ -56,7 +56,7 @@ describe('utils', () => {
|
||||
).toEqual(['one', 'myapp/two', 'myapp/three']);
|
||||
});
|
||||
|
||||
it('should interpolate {projectRoot} when it is not in front', () => {
|
||||
it('should interpolate {projectRoot} when it is not at the beginning', () => {
|
||||
expect(
|
||||
getOutputsForTargetAndConfiguration(
|
||||
task,
|
||||
@ -67,6 +67,55 @@ describe('utils', () => {
|
||||
).toEqual(['dist/myapp']);
|
||||
});
|
||||
|
||||
it('should throw when {workspaceRoot} is used not at the beginning', () => {
|
||||
expect(() =>
|
||||
getOutputsForTargetAndConfiguration(
|
||||
task,
|
||||
getNode({
|
||||
outputs: ['test/{workspaceRoot}/dist'],
|
||||
})
|
||||
)
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should interpolate {projectRoot} = . by removing the slash after it', () => {
|
||||
const data = {
|
||||
name: 'myapp',
|
||||
type: 'app',
|
||||
data: {
|
||||
root: '.',
|
||||
targets: {
|
||||
build: {
|
||||
outputs: ['{projectRoot}/dist'],
|
||||
},
|
||||
},
|
||||
files: [],
|
||||
},
|
||||
};
|
||||
expect(getOutputsForTargetAndConfiguration(task, data as any)).toEqual([
|
||||
'dist',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should throw when {projectRoot} is used not at the beginning and the value is .', () => {
|
||||
const data = {
|
||||
name: 'myapp',
|
||||
type: 'app',
|
||||
data: {
|
||||
root: '.',
|
||||
targets: {
|
||||
build: {
|
||||
outputs: ['test/{projectRoot}'],
|
||||
},
|
||||
},
|
||||
files: [],
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
getOutputsForTargetAndConfiguration(task, data as any)
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should support interpolation based on options', () => {
|
||||
expect(
|
||||
getOutputsForTargetAndConfiguration(
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { flatten } from 'flat';
|
||||
import { output } from '../utils/output';
|
||||
import { Workspaces } from '../config/workspaces';
|
||||
import { mergeNpmScriptsWithTargets } from '../utils/project-graph-utils';
|
||||
@ -183,19 +182,35 @@ export function getOutputsForTargetAndConfiguration(
|
||||
}
|
||||
|
||||
export function interpolate(template: string, data: any): string {
|
||||
return template
|
||||
.replace('{workspaceRoot}/', '')
|
||||
.replace(/{([\s\S]+?)}/g, (match: string) => {
|
||||
let value = data;
|
||||
let path = match.slice(1, -1).trim().split('.');
|
||||
for (let idx = 0; idx < path.length; idx++) {
|
||||
if (!value[path[idx]]) {
|
||||
return match;
|
||||
}
|
||||
value = value[path[idx]];
|
||||
if (template.includes('{workspaceRoot}', 1)) {
|
||||
throw new Error(
|
||||
`Output '${template}' is invalid. {workspaceRoot} can only be used at the beginning of the expression.`
|
||||
);
|
||||
}
|
||||
|
||||
if (data.projectRoot == '.' && template.includes('{projectRoot}', 1)) {
|
||||
throw new Error(
|
||||
`Output '${template}' is invalid. When {projectRoot} is '.', it can only be used at the beginning of the expression.`
|
||||
);
|
||||
}
|
||||
|
||||
let res = template.replace('{workspaceRoot}/', '');
|
||||
|
||||
if (data.projectRoot == '.') {
|
||||
res = template.replace('{projectRoot}/', '');
|
||||
}
|
||||
|
||||
return res.replace(/{([\s\S]+?)}/g, (match: string) => {
|
||||
let value = data;
|
||||
let path = match.slice(1, -1).trim().split('.');
|
||||
for (let idx = 0; idx < path.length; idx++) {
|
||||
if (!value[path[idx]]) {
|
||||
return match;
|
||||
}
|
||||
return value;
|
||||
});
|
||||
value = value[path[idx]];
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
export function getExecutorNameForTask(
|
||||
|
||||
@ -71,7 +71,7 @@ exports[`@nrwl/vite:configuration transform React app to use Vite should transfo
|
||||
\\"test\\": {
|
||||
\\"builder\\": \\"@nrwl/jest:jest\\",
|
||||
\\"outputs\\": [
|
||||
\\"{workspaceRoot}/coverage/{projectRoot}\\"
|
||||
\\"{workspaceRoot}/coverage/{projectName}\\"
|
||||
],
|
||||
\\"options\\": {
|
||||
\\"jestConfig\\": \\"apps/my-test-react-app/jest.config.ts\\",
|
||||
@ -148,7 +148,7 @@ exports[`@nrwl/vite:configuration transform Web app to use Vite should transform
|
||||
\\"test\\": {
|
||||
\\"builder\\": \\"@nrwl/jest:jest\\",
|
||||
\\"outputs\\": [
|
||||
\\"{workspaceRoot}/coverage/{projectRoot}\\"
|
||||
\\"{workspaceRoot}/coverage/{projectName}\\"
|
||||
],
|
||||
\\"options\\": {
|
||||
\\"jestConfig\\": \\"apps/my-test-web-app/jest.config.ts\\",
|
||||
|
||||
@ -28,7 +28,7 @@ describe('vitest generator', () => {
|
||||
"passWithNoTests": true,
|
||||
},
|
||||
"outputs": Array [
|
||||
"{workspaceRoot}/coverage/{projectRoot}",
|
||||
"{workspaceRoot}/coverage/{projectName}",
|
||||
],
|
||||
}
|
||||
`);
|
||||
|
||||
@ -74,7 +74,7 @@
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/my-test-react-app/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/my-test-web-app/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user