Sha256: 658b9681a9a75addf7754e7a6090fb07c9ec51ecc10e4ab2b14c6269abcd3adc

Contents?: true

Size: 1.04 KB

Versions: 438

Compression:

Stored size: 1.04 KB

Contents

/*jshint node: true */
var inserted,
    Module = require('module'),
    fs = require('fs'),
    existingExtFn = Module._extensions['.js'],
    amdefineRegExp = /amdefine\.js/;

inserted  = "if (typeof define !== 'function') {var define = require('amdefine')(module)}";

//From the node/lib/module.js source:
function stripBOM(content) {
    // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
    // because the buffer-to-string conversion in `fs.readFileSync()`
    // translates it to FEFF, the UTF-16 BOM.
    if (content.charCodeAt(0) === 0xFEFF) {
        content = content.slice(1);
    }
    return content;
}

//Also adapted from the node/lib/module.js source:
function intercept(module, filename) {
    var content = stripBOM(fs.readFileSync(filename, 'utf8'));

    if (!amdefineRegExp.test(module.id)) {
        content = inserted + content;
    }

    module._compile(content, filename);
}

intercept._id = 'amdefine/intercept';

if (!existingExtFn._id || existingExtFn._id !== intercept._id) {
    Module._extensions['.js'] = intercept;
}

Version data entries

438 entries across 223 versions & 32 rubygems

Version Path
cortex-0.1.3 spec/dummy/node_modules/amdefine/intercept.js
ela-4.0.0 node_modules/amdefine/intercept.js
ela-3.4.3 node_modules/amdefine/intercept.js
ela-3.4.2 node_modules/amdefine/intercept.js
ela-3.4.0 node_modules/amdefine/intercept.js
ela-3.3.1 node_modules/amdefine/intercept.js
ela-3.3.0 node_modules/amdefine/intercept.js
ela-3.2.0 node_modules/amdefine/intercept.js
ela-3.1.1 node_modules/amdefine/intercept.js
ela-3.1.0 node_modules/amdefine/intercept.js
ela-3.0.0 node_modules/amdefine/intercept.js
ela-2.0.0 node_modules/amdefine/intercept.js
ela-1.1.0 node_modules/amdefine/intercept.js
lanes-0.8.0 node_modules/amdefine/intercept.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/intercept.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/intercept.js
select_all-rails-0.3.1 node_modules/amdefine/intercept.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/intercept.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/amdefine/intercept.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/intercept.js