From 392bbc9ff827bad5382e8c0bb7314eabaa7c3ef4 Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Mon, 11 Dec 2017 10:28:53 +0100 Subject: [PATCH 1/3] run prettier --- src/HMRServer.js | 2 +- src/WorkerFarm.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HMRServer.js b/src/HMRServer.js index aaa27908ad4..47a0053ba6a 100644 --- a/src/HMRServer.js +++ b/src/HMRServer.js @@ -44,7 +44,7 @@ class HMRServer { }); } - const containsHtmlAsset = assets.some(asset => asset.type === "html"); + const containsHtmlAsset = assets.some(asset => asset.type === 'html'); if (containsHtmlAsset) { this.broadcast({ type: 'reload' diff --git a/src/WorkerFarm.js b/src/WorkerFarm.js index 72c36ac4b6f..cd083d4c333 100644 --- a/src/WorkerFarm.js +++ b/src/WorkerFarm.js @@ -9,7 +9,7 @@ class WorkerFarm extends Farm { constructor(options) { let opts = { autoStart: true, - maxConcurrentWorkers: getNumWorkers(), + maxConcurrentWorkers: getNumWorkers() }; super(opts, require.resolve('./worker')); From e96ce13acc5bfd64e48b506139d683fff4e06924 Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Wed, 13 Dec 2017 09:29:24 +0100 Subject: [PATCH 2/3] fix --- bin/.babelrc | 7 ++++ bin/cli.js | 109 +++---------------------------------------------- bin/src/cli.js | 104 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 117 insertions(+), 105 deletions(-) create mode 100644 bin/.babelrc mode change 100755 => 100644 bin/cli.js create mode 100755 bin/src/cli.js diff --git a/bin/.babelrc b/bin/.babelrc new file mode 100644 index 00000000000..d0a284477ea --- /dev/null +++ b/bin/.babelrc @@ -0,0 +1,7 @@ +{ + "presets": [["env", { + "targets": { + "node": "6" + } + }]] +} \ No newline at end of file diff --git a/bin/cli.js b/bin/cli.js old mode 100755 new mode 100644 index ea71832a42b..ea20759e601 --- 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/bin/src/cli.js b/bin/src/cli.js new file mode 100755 index 00000000000..78696ef2eab --- /dev/null +++ b/bin/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/package.json b/package.json index ea44252a924..2b79fcd67ca 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "scripts": { "test": "cross-env NODE_ENV=test mocha", "format": "prettier --write './{src,bin,test}/**/*.{js,json,md}'", - "build": "babel src -d lib", + "build": "babel src -d lib && babel bin/src -d bin/lib", "prepublish": "yarn build", "precommit": "lint-staged", "postinstall": From 055478c4c7a868079e08c35f3cedb5cd8de322ee Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Wed, 13 Dec 2017 13:13:44 +0100 Subject: [PATCH 3/3] use same src folder as everything else --- bin/.babelrc | 7 ------- bin/cli.js | 4 ++-- package.json | 2 +- {bin/src => src}/cli.js | 4 ++-- 4 files changed, 5 insertions(+), 12 deletions(-) delete mode 100644 bin/.babelrc rename {bin/src => src}/cli.js (96%) diff --git a/bin/.babelrc b/bin/.babelrc deleted file mode 100644 index d0a284477ea..00000000000 --- a/bin/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presets": [["env", { - "targets": { - "node": "6" - } - }]] -} \ No newline at end of file diff --git a/bin/cli.js b/bin/cli.js index ea20759e601..523bcad4f02 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,5 +1,5 @@ // 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'); + ? require('../lib/cli') + : require('../src/cli'); diff --git a/package.json b/package.json index 2b79fcd67ca..ea44252a924 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "scripts": { "test": "cross-env NODE_ENV=test mocha", "format": "prettier --write './{src,bin,test}/**/*.{js,json,md}'", - "build": "babel src -d lib && babel bin/src -d bin/lib", + "build": "babel src -d lib", "prepublish": "yarn build", "precommit": "lint-staged", "postinstall": diff --git a/bin/src/cli.js b/src/cli.js similarity index 96% rename from bin/src/cli.js rename to src/cli.js index 78696ef2eab..ea71832a42b 100755 --- a/bin/src/cli.js +++ b/src/cli.js @@ -3,7 +3,7 @@ require('v8-compile-cache'); const chalk = require('chalk'); const program = require('commander'); -const version = require('../../package.json').version; +const version = require('../package.json').version; program.version(version); @@ -83,7 +83,7 @@ program.parse(args); async function bundle(main, command) { // Require bundler here so the help command is fast - const Bundler = require('../../'); + const Bundler = require('../'); if (command.name() === 'build') { process.env.NODE_ENV = 'production';