Skip to content

Commit

Permalink
feat(core): adds support for Intl.RelativeTimeFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Jan 14, 2019
1 parent f5a8957 commit 749bef9
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 55 deletions.
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@wessberg/rollup-plugin-ts": "1.1.17",
"@wessberg/scaffold": "^1.0.5",
"@wessberg/ts-config": "^0.0.34",
"rollup": "^1.1.0",
"standard-changelog": "^2.0.6",
"tslint": "^5.12.1",
"typescript": "^3.2.2",
Expand All @@ -63,6 +62,7 @@
"@babel/preset-stage-3": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@types/file-type": "^10.6.0",
"@types/astring": "^1.3.0",
"@types/iltorb": "^2.3.0",
"@types/memory-fs": "^0.3.2",
"@types/mime": "^2.0.0",
Expand All @@ -72,14 +72,15 @@
"@webcomponents/shadycss": "^1.8.0",
"@webcomponents/shadydom": "^1.4.1",
"@webcomponents/template": "^1.4.0",
"@wessberg/browserslist-generator": "1.0.2",
"@wessberg/browserslist-generator": "1.0.3",
"@wessberg/di": "^2.0.3",
"@wessberg/fileloader": "^1.1.9",
"@wessberg/filesaver": "^1.0.8",
"@wessberg/pointer-events": "^1.0.8",
"@wessberg/stringutil": "^1.0.18",
"Base64": "^1.0.1",
"ava": "^1.0.1",
"astring": "^1.3.1",
"ava": "^1.1.0",
"blob-polyfill": "^3.0.20180112",
"chalk": "^2.4.2",
"console-polyfill": "^0.3.0",
Expand All @@ -92,6 +93,7 @@
"iltorb": "^2.4.1",
"intersection-observer": "^0.5.1",
"intl": "^1.2.5",
"intl-relative-time-format": "^1.0.0",
"memory-fs": "^0.4.1",
"mime": "^2.4.0",
"mutationobserver-shim": "^0.3.2",
Expand All @@ -105,10 +107,14 @@
"requestanimationframe": "0.0.23",
"requestidlecallback": "^0.3.0",
"resize-observer": "^1.0.0",
"rollup": "^1.1.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-multi-entry": "^2.1.0",
"scroll-behavior-polyfill": "^2.0.3",
"semver": "^5.6.0",
"setimmediate": "^1.0.5",
"systemjs": "^2.1.1",
"systemjs": "^3.0.0",
"temp-dir": "^1.0.0",
"toposort": "^2.0.2",
"tslib": "^1.9.3",
Expand Down
1 change: 1 addition & 0 deletions src/bl/polyfill/polyfill-bl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class PolyfillBl implements IPolyfillBl {
.filter(feature => feature.name in constant.polyfill)),
request.userAgent
);

