Skip to content

Commit

Permalink
fix(enhanced): update share options of share plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed Nov 25, 2024
1 parent 358ba00 commit cbd573c
Show file tree
Hide file tree
Showing 29 changed files with 83 additions and 23 deletions.
2 changes: 0 additions & 2 deletions packages/enhanced/src/lib/sharing/SharePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class SharePlugin {
requiredVersion: options.requiredVersion,
strictVersion: options.strictVersion,
singleton: options.singleton,
issuerLayer: options.issuerLayer,
requiredLayer: options.requiredLayer,
},
}));
//@ts-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'react';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it('should load module with correct layer from entry layer', async () => {
const { version, layer } = await import('./async-boundary');
expect(version).toBe('1.0.0');
expect(layer).toBe('module-layer');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './index-test';
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = function layerLoader(source) {
// Inject the layer name as an export
return [
source,
'export const layer = "react-layer";'
].join('\n');
return [source, 'export const layer = "module-layer";'].join('\n');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { ConsumeSharedPlugin } = require('../../../../dist/src');
const path = require('path');

module.exports = {
mode: 'development',
devtool: false,
entry: {
main: {
import: './index.js',
layer: 'entry-layer',
},
},
experiments: {
layers: true,
},
module: {
rules: [
{
test: /async-boundary\.js$/,
issuerLayer: 'entry-layer',
use: [
{
loader: path.resolve(__dirname, './layer-exporter.js'),
},
],
},
],
},
plugins: [
new ConsumeSharedPlugin({
consumes: {
react: {
singleton: true,
shareKey: 'react',
},
},
}),
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/.federation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'react';
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = function layerLoader(source) {
// Inject the layer name as an export
return [
source,
'export const layer = "differing-layer";'
].join('\n');
return [source, 'export const layer = "differing-layer";'].join('\n');
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
it('Module graph should have a layer different layer', async () => {
const {version, layer} = (await import('react'));
const { version, layer } = await import('react');
expect(version).toBe('1.0.0');
expect(layer).toBe('differing-layer');
});

it('Module graph should have a layer set explicitly thats not the inherited issuerLayer', async () => {
const {dix, layer} = (await import('react/index2'));
const { dix, layer } = await import('react/index2');
expect(dix).toBe('1.0.0');
expect(layer).toBe('explicit-layer');
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = function layerLoader(source) {
// Inject the layer name as an export
return [
source,
'export const layer = "explicit-layer";'
].join('\n');
return [source, 'export const layer = "explicit-layer";'].join('\n');
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
it('Module Graph should have layerd share', async () => {
const {version, layer} = (await import('./async-boundary'));
const { version, layer } = await import('./async-boundary');
expect(version).toBe('1.0.0');
expect(layer).toBe('react-layer');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './index-test';
import './other-test';
import './differing-test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function layerLoader(source) {
// Inject the layer name as an export
return [source, 'export const layer = "react-layer";'].join('\n');
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
it('Module Graph should unlayered share', async () => {
const {version, layer} = (await import('./async-boundary'));
const { version, layer } = await import('./async-boundary');
expect(version).toBe('1.0.0');
expect(layer).toBeUndefined();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './other-test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "layered-react-test",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "webpack --config=webpack.config.js"
},
"dependencies": {
"react": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
layers: true,
findBundle: function () {
return ['bundle0.js'];
},
};

This file was deleted.

3 changes: 0 additions & 3 deletions packages/enhanced/test/configCases/sharing/layers/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/enhanced/test/configCases/sharing/layers/other.js

This file was deleted.

0 comments on commit cbd573c

Please sign in to comment.