Skip to content

Commit d2ba115

Browse files
authored
feat: automatically add cross-origin script attr when applicable (#70)
1 parent a37a033 commit d2ba115

File tree

18 files changed

+42
-22
lines changed

18 files changed

+42
-22
lines changed

src/__tests__/fixtures/asset-tag/__snapshots__/webpack4/server--main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_
254254

255255

256256

257+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
257258

258259
function renderAssets(out) {
259260
const entries = this.___entries;
@@ -275,7 +276,7 @@ function renderAssets(out) {
275276
for (const href of assets.js) {
276277
if (!written.has(href)) {
277278
written.add(href);
278-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
279+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
279280
}
280281
}
281282
}

src/__tests__/fixtures/asset-tag/__snapshots__/webpack5/server--main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__.
156156

157157

158158

159+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
159160

160161
function renderAssets(out) {
161162
const entries = this.___entries;
@@ -177,7 +178,7 @@ function renderAssets(out) {
177178
for (const href of assets.js) {
178179
if (!written.has(href)) {
179180
written.add(href);
180-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
181+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
181182
}
182183
}
183184
}

src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack4/server--main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_
166166

167167

168168

169+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
169170

170171
function renderAssets(out) {
171172
const entries = this.___entries;
@@ -187,7 +188,7 @@ function renderAssets(out) {
187188
for (const href of assets.js) {
188189
if (!written.has(href)) {
189190
written.add(href);
190-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
191+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
191192
}
192193
}
193194
}

src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack5/server--main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__.
6666

6767

6868

69+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
6970

7071
function renderAssets(out) {
7172
const entries = this.___entries;
@@ -87,7 +88,7 @@ function renderAssets(out) {
8788
for (const href of assets.js) {
8889
if (!written.has(href)) {
8990
written.add(href);
90-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
91+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
9192
}
9293
}
9394
}

src/__tests__/fixtures/basic-template-plugin-production/__snapshots__/webpack4/server--main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/fixtures/basic-template-plugin-production/__snapshots__/webpack5/server--main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/fixtures/basic-template-plugin/__snapshots__/webpack4/server--main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_
166166

167167

168168

169+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
169170

170171
function renderAssets(out) {
171172
const entries = this.___entries;
@@ -187,7 +188,7 @@ function renderAssets(out) {
187188
for (const href of assets.js) {
188189
if (!written.has(href)) {
189190
written.add(href);
190-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
191+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
191192
}
192193
}
193194
}

src/__tests__/fixtures/basic-template-plugin/__snapshots__/webpack5/server--main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__.
6666

6767

6868

69+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
6970

7071
function renderAssets(out) {
7172
const entries = this.___entries;
@@ -87,7 +88,7 @@ function renderAssets(out) {
8788
for (const href of assets.js) {
8889
if (!written.has(href)) {
8990
written.add(href);
90-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
91+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
9192
}
9293
}
9394
}

src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack4/server--main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_
154154

155155

156156

157+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
157158

158159
function renderAssets(out) {
159160
const entries = this.___entries;
@@ -175,7 +176,7 @@ function renderAssets(out) {
175176
for (const href of assets.js) {
176177
if (!written.has(href)) {
177178
written.add(href);
178-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
179+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
179180
}
180181
}
181182
}
@@ -321,6 +322,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_
321322

322323

323324

325+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
324326

325327
function renderAssets(out) {
326328
const entries = this.___entries;
@@ -342,7 +344,7 @@ function renderAssets(out) {
342344
for (const href of assets.js) {
343345
if (!written.has(href)) {
344346
written.add(href);
345-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
347+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
346348
}
347349
}
348350
}
@@ -458,6 +460,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_
458460

459461

460462

463+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
461464

462465
function renderAssets(out) {
463466
const entries = this.___entries;
@@ -479,7 +482,7 @@ function renderAssets(out) {
479482
for (const href of assets.js) {
480483
if (!written.has(href)) {
481484
written.add(href);
482-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
485+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
483486
}
484487
}
485488
}

src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack5/server--main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__.
7373

7474

7575

76+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
7677

7778
function renderAssets(out) {
7879
const entries = this.___entries;
@@ -94,7 +95,7 @@ function renderAssets(out) {
9495
for (const href of assets.js) {
9596
if (!written.has(href)) {
9697
written.add(href);
97-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
98+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
9899
}
99100
}
100101
}
@@ -247,6 +248,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__.
247248

248249

249250

251+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
250252

251253
function renderAssets(out) {
252254
const entries = this.___entries;
@@ -268,7 +270,7 @@ function renderAssets(out) {
268270
for (const href of assets.js) {
269271
if (!written.has(href)) {
270272
written.add(href);
271-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
273+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
272274
}
273275
}
274276
}
@@ -389,6 +391,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__.
389391

390392

391393

394+
const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin";
392395

393396
function renderAssets(out) {
394397
const entries = this.___entries;
@@ -410,7 +413,7 @@ function renderAssets(out) {
410413
for (const href of assets.js) {
411414
if (!written.has(href)) {
412415
written.add(href);
413-
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr} async></script>`;
416+
scripts += `<script src=${JSON.stringify(__webpack_require__.p + href)}${nonceAttr + crossOriginAttr} async></script>`;
414417
}
415418
}
416419
}

0 commit comments

Comments
 (0)