Skip to content

Commit

Permalink
Add Typescript definitions for 'create-emotion-server' and 'emotion-s…
Browse files Browse the repository at this point in the history
…erver'
  • Loading branch information
mgroenhoff committed May 29, 2018
1 parent d9a9e33 commit 45c8dff
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 6 deletions.
11 changes: 8 additions & 3 deletions packages/create-emotion-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
"version": "9.1.3",
"description": "SSR and style extraction tooling for emotion, The Next Generation of CSS-in-JS.",
"main": "lib/index.js",
"types": "types/index.d.ts",
"files": [
"src",
"lib"
"lib",
"types"
],
"scripts": {
"build": "npm-run-all clean babel",
"babel": "babel src -d lib",
"watch": "babel src -d lib --watch",
"clean": "rimraf lib"
"clean": "rimraf lib",
"test:typescript": "dtslint types",
"watch": "babel src -d lib --watch"
},
"dependencies": {
"html-tokenize": "^2.0.0",
"multipipe": "^1.0.2",
"through": "^2.3.8"
},
"devDependencies": {
"@types/node": "*",
"babel-cli": "^6.24.1",
"dtslint": "^0.3.0",
"emotion": "^9.1.3",
"npm-run-all": "^4.0.2",
"react-emotion": "^9.1.3",
Expand Down
12 changes: 12 additions & 0 deletions packages/create-emotion-server/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="node" />
// TypeScript Version: 2.3

import { Emotion } from 'create-emotion';

export interface EmotionServer {
extractCritical(html: string): { html: string; ids: string[]; css: string; };
renderStylesToString(html: string): string;
renderStylesToNodeStream(): NodeJS.ReadWriteStream;
}

export default function createEmotionServer(emotion: Emotion): EmotionServer;
15 changes: 15 additions & 0 deletions packages/create-emotion-server/types/tests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Emotion } from 'create-emotion';

import createEmotionServer from '../';

declare const emotion: Emotion;

const emotionServer = createEmotionServer(emotion);

const { html, css, ids } = emotionServer.extractCritical("<div></div>");

emotionServer.renderStylesToString("<div></div>");

declare const stream: NodeJS.ReadableStream;

stream.pipe(emotionServer.renderStylesToNodeStream());
26 changes: 26 additions & 0 deletions packages/create-emotion-server/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"baseUrl": "../",
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": [
"es6"
],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"target": "es5",
"typeRoots": [
"../"
],
"types": []
},
"include": [
"./*.ts",
"./*.tsx"
]
}
6 changes: 6 additions & 0 deletions packages/create-emotion-server/types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-relative-import-in-test": false
}
}
11 changes: 8 additions & 3 deletions packages/emotion-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
"version": "9.1.3",
"description": "Extract and inline critical css with emotion for server side rendering.",
"main": "lib/index.js",
"types": "types/index.d.ts",
"files": [
"src",
"lib"
"lib",
"types"
],
"scripts": {
"build": "npm-run-all clean babel",
"babel": "babel src -d lib",
"watch": "babel src -d lib --watch",
"clean": "rimraf lib"
"clean": "rimraf lib",
"test:typescript": "dtslint types",
"watch": "babel src -d lib --watch"
},
"dependencies": {
"create-emotion-server": "^9.1.3"
Expand All @@ -20,8 +23,10 @@
"emotion": "^9.1.3"
},
"devDependencies": {
"@types/react-dom": "16.0.5",
"babel-cli": "^6.24.1",
"babel-plugin-emotion": "^9.1.2",
"dtslint": "^0.3.0",
"emotion": "^9.1.3",
"npm-run-all": "^4.0.2",
"react-emotion": "^9.1.3",
Expand Down
7 changes: 7 additions & 0 deletions packages/emotion-server/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// TypeScript Version: 2.3

import { EmotionServer } from 'create-emotion-server';

export const renderStylesToString: EmotionServer["renderStylesToString"];
export const renderStylesToNodeStream: EmotionServer["renderStylesToNodeStream"];
export const extractCritical: EmotionServer["extractCritical"];
11 changes: 11 additions & 0 deletions packages/emotion-server/types/tests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { renderToNodeStream, renderToString } from 'react-dom/server';
import { extractCritical, renderStylesToNodeStream, renderStylesToString } from '../';

declare const element: React.ReactElement<any>;

const { html, css, ids } = extractCritical(renderToString(element));

renderStylesToString(renderToString(element));

renderToNodeStream(element).pipe(renderStylesToNodeStream());
27 changes: 27 additions & 0 deletions packages/emotion-server/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"baseUrl": "../",
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": [
"es6"
],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"target": "es5",
"typeRoots": [
"../"
],
"types": []
},
"include": [
"./*.ts",
"./*.tsx"
]
}
6 changes: 6 additions & 0 deletions packages/emotion-server/types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-relative-import-in-test": false
}
}

0 comments on commit 45c8dff

Please sign in to comment.