diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 5fbb5d3f786..cbd69f8d53a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -9,6 +9,7 @@ Search open/closed issues before submitting since someone might have asked the s ### 🎛 Configuration (.babelrc, package.json, cli command) + ```js @@ -18,31 +19,41 @@ Search open/closed issues before submitting since someone might have asked the s ``` ### 🤔 Expected Behavior + + ### 😯 Current Behavior + + + ### 💁 Possible Solution + + ### 🔦 Context + + ### 🌍 Your Environment + -| Software | Version(s) -| ---------------- | ---------- -| Parcel | -| Node | -| npm/Yarn | -| Operating System | +| Software | Version(s) | +| ---------------- | ---------- | +| Parcel | +| Node | +| npm/Yarn | +| Operating System | \ No newline at end of file +👉 https://opencollective.com/parcel/donate --> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 357d881faa1..fb327ce89a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,29 +35,24 @@ yarn test [node]: https://nodejs.org/ [yarn]: https://yarnpkg.com/ - ## Financial contributions We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/parcel). Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed. - ## Credits - ### Contributors Thank you to all the people who have already contributed to parcel! - ### Backers Thank you to all our backers! [[Become a backer](https://opencollective.com/parcel#backer)] - ### Sponsors Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/parcel#sponsor)) @@ -71,4 +66,4 @@ Thank you to all our sponsors! (please ask your company to also support this ope - \ No newline at end of file + diff --git a/README.md b/README.md index f5c19afd3e2..5889dff1ffe 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ ```shell yarn global add parcel-bundler ``` + or with npm: + ```shell npm install -g parcel-bundler ``` @@ -97,14 +99,12 @@ All feedback and suggestions are welcome! This project exists thanks to all the people who contribute. [[Contribute]](CONTRIBUTING.md). - ## Backers Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/parcel#backer)] - ## Sponsors Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/parcel#sponsor)] @@ -120,8 +120,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l - - ## License MIT diff --git a/bin/cli.js b/bin/cli.js old mode 100755 new mode 100644 index ea71832a42b..523bcad4f02 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,104 +1,5 @@ -#!/usr/bin/env node - -require('v8-compile-cache'); -const chalk = require('chalk'); -const program = require('commander'); -const version = require('../package.json').version; - -program.version(version); - -program - .command('serve [input]') - .description('starts a development server') - .option('-p, --port ', 'set the port to serve on. defaults to 1234') - .option('-o, --open', 'automatically open in default browser') - .option( - '-d, --out-dir ', - 'set the output directory. defaults to "dist"' - ) - .option( - '--public-url ', - 'set the public URL to serve on. defaults to the same as the --out-dir option' - ) - .option('--no-hmr', 'disable hot module replacement') - .option('--no-cache', 'disable the filesystem cache') - .option('-V, --version', 'output the version number') - .action(bundle); - -program - .command('watch [input]') - .description('starts the bundler in watch mode') - .option( - '-d, --out-dir ', - 'set the output directory. defaults to "dist"' - ) - .option( - '--public-url ', - 'set the public URL to serve on. defaults to the same as the --out-dir option' - ) - .option('--no-hmr', 'disable hot module replacement') - .option('--no-cache', 'disable the filesystem cache') - .action(bundle); - -program - .command('build [input]') - .description('bundles for production') - .option( - '-d, --out-dir ', - 'set the output directory. defaults to "dist"' - ) - .option( - '--public-url ', - 'set the public URL to serve on. defaults to the same as the --out-dir option' - ) - .option('--no-minify', 'disable minification') - .option('--no-cache', 'disable the filesystem cache') - .action(bundle); - -program - .command('help [command]') - .description('display help information for a command') - .action(function(command) { - let cmd = program.commands.find(c => c.name() === command) || program; - cmd.help(); - }); - -program.on('--help', function() { - console.log(''); - console.log( - ' Run `' + - chalk.bold('parcel help ') + - '` for more information on specific commands' - ); - console.log(''); -}); - -// Make serve the default command -var args = process.argv; -if (!args[2] || !program.commands.some(c => c.name() === args[2])) { - args.splice(2, 0, 'serve'); -} - -program.parse(args); - -async function bundle(main, command) { - // Require bundler here so the help command is fast - const Bundler = require('../'); - - if (command.name() === 'build') { - process.env.NODE_ENV = 'production'; - } else { - process.env.NODE_ENV = process.env.NODE_ENV || 'development'; - } - - const bundler = new Bundler(main, command); - - if (command.name() === 'serve') { - const server = await bundler.serve(command.port || 1234); - if (command.open) { - require('opn')(`http://localhost:${server.address().port}`); - } - } else { - bundler.bundle(); - } -} +// Node 8 supports native async functions - no need to use compiled code! +module.exports = + parseInt(process.versions.node, 10) < 8 + ? require('../lib/cli') + : require('../src/cli'); diff --git a/package.json b/package.json index e6b8c3b2e6d..ea44252a924 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,8 @@ "build": "babel src -d lib", "prepublish": "yarn build", "precommit": "lint-staged", - "postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\"" + "postinstall": + "node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\"" }, "bin": { "parcel": "bin/cli.js" @@ -75,10 +76,7 @@ "node": ">= 6.0.0" }, "lint-staged": { - "*.{js,json,md}": [ - "prettier --write", - "git add" - ] + "*.{js,json,md}": ["prettier --write", "git add"] }, "collective": { "type": "opencollective", diff --git a/src/cli.js b/src/cli.js new file mode 100755 index 00000000000..ea71832a42b --- /dev/null +++ b/src/cli.js @@ -0,0 +1,104 @@ +#!/usr/bin/env node + +require('v8-compile-cache'); +const chalk = require('chalk'); +const program = require('commander'); +const version = require('../package.json').version; + +program.version(version); + +program + .command('serve [input]') + .description('starts a development server') + .option('-p, --port ', 'set the port to serve on. defaults to 1234') + .option('-o, --open', 'automatically open in default browser') + .option( + '-d, --out-dir ', + 'set the output directory. defaults to "dist"' + ) + .option( + '--public-url ', + 'set the public URL to serve on. defaults to the same as the --out-dir option' + ) + .option('--no-hmr', 'disable hot module replacement') + .option('--no-cache', 'disable the filesystem cache') + .option('-V, --version', 'output the version number') + .action(bundle); + +program + .command('watch [input]') + .description('starts the bundler in watch mode') + .option( + '-d, --out-dir ', + 'set the output directory. defaults to "dist"' + ) + .option( + '--public-url ', + 'set the public URL to serve on. defaults to the same as the --out-dir option' + ) + .option('--no-hmr', 'disable hot module replacement') + .option('--no-cache', 'disable the filesystem cache') + .action(bundle); + +program + .command('build [input]') + .description('bundles for production') + .option( + '-d, --out-dir ', + 'set the output directory. defaults to "dist"' + ) + .option( + '--public-url ', + 'set the public URL to serve on. defaults to the same as the --out-dir option' + ) + .option('--no-minify', 'disable minification') + .option('--no-cache', 'disable the filesystem cache') + .action(bundle); + +program + .command('help [command]') + .description('display help information for a command') + .action(function(command) { + let cmd = program.commands.find(c => c.name() === command) || program; + cmd.help(); + }); + +program.on('--help', function() { + console.log(''); + console.log( + ' Run `' + + chalk.bold('parcel help ') + + '` for more information on specific commands' + ); + console.log(''); +}); + +// Make serve the default command +var args = process.argv; +if (!args[2] || !program.commands.some(c => c.name() === args[2])) { + args.splice(2, 0, 'serve'); +} + +program.parse(args); + +async function bundle(main, command) { + // Require bundler here so the help command is fast + const Bundler = require('../'); + + if (command.name() === 'build') { + process.env.NODE_ENV = 'production'; + } else { + process.env.NODE_ENV = process.env.NODE_ENV || 'development'; + } + + const bundler = new Bundler(main, command); + + if (command.name() === 'serve') { + const server = await bundler.serve(command.port || 1234); + if (command.open) { + require('opn')(`http://localhost:${server.address().port}`); + } + } else { + bundler.bundle(); + } +} diff --git a/test/plugins.js b/test/plugins.js index 54e9296787e..142716f960f 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -16,7 +16,9 @@ describe('plugins', function() { }); it('should load package.json from parent tree', async function() { - let b = await bundle(__dirname + '/integration/plugins/sub-folder/index.js'); + let b = await bundle( + __dirname + '/integration/plugins/sub-folder/index.js' + ); assertBundleTree(b, { name: 'index.js',