Skip to content

Commit

Permalink
feat(polyfill): adds support for 'globalThis'
Browse files Browse the repository at this point in the history
feat(debug): adds user agent information to request logging
docs(readme): updates README with usage description of the new 'context' feature
docs(readme): updates README with an auto-generated list of all polyfill names, including aliases.
  • Loading branch information
wessberg committed Feb 7, 2019
1 parent 1307877 commit ffb3e0d
Show file tree
Hide file tree
Showing 13 changed files with 650 additions and 411 deletions.
26 changes: 13 additions & 13 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ Our Standards
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

Our Responsibilities
Expand All @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting any of the code of conduct enforcers: [Frederik Wessberg](mailto:frederikwessberg@hotmail.com).
reported by contacting any of the code of conduct enforcers: [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg)).
All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand All @@ -68,4 +68,4 @@ members of the project's leadership.
Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at http://contributor-covenant.org/version/1/4/
available at http://contributor-covenant.org/version/1/4/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ You are more than welcome to contribute to `@wessberg/polyfiller` in any way you
- Fixing issues and suggesting new features
- Blogging, tweeting, and creating tutorials about `@wessberg/polyfiller`
- Reaching out to [@FredWessberg](https://twitter.com/FredWessberg) on Twitter
- Submit an issue or a Pull Request
- Submit an issue or a Pull Request
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © 2019 Frederik Wessberg <frederikwessberg@hotmail.com>
Copyright © 2019 [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
SOFTWARE
904 changes: 546 additions & 358 deletions README.md

Large diffs are not rendered by default.

50 changes: 22 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"scripts": {
"serve": "node ./dist/index.js",
"serve:production": "NODE_ENV=production npm run serve",
"generate:readme": "scaffold readme --blacklist intro",
"generate:license": "scaffold license",
"generate:contributing": "scaffold contributing",
"generate:coc": "scaffold coc",
"generate:readme": "scaffold readme --yes",
"generate:license": "scaffold license --yes",
"generate:contributing": "scaffold contributing --yes",
"generate:coc": "scaffold coc --yes",
"generate:changelog": "standard-changelog --first-release",
"generate:all": "npm run generate:license & npm run generate:contributing & npm run generate:coc & npm run generate:readme & npm run generate:changelog",
"generate:all": "npm run generate:license & npm run generate:contributing & npm run generate:coc & npm run generate:readme && npm run generate:changelog",
"clean:dist": "rm -rf dist",
"clean:compiled": "rm -rf compiled",
"clean": "npm run clean:dist && npm run clean:compiled",
Expand All @@ -26,6 +26,7 @@
"prebuild": "npm run clean:dist",
"build": "npm run rollup",
"rollup": "rollup -c rollup.config.js",
"scripts:markdown-format-feature-names": "ts-node --project scripts/tsconfig.json scripts/markdown-format-feature-names.ts",
"preversion": "npm run lint && NODE_ENV=production npm run build",
"version": "npm run generate:all && git add .",
"postpublish": "npm run deploy",
Expand All @@ -46,14 +47,15 @@
"@wessberg/rollup-plugin-ts": "1.1.28",
"@wessberg/scaffold": "^1.0.13",
"@wessberg/ts-config": "^0.0.39",
"husky": "^1.3.1",
"np": "^4.0.2",
"prettier": "^1.16.4",
"pretty-quick": "^1.10.0",
"standard-changelog": "^2.0.6",
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"useragent-generator": "^1.1.0",
"prettier": "^1.16.4",
"pretty-quick": "^1.10.0",
"husky": "^1.3.1",
"np": "^4.0.2"
"useragent-generator": "^1.1.0"
},
"dependencies": {
"@babel/core": "^7.2.2",
Expand Down Expand Up @@ -134,28 +136,20 @@
"bugs": {
"url": "https://github.com/wessberg/polyfiller/issues"
},
"author": {
"name": "Frederik Wessberg",
"email": "frederikwessberg@hotmail.com",
"url": "https://github.com/wessberg"
},
"contributors": [
{
"name": "Frederik Wessberg",
"email": "frederikwessberg@hotmail.com",
"url": "https://github.com/wessberg",
"imageUrl": "https://avatars2.githubusercontent.com/u/20454213?s=460&v=4",
"role": "Lead Developer",
"twitter": "FredWessberg"
}
],
"engines": {
"node": ">=9.0.0"
},
"license": "MIT",
"scaffold": {
"patreonUserId": "11315442",
"logo": "https://raw.githubusercontent.com/wessberg/Polyfiller/master/documentation/asset/logo-color-text.png",
"contributorMeta": {
"Frederik Wessberg": {
"imageUrl": "https://avatars2.githubusercontent.com/u/20454213?s=460&v=4",
"role": "Maintainer",
"twitterHandle": "FredWessberg",
"isCocEnforcer": true
}
},
"backers": []
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
Expand Down
7 changes: 7 additions & 0 deletions scaffold.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
...require("@wessberg/ts-config/scaffold.config"),
logo: {
url: "https://raw.githubusercontent.com/wessberg/Polyfiller/master/documentation/asset/logo-color-text.png",
height: 80
}
};
29 changes: 29 additions & 0 deletions scripts/markdown-format-feature-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {constant} from "../src/constant/constant";
import {PolyfillName} from "../src/polyfill/polyfill-name";
import {PolyfillDictEntry} from "../src/polyfill/polyfill-dict";

const seenPolyfills: Set<PolyfillName> = new Set();

let formatted = "";

const entries = Object.entries(constant.polyfill) as [PolyfillName, PolyfillDictEntry][];

// Start with listing all aliases as well as the polyfills they alias
for (const [key, value] of entries) {
if ("polyfills" in value) {
seenPolyfills.add(key);
formatted += `- **\`${key}\`**\n`;
value.polyfills.forEach(polyfill => {
seenPolyfills.add(polyfill);
formatted += ` - \`${polyfill}\`\n`;
});
}
}

// Go another round, but this time only list those polyfills that hasn't been seen yet (and isn't aliases)
for (const [key, value] of entries) {
if ("polyfills" in value || seenPolyfills.has(key)) continue;
formatted += `- \`${key}\`\n`;
}

console.log(formatted);
7 changes: 7 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@wessberg/ts-config",
"compilerOptions": {
"target": "es2017",
"module": "commonjs"
}
}
13 changes: 12 additions & 1 deletion src/constant/constant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IConstant} from "./i-constant";
import {environment} from "../environment/environment";
// @ts-ignore
import * as tempDir from "temp-dir";
import tempDir from "temp-dir";
import {join} from "path";
import {ALL_CONTEXTS, WINDOW_CONTEXT, WINDOW_NODE_CONTEXT} from "../polyfill/polyfill-context";

Expand Down Expand Up @@ -2966,6 +2966,17 @@ export const constant: IConstant = {
version: environment.NPM_PACKAGE_DEPENDENCIES_SETIMMEDIATE,
dependencies: [],
contexts: ALL_CONTEXTS
},
globalthis: {
polyfills: ["global-this"]
},
"global-this": {
library: "core-js",
relativePaths: ["modules/esnext.global-this.js"],
features: ["javascript.builtins.globals.globalThis"],
version: environment.NPM_PACKAGE_DEPENDENCIES_CORE_JS,
dependencies: [],
contexts: ALL_CONTEXTS
}
}
};
6 changes: 4 additions & 2 deletions src/polyfill/polyfill-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export declare type PolyfillName =
| "animation"
| "requestanimationframe"
| "requestidlecallback"
| "setimmediate";
| "setimmediate"
| "globalthis";

