Skip to content

Commit fcdaa4e

Browse files
authored
Add TypeScript type declarations to the npm package (#1563)
Closes #13
1 parent 7954190 commit fcdaa4e

File tree

10 files changed

+55
-25
lines changed

10 files changed

+55
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.45.0-rc.2
2+
3+
### JS API
4+
5+
* Ship TypeScript type declarations with the package.
6+
17
## 1.45.0-rc.1
28

39
### JS API

package/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
},
1919
"dependencies": {
2020
"chokidar": ">=3.0.0 <4.0.0",
21-
"immutable": "^4.0.0"
21+
"immutable": "^4.0.0",
22+
"source-map-js": ">=0.6.2 <2.0.0"
2223
},
23-
"keywords": ["style", "scss", "sass", "preprocessor", "css"]
24+
"keywords": ["style", "scss", "sass", "preprocessor", "css"],
25+
"types": "types/index.d.ts"
2426
}

pkg/sass_api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0-beta.22
2+
3+
* No user-visible changes.
4+
15
## 1.0.0-beta.21
26

37
* No user-visible changes.

pkg/sass_api/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 1.0.0-beta.21
5+
version: 1.0.0-beta.22
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: '>=2.12.0 <3.0.0'
1111

1212
dependencies:
13-
sass: 1.45.0-rc.1
13+
sass: 1.45.0-rc.2
1414

1515
dependency_overrides:
1616
sass: {path: ../..}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.45.0-rc.1
2+
version: 1.45.0-rc.2
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

tool/grind.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:path/path.dart' as p;
1212
import 'package:source_span/source_span.dart';
1313

1414
import 'grind/synchronize.dart';
15+
import 'grind/utils.dart';
1516

1617
export 'grind/bazel.dart';
1718
export 'grind/benchmark.dart';
@@ -39,6 +40,7 @@ void main(List<String> args) {
3940
json.decode(File("package/package.json").readAsStringSync())
4041
as Map<String, dynamic>;
4142
pkg.npmReadme.fn = () => _readAndResolveMarkdown("package/README.npm.md");
43+
pkg.npmAdditionalFiles.fn = _fetchJSTypes;
4244
pkg.standaloneName.value = "dart-sass";
4345
pkg.githubUser.fn = () => Platform.environment["GH_USER"];
4446
pkg.githubPassword.fn = () => Platform.environment["GH_TOKEN"];
@@ -144,6 +146,20 @@ String _readAndResolveMarkdown(String path) => File(path)
144146
return included.substring(headerMatch.end, sectionEnd).trim();
145147
});
146148

