Skip to content

Commit

Permalink
Merge pull request #688 from swc-project/fix-paths
Browse files Browse the repository at this point in the history
fix(register): paths option
  • Loading branch information
Brooooooklyn authored Feb 10, 2023
2 parents 06d4802 + c51be25 commit 544fd7c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/integrate/__tests__/paths/paths.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { FIXTURE } from '@integrate/fixture'
import test from 'ava'

test('should transpile paths', (t) => {
t.is(FIXTURE, 'fixture')
})
1 change: 1 addition & 0 deletions packages/integrate/src/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const FIXTURE = 'fixture'
16 changes: 8 additions & 8 deletions packages/register/read-default-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,23 @@ export function tsCompilerOptionsToSwcConfig(options: ts.CompilerOptions, filena
sourcemap: createSourcemapOption(options),
experimentalDecorators: options.experimentalDecorators ?? false,
emitDecoratorMetadata: options.emitDecoratorMetadata ?? false,
dynamicImport: true,
esModuleInterop: options.esModuleInterop ?? false,
keepClassNames: true,
paths: Object.fromEntries(
Object.entries(options.paths ?? {}).map(([aliasKey, aliasPaths]) => [
aliasKey,
((aliasPaths as string[]) ?? []).map((path) => resolve(options.baseUrl ?? './', path)),
]),
) as Options['paths'],
swc: {
filename,
jsc: {
externalHelpers: Boolean(options.importHelpers),
parser: {
syntax: 'typescript',
tsx: isJsx,
dynamicImport: true,
},
paths: Object.fromEntries(
Object.entries(options.paths ?? {}).map(([aliasKey, aliasPaths]) => [
aliasKey,
((aliasPaths as string[]) ?? []).map((path) => resolve(options.baseUrl ?? './', path)),
]),
) as Options['paths'],
keepClassNames: true,
transform: {
react:
options.jsxFactory || options.jsxFragmentFactory || options.jsx || options.jsxImportSource
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"baseUrl": "./packages",
"paths": {
"@swc-node/core": ["@swc-node/core/index.ts"],
"@swc-node/register/*": ["./register/*"]
"@swc-node/register/*": ["./register/*"],
"@integrate/*": ["./integrate/src/*"]
}
},
"include": ["./packages", "bench", "./jest.config.js"],
Expand Down

0 comments on commit 544fd7c

Please sign in to comment.