@hubspot/cms-dev-server 0.4.3 → 0.4.4
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/index.js +35 -5
- package/dist/internalSsr.js +47 -3
- package/dist/run.js +113 -35
- package/package.json +3 -3
- package/types/createViteDevServer.d.ts +1 -1
- package/dist/components/ModulesList.js +0 -14
- package/dist/components/PartialsList.js +0 -13
- package/dist/createDevServer.js +0 -164
- package/dist/createDevServerConfiguration.js +0 -155
- package/dist/createViteDevServer.js +0 -52
- package/dist/lib/cli.js +0 -27
- package/dist/lib/debug.js +0 -2
- package/dist/lib/errors.js +0 -22
- package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
- package/dist/lib/getDevServerConfiguration.js +0 -63
- package/dist/lib/httpsRedirectingServer.js +0 -48
- package/dist/lib/moduleGraph.js +0 -11
- package/dist/lib/proxyHelpers.js +0 -70
- package/dist/lib/proxyHelpers.test.js +0 -136
- package/dist/lib/renderComponentWithCSS.js +0 -26
- package/dist/lib/renderHelpers.js +0 -45
- package/dist/lib/renderModule.js +0 -56
- package/dist/lib/renderPartial.js +0 -15
- package/dist/lib/templates.js +0 -66
- package/dist/proxyPage/constants.js +0 -1
- package/dist/proxyPage/fetchContentMetadata.js +0 -59
- package/dist/proxyPage/fetchDomains.js +0 -29
- package/dist/proxyPage/fetchPreviewInfo.js +0 -37
- package/dist/proxyPage/proxyPage.js +0 -174
- package/dist/proxyPage/renderLocalError.js +0 -27
- package/dist/proxyPage/utils.js +0 -38
- package/dist/routes/createDevServerRoutes.js +0 -43
- package/dist/routes/homeRouteHandler.js +0 -12
- package/dist/routes/linksToAllModulesRouteHandler.js +0 -10
- package/dist/routes/linksToAllPartialsRouteHandler.js +0 -10
- package/dist/routes/module.js +0 -41
- package/dist/routes/partial.js +0 -30
- package/dist/routes/proxyPageResourceRedirect.js +0 -22
- package/dist/routes/proxyPageRouteHandler.js +0 -40
- package/dist/routes/proxyPathPageResourceRedirect.js +0 -36
- package/dist/routes/proxyPathPageRouteHandler.js +0 -43
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +0 -63
- package/dist/shadowDevServer/startShadowDevServer.js +0 -31
- package/dist/storybook/getFieldsArgTypes.js +0 -54
- package/dist/storybook/getFieldsArgTypes.test.js +0 -91
- package/dist/storybook/getNestedFieldObjectForArgs.js +0 -22
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +0 -40
- package/dist/storybook/main.js +0 -31
- package/dist/storybook/moduleStory.js +0 -61
- package/dist/storybook/preview.js +0 -9
- package/dist/storybook/types.js +0 -1
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
3
|
-
describe('getNestedFieldObjectForArgs', () => {
|
|
4
|
-
it('leaves top level args as is', () => {
|
|
5
|
-
const argMap = {
|
|
6
|
-
testField: 'testValue',
|
|
7
|
-
testField2: 'testValue',
|
|
8
|
-
};
|
|
9
|
-
const result = getNestedFieldObjectForArgs(argMap);
|
|
10
|
-
expect(result).toStrictEqual(argMap);
|
|
11
|
-
});
|
|
12
|
-
it('turns a . separated arg name into a nested field', () => {
|
|
13
|
-
const argMap = {
|
|
14
|
-
'group.testField': 'testValue',
|
|
15
|
-
topLevelField: 'testValue',
|
|
16
|
-
};
|
|
17
|
-
const result = getNestedFieldObjectForArgs(argMap);
|
|
18
|
-
expect(result).toStrictEqual({
|
|
19
|
-
group: {
|
|
20
|
-
testField: 'testValue',
|
|
21
|
-
},
|
|
22
|
-
topLevelField: 'testValue',
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
it('keeps nested fields with the same group prefix nested in the same object', () => {
|
|
26
|
-
const argMap = {
|
|
27
|
-
'group.testField': 'testValue',
|
|
28
|
-
'group.secondField': 'testValue',
|
|
29
|
-
topLevelField: 'testValue',
|
|
30
|
-
};
|
|
31
|
-
const result = getNestedFieldObjectForArgs(argMap);
|
|
32
|
-
expect(result).toStrictEqual({
|
|
33
|
-
group: {
|
|
34
|
-
testField: 'testValue',
|
|
35
|
-
secondField: 'testValue',
|
|
36
|
-
},
|
|
37
|
-
topLevelField: 'testValue',
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
package/dist/storybook/main.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { mergeConfig } from 'vite';
|
|
3
|
-
const webRoot = process.env.WEB_ROOT;
|
|
4
|
-
const storyPath = path.resolve(process.cwd(), webRoot, '**/*.stories.*');
|
|
5
|
-
const sharedDepsEnabled = Boolean(process.env.SHARED_DEPS_ENABLED);
|
|
6
|
-
export default {
|
|
7
|
-
addons: ['@storybook/addon-essentials'],
|
|
8
|
-
framework: '@storybook/react-vite',
|
|
9
|
-
stories: [storyPath],
|
|
10
|
-
viteFinal: async (config) => {
|
|
11
|
-
const { resolveIslandPlugin } = await import('@hubspot/cms-js-internal');
|
|
12
|
-
const viteConfig = {
|
|
13
|
-
resolve: {
|
|
14
|
-
dedupe: [
|
|
15
|
-
'react',
|
|
16
|
-
'react-dom',
|
|
17
|
-
'@hubspot/cms-components',
|
|
18
|
-
'@hubspot/cms-dev-server',
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
optimizeDeps: {
|
|
22
|
-
include: ['react', 'react-dom', 'react-dom/client'],
|
|
23
|
-
},
|
|
24
|
-
css: {
|
|
25
|
-
postcss: webRoot,
|
|
26
|
-
},
|
|
27
|
-
plugins: [resolveIslandPlugin({ sharedDepsEnabled })],
|
|
28
|
-
};
|
|
29
|
-
return mergeConfig(config, viteConfig);
|
|
30
|
-
},
|
|
31
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
3
|
-
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
|
-
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
5
|
-
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
6
|
-
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
7
|
-
export function moduleFieldsToJson(fields) {
|
|
8
|
-
let moduleJson;
|
|
9
|
-
const outputCallback = (callbackJson) => {
|
|
10
|
-
moduleJson = callbackJson;
|
|
11
|
-
};
|
|
12
|
-
renderToStaticMarkup(React.cloneElement(fields, {
|
|
13
|
-
outputCallback,
|
|
14
|
-
}));
|
|
15
|
-
if (!moduleJson) {
|
|
16
|
-
throw new Error("couldn't render module fields definition to fields.json");
|
|
17
|
-
}
|
|
18
|
-
return moduleJson;
|
|
19
|
-
}
|
|
20
|
-
export function moduleStory(ModuleComponent, fields) {
|
|
21
|
-
const moduleJson = renderFieldsToJson(fields);
|
|
22
|
-
const argTypes = getFieldsArgTypes(moduleJson);
|
|
23
|
-
const story = (_args) => _jsx(ModuleComponent, { ..._args });
|
|
24
|
-
const storyWithArgs = story.bind({});
|
|
25
|
-
storyWithArgs.argTypes = argTypes;
|
|
26
|
-
storyWithArgs.args = {};
|
|
27
|
-
return storyWithArgs;
|
|
28
|
-
}
|
|
29
|
-
export function moduleStoryWithIsland(moduleName, fields) {
|
|
30
|
-
const moduleJson = moduleFieldsToJson(fields);
|
|
31
|
-
const argTypes = getFieldsArgTypes(moduleJson);
|
|
32
|
-
const story = (_args) => {
|
|
33
|
-
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
34
|
-
const fieldValuesString = JSON.stringify(fieldValues);
|
|
35
|
-
const domain = `${window.location.protocol}//${window.location.hostname.replace('storybook.', '')}:3000`;
|
|
36
|
-
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
37
|
-
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
const existingElement = document.querySelector('#hs-module-iframe');
|
|
40
|
-
if (existingElement) {
|
|
41
|
-
existingElement.setAttribute('src', iframeSrc);
|
|
42
|
-
return () => {
|
|
43
|
-
existingElement.remove();
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const iframeElement = document.createElement('iframe');
|
|
47
|
-
iframeElement.setAttribute('src', iframeSrc);
|
|
48
|
-
iframeElement.setAttribute('id', 'hs-module-iframe');
|
|
49
|
-
iframeElement.setAttribute('style', `border: none;width: 100%;height: 100%;overflow: auto;`);
|
|
50
|
-
document.body.appendChild(iframeElement);
|
|
51
|
-
return () => {
|
|
52
|
-
iframeElement.remove();
|
|
53
|
-
};
|
|
54
|
-
}, [iframeSrc]);
|
|
55
|
-
return _jsx("div", {});
|
|
56
|
-
};
|
|
57
|
-
const storyWithArgs = story.bind({});
|
|
58
|
-
storyWithArgs.argTypes = argTypes;
|
|
59
|
-
storyWithArgs.args = {};
|
|
60
|
-
return storyWithArgs;
|
|
61
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { ServerRenderContext, createServerRenderContext, ClientRenderContextProvider, } from '@hubspot/cms-components';
|
|
3
|
-
export const parameters = {
|
|
4
|
-
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
5
|
-
};
|
|
6
|
-
const contextValue = createServerRenderContext('http://testUrl.com');
|
|
7
|
-
export const decorators = [
|
|
8
|
-
Story => (_jsx(ClientRenderContextProvider, { pageUrl: "http://test.com", islands: [], children: _jsx(ServerRenderContext.Provider, { value: contextValue, children: _jsx(Story, {}) }) })),
|
|
9
|
-
];
|
package/dist/storybook/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|