Skip to content

Commit 079ca97

Browse files
authored
Separate out minified and non-minified JS compilation tasks (#245)
1 parent e63b8e1 commit 079ca97

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ install:
4545
- if-node . "$HOME/.nvm/nvm.sh"
4646
- if-node nvm install "$NODE_VERSION"
4747
- if-node nvm use "$NODE_VERSION"
48-
- SASS_MINIFY_JS=false if-node pub run grinder before_test
48+
- if-node pub run grinder before_test
4949

5050
# Download sass-spec and install its dependencies if we're running specs.
5151
- if-specs() { if [ "$TASK" = specs ]; then "$@"; fi }

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ install:
1717
- ps: >-
1818
If ($env:NODE -eq "true") {
1919
Install-Product node ''
20-
$env:SASS_MINIFY_JS = "false"
2120
pub run grinder npm_package
2221
}
2322

tool/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ travis_cmd pub run grinder github_release
2828
travis_fold end github
2929

3030
travis_fold start npm
31-
travis_cmd pub run grinder npm_package
31+
travis_cmd pub run grinder npm_release_package
3232
travis_cmd npm publish build/npm
3333
travis_cmd npm publish build/npm-old
3434
travis_fold end npm

tool/grind.dart

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:collection/collection.dart';
1212
import 'package:crypto/crypto.dart';
1313
import 'package:grinder/grinder.dart';
1414
import 'package:http/http.dart' as http;
15+
import 'package:meta/meta.dart';
1516
import 'package:node_preamble/preamble.dart' as preamble;
1617
import 'package:pub_semver/pub_semver.dart';
1718
import 'package:source_span/source_span.dart';
@@ -85,34 +86,56 @@ package() async {
8586
client.close();
8687
}
8788

88-
@Task('Compile to JS.')
89-
js() {
89+
@Task('Compile to JS in dev mode.')
90+
js() => _js(release: false);
91+
92+
@Task('Compile to JS in release mode.')
93+
js_release() => _js(release: true);
94+
95+
/// Compiles Sass to JS.
96+
///
97+
/// If [release] is `true`, this compiles minified with
98+
/// --trust-type-annotations. Otherwise, it compiles unminified with pessimistic
99+
/// type checks.
100+
void _js({@required bool release}) {
90101
_ensureBuild();
91102
var destination = new File('build/sass.dart.js');
92103

93104
var args = [
94-
'--trust-type-annotations',
95105
'-Dnode=true',
96106
'-Dversion=$_version',
97107
'-Ddart-version=$_dartVersion',
98108
];
99-
if (Platform.environment["SASS_MINIFY_JS"] != "false") args.add("--minify");
109+
if (release) args..add("--minify")..add("--trust-type-annotations");
100110

101111
Dart2js.compile(new File('bin/sass.dart'),
102112
outFile: destination, extraArgs: args);
103113
var text = destination.readAsStringSync();
104114
destination.writeAsStringSync(preamble.getPreamble() + text);
105115
}
106116

107-
@Task('Build a pure-JS npm package.')
117+
@Task('Build a pure-JS dev-mode npm package.')
108118
@Depends(js)
109-
npm_package() {
119+
npm_package() => _npm(release: false);
120+
121+
@Task('Build a pure-JS release-mode npm package.')
122+
@Depends(js_release)
123+
npm_release_package() => _npm(release: true);
124+
125+
/// Builds a pure-JS npm package.
126+
///
127+
/// If [release] is `true`, this compiles minified with
128+
/// --trust-type-annotations. Otherwise, it compiles unminified with pessimistic
129+
/// type checks.
130+
void _npm({@required bool release}) {
110131
var json = JSON.decode(new File('package/package.json').readAsStringSync())
111132
as Map<String, dynamic>;
112133
json['version'] = _version;
113134

114135
_writeNpmPackage('build/npm', json);
115-
_writeNpmPackage('build/npm-old', json..addAll({"name": "dart-sass"}));
136+
if (release) {
137+
_writeNpmPackage('build/npm-old', json..addAll({"name": "dart-sass"}));
138+
}
116139
}
117140

118141
@Task('Installs dependencies from npm.')

0 commit comments

Comments
 (0)