defense-of-dot-js icon indicating copy to clipboard operation
defense-of-dot-js copied to clipboard

Possible problems with transpiling into the project root

Open mariusGundersen opened this issue 8 years ago • 4 comments

One potential problem with the described system for poly-packages is that they will have to point their transpilation output to the source of the project. This makes it slightly more difficult to gitignore and clean up built files, since they will now have to be specified directly. When the build output is inside a folder, then the entire folder can be cleaned and gitignored. With this proposal other js files that are in the root (like index.js, test.js, etc) will have to be handled. Maybe not the biggest issue.

mariusGundersen avatar Apr 27 '16 13:04 mariusGundersen

@mariusGundersen this not really a problem, and there is few ways you can mitigate this problem. Considering that those files in the root are really describing the API of the CJS, you can have them as single liners to another folder, e.g.:

/foo.js

module.exports = require('./cjs/foo.js');

where ./cjs/foo.js will be produced from ./lib/foo.js. In which case you can ignore the entire cjs/ folder which is the transpiled version of ./lib.

Again, this is an edge case where you have a popular pkg that uses files in the root folder as part of their external api.

caridy avatar Apr 27 '16 13:04 caridy

I would also add that it wouldn't be too hard to write a script that periodically syncs .gitignore with the contents of the module root.

It's also possible to build the npm package in a tmpdir rather than in the same directory you use for development, which lets that directory get as "messy" as the final package needs.

wycats avatar Apr 27 '16 16:04 wycats

Can be handled fairly easily to allow for expansion of the api with a oddly defined .gitignore:

*
!.gitignore
!pakage.json
!module.js
!lib/*

This would allow to add whatever want to lib/ and you wouldn't have to update the .gitignore. You may want to add !.jshint or other various dot files to the exception list, but those are usually fewer in number and not subject to much change.

robbiespeed avatar May 13 '16 03:05 robbiespeed

You could also easily build the package in a subfolder (like build) & copy es6 modules in it + a package.json and then publish from the build folder.

Now you just have to ignore the build folder in your .gitignore and make the default project have only a module in your main package.json.

It would also make dropping CommonJS super easy. Just remove the build system and start publishing from your root folder as you had done in the past.

qraynaud avatar Jun 16 '16 19:06 qraynaud