@hubspot/cms-dev-server 1.1.0-prerelease.3 → 1.1.0-prerelease.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.
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.1.0-prerelease.3",
3
+ "version": "1.1.0-prerelease.4",
4
4
  "type": "module",
5
5
  "main": "./dist/createViteDevServer.js",
6
6
  "scripts": {
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@hubspot/cli-lib": "^3.0.12",
20
- "@hubspot/cms-components": "^1.1.0-prerelease.3",
21
- "@hubspot/cms-js-internal": "^1.1.0-prerelease.3",
20
+ "@hubspot/cms-components": "^1.1.0-prerelease.4",
21
+ "@hubspot/cms-js-internal": "^1.1.0-prerelease.4",
22
22
  "@vitejs/plugin-react": "^2.0.0",
23
23
  "ansi-to-html": "0.7.x",
24
24
  "express": "^4.17.3",
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "6c93a3a29a460376f47eb6e9c87a06dbc25194d6"
64
+ "gitHead": "48f05583415f59bcfd6e191a0031660fd4f316c0"
65
65
  }
@@ -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
- }