Skip to content

Commit 9a06ccd

Browse files
authored
Fetch matching feature branches (#169)
This also stops running shell commands silently to help diagnose errors, and ensures that the embedded protocol's VERSION file is accessible even when installing from a path.
1 parent bba6a4f commit 9a06ccd

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
with:
6262
node-version: ${{ matrix.node-version }}
6363
check-latest: true
64+
- uses: frenck/action-setup-yq@v1
65+
with: {version: v4.30.5} # frenck/action-setup-yq#35
6466
- uses: arduino/setup-protoc@v1
6567
with:
6668
version: ${{ env.PROTOC_VERSION }}
@@ -84,8 +86,8 @@ jobs:
8486
- name: Link the embedded compiler to Dart Sass
8587
run: |
8688
if [[ -d dart-sass ]]; then
87-
echo "dependency_overrides: {sass: {path: ../dart-sass}}" \
88-
>> dart-sass-embedded/pubspec.yaml
89+
yq -i '.dependency_overrides.sass = {"path": "../dart-sass"}' \
90+
dart-sass-embedded/pubspec.yaml
8991
fi
9092
9193
- name: Check out the JS API definition
@@ -126,6 +128,8 @@ jobs:
126128
with: {sdk: stable}
127129
- uses: actions/setup-node@v2
128130
with: {node-version: "${{ matrix.node_version }}"}
131+
- uses: frenck/action-setup-yq@v1
132+
with: {version: v4.30.5} # frenck/action-setup-yq#35
129133
- uses: arduino/setup-protoc@v1
130134
with:
131135
version: ${{ env.PROTOC_VERSION }}
@@ -146,8 +150,8 @@ jobs:
146150
- name: Link the embedded compiler to Dart Sass
147151
run: |
148152
if [[ -d dart-sass ]]; then
149-
echo "dependency_overrides: {sass: {path: ../dart-sass}}" \
150-
>> dart-sass-embedded/pubspec.yaml
153+
yq -i '.dependency_overrides.sass = {"path": "../dart-sass"}' \
154+
dart-sass-embedded/pubspec.yaml
151155
fi
152156
153157
- name: Check out the JS API definition

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sass-embedded",
33
"version": "1.56.2",
4-
"protocol-version": "1.1.0",
4+
"protocol-version": "1.2.0",
55
"compiler-version": "1.56.2",
66
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
77
"repository": "sass/embedded-host-node",
@@ -62,6 +62,7 @@
6262
"npm-run-all": "^4.1.5",
6363
"protoc": "1.0.4",
6464
"shelljs": "^0.8.4",
65+
"simple-git": "^3.15.1",
6566
"source-map-js": "^0.6.1",
6667
"tar": "^6.0.5",
6768
"ts-jest": "^27.0.5",

tool/utils.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import fetch from 'node-fetch';
88
import * as p from 'path';
99
import * as yaml from 'yaml';
1010
import * as shell from 'shelljs';
11+
import {simpleGit} from 'simple-git';
1112
import {extract as extractTar} from 'tar';
1213

1314
import * as pkg from '../package.json';
@@ -85,7 +86,7 @@ export async function getEmbeddedProtocol(
8586
): Promise<void> {
8687
const repo = 'embedded-protocol';
8788

88-
options ??= defaultVersionOption('protocol-version');
89+
options ??= await defaultVersionOption('protocol-version');
8990
if ('version' in options) {
9091
const version = options?.version;
9192
await downloadRelease({
@@ -108,7 +109,11 @@ export async function getEmbeddedProtocol(
108109
const source =
109110
options && 'path' in options ? options.path : p.join(BUILD_PATH, repo);
110111
buildEmbeddedProtocol(source);
111-
await link('build/embedded-protocol', p.join(outPath, repo));
112+
113+
// Make the VERSION consistently accessible for the dependency test and any
114+
// curious users.
115+
await link(p.join(source, 'VERSION'), 'build/embedded-protocol-out/VERSION');
116+
await link('build/embedded-protocol-out', p.join(outPath, repo));
112117
}
113118

114119
/**
@@ -136,7 +141,7 @@ export async function getDartSassEmbedded(
136141
}
137142
): Promise<void> {
138143
const repo = 'dart-sass-embedded';
139-
options ??= defaultVersionOption('compiler-version');
144+
options ??= await defaultVersionOption('compiler-version');
140145

141146
await checkForMusl();
142147

@@ -287,8 +292,7 @@ function fetchRepo(options: {
287292
`git clone \
288293
--depth=1 \
289294
https://github.com/sass/${options.repo} \
290-
${p.join(options.outPath, options.repo)}`,
291-
{silent: true}
295+
${p.join(options.outPath, options.repo)}`
292296
);
293297
}
294298

@@ -297,10 +301,7 @@ function fetchRepo(options: {
297301
console.log(`Fetching ${version} for ${options.repo}.`);
298302
shell.exec(
299303
`git fetch --depth=1 origin ${options.ref} && git reset --hard FETCH_HEAD`,
300-
{
301-
silent: true,
302-
cwd: p.join(options.outPath, options.repo),
303-
}
304+
{cwd: p.join(options.outPath, options.repo)}
304305
);
305306
}
306307

@@ -322,38 +323,38 @@ function buildEmbeddedProtocol(repoPath: string): void {
322323
process.platform === 'win32'
323324
? '%CD%/node_modules/.bin/protoc-gen-ts.cmd'
324325
: 'node_modules/.bin/protoc-gen-ts';
325-
mkdirSync('build/embedded-protocol', {recursive: true});
326+
mkdirSync('build/embedded-protocol-out', {recursive: true});
326327
shell.exec(
327328
`${protocPath} \
328329
--plugin="protoc-gen-ts=${pluginPath}" \
329-
--js_out="import_style=commonjs,binary:build/embedded-protocol" \
330-
--ts_out="build/embedded-protocol" \
330+
--js_out="import_style=commonjs,binary:build/embedded-protocol-out" \
331+
--ts_out="build/embedded-protocol-out" \
331332
--proto_path="${repoPath}" \
332-
${proto}`,
333-
{silent: true}
333+
${proto}`
334334
);
335335
}
336336

337337
// Builds the Embedded Dart Sass executable from the source at `repoPath`.
338338
function buildDartSassEmbedded(repoPath: string): void {
339339
console.log('Downloading dart-sass-embedded dependencies.');
340-
shell.exec('dart pub upgrade', {
341-
cwd: repoPath,
342-
silent: true,
343-
});
340+
shell.exec('dart pub upgrade', {cwd: repoPath});
344341

345342
console.log('Building dart-sass-embedded executable.');
346-
shell.exec('dart run grinder protobuf pkg-standalone-dev', {
347-
cwd: repoPath,
348-
silent: true,
349-
});
343+
shell.exec('dart run grinder protobuf pkg-standalone-dev', {cwd: repoPath});
350344
}
351345

352346
// Given the name of a field in `package.json`, returns the default version
353347
// option described by that field.
354-
function defaultVersionOption(
348+
async function defaultVersionOption(
355349
pkgField: keyof typeof pkg
356-
): {version: string} | {ref: string} {
350+
): Promise<{version: string} | {ref: string}> {
351+
// If we're on a feature branch, fetch the matching feature branch from the
352+
// compiler.
353+
if (pkgField === 'compiler-version') {
354+
const branch = (await simpleGit().branch()).current;
355+
if (branch.startsWith('feature.')) return {ref: branch};
356+
}
357+
357358
const version = pkg[pkgField] as string;
358359
return version.endsWith('-dev') ? {ref: 'main'} : {version};
359360
}

0 commit comments

Comments
 (0)