-
Notifications
You must be signed in to change notification settings - Fork 592
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 A3 projects with npm workspaces packages #4284
Conversation
PRO-4733 Add support for `npm workspaces` in `moog-require`
They are now using npm workspaces, and when a project uses workspaces, Apostrophe is unable to detect sub-packages and that's an npm feature. Decision is to respect npm workspaces. The code should be written to understand what workspaces are active in the project and honor modules in those workspaces just like it honors the packages in package.json itself. Acceptance criteria A package in a workspace can be loaded as an Apostrophe module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General strategy makes sense, see notes. Thanks
lib/moog-require.js
Outdated
@@ -7,6 +7,30 @@ const importFresh = require('import-fresh'); | |||
const resolveFrom = require('resolve-from'); | |||
const regExpQuote = require('regexp-quote'); | |||
|
|||
const getDependencies = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use function
and place these at the end, don't front-load the file with implementation detail code that makes it harder to read the overall intent.
lib/moog-require.js
Outdated
return []; | ||
} | ||
|
||
const workspacePackages = glob.sync(`{${workspaces.join(',')}}/package.json`, { follow: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not make assumptions about the current working directory. Note how the code that calls getWorkspacesDependencies
figures out what folders to look at on each iteration and pass folder
into getWorkspacesDependencies
so you can concatenate it with the workspace name.
CHANGELOG.md
Outdated
|
||
### Adds | ||
|
||
* Add support for npm workspaces dependencies. A workspace dependencies can now be used as an Apostrophe module even if it is not a direct dependency of the Apostrophe project. Only direct workspaces dependencies of the Apostrophe project are supported. e.g. I have an Apostrophe project called `website`. `website` is set with 2 workspaces, `workspace-a` & `workspace-b`. `workspace-a` `package.json` contains a module named `blog` as a dependency. `website` can reference `blog` as enabled in the `modules` configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A workspaces dependencies -> A workspaces dependency
"For instance, I have..."
"With 2 workspaces" -> "with two npm workspaces"
Link "npm workspaces" to relevant npm documentation on the first mention
(And sync up with Bob for docs)
return []; | ||
} | ||
|
||
const pattern = workspaces.length === 1 ? workspaces[0] : `{${workspaces.join(',')}}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure the join call is always sufficient here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment, glob expects at least two entries when using curly braces. Silly bug!
|
||
const pattern = workspaces.length === 1 ? workspaces[0] : `{${workspaces.join(',')}}`; | ||
const packagePath = path.resolve(folder, pattern, 'package.json'); | ||
const workspacePackages = glob.sync(packagePath, { follow: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
niiice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very slick use of advanced glob features
* main: fix code overthinking Response to first comments Add note to CHANGELOG expands per area configuration
@@ -0,0 +1,40 @@ | |||
const createLogger = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good technique.
* main: hotfix for logging non-Error exceptions from api routes typo works update confirm message replace --force with --confirm + remove prompts for hosted customer users add --force to skip prompt remove stray log use prompts and update changelog figure should reset the wrapper handle paragraph without texts add lint-fix and remove-empty-paragraph task to rich-text
Summary
Add support for direct workspace dependencies
What are the specific steps to test this change?
You run the test
test/workspaces-project.js
ora3-boilerplate
npm init -w workspace-a -y
to createworkspace-a
@apostrophecms-pro/scheduled-publishing
inworkspace-a
withnpm install -w workspace-a --save @apostrophecms-pro/scheduled-publishing
a3-boilerplate
project, enable the module@apostrophecms-pro/scheduled-publishing
. It should not be present in thea3-boilerplate
package.json
. It should pass.apostrophe
main
branch, the same thing should fail withThe configured bundle @apostrophecms-pro/scheduled-publishing was not found in npm
What kind of change does this PR introduce?
(Check at least one)
Make sure the PR fulfills these requirements:
If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.
Other information: