Skip to content

Commit ce1b187

Browse files
committed
fix: temporarily switch to using a locally patched version of get-own-property-symbols to fix patch-package-related postinstall issues
1 parent 7e641ce commit ce1b187

File tree

3 files changed

+360
-6
lines changed

3 files changed

+360
-6
lines changed

packages/core/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
"lit-html": "^1.1.1",
2828
"lodash.merge": "^4.6.2",
2929
"mdn-polyfills": "^5.17.1",
30-
"patch-package": "^6.1.2",
31-
"postinstall-postinstall": "^2.0.0",
3230
"preact": "8.4.2",
3331
"preact-compat": "^3.19.0",
3432
"pwa-helpers": "^0.9.1",
@@ -40,9 +38,6 @@
4038
"skatejs": "^5.2.4",
4139
"smoothscroll-polyfill": "^0.4.4"
4240
},
43-
"scripts": {
44-
"postinstall": "patch-package --patch-dir .patches/"
45-
},
4641
"bugs": "https://github.com/bolt-design-system/bolt/issues",
4742
"homepage": "https://boltdesignsystem.com",
4843
"publishConfig": {
Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
/*!
2+
Copyright (C) 2015 by WebReflection
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
22+
*/
23+
(function (Object, GOPS) {'use strict';
24+
25+
// (C) Andrea Giammarchi - Mit Style
26+
27+
if (GOPS in Object) return;
28+
29+
var
30+
setDescriptor,
31+
G = typeof global === typeof G ? window : global,
32+
id = 0,
33+
random = '' + Math.random(),
34+
prefix = '__\x01symbol:',
35+
prefixLength = prefix.length,
36+
internalSymbol = '__\x01symbol@@' + random,
37+
DP = 'defineProperty',
38+
DPies = 'defineProperties',
39+
GOPN = 'getOwnPropertyNames',
40+
GOPD = 'getOwnPropertyDescriptor',
41+
PIE = 'propertyIsEnumerable',
42+
gOPN = Object[GOPN],
43+
gOPD = Object[GOPD],
44+
create = Object.create,
45+
keys = Object.keys,
46+
freeze = Object.freeze || Object,
47+
defineProperty = Object[DP],
48+
$defineProperties = Object[DPies],
49+
descriptor = gOPD(Object, GOPN),
50+
ObjectProto = Object.prototype,
51+
hOP = ObjectProto.hasOwnProperty,
52+
pIE = ObjectProto[PIE],
53+
toString = ObjectProto.toString,
54+
addInternalIfNeeded = function (o, uid, enumerable) {
55+
if (!hOP.call(o, internalSymbol)) {
56+
defineProperty(o, internalSymbol, {
57+
enumerable: false,
58+
configurable: false,
59+
writable: false,
60+
value: {}
61+
});
62+
}
63+
o[internalSymbol]['@@' + uid] = enumerable;
64+
},
65+
createWithSymbols = function (proto, descriptors) {
66+
var self = create(proto);
67+
gOPN(descriptors).forEach(function (key) {
68+
if (propertyIsEnumerable.call(descriptors, key)) {
69+
$defineProperty(self, key, descriptors[key]);
70+
}
71+
});
72+
return self;
73+
},
74+
copyAsNonEnumerable = function (descriptor) {
75+
var newDescriptor = create(descriptor);
76+
newDescriptor.enumerable = false;
77+
return newDescriptor;
78+
},
79+
get = function get(){},
80+
onlyNonSymbols = function (name) {
81+
return name != internalSymbol &&
82+
!hOP.call(source, name);
83+
},
84+
onlySymbols = function (name) {
85+
return name != internalSymbol &&
86+
hOP.call(source, name);
87+
},
88+
propertyIsEnumerable = function propertyIsEnumerable(key) {
89+
var uid = '' + key;
90+
return onlySymbols(uid) ? (
91+
hOP.call(this, uid) &&
92+
this[internalSymbol]['@@' + uid]
93+
) : pIE.call(this, key);
94+
},
95+
setAndGetSymbol = function (uid) {
96+
var descriptor = {
97+
enumerable: false,
98+
configurable: true,
99+
get: get,
100+
set: function (value) {
101+
setDescriptor(this, uid, {
102+
enumerable: false,
103+
configurable: true,
104+
writable: true,
105+
value: value
106+
});
107+
addInternalIfNeeded(this, uid, true);
108+
}
109+
};
110+
defineProperty(ObjectProto, uid, descriptor);
111+
return freeze(source[uid] = defineProperty(
112+
Object(uid),
113+
'constructor',
114+
sourceConstructor
115+
));
116+
},
117+
Symbol = function Symbol(description) {
118+
if (this instanceof Symbol) {
119+
throw new TypeError('Symbol is not a constructor');
120+
}
121+
return setAndGetSymbol(
122+
prefix.concat(description || '', random, ++id)
123+
);
124+
},
125+
source = create(null),
126+
sourceConstructor = {value: Symbol},
127+
sourceMap = function (uid) {
128+
return source[uid];
129+
},
130+
$defineProperty = function defineProp(o, key, descriptor) {
131+
var uid = '' + key;
132+
if (onlySymbols(uid)) {
133+
setDescriptor(o, uid, descriptor.enumerable ?
134+
copyAsNonEnumerable(descriptor) : descriptor);
135+
addInternalIfNeeded(o, uid, !!descriptor.enumerable);
136+
} else {
137+
defineProperty(o, key, descriptor);
138+
}
139+
return o;
140+
},
141+
$getOwnPropertySymbols = function getOwnPropertySymbols(o) {
142+
return gOPN(o).filter(onlySymbols).map(sourceMap);
143+
}
144+
;
145+
146+
descriptor.value = $defineProperty;
147+
defineProperty(Object, DP, descriptor);
148+
149+
descriptor.value = $getOwnPropertySymbols;
150+
defineProperty(Object, GOPS, descriptor);
151+
152+
/**
153+
* @see https://github.com/aurelia/polyfills/pull/52/files
154+
*/
155+
var cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : [];
156+
var originalObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
157+
descriptor.value = function getOwnPropertyNames(o) {
158+
if (toString.call(o) === '[object Window]') {
159+
try {
160+
return originalObjectGetOwnPropertyNames(o);
161+
} catch (e) {
162+
// IE bug where layout engine calls userland gOPN for cross-domain "window" objects
163+
return [].concat([], cachedWindowNames);
164+
}
165+
}
166+
167+
return gOPN(o).filter(onlyNonSymbols);
168+
};
169+
defineProperty(Object, GOPN, descriptor);
170+
171+
descriptor.value = function defineProperties(o, descriptors) {
172+
var symbols = $getOwnPropertySymbols(descriptors);
173+
if (symbols.length) {
174+
keys(descriptors).concat(symbols).forEach(function (uid) {
175+
if (propertyIsEnumerable.call(descriptors, uid)) {
176+
$defineProperty(o, uid, descriptors[uid]);
177+
}
178+
});
179+
} else {
180+
$defineProperties(o, descriptors);
181+
}
182+
return o;
183+
};
184+
defineProperty(Object, DPies, descriptor);
185+
186+
descriptor.value = propertyIsEnumerable;
187+
defineProperty(ObjectProto, PIE, descriptor);
188+
189+
descriptor.value = Symbol;
190+
defineProperty(G, 'Symbol', descriptor);
191+
192+
// defining `Symbol.for(key)`
193+
descriptor.value = function (key) {
194+
var uid = prefix.concat(prefix, key, random);
195+
return uid in ObjectProto ? source[uid] : setAndGetSymbol(uid);
196+
};
197+
defineProperty(Symbol, 'for', descriptor);
198+
199+
// defining `Symbol.keyFor(symbol)`
200+
descriptor.value = function (symbol) {
201+
if (onlyNonSymbols(symbol))
202+
throw new TypeError(symbol + ' is not a symbol');
203+
if (!hOP.call(source, symbol)) {
204+
return void 0;
205+
}
206+
var label = symbol.slice(prefixLength);
207+
if (label.slice(0, prefixLength) !== prefix) {
208+
return void 0;
209+
}
210+
label = label.slice(prefixLength);
211+
if (label === random) {
212+
return void 0;
213+
}
214+
label = label.slice(0, label.length - random.length);
215+
return label.length > 0 ? label : void 0;
216+
};
217+
defineProperty(Symbol, 'keyFor', descriptor);
218+
219+
descriptor.value = function getOwnPropertyDescriptor(o, key) {
220+
var descriptor = gOPD(o, key);
221+
if (descriptor && onlySymbols(key)) {
222+
descriptor.enumerable = propertyIsEnumerable.call(o, key);
223+
}
224+
return descriptor;
225+
};
226+
defineProperty(Object, GOPD, descriptor);
227+
228+
descriptor.value = function (proto, descriptors) {
229+
return (arguments.length === 1 || typeof descriptors === "undefined") ?
230+
create(proto) :
231+
createWithSymbols(proto, descriptors);
232+
};
233+
defineProperty(Object, 'create', descriptor);
234+
235+
descriptor.value = function () {
236+
var str = toString.call(this);
237+
return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str;
238+
};
239+
defineProperty(ObjectProto, 'toString', descriptor);
240+
241+
try { // fails in few pre ES 5.1 engines
242+
if (true === create(
243+
defineProperty(
244+
{},
245+
prefix,
246+
{
247+
get: function () {
248+
return defineProperty(this, prefix, {value: true})[prefix];
249+
}
250+
}
251+
)
252+
)[prefix]) {
253+
setDescriptor = defineProperty;
254+
} else {
255+
throw 'IE11';
256+
}
257+
} catch(o_O) {
258+
setDescriptor = function (o, key, descriptor) {
259+
var protoDescriptor = gOPD(ObjectProto, key);
260+
delete ObjectProto[key];
261+
defineProperty(o, key, descriptor);
262+
defineProperty(ObjectProto, key, protoDescriptor);
263+
};
264+
}
265+
266+
}(Object, 'getOwnPropertySymbols'));
267+
268+
(function (O, Symbol) {'use strict';
269+
var
270+
dP = O.defineProperty,
271+
ObjectProto = O.prototype,
272+
toString = ObjectProto.toString,
273+
toStringTag = 'toStringTag',
274+
descriptor
275+
;
276+
[
277+
'iterator', // A method returning the default iterator for an object. Used by for...of.
278+
'match', // A method that matches against a string, also used to determine if an object may be used as a regular expression. Used by String.prototype.match().
279+
'replace', // A method that replaces matched substrings of a string. Used by String.prototype.replace().
280+
'search', // A method that returns the index within a string that matches the regular expression. Used by String.prototype.search().
281+
'split', // A method that splits a string at the indices that match a regular expression. Used by String.prototype.split().
282+
'hasInstance', // A method determining if a constructor object recognizes an object as its instance. Used by instanceof.
283+
'isConcatSpreadable', // A Boolean value indicating if an object should be flattened to its array elements. Used by Array.prototype.concat().
284+
'unscopables', // An Array of string values that are property values. These are excluded from the with environment bindings of the associated objects.
285+
'species', // A constructor function that is used to create derived objects.
286+
'toPrimitive', // A method converting an object to a primitive value.
287+
toStringTag // A string value used for the default description of an object. Used by Object.prototype.toString().
288+
].forEach(function (name) {
289+
if (!(name in Symbol)) {
290+
dP(Symbol, name, {value: Symbol(name)});
291+
switch (name) {
292+
case toStringTag:
293+
descriptor = O.getOwnPropertyDescriptor(ObjectProto, 'toString');
294+
descriptor.value = function () {
295+
var
296+
str = toString.call(this),
297+
tst = this != null ? this[Symbol.toStringTag] : this
298+
;
299+
return tst == null ? str : ('[object ' + tst + ']');
300+
};
301+
dP(ObjectProto, 'toString', descriptor);
302+
break;
303+
}
304+
}
305+
});
306+
}(Object, Symbol));
307+
308+
(function (Si, AP, SP) {
309+
310+
function returnThis() { return this; }
311+
312+
// make Arrays usable as iterators
313+
// so that other iterables can copy same logic
314+
if (!AP[Si]) AP[Si] = function () {
315+
var
316+
i = 0,
317+
self = this,
318+
iterator = {
319+
next: function next() {
320+
var done = self.length <= i;
321+
return done ?
322+
{done: done} :
323+
{done: done, value: self[i++]};
324+
}
325+
}
326+
;
327+
iterator[Si] = returnThis;
328+
return iterator;
329+
};
330+
331+
// make Strings usable as iterators
332+
// to simplify Array.from and for/of like loops
333+
if (!SP[Si]) SP[Si] = function () {
334+
var
335+
fromCodePoint = String.fromCodePoint,
336+
self = this,
337+
i = 0,
338+
length = self.length,
339+
iterator = {
340+
next: function next() {
341+
var
342+
done = length <= i,
343+
c = done ? '' : fromCodePoint(self.codePointAt(i))
344+
;
345+
i += c.length;
346+
return done ?
347+
{done: done} :
348+
{done: done, value: c};
349+
}
350+
}
351+
;
352+
iterator[Si] = returnThis;
353+
return iterator;
354+
};
355+
356+
}(Symbol.iterator, Array.prototype, String.prototype));

packages/core/polyfills/symbol-polyfill.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-disable no-extend-native */
22
// import polyfill for Symbol and Object.getOwnPropertySymbols
3-
import 'get-own-property-symbols/build/get-own-property-symbols.max.js';
3+
4+
// pre-patched version of get-own-property-symbols.
5+
// @todo: replace this with a proper fork or improved patch-package workflow
6+
import './get-own-property-symbols.max.js';
47

58
// Fix issue in toString patch when compiled into strict mode via closure
69
// https://github.com/es-shims/get-own-property-symbols/issues/16

0 commit comments

Comments
 (0)