@woodsportal/hubspot-kit 1.0.35 → 1.0.36

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woodsportal/hubspot-kit",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "description": "WoodsCLI — HubSpot CMS dev kit by WoodsPortal. wp CLI, Vite presets, module-config overlay, and theme/module build pipelines.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,7 +51,7 @@
51
51
  "build": "tsup",
52
52
  "dev": "tsup --watch",
53
53
  "typecheck": "tsc --noEmit",
54
- "test": "node --import tsx --test 'src/lib/**/*.test.ts' 'src/schema/**/*.test.ts' 'src/vite/**/*.test.ts' 'scripts/portal-build-id.test.mjs' 'scripts/vite/ensure-dev-kit-shims.test.mjs' && vitest run src/dev-module-config/__tests__/normalize-repeater-items.test.ts src/dev-module-config/__tests__/module-config-transform.test.ts src/dev-module-config/__tests__/flatten-visible-fields.test.ts",
54
+ "test": "node --import tsx --test 'src/lib/**/*.test.ts' 'src/schema/**/*.test.ts' 'src/vite/**/*.test.ts' 'scripts/portal-build-id.test.mjs' 'scripts/vite/ensure-dev-kit-shims.test.mjs' 'scripts/vite/consumer-react-aliases.test.mjs' && vitest run src/dev-module-config/__tests__/normalize-repeater-items.test.ts src/dev-module-config/__tests__/module-config-transform.test.ts src/dev-module-config/__tests__/flatten-visible-fields.test.ts",
55
55
  "test:examples": "node examples/smoke/run-matrix.mjs --tier static",
56
56
  "lint": "eslint src",
57
57
  "verify": "npm run typecheck && npm run test && npm run test:examples && npm run build",
@@ -1,107 +1,29 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Local dev server — loads Vite and plugins from the consumer project's node_modules
4
- * (configFile: false) so the kit does not need its own vite install.
3
+ * Local dev server — programmatic Vite (configFile: false) avoids fragile
4
+ * vite.config.* loading on some Node versions and keeps one config source.
5
5
  */
6
- import { existsSync } from 'node:fs'
7
- import { resolve } from 'node:path'
8
-
9
- import { importConsumerDep } from './resolve-consumer-dep.mjs'
10
6
  import { findProjectRoot, getKitRoot } from './project-root.mjs'
7
+ import { importConsumerDep } from './resolve-consumer-dep.mjs'
8
+ import { createDevServerViteConfig } from './vite/create-dev-server-config.mjs'
11
9
 
12
10
  const projectRoot = findProjectRoot()
13
11
  const kitRoot = getKitRoot()
14
12
  const port = Number(process.env.WP_HS_DEV_PORT ?? process.argv[2] ?? 3000)
15
13
 
16
- const [
17
- { ensureDevKitShims },
18
- { default: resolveFromProjectRoot },
19
- { default: sdkLogBridge },
20
- { default: moduleConfigStore },
21
- { createDevReactPluginOptions },
22
- { default: isPrefix },
23
- { default: bootstrapShimResolver },
24
- { readWoodsportalConfig },
25
- { createServer },
26
- viteReactMod,
27
- tanstackMod,
28
- tailwindcssMod,
29
- ] = await Promise.all([
30
- import('./vite/ensure-dev-kit-shims.js'),
31
- import('./vite/resolve-from-project-root.js'),
32
- import('./vite/sdk-log-bridge.js'),
33
- import('./vite/module-config-store.js'),
34
- import('./vite/react-dev-plugin-options.js'),
35
- import('./tailwind/prefix.env.js'),
36
- import('./vite/bootstrap-shim-resolver.js'),
37
- import('./read-woodsportal-config.mjs'),
38
- importConsumerDep('vite'),
39
- importConsumerDep('@vitejs/plugin-react'),
40
- importConsumerDep('@tanstack/router-plugin/vite'),
41
- importConsumerDep('@tailwindcss/vite'),
42
- ])
43
-
44
- const viteReact = viteReactMod.default ?? viteReactMod
45
- const { TanStackRouterVite } = tanstackMod
46
- const tailwindcss = tailwindcssMod.default ?? tailwindcssMod
47
-
48
- const { moduleConfigRoot, bootstrapShim, bootstrapGreenfieldShim } = ensureDevKitShims(
49
- projectRoot,
50
- kitRoot,
51
- )
52
- const { config } = readWoodsportalConfig(projectRoot)
53
- const routesDir = resolve(projectRoot, 'src/routes')
54
- const hasTanStackRoutes = existsSync(routesDir)
14
+ process.env.WP_HS_PROJECT_ROOT = projectRoot
55
15
 
