]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/node_modules/coffeestack/node_modules/source-map/node_modules/amdefine/intercept.js
771a98301fbf211e1052043bf5b35853c072cd29
3 Module
= require('module'),
5 existingExtFn
= Module
._extensions
['.js'],
6 amdefineRegExp
= /amdefine\.js/;
8 inserted
= "if (typeof define !== 'function') {var define = require('amdefine')(module)}";
10 //From the node/lib/module.js source:
11 function stripBOM(content
) {
12 // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
13 // because the buffer-to-string conversion in `fs.readFileSync()`
14 // translates it to FEFF, the UTF-16 BOM.
15 if (content
.charCodeAt(0) === 0xFEFF) {
16 content
= content
.slice(1);
21 //Also adapted from the node/lib/module.js source:
22 function intercept(module
, filename
) {
23 var content
= stripBOM(fs
.readFileSync(filename
, 'utf8'));
25 if (!amdefineRegExp
.test(module
.id
)) {
26 content
= inserted
+ content
;
29 module
._compile(content
, filename
);
32 intercept
._id
= 'amdefine/intercept';
34 if (!existingExtFn
._id
|| existingExtFn
._id
!== intercept
._id
) {
35 Module
._extensions
['.js'] = intercept
;