Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): update swc options so path mappings can work in all environm…
Browse files Browse the repository at this point in the history
…ents
jaysoo committed Apr 19, 2023
1 parent c6310e6 commit f148e7d
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions e2e/js/src/js-swc.test.ts
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ export function x() {
// update .swcrc to use path mappings
updateJson(`libs/${lib}/.swcrc`, (json) => {
json.jsc.paths = {
'src/*': ['src/*'],
'~/*': ['./src/*'],
};
return json;
});
@@ -144,7 +144,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 +154,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`, {
2 changes: 1 addition & 1 deletion packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ export function normalizeOptions(
swcrcContent.jsc.paths &&
!swcrcContent.jsc.baseUrl
) {
swcrcContent.jsc.baseUrl = `./${projectDir}`;
swcrcContent.jsc.baseUrl = `.`;
swcrcPath = getSwcrcPath(options, contextRoot, projectRoot, true);
writeJsonFile(swcrcPath, swcrcContent);
}
2 changes: 1 addition & 1 deletion packages/js/src/utils/swc/compile-swc.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f148e7d

Please sign in to comment.