56
- const prefixPlugins = isPrefix('dev')
57
- ? [
58
- (await import('./tailwind/prefix-plugin.js')).default(),
59
- (await import('./tailwind/tailwind-content-plugin.js')).default(),
60
- ]
61
- : []
16
+ const userConfig = await createDevServerViteConfig({ projectRoot, kitRoot, port })
17
+ const resolved =
18
+ typeof userConfig === 'function'
19
+ ? await userConfig({ mode: 'dev', command: 'serve' })
20
+ : await userConfig
62
21
 
22
+ const { createServer } = await importConsumerDep('vite')
63
23
  const server = await createServer({
64
- root: projectRoot,
24
+ ...resolved,
65
25
  configFile: false,
66
26
  mode: 'dev',
67
- plugins: [
68
- bootstrapShimResolver({ bootstrapShim, bootstrapGreenfieldShim, kitRoot }),
69
- resolveFromProjectRoot(projectRoot, kitRoot),
70
- sdkLogBridge(),
71
- moduleConfigStore(projectRoot),
72
- ...(hasTanStackRoutes ? [TanStackRouterVite({ autoCodeSplitting: false })] : []),
73
- viteReact(createDevReactPluginOptions()),
74
- tailwindcss(),
75
- ...prefixPlugins,
76
- ],
77
- resolve: {
78
- preserveSymlinks: true,
79
- dedupe: ['react', 'react-dom'],
80
- alias: {
81
- '@/dev/module-config': moduleConfigRoot,
82
- '@wphs/bootstrap': bootstrapShim,
83
- '@wphs/bootstrap-greenfield': bootstrapGreenfieldShim,
84
- '@woodsportal/hubspot-kit/dev/bootstrap': bootstrapShim,
85
- '@woodsportal/hubspot-kit/dev/bootstrap-greenfield': bootstrapGreenfieldShim,
86
- '@wphs/adapter': resolve(projectRoot, config?.dev?.adapter ?? './wphs.adapter.ts'),
87
- '@': resolve(projectRoot, './src'),
88
- },
89
- },
90
- optimizeDeps: {
91
- include: ['react', 'react-dom', 'react/jsx-dev-runtime', 'react/jsx-runtime'],
92
- exclude: ['woodsportal-client-sdk', 'woodsportal-client-sdk/auth', 'woodsportal-client-sdk/crm'],
93
- },
94
- define: {
95
- 'process.env.NODE_ENV': JSON.stringify('development'),
96
- 'process.env': {},
97
- process: JSON.stringify({ env: {} }),
98
- },
99
- server: {
100
- port,
101
- fs: {
102
- allow: [projectRoot, kitRoot],
103
- },
104
- },
105
27
  })
106
28
 
107
29
  await server.listen()
