-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: set baseUrl if none is provided #386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,10 +83,14 @@ describe('transform tests', () => { | |
|
||
it('test: transformCode (process aliases)', () => { | ||
const aliases: Alias[] = [ | ||
{ find: /^@\/(.+)/, replacement: resolve(__dirname, '../$1') }, | ||
{ find: /^@components\/(.+)/, replacement: resolve(__dirname, '../src/components/$1') }, | ||
{ find: /^@\/(?!\.{1,2}\/)([^*]+)/, replacement: resolve(__dirname, '../$1') }, | ||
{ | ||
find: /^@components\/(?!\.{1,2}\/)([^*]+)/, | ||
replacement: resolve(__dirname, '../src/components/$1') | ||
}, | ||
{ find: /^~\//, replacement: resolve(__dirname, '../src/') }, | ||
{ find: '$src', replacement: resolve(__dirname, '../src') } | ||
{ find: '$src', replacement: resolve(__dirname, '../src') }, | ||
{ find: /^(?!\.{1,2}\/)([^*]+)/, replacement: resolve(__dirname, '../src/$1') } | ||
] | ||
const filePath = resolve(__dirname, '../src/index.ts') | ||
|
||
|
@@ -121,6 +125,31 @@ describe('transform tests', () => { | |
content: 'import("@/components/test").Test;', | ||
output: "import('../components/test').Test;" | ||
}, | ||
{ | ||
// https://github.com/qmhc/vite-plugin-dts/issues/330 | ||
description: 'wildcard alias at root level with relative import', | ||
filePath: './src/components/Sample/index.ts', | ||
content: 'import { Sample } from "./Sample";', | ||
output: "import { Sample } from './Sample';\n" | ||
}, | ||
Comment on lines
+128
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the added test case that was failing initially. The path was incorrectly being adjusted to |
||
{ | ||
description: 'wildcard alias at root level with relative import and dot in name', | ||
filePath: './src/components/Sample/index.ts', | ||
content: 'import { Sample } from "./test.data";', | ||
output: "import { Sample } from './test.data';\n" | ||
}, | ||
{ | ||
description: 'wildcard alias at root level with relative parent import and dot in name', | ||
filePath: './src/components/Sample/index.ts', | ||
content: 'import { Sample } from "../test.data";', | ||
output: "import { Sample } from '../test.data';\n" | ||
}, | ||
{ | ||
description: 'wildcard alias at root level with relative import and dot in name', | ||
filePath: './src/components/Sample/index.ts', | ||
content: 'import { Sample } from "utils/test.data";', | ||
output: "import { Sample } from '../../utils/test.data';\n" | ||
}, | ||
{ | ||
description: 'import inside folder with named alias at subfolder', | ||
content: 'import type { TestBase } from "@/components/test";', | ||
|
@@ -170,7 +199,6 @@ describe('transform tests', () => { | |
}, | ||
{ | ||
description: 'alias as everything, relative import', | ||
aliases: [{ find: /^(.+)$/, replacement: resolve(__dirname, '../src/$1') }], | ||
content: 'import { TestBase } from "test";', | ||
output: "import { TestBase } from './test';\n" | ||
} | ||
|
@@ -212,8 +240,24 @@ describe('transform tests', () => { | |
) | ||
|
||
expect(transformCode(options('import { TestBase } from "./test";')).content).toEqual( | ||
"import { TestBase } from './test';\n" | ||
) | ||
Comment on lines
242
to
+244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Git is a little confused here because of the added tests, but this is the diff for the changed test: - expect(transformCode(options('import { TestBase } from "./test";')).content).toEqual(
- "import { TestBase } from './utils/test';\n"
- )
+ expect(transformCode(options('import { TestBase } from "./test";')).content).toEqual(
+ "import { TestBase } from './test';\n"
+ ) Essentially, relative paths should stay relative and I had previously made this test incorrect. |
||
|
||
expect(transformCode(options('import { TestBase } from "test";')).content).toEqual( | ||
"import { TestBase } from './utils/test';\n" | ||
) | ||
|
||
expect(transformCode(options('import { TestBase } from "test.path";')).content).toEqual( | ||
"import { TestBase } from './utils/test.path';\n" | ||
) | ||
|
||
expect(transformCode(options('import { TestBase } from "./test.path";')).content).toEqual( | ||
"import { TestBase } from './test.path';\n" | ||
) | ||
Comment on lines
+246
to
+256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the new tests cases to cover the correct behavior. |
||
|
||
expect(transformCode(options('import { TestBase } from "../test.path";')).content).toEqual( | ||
"import { TestBase } from '../test.path';\n" | ||
) | ||
}) | ||
|
||
it('test: transformCode (remove pure imports)', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,14 +168,14 @@ describe('utils tests', () => { | |
}) | ||
).toStrictEqual([ | ||
{ | ||
find: /^@\/(.+)$/, | ||
find: /^@\/(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching(maybeWindowsPath('/tmp/fake/project/root/at/$1')) | ||
} | ||
]) | ||
|
||
expect(parseTsAliases('/tmp/fake/project/root', { '~/*': ['./tilde/*'] })).toStrictEqual([ | ||
{ | ||
find: /^~\/(.+)$/, | ||
find: /^~\/(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching(maybeWindowsPath('/tmp/fake/project/root/tilde/$1')) | ||
} | ||
]) | ||
|
@@ -184,7 +184,7 @@ describe('utils tests', () => { | |
parseTsAliases('/tmp/fake/project/root', { '@/no-dot-prefix/*': ['no-dot-prefix/*'] }) | ||
).toStrictEqual([ | ||
{ | ||
find: /^@\/no-dot-prefix\/(.+)$/, | ||
find: /^@\/no-dot-prefix\/(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching( | ||
maybeWindowsPath('/tmp/fake/project/root/no-dot-prefix/$1') | ||
) | ||
|
@@ -195,7 +195,7 @@ describe('utils tests', () => { | |
parseTsAliases('/tmp/fake/project/root', { '@/components/*': ['./at/components/*'] }) | ||
).toStrictEqual([ | ||
{ | ||
find: /^@\/components\/(.+)$/, | ||
find: /^@\/components\/(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching( | ||
maybeWindowsPath('/tmp/fake/project/root/at/components/$1') | ||
) | ||
|
@@ -204,7 +204,7 @@ describe('utils tests', () => { | |
|
||
expect(parseTsAliases('/tmp/fake/project/root', { 'top/*': ['./top/*'] })).toStrictEqual([ | ||
{ | ||
find: /^top\/(.+)$/, | ||
find: /^top\/(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching(maybeWindowsPath('/tmp/fake/project/root/top/$1')) | ||
} | ||
]) | ||
|
@@ -219,15 +219,15 @@ describe('utils tests', () => { | |
// https://github.com/qmhc/vite-plugin-dts/issues/330 | ||
expect(parseTsAliases('/tmp/fake/project/root', { '*': ['./src/*'] })).toStrictEqual([ | ||
{ | ||
find: /^(.+)$/, | ||
find: /^(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching(maybeWindowsPath('/tmp/fake/project/root/src/$1')) | ||
} | ||
]) | ||
|
||
// https://github.com/qmhc/vite-plugin-dts/issues/290#issuecomment-1872495764 | ||
expect(parseTsAliases('/tmp/fake/project/root', { '#*': ['./hashed/*'] })).toStrictEqual([ | ||
{ | ||
find: /^#(.+)$/, | ||
find: /^#(?!\.{1,2}\/)([^*]+)$/, | ||
replacement: expect.stringMatching(maybeWindowsPath('/tmp/fake/project/root/hashed/$1')) | ||
} | ||
]) | ||
|
@@ -248,11 +248,8 @@ describe('utils tests', () => { | |
}) | ||
|
||
it('test: getTsLibFolder', () => { | ||
const root = normalizePath(resolve(__dirname, '..')) | ||
const entryRoot = resolve(root, 'src') | ||
|
||
expect(getTsLibFolder({ root, entryRoot })).toMatch(/node_modules\/typescript$/) | ||
expect(getTsLibFolder()).toMatch(/node_modules\/typescript$/) | ||
|
||
expect(existsSync(getTsLibFolder({ root, entryRoot }) || '')).toBe(true) | ||
expect(existsSync(getTsLibFolder() || '')).toBe(true) | ||
}) | ||
Comment on lines
250
to
254
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to the main change, but |
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous pattern
(.+)
was matching everything when the*
pattern was used as a path alias. This matches everything except relative paths (cwd and parent).