Skip to content

Commit

Permalink
fix(js): fix swc compilation output path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Aug 11, 2023
1 parent 107a753 commit d4ff7da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 1 addition & 3 deletions packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ function normalizeOptions(
);

const swcrcPath = getSwcrcPath(options, root, projectRoot);
// TODO(meeroslav): Check why this is needed in order for swc to properly nest folders
const distParent = outputPath.split('/').slice(0, -1).join('/');
const swcCliOptions = {
srcPath: projectRoot,
destPath: relative(root, distParent),
destPath: relative(root, outputPath),
swcrcPath,
};

Expand Down
20 changes: 12 additions & 8 deletions packages/js/src/utils/swc/compile-swc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
cacheDir,
ExecutorContext,
getPackageManagerCommand,
logger,
} from '@nx/devkit';
import { cacheDir, ExecutorContext, logger } from '@nx/devkit';
import { exec, execSync } from 'child_process';
import { removeSync } from 'fs-extra';
import { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';
Expand All @@ -15,8 +10,17 @@ function getSwcCmd(
{ swcrcPath, srcPath, destPath }: SwcCliOptions,
watch = false
) {
const packageManager = getPackageManagerCommand();
let swcCmd = `${packageManager.exec} swc ${
// nx-ignore-next-line
const swcCLI = require.resolve('@swc/cli/bin/swc.js');
const firstSegmentIndex = srcPath.indexOf('/');
if (firstSegmentIndex !== -1) {
// for swc we need to strip the destination path down to the first segment
// dist/libs/{parentLib}/{libs} -> dist/libs
// TODO(meeroslav) remove this when https://github.com/swc-project/swc/issues/3028 is fixed
destPath = destPath.slice(0, -srcPath.length + firstSegmentIndex);
}

let swcCmd = `${swcCLI} ${
// TODO(jack): clean this up when we remove inline module support
// Handle root project
srcPath === '.' ? 'src' : srcPath
Expand Down

0 comments on commit d4ff7da

Please sign in to comment.