get-source
Advanced tools
Comparing version 1.0.16 to 1.0.17
@@ -9,3 +9,2 @@ "use strict"; | ||
path = require ('./impl/path'), | ||
memoize = require ('lodash.memoize'), | ||
dataURIToBuffer = require ('data-uri-to-buffer'), | ||
@@ -16,2 +15,13 @@ lastOf = x => x[x.length - 1] | ||
const memoize = f => { | ||
const m = (x = '') => (x in m.cache) ? m.cache[x] : (m.cache[x] = f(x)) | ||
m.forgetEverything = () => { m.cache = Object.create (null) } | ||
m.cache = Object.create (null) | ||
return m | ||
} | ||
/* ------------------------------------------------------------------------ */ | ||
const newSourceFileMemoized = memoize (file => new SourceFile (file)) | ||
@@ -21,2 +31,5 @@ | ||
getSource.resetCache = () => newSourceFileMemoized.forgetEverything () | ||
getSource.getCache = () => newSourceFileMemoized.cache | ||
/* ------------------------------------------------------------------------ */ | ||
@@ -23,0 +36,0 @@ |
{ | ||
"name": "get-source", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "Platform-agnostic source code inspection, with sourcemaps support", | ||
@@ -36,5 +36,4 @@ "main": "get-source", | ||
"data-uri-to-buffer": "^1.0.0", | ||
"lodash.memoize": "^4.1.2", | ||
"source-map": "^0.5.6" | ||
} | ||
} |
37
test.js
@@ -58,3 +58,4 @@ "use strict"; | ||
const getSource = require ('./get-source'), | ||
fs = require ('fs') | ||
fs = require ('fs'), | ||
path = require ('path') | ||
@@ -71,3 +72,3 @@ it ('caches read files', () => { | ||
original.path.should.equal ('/Users/mac/get-source/test_files/original.js') // resolves input paths | ||
original.path.should.equal (path.resolve ('./test_files/original.js')) // resolves input paths | ||
original.text.should.equal (fs.readFileSync ('./test_files/original.js', { encoding: 'utf-8' })) | ||
@@ -93,3 +94,3 @@ original.lines.should.deep.equal ([ | ||
uglified.path.should.equal ('/Users/mac/get-source/test_files/original.uglified.js') | ||
uglified.path.should.equal (path.resolve ('./test_files/original.uglified.js')) | ||
uglified.lines.should.deep.equal ([ | ||
@@ -116,3 +117,3 @@ 'function hello(){return"hello world"}', | ||
uglified.path.should.equal ('/Users/mac/get-source/test_files/original.uglified.with.sources.js') | ||
uglified.path.should.equal (path.resolve ('./test_files/original.uglified.with.sources.js')) | ||
uglified.lines.should.deep.equal ([ | ||
@@ -130,3 +131,3 @@ 'function hello(){return"hello world"}', | ||
resolved.column.should.equal (1) | ||
resolved.sourceFile.path.should.equal ('/Users/mac/get-source/test_files/## embedded ##') // I've changed the filename manually, by editing .map file | ||
resolved.sourceFile.path.should.equal (path.resolve ('./test_files') + '/## embedded ##') // I've changed the filename manually, by editing .map file | ||
resolved.sourceLine.should.equal ('\treturn \'hello world\' }') | ||
@@ -155,3 +156,3 @@ }) | ||
beautified.path.should.equal ('/Users/mac/get-source/test_files/original.uglified.beautified.js') | ||
beautified.path.should.equal (path.resolve ('./test_files/original.uglified.beautified.js')) | ||
beautified.text.should.equal (fs.readFileSync ('./test_files/original.uglified.beautified.js', { encoding: 'utf-8' })) | ||
@@ -165,3 +166,3 @@ | ||
resolved.column.should.equal (1) | ||
resolved.sourceFile.path.should.equal ('/Users/mac/get-source/test_files/original.js') | ||
resolved.sourceFile.path.should.equal (path.resolve ('./test_files/original.js')) | ||
resolved.sourceLine.should.equal ('\treturn \'hello world\' }') | ||
@@ -187,2 +188,24 @@ }) | ||
}) | ||
it ('caching works', () => { | ||
const files = | ||
[ './test.js', | ||
'./package.json', | ||
'./test_files/original.js', | ||
'./test_files/original.uglified.js', | ||
'./test_files/original.uglified.js.map', | ||
'./test_files/original.uglified.with.sources.js', | ||
'./test_files/original.uglified.with.sources.js.map', | ||
'./test_files/original.babeled.with.inline.sourcemap.js', | ||
'./test_files/original.uglified.beautified.js', | ||
'./test_files/original.uglified.beautified.js.map', | ||
'./abyrvalg' ] | ||
Object.keys (getSource.getCache ()).should.deep.equal (files.map (x => path.resolve (x))) | ||
getSource.resetCache () | ||
Object.keys (getSource.getCache ()).length.should.equal (0) | ||
}) | ||
}) | ||
@@ -189,0 +212,0 @@ |
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
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
23024
2
352
16
- Removedlodash.memoize@^4.1.2
- Removedlodash.memoize@4.1.2(transitive)