fix: Ensure TSConfig paths start with ../ or ./ so they are valid (#927)

This commit is contained in:
Aaron
2024-08-18 15:18:23 -05:00
committed by GitHub
parent 5f2e1c38a7
commit 5f653b3ff9
2 changed files with 21 additions and 1 deletions
@@ -379,6 +379,22 @@ describe('TypeScript Project', () => {
`);
});
it('should start path aliases with "./" for paths inside the .wxt dir', async () => {
const project = new TestProject();
project.addFile('src/entrypoints/unlisted.html', '<html></html>');
project.setConfigFileConfig({
srcDir: 'src',
alias: {
example: '.wxt/example.ts',
},
});
await project.prepare();
const output = await project.serializeFile('.wxt/tsconfig.json');
expect(output).toContain('./example.ts');
});
// TODO: Once a module has been published, use it here for testing - local files are never added to the .wxt/wxt.d.ts file
it.todo(
'should add modules from NPM to the TS project if they have a configKey',
@@ -233,7 +233,11 @@ function getMainDeclarationEntry(references: WxtDirEntry[]): WxtDirFileEntry {
async function getTsConfigEntry(): Promise<WxtDirFileEntry> {
const dir = wxt.config.wxtDir;
const getTsconfigPath = (path: string) => normalizePath(relative(dir, path));
const getTsconfigPath = (path: string) => {
const res = normalizePath(relative(dir, path));
if (res.startsWith('.') || res.startsWith('/')) return res;
return './' + res;
};
const paths = Object.entries(wxt.config.alias)
.flatMap(([alias, absolutePath]) => {
const aliasPath = getTsconfigPath(absolutePath);