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

adding ts support #16

Merged
merged 12 commits into from
Jan 22, 2018
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
.DS_Store
*.log
.rpt2_cache
build
dist
package-lock.json
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",
"lint": "eslint src",
"test:build": "node dist/cli.js --no-compress --cwd test/demo",
"test": "npm run -s lint && npm run -s build && npm run -s test:build",
"test:build:ts": "node dist/cli.js --no-compress --cwd test/ts-demo --entry=src/index.ts",
"test": "npm run -s lint && npm run -s build && npm run -s test:build && npm run -s test:build:ts",
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
},
"repository": "developit/microbundle",
Expand Down Expand Up @@ -54,9 +55,11 @@
"rollup-plugin-postcss": "^1.1.0",
"rollup-plugin-preserve-shebang": "^0.1.4",
"rollup-plugin-sizes": "^0.4.2",
"rollup-plugin-typescript": "^0.8.1",
"rollup-plugin-strict-alias": "^1.0.0",
"rollup-plugin-uglify": "^2.0.1",
"sade": "^1.3.1",
"typescript": "^2.6.2",
"uglify-es": "^3.3.6"
},
"devDependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { resolve, relative, dirname, basename } from 'path';
import { resolve, relative, dirname, basename, extname } from 'path';
import chalk from 'chalk';
import { map, series } from 'asyncro';
import promisify from 'es6-promisify';
Expand All @@ -17,6 +17,7 @@ import gzipSize from 'gzip-size';
import prettyBytes from 'pretty-bytes';
import shebangPlugin from 'rollup-plugin-preserve-shebang';
import flow from 'rollup-plugin-flow';
import typescript from 'rollup-plugin-typescript';
import camelCase from 'camelcase';

const interopRequire = m => m.default || m;
Expand Down Expand Up @@ -186,6 +187,8 @@ function createConfig(options, entry, format, writeMeta) {
catch (e) {}
}

const useTypescript = extname(entry)==='.ts';

let config = {
inputOptions: {
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
Expand All @@ -202,7 +205,8 @@ function createConfig(options, entry, format, writeMeta) {
inject: false,
extract: !!writeMeta
}),
flow({ all: true }),
useTypescript && typescript(),
!useTypescript && flow({ all: true }),
nodent({
exclude: 'node_modules/**',
noRuntime: true,
Expand All @@ -216,7 +220,7 @@ function createConfig(options, entry, format, writeMeta) {
}
}
}),
buble({
!useTypescript && buble({
exclude: 'node_modules/**',
jsx: options.jsx || 'h',
objectAssign: options.assign || 'Object.assign',
Expand Down
2 changes: 1 addition & 1 deletion test/demo/src/two.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export async function two(...args) {
return args.reduce( (total, value) => total + value, 0);
}
}
3 changes: 3 additions & 0 deletions test/ts-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "ts-demo"
}
9 changes: 9 additions & 0 deletions test/ts-demo/src/car.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface Driveable {
drive(distance: number): boolean;
}

export default class Car implements Driveable {
public drive(distance: number): boolean {
return true;
}
}
5 changes: 5 additions & 0 deletions test/ts-demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Car from './car';

let Ferrari = new Car();

export default Ferrari;