-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): adds support for Intl.RelativeTimeFormat
- Loading branch information
Showing
15 changed files
with
454 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
Oops, something went wrong.