@hubspot/ui-extensions-dev-server 0.0.1-prealpha.4 → 0.0.1-prealpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/plugins/manifestPlugin.js +108 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/ui-extensions-dev-server",
|
|
3
|
-
"version": "0.0.1-prealpha.
|
|
3
|
+
"version": "0.0.1-prealpha.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"utils.js",
|
|
23
23
|
"tests/runTests.js",
|
|
24
24
|
"tests/testBuild.js",
|
|
25
|
-
"tests/testDevServer.js"
|
|
25
|
+
"tests/testDevServer.js",
|
|
26
|
+
"plugins/manifestPlugin.js"
|
|
26
27
|
],
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"dependencies": {
|
|
@@ -56,5 +57,5 @@
|
|
|
56
57
|
"optional": true
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "a4652eb58cbde813dbebc8b7127c36102b9b6ed6"
|
|
60
61
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const { readFileSync } = require('fs');
|
|
2
|
+
const { normalize } = require('path');
|
|
3
|
+
const logger = require('../logger');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_MANIFEST_NAME = 'manifest.json';
|
|
6
|
+
const PACKAGE_LOCK_FILE = 'package-lock.json';
|
|
7
|
+
const PACKAGE_FILE = 'package.json';
|
|
8
|
+
const EXTENSIONS_PATH = 'src/app/extensions/';
|
|
9
|
+
|
|
10
|
+
function plugin(options = {}) {
|
|
11
|
+
return {
|
|
12
|
+
name: 'ui-extensions-manifest-generation-plugin',
|
|
13
|
+
enforce: 'post', // run after default rollup plugins
|
|
14
|
+
generateBundle(_rollupOptions, bundle) {
|
|
15
|
+
const { output = DEFAULT_MANIFEST_NAME, minify = false } = options;
|
|
16
|
+
try {
|
|
17
|
+
const manifest = _generateManifestContents(bundle);
|
|
18
|
+
this.emitFile({
|
|
19
|
+
type: 'asset',
|
|
20
|
+
source: minify
|
|
21
|
+
? JSON.stringify(manifest)
|
|
22
|
+
: JSON.stringify(manifest, null, 2),
|
|
23
|
+
fileName: normalize(output),
|
|
24
|
+
});
|
|
25
|
+
} catch (e) {
|
|
26
|
+
logger.warn(`\nUnable to write manifest file in ${output}, ${e}`);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _generateManifestContents(bundle) {
|
|
33
|
+
const baseManifest = {
|
|
34
|
+
package: _loadPackageFile(),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// The keys to bundle are the filename without any path information
|
|
38
|
+
const bundles = Object.keys(bundle);
|
|
39
|
+
|
|
40
|
+
if (bundles.length === 1) {
|
|
41
|
+
return {
|
|
42
|
+
..._generateManifestEntry(bundle[bundles[0]]),
|
|
43
|
+
...baseManifest,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const manifest = bundles.reduce((acc, current) => {
|
|
48
|
+
return {
|
|
49
|
+
...acc,
|
|
50
|
+
[current]: _generateManifestEntry(bundle[current], false),
|
|
51
|
+
};
|
|
52
|
+
}, {});
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...manifest,
|
|
56
|
+
...baseManifest,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _generateManifestEntry(subBundle) {
|
|
61
|
+
const { facadeModuleId, moduleIds, modules } = subBundle;
|
|
62
|
+
return {
|
|
63
|
+
entry: _stripPathPriorToExtDir(facadeModuleId),
|
|
64
|
+
modules: _buildModulesInfo(moduleIds, modules),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _loadJsonFileSafely(filename) {
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(readFileSync(filename).toString());
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function _loadPackageFile() {
|
|
77
|
+
// Look for package-lock.json then fallback to package.json
|
|
78
|
+
return (
|
|
79
|
+
_loadJsonFileSafely(PACKAGE_LOCK_FILE) || _loadJsonFileSafely(PACKAGE_FILE)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function _stripPathPriorToExtDir(filepath) {
|
|
84
|
+
return filepath.split(EXTENSIONS_PATH).pop();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function _buildModulesInfo(moduleIds, modules) {
|
|
88
|
+
return moduleIds.reduce(
|
|
89
|
+
(acc, mod) => {
|
|
90
|
+
const { renderedExports } = modules[mod];
|
|
91
|
+
|
|
92
|
+
const moduleData = {
|
|
93
|
+
module: _stripPathPriorToExtDir(mod),
|
|
94
|
+
renderedExports,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if (moduleData.module.includes('node_modules')) {
|
|
98
|
+
acc.external.push(moduleData);
|
|
99
|
+
} else {
|
|
100
|
+
acc.internal.push(moduleData);
|
|
101
|
+
}
|
|
102
|
+
return acc;
|
|
103
|
+
},
|
|
104
|
+
{ internal: [], external: [] }
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = plugin;
|