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

Commit

Permalink
Fix const reassign & throw BrunchError (#1535)
Browse files Browse the repository at this point in the history
* introduce plugin adapter

* move `plugin.minify` handling to `plugin-adapter`

* move missing `plugin.defaultEnv` handling to `plugin-adapter`

* move `plugin.include` handling to `plugin-adapter`

* arguments is still a thing

* use String#repeat

* move `logger.notifications` to `config.js`

* minor tweaks

* fix OptimizeJob

* add `teardown` to `config.hooks`

* reorder `onCompile` and `preCompile` hooks

* replace `.constructor.name` with `brunchPluginName`

* escape `plugin.extension` when converted to RegExp

* move `promisifyHook` to utils

* remove noops

* promisify `preCompile` in `config.js`

* promisify `preCompile` hook in `plugin-adapter`

* reassign method in `promisifyHook`

* introduce hooks merging

* do not pass `onCompile` to `plugins.js`

* remove old comments

* refactor hash returned by `plugins.js`

* fixes

* move `callPlugin` to `plugin-adapter`

* call plugin methods directly

* fixes

* early return

* less indent

* hoist pure functions

* callback => onCompile

* verbose ava

* revert

* move string wrapping to `plugin-adapter`

* fix pattern

* tweaks

* refactor patternFor/isPluginFor

* tweaks

* respect custom paths to pkg.json in `plugins.js`

* fix compileStatic wrapping

* set up `staticPattern` conditionally

* Fix const reassign

* more descriptive name

* Report legacy new syntax with BrunchError
  • Loading branch information
shvaikalesh authored and paulmillr committed Oct 22, 2016
1 parent 34bab85 commit 169b742
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Expand Up @@ -135,6 +135,7 @@
"constructor-super": 2,
"generator-star-spacing": [2, "after"],
"no-class-assign": 2,
"no-const-assign": 2,
"no-dupe-class-members": 2,
"no-new-symbol": 2,
"no-this-before-super": 2,
Expand Down
24 changes: 13 additions & 11 deletions lib/index.js
@@ -1,17 +1,17 @@
'use strict';
require('micro-es7-shim');
const logger = require('loggy');
const isOldBrunchNewSyntax = options => {
const BrunchError = require('./utils/error');
const checkLegacyNewSyntax = options => {
const rawArgs = options.parent.rawArgs;
const newIdx = rawArgs.indexOf('new');
const opts = rawArgs.slice(newIdx + 1);
const oldSyntax = !options.skeleton && opts.length === 2;
if (!oldSyntax) return false;
const newArgs = rawArgs.slice(rawArgs.indexOf('new') + 1);
const oldSyntax = !options.skeleton && newArgs.length === 2;
if (!oldSyntax) return;

const skeleton = opts[0];
const path = opts[1];
logger.error(`The 'brunch new ${skeleton} ${path}' syntax is no longer supported. Use 'brunch new ${path} -s ${skeleton}'`);
return true;
throw new BrunchError('LEGACY_NEW_SYNTAX', {
skeleton: newArgs[0],
path: newArgs[1],
});
};

const hasDebug = obj => {
Expand All @@ -20,11 +20,13 @@ const hasDebug = obj => {

exports.defaultSkeleton = 'https://github.com/brunch/dead-simple';
exports.new = (rootPath, options) => {
if (isOldBrunchNewSyntax(options)) process.exit(1);
checkLegacyNewSyntax(options);

const initSkeleton = require('init-skeleton').init;
const skeleton = options.skeleton ||
process.env.BRUNCH_INIT_SKELETON || exports.defaultSkeleton;
process.env.BRUNCH_INIT_SKELETON ||
exports.defaultSkeleton;

return initSkeleton(skeleton, {
logger,
rootPath,
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/messages.json
Expand Up @@ -18,5 +18,6 @@
"CONVENTION_INVALID": "#{convention} in invalid convention.",
"FILE_DATA_INVALID": "File #{path} data is invalid.",
"REMOVE_GET_DEPS": "Compiler '#{name}' already passes dependencies. Remove 'getDependencies' method.",
"READ_FAILED": "Failed to read file #{path}."
"READ_FAILED": "Failed to read file #{path}.",
"LEGACY_NEW_SYNTAX": "The 'brunch new #{skeleton} #{path}' syntax is no longer supported. Use 'brunch new #{path} -s #{skeleton}'."
}
8 changes: 4 additions & 4 deletions lib/utils/plugin-adapter.js
Expand Up @@ -8,7 +8,7 @@ const methods = [
'optimize',
];

const extToRe = ext => {
const extToRegExp = ext => {
if (!ext) return;
const escaped = `.${ext}$`.replace(/\./g, '\\.');
return new RegExp(escaped, 'i');
Expand Down Expand Up @@ -37,7 +37,7 @@ const safeWrapInFile = (plugin, key) => {
};

const promisifyMethod = (plugin, key) => {
const fn = plugin[key];
let fn = plugin[key];
if (typeof fn !== 'function') return;
if (fn.length === 1) return;

Expand Down Expand Up @@ -80,12 +80,12 @@ module.exports = plugin => {
});

plugin.pattern = plugin.pattern ||
extToRe(plugin.extension) ||
extToRegExp(plugin.extension) ||
/.^/; // never matches

if (plugin.compileStatic) {
plugin.staticPattern = plugin.staticPattern ||
extToRe(plugin.staticExtension) ||
extToRegExp(plugin.staticExtension) ||
plugin.pattern;
}

Expand Down

0 comments on commit 169b742

Please sign in to comment.