Skip to content

Commit

Permalink
fix: update relative paths for some polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Mar 4, 2020
1 parent 9e28a6c commit d1e09a1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
1 change: 1 addition & 0 deletions rollup.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
plugins: [
ts({
tsconfig: "tsconfig.json",
transpileOnly: true,
transformers: [di]
})
],
Expand Down
31 changes: 15 additions & 16 deletions src/constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2836,15 +2836,15 @@ export const constant: IConstant = {
},
queryselector: {
library: "polyfill-library",
relativePaths: ["polyfills/document/querySelector/polyfill.js"],
relativePaths: ["polyfills/__dist/document.querySelector/min.js"],
features: ["queryselector"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["element", "document", "document-fragment"],
contexts: WINDOW_CONTEXT
},
"document-fragment": {
library: "polyfill-library",
relativePaths: ["polyfills/DocumentFragment/polyfill.js"],
relativePaths: ["polyfills/__dist/DocumentFragment/min.js"],
features: ["queryselector"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: [],
Expand All @@ -2869,7 +2869,7 @@ export const constant: IConstant = {
},
"node.contains": {
library: "polyfill-library",
relativePaths: ["polyfills/Node/prototype/contains/polyfill.js"],
relativePaths: ["polyfills/__dist/Node.prototype.contains/min.js"],
// If 'addEventListener' isn't found, the Window interface shouldn't exist on the window
features: ["addeventlistener"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
Expand All @@ -2878,16 +2878,15 @@ export const constant: IConstant = {
},
window: {
library: "polyfill-library",
relativePaths: ["polyfills/Window/polyfill.js"],

relativePaths: ["polyfills/__dist/Window/min.js"],
features: ["addeventlistener"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: [],
contexts: WINDOW_CONTEXT
},
document: {
library: "polyfill-library",
relativePaths: ["polyfills/document/polyfill.js"],
relativePaths: ["polyfills/__dist/document/min.js"],
// If 'addEventListener' isn't found, the Document interface shouldn't exist on the window
features: ["addeventlistener"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
Expand All @@ -2896,23 +2895,23 @@ export const constant: IConstant = {
},
"class-list": {
library: "polyfill-library",
relativePaths: ["polyfills/Element/prototype/classList/polyfill.js"],
relativePaths: ["polyfills/__dist/Element.prototype.classList/min.js"],
features: ["classlist"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["dom-token-list"],
contexts: WINDOW_CONTEXT
},
"dom-token-list": {
library: "polyfill-library",
relativePaths: ["polyfills/_DOMTokenList/polyfill.js", "polyfills/DOMTokenList/polyfill.js"],
relativePaths: ["polyfills/__dist/_DOMTokenList/min.js", "polyfills/__dist/DOMTokenList/min.js"],
features: ["rellist"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["es.object.define-property"],
contexts: WINDOW_CONTEXT
},
element: {
library: "polyfill-library",
relativePaths: ["polyfills/Element/polyfill.js"],
relativePaths: ["polyfills/__dist/Element/min.js"],
// If 'addEventListener' isn't found, the Element interface shouldn't exist on the window
features: ["addeventlistener"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
Expand All @@ -2924,47 +2923,47 @@ export const constant: IConstant = {
},
"event.constructor": {
library: "polyfill-library",
relativePaths: ["polyfills/Event/polyfill.js"],
relativePaths: ["polyfills/__dist/Event/min.js"],
features: ["api.Event.Event"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["window", "document", "element", "es.object.define-property"],
contexts: WINDOW_CONTEXT
},
"event.focusin": {
library: "polyfill-library",
relativePaths: ["polyfills/Event/focusin/polyfill.js"],
relativePaths: ["polyfills/__dist/Event.focusin/min.js"],
features: ["focusin-focusout-events"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["event.constructor"],
contexts: WINDOW_CONTEXT
},
"event.hashchange": {
library: "polyfill-library",
relativePaths: ["polyfills/Event/hashchange/polyfill.js"],
relativePaths: ["polyfills/__dist/Event.hashchange/min.js"],
features: ["hashchange"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["event.constructor"],
contexts: WINDOW_CONTEXT
},
"custom-event": {
library: "polyfill-library",
relativePaths: ["polyfills/CustomEvent/polyfill.js"],
relativePaths: ["polyfills/__dist/CustomEvent/min.js"],
features: ["customevent"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["event"],
contexts: WINDOW_CONTEXT
},
"event-source": {
library: "polyfill-library",
relativePaths: ["polyfills/EventSource/polyfill.js"],
relativePaths: ["polyfills/__dist/EventSource/min.js"],
features: ["eventsource"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: [],
contexts: WINDOW_CONTEXT
},
"get-computed-style": {
library: "polyfill-library",
relativePaths: ["polyfills/getComputedStyle/polyfill.js"],
relativePaths: ["polyfills/__dist/getComputedStyle/min.js"],
features: ["getcomputedstyle"],
version: environment.NPM_PACKAGE_DEPENDENCIES_POLYFILL_LIBRARY,
dependencies: ["window"],
Expand Down Expand Up @@ -3031,7 +3030,7 @@ export const constant: IConstant = {
},
"constructable-style-sheets": {
library: "construct-style-sheets-polyfill",
relativePaths: ["adoptedStyleSheets.min.js"],
relativePaths: ["dist/adoptedStyleSheets.js"],
features: ["api.DocumentOrShadowRoot.adoptedStyleSheets"],
version: environment.NPM_PACKAGE_DEPENDENCIES_CONSTRUCT_STYLE_SHEETS_POLYFILL,
dependencies: ["shadow-dom"],
Expand Down
20 changes: 10 additions & 10 deletions src/service/polyfill-builder/polyfill-builder-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedMetaVariantPath != null) {
absolutePaths.push(resolvedMetaVariantPath);
} else {
this.logger.debug(`Unresolved path:`, metaVariantPathInput);
throw new ReferenceError(`Unresolved path: '${metaVariantPathInput}'`);
}
}
}
Expand All @@ -131,7 +131,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedMetaVariantPath != null) {
absolutePaths.push(resolvedMetaVariantPath);
} else {
this.logger.debug(`Unresolved path:`, metaVariantPathInput);
throw new ReferenceError(`Unresolved path: '${metaVariantPathInput}'`);
}
}
}
Expand All @@ -145,7 +145,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedPath != null) {
absolutePaths.push(resolvedPath);
} else {
this.logger.debug(`Unresolved path:`, pathInput);
throw new ReferenceError(`Unresolved path: '${pathInput}'`);
}
}
}
Expand All @@ -159,7 +159,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedErrorPath != null) {
absolutePaths.push(resolvedErrorPath);
} else {
this.logger.debug(`Unresolved path:`, errorPathInput);
throw new ReferenceError(`Unresolved path: '${errorPathInput}'`);
}
}
}
Expand All @@ -173,7 +173,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedShadyDomExtensionPath != null) {
absolutePaths.push(resolvedShadyDomExtensionPath);
} else {
this.logger.debug(`Unresolved path:`, shadyDomExtensionPathInput);
throw new ReferenceError(`Unresolved path: '${shadyDomExtensionPathInput}'`);
}
}
}
Expand All @@ -186,7 +186,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedMediaQueryExtensionPath != null) {
absolutePaths.push(resolvedMediaQueryExtensionPath);
} else {
this.logger.debug(`Unresolved path:`, mediaQueryExtensionPathInput);
throw new ReferenceError(`Unresolved path: '${mediaQueryExtensionPathInput}'`);
}
}
}
Expand All @@ -199,7 +199,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedRxjsExtensionPath != null) {
absolutePaths.push(resolvedRxjsExtensionPath);
} else {
this.logger.debug(`Unresolved path:`, rxjsExtensionPathInput);
throw new ReferenceError(`Unresolved path: '${rxjsExtensionPathInput}'`);
}
}
}
Expand All @@ -212,7 +212,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedFetchExtensionPath != null) {
absolutePaths.push(resolvedFetchExtensionPath);
} else {
this.logger.debug(`Unresolved path:`, fetchExtensionPathInput);
throw new ReferenceError(`Unresolved path: '${fetchExtensionPathInput}'`);
}
}
}
Expand All @@ -225,7 +225,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedResizeObserverExtensionPath != null) {
absolutePaths.push(resolvedResizeObserverExtensionPath);
} else {
this.logger.debug(`Unresolved path:`, resizeObserverExtensionPathInput);
throw new ReferenceError(`Unresolved path: '${resizeObserverExtensionPathInput}'`);
}
}
}
Expand All @@ -246,7 +246,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
if (resolvedLocalePath != null) {
absolutePaths.push(resolvedLocalePath);
} else {
this.logger.debug(`Unresolved path:`, localePathInput);
throw new ReferenceError(`Unresolved path: '${localePathInput}'`);
}
}
})
Expand Down
32 changes: 32 additions & 0 deletions test/server/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {chrome, ie} from "useragent-generator";
import {ContentEncodingKind} from "../../src/encoding/content-encoding-kind";
import {getPolyfillRequestFromUrl} from "../../src/util/polyfill/polyfill-util";
import {URL} from "url";
import {PolyfillDictNormalizedEntry} from "../../src/polyfill/polyfill-dict";

const config = container.get<IConfig>();

Expand Down Expand Up @@ -61,6 +62,37 @@ test("Will not generate polyfills for 'Element' on Chrome 69 for a Galaxy S5", a
t.true(result.statusCode === constants.HTTP_STATUS_OK);
});

test("Is able to generate a bundle of every available polyfill", async t => {
const features = Object.entries(constant.polyfill)
.filter(([, value]) => !("polyfills" in value))
.map(([key, value]) => {
switch (key) {
case "zone":
return `${key}|${Object.keys(((value as unknown) as PolyfillDictNormalizedEntry).meta!).join("|")}|force`;
case "intl.core":
case "intl.list-format":
case "intl.relative-time-format":
return `${key}|locale=en~da|force`;
default:
return `${key}|force`;
}
});

const result = await sendRequest({
http2: config.http2,
tls: true,
userAgent:
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3450.0 Mobile Safari/537.36",
method: "GET",
host: config.host,
port: config.port,
path: `${constant.endpoint.polyfill}?features=${features.join(",")}`,
acceptEncoding: undefined
});

t.true(result.statusCode === constants.HTTP_STATUS_OK);
});

test("Will generate correct polyfills for IE11", async t => {
const result = await sendRequest({
http2: config.http2,
Expand Down

0 comments on commit d1e09a1

Please sign in to comment.