From c51be25d28da06d29620caee2505bff609cba445 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sat, 11 Feb 2023 01:14:39 +0800 Subject: [PATCH] fix(register): paths option --- packages/integrate/__tests__/paths/paths.spec.ts | 6 ++++++ packages/integrate/src/fixture.ts | 1 + packages/register/read-default-tsconfig.ts | 16 ++++++++-------- tsconfig.json | 3 ++- 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 packages/integrate/__tests__/paths/paths.spec.ts create mode 100644 packages/integrate/src/fixture.ts diff --git a/packages/integrate/__tests__/paths/paths.spec.ts b/packages/integrate/__tests__/paths/paths.spec.ts new file mode 100644 index 000000000..98e9867d9 --- /dev/null +++ b/packages/integrate/__tests__/paths/paths.spec.ts @@ -0,0 +1,6 @@ +import { FIXTURE } from '@integrate/fixture' +import test from 'ava' + +test('should transpile paths', (t) => { + t.is(FIXTURE, 'fixture') +}) diff --git a/packages/integrate/src/fixture.ts b/packages/integrate/src/fixture.ts new file mode 100644 index 000000000..3ec47de9a --- /dev/null +++ b/packages/integrate/src/fixture.ts @@ -0,0 +1 @@ +export const FIXTURE = 'fixture' diff --git a/packages/register/read-default-tsconfig.ts b/packages/register/read-default-tsconfig.ts index 57756d8fa..59d7b3ef3 100644 --- a/packages/register/read-default-tsconfig.ts +++ b/packages/register/read-default-tsconfig.ts @@ -114,15 +114,7 @@ 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: { @@ -130,7 +122,15 @@ export function tsCompilerOptionsToSwcConfig(options: ts.CompilerOptions, filena 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 diff --git a/tsconfig.json b/tsconfig.json index bf80a158f..50c1a4dc2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"],