@cara/porter
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -0,1 +1,43 @@ | ||
2.2.0 / 2018-10-23 | ||
================== | ||
* New: cache transpile and minify results with {@link JsModule@cache} | ||
* dropped opts.cache.except because {@link Porter} no longer caches final js outputs, which is equivalent of `opts.cache.except = *` | ||
2.1.4 / 2018-09-10 | ||
================== | ||
* Fix: make sure isolated packages have all their versions compiled | ||
* Fix: prevent premature module execution | ||
2.1.3 / 2018-08-30 | ||
================== | ||
* fix: css module parsing | ||
* fix: await next() | ||
2.1.2 / 2018-08-20 | ||
================== | ||
* fix preload bundling, porter now tries its best to skip preloaded packages when bundling entries | ||
* fix multiple porter.lock assignment, only entries can now assign porter.lock | ||
* fix minor regression issues since favoring bundling | ||
* switch to `watch => reload` for better development experience | ||
* dropped opts.persist since it's no longer necessary | ||
2.1.1 / 2018-08-14 | ||
================== | ||
* Fix: loaderCache should not be shared at application level for it contains package specific data. | ||
2.1.0 / 2018-08-13 | ||
================== | ||
* New: bundling at large | ||
2.0.2 / 2018-08-07 | ||
================== | ||
* Fix: close a safari 9 argument shadowing issue with a temporary UglifyJS fork | ||
2.0.1 / 2018-07-30 | ||
@@ -2,0 +44,0 @@ ================== |
{ | ||
"name": "@cara/porter", | ||
"description": "A koa and express middleware for browser side javascript module authoring.", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"main": "src/porter.js", | ||
@@ -16,3 +16,2 @@ "repository": { | ||
"debug": "^3.1.0", | ||
"farmhash": "^2.1.0", | ||
"glob": "^7.0.5", | ||
@@ -19,0 +18,0 @@ "js-tokens": "^4.0.0", |
@@ -108,3 +108,3 @@ # Porter | ||
### `cache={ dest, except }` | ||
### `cache={ dest }` | ||
@@ -111,0 +111,0 @@ To accelerate responses, Porter caches following things: |
@@ -5,3 +5,3 @@ 'use strict' | ||
const UglifyJS = require('uglify-js') | ||
const { readFile } = require('mz/fs') | ||
const { access, readFile, writeFile } = require('mz/fs') | ||
@@ -12,2 +12,3 @@ const Module = require('./module') | ||
const matchRequire = require('../lib/matchRequire') | ||
const mkdirp = require('../lib/mkdirp') | ||
@@ -36,2 +37,7 @@ | ||
const fpath = path.join(this.package.app.cache.dest, this.id) | ||
const cache = await readFile(`${fpath}.cache`, 'utf8').catch(() => {}) | ||
if (cache) this.cache = JSON.parse(cache) | ||
const { code } = await this.load() | ||
@@ -64,4 +70,27 @@ const deps = this.deps || this.matchImport(code) | ||
async writeCache({ code, map }) { | ||
const fpath = path.join(this.package.app.cache.dest, this.id) | ||
const dir = path.dirname(fpath) | ||
try { | ||
await access(dir) | ||
} catch (err) { | ||
await mkdirp(dir) | ||
} | ||
if (typeof map === 'string') map = JSON.parse(map) | ||
await writeFile(`${fpath}.cache`, JSON.stringify({ code, map })) | ||
} | ||
async obtain() { | ||
if (this.cache) return this.cache | ||
this.cache = await super.obtain() | ||
await this.writeCache(this.cache) | ||
return this.cache | ||
} | ||
async minify() { | ||
if (this.minified) return this.minified | ||
if (this.cache) return this.cache | ||
const { code, map } = await this.load() | ||
@@ -73,4 +102,5 @@ const deps = this.deps || this.matchImport(code) | ||
this.deps = deps | ||
this.minified = this.tryUglify(await this.transpile({ code, map })) | ||
return this.minified | ||
this.cache = this.tryUglify(await this.transpile({ code, map })) | ||
await this.writeCache(this.cache) | ||
return this.cache | ||
} | ||
@@ -189,4 +219,3 @@ | ||
root: '/' | ||
}, | ||
ie8: true | ||
} | ||
}) | ||
@@ -193,0 +222,0 @@ |
'use strict' | ||
const crypto = require('crypto') | ||
const debug = require('debug')('porter') | ||
const farmhash = require('farmhash') | ||
const fs = require('mz/fs') | ||
@@ -329,3 +329,3 @@ const path = require('path') | ||
bundleFileName(entries) { | ||
const hash = farmhash.hash64(entries.join(',')) | ||
const hash = crypto.createHash('md5').update(entries.join(',')).digest('hex') | ||
return `~bundle-${hash.slice(0, 8)}.js` | ||
@@ -332,0 +332,0 @@ } |
@@ -5,4 +5,4 @@ 'use strict' | ||
const autoprefixer = require('autoprefixer') | ||
const crypto = require('crypto') | ||
const debug = require('debug')('porter') | ||
const farmhash = require('farmhash') | ||
const fs = require('mz/fs') | ||
@@ -34,3 +34,3 @@ const mime = require('mime') | ||
const transpile = { only: [], ...opts.transpile } | ||
const cache = { dest, except: [], ...opts.cache } | ||
const cache = { dest, ...opts.cache } | ||
const bundle = { except: [], ...opts.bundle } | ||
@@ -42,5 +42,2 @@ | ||
transpile.only.push(pkg.name) | ||
if (!cache.except.includes('*')) { | ||
cache.except.push(pkg.name, ...transpile.only) | ||
} | ||
cache.dest = path.resolve(root, cache.dest) | ||
@@ -129,5 +126,10 @@ | ||
const { cache } = this | ||
rimraf(path.join(cache.dest, '**/*.{css,js,map}'), err => { | ||
if (err) console.error(err.stack) | ||
}) | ||
if (cache.dest !== this.dest) { | ||
await new Promise((resolve, reject) => { | ||
rimraf(path.join(cache.dest, '**/*.{css,js,map}'), err => { | ||
if (err) reject(err) | ||
else resolve() | ||
}) | ||
}) | ||
} | ||
} | ||
@@ -247,4 +249,3 @@ | ||
async writeSourceMap({ id, isMain, name, code, map }) { | ||
const { dest, except } = this.cache | ||
const fpath = path.join(dest, id) | ||
const fpath = path.join(this.cache.dest, id) | ||
@@ -262,8 +263,5 @@ if (map instanceof SourceMapGenerator) { | ||
await mkdirp(path.dirname(fpath)) | ||
await Promise.all([ | ||
except.includes(name) ? Promise.resolve() : writeFile(fpath, code), | ||
writeFile(mapPath, JSON.stringify(map, (k, v) => { | ||
if (k !== 'sourcesContent') return v | ||
})) | ||
]) | ||
await writeFile(mapPath, JSON.stringify(map, (k, v) => { | ||
if (k !== 'sourcesContent') return v | ||
})) | ||
@@ -362,3 +360,3 @@ return { code } | ||
'Content-Type': mime.lookup(ext), | ||
ETag: farmhash.hash64(result[0]) | ||
ETag: crypto.createHash('md5').update(result[0]).digest('hex') | ||
}) | ||
@@ -365,0 +363,0 @@ } |
83035
18
2015
- Removedfarmhash@^2.1.0
- Removedansi-regex@2.1.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedbl@1.2.3(transitive)
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)
- Removedchownr@1.1.4(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddetect-libc@1.0.3(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexpand-template@1.1.1(transitive)
- Removedfarmhash@2.1.0(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedgauge@2.7.4(transitive)
- Removedgithub-from-package@0.0.0(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedini@1.3.8(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednan@2.22.0(transitive)
- Removednode-abi@2.30.1(transitive)
- Removednoop-logger@0.1.1(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedprebuild-install@2.5.3(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpump@1.0.32.0.1(transitive)
- Removedrc@1.2.8(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@2.8.2(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedtar-fs@1.16.4(transitive)
- Removedtar-stream@1.6.2(transitive)
- Removedto-buffer@1.1.1(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwhich-pm-runs@1.1.0(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedxtend@4.0.2(transitive)