Skip to content

Commit

Permalink
chore: Update to babel 7 + Typescript (#5)
Browse files Browse the repository at this point in the history
#3 Replaced Flow w/ Typescript and as a result removed Babel because TypeScript both transpiles and type checks. However this makes us miss out on a lot of the plugins that are a part of the Babel community. Babel 7 adds support for Typescript.

Use babel 7 to build assets instead of tsc. The tsc command is still used for static type checking. Note that the babel typescript plugin will transpile code regardless of its typecheck correctyness. 

tsc is also still used to generate the declaration files, since it looks as though the babel-typescript-plugin does not support creating those at this time. However there's a "create declaration only" flag that is convenient for this. 

I've excluded the .spec files from the babel build, so now they won't appear in lib. I didn't move the ignore declaration into the .babelrc because I can imagine a situation where we might want to use a cool feature in our test suite that babel can transpile for is (even though node 8 gets us there at the moment). However there's never a need to have the transpiled versions in our lib. 

Lastly, we can now support async await etc with the additions of lib -- es2015 and dom which I think will be especially useful in our tests because most of our exports will likely be functions that return promises.

PS: i'm not tied to the tests, i just want to prove that they work! I'm happy to remove them, as we definitely should in the future, thought it might be nice while we're building the foundation though.

Fixes #4
  • Loading branch information
ryanwholey authored and BenAtEventbrite committed Feb 22, 2018
1 parent 98d06d7 commit 45901bd
Show file tree
Hide file tree
Showing 8 changed files with 1,483 additions and 859 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"presets": [
["@babel/env", {
"targets": {
"browsers": ["last 2 versions"],
"node": "current"
},
"loose": true
}],
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}
12 changes: 0 additions & 12 deletions config/jest-preprocess-typescript.js

This file was deleted.

2 changes: 1 addition & 1 deletion jest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"moduleFileExtensions": ["ts", "js"],
"transform": {
"^.+\\.ts$": "<rootDir>/config/jest-preprocess-typescript.js"
"^.+\\.(ts|js)$": "typescript-babel-jest"
},
"testMatch": ["**/src/**/*.spec.(ts|js)"]
}
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
"bugs": {
"url": "https://github.com/eventbrite/eventbrite-sdk-javascript/issues"
},
"homepage":
"https://github.com/eventbrite/eventbrite-sdk-javascript#readme",
"homepage": "https://github.com/eventbrite/eventbrite-sdk-javascript#readme",
"license": "MIT",
"scripts": {
"check:static": "npm-run-all --parallel lint 'tsc --noEmit'",
"check:static": "npm-run-all --parallel lint tsc",
"format": "prettier-eslint --write",
"lint": "eslint --cache --max-warnings 0 --ext .ts,.js src",
"precommit": "lint-staged",
"test": "jest --config=jest.json",
"test:watch": "yarn test --watch",
"build": "npm-run-all --parallel build:declarations build:transpile",
"build:declarations": "tsc --p ./tsconfig.build.json",
"build:transpile": "babel src --ignore **/*.spec.ts --out-dir lib/cjs --extensions \".ts,.tsx\"",
"tsc": "tsc",
"test:ci": "yarn test --ci",
"validate": "npm-run-all --parallel check:static test:ci"
Expand All @@ -37,7 +39,16 @@
"isomorphic-fetch": "^2.2.1",
"lodash": "^4.17.5"
},
"resolutions": {
"babel-core": "^7.0.0-bridge.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.40",
"@babel/core": "^7.0.0-beta.40",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.40",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"@babel/preset-typescript": "^7.0.0-beta.40",
"@types/isomorphic-fetch": "^0.0.34",
"@types/jest": "^22.1.3",
"@types/lodash": "^4.14.104",
Expand All @@ -47,12 +58,13 @@
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-typescript": "^0.8.1",
"husky": "^0.14.3",
"jest": "^22.3.0",
"jest": "^22.4.0",
"lint-staged": "^6.1.0",
"node": "^8.9.2",
"npm-run-all": "^4.1.2",
"prettier-eslint-cli": "^4.7.1",
"typescript": "^2.7.2",
"typescript-babel-jest": "^1.0.5",
"typescript-eslint-parser": "^14.0.0"
}
}
16 changes: 16 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ describe('configurations', () => {
expect(() => briteRest()).not.toThrow();
});
});

// TODO: remove when build process has stabilized
describe('build functionality', () => {
it('should compile while using async await', async () => {
const result = await new Promise<number>((resolve) => resolve(1));

expect(result).toEqual(1);
});

it('should work with spread operator', () => {
const parent = {first: 1};
const child = {...parent, second: 2};

expect(child).toEqual({first: 1, second: 2});
});
});
12 changes: 12 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./lib",
"emitDeclarationOnly": true,
"noEmit": false
},
"exclude": [
"**/*.spec.ts"
]
}
15 changes: 6 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "./lib/cjs",
"declaration": true,
"noEmitOnError": true,
"noImplicitAny": true
},
"include": ["src/**/*"]
"compilerOptions": {
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"noEmit": true
},
"include": ["src/**/*"]
}
Loading

0 comments on commit 45901bd

Please sign in to comment.