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

PDE-4678 fix(cli): zapier build fails with npm workspaces #738

Merged
merged 14 commits into from
Feb 2, 2024

Conversation

eliangcs
Copy link
Member

@eliangcs eliangcs commented Jan 30, 2024

Fixes #648.

Some developers may choose to structure their project using npm workpaces or yarn workspaces. An example project structure might look like:

(project root)
├─ package.json
└── packages/
    ├─ app-1/
    │  ├─ index.js
    │  └─ package.json
    └─ app-2/
        ├─ index.js
        └─ package.json

If you run npm install in the above example, app-1 and app-2 will share their dependencies in the project root's node_modules. Only the dependencies with version discrepancies will be placed into app-1/node_modules or app-2/node_modules.

The current implementation of zapier build doesn't support workspaces. It always assume it can always find zapier-platform-core in the working directory's node_modules.

This PR fixes that by finding zapier-platform-core in the working directory and all the parent directories.

@eliangcs
Copy link
Member Author

@rnegron this is still work-in-progress as I'd like to add some test cases. But you might want to take a look first, because I also modified copyDir() as you did in #737.

@eliangcs eliangcs changed the title fix(cli): zapier build fails with npm workspaces PDE-4678 fix(cli): zapier build fails with npm workspaces Jan 30, 2024
@rnegron
Copy link
Member

rnegron commented Jan 30, 2024

@eliangcs

But you might want to take a look first, because I also modified copyDir() as you did in #737.

Thanks for letting me know! Let's use this PR for those initial async/await changes, since I will likely modify it further to add some fs.lstatSync(...).isSymbolicLink() related logic!

@eliangcs eliangcs marked this pull request as ready for review January 31, 2024 08:11
@eliangcs
Copy link
Member Author

@rnegron this is ready for review. Thanks!

rnegron
rnegron previously approved these changes Jan 31, 2024
@@ -309,3 +311,189 @@ describe('build (runs slowly)', function () {
should.equal(buildExists, true);
});
});

describe('build in workspaces', function () {
Copy link
Member

Choose a reason for hiding this comment

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

Great and easy to follow tests! 👍🏻

@@ -38,27 +37,137 @@ describe('files', () => {
.catch(done);
});

// TODO: this is broken in travis - works locally though
Copy link
Member

Choose a reason for hiding this comment

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

👏🏻


startSpinner('Building app definition.json');
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this spinner was removed intentionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a mistake. Added it back in 52fba09. Thanks!

Comment on lines +87 to +88
Returns a promise that copies a directory recursively.

Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 Always appreciate these descriptive comments

@eliangcs
Copy link
Member Author

eliangcs commented Feb 1, 2024

@rnegron I merged your PR #737 and added some code to exclude workspace symlinks, such as node_modules/app-1 and node_modules/app-2, from the build.zip. Can you re-review? Thanks a lot!

fse.readlinkSync(src)
);
for (const workspace of workspaces) {
if (minimatch(realPath, workspace)) {
Copy link
Member

Choose a reason for hiding this comment

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

@eliangcs Could we add a comment here explaining what this minimatch line is doing? I believe it's true if the src symlink resolves (points to) to a workspace path, in which case we want to filter out (return false) this particular src. So that we don't copy over any symlinks that point to workspace folders.

Copy link
Member Author

@eliangcs eliangcs Feb 2, 2024

Choose a reason for hiding this comment

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

You interpretation is correct. Since the workspaces array in the root package.json can contain glob patterns, like packages/*, I use minimatch to help us do glob pattern matching. For example, minimatch('/path/to/packages/app-1', '/path/to/packages/*') returns true.

I'll add a comment in a separate PR. Thanks!

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.

[Bug]: zapier push fails with npm workspaces
2 participants