149+
/// Returns a map from JS type declaration file names to their contnets.
150+
Map<String, String> _fetchJSTypes() {
151+
var languageRepo =
152+
cloneOrCheckout("https://github.com/sass/sass", "main", name: 'language');
153+
154+
var typeRoot = p.join(languageRepo, 'js-api-doc');
155+
return {
156+
for (var entry in Directory(typeRoot).listSync(recursive: true))
157+
if (entry is File && entry.path.endsWith('.d.ts'))
158+
p.join('types', p.relative(entry.path, from: typeRoot)):
159+
entry.readAsStringSync()
160+
};
161+
}
162+
147163
/// Throws a nice [SourceSpanException] associated with [match].
148164
void _matchError(Match match, String message, {Object? url}) {
149165
var file = SourceFile.fromString(match.input, url: url);

tool/grind/bazel.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Future<void> updateBazel() async {
1616

1717
run("npm", arguments: ["install", "-g", "yarn"]);
1818

19-
var repo = await cloneOrCheckout(
20-
"https://github.com/bazelbuild/rules_sass.git", "main");
19+
var repo =
20+
cloneOrCheckout("https://github.com/bazelbuild/rules_sass.git", "main");
2121

2222
var packageFile = File(p.join(repo, "sass", "package.json"));
2323
log("updating ${packageFile.path}");

tool/grind/benchmark.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ Future<void> benchmarkGenerate() async {
3232
".foo {a: b}", math.pow(2, 17),
3333
footer: '.bar {@extend .foo}');
3434

35-
await cloneOrCheckout("https://github.com/twbs/bootstrap", "v4.1.3");
35+
cloneOrCheckout("https://github.com/twbs/bootstrap", "v4.1.3");
3636
await _writeNTimes("${sources.path}/bootstrap.scss",
3737
"@import '../bootstrap/scss/bootstrap';", 16);
3838

39-
await cloneOrCheckout("https://github.com/alex-page/sass-a11ycolor",
39+
cloneOrCheckout("https://github.com/alex-page/sass-a11ycolor",
4040
"2e7ef93ec06f8bbec80b632863e4b2811618af89");
4141
File("${sources.path}/a11ycolor.scss").writeAsStringSync("""
4242
@import '../sass-a11ycolor/dist';
@@ -55,14 +55,14 @@ Future<void> benchmarkGenerate() async {
5555
}
5656
""");
5757

58-
await cloneOrCheckout("https://github.com/zaydek/duomo", "v0.7.12");
58+
cloneOrCheckout("https://github.com/zaydek/duomo", "v0.7.12");
5959
File("${sources.path}/duomo.scss")
6060
.writeAsStringSync("@import '../duomo/scripts/duomo.scss'");
6161

6262
// Note: This version only supports Node Sass 5.x, which only supports up to
6363
// Node 14.x. Once there's a version that support Node Sass 6.x, we should use
6464
// that instead.
65-
var carbon = await cloneOrCheckout(
65+
var carbon = cloneOrCheckout(
6666
"https://github.com/carbon-design-system/ibm-cloud-cognitive",
6767
"@carbon/[email protected]");
6868
await runAsync("npm", arguments: ["install"], workingDirectory: carbon);
@@ -101,9 +101,8 @@ Future<void> _writeNTimes(String path, String text, num times,
101101
@Depends(benchmarkGenerate, "pkg-compile-snapshot", "pkg-compile-native",
102102
"pkg-npm-release")
103103
Future<void> benchmark() async {
104-
var libsass =
105-
await cloneOrCheckout('https://github.com/sass/libsass', 'master');
106-
var sassc = await cloneOrCheckout('https://github.com/sass/sassc', 'master');
104+
var libsass = cloneOrCheckout('https://github.com/sass/libsass', 'master');
105+
var sassc = cloneOrCheckout('https://github.com/sass/sassc', 'master');
107106

108107
await runAsync("make",
109108
runOptions: RunOptions(

tool/grind/frameworks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Future<void> fetchBulma() => _getLatestRelease('jgthms/bulma');
3131
/// If [pattern] is passed, this will clone the latest release that matches that
3232
/// pattern.
3333
Future<void> _getLatestRelease(String slug, {Pattern? pattern}) async {
34-
await cloneOrCheckout('git://github.com/$slug',
34+
cloneOrCheckout('git://github.com/$slug',
3535
await _findLatestRelease(slug, pattern: pattern));
3636
}
3737

tool/grind/utils.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'dart:async';
65
import 'dart:convert';
76
import 'dart:io';
87

@@ -45,29 +44,33 @@ String environment(String name) {
4544
/// Ensure that the repository at [url] is cloned into the build directory and
4645
/// pointing to [ref].
4746
///
47+
/// If [name] is passed, it's used as the basename of the directory for the
48+
/// repo. Otherwise, [url]'s basename is used.
49+
///
4850
/// Returns the path to the repository.
49-
Future<String> cloneOrCheckout(String url, String ref) async {
50-
var name = p.url.basename(url);
51-
if (p.url.extension(name) == ".git") name = p.url.withoutExtension(name);
51+
String cloneOrCheckout(String url, String ref, {String? name}) {
52+
if (name == null) {
53+
name = p.url.basename(url);
54+
if (p.url.extension(name) == ".git") name = p.url.withoutExtension(name);
55+
}
5256

5357
var path = p.join("build", name);
5458

5559
if (!Directory(p.join(path, '.git')).existsSync()) {
5660
delete(Directory(path));
57-
await runAsync("git", arguments: ["init", path]);
58-
await runAsync("git",
61+
run("git", arguments: ["init", path]);
62+
run("git",
5963
arguments: ["config", "advice.detachedHead", "false"],
6064
workingDirectory: path);
61-
await runAsync("git",
65+
run("git",
6266
arguments: ["remote", "add", "origin", url], workingDirectory: path);
6367
} else {
6468
log("Updating $url");
6569
}
6670

67-
await runAsync("git",
71+
run("git",
6872
arguments: ["fetch", "origin", "--depth=1", ref], workingDirectory: path);
69-
await runAsync("git",
70-
arguments: ["checkout", "FETCH_HEAD"], workingDirectory: path);
73+
run("git", arguments: ["checkout", "FETCH_HEAD"], workingDirectory: path);
7174
log("");
7275

7376
return path;

0 commit comments

Comments
 (0)