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): add swc/helpers to js packages on converting to swc #9467

Merged
merged 3 commits into from Mar 22, 2022
Merged
Changes from 1 commit
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
26 changes: 24 additions & 2 deletions packages/js/src/generators/convert-to-swc/convert-to-swc.ts
@@ -1,4 +1,5 @@
import {
addDependenciesToPackageJson,
convertNxGenerator,
installPackagesTask,
ProjectConfiguration,
Expand All @@ -10,6 +11,7 @@ import {
import { join } from 'path';
import { addSwcConfig } from '../../utils/swc/add-swc-config';
import { addSwcDependencies } from '../../utils/swc/add-swc-dependencies';
import { swcHelpersVersion } from '../../utils/versions';
import { ConvertToSwcGeneratorSchema } from './schema';

export async function convertToSwcGenerator(
Expand All @@ -25,7 +27,6 @@ export async function convertToSwcGenerator(
options.project,
options.targets
);

return checkSwcDependencies(tree, projectConfiguration);
}

Expand Down Expand Up @@ -66,10 +67,20 @@ function checkSwcDependencies(
);

const packageJson = readJson(tree, 'package.json');
const projectPackageJsonPath = join(
projectConfiguration.root,
'package.json'
);
const projectPackageJson = readJson(tree, projectPackageJsonPath);

const hasSwcDependency =
packageJson.dependencies && packageJson.dependencies['@swc/core'];

if (isSwcrcPresent && hasSwcDependency) return;
const hasSwcHelpers =
projectPackageJson.dependencies &&
projectPackageJson.dependencies['@swc/helpers'];

if (isSwcrcPresent && hasSwcDependency && hasSwcHelpers) return;

if (!isSwcrcPresent) {
addSwcConfig(tree, projectConfiguration.root);
Expand All @@ -79,6 +90,17 @@ function checkSwcDependencies(
addSwcDependencies(tree);
}

if (!hasSwcHelpers) {
addDependenciesToPackageJson(
tree,
{
'@swc/helpers': swcHelpersVersion,
},
{},
projectPackageJsonPath
);
}

return () => {
if (!hasSwcDependency) {
installPackagesTask(tree);
Expand Down