snowyu / inherits-ex.js Goto Github PK
View Code? Open in Web Editor NEWBrowser-friendly enhanced inheritance and mixin fully compatible with standard node.js inherits and coffee-script.
License: MIT License
Browser-friendly enhanced inheritance and mixin fully compatible with standard node.js inherits and coffee-script.
License: MIT License
In isEmptyFunction.js:
module.exports = function(aFunc, istanbul) {
if (!istanbul) try {istanbul = require('istanbul');} catch(e){}
};
Webpack / Browserify / etc don't do "conditional" requires, so that try
block doesn't do what you think it does. The require gets executed at build time, and if you do not happen to have istanbul installed, you get warnings like this:
Module not found: Error: Can't resolve 'istanbul' in '/Users/patrickminton/src/exm-admin-tool/node_modules/inherits-ex/lib'
@ ./~/inherits-ex/lib/isEmptyFunction.js 5:35-54
@ ./~/inherits-ex/lib/newPrototype.js
@ ./~/inherits-ex/lib/inheritsDirectly.js
@ ./~/inherits-ex/index.js
Worse, if you DO have istanbul installed, it breaks the build, because Istanbul itself does something that does not work in browsers, in https://github.com/gotwarlost/istanbul/blob/master/lib/hook.js:
var path = require('path'),
fs = require('fs'),
Module = require('module'),
`require('module') works fine in node.js, but does not work in a browser:
โ node
> const m = require('module')
undefined
> m
{ [Function: Module]
which is probably fine, because you aren't supposed to use istanbul in a browser....except that isEmptyFunction will try to do just that. The result is builds that break:
ERROR in ./~/istanbul/lib/hook.js
Module not found: Error: Can't resolve 'module' in '/Users/patrickminton/src/exm-admin-tool/node_modules/istanbul/lib'
@ ./~/istanbul/lib/hook.js 36:13-30
@ ./~/istanbul/index.js
@ ./~/inherits-ex/lib/isEmptyFunction.js
@ ./~/inherits-ex/lib/newPrototype.js
@ ./~/inherits-ex/lib/inheritsDirectly.js
@ ./~/inherits-ex/index.js
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.