-
Notifications
You must be signed in to change notification settings - Fork 9
Refactoring #11
base: master
Are you sure you want to change the base?
Refactoring #11
Conversation
denar90
commented
Jan 17, 2017
- coffee -> es6 + refactoring
Let's not commit |
index.js
Outdated
} | ||
|
||
// Defaults options | ||
this.options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const defaultOptions =
and remove the comment
index.js
Outdated
|
||
// Defaults options | ||
this.options = { | ||
ignore: /[\\/][.]/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/\/\./
index.js
Outdated
manifestFile: 'appcache.appcache' | ||
}; | ||
|
||
// Merge config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the comment pls
index.js
Outdated
} | ||
|
||
AppCacheCompiler.prototype.brunchPlugin = true; | ||
AppCacheCompiler.prototype.staticTargetExtension = 'html'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is extra
README.md
Outdated
staticRoot: '/static' | ||
network: ['*'] | ||
```js | ||
exports.config = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.exports = {
package.json
Outdated
"mocha": "^3", | ||
"sinon": "^1.17.7", | ||
"eslint": "^3.12.2", | ||
"eslint-config-brunch": "brunch/eslint-config-brunch" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^1.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^1
, ^3
etc.
index.js
Outdated
} | ||
|
||
processFile(file) { | ||
if (!/[.]appcache$/.test(file.path) && !this.config.ignore.test(file.path) && !this.paths.includes(file.path)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.endsWith('.appcache')
index.js
Outdated
return (Array.from(Object.keys(obj).sort()).map(k => `${k} ${obj[k]}`)).join('\n'); | ||
}; | ||
|
||
_readStream(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole point of rewrite is to not have this method. Use file.data
.
package.json
Outdated
@@ -8,14 +8,18 @@ | |||
"type": "git", | |||
"url": "[email protected]:brunch/appcache-brunch.git" | |||
}, | |||
"main": "./lib/index", | |||
"main": "index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is default value. We can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't quite obvious, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On pair with index.html
.
index.js
Outdated
} | ||
|
||
_format(obj) { | ||
return (Array.from(Object.keys(obj).sort()).map(k => `${k} ${obj[k]}`)).join('\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Array.from(iter).map(fn)
+ Array.from(iter, fn)
index.js
Outdated
try { | ||
if (this.changedFileContentShasum) { | ||
this.pathsToCache = files | ||
.filter(file => !/[.]appcache$/.test(file.path) && !this.config.ignore.test(file.path) && !this.pathsToCache.includes(file.path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.endsWith('.appcache')
and consider extracting this fn.
.map(file => file.path) | ||
.sort(); | ||
|
||
this.pathsToCache.push(...pathsToCache); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, do not prefer this, but it looks acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
index.js
Outdated
} | ||
|
||
_format(obj) { | ||
return (Array.from(Object.keys(obj).sort(), k => `${k} ${obj[k]}`)).join('\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra ()
aren't necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we agree this should not be method?
Uses this
=> method
Otherwise => helper
Easy.
test/test.js
Outdated
}); | ||
|
||
it('should call "_processFile" method', () => { | ||
return plugin.compile(mocks.files[0], () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't plugin.compile
returns a Promise? Why do you pass a callback then?
test/test.js
Outdated
}); | ||
|
||
it('sets changedFileContentShasum', () => { | ||
const file = mocks.files[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [file] = mocks.files
as we already dropped Node.js < 6.
test/test.js
Outdated
const mocks = require('./fixtures/mocks'); | ||
const config = require('./fixtures/brunch.conf'); | ||
|
||
const Plugin = require('../index'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require('..')
it('ignores appcache files', () => { | ||
const file = mocks.ignoredFiles[0]; | ||
plugin._processFile(file); | ||
assert.deepEqual(plugin.paths, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But assert
doesn't have empty method...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does in master
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In nodejs
master?
Should we keep it as it is until new version be released?
test/test.js
Outdated
|
||
assert.equal(actualAppCacheContent, expectedAppCacheContent); | ||
}) | ||
.catch(e => console.log(e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this.
index.js
Outdated
${format(this.config.fallback)} | ||
|
||
CACHE: | ||
${(Array.from(this.pathsToCache).map(p => `${this.config.staticRoot}/${p}`)).join('\n')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.from(this.pathsToCache, p => `${this.config.staticRoot}/${p}`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and without extra ()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disabled no-extra-parens
in eslint config cause it gave false-positives. Maybe we should reconsider this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed for format
method but missed this one...
network: ['*'], | ||
fallback: {}, | ||
staticRoot: '.', | ||
manifestFile: 'appcache.appcache', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array(2).fill('appcache').join('.')
index.js
Outdated
} | ||
|
||
AppCacheCompiler.prototype.brunchPlugin = true; | ||
AppCacheCompiler.prototype.pattern = /(?:)/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const matchesAll = /(?:)/
AppCacheCompiler.prototype.pattern = matchesAll
.travis.yml
Outdated
language: node_js | ||
- osx | ||
node_js: | ||
- 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use just node
— the latest version of Node.js
I think it can go after real world testing aka brunch/brunch.github.io#267 |
Should we stop working on a new version since all browsers support https://caniuse.com/#feat=serviceworkers service workers? |