koa-simple-static
Advanced tools
Comparing version 0.9.1 to 0.10.0
@@ -29,29 +29,3 @@ 'use strict'; | ||
/*:: import type { Context } from 'koa'*/ // @flow | ||
/*:: type StatFile = { | ||
dev: number, | ||
mode: number, | ||
nlink: number, | ||
uid: number, | ||
gid: number, | ||
rdev: number, | ||
blksize: number, | ||
ino: number, | ||
size: number, | ||
blocks: number, | ||
atimeMs: number, | ||
mtimeMs: number, | ||
ctimeMs: number, | ||
birthtimeMs: number, | ||
atime: Date, | ||
mtime: Date, | ||
ctime: Date, | ||
birthtime: Date | ||
}*/ | ||
/*:: type Next = () => Promise<*>*/ | ||
/*:: type ExtraHeader = { [key: string]: string }*/ | ||
const loadFile = (name /*: string*/, dir /*: string*/, options /*: **/, files /*: **/) /*: **/ => { | ||
const loadFile = (name, dir, options, files) => { | ||
const pathname = (0, _path.normalize)((0, _path.join)(options.prefix, name)); | ||
@@ -61,3 +35,3 @@ const obj = files[pathname] = files[pathname] ? files[pathname] : {}; | ||
const stats = (0, _fs.statSync)(filename); | ||
let buffer /*: Buffer | null*/ = (0, _fs.readFileSync)(filename); | ||
let buffer = (0, _fs.readFileSync)(filename); | ||
@@ -76,12 +50,3 @@ obj.cacheControl = options.cacheControl; | ||
/*:: type Opts = { | ||
dir: string, | ||
extraHeaders?: ExtraHeader[], | ||
cacheControl?: number, | ||
maxAge?: number, | ||
prefix: string | ||
}*/ | ||
const simpleStatic = (options /*: Opts*/) /*: **/ => { | ||
const simpleStatic = options => { | ||
const dir = (0, _path.normalize)(options.dir); | ||
@@ -91,7 +56,7 @@ options.prefix = '/'; | ||
(0, _fsReaddirRecursive2.default)(dir).forEach((name /*: string*/) /*: void*/ => { | ||
(0, _fsReaddirRecursive2.default)(dir).forEach(name => { | ||
loadFile(name, dir, options, files); | ||
}); | ||
return async (ctx /*: Context*/, next /*: Next*/) /*: **/ => { | ||
return async (ctx, next) => { | ||
// only accept HEAD and GET | ||
@@ -110,4 +75,4 @@ if (ctx.method !== 'HEAD' && ctx.method !== 'GET') { | ||
if (options.extraHeaders && Array.isArray(options.extraHeaders) && options.extraHeaders.length) { | ||
options.extraHeaders.forEach((header /*: ExtraHeader*/) /*: void*/ => { | ||
for (const h /*: string*/ in header) { | ||
options.extraHeaders.forEach(header => { | ||
for (const h in header) { | ||
// eslint-disable-line guard-for-in | ||
@@ -121,5 +86,5 @@ ctx.append(h, header[h]); | ||
// normalize for `//index` | ||
let filename /*: string*/ = (0, _zeelib.safeDecodeURIComponent)((0, _path.normalize)(ctx.path)); | ||
let filename = (0, _zeelib.safeDecodeURIComponent)((0, _path.normalize)(ctx.path)); | ||
let file /*: **/ = files[filename]; | ||
let file = files[filename]; | ||
@@ -134,3 +99,3 @@ // try to load file | ||
// handle index.html | ||
let hasIndex /*: bool*/ = false; | ||
let hasIndex = false; | ||
try { | ||
@@ -154,3 +119,3 @@ hasIndex = await (0, _fs.statSync)((0, _path.normalize)((0, _path.join)(dir, `${filename}/index.html`))).isFile(); | ||
let s /*: StatFile*/; | ||
let s; | ||
try { | ||
@@ -236,3 +201,3 @@ s = await (0, _fs.statSync)((0, _path.join)(dir, filename)); | ||
stream.on('data', hash.update.bind(hash)); | ||
stream.on('end', () /*: void*/ => { | ||
stream.on('end', () => { | ||
file.md5 = hash.digest('base64'); | ||
@@ -239,0 +204,0 @@ }); |
{ | ||
"name": "koa-simple-static", | ||
"description": "Simple caching static file server for Koa 2.", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"author": { | ||
@@ -12,4 +12,8 @@ "name": "Zac Anger", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"build": "babel src/index.js --out-file lib/index.js", | ||
"clean": "rm -rf lib && mkdir lib", | ||
"cover": "npm run cover:flow && npm run cover:tape", | ||
@@ -19,3 +23,4 @@ "cover:coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"cover:tape": "nyc npm run test:tape", | ||
"prebuild": "npm run test:lint && npm run cover", | ||
"postbuild": "flow-copy-source -i \"*.test.js\" src lib", | ||
"prebuild": "npm run test:lint && npm run cover && npm run clean", | ||
"preversion": "npm run build", | ||
@@ -47,26 +52,27 @@ "test": "npm run test:lint && npm run test:flow && npm run test:tape", | ||
"dependencies": { | ||
"compressible": "2.0.12", | ||
"compressible": "2.0.13", | ||
"fs-readdir-recursive": "1.1.0", | ||
"mime-types": "2.1.17", | ||
"mime-types": "2.1.18", | ||
"mz": "2.7.0", | ||
"zeelib": "6.0.1" | ||
"zeelib": "6.1.2" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.26.0", | ||
"babel-eslint": "8.2.1", | ||
"babel-eslint": "8.2.2", | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.26.0", | ||
"babel-plugin-transform-export-extensions": "6.22.0", | ||
"babel-plugin-transform-flow-comments": "6.22.0", | ||
"babel-preset-flow": "6.23.0", | ||
"babel-preset-latest-minimal": "1.1.2", | ||
"babel-tape-runner": "2.0.1", | ||
"coveralls": "3.0.0", | ||
"eslint": "4.17.0", | ||
"eslint-config-jane": "0.8.2", | ||
"eslint": "4.18.1", | ||
"eslint-config-jane": "0.10.0", | ||
"eslint-plugin-babel": "4.1.2", | ||
"eslint-plugin-flowtype": "2.44.0", | ||
"eslint-plugin-import": "2.8.0", | ||
"eslint-plugin-flowtype": "2.46.0", | ||
"eslint-plugin-import": "2.9.0", | ||
"eslint-plugin-node": "6.0.0", | ||
"eslint-plugin-promise": "3.6.0", | ||
"eslint-plugin-unicorn": "4.0.2", | ||
"flow-bin": "0.65.0", | ||
"flow-bin": "0.66.0", | ||
"flow-copy-source": "1.3.0", | ||
"flow-coverage-report": "0.4.1", | ||
@@ -78,3 +84,3 @@ "istanbul": "0.4.5", | ||
"tap-spec": "4.1.1", | ||
"tape": "4.8.0" | ||
"tape": "4.9.0" | ||
}, | ||
@@ -81,0 +87,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
17574
25
6
165
+ Addedcompressible@2.0.13(transitive)
+ Addedmime-db@1.33.0(transitive)
+ Addedmime-types@2.1.18(transitive)
+ Addedzeelib@6.1.2(transitive)
- Removedcompressible@2.0.12(transitive)
- Removedmime-db@1.30.0(transitive)
- Removedmime-types@2.1.17(transitive)
- Removedzeelib@6.0.1(transitive)
Updatedcompressible@2.0.13
Updatedmime-types@2.1.18
Updatedzeelib@6.1.2