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

PREAPPS-7580 Change Zimlet loading mechanism for supporting Content Security Policy #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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