Skip to content

Commit

Permalink
fix(js): .swcrc path option should follow existing conventions (#10127)
Browse files Browse the repository at this point in the history
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
  • Loading branch information
djgrant and AgentEnder committed May 6, 2022
1 parent c4e5b7c commit 63006b7
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 8 deletions.
5 changes: 2 additions & 3 deletions docs/generated/packages/js.json
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
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.5-beta.0",
"description": "Rename option swcrcPath to swcrc, and resolve relative to workspace root",
"factory": "./src/migrations/update-14.1.5-beta.0/update-swcrc-path"
}
},
"packageJsonUpdates": {}
Expand Down
5 changes: 2 additions & 3 deletions packages/js/src/executors/swc/schema.json
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
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
@@ -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'
);
});
});
@@ -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
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

1 comment on commit 63006b7

@vercel
Copy link

@vercel vercel bot commented on 63006b7 May 6, 2022

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

Please sign in to comment.