Skip to content

Commit 0558038

Browse files
authored
fix: validate options.name to be a valid JS identifier name (#91)
1 parent 9aa073e commit 0558038

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/core/src/plugin/validate-options.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import type { ModuleFederationConfig, Shared } from '../types';
22
import { ConfigError } from '../utils';
33

4+
function validateName(name: string) {
5+
const validEcmaIdentifierRegex =
6+
// biome-ignore lint/suspicious/noMisleadingCharacterClass: works
7+
/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u;
8+
9+
if (!validEcmaIdentifierRegex.test(name)) {
10+
throw new ConfigError(
11+
`Invalid 'name': ${name}. The 'name' must be a valid JavaScript identifier.`
12+
);
13+
}
14+
}
15+
416
function validateFilename(filename: string | undefined) {
517
// filename is optional
618
if (!filename) {
@@ -66,6 +78,9 @@ function validateShared(shared: Shared | undefined) {
6678
}
6779

6880
export function validateOptions(options: ModuleFederationConfig) {
81+
// validate name
82+
validateName(options.name);
83+
6984
// validate filename
7085
validateFilename(options.filename);
7186

0 commit comments

Comments
 (0)