Comparing version 0.2.0 to 1.2.0
@@ -168,4 +168,2 @@ //---------------------------------------------------------------------------- | ||
if (x.prototype !== y.prototype) return false | ||
var xKeys = ownPropertyNames(x) | ||
@@ -182,2 +180,4 @@ var yKeys = ownPropertyNames(y) | ||
if (x.prototype && y.prototype && (x.prototype !== y.prototype)) return false | ||
return true | ||
@@ -184,0 +184,0 @@ } |
//---------------------------------------------------------------------------- | ||
// Copyright (c) 2010 Patrick Mueller | ||
// Copyright (c) 2010, 2011 Patrick Mueller | ||
// | ||
@@ -18,14 +18,8 @@ // The MIT License - see: http://www.opensource.org/licenses/mit-license.php | ||
//---------------------------------------------------------------------------- | ||
// only supports "preloaded" modules ala require.define (Transport/D) | ||
// http://wiki.commonjs.org/wiki/Modules/Transport/D | ||
// but only supports the first parameter | ||
// only supports "preloaded" modules ala define() (AMD) | ||
// http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition | ||
// but the id parameter is required | ||
//---------------------------------------------------------------------------- | ||
//---------------------------------------------------------------------------- | ||
// globals | ||
//---------------------------------------------------------------------------- | ||
var require | ||
var modjewel | ||
//---------------------------------------------------------------------------- | ||
// function wrapper | ||
@@ -39,3 +33,4 @@ //---------------------------------------------------------------------------- | ||
var PROGRAM = "modjewel" | ||
var VERSION = "1.1.0" | ||
var VERSION = "1.2.0" | ||
var global = this | ||
@@ -45,3 +40,3 @@ //---------------------------------------------------------------------------- | ||
//---------------------------------------------------------------------------- | ||
if (modjewel) { | ||
if (global.modjewel) { | ||
log("modjewel global variable already defined") | ||
@@ -51,3 +46,6 @@ return | ||
var OriginalRequire = require | ||
global.modjewel = null | ||
var OriginalRequire = global.require | ||
var OriginalDefine = global.define | ||
var NoConflict = false | ||
@@ -89,6 +87,7 @@ | ||
var fromModule = currentModule ? currentModule.id : "<root>" | ||
error("module '" + moduleId + "' not found from '" + fromModule + "', must be preloaded") | ||
error("module '" + moduleId + "' not found from '" + fromModule + "', must be define()'d first") | ||
} | ||
var moduleDefFunction = ModulePreloadStore[moduleId] | ||
var factory = ModulePreloadStore[moduleId][0] | ||
var prereqs = ModulePreloadStore[moduleId][1] | ||
@@ -105,3 +104,24 @@ var module = create_module(moduleId) | ||
moduleDefFunction.call(null, newRequire, module.exports, module) | ||
var prereqModules = [] | ||
for (var i=0; i<prereqs.length; i++) { | ||
var prereqId = prereqs[i] | ||
var prereqModule | ||
if (prereqId == "require") prereqModule = newRequire | ||
else if (prereqId == "exports") prereqModule = module.exports | ||
else if (prereqId == "module") prereqModule = module | ||
else prereqModule = newRequire(prereqId) | ||
prereqModules.push(prereqModule) | ||
} | ||
if (typeof factory == "function") { | ||
var result = factory.apply(null, prereqModules) | ||
if (result) { | ||
module.exports = result | ||
} | ||
} | ||
else { | ||
module.exports = factory | ||
} | ||
} | ||
@@ -137,2 +157,3 @@ finally { | ||
exports: {}, | ||
prereqIds: [], | ||
moduleIdsRequired: [] | ||
@@ -149,8 +170,9 @@ } | ||
MainModule = create_module(null) | ||
require_define("modjewel", modjewel_module) | ||
require = get_require(MainModule) | ||
require.define({modjewel: modjewel_module}) | ||
modjewel = require("modjewel") | ||
global.require = get_require(MainModule) | ||
global.define = require_define | ||
global.define.amd = true | ||
global.modjewel = require("modjewel") | ||
} | ||
@@ -161,28 +183,43 @@ | ||
// a simplification of | ||
// http://wiki.commonjs.org/wiki/Modules/Transport/D | ||
// but only supports the first parameter | ||
// http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition | ||
// where id is required | ||
//---------------------------------------------------------------------------- | ||
function require_define(moduleSet) { | ||
for (var moduleName in moduleSet) { | ||
if (!hop(moduleSet, moduleName)) continue | ||
if (moduleName.match(/^\./)) { | ||
console.log("require.define(): moduleName in moduleSet must not start with '.': '" + moduleName + "'") | ||
function require_define(moduleId, prereqs, factory) { | ||
var rem = ["require", "exports", "module"] | ||
if (typeof moduleId != "string") { | ||
console.log("modjewel.define(): first parameter must be a string; was: " + moduleId) | ||
return | ||
} | ||
if (arguments.length == 2) { | ||
factory = prereqs | ||
prereqs = null | ||
} | ||
if (!prereqs || prereqs.length == 0) { | ||
prereqs = rem | ||
} | ||
if (typeof factory != "function") { | ||
if (factory) { | ||
ModulePreloadStore[moduleId] = [factory, prereqs] | ||
return | ||
} | ||
var moduleDefFunction = moduleSet[moduleName] | ||
if (typeof moduleDefFunction != "function") { | ||
console.log("require.define(): expecting a function as value of '" + moduleName + "' in moduleSet") | ||
return | ||
} | ||
if (hop(ModulePreloadStore, moduleName)) { | ||
console.log("require.define(): module '" + moduleName + "' has already been preloaded") | ||
return | ||
} | ||
console.log("modjewel.define(): factory was falsy: " + factory) | ||
return | ||
} | ||
if (moduleId.match(/^\./)) { | ||
console.log("modjewel.define(): moduleId must not start with '.': '" + moduleName + "'") | ||
return | ||
} | ||
if (hop(ModulePreloadStore, moduleId)) { | ||
console.log("modjewel.define(): module '" + moduleId + "' has already been defined") | ||
return | ||
} | ||
ModulePreloadStore[moduleName] = moduleDefFunction | ||
} | ||
ModulePreloadStore[moduleId] = [factory, prereqs] | ||
} | ||
@@ -301,3 +338,4 @@ | ||
require = OriginalRequire | ||
global.require = OriginalRequire | ||
global.define = OriginalDefine | ||
} | ||
@@ -304,0 +342,0 @@ |
{ | ||
"name": "modjewel", | ||
"description": "modjewel provides a require() function for use with CommonJS modules, designed for use in web browsers.", | ||
"version": "0.2.0", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/pmuellr/modjewel", | ||
@@ -6,0 +6,0 @@ "author": "Patrick Mueller", |
@@ -7,7 +7,9 @@ modjewel | ||
The `modjewel-require.js` file provides a `require()` | ||
function for use with [CommonJS](http://commonjs.org/) modules, | ||
designed for use in web browsers. | ||
The `modjewel-require.js` file provides `require()` and `define()` | ||
functions for use with [CommonJS](http://commonjs.org/) modules, | ||
designed for use in web browsers. The `define()` function is as | ||
specified in [Asynchronous Module Definition](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition) | ||
(AMD). | ||
Note that dynamic loading is not supported; see the note on `require.define()` below. | ||
Note that dynamic loading is not supported; see the note on `define()` below. | ||
@@ -47,3 +49,3 @@ | ||
require.define() | ||
define() | ||
----------------- | ||
@@ -54,5 +56,4 @@ | ||
The object passed to this function is described in the | ||
[Transport/D proposal](http://wiki.commonjs.org/wiki/Modules/Transport/D), | ||
but the second parameter is ignored. | ||
The object passed to this function is described in | ||
[Asynchronous Module Definition](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition). | ||
@@ -120,11 +121,11 @@ | ||
module2transportd.py | ||
module2amd.py | ||
-------------------- | ||
Convert CommonJS modules to Transport/D format. It can also generate a HTML | ||
Convert CommonJS modules to AMD format. It can also generate a HTML | ||
test driver to test the modules in a browser. It generates files named | ||
`(original base name).transportd.js` from files named `(original base name).js`. | ||
`(original base name).amd.js` from files named `(original base name).js`. | ||
The generated files have code prefixing and suffixing the original file | ||
contents with a `require.define()` invocation. The contents of the file | ||
contents with a `define()` invocation. The contents of the file | ||
are otherwise unchanged, and the line numbers for the content will be the | ||
@@ -131,0 +132,0 @@ same in both files. |
@@ -55,2 +55,9 @@ var test = require('test') | ||
//------------------------------------------------------------------------------ | ||
test.assert(window.require != null, "require is not null") | ||
test.assert(window.define != null, "define is not null") | ||
modjewel.noConflict() | ||
test.assert(window.require == null, "require is null") | ||
test.assert(window.define == null, "define is null") | ||
//------------------------------------------------------------------------------ | ||
test.print('DONE', 'info') |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
459380
179
9664
0
135
0
18
2