Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapped globSync and extracted blueprintRoot #24

Merged
merged 8 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/migration/ember-addon/steps/create-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import { join } from 'node:path';

import { findFiles, unionize } from '../../../utils/files.js';

function validatePackageJson({ name, version }) {
if (!name) {
throw new SyntaxError('Package name is missing.');
}

if (name.includes('/')) {
// eslint-disable-next-line no-unused-vars
const [_scope, packageName] = name.split('/');

if (!packageName) {
throw new SyntaxError('Package name is missing.');
}
}

if (!version) {
throw new SyntaxError('Package version is missing.');
}
}

function analyzePackageJson(codemodOptions) {
const { projectRoot } = codemodOptions;

Expand All @@ -20,13 +39,7 @@ function analyzePackageJson(codemodOptions) {
version,
} = JSON.parse(packageJsonFile);

if (!name) {
throw new SyntaxError('Package name is missing.');
}

if (!version) {
throw new SyntaxError('Package version is missing.');
}
validatePackageJson({ name, version });

const projectDependencies = new Map([
...Object.entries(dependencies ?? {}),
Expand Down Expand Up @@ -89,13 +102,7 @@ function deriveAddonLocation(addonPackage) {
}

// eslint-disable-next-line no-unused-vars
const [scope, packageName] = addonPackage.name.split('/');

if (!packageName) {
throw new SyntaxError(
`ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
);
}
Comment on lines -86 to -90
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ember-codemod-pod-to-octane, I realized that it's not a good idea to perform validation inside this function (concerns weren't separated well).

const [_scope, packageName] = addonPackage.name.split('/');

return packageName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('migration | ember-addon | steps | create-options > error handling (package
(error) => {
assert.strictEqual(
error.message,
'ERROR: In package.json, the package name `@ijlee2/` is not valid.'
'ERROR: package.json is missing or is not valid. (Package name is missing.)\n'
);

return true;
Expand Down