Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Typescript definitions for 'create-emotion-server' and 'emotion-server' #692

Merged
merged 6 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should depend on @types/react-dom as dependencies, or, at least as peerDependencies, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only use is inside the tests so I don't think it should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgroenhoff Oh, you're right. My miss.

"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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You miss the final linefeeding for this file

Copy link
Contributor Author

@mgroenhoff mgroenhoff Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many more tslint.json files without this line feed. Do you want me to add them to those as well?
Edit: I went ahead and did it anyway

7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,13 @@
version "1.6.2"
resolved "https://registry.yarnpkg.com/@types/parsimmon/-/parsimmon-1.6.2.tgz#2ecb8424e06fd8db78b6f697b635064dfa355441"

"@types/react-dom@16.0.5":
version "16.0.5"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.0.5.tgz#a757457662e3819409229e8f86795ff37b371f96"
dependencies:
"@types/node" "*"
"@types/react" "*"

"@types/react-router-dom@^4.2.2":
version "4.2.6"
resolved "https://registry.yarnpkg.com/@types/react-router-dom/-/react-router-dom-4.2.6.tgz#9f7eb3c0e6661a9607d878ff8675cc4ea95cd276"
Expand Down