Skip to content

Commit 9a19ed4

Browse files
PREAPPS-7580 Added the name function for zimlet identification.
1 parent 4626520 commit 9a19ed4

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
'eslint-config-synacor'
55
],
66
globals: {
7-
zimlet: true
7+
getZimlet: true
88
},
99
rules: {
1010
indent: ['error', 'tab', {

src/entry.js

+32-27
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
/** This is the real webpack entry file. It manages setting up the zimlet and HMR.
22
* The user-defined entry file (index.js) is imported here via a `zimlet-cli-entrypoint` alias.
33
*/
4-
( () => {
5-
function init() {
6-
zimlet( context => {
7-
let { zimbra, config, plugins, shims, components, store, meta } = context;
4+
(() =>
5+
getZimlet({
6+
code: (() => {
7+
function init() {
8+
return (context) => {
9+
let { zimbra, config, plugins, shims, components, store, meta } =
10+
context;
811

9-
// Add shims to the global scope to expose dependencies to Zimlets
10-
// Shimmed dependencies include preact, preact-router, react-apollo
11-
global.shims = shims;
12+
// Add shims to the global scope to expose dependencies to Zimlets
13+
// Shimmed dependencies include preact, preact-router, react-apollo
14+
global.shims = shims;
1215

13-
global.zimbra = zimbra;
14-
global.config = config;
15-
global.plugins = plugins;
16-
global.components = components;
17-
global.store = store;
16+
global.zimbra = zimbra;
17+
global.config = config;
18+
global.plugins = plugins;
19+
global.components = components;
20+
global.store = store;
1821

19-
global.ZIMLET_STYLES = [];
22+
global.ZIMLET_STYLES = [];
2023

21-
global.meta = meta;
24+
global.meta = meta;
2225

23-
let entry = require('zimlet-cli-entrypoint');
24-
let r = entry && entry.default || entry;
26+
let entry = require('zimlet-cli-entrypoint');
27+
let r = (entry && entry.default) || entry;
2528

26-
// If export is a factory, pass it context. Otherwise it's a singleton.
27-
let instance = typeof r==='function' ? r(context) : r;
29+
// If export is a factory, pass it context. Otherwise it's a singleton.
30+
let instance = typeof r === 'function' ? r(context) : r;
2831

29-
context.styles.set(global.ZIMLET_STYLES.join('\n'));
32+
context.styles.set(global.ZIMLET_STYLES.join('\n'));
3033

31-
return instance;
32-
});
33-
}
34+
return instance;
35+
};
36+
}
3437

35-
init();
38+
if (process.env.NODE_ENV === 'development' && module.hot) {
39+
module.hot.accept('zimlet-cli-entrypoint', init);
40+
}
3641

37-
if (process.env.NODE_ENV==='development' && module.hot) {
38-
module.hot.accept('zimlet-cli-entrypoint', init);
39-
}
40-
})();
42+
return init();
43+
})(),
44+
name: () => require('zimlet-cli-entrypoint-package').name
45+
}))();

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export function configure(env) {
186186
react: getShimPath('preact/compat'),
187187
'react-dom': getShimPath('preact/compat'),
188188
style: path.resolve(context, 'style'),
189-
'zimlet-cli-entrypoint': path.resolve(context, entry)
189+
'zimlet-cli-entrypoint': path.resolve(context, entry),
190+
'zimlet-cli-entrypoint-package': path.resolve(context, path.resolve(cwd, 'package.json'))
190191
}
191192
},
192193

0 commit comments

Comments
 (0)