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

Support for non-modular packages in tests and workspace resolver #2167

Closed
wants to merge 7 commits into from

Conversation

cristiano-belloni
Copy link
Contributor

@cristiano-belloni cristiano-belloni commented Sep 27, 2022

This PR stems from the discussion here: #2168 and from the necessity of either:
a) not list non-modular workspaces in workspace-resolver or
b) list them, but clarifying that they are non-modular.

Since we don't want to impact how mismatchedWorkspaceDependencies works and we like the idea of executing workspace commands on non-modular workspaces, this PR modifies the output of workspace-resolver, adding a type field, and adds support for non-modular (from now: extraneous) workspaces in modular test. In particular, modular test will:

  • identify the eventual extraneous packages with selective options (--package, --changed, --ancestors), in addition to the usual modular packages
  • try to run yarn workspace <extraneous-workspace-name> test for each one of them, after running the regular jest tests
  • emit a warning for all the selected extraneous packages that don't have a test script
  • fail the test command if one of them fails
  • succeed normally if all of them succeed

I also refactored the test command to factor out utilities and tasks.

Note: The PR seems huge, but most of the content are new test fixtures to simulate a monorepo with examples of failing, successful and non-existent test scripts in extraneous workspaces, with regular Modular workspace ancestors.

TASKS

  • type is first-class
  • Run package.json test script for non-modular workspaces or warn

@changeset-bot
Copy link

changeset-bot bot commented Sep 27, 2022

🦋 Changeset detected

Latest commit: a39a00c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
modular-scripts Minor
@modular-scripts/workspace-resolver Minor
@modular-scripts/modular-types Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coveralls
Copy link
Collaborator

coveralls commented Sep 27, 2022

Coverage Status

Coverage decreased (-0.8%) to 32.798% when pulling a39a00c on feature/non-existent-modular-type into 14b1334 on main.

@cristiano-belloni cristiano-belloni changed the title Modular type as a first-class property in ModularWorkspacePackage Support for non-modular packages in tests and workspace resolver Sep 28, 2022
@cristiano-belloni cristiano-belloni marked this pull request as ready for review September 30, 2022 14:08
Copy link
Contributor

@sgb-io sgb-io left a comment

Choose a reason for hiding this comment

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

LGTM, although I would suggest we update the README.md for workspace-resolver, so that this change is publicly documented (mainly the existence of the new type field and it's purpose).

@@ -153,7 +152,7 @@ export function analyzeWorkspaceDependencies(
// Exclude the root when analyzing package inter-dependencies
const packagesWithoutRoot = Array.from(workspacePackages.entries()).filter(
([, pkg]) => {
return pkg.modular.type !== 'root';
return pkg.modular?.type !== 'root';
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing, but this filter can be inlined to the next forEach on line 160 to avoid looping through the workspace twice.

As type has been added to the ModularWorkspacePackage, this can now be:

Suggested change
return pkg.modular?.type !== 'root';
return pkg.type !== 'root';

@@ -65,7 +65,8 @@ export async function resolveWorkspace(
const pkgPath = packageJsonPath(root);

const json = await readPackageJson(isRoot, workingDirToUse, pkgPath);
const isModularRoot = json.modular?.type === 'root';
const type = json.modular?.type || undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to cater for converting to undefined any modular.type that has been explicitly set to null?

Suggested change
const type = json.modular?.type || undefined;
const type = json.modular?.type;

@cristiano-belloni
Copy link
Contributor Author

Closing as it needs to be discussed further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants