Skip to content

Commit

Permalink
chore: migrate babel/src to TS (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Feb 9, 2020
1 parent 64495cb commit d3e11d2
Show file tree
Hide file tree
Showing 30 changed files with 1,683 additions and 1,126 deletions.
22 changes: 19 additions & 3 deletions .eslintrc
@@ -1,8 +1,24 @@
{
"extends": "@callstack",
"rules": {
"global-require": "off",
"react-native/no-raw-text": "off",
"react-native/no-inline-styles": "off"
"global-require": "off",
"react-native/no-raw-text": "off",
"react-native/no-inline-styles": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"**/*.test.{js,ts,jsx,tsx}",
"src/{babel,server}/**/*.{js,ts,jsx,tsx}"
]
}
]
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
4 changes: 4 additions & 0 deletions .prettierrc
@@ -0,0 +1,4 @@
{
"trailingComma": "es5",
"singleQuote": true
}
24 changes: 15 additions & 9 deletions package.json
Expand Up @@ -34,7 +34,7 @@
],
"scripts": {
"lint": "eslint --ext .js,.ts,.tsx .",
"typecheck": "tsc && flow",
"typecheck": "tsc --noEmit && flow",
"typescript": "dtslint",
"test": "jest",
"add-contributor": "all-contributors add",
Expand All @@ -59,8 +59,12 @@
"@callstack/eslint-config": "^4.1.0",
"@commitlint/config-conventional": "^7.5.0",
"@release-it/conventional-changelog": "^1.0.2",
"@types/react": "^16.8.4",
"@typescript-eslint/eslint-plugin": "^1.5.0",
"@types/cosmiconfig": "^5.0.3",
"@types/dedent": "^0.7.0",
"@types/jest": "^24.0.11",
"@types/react": "^16.8.12",
"@types/react-is": "^16.7.1",
"@typescript-eslint/eslint-plugin": "^1.6.0",
"all-contributors-cli": "^6.1.1",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.5.0",
Expand All @@ -73,20 +77,21 @@
"flow-bin": "^0.94.0",
"flow-copy-source": "^2.0.3",
"husky": "^1.3.1",
"jest": "^24.5.0",
"jest": "^24.7.1",
"prettier": "^1.16.4",
"react": "^16.8.3",
"react-test-renderer": "^16.8.3",
"release-it": "^12.2.0",
"typescript": "^3.3.4000"
"typescript": "^3.4.1"
},
"dependencies": {
"@babel/core": "^7.3.3",
"@babel/generator": "^7.3.3",
"@babel/core": "^7.4.3",
"@babel/generator": "^7.4.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/register": "^7.0.0",
"@babel/register": "^7.4.0",
"@babel/traverse": "^7.4.3",
"@emotion/is-prop-valid": "^0.7.3",
"core-js": "^3.6.3",
"cosmiconfig": "^5.1.0",
Expand All @@ -106,7 +111,8 @@
"yargs": "^13.2.1"
},
"resolutions": {
"**/babel-core": "7.0.0-bridge.0"
"**/babel-core": "7.0.0-bridge.0",
"@types/react": "^16.8.12"
},
"husky": {
"hooks": {
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/__snapshots__/babel.test.js.snap
Expand Up @@ -413,6 +413,9 @@ Dependencies: NA
exports[`transpiles styled template literal with function and component 1`] = `
"import { styled } from 'linaria/react';
const Heading = () => null;
export const Title =
/*#__PURE__*/
styled(Heading)({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/__snapshots__/preval.test.js.snap
Expand Up @@ -183,7 +183,7 @@ Dependencies: ../slugify
exports[`evaluates expressions with expressions depending on shared dependency 1`] = `
"import { styled } from 'linaria/react';
const slugify = require('../slugify');
const slugify = require('../slugify').default;
const boo = t => slugify(t) + 'boo';
Expand Down Expand Up @@ -304,7 +304,7 @@ Dependencies: NA
exports[`evaluates multiple expressions with shared dependency 1`] = `
"import { styled } from 'linaria/react';
const slugify = require('../slugify');
const slugify = require('../slugify').default;
const boo = t => slugify(t) + 'boo';
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/babel.test.js
Expand Up @@ -51,6 +51,7 @@ it('transpiles styled template literal with function and component', async () =>
const { code, metadata } = await transpile(
dedent`
import { styled } from 'linaria/react';
const Heading = () => null;
export const Title = styled(Heading)\`
font-size: 14px;
Expand Down
26 changes: 13 additions & 13 deletions src/__tests__/preval.test.js
@@ -1,11 +1,11 @@
/* eslint-disable no-template-curly-in-string */
/* @flow */

const path = require('path');
const babel = require('@babel/core');
const dedent = require('dedent');
const stripAnsi = require('strip-ansi');
const serializer = require('../__utils__/linaria-snapshot-serializer');
import * as babel from '@babel/core';
import dedent from 'dedent';
import { join, resolve } from 'path';
import stripAnsi from 'strip-ansi';

import serializer from '../__utils__/linaria-snapshot-serializer';

expect.addSnapshotSerializer(serializer);

Expand All @@ -19,7 +19,7 @@ const babelrc = {
const transpile = async input => {
const { code, metadata } = await babel.transformAsync(input, {
...babelrc,
filename: path.join(__dirname, 'source.js'),
filename: join(__dirname, 'source.js'),
});

// The slug will be machine specific, so replace it with a consistent one
Expand Down Expand Up @@ -113,7 +113,7 @@ it('evaluates expressions with expressions depending on shared dependency', asyn
const { code, metadata } = await transpile(
dedent`
import { styled } from 'linaria/react';
const slugify = require('../slugify');
const slugify = require('../slugify').default;
const boo = t => slugify(t) + 'boo';
const bar = t => slugify(t) + 'bar';
Expand All @@ -134,7 +134,7 @@ it('evaluates multiple expressions with shared dependency', async () => {
const { code, metadata } = await transpile(
dedent`
import { styled } from 'linaria/react';
const slugify = require('../slugify');
const slugify = require('../slugify').default;
const boo = t => slugify(t) + 'boo';
const bar = t => slugify(t) + 'bar';
Expand Down Expand Up @@ -416,7 +416,7 @@ it('throws codeframe error when evaluation fails', async () => {

it('handles escapes properly', async () => {
const { code, metadata } = await babel.transformFileAsync(
path.resolve(__dirname, '../__fixtures__/escape-character.js'),
resolve(__dirname, '../__fixtures__/escape-character.js'),
babelrc
);

Expand All @@ -435,7 +435,7 @@ it('derives display name from filename', async () => {
`,
{
...babelrc,
filename: path.join(__dirname, 'FancyName.js'),
filename: join(__dirname, 'FancyName.js'),
}
);

Expand All @@ -454,7 +454,7 @@ it('derives display name from parent folder name', async () => {
`,
{
...babelrc,
filename: path.join(__dirname, 'FancyName/index.js'),
filename: join(__dirname, 'FancyName/index.js'),
}
);

Expand All @@ -476,7 +476,7 @@ it("throws if couldn't determine a display name", async () => {
`,
{
...babelrc,
filename: path.join(__dirname, '/.js'),
filename: join(__dirname, '/.js'),
}
);
} catch (e) {
Expand Down

0 comments on commit d3e11d2

Please sign in to comment.