Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Nov 5, 2015
1 parent b69106e commit 8bbace8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,12 @@ fis.hook('amd'{
* `skipBuiltinModules` 默认为 `false`, 只有在 `forwardDeclaration` 启动的时候才有效,用来设置前置依赖列表中是否跳过内置模块如: `require`, `module`, `exports`
* `extList` 默认为 `['.js', '.coffee', '.jsx', '.es6']`,当引用模块时没有指定后缀,该插件会尝试这些后缀。
* `tab` 默认为 `2`, 用来设置包裹时,内容缩进的空格数。
* `ignoreDependencies` 默认为空,当分析到某个文件的时候,此插件会把当前文件标记依赖目标文件。如果你希望部分文件不这么做,那么请设置此插件。

```js
fis.hook('amd', {
ignoreDependencies: [
'angular2/angular2'
]
});
```
25 changes: 24 additions & 1 deletion amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ function autowrap(info, conf) {
function parse(file, content, conf) {
var ret = file._amdAnalyzed || analyze(content);
var forgetDefine = file.isMod === false || file.isPartial;
var ignoreDependencies = opts.ignoreDependencies || [];
var isIgnored = function(str) {
var found = false;

ignoreDependencies.every(function(item) {
if (item && item.exec && item.exec(str)) {
found = true;
return false;
}
return true;
});

return found;
};

delete file._amdAnalyzed;

Expand Down Expand Up @@ -227,7 +241,7 @@ function parse(file, content, conf) {
module.deps.forEach(function(elem) {

// 不需要查找依赖,如果是 require、module、或者 exports.
if (~'require,module,exports'.indexOf(elem.value)) {
if (~'require,module,exports'.indexOf(elem.value) || isIgnored('/' + elem.value)) {
deps.push(elem.raw);
args.push(argsRaw.shift());
return;
Expand Down Expand Up @@ -269,6 +283,11 @@ function parse(file, content, conf) {

var elem = item.node.arguments[0];
var v = elem.value;

if (isIgnored('/' + v)) {
return;
}

var info = fis.util.stringQuote(elem.raw);
v = info.rest.trim();
var parts = v.split('!');
Expand Down Expand Up @@ -418,6 +437,10 @@ function parse(file, content, conf) {
var async = conf.globalAsyncAsSync ? req.markAsync : !req.markSync;

(req.deps || []).forEach(function(elem) {
if (isIgnored('/' + elem.value)) {
return;
}

var v = elem.raw;
var info = fis.util.stringQuote(v);
v = info.rest.trim();
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ var entry = module.exports = function(fis, opts) {
opts.shim = normalized;
})();

var ignoreDependencies = opts.ignoreDependencies || [];
if (typeof ignoreDependencies === 'string') {
ignoreDependencies = ignoreDependencies.split(/\s*,\s*/);
} else if (!Array.isArray(ignoreDependencies)) {
ignoreDependencies = [ignoreDependencies];
}
opts.ignoreDependencies = ignoreDependencies.map(function(item) {
return typeof item === 'string' ? fis.util.glob(item) : item;
});

fis.on('lookup:file', lookup);
fis.on('standard:js', function(info) {
var file = info.file;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fis3-hook-amd",
"version": "0.1.6",
"version": "0.1.7",
"description": "fis3 amd",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8bbace8

Please sign in to comment.