Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): .swcrc path option should follow existing conventions #10127

Merged
merged 7 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/generated/packages/js.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,9 @@
"type": "string",
"description": "The path to the Typescript configuration file."
},
"swcrcPath": {
"swcrc": {
"type": "string",
"description": "The path to the SWC configuration file.",
"default": ".lib.swcrc"
"description": "The path to the SWC configuration file. Default: .lib.swcrc"
},
"assets": {
"type": "array",
Expand Down
6 changes: 6 additions & 0 deletions packages/js/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"version": "14.0.0-beta.2",
"description": "Exclude jest config from .lib.swcrc",
"factory": "./src/migrations/update-14-0-0/exclude-jest-config-swcrc"
},
"update-swcrc-path": {
"cli": "nx",
"version": "14.1.1-beta.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14.1.1 has been released already, can you bump this to 14.1.5-beta.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

"description": "Rename option swcrcPath to swcrc, and resolve relative to workspace root",
"factory": "./src/migrations/update-14.1.1-beta.0/update-swcrc-path"
}
},
"packageJsonUpdates": {}
Expand Down
5 changes: 2 additions & 3 deletions packages/js/src/executors/swc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
"type": "string",
"description": "The path to the Typescript configuration file."
},
"swcrcPath": {
"swcrc": {
"type": "string",
"description": "The path to the SWC configuration file.",
"default": ".lib.swcrc"
"description": "The path to the SWC configuration file. Default: .lib.swcrc"
},
"assets": {
"type": "array",
Expand Down
5 changes: 4 additions & 1 deletion packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ function normalizeOptions(
// default to current directory if projectRootParts is [].
// Eg: when a project is at the root level, outside of layout dir
const swcCwd = projectRootParts.join('/') || '.';
const swcrcPath = options.swcrc
? join(contextRoot, options.swcrc)
: join(contextRoot, projectRoot, '.lib.swcrc');

const swcCliOptions = {
srcPath: projectDir,
destPath: relative(join(contextRoot, swcCwd), outputPath),
swcCwd,
swcrcPath: join(contextRoot, projectRoot, options.swcrcPath),
swcrcPath,
};

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 } = readProjectConfiguration(tree, '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'
);
});
});
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;
2 changes: 1 addition & 1 deletion packages/js/src/utils/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ExecutorOptions {
main: string;
outputPath: string;
tsConfig: string;
swcrcPath: string;
swcrc?: string;
watch: boolean;
transformers: TransformerEntry[];
updateBuildableProjectDepsInPackageJson?: boolean;
Expand Down