export declare type PolyfillDealiasedName =
| "es.object.assign"
Expand Down Expand Up @@ -344,4 +345,5 @@ export declare type PolyfillDealiasedName =
| "event-source"
| "pointer-event"
| "set-immediate"
| "web-animations";
| "web-animations"
| "global-this";
7 changes: 3 additions & 4 deletions src/util/request-util/request-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {IOKResponse, Response} from "../../server/i-response";
import chalk from "chalk";
import {connect, ClientHttp2Stream, ClientHttp2Session} from "http2";
import {ContentEncodingKind} from "../../encoding/content-encoding-kind";
import * as URLNamespace from "url";
import {URL} from "url";
import {constant} from "../../constant/constant";
const {URL} = URLNamespace;

// tslint:disable:no-any

Expand Down Expand Up @@ -79,8 +78,8 @@ function paintMethod(method: Request["method"]): string {
* Prints the given request
* @param {IRequest} request
*/
export function printRequest({method, url}: Request): void {
console.log(`${paintMethod(method)} ${url.toString()}`);
export function printRequest({method, url, userAgent}: Request): void {
console.log(`${paintMethod(method)} ${url.toString()} (${chalk.gray(userAgent)})`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/server/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test("Will set a 'x-applied-polyfills' header on HTTP2 responses with a HTTP-fri
method: "GET",
host: config.host,
port: config.port,
path: `${constant.endpoint.polyfill}?features=event,custom-event,zone,es.promise.finally,pointer-event|force,systemjs|variant=system,intl|force|locale=en~da`,
path: `${constant.endpoint.polyfill}?features=event,custom-event,zone,es.promise.finally,pointer-event|force,systemjs|variant=system,intl|force|locale=en~da&context=node`,
acceptEncoding: undefined
});

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "@wessberg/ts-config",
"include": ["src/**/*.*"],
"compilerOptions": {
"target": "es2017"
"target": "es2017",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}

0 comments on commit ffb3e0d

Please sign in to comment.