@makefully/adaptfully 3.15.0 → 3.15.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.
- package/CHANGELOG.md +6 -0
- package/lib/node/packagers/base.js +93 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 3.15.1 — 2026-09-01
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Capacitor/Cordova HTML injection** — packager `<meta>` tags (CSP, viewport) are injected into `<head>`; script tags stay in the body `<!-- adaptfully -->` slot. Fixes browsers ignoring CSP delivered outside `<head>`.
|
|
10
|
+
|
|
5
11
|
## 3.15.0 — 2026-08-24
|
|
6
12
|
|
|
7
13
|
### Added
|
|
@@ -11,6 +11,8 @@ export const VALID_PACKAGERS = ['web', 'electron', 'cordova', 'capacitor'];
|
|
|
11
11
|
|
|
12
12
|
const PACKAGER_MARKER = '<!-- adaptfully-packager -->';
|
|
13
13
|
const PACKAGER_END_MARKER = '<!-- /adaptfully-packager -->';
|
|
14
|
+
const HEAD_PACKAGER_MARKER = '<!-- adaptfully-packager-head -->';
|
|
15
|
+
const HEAD_PACKAGER_END_MARKER = '<!-- /adaptfully-packager-head -->';
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* @typedef {Object} PackagerOptions
|
|
@@ -58,21 +60,64 @@ function writeGameConfig(dest, platformKey, pkg, log) {
|
|
|
58
60
|
|
|
59
61
|
/**
|
|
60
62
|
* @param {string} html
|
|
63
|
+
* @param {string} marker
|
|
64
|
+
* @param {string} endMarker
|
|
61
65
|
* @param {string} injection
|
|
62
66
|
*/
|
|
63
|
-
function
|
|
64
|
-
if (!injection) {
|
|
65
|
-
return html;
|
|
66
|
-
}
|
|
67
|
-
|
|
67
|
+
function replaceMarkedBlock(html, marker, endMarker, injection) {
|
|
68
68
|
const markerPattern = new RegExp(
|
|
69
|
-
`${escapeRegExp(
|
|
69
|
+
`${escapeRegExp(marker)}[\\s\\S]*?${escapeRegExp(endMarker)}\\n?`,
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
if (markerPattern.test(html)) {
|
|
73
73
|
return html.replace(markerPattern, injection);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
if (html.includes(marker)) {
|
|
77
|
+
return html.replace(marker, `${injection}${marker}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return html;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {string} html
|
|
85
|
+
* @param {string} injection
|
|
86
|
+
*/
|
|
87
|
+
function injectHeadPackagerExtras(html, injection) {
|
|
88
|
+
if (!injection) {
|
|
89
|
+
return html;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let updated = replaceMarkedBlock(html, HEAD_PACKAGER_MARKER, HEAD_PACKAGER_END_MARKER, injection);
|
|
93
|
+
|
|
94
|
+
if (updated === html && html.includes('</head>')) {
|
|
95
|
+
updated = html.replace('</head>', `${injection}</head>`);
|
|
96
|
+
} else if (updated === html) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
'Cannot inject packager head extras: HTML needs '
|
|
99
|
+
+ `${HEAD_PACKAGER_MARKER}…${HEAD_PACKAGER_END_MARKER} or </head>`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return updated;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {string} html
|
|
108
|
+
* @param {string} injection
|
|
109
|
+
*/
|
|
110
|
+
function injectBodyPackagerExtras(html, injection) {
|
|
111
|
+
if (!injection) {
|
|
112
|
+
return html;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let updated = replaceMarkedBlock(html, PACKAGER_MARKER, PACKAGER_END_MARKER, injection);
|
|
116
|
+
|
|
117
|
+
if (updated !== html) {
|
|
118
|
+
return updated;
|
|
119
|
+
}
|
|
120
|
+
|
|
76
121
|
if (html.includes(PACKAGER_MARKER)) {
|
|
77
122
|
return html.replace(PACKAGER_MARKER, `${injection}${PACKAGER_MARKER}`);
|
|
78
123
|
}
|
|
@@ -85,17 +130,36 @@ function injectPackagerExtras(html, injection) {
|
|
|
85
130
|
return html.replace('<!-- scripts -->', `${injection}<!-- scripts -->`);
|
|
86
131
|
}
|
|
87
132
|
|
|
88
|
-
if (html.includes('</
|
|
89
|
-
return html.replace('</
|
|
133
|
+
if (html.includes('</body>')) {
|
|
134
|
+
return html.replace('</body>', `${injection}</body>`);
|
|
90
135
|
}
|
|
91
136
|
|
|
92
137
|
throw new Error(
|
|
93
|
-
'Cannot inject packager extras: HTML needs '
|
|
138
|
+
'Cannot inject packager body extras: HTML needs '
|
|
94
139
|
+ '<!-- adaptfully-packager -->…<!-- /adaptfully-packager -->, '
|
|
95
|
-
+ '<!-- adaptfully -->, <!-- scripts -->, or </
|
|
140
|
+
+ '<!-- adaptfully -->, <!-- scripts -->, or </body>',
|
|
96
141
|
);
|
|
97
142
|
}
|
|
98
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @param {string} html
|
|
146
|
+
* @param {{ head?: string, body?: string }} injection
|
|
147
|
+
*/
|
|
148
|
+
function injectPackagerExtras(html, injection) {
|
|
149
|
+
if (!injection?.head && !injection?.body) {
|
|
150
|
+
return html;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let updated = html;
|
|
154
|
+
if (injection.head) {
|
|
155
|
+
updated = injectHeadPackagerExtras(updated, injection.head);
|
|
156
|
+
}
|
|
157
|
+
if (injection.body) {
|
|
158
|
+
updated = injectBodyPackagerExtras(updated, injection.body);
|
|
159
|
+
}
|
|
160
|
+
return updated;
|
|
161
|
+
}
|
|
162
|
+
|
|
99
163
|
function escapeRegExp(value) {
|
|
100
164
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
101
165
|
}
|
|
@@ -243,22 +307,28 @@ export class Packager {
|
|
|
243
307
|
/**
|
|
244
308
|
* @param {string[]} headExtras
|
|
245
309
|
* @param {string[]} bodyScripts
|
|
246
|
-
* @returns {string}
|
|
310
|
+
* @returns {{ head: string, body: string }}
|
|
247
311
|
*/
|
|
248
312
|
formatHtmlInjection(headExtras, bodyScripts) {
|
|
249
|
-
|
|
250
|
-
|
|
313
|
+
let head = '';
|
|
314
|
+
if (headExtras.length > 0) {
|
|
315
|
+
head = `${HEAD_PACKAGER_MARKER}\n`;
|
|
316
|
+
for (const extra of headExtras) {
|
|
317
|
+
head += `${extra}\n`;
|
|
318
|
+
}
|
|
319
|
+
head += `${HEAD_PACKAGER_END_MARKER}\n`;
|
|
251
320
|
}
|
|
252
321
|
|
|
253
|
-
let
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
322
|
+
let body = '';
|
|
323
|
+
if (bodyScripts.length > 0) {
|
|
324
|
+
body = `${PACKAGER_MARKER}\n`;
|
|
325
|
+
for (const script of bodyScripts) {
|
|
326
|
+
body += `${script}\n`;
|
|
327
|
+
}
|
|
328
|
+
body += `${PACKAGER_END_MARKER}\n`;
|
|
259
329
|
}
|
|
260
|
-
|
|
261
|
-
return
|
|
330
|
+
|
|
331
|
+
return { head, body };
|
|
262
332
|
}
|
|
263
333
|
|
|
264
334
|
/** @param {string} dest */
|
|
@@ -268,7 +338,7 @@ export class Packager {
|
|
|
268
338
|
}
|
|
269
339
|
}
|
|
270
340
|
|
|
271
|
-
/** @returns {string} */
|
|
341
|
+
/** @returns {{ head: string, body: string }} */
|
|
272
342
|
buildHtmlInjection() {
|
|
273
343
|
const bodyScripts = [];
|
|
274
344
|
if (this.needsGameConfig()) {
|
|
@@ -283,7 +353,7 @@ export class Packager {
|
|
|
283
353
|
*/
|
|
284
354
|
applyHtmlExtras(dest, htmlPaths) {
|
|
285
355
|
const injection = this.buildHtmlInjection();
|
|
286
|
-
if (!injection) {
|
|
356
|
+
if (!injection.head && !injection.body) {
|
|
287
357
|
return;
|
|
288
358
|
}
|
|
289
359
|
|