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

Conversation

ijlee2
Copy link
Owner

@ijlee2 ijlee2 commented Mar 10, 2023

Background

In #20, updating glob from v8 to v9 involved fixing breaking changes. Fortunately, the fix wasn't difficult because I had used glob.sync (now named globSync) in only two (2) different ways.

Nonetheless, globSync is used in several files, each with a unique context (i.e. the steps are different from one another). To help onboard new contributors, we should wrap globSync and minimize the API that we need.

What changed?

I took care of a few technical risks:

  • Commits 1-3: Created a function called findFiles, which wraps globSync and minimizes the API.
  • Commit 4: Extracted a function called unionize, which creates the brace expansion that glob understands.
  • Commit 5: Extracted a constant called blueprintRoot. The value depends on where npx installs the codemod on the end-developer's machine.
  • Commit 6: Wrote tests for findFiles and blueprintRoot.
  • Commit 7: Separated validation concerns.
  • Commit 8: Documented a hidden order dependency.

@ijlee2 ijlee2 added the enhance: code Issue asks for new feature or refactor label Mar 10, 2023
@ijlee2 ijlee2 force-pushed the refactor-wrap-glob branch from 6c1053b to 80985cd Compare March 10, 2023 07:23
@ijlee2 ijlee2 marked this pull request as ready for review March 10, 2023 07:24
@ijlee2 ijlee2 merged commit 610d178 into main Mar 10, 2023
@ijlee2 ijlee2 deleted the refactor-wrap-glob branch March 10, 2023 07:39
@ijlee2 ijlee2 added enhance: documentation Issue asks for better documentation (e.g. README, code, tests) and removed enhance: code Issue asks for new feature or refactor labels Mar 10, 2023
@@ -30,7 +30,6 @@ function getPublicAssets(options) {

const filePaths = findFiles('public/**/*', {
cwd: projectRoot,
matchFilesOnly: true,
Copy link
Owner Author

Choose a reason for hiding this comment

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

So far, we always looked for files (and never directories).


test('utils | blueprints | blueprint-root', function () {
assert.strictEqual(
blueprintRoot.endsWith('src/blueprints/ember-addon'),
Copy link
Owner Author

Choose a reason for hiding this comment

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

Given that the value of blueprintRoot depends on where the codemod is installed locally, the assertion using endsWith may be the strongest assertion that we can make (without leaking the implementation details in the test).

Comment on lines -94 to -98
if (!packageName) {
throw new SyntaxError(
`ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
);
}
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).

Comment on lines +111 to +113
/*
This object has an order dependency. The `default` key must appear last.
*/
Copy link
Owner Author

Choose a reason for hiding this comment

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

Related: #16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance: documentation Issue asks for better documentation (e.g. README, code, tests)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant