Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vite): set mode in configuration (#13856)
(cherry picked from commit f4802ae)
- Loading branch information
1 parent
93e9df6
commit 9872261
Showing
7 changed files
with
91 additions
and
9 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
32 changes: 32 additions & 0 deletions
32
packages/vite/src/migrations/update-15-3-4/set-mode-in-configuration.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,32 @@ | ||
import { readProjectConfiguration, Tree } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; | ||
import { mockViteReactAppGenerator } from '../../utils/test-utils'; | ||
import { setModeInConfiguration } from './set-mode-in-configuration'; | ||
|
||
describe('set mode in configuration object', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyV1Workspace(); | ||
mockViteReactAppGenerator(tree); | ||
}); | ||
|
||
it('should set the mode to be the configuration name and preserve other settings', async () => { | ||
await setModeInConfiguration(tree); | ||
|
||
const projectConfig = readProjectConfiguration( | ||
tree, | ||
'my-test-react-vite-app' | ||
); | ||
|
||
expect(projectConfig.targets.build.configurations.production.mode).toEqual( | ||
'production' | ||
); | ||
|
||
expect(projectConfig.targets.build.configurations.ssr.mode).toEqual('ssr'); | ||
expect(projectConfig.targets.build.configurations.ssr.ssr).toBeTruthy(); | ||
expect( | ||
projectConfig.targets.build.configurations.ssr['my-other-setting'] | ||
).toBe('my-other-value'); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/vite/src/migrations/update-15-3-4/set-mode-in-configuration.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,36 @@ | ||
import { | ||
formatFiles, | ||
readProjectConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
|
||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
|
||
export async function setModeInConfiguration(tree: Tree) { | ||
forAllProjectsUsingViteAddMode(tree); | ||
await formatFiles(tree); | ||
} | ||
|
||
export default setModeInConfiguration; | ||
|
||
function forAllProjectsUsingViteAddMode(tree: Tree): void { | ||
forEachExecutorOptions( | ||
tree, | ||
'@nrwl/vite:build', | ||
(_options, projectName, targetName, configuration) => { | ||
if (!configuration) { | ||
return; | ||
} | ||
|
||
const projectConfiguration = readProjectConfiguration(tree, projectName); | ||
projectConfiguration.targets[targetName].configurations[ | ||
configuration | ||
].mode ??= configuration; | ||
|
||
updateProjectConfiguration(tree, projectName, { | ||
...projectConfiguration, | ||
}); | ||
} | ||
); | ||
} |
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