@woodsportal/hubspot-kit 1.0.41-dev.2 → 1.0.41-dev.3

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.41-dev.2",
3
+ "version": "1.0.41-dev.3",
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",
@@ -155,22 +155,53 @@ async function assertGithubRepoPublic(github) {
155
155
  }
156
156
  }
157
157
 
158
- async function checkJsDelivr(config, vendorFile, appFile, appCssFile) {
158
+ async function headJsDelivrFile(base, file, { required = false } = {}) {
159
+ const url = `${base}/${file}`
160
+ log(`Checking jsDelivr (may take a minute on first publish): ${url}`)
161
+ try {
162
+ const res = await fetch(url, { method: 'HEAD' })
163
+ if (res.ok) {
164
+ log(` OK ${res.status} ${file}`)
165
+ return true
166
+ }
167
+ const msg = `${file} → HTTP ${res.status}${required ? '' : ' (jsDelivr may still be propagating — wait 5–15 min)'}`
168
+ if (required) {
169
+ fail(msg)
170
+ }
171
+ log(` ${msg}`)
172
+ return false
173
+ } catch (err) {
174
+ const msg = `Could not reach jsDelivr for ${file}: ${err.message}`
175
+ if (required) {
176
+ fail(msg)
177
+ }
178
+ log(` ${msg}`)
179
+ return false
180
+ }
181
+ }
182
+
183
+ async function checkJsDelivr(config, vendorFile, appFile, appCssFile, lazyChunkFiles = []) {
159
184
  const base = jsDelivrBaseUrl(config.github, config.cdnPathInRepo, config.defaultBranch)
160
185
  for (const file of [appCssFile, vendorFile, appFile]) {
161
- const url = `${base}/${file}`
162
- log(`Checking jsDelivr (may take a minute on first publish): ${url}`)
163
- try {
164
- const res = await fetch(url, { method: 'HEAD' })
165
- if (res.ok) {
166
- log(` OK ${res.status} ${file}`)
167
- } else {
168
- log(` ${file} HTTP ${res.status} (jsDelivr may still be propagating wait 5–15 min)`)
169
- }
170
- } catch (err) {
171
- log(` Could not reach jsDelivr for ${file}: ${err.message}`)
172
- }
186
+ await headJsDelivrFile(base, file)
187
+ }
188
+ if (lazyChunkFiles.length > 0) {
189
+ const sample = lazyChunkFiles[0]
190
+ log(`Checking lazy chunk sample (${lazyChunkFiles.length} in manifest): ${sample}`)
191
+ await headJsDelivrFile(base, sample, { required: true })
192
+ } else {
193
+ log(' No lazy chunks/ in manifest skipping lazy chunk HEAD check')
194
+ }
195
+ }
196
+
197
+ function readLazyChunkFilesFromManifest(manifestPath) {
198
+ if (!existsSync(manifestPath)) {
199
+ return []
173
200
  }
201
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
202
+ return (manifest.scripts ?? [])
203
+ .map((entry) => entry?.file)
204
+ .filter((file) => typeof file === 'string' && file.startsWith('chunks/'))
174
205
  }
175
206
 
176
207
  const config = loadPortalCdnConfig()
@@ -334,6 +365,9 @@ log(' yarn build:hubspot:prod # prod API')
334
365
  log(' 3. yarn upload:hubspot')
335
366
  log(' Or: yarn deploy:dev | yarn deploy:prod')
336
367
 
368
+ const manifestPath = join(sourceCdn, 'manifest.json')
369
+ const lazyChunkFiles = readLazyChunkFilesFromManifest(manifestPath)
370
+
337
371
  if (!skipJsDelivrCheck) {
338
- await checkJsDelivr(config, vendorFile, appFile, appCssFile)
372
+ await checkJsDelivr(config, vendorFile, appFile, appCssFile, lazyChunkFiles)
339
373
  }
@@ -22,6 +22,8 @@ const reactShimAliases = [
22
22
  export default defineConfig(({ mode }) => {
23
23
  const baseResolve = portalResolve(mode)
24
24
  return {
25
+ // Relative base so dynamic import() resolves lazy chunks from jsDelivr (same dir as app.js), not HubSpot origin.
26
+ base: './',
25
27
  // TanStack autoCodeSplitting + ESM CDN entry caused router.init stack overflow on HubSpot.
26
28
  // Keep Rollup lazy chunks via React.lazy() / dynamic import(); route modules stay in the app entry.
27
29
  plugins: portalPlugins(mode, { codeSplitting: false }),