@@ -0,0 +1,31 @@
1
+ import { createRequire } from 'node:module'
2
+ import { resolve } from 'node:path'
3
+ import { pathToFileURL } from 'node:url'
4
+
5
+ /** Subpath runtimes only — do not alias top-level `react` / `react-dom` (breaks `react/jsx-runtime`). */
6
+ const REACT_RUNTIME_SPECS = [
7
+ 'react/jsx-runtime',
8
+ 'react/jsx-dev-runtime',
9
+ 'react-dom/client',
10
+ 'react/compiler-runtime',
11
+ ]
12
+
13
+ /**
14
+ * Pin React runtimes to the consumer's node_modules so kit UI under `.wphs/` or
15
+ * `node_modules/@woodsportal/hubspot-kit` never loads a mismatched CJS copy in the browser.
16
+ */
17
+ export function consumerReactAliases(projectRoot) {
18
+ const require = createRequire(pathToFileURL(resolve(projectRoot, 'package.json')))
19
+ /** @type {Record<string, string>} */
20
+ const alias = {}
21
+
22
+ for (const spec of REACT_RUNTIME_SPECS) {
23
+ try {
24
+ alias[spec] = require.resolve(spec)
25
+ } catch {
26
+ // consumer may omit optional subpaths until install completes
27
+ }
28
+ }
29
+
30
+ return alias
31
+ }
@@ -0,0 +1,32 @@
1
+ import assert from 'node:assert/strict'
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join, resolve } from 'node:path'
5
+ import { describe, it } from 'node:test'
6
+
7
+ import { consumerReactAliases } from './consumer-react-aliases.js'
8
+
9
+ describe('consumerReactAliases', () => {
10
+ it('resolves react jsx runtimes from the consumer project root', () => {
11
+ const root = mkdtempSync(join(tmpdir(), 'wp-react-alias-'))
12
+ try {
13
+ mkdirSync(join(root, 'node_modules', 'react'), { recursive: true })
14
+ writeFileSync(
15
+ join(root, 'node_modules', 'react', 'package.json'),
16
+ JSON.stringify({
17
+ name: 'react',
18
+ exports: {
19
+ './jsx-dev-runtime': './jsx-dev-runtime.js',
20
+ },
21
+ }),
22
+ )
23
+ writeFileSync(join(root, 'node_modules', 'react', 'jsx-dev-runtime.js'), 'export {}')
24
+ writeFileSync(join(root, 'package.json'), JSON.stringify({ name: 'fixture', type: 'module' }))
25
+
26
+ const alias = consumerReactAliases(root)
27
+ assert.match(alias['react/jsx-dev-runtime'], /node_modules[/\\]react[/\\]jsx-dev-runtime\.js$/)
28
+ } finally {
29
+ rmSync(root, { recursive: true, force: true })
30
+ }
31
+ })
32
+ })
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Shared Vite dev-server config for `vite.config.dev.mjs` and `scripts/run-dev.mjs`.
3
+ */
4
+ import { existsSync } from 'node:fs'
5
+ import { resolve } from 'node:path'
6
+
7
+ import { importConsumerDep } from '../resolve-consumer-dep.mjs'
8
+ import { findProjectRoot, getKitRoot } from '../project-root.mjs'
9
+ import { readWoodsportalConfig } from '../read-woodsportal-config.mjs'
10
+ import { consumerReactAliases } from './consumer-react-aliases.js'
11
+
12
+ export async function createDevServerViteConfig(options = {}) {
13
+ const port = options.port ?? Number(process.env.WP_HS_DEV_PORT ?? 3000)
14
+ const projectRoot = options.projectRoot ?? findProjectRoot()
15
+ const kitRoot = options.kitRoot ?? getKitRoot()
16
+
17
+ const [
18
+ { ensureDevKitShims },
19
+ { default: bootstrapShimResolver },
20
+ { default: resolveFromProjectRoot },
21
+ { default: sdkLogBridge },
22
+ { default: moduleConfigStore },
23
+ { createDevReactPluginOptions },
24
+ { default: isPrefix },
25
+ ] = await Promise.all([
26
+ import('./ensure-dev-kit-shims.js'),
27
+ import('./bootstrap-shim-resolver.js'),
28
+ import('./resolve-from-project-root.js'),
29
+ import('./sdk-log-bridge.js'),
30
+ import('./module-config-store.js'),
31
+ import('./react-dev-plugin-options.js'),
32
+ import('../tailwind/prefix.env.js'),
33
+ ])
34
+
35
+ const { moduleConfigRoot, bootstrapShim, bootstrapGreenfieldShim } = ensureDevKitShims(
36
+ projectRoot,
37
+ kitRoot,
38
+ )
39
+ const { config } = readWoodsportalConfig(projectRoot)
40
+ const routesDir = resolve(projectRoot, 'src/routes')
41
+ const hasTanStackRoutes = existsSync(routesDir)
42
+
43
+ const { defineConfig } = await importConsumerDep('vite')
44
+ const [{ default: viteReact }, { TanStackRouterVite }, { default: tailwindcss }] = await Promise.all([
45
+ importConsumerDep('@vitejs/plugin-react'),
46
+ importConsumerDep('@tanstack/router-plugin/vite'),
47
+ importConsumerDep('@tailwindcss/vite'),
48
+ ])
49
+
50
+ return defineConfig(async ({ mode, command }) => {
51
+ const prefixPlugins = isPrefix(mode)
52
+ ? [
53
+ (await import('../tailwind/prefix-plugin.js')).default(),
54
+ (await import('../tailwind/tailwind-content-plugin.js')).default(),
55
+ ]
56
+ : []
57
+
58
+ return {
59
+ root: projectRoot,
60
+ plugins: [
61
+ bootstrapShimResolver({ bootstrapShim, bootstrapGreenfieldShim, kitRoot }),
62
+ resolveFromProjectRoot(projectRoot, kitRoot),
63
+ ...(command === 'serve' && mode === 'dev'
64
+ ? [sdkLogBridge(), moduleConfigStore(projectRoot)]
65
+ : []),
66
+ ...(hasTanStackRoutes ? [TanStackRouterVite({ autoCodeSplitting: false })] : []),
67
+ viteReact(createDevReactPluginOptions()),
68
+ tailwindcss(),
69
+ ...prefixPlugins,
70
+ ],
71
+ resolve: {
72
+ dedupe: ['react', 'react-dom'],
73
+ alias: {
74
+ ...consumerReactAliases(projectRoot),
75
+ '@/dev/module-config': moduleConfigRoot,
76
+ '@wphs/bootstrap': bootstrapShim,
77
+ '@wphs/bootstrap-greenfield': bootstrapGreenfieldShim,
78
+ '@woodsportal/hubspot-kit/dev/bootstrap': bootstrapShim,
79
+ '@woodsportal/hubspot-kit/dev/bootstrap-greenfield': bootstrapGreenfieldShim,
80
+ '@wphs/adapter': resolve(projectRoot, config?.dev?.adapter ?? './wphs.adapter.ts'),
81
+ '@': resolve(projectRoot, './src'),
82
+ },
83
+ },
84
+ optimizeDeps: {
85
+ include: [
86
+ 'react',
87
+ 'react-dom',
88
+ 'react/jsx-dev-runtime',
89
+ 'react/jsx-runtime',
90
+ 'react-dom/client',
91
+ ],
92
+ exclude: [
93
+ 'woodsportal-client-sdk',
94
+ 'woodsportal-client-sdk/auth',
95
+ 'woodsportal-client-sdk/crm',
96
+ ],
97
+ },
98
+ define: {
99
+ 'import.meta.env.VITE_WPHS_MODULE_NAME': JSON.stringify(
100
+ config?.module?.name ?? config?.theme?.name ?? 'module',
101
+ ),
102
+ 'process.env.NODE_ENV': JSON.stringify(mode === 'dev' ? 'development' : 'production'),
103
+ 'process.env': {},
104
+ process: JSON.stringify({ env: {} }),
105
+ },
106
+ server: {
107
+ port,
108
+ fs: {
109
+ allow: [projectRoot, kitRoot],
110
+ },
111
+ },
112
+ }
113
+ })
114
+ }
@@ -1,14 +1,24 @@
1
1
  import { createRequire } from 'node:module'
