Skip to content

Commit 81a80c9

Browse files
authored
Add package metadata files and get tests running (#1)
This also tweaks the API so it follows the JS iterator protocol.
1 parent 082129e commit 81a80c9

17 files changed

+410
-68
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
dist/
3+
**/*.js

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./node_modules/gts/",
3+
"rules": {
4+
"@typescript-eslint/explicit-function-return-type": [
5+
"error",
6+
{"allowExpressions": true}
7+
],
8+
"func-style": ["error", "declaration"],
9+
"prefer-const": ["error", {"destructuring": "all"}],
10+
// It would be nice to sort import declaration order as well, but that's not
11+
// autofixable and it's not worth the effort of handling manually.
12+
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
13+
}
14+
}

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: CI
2+
3+
defaults:
4+
run: {shell: bash}
5+
6+
env:
7+
PROTOC_VERSION: 3.x
8+
9+
on:
10+
push:
11+
branches: [main, feature.*]
12+
tags: ['**']
13+
pull_request:
14+
15+
jobs:
16+
static_analysis:
17+
name: Static analysis
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 'lts/*'
25+
check-latest: true
26+
- run: npm install
27+
- run: npm run check
28+
29+
tests:
30+
name: 'Tests | Node ${{ matrix.node-version }} | ${{ matrix.os }}'
31+
runs-on: ${{ matrix.os }}-latest
32+
33+
strategy:
34+
matrix:
35+
os: [ubuntu, macos, windows]
36+
node-version: ['lts/*', 'lts/-1', 'lts/-2']
37+
fail-fast: false
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-node@v4
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
check-latest: true
45+
- run: npm install
46+
- run: npm run test
47+
48+
deploy:
49+
name: Deploy
50+
runs-on: ubuntu-latest
51+
if: "startsWith(github.ref, 'refs/tags/') && github.repository == 'sass/sync-process'"
52+
needs: [static_analysis, tests]
53+
54+
steps:
55+
- uses: actions/checkout@v4
56+
- uses: actions/setup-node@v4
57+
with:
58+
node-version: 'lts/*'
59+
check-latest: true
60+
registry-url: 'https://registry.npmjs.org'
61+
- run: npm install
62+
- run: npm publish
63+
env:
64+
NODE_AUTH_TOKEN: '${{ secrets.NPM_TOKEN }}'
65+
66+
typedoc:
67+
runs-on: ubuntu-latest
68+
if: "startsWith(github.ref, 'refs/tags/') && github.repository == 'sass/sync-process'"
69+
needs: [deploy]
70+
71+
environment:
72+
name: github-pages
73+
url: ${{ steps.deployment.outputs.page_url }}
74+
75+
permissions:
76+
pages: write
77+
id-token: write
78+
79+
steps:
80+
- uses: actions/checkout@v4
81+
- uses: actions/setup-node@v4
82+
with:
83+
node-version: 'lts/*'
84+
check-latest: true
85+
registry-url: 'https://registry.npmjs.org'
86+
- run: npm install
87+
- run: npm run doc
88+
89+
- name: Upload static files as artifact
90+
uses: actions/upload-pages-artifact@v3
91+
with: {path: docs}
92+
93+
- id: deployment
94+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.DS_Store
2+
build
3+
dist
4+
node_modules
5+
npm-debug.log*
6+
package-lock.json
7+
8+
# Editors
9+
.idea
10+
.vscode
11+
*.njsproj
12+
*.ntvs*
13+
*.sln
14+
*.suo
15+
*.sw?

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json'),
3+
};

CODE_OF_CONDUCT.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Sass is more than a technology; Sass is driven by the community of individuals
2+
that power its development and use every day. As a community, we want to embrace
3+
the very differences that have made our collaboration so powerful, and work
4+
together to provide the best environment for learning, growing, and sharing of
5+
ideas. It is imperative that we keep Sass a fun, welcoming, challenging, and
6+
fair place to play.
7+
8+
[The full community guidelines can be found on the Sass website.][link]
9+
10+
[link]: http://sass-lang.com/community-guidelines

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# How to Contribute
2+
3+
We'd love to accept your patches and contributions to this project. There are
4+
just a few small guidelines you need to follow.
5+
6+
* [Contributor License Agreement](#contributor-license-agreement)
7+
* [Code Reviews](#code-reviews)
8+
* [Large Language Models](#large-language-models)
9+
10+
## Contributor License Agreement
11+
12+
Contributions to this project must be accompanied by a Contributor License
13+
Agreement. You (or your employer) retain the copyright to your contribution;
14+
this simply gives us permission to use and redistribute your contributions as
15+
part of the project. Head over to <https://cla.developers.google.com/> to see
16+
your current agreements on file or to sign a new one.
17+
18+
You generally only need to submit a CLA once, so if you've already submitted one
19+
(even if it was for a different project), you probably don't need to do it
20+
again.
21+
22+
## Code Reviews
23+
24+
All submissions, including submissions by project members, require review. We
25+
use GitHub pull requests for this purpose. Consult
26+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
27+
information on using pull requests.
28+
29+
## Large Language Models
30+
31+
Do not submit any code or prose written or modified by large language models or
32+
"artificial intelligence" such as GitHub Copilot or ChatGPT to this project.
33+
These tools produce code that looks plausible, which means that not only is it
34+
likely to contain bugs those bugs are likely to be difficult to notice on
35+
review. In addition, because these models were trained indiscriminately and
36+
non-consensually on open-source code with a variety of licenses, it's not
37+
obvious that we have the moral or legal right to redistribute code they
38+
generate.

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2024, Google LLC
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# `sync-process`
2+
3+
This package exposes a `SyncProcess` class that allows Node.js to run
4+
a subprocess synchronously *and* interactively.
5+
6+
## Usage
7+
8+
Use `new SyncProcess()` to start running a subprocess. This supports the same
9+
API as [`child_process.spawn()`] other than a few options. You can send input to
10+
the process using `process.stdin`, and receive events from it (stdout, stderr,
11+
or exit) using `process.next()`. This implements [the iterator protocol], but
12+
*not* the iterable protocol because it's intrinsically stateful.
13+
14+
[the iterator protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol
15+
[`child_process.spawn()`]: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
16+
17+
```js
18+
import {SyncProcess} from 'sync-process';
19+
// or
20+
// const {SyncProcess} = require('sync-process');
21+
22+
const node = new SyncProcess('node', ['--interactive']);
23+
24+
for (;;) {
25+
if (node.next().value.data.toString().endsWith('> ')) break;
26+
}
27+
28+
node.stdin.write("41 * Math.pow(2, 5)\n");
29+
console.log((node.next().value.data.toString().split("\n")[0]));
30+
node.stdin.write(".exit\n");
31+
console.log(`Node exited with exit code ${node.next().value.code}`);
32+
```
33+
34+
## Why synchrony?
35+
36+
See [the `sync-message-port` documentation] for an explanation of why running
37+
code synchronously can be valuable even in an asynchronous ecosystem like
38+
Node.js
39+
40+
[the `sync-message-port` documentation]: https://github.com/sass/sync-message-port?tab=readme-ov-file#why-synchrony
41+
42+
### Why not `child_process.spawnSync()`?
43+
44+
Although Node's built-in [`child_process.spawnSync()`] function does run
45+
synchronously, it's not interactive. It only returns once the process has run to
46+
completion and exited, which means it's not suitable for any long-lived
47+
subprocess that interleaves sending and receiving data, such as when using the
48+
[embedded Sass protocol].
49+
50+
[`child_process.spawnSync()`]: https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options
51+
[embedded Sass protocol]: https://github.com/sass/sass/blob/main/spec/embedded-protocol.md
52+
53+
---
54+
55+
Disclaimer: this is not an official Google product.

0 commit comments

Comments
 (0)