dalila 1.9.25 → 1.9.26
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 +1 -1
- package/scripts/dev-server.cjs +59 -3
package/package.json
CHANGED
package/scripts/dev-server.cjs
CHANGED
|
@@ -335,6 +335,52 @@ function createImportMapScript(dalilaPath, sourceDirPath = '/src/') {
|
|
|
335
335
|
return ` <script type="importmap">\n${payload}\n </script>`;
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
function mergeImportMapIntoHtml(html, dalilaPath, sourceDirPath = '/src/') {
|
|
339
|
+
const importMapPattern = /<script\b[^>]*type=["']importmap["'][^>]*>([\s\S]*?)<\/script>/i;
|
|
340
|
+
const match = html.match(importMapPattern);
|
|
341
|
+
if (!match) {
|
|
342
|
+
return {
|
|
343
|
+
html,
|
|
344
|
+
merged: false,
|
|
345
|
+
script: '',
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const existingPayload = match[1]?.trim() || '{}';
|
|
350
|
+
let importMap;
|
|
351
|
+
try {
|
|
352
|
+
importMap = JSON.parse(existingPayload);
|
|
353
|
+
} catch {
|
|
354
|
+
return {
|
|
355
|
+
html,
|
|
356
|
+
merged: false,
|
|
357
|
+
script: '',
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const existingImports = importMap && typeof importMap.imports === 'object' && importMap.imports !== null
|
|
362
|
+
? importMap.imports
|
|
363
|
+
: {};
|
|
364
|
+
const mergedImportMap = {
|
|
365
|
+
...importMap,
|
|
366
|
+
imports: {
|
|
367
|
+
...createImportMapEntries(dalilaPath, sourceDirPath),
|
|
368
|
+
...existingImports,
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
const payload = JSON.stringify(mergedImportMap, null, 2)
|
|
372
|
+
.split('\n')
|
|
373
|
+
.map(line => ` ${line}`)
|
|
374
|
+
.join('\n');
|
|
375
|
+
const script = ` <script type="importmap">\n${payload}\n </script>`;
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
html: html.replace(importMapPattern, ''),
|
|
379
|
+
merged: true,
|
|
380
|
+
script,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
338
384
|
// ============================================================================
|
|
339
385
|
// Preload Script Detection (auto-inject for persist() with preload: true)
|
|
340
386
|
// ============================================================================
|
|
@@ -536,11 +582,15 @@ function injectBindings(html, requestPath) {
|
|
|
536
582
|
const normalizedPath = normalizeHtmlRequestPath(requestPath);
|
|
537
583
|
// Different paths for dalila repo vs user projects
|
|
538
584
|
const dalilaPath = isDalilaRepo ? '/dist' : '/node_modules/dalila/dist';
|
|
539
|
-
const
|
|
585
|
+
const sourceDirPath = buildProjectSourceDirPath(projectDir);
|
|
586
|
+
const mergedImportMap = mergeImportMapIntoHtml(html, dalilaPath, sourceDirPath);
|
|
587
|
+
const importMap = mergedImportMap.merged
|
|
588
|
+
? mergedImportMap.script
|
|
589
|
+
: createImportMapScript(dalilaPath, sourceDirPath);
|
|
540
590
|
|
|
541
591
|
// For user projects, inject import map + HMR script
|
|
542
592
|
if (!isDalilaRepo) {
|
|
543
|
-
let output = addLoadingAttributes(html);
|
|
593
|
+
let output = addLoadingAttributes(mergedImportMap.html);
|
|
544
594
|
|
|
545
595
|
// Smart HMR script for user projects
|
|
546
596
|
const hmrScript = `
|
|
@@ -692,7 +742,12 @@ function injectBindings(html, requestPath) {
|
|
|
692
742
|
};
|
|
693
743
|
</script>`;
|
|
694
744
|
|
|
695
|
-
|
|
745
|
+
const headAdditions = buildUserProjectHeadAdditions(projectDir, dalilaPath)
|
|
746
|
+
.filter((fragment) => !mergedImportMap.merged || !/type=["']importmap["']/i.test(fragment));
|
|
747
|
+
if (importMap) {
|
|
748
|
+
headAdditions.push(importMap);
|
|
749
|
+
}
|
|
750
|
+
output = injectHeadFragments(output, headAdditions, {
|
|
696
751
|
beforeModule: true,
|
|
697
752
|
beforeStyles: true,
|
|
698
753
|
});
|
|
@@ -1353,6 +1408,7 @@ module.exports = {
|
|
|
1353
1408
|
safeDecodeUrlPath,
|
|
1354
1409
|
createImportMapEntries,
|
|
1355
1410
|
createImportMapScript,
|
|
1411
|
+
mergeImportMapIntoHtml,
|
|
1356
1412
|
detectPreloadScripts,
|
|
1357
1413
|
buildUserProjectHeadAdditions,
|
|
1358
1414
|
injectHeadFragments,
|