2
- import { resolve } from 'node:path'
2
+ import { resolve, sep } from 'node:path'
3
3
  import { pathToFileURL } from 'node:url'
4
4
 
5
5
  /**
6
- * When Vite transforms files under @woodsportal/hubspot-kit, bare imports must
7
- * resolve from the consumer project's node_modules (not the kit package root).
6
+ * When Vite transforms kit dev UI (`.wphs/`, package src, or dev-module-config),
7
+ * bare imports must resolve from the consumer project's node_modules.
8
8
  */
9
9
  export default function resolveFromProjectRoot(projectRoot, kitRoot) {
10
10
  const require = createRequire(pathToFileURL(resolve(projectRoot, 'package.json')))
11
11
  const kitRootNorm = resolve(kitRoot)
12
+ const wphsNorm = resolve(projectRoot, '.wphs')
13
+
14
+ function isKitUiImporter(importer) {
15
+ const norm = resolve(importer)
16
+ if (norm.startsWith(kitRootNorm)) return true
17
+ if (norm.includes(`${sep}.wphs${sep}`) || norm.includes(`${sep}.wphs`)) return true
18
+ if (norm.includes(`${sep}dev-module-config${sep}`)) return true
19
+ if (norm.includes(`${sep}.kit-module-config${sep}`)) return true
20
+ return false
21
+ }
12
22
 
13
23
  return {
14
24
  name: 'wp-resolve-from-project-root',
@@ -18,7 +28,7 @@ export default function resolveFromProjectRoot(projectRoot, kitRoot) {
18
28
  if (source.startsWith('.') || source.startsWith('/') || source.startsWith('\0')) {
19
29
  return null
20
30
  }
21
- if (!resolve(importer).startsWith(kitRootNorm)) {
31
+ if (!isKitUiImporter(importer)) {
22
32
  return null
23
33
  }
24
34
  try {
@@ -1,107 +1,3 @@
1
- import { importConsumerDep } from '../scripts/resolve-consumer-dep.mjs'
1
+ import { createDevServerViteConfig } from '../scripts/vite/create-dev-server-config.mjs'
2
2
 
3
- export default loadDevViteConfig()
4
-
5
- async function loadDevViteConfig() {
6
- const [
7
- { findProjectRoot, getKitRoot },
8
- { readWoodsportalConfig },
9
- { ensureDevKitShims },
10
- { default: bootstrapShimResolver },
11
- { default: resolveFromProjectRoot },
12
- { default: sdkLogBridge },
13
- { default: moduleConfigStore },
14
- { createDevReactPluginOptions },
15
- { default: isPrefix },
16
- ] = await Promise.all([
17
- import('../scripts/project-root.mjs'),
18
- import('../scripts/read-woodsportal-config.mjs'),
19
- import('../scripts/vite/ensure-dev-kit-shims.js'),
20
- import('../scripts/vite/bootstrap-shim-resolver.js'),
21
- import('../scripts/vite/resolve-from-project-root.js'),
22
- import('../scripts/vite/sdk-log-bridge.js'),
23
- import('../scripts/vite/module-config-store.js'),
24
- import('../scripts/vite/react-dev-plugin-options.js'),
25
- import('../scripts/tailwind/prefix.env.js'),
26
- ])
27
-
28
- const { existsSync } = await import('node:fs')
29
- const { resolve } = await import('node:path')
30
-
31
- const kitRoot = getKitRoot()
32
- const projectRoot = findProjectRoot()
33
- const { moduleConfigRoot, bootstrapShim, bootstrapGreenfieldShim } = ensureDevKitShims(
34
- projectRoot,
35
- kitRoot,
36
- )
37
- const { config } = readWoodsportalConfig(projectRoot)
38
- const routesDir = resolve(projectRoot, 'src/routes')
39
- const hasTanStackRoutes = existsSync(routesDir)
40
-
41
- // Load vite before plugins: parallel import of vite + @vitejs/plugin-react breaks on Node 20+ (CJS/ESM interop).
42
- const { defineConfig } = await importConsumerDep('vite')
43
- const [{ default: viteReact }, { TanStackRouterVite }, { default: tailwindcss }] = await Promise.all([
44
- importConsumerDep('@vitejs/plugin-react'),
45
- importConsumerDep('@tanstack/router-plugin/vite'),
46
- importConsumerDep('@tailwindcss/vite'),
47
- ])
48
-
49
- return defineConfig(async ({ mode, command }) => {
50
- const prefixPlugins = isPrefix(mode)
51
- ? [
52
- (await import('../scripts/tailwind/prefix-plugin.js')).default(),
53
- (await import('../scripts/tailwind/tailwind-content-plugin.js')).default(),
54
- ]
55
- : []
56
-
57
- return {
58
- root: projectRoot,
59
- plugins: [
60
- bootstrapShimResolver({ bootstrapShim, bootstrapGreenfieldShim, kitRoot }),
61
- resolveFromProjectRoot(projectRoot, kitRoot),
62
- ...(command === 'serve' && mode === 'dev'
63
- ? [sdkLogBridge(), moduleConfigStore(projectRoot)]
64
- : []),
65
- ...(hasTanStackRoutes ? [TanStackRouterVite({ autoCodeSplitting: false })] : []),
66
- viteReact(createDevReactPluginOptions()),
67
- tailwindcss(),
68
- ...prefixPlugins,
69
- ],
70
- resolve: {
71
- preserveSymlinks: true,
72
- dedupe: ['react', 'react-dom'],
73
- alias: {
74
- '@/dev/module-config': moduleConfigRoot,
75
- '@wphs/bootstrap': bootstrapShim,
76
- '@wphs/bootstrap-greenfield': bootstrapGreenfieldShim,
77
- '@woodsportal/hubspot-kit/dev/bootstrap': bootstrapShim,
78
- '@woodsportal/hubspot-kit/dev/bootstrap-greenfield': bootstrapGreenfieldShim,
79
- '@wphs/adapter': resolve(projectRoot, config?.dev?.adapter ?? './wphs.adapter.ts'),
80
- '@': resolve(projectRoot, './src'),
81
- },
82
- },
83
- optimizeDeps: {
84
- include: ['react', 'react-dom', 'react/jsx-dev-runtime', 'react/jsx-runtime'],
85
- exclude: [
86
- 'woodsportal-client-sdk',
87
- 'woodsportal-client-sdk/auth',
88
- 'woodsportal-client-sdk/crm',
89
- ],
90
- },
91
- define: {
92
- 'import.meta.env.VITE_WPHS_MODULE_NAME': JSON.stringify(
93
- config?.module?.name ?? config?.theme?.name ?? 'module',
94
- ),
95
- 'process.env.NODE_ENV': JSON.stringify(mode === 'dev' ? 'development' : 'production'),
96
- 'process.env': {},
97
- process: JSON.stringify({ env: {} }),
98
- },
99
- server: {
100
- port: 3000,
101
- fs: {
102
- allow: [projectRoot, kitRoot],
103
- },
104
- },
105
- }
106
- })
107
- }
3
+ export default createDevServerViteConfig()