protoblast
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -0,1 +1,10 @@ | ||
## 0.7.2 (2020-07-21) | ||
* Add `String#dedent()` method | ||
* Add `deprecate` decorator | ||
* Add sourcemap support | ||
* Fix error in `Function.parallel` & `Function.series` where primitives would be turned into objects | ||
* `RURL#segments` will now no longer contain empty strings | ||
* Add `RURL#isDescendant(parent)` to see if the current path is a descendant of the given path | ||
## 0.7.1 (2020-07-11) | ||
@@ -2,0 +11,0 @@ |
@@ -211,2 +211,36 @@ module.exports = function BlastDecorators(Blast, Collection) { | ||
/** | ||
* Deprecate the method: log a warning upon use | ||
* | ||
* @author Jelle De Loecker <jelle@develry.be> | ||
* @since 0.7.1 | ||
* @version 0.7.1 | ||
* | ||
* @param {Object} config | ||
*/ | ||
Blast.Decorators.deprecate = function deprecate(config) { | ||
return function deprecate(options) { | ||
var count = 0, | ||
fnc = options.descriptor.value, | ||
key = options.key; | ||
options.descriptor.value = function deprecate() { | ||
if (count == 0) { | ||
let message = this.constructor.getClassPath() | ||
+ '#' + key + '() has been deprecated'; | ||
console.warn(message); | ||
count++; | ||
} | ||
return fnc.apply(this, arguments); | ||
} | ||
return options; | ||
}; | ||
}; | ||
}; |
@@ -97,3 +97,3 @@ module.exports = function BlastFunctionFlow(Blast, Collection, Bound) { | ||
* @since 0.1.2 | ||
* @version 0.7.0 | ||
* @version 0.7.2 | ||
* | ||
@@ -262,3 +262,8 @@ * @param {Boolean} _forceAsync Force asynchronous behaviour [TRUE] | ||
pledge._addProgressPledge(tasks[next]); | ||
Blast.Classes.Pledge.prototype.handleCallback.call(tasks[next], nextHandler); | ||
if (typeof tasks[next] != 'object') { | ||
Blast.Classes.Pledge.resolve(tasks[next]).done(nextHandler); | ||
} else { | ||
Blast.Classes.Pledge.prototype.handleCallback.call(tasks[next], nextHandler); | ||
} | ||
} | ||
@@ -320,3 +325,3 @@ } catch (err) { | ||
* @since 0.1.2 | ||
* @version 0.6.3 | ||
* @version 0.7.2 | ||
*/ | ||
@@ -549,3 +554,8 @@ Blast.defineStatic('Function', function parallel(_forceAsync, _limit, _tasks, _callback) { | ||
pledge._addProgressPledge(fnc); | ||
Blast.Classes.Pledge.prototype.handleCallback.call(fnc, nextHandler); | ||
if (typeof fnc != 'object') { | ||
Blast.Classes.Pledge.resolve(fnc).done(nextHandler); | ||
} else { | ||
Blast.Classes.Pledge.prototype.handleCallback.call(fnc, nextHandler); | ||
} | ||
} | ||
@@ -552,0 +562,0 @@ } catch (err) { |
@@ -1223,3 +1223,3 @@ module.exports = function BlastInheritance(Blast, Collection) { | ||
* @since 0.6.0 | ||
* @version 0.6.0 | ||
* @version 0.7.2 | ||
* | ||
@@ -1235,4 +1235,2 @@ * @param {Function} constructor Constructor to modify prototype of | ||
var options | ||
if (typeof key == 'function') { | ||
@@ -1243,3 +1241,3 @@ method = key; | ||
options = { | ||
let options = { | ||
kind : 'method', | ||
@@ -1253,2 +1251,6 @@ key : key, | ||
if (typeof decorator == 'string') { | ||
decorator = Obj.path(Blast.Decorators, decorator)(); | ||
} | ||
// Get the new options from the decorator | ||
@@ -1255,0 +1257,0 @@ options = decorator(options); |
263
lib/init.js
@@ -287,2 +287,5 @@ module.exports = function BlastInitLoader(modifyPrototype) { | ||
Blast.ACTIVE_FILE = Symbol('active_file'); | ||
// We break this string up so the Blast.convertCoverage doesn't find this | ||
var source_map_url_prefix = '//# sourceMappingURL' + '=data:application/json;charset=utf-8;base64,'; | ||
} | ||
@@ -943,3 +946,3 @@ // PROTOBLAST END CUT | ||
* @since 0.1.1 | ||
* @version 0.7.0 | ||
* @version 0.7.2 | ||
* | ||
@@ -969,2 +972,30 @@ * @param {Object} options | ||
let create_source_map = options.create_source_map, | ||
enable_coverage = options.enable_coverage; | ||
// If the source-map module couldn't be loaded, ignore it | ||
if (Blast.sourceMap === false) { | ||
create_source_map = false; | ||
} | ||
// If we want to add coverage, the sourcemap is required! | ||
if (enable_coverage) { | ||
create_source_map = true; | ||
if (!Blast.instrumentSource) { | ||
require('./coverage.js'); | ||
} | ||
} | ||
// If we want to make a sourcemap, but the module hasn't been loaded | ||
// try to load it now | ||
if (create_source_map && Blast.sourceMap == null) { | ||
try { | ||
Blast.sourceMap = require('source-map'); | ||
} catch (err) { | ||
create_source_map = false; | ||
Blast.sourceMap = false; | ||
} | ||
} | ||
if (!id) { | ||
@@ -980,2 +1011,6 @@ id = 'full'; | ||
if (enable_coverage) { | ||
id += '_cov'; | ||
} | ||
if (cache[id] && !refresh) { | ||
@@ -1015,2 +1050,6 @@ return cache[id]; | ||
if (enable_coverage) { | ||
compose_id += '_cov'; | ||
} | ||
if (cache[compose_id] && !refresh) { | ||
@@ -1049,6 +1088,24 @@ cache[id] = cache[compose_id]; | ||
Blast.getCachedFile(path).then(function gotCode(code) { | ||
var data = 'require.register("' + name + '.js", function(module, exports, require){\n'; | ||
let filename = name + '.js'; | ||
var data = 'require.register("' + filename + '", function(module, exports, require){\n'; | ||
data += code; | ||
data += '});\n'; | ||
next(null, data); | ||
let result = { | ||
start : 1, // Starts at 1 for the `require` line | ||
code : data, | ||
filename : filename, | ||
name_id : name, | ||
name : name, | ||
path : path, | ||
source : null | ||
}; | ||
if (create_source_map) { | ||
result.source = code; | ||
} | ||
next(null, result); | ||
}).catch(next); | ||
@@ -1062,4 +1119,15 @@ }); | ||
let source, | ||
start = 0; | ||
if (create_source_map) { | ||
source = code; | ||
} | ||
if (options.add_wrapper !== false) { | ||
if (options.add_wrapper || code.slice(0, 14) != 'module.exports') { | ||
// Add 1 line for the `register` line | ||
start++; | ||
let data = 'module.exports = function('; | ||
@@ -1073,3 +1141,3 @@ | ||
data += ') {'; | ||
data += ') {\n'; | ||
@@ -1080,8 +1148,28 @@ code = data + code + '\n};'; | ||
code = 'require.register("' + (options.name_id || options.name) + '", function(module, exports, require){\n' | ||
let name = options.name_id || options.name, | ||
filename = libpath.basename(options.path); | ||
code = 'require.register("' + name + '", function(module, exports, require){\n' | ||
+ code | ||
+ '});\n'; | ||
next(null, code); | ||
// Add 1 line for the `require` line | ||
start++; | ||
let result = { | ||
start : start, | ||
code : code, | ||
filename : filename, | ||
name : options.name, | ||
name_id : options.name_id, | ||
path : options.path, | ||
source : null | ||
}; | ||
if (create_source_map) { | ||
result.source = source; | ||
} | ||
next(null, result); | ||
}).catch(next); | ||
@@ -1100,7 +1188,96 @@ }); | ||
let template = files.shift(), | ||
index = template.indexOf('//_REGISTER_//'), | ||
let current_line, | ||
sourcemap, | ||
template = files.shift(), | ||
index = template.indexOf('//_REGISTER_//'), | ||
filename = libpath.resolve(tmpdir, compose_id + '.js'), | ||
code = files.join('\n'); | ||
code = '', | ||
file, | ||
i; | ||
let template_start = template.slice(0, index), | ||
template_offset = Blast.Bound.String.count(template_start, '\n'); | ||
if (create_source_map) { | ||
sourcemap = new Blast.sourceMap.SourceMapGenerator({ | ||
file : compose_id + '.js', | ||
sourceRoot : '' | ||
}); | ||
} | ||
for (i = 0; i < files.length; i++) { | ||
file = files[i]; | ||
if (code) { | ||
code += '\n'; | ||
} | ||
if (create_source_map) { | ||
// Count the current line we're on | ||
current_line = template_offset + Blast.Bound.String.count(code, '\n'); | ||
} | ||
if (typeof file == 'string') { | ||
let path = libpath.resolve(__dirname, 'client.js'); | ||
code += file; | ||
if (create_source_map) { | ||
// Ugly hack for the client.js file | ||
file = { | ||
start : 0, | ||
code : file, | ||
source : file, | ||
path : path, | ||
name : 'blast_template_client.js' | ||
}; | ||
} | ||
} else { | ||
code += file.code; | ||
} | ||
if (create_source_map) { | ||
let filename = file.name; | ||
if (filename.indexOf('.js') == -1) { | ||
filename += '.js'; | ||
} | ||
filename = file.path; | ||
sourcemap.setSourceContent(filename, file.source); | ||
let target_line = current_line + (file.start || 0), | ||
end_column, | ||
char_start, | ||
char_end, | ||
tokens, | ||
lines = file.source.split('\n'), | ||
token, | ||
i, | ||
j; | ||
for (i = 0; i < lines.length; i++) { | ||
line = lines[i]; | ||
tokens = Blast.Bound.Function.tokenize(line, false); | ||
char_start = 0; | ||
for (j = 0; j < tokens.length; j++) { | ||
char_end = char_start + tokens[j].length; | ||
sourcemap.addMapping({ | ||
source : filename, | ||
original : {line: 1 + i, column: char_start}, | ||
generated : {line: target_line + i + 1, column: char_start}, | ||
name : tokens[j] | ||
}); | ||
char_start = char_end; | ||
} | ||
} | ||
} | ||
} | ||
if (options.use_common) { | ||
@@ -1124,7 +1301,43 @@ code += '\nuse_common = true;\n'; | ||
template = template.slice(0, index) + code + template.slice(index); | ||
template = template_start + code + template.slice(index); | ||
let cut_rx = /\/\/\s?PROTOBLAST\s?START\s?CUT([\s\S]*?)(\/\/\s?PROTOBLAST\s?END\s?CUT)/gm; | ||
// Remove everything between "PROTOBLAST START CUT" and "PROTOBLAST END CUT" (with slashes) | ||
template = template.replace(/\/\/\s?PROTOBLAST\s?START\s?CUT([\s\S]*?)(\/\/\s?PROTOBLAST\s?END\s?CUT)/gm, ''); | ||
if (create_source_map) { | ||
// Instead of actually cutting the code when making a sourcemap, | ||
// the code is commented | ||
template = template.replace(cut_rx, function doReplace(match) { | ||
let result = '', | ||
lines = match.split('\n'), | ||
line, | ||
i; | ||
for (i = 0; i < lines.length; i++) { | ||
if (i) { | ||
result += '\n'; | ||
} | ||
line = lines[i]; | ||
result += '// ' + line; | ||
} | ||
return result; | ||
}); | ||
let sourcemap_64 = Buffer.from(sourcemap.toString()).toString('base64'); | ||
let inline_source_map = source_map_url_prefix + sourcemap_64; | ||
template += '\n' + inline_source_map; | ||
} else { | ||
template = template.replace(cut_rx, ''); | ||
} | ||
if (enable_coverage) { | ||
template = Blast.instrumentSource(template, 'test_path.js', JSON.parse(sourcemap.toString())).code; | ||
} | ||
let retries = 0; | ||
@@ -1434,3 +1647,3 @@ | ||
// Restore the original functions | ||
modulep.wrap = modulep.original_wrap; | ||
modulep.wrap = simpleScriptWrap; | ||
modulep._resolveFilename = modulep.original_resolve; | ||
@@ -1441,3 +1654,3 @@ | ||
if (script.indexOf('__cov_') > -1 && script.indexOf('module.exports=function ') > 7) { | ||
if (global.__coverage__ && script.indexOf('module.exports=function ') > 7) { | ||
// We're in coverage mode, just ignore | ||
@@ -1472,3 +1685,3 @@ } else { | ||
} catch (err) { | ||
modulep.wrap = modulep.original_wrap; | ||
modulep.wrap = simpleScriptWrap; | ||
modulep._resolveFilename = modulep.original_resolve; | ||
@@ -1479,2 +1692,24 @@ throw err; | ||
} | ||
/** | ||
* Just restoring the originel `wrap` function doesn't seem to work | ||
* when it tries to load a shebang file (Proxy nonsense?) | ||
* So check the script first | ||
* | ||
* @author Jelle De Loecker <jelle@elevenways.be> | ||
* @since 0.7.2 | ||
* @version 0.7.2 | ||
* | ||
* @param {String} script | ||
* | ||
* @return {String} | ||
*/ | ||
function simpleScriptWrap(script) { | ||
if (script[0] == '#' && script[1] == '!') { | ||
script = '//' + script.slice(2); | ||
} | ||
return modulep.original_wrap(script); | ||
} | ||
//PROTOBLAST END CUT | ||
@@ -1481,0 +1716,0 @@ |
@@ -739,3 +739,3 @@ module.exports = function BlastURL(Blast, Collection, Bound, Obj) { | ||
* @since 0.7.1 | ||
* @version 0.7.1 | ||
* @version 0.7.2 | ||
* | ||
@@ -749,3 +749,3 @@ * @type {String} | ||
return Bound.String.afterLast(last_segment, '.'); | ||
return last_segment ? Bound.String.afterLast(last_segment, '.') : ''; | ||
@@ -851,3 +851,3 @@ }, function setExtension(extension) { | ||
* @since 0.5.7 | ||
* @version 0.5.7 | ||
* @version 0.7.2 | ||
* | ||
@@ -859,3 +859,3 @@ * @type {Array} | ||
if (this._data.segments == null) { | ||
this._data.segments = this.pathname.slice(1).split('/'); | ||
this._data.segments = Bound.Array.clean(this.pathname.slice(1).split('/'), ''); | ||
} | ||
@@ -866,3 +866,3 @@ | ||
this._data.segments = segments; | ||
this._data.segments = Bound.Array.clean(segments, ''); | ||
this._data.pathname = '/' + segments.join('/'); | ||
@@ -1772,2 +1772,34 @@ | ||
/** | ||
* Is this url a subpath of the given url? | ||
* | ||
* @author Jelle De Loecker <jelle@develry.be> | ||
* @since 0.7.2 | ||
* @version 0.7.2 | ||
* | ||
* @param {String|RURL} url | ||
* | ||
* @return {Boolean} | ||
*/ | ||
RURL.setMethod(function isDescendant(url) { | ||
url = RURL.parse(url); | ||
if (url.hostname && this.hostname && this.hostname != url.hostname) { | ||
return false; | ||
} | ||
let parent_segments = url.segments, | ||
segments = this.segments, | ||
i; | ||
for (i = 0; i < parent_segments.length; i++) { | ||
if (parent_segments[i] != segments[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); | ||
// Make it a global class | ||
@@ -1774,0 +1806,0 @@ Blast.defineClass('RURL', RURL); |
@@ -284,3 +284,3 @@ module.exports = function BlastImmediate(Blast, Collection) { | ||
}); | ||
} | ||
}; | ||
@@ -287,0 +287,0 @@ Blast.defineGlobal('clearImmediate', realClearImmediate); |
@@ -2619,2 +2619,48 @@ module.exports = function BlastString(Blast, Collection, Bound, Obj) { | ||
}); | ||
/** | ||
* Dedent a piece of text | ||
* | ||
* @author Jelle De Loecker <jelle@develry.be> | ||
* @since 0.7.2 | ||
* @version 0.7.2 | ||
* | ||
* @return {String} | ||
*/ | ||
Blast.definePrototype('String', function dedent() { | ||
let text = this; | ||
let length, | ||
lines = text.split('\n'), | ||
trims = [], | ||
count, | ||
line, | ||
i; | ||
for (i = 0; i < lines.length; i++) { | ||
line = lines[i]; | ||
length = line.trimLeft().length; | ||
if (length == 0) { | ||
trims.push(Infinity); | ||
} else { | ||
trims.push(line.length - length); | ||
} | ||
} | ||
let min = Bound.Array.min(trims); | ||
for (i = 0; i < lines.length; i++) { | ||
line = lines[i]; | ||
count = trims[i]; | ||
if (count) { | ||
line = line.slice(min); | ||
lines[i] = line; | ||
} | ||
} | ||
return lines.join('\n'); | ||
}); | ||
}; |
{ | ||
"name": "protoblast", | ||
"description": "Native object expansion library", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"author": "Jelle De Loecker <jelle@elevenways.be>", | ||
@@ -21,22 +21,25 @@ "keywords": [ | ||
"scripts": { | ||
"test" : "node_modules/.bin/mocha --reporter spec", | ||
"coverage" : "./node_modules/istanbul/lib/cli.js cover _mocha", | ||
"report-coverage" : "cat ./coverage/lcov.info | codecov" | ||
"test" : "mocha --exit --reporter spec --bail --timeout 5000 --file test/00-init.js", | ||
"coverage" : "nyc --reporter=text --reporter=lcov mocha --exit --timeout 20000 --bail --file test/00-init.js", | ||
"report-coverage" : "nyc report --reporter=lcov && cat ./coverage/lcov.info | codecov" | ||
}, | ||
"main": "lib/init.js", | ||
"devDependencies": { | ||
"browserify" : "5.11.0", | ||
"codecov" : "~3.7.0", | ||
"git-rev" : "0.2.1", | ||
"istanbul" : "^0.4.5", | ||
"jsuri" : "~1.3.1", | ||
"matcha" : "skerit/matcha", | ||
"mocha" : "^5.0.1", | ||
"promises-aplus-tests" : "~2.1.2", | ||
"uglify-js" : "3.2.0", | ||
"wd" : "1.4.1" | ||
"browserify" : "~16.5.1", | ||
"codecov" : "~3.7.0", | ||
"git-rev" : "0.2.1", | ||
"istanbul-lib-instrument" : "~4.0.3", | ||
"jsuri" : "~1.3.1", | ||
"matcha" : "skerit/matcha", | ||
"mocha" : "~8.0.1", | ||
"nyc" : "^15.1.0", | ||
"promises-aplus-tests" : "~2.1.2", | ||
"puppeteer" : "~5.1.0", | ||
"source-map" : "~0.7.3", | ||
"uglify-js" : "3.2.0", | ||
"wd" : "~1.12.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.9.0" | ||
"node": ">=10.21.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
706178
52
28581
13
13