From 34ce307474e92b2166756f7f81b43b929da1714c Mon Sep 17 00:00:00 2001 From: Gerard Wilkinson Date: Sat, 28 Oct 2023 13:20:31 +0100 Subject: [PATCH 1/6] fix: toExports extension strip --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index ac2a1792..8d7abe48 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,7 @@ export function toExports (imports: Import[], fileDir?: string, includeType = fa const map = toImportModuleMap(imports, includeType) return Object.entries(map) .flatMap(([name, imports]) => { - name = name.replace(/\.[a-z]+$/, '') + name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, "$1$2") if (fileDir && isAbsolute(name)) { name = relative(fileDir, name) if (!name.match(/^[.\/]/)) { From a40abff67ddd6115bab6d294a042185b1d1f520f Mon Sep 17 00:00:00 2001 From: Gerard Wilkinson Date: Sat, 28 Oct 2023 13:45:47 +0100 Subject: [PATCH 2/6] feat: expand extension strip tests --- test/to-export.test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/to-export.test.ts b/test/to-export.test.ts index 52c39ab2..301f4a26 100644 --- a/test/to-export.test.ts +++ b/test/to-export.test.ts @@ -66,13 +66,19 @@ describe('toExports', () => { it('strip extensions', () => { const imports: Import[] = [ { from: 'test1.ts', name: 'foo', as: 'foo' }, - { from: 'test2.mjs', name: 'foobar', as: 'foobar' } + { from: 'test2.mjs', name: 'foobar', as: 'foobar' }, + { from: './test1.ts', name: 'foo', as: 'foo' }, + { from: './test2.mjs', name: 'foobar', as: 'foobar' }, + { from: 'test1.ts/test1.ts', name: 'foo', as: 'foo' } ] expect(toExports(imports)) .toMatchInlineSnapshot(` - "export { foo } from 'test1'; - export { foobar } from 'test2';" + "export { foo } from 'test1.ts'; + export { foobar } from 'test2.mjs'; + export { foo } from './test1'; + export { foobar } from './test2'; + export { foo } from 'test1.ts/test1';" `) }) From fb75895dd03469d9df1693870ef9f93f887172be Mon Sep 17 00:00:00 2001 From: Gerard Wilkinson Date: Wed, 1 Nov 2023 09:29:31 +0000 Subject: [PATCH 3/6] fix: toExports double quotes --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 8d7abe48..a5aa31d1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,7 @@ export function toExports (imports: Import[], fileDir?: string, includeType = fa const map = toImportModuleMap(imports, includeType) return Object.entries(map) .flatMap(([name, imports]) => { - name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, "$1$2") + name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, '$1$2') if (fileDir && isAbsolute(name)) { name = relative(fileDir, name) if (!name.match(/^[.\/]/)) { From 22648ff9816acea1c9d53416e0063cba2f0024c0 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 9 Nov 2023 16:43:53 +0100 Subject: [PATCH 4/6] chore: update --- src/utils.ts | 6 +++++- test/to-export.test.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index a5aa31d1..47d652c2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,7 @@ export function toExports (imports: Import[], fileDir?: string, includeType = fa const map = toImportModuleMap(imports, includeType) return Object.entries(map) .flatMap(([name, imports]) => { - name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, '$1$2') + if (isFilePath(name)) { name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, '$1$2') } if (fileDir && isAbsolute(name)) { name = relative(fileDir, name) if (!name.match(/^[.\/]/)) { @@ -311,3 +311,7 @@ export function resolveIdAbsolute (id: string, parentId?: string) { url: parentId }) } + +function isFilePath (path: string) { + return path.startsWith('.') || path.startsWith('/') || path.startsWith('\\') || path.includes('://') +} diff --git a/test/to-export.test.ts b/test/to-export.test.ts index 301f4a26..636e76a3 100644 --- a/test/to-export.test.ts +++ b/test/to-export.test.ts @@ -78,7 +78,7 @@ describe('toExports', () => { export { foobar } from 'test2.mjs'; export { foo } from './test1'; export { foobar } from './test2'; - export { foo } from 'test1.ts/test1';" + export { foo } from 'test1.ts/test1.ts';" `) }) From 7d1d93f7ee71b768f7604c7785bee865d4fc564a Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 9 Nov 2023 16:48:14 +0100 Subject: [PATCH 5/6] chore: update --- src/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 47d652c2..a2e1a85d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,9 @@ export function toExports (imports: Import[], fileDir?: string, includeType = fa const map = toImportModuleMap(imports, includeType) return Object.entries(map) .flatMap(([name, imports]) => { - if (isFilePath(name)) { name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, '$1$2') } + if (isFilePath(name)) { + name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, '$1$2') + } if (fileDir && isAbsolute(name)) { name = relative(fileDir, name) if (!name.match(/^[.\/]/)) { @@ -313,5 +315,5 @@ export function resolveIdAbsolute (id: string, parentId?: string) { } function isFilePath (path: string) { - return path.startsWith('.') || path.startsWith('/') || path.startsWith('\\') || path.includes('://') + return path.startsWith('.') || isAbsolute(path) || path.includes('://') } From 3c77a72bd34d3c905d7624a0e42d94d039f3a917 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 9 Nov 2023 16:48:48 +0100 Subject: [PATCH 6/6] chore: update --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index a2e1a85d..7e9f770b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -119,7 +119,7 @@ export function toExports (imports: Import[], fileDir?: string, includeType = fa return Object.entries(map) .flatMap(([name, imports]) => { if (isFilePath(name)) { - name = name.replace(/(\/|\.\/)(.*)(\.[^.]+)/, '$1$2') + name = name.replace(/\.[a-zA-Z]+$/, '') } if (fileDir && isAbsolute(name)) { name = relative(fileDir, name)