Skip to content

Commit

Permalink
PREAPPS-7580 Added the name function for zimlet identification.
Browse files Browse the repository at this point in the history
  • Loading branch information
damini-vashishtha committed Jul 15, 2024
1 parent 4626520 commit 9a19ed4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'eslint-config-synacor'
],
globals: {
zimlet: true
getZimlet: true
},
rules: {
indent: ['error', 'tab', {
Expand Down
59 changes: 32 additions & 27 deletions src/entry.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
/** This is the real webpack entry file. It manages setting up the zimlet and HMR.
* The user-defined entry file (index.js) is imported here via a `zimlet-cli-entrypoint` alias.
*/
( () => {
function init() {
zimlet( context => {
let { zimbra, config, plugins, shims, components, store, meta } = context;
(() =>
getZimlet({
code: (() => {
function init() {
return (context) => {
let { zimbra, config, plugins, shims, components, store, meta } =
context;

// Add shims to the global scope to expose dependencies to Zimlets
// Shimmed dependencies include preact, preact-router, react-apollo
global.shims = shims;
// Add shims to the global scope to expose dependencies to Zimlets
// Shimmed dependencies include preact, preact-router, react-apollo
global.shims = shims;

global.zimbra = zimbra;
global.config = config;
global.plugins = plugins;
global.components = components;
global.store = store;
global.zimbra = zimbra;
global.config = config;
global.plugins = plugins;
global.components = components;
global.store = store;

global.ZIMLET_STYLES = [];
global.ZIMLET_STYLES = [];

global.meta = meta;
global.meta = meta;

let entry = require('zimlet-cli-entrypoint');
let r = entry && entry.default || entry;
let entry = require('zimlet-cli-entrypoint');
let r = (entry && entry.default) || entry;

// If export is a factory, pass it context. Otherwise it's a singleton.
let instance = typeof r==='function' ? r(context) : r;
// If export is a factory, pass it context. Otherwise it's a singleton.
let instance = typeof r === 'function' ? r(context) : r;

context.styles.set(global.ZIMLET_STYLES.join('\n'));
context.styles.set(global.ZIMLET_STYLES.join('\n'));

return instance;
});
}
return instance;
};
}

init();
if (process.env.NODE_ENV === 'development' && module.hot) {
module.hot.accept('zimlet-cli-entrypoint', init);
}

if (process.env.NODE_ENV==='development' && module.hot) {
module.hot.accept('zimlet-cli-entrypoint', init);
}
})();
return init();
})(),
name: () => require('zimlet-cli-entrypoint-package').name
}))();
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export function configure(env) {
react: getShimPath('preact/compat'),
'react-dom': getShimPath('preact/compat'),
style: path.resolve(context, 'style'),
'zimlet-cli-entrypoint': path.resolve(context, entry)
'zimlet-cli-entrypoint': path.resolve(context, entry),
'zimlet-cli-entrypoint-package': path.resolve(context, path.resolve(cwd, 'package.json'))
}
},

Expand Down

0 comments on commit 9a19ed4

Please sign in to comment.