Skip to content

Commit

Permalink
fix(misc): correct some broken normalizations
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Nov 28, 2024
1 parent 1d13e34 commit a5439e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
1 change: 0 additions & 1 deletion packages/expo/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('component', () => {
appTree = createTreeWithEmptyWorkspace();
appTree.write('.gitignore', '');
defaultSchema = {
name: 'hello',
path: 'my-lib/src/lib/hello/hello',
skipTests: false,
export: false,
Expand Down
19 changes: 1 addition & 18 deletions packages/expo/src/generators/component/lib/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export async function normalizeOptions(
host: Tree,
options: Schema
): Promise<NormalizedSchema> {
assertValidOptions(options);

const {
artifactName: name,
fileName,
Expand Down Expand Up @@ -45,6 +43,7 @@ export async function normalizeOptions(

return {
...options,
name,
directory,
className,
fileName,
Expand All @@ -53,19 +52,3 @@ export async function normalizeOptions(
projectName,
};
}

function assertValidOptions(options: Schema) {
const slashes = ['/', '\\'];
slashes.forEach((s) => {
if (options.name.indexOf(s) !== -1) {
const [name, ...rest] = options.name.split(s).reverse();
let suggestion = rest.map((x) => x.toLowerCase()).join(s);
if (options.path) {
suggestion = `${options.path}${s}${suggestion}`;
}
throw new Error(
`Found "${s}" in the component name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`
);
}
});
}
20 changes: 10 additions & 10 deletions packages/react/src/generators/hook/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ async function normalizeOptions(
options: Schema
): Promise<NormalizedSchema> {
const {
artifactName,
directory,
fileName: _fileName,
fileName: hookFilename,
project: projectName,
} = await determineArtifactNameAndDirectoryOptions(host, {
path: options.path,
name: options.name,
fileExtension: 'tsx',
});

const { className, fileName } = names(_fileName);
const { className } = names(hookFilename);

// If using `as-provided` file and directory, then don't normalize.
// Otherwise, support legacy behavior of prefixing filename with `use-`.
const hookFilename = fileName;
const hookName = className.toLocaleLowerCase().startsWith('use')
? className
: 'use'.concat(className);
const hookTypeName = className.toLocaleLowerCase().startsWith('use')
// if name is provided, use it as is for the hook name, otherwise prepend
// `use` to the pascal-cased file name if it doesn't already start with `use`
const hookName = options.name
? artifactName
: className.toLocaleLowerCase().startsWith('use')
? className
: 'Use'.concat(className);
: `use${className}`;
const hookTypeName = names(hookName).className;
const project = getProjects(host).get(projectName);

const { sourceRoot: projectSourceRoot, projectType } = project;
Expand Down

0 comments on commit a5439e8

Please sign in to comment.