// Store them within the cache
await this.cacheRegistry.setPolyfillFeatureSet(request.features, featureSet, request.userAgent);
} else {
Expand Down
33 changes: 32 additions & 1 deletion src/constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ export const constant: IConstant = {
},
"es.set.add-all": {
library: "core-js",
relativePaths: ["modules/esnext.set.add-all.js"],
relativePaths: ["modules/esnext.set.addTime-all.js"],
// TODO: Update when MDN or Caniuse Compatibility is added
features: [],
version: environment.NPM_PACKAGE_DEPENDENCIES_CORE_JS,
Expand Down Expand Up @@ -2385,6 +2385,14 @@ export const constant: IConstant = {
dependencies: ["es.array.for-each", "es.object.get-own-property-names", "es.promise", "xhr"]
},
intl: {
polyfills: [
"intl.core",
"intl.relative-time-format"
// TODO: Add Intl.ListFormat
/*, "intl.list-format" */
]
},
"intl.core": {
library: "intl",
relativePaths: ["dist/Intl.min.js"],
meta: {
Expand All @@ -2394,6 +2402,29 @@ export const constant: IConstant = {
version: environment.NPM_PACKAGE_DEPENDENCIES_INTL,
dependencies: []
},
"intl.relative-time-format": {
library: "intl-relative-time-format",
relativePaths: [
"dist/index.js"
],
meta: {
localeDir: "locale-data"
},
features: [
"javascript.builtins.Intl.RelativeTimeFormat"
],
version: environment.NPM_PACKAGE_DEPENDENCIES_INTL_RELATIVE_TIME_FORMAT,
dependencies: [
"intl.core",
"es.array.includes",
"es.object.create",
"es.object.is",
"es.string.includes",
"es.string.replace",
"es.symbol.to-string-tag",
"es.weak-map"
]
},
animation: {
library: "web-animations-js",
relativePaths: ["web-animations.min.js"],
Expand Down
1 change: 1 addition & 0 deletions src/environment/environment-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const environmentDefaults = {
NPM_PACKAGE_DEPENDENCIES_EVENTS_POLYFILL: "",
NPM_PACKAGE_DEPENDENCIES_MUTATIONOBSERVER_SHIM: "",
NPM_PACKAGE_DEPENDENCIES_INTL: "",
NPM_PACKAGE_DEPENDENCIES_INTL_RELATIVE_TIME_FORMAT: "",
NPM_PACKAGE_DEPENDENCIES__WEBCOMPONENTS_CUSTOM_ELEMENTS: "",
NPM_PACKAGE_DEPENDENCIES__WESSBERG_POINTER_EVENTS: "",
NPM_PACKAGE_DEPENDENCIES_CORE_JS: "",
Expand Down
1 change: 1 addition & 0 deletions src/polyfill/polyfill-dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IPolyfillDictEntryBase {
version: string;
dependencies: PolyfillName[];
mustComeAfter?: PolyfillName[]|"*";
flatten?: boolean;
}

export interface IPolyfillLibraryDictEntry extends IPolyfillDictEntryBase {
Expand Down
7 changes: 5 additions & 2 deletions src/polyfill/polyfill-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export declare type PolyfillName = PolyfillDealiasedName
|"esnext.weak-set"
|"event"
|"dom.collections.iterable"
|"web-components";
|"web-components"
|"intl";

export declare type PolyfillDealiasedName =
|"es.object.assign"
Expand Down Expand Up @@ -296,7 +297,9 @@ export declare type PolyfillDealiasedName =
|"dom.collections.iterator"
|"dom.collections.for-each"
|"fetch"
|"intl"
|"intl.core"
|"intl.relative-time-format"
// |"intl.list-format"
|"animation"
|"proxy"
|"window"
Expand Down
73 changes: 73 additions & 0 deletions src/service/flattener/flattener-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {IFlattenerService} from "./i-flattener-service";
import {IFlattenerOptions} from "./i-flattener-options";
import {generate} from "astring";
import {rollup} from "rollup";
// @ts-ignore
import commonjs from "rollup-plugin-commonjs";
// @ts-ignore
import nodeResolve from "rollup-plugin-node-resolve";
// @ts-ignore
import multiEntry from "rollup-plugin-multi-entry";

/**
* A service that can flatten the given code into a single file
*/
export class FlattenerService implements IFlattenerService {

/**
* Flattens the given code into a single file based on the given options
* @param {IFlattenerOptions} options
* @return {Promise<string>}
*/
public async flatten ({path, transform}: IFlattenerOptions): Promise<string> {
const paths = Array.isArray(path) ? path : [path];
if (paths.length < 1) return "";

const bundle = await rollup({
input: paths,
context: "this",
plugins: [
multiEntry(),
{
name: "transformer",
transform (code: string, id: string) {
if (transform == null) return;

const result = transform.call(this, code, id);
if (result == null) return result;

return {
code: generate(result),
map: {mappings: ""}
};
}
},
nodeResolve({
module: true,
jsnext: true
}),
commonjs()
]
});

const bundleSet = await bundle.generate({
format: "iife",
name: paths[0],
sourcemap: false
});

// Produce a flattened bundle
let flattened = bundleSet.output
.map(file => file.code)
.join("\n");

// If the IIFE is named, make sure to remove its outer declaration. We only care about the side-effects
const indexOfIife = flattened.indexOf("(function");
if (indexOfIife >= 0) {
flattened = flattened.slice(indexOfIife);
}

return flattened;
}

}
6 changes: 6 additions & 0 deletions src/service/flattener/i-flattener-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {TransformSourceDescription} from "rollup";

export interface IFlattenerOptions {
path: string[]|string;
transform? (code: string, id: string): TransformSourceDescription["ast"]|void;
}
5 changes: 5 additions & 0 deletions src/service/flattener/i-flattener-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {IFlattenerOptions} from "./i-flattener-options";

export interface IFlattenerService {
flatten (options: IFlattenerOptions): Promise<string>;
}
Loading

0 comments on commit 749bef9

Please sign in to comment.