-
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(misc): change updateBuildableProjectDepsInPackageJson option def…
…ault value to false
- Loading branch information
1 parent
8c9ad0d
commit 63faf43
Showing
22 changed files
with
399 additions
and
16 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
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
86 changes: 86 additions & 0 deletions
86
...lar/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.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,86 @@ | ||
import { | ||
ProjectConfiguration, | ||
Tree, | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import migration from './explicitly-set-projects-to-update-buildable-deps'; | ||
|
||
describe('explicitly-set-projects-to-update-buildable-deps migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
}); | ||
|
||
it.each([ | ||
'@nx/angular:ng-packagr-lite', | ||
'@nrwl/angular:ng-packagr-lite', | ||
'@nx/angular:package', | ||
'@nrwl/angular:package', | ||
])( | ||
'should set updateBuildableProjectDepsInPackageJson option to "true" when not specified in target using "%s"', | ||
async (executor) => { | ||
addProjectConfiguration(tree, 'lib1', { | ||
root: 'libs/lib1', | ||
projectType: 'library', | ||
targets: { build: { executor, options: {} } }, | ||
}); | ||
|
||
await migration(tree); | ||
|
||
const project = readProjectConfiguration(tree, 'lib1'); | ||
expect( | ||
project.targets.build.options.updateBuildableProjectDepsInPackageJson | ||
).toBe(true); | ||
} | ||
); | ||
|
||
it.each([ | ||
'@nx/angular:ng-packagr-lite', | ||
'@nrwl/angular:ng-packagr-lite', | ||
'@nx/angular:package', | ||
'@nrwl/angular:package', | ||
])( | ||
'should not overwrite updateBuildableProjectDepsInPackageJson option when it is specified in target using "%s"', | ||
async (executor) => { | ||
addProjectConfiguration(tree, 'lib1', { | ||
root: 'libs/lib1', | ||
projectType: 'library', | ||
targets: { | ||
build: { | ||
executor, | ||
options: { updateBuildableProjectDepsInPackageJson: false }, | ||
}, | ||
}, | ||
}); | ||
|
||
await migration(tree); | ||
|
||
const project = readProjectConfiguration(tree, 'lib1'); | ||
expect( | ||
project.targets.build.options.updateBuildableProjectDepsInPackageJson | ||
).toBe(false); | ||
} | ||
); | ||
|
||
it('should not update targets using other executors', async () => { | ||
const originalProjectConfig: ProjectConfiguration = { | ||
root: 'libs/lib1', | ||
projectType: 'library', | ||
targets: { | ||
build: { | ||
executor: 'some-executor', | ||
options: {}, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'lib1', originalProjectConfig); | ||
|
||
await migration(tree); | ||
|
||
const project = readProjectConfiguration(tree, 'lib1'); | ||
expect(project.targets).toStrictEqual(originalProjectConfig.targets); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
.../angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.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,44 @@ | ||
import { | ||
formatFiles, | ||
getProjects, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nx/devkit'; | ||
|
||
const executors = new Set([ | ||
'@nx/angular:ng-packagr-lite', | ||
'@nrwl/angular:ng-packagr-lite', | ||
'@nx/angular:package', | ||
'@nrwl/angular:package', | ||
]); | ||
|
||
export default async function (tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
for (const [projectName, project] of projects) { | ||
if (project.projectType !== 'library') { | ||
continue; | ||
} | ||
|
||
let updated = false; | ||
for (const [, target] of Object.entries(project.targets || {})) { | ||
if (!executors.has(target.executor)) { | ||
continue; | ||
} | ||
|
||
if ( | ||
target.options && | ||
target.options.updateBuildableProjectDepsInPackageJson === undefined | ||
) { | ||
target.options.updateBuildableProjectDepsInPackageJson = true; | ||
updated = true; | ||
} | ||
} | ||
|
||
if (updated) { | ||
updateProjectConfiguration(tree, projectName, project); | ||
} | ||
} | ||
|
||
await formatFiles(tree); | ||
} |
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
76 changes: 76 additions & 0 deletions
76
.../js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.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,76 @@ | ||
import { | ||
ProjectConfiguration, | ||
Tree, | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import migration from './explicitly-set-projects-to-update-buildable-deps'; | ||
|
||
describe('explicitly-set-projects-to-update-buildable-deps migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
}); | ||
|
||
it.each(['@nx/js:swc', '@nrwl/js:swc', '@nx/js:tsc', '@nrwl/js:tsc'])( | ||
'should set updateBuildableProjectDepsInPackageJson option to "true" when not specified in target using "%s"', | ||
async (executor) => { | ||
addProjectConfiguration(tree, 'lib1', { | ||
root: 'libs/lib1', | ||
projectType: 'library', | ||
targets: { build: { executor, options: {} } }, | ||
}); | ||
|
||
await migration(tree); | ||
|
||
const project = readProjectConfiguration(tree, 'lib1'); | ||
expect( | ||
project.targets.build.options.updateBuildableProjectDepsInPackageJson | ||
).toBe(true); | ||
} | ||
); | ||
|
||
it.each(['@nx/js:swc', '@nrwl/js:swc', '@nx/js:tsc', '@nrwl/js:tsc'])( | ||
'should not overwrite updateBuildableProjectDepsInPackageJson option when it is specified in target using "%s"', | ||
async (executor) => { | ||
addProjectConfiguration(tree, 'lib1', { | ||
root: 'libs/lib1', | ||
projectType: 'library', | ||
targets: { | ||
build: { | ||
executor, | ||
options: { updateBuildableProjectDepsInPackageJson: false }, | ||
}, | ||
}, | ||
}); | ||
|
||
await migration(tree); | ||
|
||
const project = readProjectConfiguration(tree, 'lib1'); | ||
expect( | ||
project.targets.build.options.updateBuildableProjectDepsInPackageJson | ||
).toBe(false); | ||
} | ||
); | ||
|
||
it('should not update targets using other executors', async () => { | ||
const originalProjectConfig: ProjectConfiguration = { | ||
root: 'libs/lib1', | ||
projectType: 'library', | ||
targets: { | ||
build: { | ||
executor: 'some-executor', | ||
options: {}, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'lib1', originalProjectConfig); | ||
|
||
await migration(tree); | ||
|
||
const project = readProjectConfiguration(tree, 'lib1'); | ||
expect(project.targets).toStrictEqual(originalProjectConfig.targets); | ||
}); | ||
}); |
Oops, something went wrong.