Skip to content

Commit

Permalink
Make it possible to build npm with a linked language repo (#2214)
Browse files Browse the repository at this point in the history
This makes several changes:

* It renames the `UPDATE_SASS_PROTOCOL` environment variable used by
  the Grinder `protobuf` task to `UPDATE_SASS_SASS_REPO` to make it
  more generic and so usable by other tasks. The previous name still
  works but is considered deprecated.

* The `pkg-npm-*` grinder tasks now respects the
  `UPDATE_SASS_SASS_REPO` environment variable. This allows repos to
  ensure that the linked language repo's version of the TypeScript
  types are used when building the npm package.

* `UPDATE_SASS_SASS_REPO=false` is set for all the `pkg-npm-*` tasks
  run by this repo, so that they will use the linked language repo's
  version of the TypeScript types.

Co-authored-by: Carlos (Goodwine) <2022649+Goodwine@users.noreply.github.com>
  • Loading branch information
nex3 and Goodwine authored Apr 11, 2024
1 parent 1137797 commit c5aff1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/util/initialize/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ runs:

- name: Generate Dart from protobuf
run: dart run grinder protobuf
env: {UPDATE_SASS_PROTOCOL: false}
env: {UPDATE_SASS_SASS_REPO: false}
shell: bash
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
- name: Deploy
run: dart run grinder pkg-npm-deploy
env:
UPDATE_SASS_SASS_REPO: false
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"

deploy_bazel:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ jobs:

- name: Build JS
run: dart run grinder pkg-npm-dev
env: {UPDATE_SASS_SASS_REPO: false}

- name: Check out Sass specification
uses: sass/clone-linked-repo@v1
Expand Down Expand Up @@ -203,6 +204,7 @@ jobs:

- name: Build JS
run: dart run grinder pkg-npm-dev
env: {UPDATE_SASS_SASS_REPO: false}

- name: Install built dependencies
run: npm install
Expand Down Expand Up @@ -282,6 +284,7 @@ jobs:
node-version: ${{ matrix.node-version }}

- run: dart run grinder pkg-npm-dev
env: {UPDATE_SASS_SASS_REPO: false}
- name: Run tests
run: dart run test -t node -j 2

Expand All @@ -303,6 +306,7 @@ jobs:
github-token: ${{ github.token }}

- run: dart run grinder pkg-npm-dev
env: {UPDATE_SASS_SASS_REPO: false}
- name: Run tests
run: dart run test -p chrome -j 2
env:
Expand Down
24 changes: 18 additions & 6 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ String _readAndResolveMarkdown(String path) => File(path)

/// Returns a map from JS type declaration file names to their contnets.
Map<String, String> _fetchJSTypes() {
var languageRepo =
cloneOrCheckout("https://github.com/sass/sass", "main", name: 'language');
var languageRepo = _updateLanguageRepo();

var typeRoot = p.join(languageRepo, 'js-api-doc');
return {
Expand Down Expand Up @@ -251,10 +250,7 @@ dart run protoc_plugin "\$@"
run('chmod', arguments: ['a+x', 'build/protoc-gen-dart']);
}

if (Platform.environment['UPDATE_SASS_PROTOCOL'] != 'false') {
cloneOrCheckout("https://github.com/sass/sass.git", "main",
name: 'language');
}
_updateLanguageRepo();

await runAsync("buf",
arguments: ["generate"],
Expand Down Expand Up @@ -325,3 +321,19 @@ String _updateHomebrewLanguageRevision(String formula) {
match.group(0)!.replaceFirst(match.group(1)!, languageRepoRevision) +
formula.substring(match.end);
}

/// Clones the main branch of `github.com/sass/sass` and returns the path to the
/// clone.
///
/// If the `UPDATE_SASS_SASS_REPO` environment variable is `false`, this instead
/// assumes the repo that already exists at `build/language/sass`.
/// `UPDATE_SASS_PROTOCOL` is also checked as a deprecated alias for
/// `UPDATE_SASS_SASS_REPO`.
String _updateLanguageRepo() =>
// UPDATE_SASS_PROTOCOL is considered deprecated, because it doesn't apply as
// generically to other tasks.
Platform.environment['UPDATE_SASS_SASS_REPO'] != 'false' &&
Platform.environment['UPDATE_SASS_PROTOCOL'] != 'false'
? cloneOrCheckout("https://github.com/sass/sass.git", "main",
name: 'language')
: 'build/language';

0 comments on commit c5aff1b

Please sign in to comment.