Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1849 from brunch/v3-pre
Browse files Browse the repository at this point in the history
v3.0
  • Loading branch information
paulmillr committed Dec 7, 2019
2 parents 3613f37 + 20553b3 commit ea8beaf
Show file tree
Hide file tree
Showing 44 changed files with 1,945 additions and 1,797 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint
on: [push, pull_request]
env:
CI: true

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v1

- name: Set Node.js version
uses: actions/setup-node@v1
with:
node-version: "12"

- name: Install npm dependencies
run: npm install

- name: Run ESLint
run: npm run lint
24 changes: 24 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Node
on: [push, pull_request]
env:
CI: true

jobs:
build:
name: v${{ matrix.node-version }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [10, 12]
os: [ubuntu-latest, macOS-latest]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run ava tests
run: npm run test
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
To install the latest version, execute `npm install -g brunch`
## Brunch 3.0-pre (unreleased)

* Configuration file is now optional; and you could have it in package.json
* Built-in webserver is now using serve-handler from micro(1) webserver.
Custom webservers are unaffected.
* **Breaking:** Require node.js 10.16 or higher
* **Breaking:** Remove Bower and AMD support
* **Breaking:** Remove support for CoffeeScript brunch configs,
emit a command that would compile coffee file to js
* **Breaking:** New node.js API - use `brunch.build()` from node without hassle
* Decrease package size by a huge amount:
* Update Chokidar to 3.0
* Remove or integrate many dependencies
* Update dependencies to latest versions

## Brunch 2.10 (Jan 13, 2017)
* Added [yarn](https://yarnpkg.com/) support.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Paul Miller, Elan Shanker, Nik Graf, Thomas Schranz, Allan Berger, Jan Monschke, Martin Schürrer
Copyright (c) 2019 Paul Miller (https://paulmillr.com), Elan Shanker, Nik Graf, Thomas Schranz, Allan Berger, Jan Monschke, Martin Schürrer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Brunch [![Weekly downloads](https://img.shields.io/npm/dw/brunch.svg)](https://github.com/brunch/brunch) [![Yearly downloads](https://img.shields.io/npm/dy/brunch.svg)](https://github.com/brunch/brunch)
# Brunch [![Weekly downloads](https://img.shields.io/npm/dw/brunch.svg)](https://www.npmjs.com/package/brunch) [![Yearly downloads](https://img.shields.io/npm/dy/brunch.svg)](https://www.npmjs.com/package/brunch)

> Web applications made easy. Since 2011.

Fast front-end web app build tool with simple declarative config and seamless incremental compilation for rapid development.

## Usage
Expand All @@ -26,10 +25,10 @@ Install Brunch with a simple node.js package manager command:

## Learn

* Visit [**brunch.io**](https://brunch.io)
* Read [**brunch docs**](https://brunch.io/docs/getting-started)
* Follow us on Twitter: [@brunch](https://twitter.com/brunch)
* Ask questions on Stack Overflow with [#brunch](https://stackoverflow.com/questions/tagged/brunch) tag
- Visit [**brunch.io**](https://brunch.io)
- Read [**brunch docs**](https://brunch.io/docs/getting-started)
- Follow us on Twitter: [@brunch](https://twitter.com/brunch)
- Ask questions on Stack Overflow with [#brunch](https://stackoverflow.com/questions/tagged/brunch) tag

## Contributing

Expand All @@ -41,7 +40,7 @@ See the [CONTRIBUTING.md](https://github.com/brunch/brunch/blob/master/CONTRIBUT

## License

MIT license (c) Paul Miller [paulmillr.com](https://paulmillr.com), Elan Shanker,
MIT license (c) 2019 Paul Miller [paulmillr.com](https://paulmillr.com), Elan Shanker,
Nik Graf, Thomas Schranz, Allan Berger, Jan Monschke, Martin Schürrer

See LICENSE file.
8 changes: 4 additions & 4 deletions bin/brunch
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node
'use strict';

// Not using ES6 in that file since we want it to "launch" on older nodes.
/* eslint-disable prefer-arrow-callback, prefer-template */
/* eslint-env es6:false */
// Not using ES6 in that file since we want it to "launch" on older nodes.
var sysPath = require('path');
var join = sysPath.join;
var fs = require('fs');
var childProcessFork = require('child_process').fork;

var version = process.versions.node;
if (parseInt(version) < 4) {
if (parseInt(version) < 10) {
console.error(
'Error: Brunch 2+ requires Node.js v4 or higher (you have v' + version + ') ' +
'Upgrade Node.js or use older Brunch (not recommended): npm i -g brunch@1'
'Error: Brunch 3+ requires Node.js v10.16 or higher (you have v' + version + ') ' +
'Upgrade Node.js or use older Brunch (not recommended): npm i -g brunch@2'
);
process.exit(1);
}
Expand Down
48 changes: 19 additions & 29 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

/* eslint-disable prefer-arrow-callback, prefer-template */
/* eslint-env es6:false */
// Not using ES6 in that file since we want it to "launch" on older nodes.
var version = process.versions.node;
if (parseInt(version) < 4) {
if (parseInt(version) < 10) {
console.error(
'Your global Brunch installation is trying to load local Brunch v2+, ' +
'which only supports Node.js v4 or higher (you have ' + version + ').\n' +
'Your global Brunch installation is trying to load local Brunch v3+, ' +
'which only supports Node.js v10.16 or higher (you have ' + version + ').\n' +
'You have two choices:\n' +
' a) Update Node.js to v4+. Then update global Brunch: ' +
' a) Update Node.js to v10+. Then update global Brunch: ' +
'`npm un -g brunch && npm i -g brunch`\n' +
' b) Adjust package.json to use Brunch 1.x (outdated, not recommended).'
' b) Adjust package.json to use Brunch 2.x (outdated, not recommended).'
);
process.exit(1);
}
Expand All @@ -20,6 +21,13 @@ var program = require('commander');
var logger = require('loggy');
var commands = require('.');

function wrapCommand(name) {
return (arg1, arg2) => {
arg2.path = arg1 || '.';
return commands[name](arg2);
};
}

program
.version(require('../package.json').version, '-v, --version')
.usage('[command] [options]');
Expand All @@ -29,9 +37,9 @@ program.command('new [path]')
.description('Create new Brunch project in path.')
.option('-s, --skeleton [name]', 'skeleton name or URL from brunch.io/skeletons')
.on('--help', function() {
require('init-skeleton').printBanner('brunch new -s');
require('./init-skeleton').printErrorBanner();
})
.action(commands.new);
.action(wrapCommand('new'));

program.command('build [path]')
.alias('b')
Expand All @@ -41,7 +49,7 @@ program.command('build [path]')
.option('-d, --debug [pattern]', 'print verbose debug output to stdout')
.option('-j, --jobs [num]', 'parallelize the build')
.option('-c, --config [path]', 'specify a path to Brunch config file')
.action(commands.build);
.action(wrapCommand('build'));

program.command('watch [path]')
.alias('w')
Expand All @@ -55,27 +63,9 @@ program.command('watch [path]')
.option('-j, --jobs [num]', 'parallelize the build')
.option('-c, --config [path]', 'specify a path to Brunch config file')
.option('--stdin', 'listen to stdin and exit when stdin closes')
.action(commands.watch);
.action(wrapCommand('watch'));

var checkForRemovedOptions = function(args, command) {
var hasArg = function(deprs) {
return deprs.some(function(arg) {
return args.includes(arg);
});
};
var hasCommand = function(valid) {
return valid.includes(command);
};
// Deprecations
if (hasArg(['-o', '--optimize'])) {
return '--optimize has been removed. Use `-p / --production`';
}
if (hasCommand(['g', 'd', 'generate', 'destroy'])) {
return '`brunch generate / destroy` command has been removed.\n\nUse scaffolt (https://github.com/paulmillr/scaffolt)\nsuccessor or similar:\n npm install -g scaffolt\n scaffolt <type> <name> [options]\n scaffolt <type> <name> [options] --revert';
}
if (hasCommand(['t', 'test'])) {
return '`brunch test` command has been removed.\n\nUse mocha-phantomjs (http://metaskills.net/mocha-phantomjs/)\nsuccessor or similar:\n npm install -g mocha-phantomjs\n mocha-phantomjs [options] <your-html-file-or-url>';
}
var checkForRemovedOptions = function(args) {
var pIndex = args.indexOf('-p');
if (pIndex !== -1) {
// if -p is followed by a number, the user probably wants to specify the port
Expand All @@ -100,7 +90,7 @@ exports.run = function() {
// but we still want to see `brunch` in help.
args[1] = 'brunch';

var error = checkForRemovedOptions(args, command);
var error = checkForRemovedOptions(args);
if (error) {
logger.error(error);
return;
Expand Down
69 changes: 36 additions & 33 deletions lib/fs_utils/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
const debug = require('debug')('brunch:asset');
const sysPath = require('universal-path');
const readFromCache = require('fcache').readFile;
const processAsset = require('./pipeline').processAsset;
const {processFile} = require('./pipeline');
const BrunchError = require('../utils/error');
const isIgnored = require('./is_ignored');

const EMPTY_BUF = Buffer.alloc(0);
const EMPTY_ARR = Object.freeze([]);

// Returns all parent directories:
// < parentDirs('app/assets/thing/index.html')
// > ['app/', 'app/assets/', 'app/assets/thing/']
const parentDirs = path => {
return path.split('/').map((part, index, parts) => {
return parts.slice(0, index).concat(part, '').join('/');
}).slice(0, -1);
});
};

class Asset {
Expand All @@ -21,14 +24,15 @@ class Asset {

this.destinationPath = this.path = path;
this.compiled = '';
this.removed = this.disposed = false;
this.removed = false;
this.disposed = false;

this._publicPath = publicPath;
this._assetsConvention = assetsConvention;
this._wasProcessed = false;
this._rawSource = new Buffer(0);
this._rawSource = EMPTY_BUF;

this.error = null;
this.error = undefined;
this.dependencies = [];
this.compilationTime = 0;

Expand All @@ -44,46 +48,45 @@ class Asset {
return this.compilationTime;
}

compile() {
async compile() {
const path = this.path;
if (this.disposed) {
throw new BrunchError('ALREADY_DISPOSED', {path});
}

if (isIgnored(path)) return Promise.resolve(this);

return readFromCache(path)
.then(data => {
const asset = this;
asset._wasProcessed = false;
asset._rawSource = data;

return {
path,
get data() {
asset._wasProcessed = true;
return `${data}`;
},
};
})
.then(processAsset)
.then(file => this._updateCache(file))
.catch(error => {
this.error = error;
return this;
});
if (isIgnored(path)) return this;

const data = await readFromCache(path);
const asset = this;
asset._wasProcessed = false;
asset._rawSource = data;

try {
const file = await processFile({
path,
get data() {
asset._wasProcessed = true;
return `${data}`;
}
}, true);
this._updateCache(file);
} catch (error) {
this.error = error;
}
}

_updateCache(file) {
const path = sysPath.normalize(file.path);
const assetsDir = parentDirs(path).find(this._assetsConvention);
const dirs = parentDirs(path);
const aIndex = dirs.findIndex(this._assetsConvention);
const assetsDir = aIndex != null && dirs[aIndex - 1];
if (!assetsDir) {
throw new BrunchError('MOVED_ASSET', {path});
}

const rel = sysPath.relative(assetsDir, path);

this.error = null;
this.error = undefined;
this.destinationPath = sysPath.join(this._publicPath, rel);
this.compiled = this._wasProcessed ? file.data : this._rawSource;
this.dependencies = file.dependencies || [];
Expand All @@ -94,11 +97,11 @@ class Asset {
debug(`Disposing asset ${this.path}`);

this.path = '';
this._rawSource = new Buffer(0);
this._rawSource = EMPTY_BUF;
this.compiled = '';
this.disposed = true;
this.error = null;
this.dependencies = Object.freeze([]);
this.error = undefined;
this.dependencies = EMPTY_ARR;

// You're frozen when your heart's not open.
Object.freeze(this);
Expand Down
Loading

0 comments on commit ea8beaf

Please sign in to comment.