@@ -5,24 +5,36 @@ var path = require('path');
55var glob = require ( 'glob' ) ;
66var fs = require ( 'fs' ) ;
77var util = require ( './util' ) ;
8+ var yaml = require ( 'js-yaml' ) ;
89
910module . exports = function ( gulp , plugins , config ) {
1011 return function ( ) {
1112 var tempFile = '_analyzer.dart' ;
1213 return util . forEachSubDirSequential (
1314 config . dest ,
1415 function ( dir ) {
15- var srcFiles = [ ] . slice . call ( glob . sync ( 'web/**/*.dart' , {
16+ var pubspecContents = fs . readFileSync ( path . join ( dir , 'pubspec.yaml' ) ) ;
17+ var pubspec = yaml . safeLoad ( pubspecContents ) ;
18+ var packageName = pubspec . name ;
19+
20+ var libFiles = [ ] . slice . call ( glob . sync ( 'lib/**/*.dart' , {
21+ cwd : dir
22+ } ) ) ;
23+
24+ var webFiles = [ ] . slice . call ( glob . sync ( 'web/**/*.dart' , {
1625 cwd : dir
1726 } ) ) ;
1827
1928 var testFiles = [ ] . slice . call ( glob . sync ( 'test/**/*_spec.dart' , {
2029 cwd : dir
2130 } ) ) ;
2231 var analyzeFile = [ 'library _analyzer;' ] ;
23- srcFiles . concat ( testFiles ) . forEach ( function ( fileName , index ) {
32+ libFiles . concat ( testFiles ) . concat ( webFiles ) . forEach ( function ( fileName , index ) {
2433 if ( fileName !== tempFile && fileName . indexOf ( "/packages/" ) === - 1 ) {
25- analyzeFile . push ( 'import "./' + fileName + '" as mod' + index + ';' ) ;
34+ if ( fileName . indexOf ( 'lib' ) == 0 ) {
35+ fileName = 'package:' + packageName + '/' + path . relative ( 'lib' , fileName ) ;
36+ }
37+ analyzeFile . push ( 'import "' + fileName + '" as mod' + index + ';' ) ;
2638 }
2739 } ) ;
2840 fs . writeFileSync ( path . join ( dir , tempFile ) , analyzeFile . join ( '\n' ) ) ;
@@ -33,15 +45,8 @@ module.exports = function(gulp, plugins, config) {
3345 ) ;
3446
3547 function analyze ( dirName , done ) {
36- // analyze files in lib directly – or you mess up package: urls
37- var sources = [ ] . slice . call ( glob . sync ( 'lib/**/*.dart' , {
38- cwd : dirName
39- } ) ) ;
40-
41- sources . push ( tempFile ) ;
42-
4348 //TODO remove --package-warnings once dartanalyzer handles transitive libraries
44- var args = [ '--fatal-warnings' , '--package-warnings' ] . concat ( sources ) ;
49+ var args = [ '--fatal-warnings' , '--package-warnings' ] . concat ( tempFile ) ;
4550
4651 var stream = spawn ( config . command , args , {
4752 // inherit stdin and stderr, but filter stdout
0 commit comments