diff --git a/e2e/js/src/js-swc.test.ts b/e2e/js/src/js-swc.test.ts index d1edd859410fc..6724570ee6be1 100644 --- a/e2e/js/src/js-swc.test.ts +++ b/e2e/js/src/js-swc.test.ts @@ -134,8 +134,9 @@ export function x() { // update .swcrc to use path mappings updateJson(`libs/${lib}/.swcrc`, (json) => { + json.jsc.baseUrl = '.'; json.jsc.paths = { - 'src/*': ['src/*'], + '~/*': ['./src/*'], }; return json; }); @@ -144,7 +145,7 @@ export function x() { updateFile(`libs/${lib}/src/lib/${lib}.ts`, () => { return ` // @ts-ignore -import { x } from 'src/x'; +import { x } from '~/x'; export function myLib() { console.log(x()); @@ -154,8 +155,8 @@ myLib(); `; }); - // now run build - runCLI(`build ${lib}`); + // now run build without type checking (since we're using path mappings not in tsconfig) + runCLI(`build ${lib} --skipTypeCheck`); // invoke the lib with node const result = execSync(`node dist/libs/${lib}/src/lib/${lib}.js`, { diff --git a/packages/js/src/executors/swc/swc.impl.ts b/packages/js/src/executors/swc/swc.impl.ts index 4bb1a4056081d..3549a2112d5d9 100644 --- a/packages/js/src/executors/swc/swc.impl.ts +++ b/packages/js/src/executors/swc/swc.impl.ts @@ -66,21 +66,7 @@ export 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('/') || '.'; - let swcrcPath = getSwcrcPath(options, contextRoot, projectRoot); - - try { - const swcrcContent = readJsonFile(swcrcPath) as Options; - // if we have path mappings setup but baseUrl isn't specified, then we're proceeding with the following logic - if ( - swcrcContent.jsc && - swcrcContent.jsc.paths && - !swcrcContent.jsc.baseUrl - ) { - swcrcContent.jsc.baseUrl = `./${projectDir}`; - swcrcPath = getSwcrcPath(options, contextRoot, projectRoot, true); - writeJsonFile(swcrcPath, swcrcContent); - } - } catch (e) {} + const swcrcPath = getSwcrcPath(options, contextRoot, projectRoot); const swcCliOptions = { srcPath: projectDir, diff --git a/packages/js/src/utils/swc/compile-swc.ts b/packages/js/src/utils/swc/compile-swc.ts index aa441ad9f8dd6..61edec414dc43 100644 --- a/packages/js/src/utils/swc/compile-swc.ts +++ b/packages/js/src/utils/swc/compile-swc.ts @@ -10,7 +10,7 @@ function getSwcCmd( { swcrcPath, srcPath, destPath }: SwcCliOptions, watch = false ) { - let swcCmd = `npx swc ${srcPath} -d ${destPath} --no-swcrc --config-file=${swcrcPath}`; + let swcCmd = `npx swc ${srcPath} -d ${destPath} --config-file=${swcrcPath}`; return watch ? swcCmd.concat(' --watch') : swcCmd; } diff --git a/packages/js/src/utils/swc/get-swcrc-path.ts b/packages/js/src/utils/swc/get-swcrc-path.ts index 43cd059d32cde..cc4acdbb1b9c4 100644 --- a/packages/js/src/utils/swc/get-swcrc-path.ts +++ b/packages/js/src/utils/swc/get-swcrc-path.ts @@ -4,14 +4,9 @@ import { SwcExecutorOptions } from '../schema'; export function getSwcrcPath( options: SwcExecutorOptions, contextRoot: string, - projectRoot: string, - temp = false + projectRoot: string ) { - let swcrcPath = options.swcrc ?? join(projectRoot, '.swcrc'); - - if (temp) { - swcrcPath = join('tmp', swcrcPath.replace('.swcrc', '.generated.swcrc')); - } - - return join(contextRoot, swcrcPath); + return options.swcrc + ? join(contextRoot, options.swcrc) + : join(contextRoot, projectRoot, '.swcrc'); }