Skip to content

Commit

Permalink
chore: distribute commonjs, ES module, and type declaration files (#83)
Browse files Browse the repository at this point in the history
This commit changes the distributable file format in the following ways:
- unbundles both the commonjs and ES module files from one file each to one for each original file for each format
- includes `.d.ts` files for each original source file
- adds `types` field to `package.json` per https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
- removes rollup as the dist builder and uses a wrapper, `script/build`, that uses `tsc` directly
- removes `coffee-lex.js.flow`

I don't like that I had to write a custom build script for this. It makes me feel like I'm doing something incorrectly to support both commonjs and ES modules. I removed rollup because it didn't seem to play well with TypeScript from a publishing perspective. Specifically, I couldn't find any way to automatically build a `d.ts` file for the project bundle generated by rollup that didn't have serious shortcomings (https://github.com/rollup/rollup-plugin-typescript/issues/54). I considered keeping the bundled `.js` and `.mjs` files and using multiple `.d.ts` files, but there didn't seem to be much benefit over simply leaving all of them split up. Other rollup-based projects can still efficiently bundle coffee-lex with the modules split out as separate files.
  • Loading branch information
eventualbuddha authored Dec 13, 2016
1 parent b45b4ec commit f052d2b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 240 deletions.
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "coffee-lex",
"description": "Stupid lexer for CoffeeScript.",
"main": "dist/coffee-lex.js",
"module": "dist/coffee-lex.mjs",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"prebuild": "rm -rf dist/",
"build": "rollup -c && cp src/coffee-lex.js.flow dist/",
"build": "./script/build",
"lint": "tslint --config tslint.json --project tsconfig.json --type-check",
"lint-fix": "tslint --config tslint.json --project tsconfig.json --type-check --fix",
"pretest": "npm run lint",
Expand Down Expand Up @@ -37,9 +38,6 @@
"@types/node": "^6.0.51",
"decaffeinate-coffeescript": "^1.10.0-patch5",
"mocha": "^3.2.0",
"reify": "^0.4.4",
"rollup": "^0.37.0",
"rollup-plugin-typescript": "^0.8.1",
"semantic-release": "^6.3.2",
"ts-node": "^1.7.2",
"tslint": "^4.0.2",
Expand Down
21 changes: 0 additions & 21 deletions rollup.config.js

This file was deleted.

20 changes: 20 additions & 0 deletions script/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -e

DIST="${DIST:-dist}"
TSC="${TSC:-node_modules/.bin/tsc}"

# Build ES module version.
"${TSC}" --project . --outDir "${DIST}" --module ES6
for js in $(find "${DIST}" -name '*.js'); do
mv "${js}" "$(dirname "${js}")/$(basename "${js}" .js).mjs"
done

# Build CommonJS version.
"${TSC}" --project . --outDir "${DIST}" --module commonjs

# Restructure.
rm -rf dist/test
mv dist/src/* dist/
rmdir dist/src
211 changes: 0 additions & 211 deletions src/coffee-lex.js.flow

This file was deleted.

9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"experimentalDecorators": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"noEmit": true
}
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules",
"dist/**/*"
]
}

0 comments on commit f052d2b

Please sign in to comment.