2017-07-06 23:40:45 +02:00
|
|
|
// Copyright 2017 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2017-07-07 02:36:15 +02:00
|
|
|
import 'package:stream_channel/stream_channel.dart';
|
2017-07-06 23:40:45 +02:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2017-12-08 02:18:34 +01:00
|
|
|
import 'package:sass/src/io.dart';
|
|
|
|
|
2017-07-07 02:36:15 +02:00
|
|
|
hybridMain(StreamChannel channel) async {
|
2017-07-06 23:40:45 +02:00
|
|
|
if (!new Directory("build/npm").existsSync()) {
|
2017-10-21 01:56:54 +02:00
|
|
|
throw "NPM package is not built. Run pub run grinder npm_package.";
|
2017-07-06 23:40:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 22:41:31 +01:00
|
|
|
var lastModified = new File("build/npm/package.json").lastModifiedSync();
|
|
|
|
var entriesToCheck = new Directory("lib").listSync(recursive: true).toList();
|
|
|
|
|
|
|
|
// If we have a dependency override, "pub run" will touch the lockfile to mark
|
|
|
|
// it as newer than the pubspec, which makes it unsuitable to use for
|
|
|
|
// freshness checking.
|
|
|
|
if (new File("pubspec.yaml")
|
|
|
|
.readAsStringSync()
|
|
|
|
.contains("dependency_overrides")) {
|
|
|
|
entriesToCheck.add(new File("pubspec.yaml"));
|
|
|
|
} else {
|
|
|
|
entriesToCheck.add(new File("pubspec.lock"));
|
|
|
|
}
|
|
|
|
|
2017-07-06 23:40:45 +02:00
|
|
|
for (var entry in entriesToCheck) {
|
2017-07-07 02:36:15 +02:00
|
|
|
if (entry is File) {
|
|
|
|
var entryLastModified = entry.lastModifiedSync();
|
|
|
|
if (lastModified.isBefore(entryLastModified)) {
|
2017-12-01 22:41:31 +01:00
|
|
|
throw "${entry.path} was modified after NPM package was generated.\n"
|
2017-12-01 23:20:49 +01:00
|
|
|
"Run pub run grinder before_test.";
|
2017-07-07 02:36:15 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 23:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
channel.sink.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensures that the NPM package is compiled and up-to-date.
|
|
|
|
///
|
2017-10-21 01:56:54 +02:00
|
|
|
/// This is safe to call even outside the Dart VM.
|
2017-12-08 02:18:34 +01:00
|
|
|
Future ensureNpmPackage() async {
|
|
|
|
// spawnHybridUri() doesn't currently work on Windows and Node due to busted
|
|
|
|
// path handling in the SDK.
|
|
|
|
if (isNode && isWindows) return;
|
|
|
|
|
2017-10-21 01:56:54 +02:00
|
|
|
var channel = spawnHybridUri("/test/ensure_npm_package.dart");
|
2017-12-08 02:18:34 +01:00
|
|
|
await channel.stream.toList();
|
2017-07-06 23:40:45 +02:00
|
|
|
}
|