Skip to content

Commit

Permalink
Cross-package manager Volto path resolver in webpack-relative-resolver (
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Mar 19, 2024
1 parent f81d86f commit 23f071e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/registry/news/5893.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-package manager Volto path resolver in `webpack-relative-resolver` @sneridagh
1 change: 1 addition & 0 deletions packages/registry/src/addon-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class AddonConfigurationRegistry {
}

this.projectRootPath = projectRootPath;
this.isVoltoProject = packageJson.name !== '@plone/volto';
this.voltoPath =
packageJson.name === '@plone/volto'
? `${projectRootPath}`
Expand Down
4 changes: 3 additions & 1 deletion packages/volto/__tests__/webpack-relative-resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ describe('WebpackRelativeResolver', () => {

it('handles "installed Volto" resolve requests', () => {
const registry = makeRegistry();
registry.voltoPath = '/myvoltoproject/node_modules/@plone/volto';
registry.isVoltoProject = true;
const resolver = new WebpackRelativeResolver(registry);
resolver.voltoPaths['@plone/volto/'] =
'/myvoltoproject/node_modules/@plone/volto/src';

const req = makeInstalledVoltoRequest();
const resolvePath = resolver.getResolvePath(req);
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/5893.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-package manager Volto path resolver in `webpack-relative-resolver` @sneridagh
1 change: 1 addition & 0 deletions packages/volto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@plone/volto-slate/(.*)$": "<rootDir>/../volto-slate/src/$1",
"@plone/registry": "<rootDir>/../registry/src",
"@plone/registry/(.*)$": "<rootDir>/../registry/src/$1",
"@plone/volto": "<rootDir>/src/index.js",
"~/config": "<rootDir>/src/config",
"~/../locales/${lang}.json": "<rootDir>/locales/en.json",
"(.*)/locales/(.*)": "<rootDir>/locales/$2",
Expand Down
5 changes: 4 additions & 1 deletion packages/volto/webpack-plugins/webpack-relative-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ class RelativeResolverPlugin {
this.source = source || 'resolve';
this.target = target || 'resolve';
this.registry = registry;
this.voltoModulePath = registry.isVoltoProject
? require.resolve('@plone/volto').split('/').slice(0, -1).join('/')
: `${registry.voltoPath}/src`;
this.voltoPaths = Object.assign(
{ '@plone/volto/': `${registry.voltoPath}/src` },
{ '@plone/volto/': this.voltoModulePath },
...Object.keys(registry.packages).map((k) => ({
[k]: registry.packages[k].modulePath,
})),
Expand Down

0 comments on commit 23f071e

Please sign in to comment.