@woodsportal/hubspot-kit 1.0.41-dev.2 → 1.0.41-dev.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/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.4",
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,81 @@ async function assertGithubRepoPublic(github) {
155
155
  }
156
156
  }
157
157
 
158
- async function checkJsDelivr(config, vendorFile, appFile, appCssFile) {
159
- const base = jsDelivrBaseUrl(config.github, config.cdnPathInRepo, config.defaultBranch)
160
- 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)`)
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 headJsDelivrFiles(base, files, { required = false, concurrency = 5 } = {}) {
184
+ if (files.length === 0) {
185
+ return { ok: true, failed: [] }
186
+ }
187
+ log(`Checking ${files.length} lazy chunk(s) on jsDelivr`)
188
+ const failed = []
189
+ for (let i = 0; i < files.length; i += concurrency) {
190
+ const batch = files.slice(i, i + concurrency)
191
+ const results = await Promise.all(
192
+ batch.map(async (file) => {
193
+ const ok = await headJsDelivrFile(base, file, { required: false })
194
+ return { file, ok }
195
+ }),
196
+ )
197
+ for (const result of results) {
198
+ if (!result.ok) {
199
+ failed.push(result.file)
169
200
  }
170
- } catch (err) {
171
- log(` Could not reach jsDelivr for ${file}: ${err.message}`)
172
201
  }
173
202
  }
203
+ if (failed.length > 0) {
204
+ const msg = `jsDelivr lazy chunk(s) not reachable: ${failed.join(', ')}`
205
+ if (required) {
206
+ fail(msg)
207
+ }
208
+ log(` ${msg}`)
209
+ }
210
+ return { ok: failed.length === 0, failed }
211
+ }
212
+
213
+ async function checkJsDelivr(config, vendorFile, appFile, appCssFile, lazyChunkFiles = []) {
214
+ const base = jsDelivrBaseUrl(config.github, config.cdnPathInRepo, config.defaultBranch)
215
+ for (const file of [appCssFile, vendorFile, appFile]) {
216
+ await headJsDelivrFile(base, file)
217
+ }
218
+ if (lazyChunkFiles.length > 0) {
219
+ await headJsDelivrFiles(base, lazyChunkFiles, { required: true })
220
+ } else {
221
+ log(' No lazy chunks/ in manifest — skipping lazy chunk HEAD check')
222
+ }
223
+ }
224
+
225
+ function readLazyChunkFilesFromManifest(manifestPath) {
226
+ if (!existsSync(manifestPath)) {
227
+ return []
228
+ }
229
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
230
+ return (manifest.scripts ?? [])
231
+ .map((entry) => entry?.file)
232
+ .filter((file) => typeof file === 'string' && file.startsWith('chunks/'))
174
233
  }
175
234
 
176
235
  const config = loadPortalCdnConfig()
@@ -334,6 +393,9 @@ log(' yarn build:hubspot:prod # prod API')
334
393
  log(' 3. yarn upload:hubspot')
335
394
  log(' Or: yarn deploy:dev | yarn deploy:prod')
336
395
 
396
+ const manifestPath = join(sourceCdn, 'manifest.json')
397
+ const lazyChunkFiles = readLazyChunkFilesFromManifest(manifestPath)
398
+
337
399
  if (!skipJsDelivrCheck) {
338
- await checkJsDelivr(config, vendorFile, appFile, appCssFile)
400
+ await checkJsDelivr(config, vendorFile, appFile, appCssFile, lazyChunkFiles)
339
401
  }
@@ -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 }),