Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): .swcrc path option should follow existing conventions (#10127)
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
- Loading branch information
1 parent
c4e5b7c
commit 63006b7
Showing
7 changed files
with
86 additions
and
8 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
34 changes: 34 additions & 0 deletions
34
packages/js/src/migrations/update-14.1.5-beta.0/update-swcrc-path.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,34 @@ | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import updateSwcrcPath from './update-swcrc-path'; | ||
|
||
describe('update-swcrc-path migration', () => { | ||
it('should replace relative `swcrcPath` option with absolute `swcrc`', async () => { | ||
const tree = createTreeWithEmptyWorkspace(2); | ||
addProjectConfiguration(tree, 'test-package', { | ||
root: 'packages/test-package', | ||
targets: { | ||
build: { | ||
executor: '@nrwl/js:swc', | ||
options: { | ||
swcrcPath: 'config/swcrc.json', | ||
somethingThatShouldNotBeRemoved: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await updateSwcrcPath(tree); | ||
|
||
const { targets, root } = readProjectConfiguration(tree, 'test-package'); | ||
expect(root).toBe('packages/test-package'); | ||
expect(targets.build.options.somethingThatShouldNotBeRemoved).toBeDefined(); | ||
expect(targets.build.options.swcrcPath).toBeUndefined(); | ||
expect(targets.build.options.swcrc).toBe( | ||
'packages/test-package/config/swcrc.json' | ||
); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/js/src/migrations/update-14.1.5-beta.0/update-swcrc-path.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,37 @@ | ||
import { | ||
joinPathFragments, | ||
readProjectConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
import { SwcExecutorOptions } from '../../utils/schema'; | ||
|
||
type OldSwcExecutorOptions = SwcExecutorOptions & { swcrcPath?: string }; | ||
|
||
export function updateSwcrcPath(tree: Tree) { | ||
forEachExecutorOptions( | ||
tree, | ||
'@nrwl/js:swc', | ||
(_, projectName, targetName, configurationName) => { | ||
const projectConfig = readProjectConfiguration(tree, projectName); | ||
const executorOptions: OldSwcExecutorOptions = configurationName | ||
? projectConfig.targets[targetName].configurations[configurationName] | ||
: projectConfig.targets[targetName].options; | ||
|
||
if (!executorOptions.swcrcPath) return; | ||
|
||
const newSwcrcPath = joinPathFragments( | ||
projectConfig.root, | ||
executorOptions.swcrcPath | ||
); | ||
|
||
delete executorOptions.swcrcPath; | ||
executorOptions.swcrc = newSwcrcPath; | ||
|
||
updateProjectConfiguration(tree, projectName, projectConfig); | ||
} | ||
); | ||
} | ||
|
||
export default updateSwcrcPath; |
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
63006b7
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-git-master-nrwl.vercel.app
nx.dev
nx-dev-nrwl.vercel.app