Skip to content

Commit e20e9ee

Browse files
committed
fix(youtube-player): fix "ban-script-src-assignments"
1 parent 44c4fe5 commit e20e9ee

File tree

6 files changed

+127
-3
lines changed

6 files changed

+127
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@types/youtube": "^0.1.0",
6767
"rxjs": "^6.6.7",
6868
"rxjs-tslint-rules": "^4.34.8",
69+
"safevalues": "^1.2.0",
6970
"tslib": "^2.3.1",
7071
"zone.js": "~0.15.0"
7172
},
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
diff --git a/node_modules/@angular/bazel/src/ng_module/ng_module.bzl b/node_modules/@angular/bazel/src/ng_module/ng_module.bzl
2+
index 5e82bcb..3c239f8 100755
3+
--- a/node_modules/@angular/bazel/src/ng_module/ng_module.bzl
4+
+++ b/node_modules/@angular/bazel/src/ng_module/ng_module.bzl
5+
@@ -18,6 +18,7 @@ load(
6+
"TsConfigInfo",
7+
"compile_ts",
8+
"js_ecma_script_module_info",
9+
+ "js_named_module_info",
10+
"js_module_info",
11+
"node_modules_aspect",
12+
"ts_providers_dict_to_struct",
13+
@@ -151,9 +152,9 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
14+
is_devmode = "devmode_manifest" in kwargs
15+
outs = _expected_outs(ctx)
16+
if is_devmode:
17+
- expected_outs = outs.devmode_js
18+
+ expected_outs = outs.devmode_js + outs.declarations
19+
else:
20+
- expected_outs = outs.closure_js + outs.declarations
21+
+ expected_outs = outs.closure_js
22+
23+
if not ctx.attr.type_check and ctx.attr.strict_templates:
24+
fail("Cannot set type_check = False and strict_templates = True for ng_module()")
25+
@@ -355,11 +356,11 @@ def _compile_action(
26+
27+
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
28+
outs = _expected_outs(ctx)
29+
- return _compile_action(ctx, inputs, outputs + outs.closure_js + outs.prod_perf_files + outs.declarations, tsconfig_file, node_opts, "prodmode")
30+
+ return _compile_action(ctx, inputs, outputs + outs.closure_js + outs.prod_perf_files, tsconfig_file, node_opts, "prodmode")
31+
32+
def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
33+
outs = _expected_outs(ctx)
34+
- compile_action_outputs = outputs + outs.devmode_js + outs.dev_perf_files
35+
+ compile_action_outputs = outputs + outs.devmode_js + outs.dev_perf_files + outs.declarations
36+
_compile_action(ctx, inputs, compile_action_outputs, tsconfig_file, node_opts, "devmode")
37+
38+
# Note: We need to define `label` and `srcs_files` as `tsc_wrapped` passes
39+
@@ -413,9 +414,13 @@ def _ng_module_impl(ctx):
40+
# and issue https://github.com/bazelbuild/rules_nodejs/issues/57 for more details.
41+
ts_providers["providers"].extend([
42+
js_module_info(
43+
- sources = ts_providers["typescript"]["es6_sources"],
44+
+ sources = ts_providers["typescript"]["es5_sources"],
45+
deps = ctx.attr.deps,
46+
),
47+
+ js_named_module_info(
48+
+ sources = ts_providers["typescript"]["es5_sources"],
49+
+ deps = ctx.attr.deps,
50+
+ ),
51+
js_ecma_script_module_info(
52+
sources = ts_providers["typescript"]["es6_sources"],
53+
deps = ctx.attr.deps,
54+
@@ -431,7 +436,7 @@ def _ng_module_impl(ctx):
55+
package_name = ctx.attr.package_name,
56+
package_path = ctx.attr.package_path,
57+
path = path,
58+
- files = ts_providers["typescript"]["es6_sources"],
59+
+ files = ts_providers["typescript"]["es5_sources"],
60+
))
61+
62+
return ts_providers_dict_to_struct(ts_providers)
63+
diff --git a/node_modules/@angular/bazel/src/ng_package/packager.mjs b/node_modules/@angular/bazel/src/ng_package/packager.mjs
64+
index 7184fd9..ef3e508 100755
65+
--- a/node_modules/@angular/bazel/src/ng_package/packager.mjs
66+
+++ b/node_modules/@angular/bazel/src/ng_package/packager.mjs
67+
@@ -7,7 +7,7 @@
68+
*/
69+
import * as fs from 'fs';
70+
import * as path from 'path';
71+
-import { analyzeFileAndEnsureNoCrossImports } from './cross_entry_points_imports';
72+
+import { analyzeFileAndEnsureNoCrossImports } from './cross_entry_points_imports.mjs';
73+
/**
74+
* List of known `package.json` fields which provide information about
75+
* supported package formats and their associated entry paths.
76+
diff --git a/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs b/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs
77+
index def2972..3de33ba 100755
78+
--- a/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs
79+
+++ b/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs
80+
@@ -12,7 +12,7 @@ import tscw from '@bazel/concatjs/internal/tsc_wrapped/index.js';
81+
import * as fs from 'fs';
82+
import * as path from 'path';
83+
import ts from 'typescript';
84+
-import { EXT, patchNgHostWithFileNameToModuleName as patchNgHost, relativeToRootDirs } from './utils';
85+
+import { EXT, patchNgHostWithFileNameToModuleName as patchNgHost, relativeToRootDirs } from './utils.mjs';
86+
// FIXME: we should be able to add the assets to the tsconfig so FileLoader
87+
// knows about them
88+
const NGC_ASSETS = /\.(css|html)$/;
89+
@@ -349,6 +349,12 @@ function gatherDiagnosticsForInputsOnly(options, bazelOpts, ngProgram) {
90+
}
91+
return diagnostics;
92+
}
93+
+
94+
+main(process.argv.slice(2)).then(exitCode => process.exitCode = exitCode).catch(e => {
95+
+ console.error(e);
96+
+ process.exitCode = 1;
97+
+});
98+
+
99+
/**
100+
* @deprecated
101+
* Kept here just for compatibility with 1P tools. To be removed soon after 1P update.
102+
diff --git a/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs b/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs
103+
index 8efba56..be29334 100755
104+
--- a/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs
105+
+++ b/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs
106+
@@ -5,7 +5,7 @@
107+
* Use of this source code is governed by an MIT-style license that can be
108+
* found in the LICENSE file at https://angular.dev/license
109+
*/
110+
-import { main } from './index';
111+
+import { main } from './index.mjs';
112+
main(process.argv.slice(2))
113+
.then((exitCode) => (process.exitCode = exitCode))
114+
.catch((e) => {

src/youtube-player/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ng_module(
2828
"@npm//@angular/core",
2929
"@npm//@types/youtube",
3030
"@npm//rxjs",
31+
"@npm//safevalues",
3132
],
3233
)
3334

src/youtube-player/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"peerDependencies": {
2424
"@angular/core": "0.0.0-NG",
2525
"@angular/common": "0.0.0-NG",
26-
"rxjs": "0.0.0-RXJS"
26+
"rxjs": "0.0.0-RXJS",
27+
"safevalues": "^1.2.0"
2728
},
2829
"sideEffects": false,
2930
"schematics": "./schematics/collection.json",

src/youtube-player/youtube-player.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
EventEmitter,
3333
} from '@angular/core';
3434
import {isPlatformBrowser} from '@angular/common';
35+
import {trustedResourceUrl} from 'safevalues';
36+
import {setScriptSrc} from 'safevalues/dom';
3537
import {Observable, of as observableOf, Subject, BehaviorSubject, fromEventPattern} from 'rxjs';
3638
import {takeUntil, switchMap} from 'rxjs/operators';
3739
import {PlaceholderImageQuality, YouTubePlayerPlaceholder} from './youtube-player-placeholder';
@@ -743,7 +745,7 @@ function loadApi(nonce: string | null): void {
743745
}
744746

745747
// We can use `document` directly here, because this logic doesn't run outside the browser.
746-
const url = 'https://www.youtube.com/iframe_api';
748+
const url = trustedResourceUrl`https://www.youtube.com/iframe_api`;
747749
const script = document.createElement('script');
748750
const callback = (event: Event) => {
749751
script.removeEventListener('load', callback);
@@ -759,7 +761,7 @@ function loadApi(nonce: string | null): void {
759761
};
760762
script.addEventListener('load', callback);
761763
script.addEventListener('error', callback);
762-
script.src = url;
764+
setScriptSrc(script, url);
763765
script.async = true;
764766

765767
if (nonce) {

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -13685,6 +13685,11 @@ safe-stable-stringify@^2.3.1:
1368513685
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
1368613686
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
1368713687

13688+
safevalues@^1.2.0:
13689+
version "1.2.0"
13690+
resolved "https://registry.yarnpkg.com/safevalues/-/safevalues-1.2.0.tgz#f9e646d6ebf31788004ef192d2a7d646c9896bb2"
13691+
integrity sha512-zIsuhjYvJCjfsfjoim2ab6gLKFYAnTiDSJGh0cC3T44L/4kNLL90hBG2BzrXPrHA3f8Ms8FSJ1mljKH5dVR1cw==
13692+
1368813693
1368913694
version "16.0.5"
1369013695
resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-16.0.5.tgz#257bc90119ade066851cafe7f2c3f3504c7cda98"

0 commit comments

Comments
 (0)