fix: Only allow a single entrypoint with a given name
This commit is contained in:
@@ -421,20 +421,11 @@ describe('findEntrypoints', () => {
|
||||
expect(entrypoints[0]).toEqual(expected);
|
||||
});
|
||||
|
||||
it.todo(
|
||||
'should ignore CSS and JS files inside a HTML page directory',
|
||||
() => {},
|
||||
);
|
||||
it('should not allow multiple entrypoints with the same name', async () => {
|
||||
globMock.mockResolvedValueOnce(['popup.html', 'popup/index.html']);
|
||||
|
||||
it.todo(
|
||||
'should warn when there is an unexpected file in the entrypoints directory',
|
||||
() => {},
|
||||
);
|
||||
|
||||
it.todo(
|
||||
'should ignore entrypoints starting with a . (preventing warnings like .DS_Store files)',
|
||||
() => {},
|
||||
);
|
||||
|
||||
it.todo('should not allow multiple entrypoints with the same name', () => {});
|
||||
await expect(() => findEntrypoints(config)).rejects.toThrowError(
|
||||
'Multiple entrypoints with the name "popup" detected, but only one is allowed: src/entrypoints/popup.html, src/entrypoints/popup/index.html',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { resolve } from 'path';
|
||||
import { relative, resolve } from 'path';
|
||||
import {
|
||||
BackgroundEntrypoint,
|
||||
BackgroundScriptDefintition,
|
||||
@@ -30,6 +30,7 @@ export async function findEntrypoints(
|
||||
relativePaths.sort();
|
||||
|
||||
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
||||
const existingNames: Record<string, Entrypoint | undefined> = {};
|
||||
|
||||
const entrypoints: Entrypoint[] = [];
|
||||
await Promise.all(
|
||||
@@ -79,7 +80,19 @@ export async function findEntrypoints(
|
||||
};
|
||||
}
|
||||
|
||||
const withSameName = existingNames[entrypoint.name];
|
||||
if (withSameName) {
|
||||
throw Error(
|
||||
`Multiple entrypoints with the name "${
|
||||
entrypoint.name
|
||||
}" detected, but only one is allowed: ${[
|
||||
relative(config.root, withSameName.inputPath),
|
||||
relative(config.root, entrypoint.inputPath),
|
||||
].join(', ')}`,
|
||||
);
|
||||
}
|
||||
entrypoints.push(entrypoint);
|
||||
existingNames[entrypoint.name] = entrypoint;
|
||||
}),
|
||||
);
|
||||
return entrypoints;
|
||||
|
||||
Reference in New Issue
Block a user