Skip to content

Commit

Permalink
fix(js): fix swc compile options
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Jul 27, 2023
1 parent 68110d4 commit 8f961cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
33 changes: 13 additions & 20 deletions packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import { compileSwc, compileSwcWatch } from '../../utils/swc/compile-swc';
import { getSwcrcPath } from '../../utils/swc/get-swcrc-path';
import { generateTmpSwcrc } from '../../utils/swc/inline';

export function normalizeOptions(
function normalizeOptions(
options: SwcExecutorOptions,
contextRoot: string,
sourceRoot?: string,
projectRoot?: string
root: string,
sourceRoot: string,
projectRoot: string
): NormalizedSwcExecutorOptions {
const outputPath = join(contextRoot, options.outputPath);
const outputPath = join(root, options.outputPath);

if (options.skipTypeCheck == null) {
options.skipTypeCheck = false;
Expand All @@ -54,23 +54,16 @@ export function normalizeOptions(

const files: FileInputOutput[] = assetGlobsToFiles(
options.assets,
contextRoot,
root,
outputPath
);

const projectRootParts = projectRoot.split('/');
// We pop the last part of the `projectRoot` to pass
// the last part (projectDir) and the remainder (projectRootParts) to swc
const projectDir = projectRootParts.pop();
// 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 = getSwcrcPath(options, contextRoot, projectRoot);

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: projectDir,
destPath: relative(join(contextRoot, swcCwd), outputPath),
swcCwd,
srcPath: projectRoot,
destPath: relative(join(root, projectRoot), distParent),
swcrcPath,
};

Expand All @@ -81,12 +74,12 @@ export function normalizeOptions(
options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')
),
files,
root: contextRoot,
root,
sourceRoot,
projectRoot,
originalProjectRoot: projectRoot,
outputPath,
tsConfig: join(contextRoot, options.tsConfig),
tsConfig: join(root, options.tsConfig),
swcCliOptions,
} as NormalizedSwcExecutorOptions;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/utils/swc/compile-swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export async function compileSwc(
}

const swcCmdLog = execSync(getSwcCmd(normalizedOptions.swcCliOptions), {
cwd: normalizedOptions.swcCliOptions.swcCwd,
}).toString();
encoding: 'utf8',
});
logger.log(swcCmdLog.replace(/\n/, ''));
const isCompileSuccess = swcCmdLog.includes('Successfully compiled');

Expand Down

0 comments on commit 8f961cf

Please sign in to comment.