slicejs-web-framework 3.2.0 → 3.2.1

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.
@@ -65,6 +65,20 @@ export default class Controller {
65
65
  return importPromise;
66
66
  }
67
67
 
68
+ buildBundleImportPath(bundleInfo) {
69
+ if (!bundleInfo || typeof bundleInfo.file !== 'string' || bundleInfo.file.length === 0) {
70
+ throw new Error('Bundle file is required');
71
+ }
72
+
73
+ const basePath = `/bundles/${bundleInfo.file}`;
74
+ const bundleHash = typeof bundleInfo.hash === 'string' ? bundleInfo.hash.trim() : '';
75
+ if (!bundleHash) {
76
+ return basePath;
77
+ }
78
+
79
+ return `${basePath}?v=${encodeURIComponent(bundleHash)}`;
80
+ }
81
+
68
82
  /**
69
83
  * Validate Bundling V2 module contract.
70
84
  * Requires named exports: SLICE_BUNDLE_META and registerAll.
@@ -126,7 +140,7 @@ export default class Controller {
126
140
  await this.loadBundleWithDependencies(dependencyName, loadingStack);
127
141
  }
128
142
 
129
- const bundlePath = `/bundles/${bundleInfo.file}`;
143
+ const bundlePath = this.buildBundleImportPath(bundleInfo);
130
144
  const bundleModule = await this.importBundleOnce(bundlePath);
131
145
  const { metadata, registerAll } = await this.validateBundleModule(bundleModule, resolvedBundleName);
132
146
 
@@ -379,6 +379,66 @@ test('loadBundle registers vendor-shared dependencies from registerAll return wh
379
379
  }
380
380
  });
381
381
 
382
+ test('loadBundle appends bundle hash as query param when importing bundle files', async () => {
383
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
384
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
385
+ await writeFile(
386
+ loaderPath,
387
+ `export async function resolve(specifier, context, nextResolve) {
388
+ if (specifier === '/Components/components.js') {
389
+ return {
390
+ shortCircuit: true,
391
+ url: 'data:text/javascript,export default {};',
392
+ };
393
+ }
394
+ return nextResolve(specifier, context);
395
+ }
396
+ `,
397
+ 'utf8'
398
+ );
399
+ register(pathToFileURL(loaderPath).href);
400
+
401
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
402
+ const { default: Controller } = await import(controllerModuleUrl);
403
+ const controller = new Controller();
404
+ const originalSlice = globalThis.slice;
405
+
406
+ controller.bundleConfig = {
407
+ bundles: {
408
+ routes: {
409
+ dashboard: {
410
+ file: 'slice-bundle.dashboard.js',
411
+ hash: 'abc123hash',
412
+ },
413
+ },
414
+ },
415
+ };
416
+
417
+ let importedPath = null;
418
+ controller.importBundleOnce = async (bundlePath) => {
419
+ importedPath = bundlePath;
420
+ return {
421
+ SLICE_BUNDLE_META: {
422
+ bundleKey: 'dashboard',
423
+ type: 'route',
424
+ },
425
+ registerAll: async () => {},
426
+ };
427
+ };
428
+
429
+ try {
430
+ globalThis.slice = {
431
+ stylesManager: {},
432
+ };
433
+
434
+ await controller.loadBundle('dashboard');
435
+ assert.equal(importedPath, '/bundles/slice-bundle.dashboard.js?v=abc123hash');
436
+ } finally {
437
+ globalThis.slice = originalSlice;
438
+ await rm(tempDir, { recursive: true, force: true });
439
+ }
440
+ });
441
+
382
442
  test('loadBundle dedupes concurrent and repeated alias/case requests using canonical bundle key', async () => {
383
443
  const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
384
444
  const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-web-framework",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=20"