Skip to content

Commit 87cf434

Browse files
committed
chore(sources): intro modules_dart; move analyzer code there
We have Dart code in `angular2` module that ought to be in its own package. Examples include Dart analysis plugins, and potentially the transformers (although transformers cannot be moved out just yet). However, this code is Dart-only and it doesn’t make sense to use JS directory layout for it. This commit introduces a sub-directory called `modules_dart`. All modules in this directory are pure Dart packages using standard pub directory layout. The code in these packages never gets transpiled. It is directly copied to `dist` unmodified, except an adjustment in relative paths in `pubspec.yaml` files.
1 parent 4bab25b commit 87cf434

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

gulpfile.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,67 @@ gulp.task('test.transpiler.unittest', function() {
508508
// -----------------
509509
// orchestrated targets
510510

511+
// Pure Dart packages only contain Dart code and conform to pub package layout.
512+
// These packages need no transpilation. All code is copied over to `dist`
513+
// unmodified and directory structure is preserved.
514+
//
515+
// This task also fixes relative `dependency_overrides` paths in `pubspec.yaml`
516+
// files.
517+
gulp.task('build/pure-packages.dart', function() {
518+
var through2 = require('through2');
519+
var yaml = require('js-yaml');
520+
var originalPrefix = '../../dist/dart/';
521+
522+
return gulp
523+
.src([
524+
'modules_dart/**/*.dart',
525+
'modules_dart/**/pubspec.yaml',
526+
])
527+
.pipe(through2.obj(function(file, enc, done) {
528+
if (file.path.endsWith('pubspec.yaml')) {
529+
// Pure packages specify dependency_overrides relative to
530+
// `modules_dart`, so they have to walk up and into `dist`.
531+
//
532+
// Example:
533+
//
534+
// dependency_overrides:
535+
// angular2:
536+
// path: ../../dist/dart/angular2
537+
//
538+
// When we copy a pure package into `dist` the relative path
539+
// must be updated. The code below replaces paths accordingly.
540+
// So the example above is turned into:
541+
//
542+
// dependency_overrides:
543+
// angular2:
544+
// path: ../angular2
545+
//
546+
var pubspec = yaml.safeLoad(file.contents.toString());
547+
var overrides = pubspec['dependency_overrides'];
548+
if (overrides) {
549+
Object.keys(overrides).forEach(function(pkg) {
550+
var overridePath = overrides[pkg]['path'];
551+
if (overridePath.startsWith(originalPrefix)) {
552+
overrides[pkg]['path'] = overridePath.replace(originalPrefix, '../');
553+
}
554+
});
555+
file.contents = new Buffer(yaml.safeDump(pubspec));
556+
}
557+
}
558+
this.push(file);
559+
done();
560+
}))
561+
.pipe(gulp.dest('dist/dart'));
562+
});
563+
511564
// Builds all Dart packages, but does not compile them
512565
gulp.task('build/packages.dart', function(done) {
513-
runSequence('build/tree.dart', 'build/format.dart', done);
566+
runSequence(
567+
'build/tree.dart',
568+
// Run after 'build/tree.dart' because broccoli clears the dist/dart folder
569+
'build/pure-packages.dart',
570+
'build/format.dart',
571+
done);
514572
});
515573

516574
// Builds and compiles all Dart packages
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: angular2_analysis_plugin
2+
version: 0.0.0
3+
description: Dart analyzer plugin for Angular 2
4+
environment:
5+
sdk: '>=1.9.0-dev.8.0'
6+
dependencies:
7+
angular2: '0.0.0'
8+
analyzer: '^0.24.4'
9+
dependency_overrides:
10+
angular2:
11+
path: ../../dist/dart/angular2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: angular2_analysis_server
2+
version: 0.0.0
3+
description: Dart analyzer server plugin for Angular 2
4+
environment:
5+
sdk: '>=1.9.0-dev.8.0'
6+
dependencies:
7+
analyzer: '^0.24.4'

scripts/publish/pubspec_cleaner.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,16 @@ var doc = yaml.safeLoad(fs.readFileSync(pubspecFile, 'utf8'));
1515
// Pub does not allow publishing with dependency_overrides
1616
delete doc['dependency_overrides'];
1717

18+
// Overwrite temporary values with real values
19+
delete doc['version'];
20+
delete doc['authors'];
21+
delete doc['homepage']
22+
23+
var BASE_PACKAGE_JSON = require('../../package.json');
24+
doc['version'] = BASE_PACKAGE_JSON.version;
25+
doc['homepage'] = BASE_PACKAGE_JSON.homepage;
26+
doc['authors'] = Object.keys(BASE_PACKAGE_JSON.contributors).map(function(name) {
27+
return name + ' <' + BASE_PACKAGE_JSON.contributors[name] + '>';
28+
});
29+
1830
fs.writeFileSync(pubspecFile, yaml.safeDump(doc));

0 commit comments

Comments
 (0)