Raw
1 /**
2 * Validates the module name to be variable safe. Since we generate
3 * a lot of code, types under the hood using the module name we
4 * have ensure that each module name is variable safe.
5 *
6 * Ofcourse, we can transform the module name to a variable safe value,
7 * but that might result into naming conflicts. For example: There are
8 * two module named as
9 *
10 * - sanity-products
11 * - sanity_products
12 *
13 * After transforming them, they will endup with the same output. This is
14 * a very simple example, but cases like these will lead to naming
15 * conflicts, so its better to use the names as it is and restrict
16 * them to be variable safe
17 */
18 const RE = /^[a-zA-Z_][0-9a-zA-Z_]*$/
19 export function validateModuleName(name: string) {
20 if (!RE.test(name)) {
21 throw new Error(
22 `Invalid module name "${name}". Module names must be alpha numeric and may contain an underscore`
23 )
24 }
25 }