@hubspot/cms-dev-server 1.1.0-prerelease.6 → 1.1.0-prerelease.8
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/dist/lib/argHelpers.js +6 -0
- package/dist/lib/cli.js +23 -0
- package/dist/lib/renderHelpers.js +34 -10
- package/dist/plugins/devMockClientEntryPlugin.js +52 -0
- package/dist/routes/module.js +2 -1
- package/dist/routes/partial.js +2 -1
- package/package.json +7 -4
- package/dist/lib/createIslandsGlobalJsForClientInDev.js +0 -32
- package/dist/lib/traverseFieldsJson.js +0 -78
- package/dist/render/renderOnServer.js +0 -40
- package/dist/render/renderOnServer.test.js +0 -24
- package/dist/render/renderStreamToPromise.js +0 -35
- package/dist/resolveSharedDeps.js +0 -28
package/dist/lib/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
export function getDevServerCommandLineOptions(argv) {
|
|
3
|
+
const args = [...argv];
|
|
4
|
+
const webRoot = args[2];
|
|
5
|
+
let hubspotCliConfigPathOption;
|
|
6
|
+
let hubspotCliAccountNameOption;
|
|
7
|
+
// Very basic CLI option parsing
|
|
8
|
+
const configOptionIndex = args.findIndex(arg => arg === '-c' || arg === '--config');
|
|
9
|
+
if (configOptionIndex > 0 && args.length > configOptionIndex) {
|
|
10
|
+
hubspotCliConfigPathOption = resolve(args[configOptionIndex + 1]);
|
|
11
|
+
args.splice(configOptionIndex, 2);
|
|
12
|
+
}
|
|
13
|
+
const accountOptionIndex = args.findIndex(arg => arg === '-a' || arg === '--account');
|
|
14
|
+
if (accountOptionIndex > 0 && args.length > accountOptionIndex) {
|
|
15
|
+
hubspotCliAccountNameOption = args[accountOptionIndex + 1];
|
|
16
|
+
args.splice(accountOptionIndex, 2);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
webRoot,
|
|
20
|
+
hubspotCliConfigPathOption,
|
|
21
|
+
hubspotCliAccountNameOption,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,21 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function getByteSizeOf(props) {
|
|
2
|
+
return Buffer.from(JSON.stringify(props)).length;
|
|
3
|
+
}
|
|
4
|
+
function formatBytesToString(bytes) {
|
|
5
|
+
if (bytes > 1000000) {
|
|
6
|
+
// If byte size is > 1mb, show size in red
|
|
7
|
+
return ['\x1b[31m', `${(bytes / 1000000).toFixed(2)}mb`];
|
|
6
8
|
}
|
|
7
|
-
else if (
|
|
8
|
-
// if
|
|
9
|
-
return ['\x1b[33m', `${(
|
|
9
|
+
else if (bytes > 10000) {
|
|
10
|
+
// if byte size is between 10kb and 1mb, show size in yellow
|
|
11
|
+
return ['\x1b[33m', `${(bytes / 1000).toFixed(2)}kb`];
|
|
10
12
|
}
|
|
11
13
|
else {
|
|
12
14
|
// Show size in green
|
|
13
|
-
return ['\x1b[32m', `${(
|
|
15
|
+
return ['\x1b[32m', `${(bytes / 1000).toFixed(2)}kb`];
|
|
14
16
|
}
|
|
17
|
+
}
|
|
18
|
+
const getPropsInfo = (props, reportOptions = { showNestedKeySizeIfGreater: null }, recursionDepth = 0) => {
|
|
19
|
+
if (recursionDepth > 8) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const propsSizeInBytes = getByteSizeOf(props);
|
|
23
|
+
const result = formatBytesToString(propsSizeInBytes);
|
|
24
|
+
if (!Array.isArray(props) &&
|
|
25
|
+
Object.keys(props).length > 0 &&
|
|
26
|
+
reportOptions.showNestedKeySizeIfGreater != null &&
|
|
27
|
+
propsSizeInBytes > reportOptions.showNestedKeySizeIfGreater) {
|
|
28
|
+
for (const [key, value] of Object.entries(props)) {
|
|
29
|
+
const size = getPropsInfo(value, reportOptions, recursionDepth + 1);
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
result.push('\n', `${key}[${value.length}]`, ...size);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result.push('\n', key, ...size);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result.flat();
|
|
15
39
|
};
|
|
16
40
|
export const logPartialInfo = (partialPath, props) => {
|
|
17
41
|
console.log('Rendering partial', partialPath);
|
|
18
42
|
console.group();
|
|
19
|
-
console.log('Props size: ', ...getPropsInfo(props));
|
|
43
|
+
console.log('Props size: ', ...getPropsInfo(props, { showNestedKeySizeIfGreater: 1000000 }));
|
|
20
44
|
console.groupEnd();
|
|
21
45
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { readdirSync } from 'fs';
|
|
3
|
+
const PARTIAL_SOURCE_DIR = 'components/partials';
|
|
4
|
+
function getAllComponentFilenamesIn(dirPath) {
|
|
5
|
+
return readdirSync(dirPath).filter(filename => {
|
|
6
|
+
const ext = path.extname(filename);
|
|
7
|
+
return ext === '.jsx' || ext === '.tsx';
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
const buildMockPartialModule = entryPointsFileNames => {
|
|
11
|
+
return entryPointsFileNames
|
|
12
|
+
.map(filename => {
|
|
13
|
+
const ext = path.extname(filename);
|
|
14
|
+
const withoutExtension = path.basename(filename, ext);
|
|
15
|
+
return `export const ${withoutExtension} = () => import('/${PARTIAL_SOURCE_DIR}/${filename}');`;
|
|
16
|
+
})
|
|
17
|
+
.join('\n');
|
|
18
|
+
};
|
|
19
|
+
// Not needed in dev unless some code wants to do `import { SomePartial } from 'components/partials'`
|
|
20
|
+
export default function devMockClientEntryPlugin(webRoot) {
|
|
21
|
+
const ENTRY_POINTS_PATH = path.resolve(webRoot, PARTIAL_SOURCE_DIR);
|
|
22
|
+
const MOCK_ENTRY_PATH = `${ENTRY_POINTS_PATH}/index.js`;
|
|
23
|
+
return {
|
|
24
|
+
enforce: 'pre',
|
|
25
|
+
name: 'client-entry',
|
|
26
|
+
options(options) {
|
|
27
|
+
if (!options.input) {
|
|
28
|
+
return {
|
|
29
|
+
...options,
|
|
30
|
+
input: [MOCK_ENTRY_PATH],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return options;
|
|
34
|
+
},
|
|
35
|
+
async resolveId(source, importer, options) {
|
|
36
|
+
if (source === PARTIAL_SOURCE_DIR /*&& options.isEntry*/) {
|
|
37
|
+
return {
|
|
38
|
+
id: source,
|
|
39
|
+
moduleSideEffects: 'no-treeshake',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
},
|
|
44
|
+
load(id) {
|
|
45
|
+
if (id === PARTIAL_SOURCE_DIR) {
|
|
46
|
+
const entryPointsFileNames = getAllComponentFilenamesIn(ENTRY_POINTS_PATH);
|
|
47
|
+
return buildMockPartialModule(entryPointsFileNames);
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/routes/module.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import url from 'url';
|
|
2
3
|
import fullOriginalUrlFromRequest from '../lib/fullOriginalUrlFromRequest.js';
|
|
3
4
|
import renderModule from '../lib/renderModule.js';
|
|
4
5
|
import { createHtmlShellDependingOnRenderContext } from '../lib/templates.js';
|
|
5
6
|
const moduleRouteHandler = async (request, response) => {
|
|
6
7
|
const { webRoot, viteServer } = request.app.locals;
|
|
7
8
|
const moduleName = request.params.moduleName;
|
|
8
|
-
const baseTemplatePath = path.join(import.meta.url
|
|
9
|
+
const baseTemplatePath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../../html/baseTemplate.html');
|
|
9
10
|
const modulePath = path.resolve(webRoot, 'components/modules/', moduleName);
|
|
10
11
|
try {
|
|
11
12
|
const { html: renderedHtml, cssNeeded, renderContext, } = await renderModule(viteServer, modulePath, null, fullOriginalUrlFromRequest(request));
|
package/dist/routes/partial.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import url from 'url';
|
|
2
3
|
import fullOriginalUrlFromRequest from '../lib/fullOriginalUrlFromRequest.js';
|
|
3
4
|
import renderPartial from '../lib/renderPartial.js';
|
|
4
5
|
import { createHtmlShellDependingOnRenderContext } from '../lib/templates.js';
|
|
5
6
|
const partialRouteHandler = async (request, response) => {
|
|
6
7
|
const { webRoot, viteServer } = request.app.locals;
|
|
7
8
|
const partialName = request.params.partial;
|
|
8
|
-
const baseTemplatePath = path.join(import.meta.url
|
|
9
|
+
const baseTemplatePath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../../html/baseTemplate.html');
|
|
9
10
|
const partialPath = path.resolve(webRoot, 'components/partials/', partialName);
|
|
10
11
|
try {
|
|
11
12
|
const { html: renderedHtml, cssNeeded, renderContext, } = await renderPartial(viteServer, partialPath, {}, fullOriginalUrlFromRequest(request));
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "1.1.0-prerelease.
|
|
3
|
+
"version": "1.1.0-prerelease.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/createViteDevServer.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=16.x"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc --build && npm run copy-html",
|
|
9
12
|
"copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
|
|
@@ -18,8 +21,8 @@
|
|
|
18
21
|
},
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"@hubspot/cli-lib": "^3.0.12",
|
|
21
|
-
"@hubspot/cms-components": "^1.1.0-prerelease.
|
|
22
|
-
"@hubspot/cms-js-internal": "^1.1.0-prerelease.
|
|
24
|
+
"@hubspot/cms-components": "^1.1.0-prerelease.8",
|
|
25
|
+
"@hubspot/cms-js-internal": "^1.1.0-prerelease.8",
|
|
23
26
|
"@vitejs/plugin-react": "^2.0.0",
|
|
24
27
|
"ansi-to-html": "0.7.x",
|
|
25
28
|
"express": "^4.17.3",
|
|
@@ -61,5 +64,5 @@
|
|
|
61
64
|
"publishConfig": {
|
|
62
65
|
"access": "public"
|
|
63
66
|
},
|
|
64
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "6f94d6cfa5034605913264f991337056b3ac53fc"
|
|
65
68
|
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const writeIslandDataToJsGlobal = (tweakedIslandsArray, indent = 0) => {
|
|
2
|
-
const indentString = new Array(indent).fill(' ').join('');
|
|
3
|
-
return `window.__islands = ${JSON.stringify(tweakedIslandsArray.map(({ id, moduleName, moduleId, props, hydrateOn, clientOnly, priority, url, }) => {
|
|
4
|
-
return {
|
|
5
|
-
id,
|
|
6
|
-
moduleName,
|
|
7
|
-
moduleId,
|
|
8
|
-
props,
|
|
9
|
-
hydrateOn,
|
|
10
|
-
clientOnly,
|
|
11
|
-
priority,
|
|
12
|
-
url,
|
|
13
|
-
};
|
|
14
|
-
}), null, 2).replace(/\n/gm, `\n${indentString}`)};`;
|
|
15
|
-
};
|
|
16
|
-
function getIslandUrls(roots, viteDevServer) {
|
|
17
|
-
return roots.map(island => {
|
|
18
|
-
const islandModule = viteDevServer.moduleGraph.getModuleById(island.moduleId);
|
|
19
|
-
if (!islandModule) {
|
|
20
|
-
throw new Error(`Unknown island moduleId: ${island.moduleId}`);
|
|
21
|
-
}
|
|
22
|
-
const tweakedIsland = {
|
|
23
|
-
...island,
|
|
24
|
-
url: islandModule.url,
|
|
25
|
-
};
|
|
26
|
-
return tweakedIsland;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export const createIslandsGlobalJsForClientInDev = (roots, viteDevServer, indent) => {
|
|
30
|
-
// Assuming island roots have already been sorted before being passed in here
|
|
31
|
-
return writeIslandDataToJsGlobal(getIslandUrls(roots, viteDevServer), indent);
|
|
32
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const traverseFieldsJSONHelper = (fields, values, handle, path // Number path elements are for repeaters
|
|
2
|
-
) => {
|
|
3
|
-
if (!fields) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
for (const field of fields) {
|
|
7
|
-
let value = values ? values[field.name] : undefined;
|
|
8
|
-
if (value === undefined) {
|
|
9
|
-
value = getDefaultValue(field);
|
|
10
|
-
}
|
|
11
|
-
if (field.occurrence) {
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
value.forEach((v, i) => {
|
|
14
|
-
handle([...path, field.name, i], v, field);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
else if (field.type === 'group') {
|
|
19
|
-
traverseFieldsJSONHelper(field.children, value, handle, [
|
|
20
|
-
...path,
|
|
21
|
-
field.name,
|
|
22
|
-
]);
|
|
23
|
-
}
|
|
24
|
-
else if (value !== undefined) {
|
|
25
|
-
handle([...path, field.name], value, field);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const traverseFieldsJSON = (fields, values, handle) => {
|
|
30
|
-
return traverseFieldsJSONHelper(fields, values, handle, []);
|
|
31
|
-
};
|
|
32
|
-
const getDefaultValue = (field) => {
|
|
33
|
-
if (field.type === 'group') {
|
|
34
|
-
if (field.occurrence) {
|
|
35
|
-
const count = field.occurrence.default || field.occurrence.min;
|
|
36
|
-
return new Array(count).fill(field.default[0]);
|
|
37
|
-
}
|
|
38
|
-
const result = {};
|
|
39
|
-
for (const childField of field.children) {
|
|
40
|
-
if (childField.type !== 'group' && childField.default) {
|
|
41
|
-
result[childField.name] = getDefaultValue(childField);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
else if (field.occurrence) {
|
|
47
|
-
const scalarValue = getDefaultScalarValue(field);
|
|
48
|
-
const count = field.occurrence.default || field.occurrence.min;
|
|
49
|
-
return new Array(count).fill(scalarValue);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return field.default;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
// If occurrence.default is set, then default value could be an array
|
|
56
|
-
// and we just want to grab the scalar value from that array
|
|
57
|
-
function getDefaultScalarValue(field) {
|
|
58
|
-
if (Array.isArray(field.default)) {
|
|
59
|
-
const firstValue = field.default[0];
|
|
60
|
-
// email field values are arrays of strings (email addresses)
|
|
61
|
-
// so check if it's an array of arrays
|
|
62
|
-
if (valueIsArray(field)) {
|
|
63
|
-
return Array.isArray(firstValue) ? firstValue : field.default;
|
|
64
|
-
}
|
|
65
|
-
return firstValue;
|
|
66
|
-
}
|
|
67
|
-
return field.default;
|
|
68
|
-
}
|
|
69
|
-
const CHOICE_FIELD_TYPE = 'choice';
|
|
70
|
-
const EMAIL_FIELD_TYPE = 'email';
|
|
71
|
-
const SIMPLE_MENU_FIELD_TYPE = 'simple_menu';
|
|
72
|
-
// Stolen from https://git.hubteam.com/HubSpot/ContentUILib/blob/ede7354d6265d7976c29bc55b692602885c28c96/ContentUtils/static/js/helpers/FieldHelpers.js#L56
|
|
73
|
-
function valueIsArray(field) {
|
|
74
|
-
return (field.type === EMAIL_FIELD_TYPE ||
|
|
75
|
-
field.type === SIMPLE_MENU_FIELD_TYPE ||
|
|
76
|
-
(field.type === CHOICE_FIELD_TYPE && field.multiple));
|
|
77
|
-
}
|
|
78
|
-
export default traverseFieldsJSON;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { renderStreamToPromise } from '@hubspot/cms-js-internal';
|
|
3
|
-
import { ServerRenderContext, createServerRenderContext, } from '@hubspot/cms-components';
|
|
4
|
-
// Slightly useful to have this so some files don't have to be tsx just to make
|
|
5
|
-
// the renderOnServer call (i.e. need JSX to do `<Component {...props} />`)
|
|
6
|
-
export async function renderComponentOnServer(Component, props, pageUrl) {
|
|
7
|
-
const componentDebugName = Component.displayName || Component.name;
|
|
8
|
-
return renderOnServer(_jsx(Component, { ...props }), pageUrl, componentDebugName);
|
|
9
|
-
}
|
|
10
|
-
export async function renderOnServer(elements, pageUrl, debugName) {
|
|
11
|
-
const renderContext = createServerRenderContext(pageUrl);
|
|
12
|
-
let html = await renderStreamToPromise(_jsx(ServerRenderContext.Provider, { value: renderContext, children: elements }));
|
|
13
|
-
if (renderContext.messagesForBrowser.length > 0) {
|
|
14
|
-
html = `${html}${scriptTagToLogServerMessages(renderContext.messagesForBrowser, `Server messages rendering: ${debugName}`)}`;
|
|
15
|
-
}
|
|
16
|
-
return { html, renderContext };
|
|
17
|
-
}
|
|
18
|
-
function scriptTagToLogServerMessages(messagesForBrowser, groupLabel) {
|
|
19
|
-
if (!messagesForBrowser) {
|
|
20
|
-
return '';
|
|
21
|
-
}
|
|
22
|
-
const consoleLines = [];
|
|
23
|
-
for (const message of messagesForBrowser) {
|
|
24
|
-
const funcString = message.level === 'error' ? 'console.error' : 'console.warn';
|
|
25
|
-
const argString = message.parameters
|
|
26
|
-
.map(arg => JSON.stringify(arg))
|
|
27
|
-
.join(', ');
|
|
28
|
-
consoleLines.push(` ${funcString}(${argString});`);
|
|
29
|
-
}
|
|
30
|
-
let groupStart = '';
|
|
31
|
-
let groupEnd = '';
|
|
32
|
-
if (groupLabel !== null) {
|
|
33
|
-
groupStart = `\n console.group(${JSON.stringify(groupLabel)});`;
|
|
34
|
-
groupEnd = ` console.groupEnd()\n`;
|
|
35
|
-
}
|
|
36
|
-
return `<script>${groupStart}
|
|
37
|
-
${consoleLines.join('\n')}
|
|
38
|
-
${groupEnd}</script>
|
|
39
|
-
`;
|
|
40
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { renderComponentOnServer, renderOnServer } from './renderOnServer.js';
|
|
4
|
-
import { getByText } from '@testing-library/dom';
|
|
5
|
-
import { JSDOM } from 'jsdom';
|
|
6
|
-
function TestComponent({ text }) {
|
|
7
|
-
return _jsx("div", { children: text });
|
|
8
|
-
}
|
|
9
|
-
describe('renderOnServer', () => {
|
|
10
|
-
it('should render elements', async () => {
|
|
11
|
-
const result = await renderOnServer(_jsx(TestComponent, { text: 'test' }), 'http://test.com', 'debug_name');
|
|
12
|
-
const dom = new JSDOM(result.html);
|
|
13
|
-
expect(getByText(dom.window.document.body, 'test')).toBeTruthy();
|
|
14
|
-
expect(result.renderContext.pageUrl).toBe('http://test.com');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe('renderComponentOnServer', () => {
|
|
18
|
-
it('should render components', async () => {
|
|
19
|
-
const result = await renderComponentOnServer(TestComponent, { text: 'test' }, 'http://test.com');
|
|
20
|
-
const dom = new JSDOM(result.html);
|
|
21
|
-
expect(getByText(dom.window.document.body, 'test')).toBeTruthy();
|
|
22
|
-
expect(result.renderContext.pageUrl).toBe('http://test.com');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import stream from 'stream';
|
|
2
|
-
import { renderToPipeableStream } from 'react-dom/server';
|
|
3
|
-
const promiseForNewWritableStream = () => {
|
|
4
|
-
const chunks = [];
|
|
5
|
-
const writableStream = new stream.Writable();
|
|
6
|
-
writableStream._write = (chunk, encoding, done) => {
|
|
7
|
-
chunks.push(Buffer.from(chunk));
|
|
8
|
-
done();
|
|
9
|
-
};
|
|
10
|
-
const streamDonePromise = new Promise((resolve, reject) => {
|
|
11
|
-
writableStream.on('error', error => {
|
|
12
|
-
reject(error);
|
|
13
|
-
});
|
|
14
|
-
writableStream._final = done => {
|
|
15
|
-
resolve(Buffer.concat(chunks).toString('utf8'));
|
|
16
|
-
done();
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
return { streamDonePromise, writableStream };
|
|
20
|
-
};
|
|
21
|
-
export const renderStreamToPromise = async (reactElements) => {
|
|
22
|
-
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
23
|
-
const { pipe /* abort */ } = renderToPipeableStream(reactElements, {
|
|
24
|
-
onShellReady() {
|
|
25
|
-
// customOutputStream.write('<!-- After onCompleteShell -->\n');
|
|
26
|
-
},
|
|
27
|
-
onAllReady() {
|
|
28
|
-
pipe(writableStream);
|
|
29
|
-
},
|
|
30
|
-
// We will log the error sent to the writable, any need to do something in these callbacks?
|
|
31
|
-
// onShellError(error) {},
|
|
32
|
-
// onError(error) {},
|
|
33
|
-
});
|
|
34
|
-
return streamDonePromise;
|
|
35
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import enhancedResolve from 'enhanced-resolve';
|
|
2
|
-
import { cwd } from 'process';
|
|
3
|
-
/**
|
|
4
|
-
* Vite plugin that resolves dependencies to cms-js-platform over webRoot
|
|
5
|
-
* client build: resolve deps to cms-js-platform version
|
|
6
|
-
* server build: mark deps as external
|
|
7
|
-
*/
|
|
8
|
-
export default function resolveSharedDeps(absoluteWebRoot) {
|
|
9
|
-
console.log(absoluteWebRoot);
|
|
10
|
-
const sharedDeps = [
|
|
11
|
-
'@hubspot/cms-components',
|
|
12
|
-
'@hubspot/cms-js-internal',
|
|
13
|
-
'react',
|
|
14
|
-
'react-dom',
|
|
15
|
-
];
|
|
16
|
-
return {
|
|
17
|
-
name: 'resolve-shared-deps',
|
|
18
|
-
enforce: 'pre',
|
|
19
|
-
async resolveId(source, __importer, __options) {
|
|
20
|
-
if (sharedDeps.some(sharedDep => source.startsWith(sharedDep))) {
|
|
21
|
-
const resolvedSource = enhancedResolve.sync(cwd(), source);
|
|
22
|
-
console.log(`RESOLVING::: ${source} TO ${resolvedSource}`);
|
|
23
|
-
return { id: resolvedSource, external: 'relative' };
|
|
24
|
-
}
|
|
25
|
-
return Promise.resolve(null);
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|