Skip to content

Commit 67d3a99

Browse files
authored
Build: assign the library exports to window.wp rather than this.wp (WordPress#26272)
* Build: assign the library exports to window.wp rather than this.wp * Update unit test snapshots * Return correct variable specifier: an array
1 parent c53e3ed commit 67d3a99

File tree

3 files changed

+75
-109
lines changed

3 files changed

+75
-109
lines changed

packages/dependency-extraction-webpack-plugin/lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class DependencyExtractionWebpackPlugin {
8888

8989
// Offload externalization work to the ExternalsPlugin.
9090
this.externalsPlugin = new ExternalsPlugin(
91-
'this',
91+
'window',
9292
this.externalizeWpDeps.bind( this )
9393
);
9494
}
@@ -119,7 +119,7 @@ class DependencyExtractionWebpackPlugin {
119119
if ( externalRequest ) {
120120
this.externalizedDeps.add( request );
121121

122-
return callback( null, { this: externalRequest } );
122+
return callback( null, externalRequest );
123123
}
124124

125125
return callback();

packages/dependency-extraction-webpack-plugin/test/__snapshots__/build.js.snap

+72-106
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,68 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Webpack \`combine-assets\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => '2ac177723ec97b400d9b7c46f5270974'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => 'bddb08fb8608759738528b9de111454d'));"`;
3+
exports[`Webpack \`combine-assets\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'a3da22ced6876ec052d2861d383960fc'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => '1a2b3802cc39dc1a607ecc4d0b23fcb0'));"`;
44

55
exports[`Webpack \`combine-assets\` should produce expected output: External modules should match snapshot 1`] = `
66
Array [
77
Object {
8-
"externalType": "this",
9-
"request": Object {
10-
"this": Array [
11-
"wp",
12-
"blob",
13-
],
14-
},
8+
"externalType": "window",
9+
"request": Array [
10+
"wp",
11+
"blob",
12+
],
1513
"userRequest": "@wordpress/blob",
1614
},
1715
Object {
18-
"externalType": "this",
19-
"request": Object {
20-
"this": Array [
21-
"wp",
22-
"tokenList",
23-
],
24-
},
16+
"externalType": "window",
17+
"request": Array [
18+
"wp",
19+
"tokenList",
20+
],
2521
"userRequest": "@wordpress/token-list",
2622
},
2723
Object {
28-
"externalType": "this",
29-
"request": Object {
30-
"this": "lodash",
31-
},
24+
"externalType": "window",
25+
"request": "lodash",
3226
"userRequest": "lodash",
3327
},
3428
]
3529
`;
3630

37-
exports[`Webpack \`dynamic-import\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '5d8e58fe98bc4c6277a76ece11fcb8b7');"`;
31+
exports[`Webpack \`dynamic-import\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'd5c613274c346f46e16ab4d320fc01e6');"`;
3832

3933
exports[`Webpack \`dynamic-import\` should produce expected output: External modules should match snapshot 1`] = `
4034
Array [
4135
Object {
42-
"externalType": "this",
43-
"request": Object {
44-
"this": Array [
45-
"wp",
46-
"blob",
47-
],
48-
},
36+
"externalType": "window",
37+
"request": Array [
38+
"wp",
39+
"blob",
40+
],
4941
"userRequest": "@wordpress/blob",
5042
},
5143
Object {
52-
"externalType": "this",
53-
"request": Object {
54-
"this": "lodash",
55-
},
44+
"externalType": "window",
45+
"request": "lodash",
5646
"userRequest": "lodash",
5747
},
5848
]
5949
`;
6050

61-
exports[`Webpack \`function-output-filename\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '407eacfb62231e58aaca5eec87e63725');"`;
51+
exports[`Webpack \`function-output-filename\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'f6dc46e27c3a9e7338ed4fa9fdf8f606');"`;
6252

6353
exports[`Webpack \`function-output-filename\` should produce expected output: External modules should match snapshot 1`] = `
6454
Array [
6555
Object {
66-
"externalType": "this",
67-
"request": Object {
68-
"this": Array [
69-
"wp",
70-
"blob",
71-
],
72-
},
56+
"externalType": "window",
57+
"request": Array [
58+
"wp",
59+
"blob",
60+
],
7361
"userRequest": "@wordpress/blob",
7462
},
7563
Object {
76-
"externalType": "this",
77-
"request": Object {
78-
"this": "lodash",
79-
},
64+
"externalType": "window",
65+
"request": "lodash",
8066
"userRequest": "lodash",
8167
},
8268
]
@@ -90,65 +76,55 @@ exports[`Webpack \`no-deps\` should produce expected output: Asset file should m
9076

9177
exports[`Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] = `Array []`;
9278

93-
exports[`Webpack \`output-format-json\` should produce expected output: Asset file should match snapshot 1`] = `"{\\"dependencies\\":[\\"lodash\\"],\\"version\\":\\"0e6d34ea09104a64e6184f524b48ad65\\"}"`;
79+
exports[`Webpack \`output-format-json\` should produce expected output: Asset file should match snapshot 1`] = `"{\\"dependencies\\":[\\"lodash\\"],\\"version\\":\\"aeb5066a5e17aea01932c77baf342372\\"}"`;
9480

9581
exports[`Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] = `
9682
Array [
9783
Object {
98-
"externalType": "this",
99-
"request": Object {
100-
"this": "lodash",
101-
},
84+
"externalType": "window",
85+
"request": "lodash",
10286
"userRequest": "lodash",
10387
},
10488
]
10589
`;
10690

107-
exports[`Webpack \`overrides\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('wp-blob', 'wp-script-handle-for-rxjs', 'wp-url'), 'version' => '2fd24c89b50c763f2e2dcc02a6933c16');"`;
91+
exports[`Webpack \`overrides\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('wp-blob', 'wp-script-handle-for-rxjs', 'wp-url'), 'version' => '67d711ce8940ddb82e7f264f61a5a3d9');"`;
10892

10993
exports[`Webpack \`overrides\` should produce expected output: External modules should match snapshot 1`] = `
11094
Array [
11195
Object {
112-
"externalType": "this",
113-
"request": Object {
114-
"this": Array [
115-
"wp",
116-
"blob",
117-
],
118-
},
96+
"externalType": "window",
97+
"request": Array [
98+
"wp",
99+
"blob",
100+
],
119101
"userRequest": "@wordpress/blob",
120102
},
121103
Object {
122-
"externalType": "this",
123-
"request": Object {
124-
"this": Array [
125-
"wp",
126-
"url",
127-
],
128-
},
104+
"externalType": "window",
105+
"request": Array [
106+
"wp",
107+
"url",
108+
],
129109
"userRequest": "@wordpress/url",
130110
},
131111
Object {
132-
"externalType": "this",
133-
"request": Object {
134-
"this": Array [
135-
"rxjs",
136-
"operators",
137-
],
138-
},
112+
"externalType": "window",
113+
"request": Array [
114+
"rxjs",
115+
"operators",
116+
],
139117
"userRequest": "rxjs/operators",
140118
},
141119
Object {
142-
"externalType": "this",
143-
"request": Object {
144-
"this": "rxjs",
145-
},
120+
"externalType": "window",
121+
"request": "rxjs",
146122
"userRequest": "rxjs",
147123
},
148124
]
149125
`;
150126

151-
exports[`Webpack \`with-externs\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('wp-url'), 'version' => 'e987036543f42978608ac27e589b5fe3');"`;
127+
exports[`Webpack \`with-externs\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('wp-url'), 'version' => '43ee069ad238d0c92526824ddfb9e4fb');"`;
152128

153129
exports[`Webpack \`with-externs\` should produce expected output: External modules should match snapshot 1`] = `
154130
Array [
@@ -158,13 +134,11 @@ Array [
158134
"userRequest": "@wordpress/blob",
159135
},
160136
Object {
161-
"externalType": "this",
162-
"request": Object {
163-
"this": Array [
164-
"wp",
165-
"url",
166-
],
167-
},
137+
"externalType": "window",
138+
"request": Array [
139+
"wp",
140+
"url",
141+
],
168142
"userRequest": "@wordpress/url",
169143
},
170144
Object {
@@ -180,49 +154,41 @@ Array [
180154
]
181155
`;
182156

183-
exports[`Webpack \`wordpress\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'f6f0d227edbcb02382070c0efac33b51');"`;
157+
exports[`Webpack \`wordpress\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '202b3ce17cfd72799ce45e7efa04d83c');"`;
184158

185159
exports[`Webpack \`wordpress\` should produce expected output: External modules should match snapshot 1`] = `
186160
Array [
187161
Object {
188-
"externalType": "this",
189-
"request": Object {
190-
"this": Array [
191-
"wp",
192-
"blob",
193-
],
194-
},
162+
"externalType": "window",
163+
"request": Array [
164+
"wp",
165+
"blob",
166+
],
195167
"userRequest": "@wordpress/blob",
196168
},
197169
Object {
198-
"externalType": "this",
199-
"request": Object {
200-
"this": "lodash",
201-
},
170+
"externalType": "window",
171+
"request": "lodash",
202172
"userRequest": "lodash",
203173
},
204174
]
205175
`;
206176

207-
exports[`Webpack \`wordpress-require\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '31a7631b4838830b14b5ab10e17f3e0f');"`;
177+
exports[`Webpack \`wordpress-require\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '47b0c1540a1caf08b8931e4a4328db04');"`;
208178

209179
exports[`Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 1`] = `
210180
Array [
211181
Object {
212-
"externalType": "this",
213-
"request": Object {
214-
"this": Array [
215-
"wp",
216-
"blob",
217-
],
218-
},
182+
"externalType": "window",
183+
"request": Array [
184+
"wp",
185+
"blob",
186+
],
219187
"userRequest": "@wordpress/blob",
220188
},
221189
Object {
222-
"externalType": "this",
223-
"request": Object {
224-
"this": "lodash",
225-
},
190+
"externalType": "window",
191+
"request": "lodash",
226192
"userRequest": "lodash",
227193
},
228194
]

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
filename: './build/[basename]/index.js',
7272
path: __dirname,
7373
library: [ 'wp', '[name]' ],
74-
libraryTarget: 'this',
74+
libraryTarget: 'window',
7575
},
7676
module: {
7777
rules: compact( [

0 commit comments

Comments
 (0)