-
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): migrate existing workspaces to use inputs configuration (#…
- Loading branch information
1 parent
ce632aa
commit 49c5e50
Showing
36 changed files
with
1,851 additions
and
19 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
82 changes: 82 additions & 0 deletions
82
packages/angular/src/migrations/update-15-0-0/add-karma-inputs.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,82 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { | ||
Tree, | ||
addProjectConfiguration, | ||
readWorkspaceConfiguration, | ||
updateWorkspaceConfiguration, | ||
} from '@nrwl/devkit'; | ||
import addKarmaInputs from './add-karma-inputs'; | ||
|
||
describe('15.0.0 migration (add-karma-inputs)', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should add inputs configuration for karma targets', async () => { | ||
updateWorkspaceConfiguration(tree, { | ||
version: 2, | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*', 'sharedGlobals'], | ||
sharedGlobals: [], | ||
production: ['default'], | ||
}, | ||
}); | ||
addProjectConfiguration(tree, 'proj', { | ||
root: 'proj', | ||
targets: { | ||
test: { | ||
executor: '@angular-devkit/build-angular:karma', | ||
options: {}, | ||
}, | ||
test2: { | ||
executor: '@angular-devkit/build-angular:karma', | ||
options: {}, | ||
}, | ||
notTest: { | ||
executor: 'nx:run-commands', | ||
}, | ||
}, | ||
}); | ||
tree.write('karma.conf.js', ''); | ||
|
||
await addKarmaInputs(tree); | ||
|
||
const updated = readWorkspaceConfiguration(tree); | ||
expect(updated).toMatchInlineSnapshot(` | ||
Object { | ||
"namedInputs": Object { | ||
"default": Array [ | ||
"{projectRoot}/**/*", | ||
"sharedGlobals", | ||
], | ||
"production": Array [ | ||
"default", | ||
"!{projectRoot}/**/*.spec.[jt]s", | ||
"!{projectRoot}/tsconfig.spec.json", | ||
"!{projectRoot}/karma.conf.js", | ||
], | ||
"sharedGlobals": Array [], | ||
}, | ||
"targetDefaults": Object { | ||
"test": Object { | ||
"inputs": Array [ | ||
"default", | ||
"^production", | ||
"{workspaceRoot}/karma.conf.js", | ||
], | ||
}, | ||
"test2": Object { | ||
"inputs": Array [ | ||
"default", | ||
"^production", | ||
"{workspaceRoot}/karma.conf.js", | ||
], | ||
}, | ||
}, | ||
"version": 2, | ||
} | ||
`); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
packages/angular/src/migrations/update-15-0-0/add-karma-inputs.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,60 @@ | ||
import { | ||
formatFiles, | ||
readWorkspaceConfiguration, | ||
Tree, | ||
updateWorkspaceConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
|
||
export default async function (tree: Tree) { | ||
const workspaceConfiguration = readWorkspaceConfiguration(tree); | ||
|
||
const karmaTargets = getKarmaTargetNames(tree); | ||
const hasProductionFileset = !!workspaceConfiguration.namedInputs?.production; | ||
|
||
if (karmaTargets.size > 0 && hasProductionFileset) { | ||
const productionFileset = new Set( | ||
workspaceConfiguration.namedInputs.production | ||
); | ||
for (const exclusion of [ | ||
'!{projectRoot}/**/*.spec.[jt]s', | ||
'!{projectRoot}/tsconfig.spec.json', | ||
'!{projectRoot}/karma.conf.js', | ||
]) { | ||
productionFileset.add(exclusion); | ||
} | ||
workspaceConfiguration.namedInputs.production = | ||
Array.from(productionFileset); | ||
} | ||
|
||
for (const targetName of karmaTargets) { | ||
workspaceConfiguration.targetDefaults ??= {}; | ||
const jestTargetDefaults = (workspaceConfiguration.targetDefaults[ | ||
targetName | ||
] ??= {}); | ||
|
||
jestTargetDefaults.inputs ??= [ | ||
'default', | ||
hasProductionFileset ? '^production' : '^default', | ||
...(tree.exists('karma.conf.js') | ||
? ['{workspaceRoot}/karma.conf.js'] | ||
: []), | ||
]; | ||
} | ||
|
||
updateWorkspaceConfiguration(tree, workspaceConfiguration); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
function getKarmaTargetNames(tree: Tree) { | ||
const karmaTargetNames = new Set<string>(); | ||
forEachExecutorOptions( | ||
tree, | ||
'@angular-devkit/build-angular:karma', | ||
(_, __, target) => { | ||
karmaTargetNames.add(target); | ||
} | ||
); | ||
return karmaTargetNames; | ||
} |
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
145 changes: 145 additions & 0 deletions
145
packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.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,145 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { | ||
Tree, | ||
addProjectConfiguration, | ||
readWorkspaceConfiguration, | ||
updateWorkspaceConfiguration, | ||
} from '@nrwl/devkit'; | ||
import addCypressInputs from './add-cypress-inputs'; | ||
|
||
describe('15.0.0 migration (add-cypress-inputs)', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should add inputs configuration for cypress targets', async () => { | ||
updateWorkspaceConfiguration(tree, { | ||
version: 2, | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*', 'sharedGlobals'], | ||
sharedGlobals: [], | ||
production: ['default'], | ||
}, | ||
}); | ||
addProjectConfiguration(tree, 'proj', { | ||
root: 'proj', | ||
targets: { | ||
e2e: { | ||
executor: '@nrwl/cypress:cypress', | ||
options: {}, | ||
}, | ||
e2e2: { | ||
executor: '@nrwl/cypress:cypress', | ||
options: {}, | ||
}, | ||
notTest: { | ||
executor: 'nx:run-commands', | ||
}, | ||
}, | ||
}); | ||
tree.write('jest.preset.js', ''); | ||
|
||
await addCypressInputs(tree); | ||
|
||
const updated = readWorkspaceConfiguration(tree); | ||
expect(updated).toMatchInlineSnapshot(` | ||
Object { | ||
"namedInputs": Object { | ||
"default": Array [ | ||
"{projectRoot}/**/*", | ||
"sharedGlobals", | ||
], | ||
"production": Array [ | ||
"default", | ||
], | ||
"sharedGlobals": Array [], | ||
}, | ||
"targetDefaults": Object { | ||
"e2e": Object { | ||
"inputs": Array [ | ||
"default", | ||
"^production", | ||
], | ||
}, | ||
"e2e2": Object { | ||
"inputs": Array [ | ||
"default", | ||
"^production", | ||
], | ||
}, | ||
}, | ||
"version": 2, | ||
} | ||
`); | ||
}); | ||
|
||
it('should inputs configuration for cypress component testing targets', async () => { | ||
updateWorkspaceConfiguration(tree, { | ||
version: 2, | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*', 'sharedGlobals'], | ||
sharedGlobals: [], | ||
production: ['default'], | ||
}, | ||
}); | ||
addProjectConfiguration(tree, 'proj', { | ||
root: 'proj', | ||
targets: { | ||
e2e: { | ||
executor: '@nrwl/cypress:cypress', | ||
options: { | ||
testingType: 'component', | ||
}, | ||
}, | ||
e2e2: { | ||
executor: '@nrwl/cypress:cypress', | ||
options: { | ||
testingType: 'component', | ||
}, | ||
}, | ||
notTest: { | ||
executor: 'nx:run-commands', | ||
}, | ||
}, | ||
}); | ||
tree.write('jest.preset.js', ''); | ||
|
||
await addCypressInputs(tree); | ||
|
||
const updated = readWorkspaceConfiguration(tree); | ||
expect(updated).toMatchInlineSnapshot(` | ||
Object { | ||
"namedInputs": Object { | ||
"default": Array [ | ||
"{projectRoot}/**/*", | ||
"sharedGlobals", | ||
], | ||
"production": Array [ | ||
"default", | ||
"!{projectRoot}/cypress/**/*", | ||
"!{projectRoot}/**/*.cy.[jt]s?(x)", | ||
"!{projectRoot}/cypress.config.[jt]s", | ||
], | ||
"sharedGlobals": Array [], | ||
}, | ||
"targetDefaults": Object { | ||
"e2e": Object { | ||
"inputs": Array [ | ||
"default", | ||
"^production", | ||
], | ||
}, | ||
"e2e2": Object { | ||
"inputs": Array [ | ||
"default", | ||
"^production", | ||
], | ||
}, | ||
}, | ||
"version": 2, | ||
} | ||
`); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.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 { | ||
formatFiles, | ||
readWorkspaceConfiguration, | ||
Tree, | ||
updateWorkspaceConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
import { CypressExecutorOptions } from '@nrwl/cypress/src/executors/cypress/cypress.impl'; | ||
|
||
export default async function (tree: Tree) { | ||
const workspaceConfiguration = readWorkspaceConfiguration(tree); | ||
|
||
const { cypressTargets, hasComponentTesting } = getCypressTargetNames(tree); | ||
const hasProductionFileset = !!workspaceConfiguration.namedInputs?.production; | ||
|
||
if (hasComponentTesting && hasProductionFileset && cypressTargets.size > 0) { | ||
const productionFileset = new Set( | ||
workspaceConfiguration.namedInputs.production | ||
); | ||
for (const exclusion of [ | ||
'!{projectRoot}/cypress/**/*', | ||
'!{projectRoot}/**/*.cy.[jt]s?(x)', | ||
'!{projectRoot}/cypress.config.[jt]s', | ||
]) { | ||
productionFileset.add(exclusion); | ||
} | ||
workspaceConfiguration.namedInputs.production = | ||
Array.from(productionFileset); | ||
} | ||
|
||
for (const targetName of cypressTargets) { | ||
workspaceConfiguration.targetDefaults ??= {}; | ||
const cypressTargetDefaults = (workspaceConfiguration.targetDefaults[ | ||
targetName | ||
] ??= {}); | ||
|
||
cypressTargetDefaults.inputs ??= [ | ||
'default', | ||
hasProductionFileset ? '^production' : '^default', | ||
]; | ||
} | ||
|
||
updateWorkspaceConfiguration(tree, workspaceConfiguration); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
function getCypressTargetNames(tree: Tree) { | ||
const cypressTargets = new Set<string>(); | ||
let hasComponentTesting = false; | ||
forEachExecutorOptions<CypressExecutorOptions>( | ||
tree, | ||
'@nrwl/cypress:cypress', | ||
(options, __, target) => { | ||
cypressTargets.add(target); | ||
if (options.testingType === 'component') { | ||
hasComponentTesting = true; | ||
} | ||
} | ||
); | ||
return { cypressTargets, hasComponentTesting }; | ||
} |
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
Oops, something went wrong.
49c5e50
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-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev