Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

add skip #856

Merged
merged 1 commit into from
Jun 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/spm-build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ commander
.option('-f, --force', 'force option')
.option('--include [include]', 'determine which files will be included, optional: self, relative, all, standalone')
.option('--ignore [ignore]', 'determine which id will not be transported')
.option('--skip [skip]', 'determine which id will not be parsed when analyse')
.option('--idleading [idleading]', 'prefix of module name, default: {{name}}/{{version}}')
.option('--zip', 'archive by zip')
.parse(process.argv);
Expand All @@ -41,6 +42,7 @@ var args = {
cwd: commander.inputDirectory,
include: commander.include,
ignore: commander.ignore,
skip: commander.skip,
idleading: commander.idleading,
zip: commander.zip,
force: commander.force,
Expand Down
3 changes: 2 additions & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function build(args, cb) {
// add package info
try {
var pkg = new Package(args.cwd, {
extraDeps: {handlebars: 'handlebars-runtime'}
extraDeps: {handlebars: 'handlebars-runtime'},
skip: args.skip
});
log.info('package', 'analyse infomation');
log.info('package', 'dependencies: ' + Object.keys(pkg.dependencies));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"serve-spm": "^0.3.1",
"spmrc": "~1.0.0",
"tar": "~0.1.19",
"umi": "~0.3.0",
"umi": "~0.4.0",
"vinyl-source-stream": "~0.1.0",
"win-spawn": "~2.0.0"
},
Expand Down
13 changes: 13 additions & 0 deletions tests/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ describe('build', function() {
});
});

it('can ignore when parse', function(done) {
var opt = {
cwd: join(base, 'ignore'),
dest: dest,
skip: ['crypto']
};
build(opt, function(err) {
should.not.exist(err);
assets('ignore', dest);
done();
});
});

function assets(prefix, dest) {
var expect = join(base, 'expect', prefix);
glob.sync('**/*', {cwd: expect})
Expand Down
13 changes: 13 additions & 0 deletions tests/build/expect/ignore/a/1.0.0/index-debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
define("a/1.0.0/index-debug", [], function(require, exports, module) {
(function() {
var _rng;
if (typeof require === 'function') {
try {
var _rb = require("crypto").randomBytes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了 skip 之后,require("crypto") 仍在源码中,这样不会报错吗?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里假设 crypto 是 nodejs 端的逻辑,浏览器里运行时不会执行到。需求来自:#854

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白,但这用例实际上会运行到。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经 try/catch 了—
Sent from Mailbox for iPhone

On Sat, Jul 19, 2014 at 12:56 AM, 偏右 notifications@github.com wrote:

@@ -0,0 +1,13 @@
+define("a/1.0.0/index-debug", [], function(require, exports, module) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑把 ignore 改成 noTransport 是不是更好理解—
Sent from Mailbox for iPhone

On Sat, Jul 19, 2014 at 10:49 AM, haoliang gao sakura9515@gmail.com
wrote:

已经 try/catch 了—
Sent from Mailbox for iPhone
On Sat, Jul 19, 2014 at 12:56 AM, 偏右 notifications@github.com wrote:

@@ -0,0 +1,13 @@
+define("a/1.0.0/index-debug", [], function(require, exports, module) {

_rng = _rb && function() {
return _rb(16);
};
} catch (e) {}
}
})();
});
1 change: 1 addition & 0 deletions tests/build/expect/ignore/a/1.0.0/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define("a/1.0.0/index",[],function(n){!function(){var t;if("function"==typeof n)try{var c=n("crypto").randomBytes;t=c&&function(){return c(16)}}catch(f){}}()});
11 changes: 11 additions & 0 deletions tests/build/ignore/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function() {
var _rng;
if (typeof require === 'function') {
try {
var _rb = require('crypto').randomBytes;
_rng = _rb && function() {
return _rb(16);
};
} catch (e) {}
}
})();
4 changes: 4 additions & 0 deletions tests/build/ignore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "a",
"version": "1.0.0"
}