@hubspot/ui-extensions-dev-server 0.0.1-prealpha.4 → 0.0.1-prealpha.6
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/build.js +7 -0
- package/dev.js +5 -0
- package/index.js +33 -0
- package/package.json +6 -6
- package/plugins/manifestPlugin.js +108 -0
- package/remoteBuild.js +0 -30
package/build.js
CHANGED
|
@@ -22,8 +22,15 @@ async function buildSingleExtension({
|
|
|
22
22
|
emptyOutDir = true,
|
|
23
23
|
plugins = { rollup: [], vite: [] },
|
|
24
24
|
minify = false,
|
|
25
|
+
root = process.cwd(), // This is the vite default, so using that as our default
|
|
25
26
|
}) {
|
|
26
27
|
await build({
|
|
28
|
+
root,
|
|
29
|
+
define: {
|
|
30
|
+
'process.env.NODE_ENV': JSON.stringify(
|
|
31
|
+
process.env.NODE_ENV || 'production'
|
|
32
|
+
),
|
|
33
|
+
},
|
|
27
34
|
build: {
|
|
28
35
|
lib: {
|
|
29
36
|
entry: file,
|
package/dev.js
CHANGED
|
@@ -12,6 +12,11 @@ const { ROLLUP_OPTIONS } = require('./constants');
|
|
|
12
12
|
async function _devBuild(config, outputDir, extension) {
|
|
13
13
|
const extensionConfig = await getExtensionConfig(config, extension);
|
|
14
14
|
build({
|
|
15
|
+
define: {
|
|
16
|
+
'process.env.NODE_ENV': JSON.stringify(
|
|
17
|
+
process.env.NODE_ENV || 'development'
|
|
18
|
+
),
|
|
19
|
+
},
|
|
15
20
|
build: {
|
|
16
21
|
watch: {
|
|
17
22
|
clearScreen: false,
|
package/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { OUTPUT_DIR } = require('./constants');
|
|
2
|
+
const { getUrlSafeFileName } = require('./utils');
|
|
3
|
+
const { buildSingleExtension } = require('./build');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const manifestPlugin = require('./plugins/manifestPlugin');
|
|
6
|
+
|
|
7
|
+
function remoteBuild(root, entryPoint, outputDir) {
|
|
8
|
+
const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];
|
|
9
|
+
const fileInfo = path.parse(entryPoint);
|
|
10
|
+
|
|
11
|
+
if (!allowedExtensions.includes(fileInfo.ext)) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`The last argument should be the filename you wish to build. Supported file extensions are [${allowedExtensions.join(
|
|
14
|
+
', '
|
|
15
|
+
)}]`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
buildSingleExtension({
|
|
20
|
+
file: entryPoint,
|
|
21
|
+
outputFileName: getUrlSafeFileName(entryPoint),
|
|
22
|
+
outputDir: outputDir || OUTPUT_DIR,
|
|
23
|
+
plugins: {
|
|
24
|
+
rollup: [manifestPlugin({ minify: true })],
|
|
25
|
+
},
|
|
26
|
+
minify: true,
|
|
27
|
+
root,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
remoteBuild,
|
|
33
|
+
};
|
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.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"constants.js",
|
|
18
18
|
"dev.js",
|
|
19
19
|
"logger.js",
|
|
20
|
-
"remoteBuild.js",
|
|
21
20
|
"run.js",
|
|
22
21
|
"utils.js",
|
|
23
22
|
"tests/runTests.js",
|
|
24
23
|
"tests/testBuild.js",
|
|
25
|
-
"tests/testDevServer.js"
|
|
24
|
+
"tests/testDevServer.js",
|
|
25
|
+
"plugins/manifestPlugin.js",
|
|
26
|
+
"index.js"
|
|
26
27
|
],
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"dependencies": {
|
|
@@ -37,8 +38,7 @@
|
|
|
37
38
|
"ws": "^8.12.1"
|
|
38
39
|
},
|
|
39
40
|
"bin": {
|
|
40
|
-
"hs-ui-extensions-dev-server": "run.js"
|
|
41
|
-
"hs-ui-extensions-remote-build": "remoteBuild.js"
|
|
41
|
+
"hs-ui-extensions-dev-server": "run.js"
|
|
42
42
|
},
|
|
43
43
|
"eslintConfig": {
|
|
44
44
|
"env": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"optional": true
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1dfa4048c08a39c6f50a5f87e92eddf1b19dde5c"
|
|
60
60
|
}
|
|
@@ -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;
|
package/remoteBuild.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { OUTPUT_DIR } = require('./constants');
|
|
3
|
-
const { getUrlSafeFileName } = require('./utils');
|
|
4
|
-
const { buildSingleExtension } = require('./build');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const manifestPlugin = require('./plugins/manifestPlugin');
|
|
7
|
-
|
|
8
|
-
const entryPoint = process.argv[process.argv.length - 1];
|
|
9
|
-
|
|
10
|
-
const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];
|
|
11
|
-
|
|
12
|
-
const fileInfo = path.parse(entryPoint);
|
|
13
|
-
|
|
14
|
-
if (!allowedExtensions.includes(fileInfo.ext)) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
`The last argument should be the filename you wish to build. Supported file extensions are [${allowedExtensions.join(
|
|
17
|
-
', '
|
|
18
|
-
)}]`
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
buildSingleExtension({
|
|
23
|
-
file: entryPoint,
|
|
24
|
-
outputFileName: getUrlSafeFileName(entryPoint),
|
|
25
|
-
outputDir: OUTPUT_DIR,
|
|
26
|
-
plugins: {
|
|
27
|
-
rollup: [manifestPlugin({ minify: true })],
|
|
28
|
-
},
|
|
29
|
-
minify: true,
|
|
30
|
-
});
|