Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package metadata files and get tests running #1

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
dist/
**/*.js
14 changes: 14 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./node_modules/gts/",
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{"allowExpressions": true}
],
"func-style": ["error", "declaration"],
"prefer-const": ["error", {"destructuring": "all"}],
// It would be nice to sort import declaration order as well, but that's not
// autofixable and it's not worth the effort of handling manually.
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
}
}
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

defaults:
run: {shell: bash}

env:
PROTOC_VERSION: 3.x

on:
push:
branches: [main, feature.*]
tags: ['**']
pull_request:

jobs:
static_analysis:
name: Static analysis
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
check-latest: true
- run: npm install
- run: npm run check

tests:
name: 'Tests | Node ${{ matrix.node-version }} | ${{ matrix.os }}'
runs-on: ${{ matrix.os }}-latest

strategy:
matrix:
os: [ubuntu, macos, windows]
node-version: ['lts/*', 'lts/-1', 'lts/-2']
fail-fast: false

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- run: npm install
- run: npm run test

deploy:
name: Deploy
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/') && github.repository == 'sass/sync-process'"
needs: [static_analysis, tests]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
check-latest: true
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_TOKEN }}'

typedoc:
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/') && github.repository == 'sass/sync-process'"
needs: [deploy]

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

permissions:
pages: write
id-token: write

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
check-latest: true
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run doc

- name: Upload static files as artifact
uses: actions/upload-pages-artifact@v3
with: {path: docs}

- id: deployment
uses: actions/deploy-pages@v4
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.DS_Store
build
dist
node_modules
npm-debug.log*
package-lock.json

# Editors
.idea
.vscode
*.njsproj
*.ntvs*
*.sln
*.suo
*.sw?
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json'),
};
10 changes: 10 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Sass is more than a technology; Sass is driven by the community of individuals
that power its development and use every day. As a community, we want to embrace
the very differences that have made our collaboration so powerful, and work
together to provide the best environment for learning, growing, and sharing of
ideas. It is imperative that we keep Sass a fun, welcoming, challenging, and
fair place to play.

[The full community guidelines can be found on the Sass website.][link]

[link]: http://sass-lang.com/community-guidelines
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# How to Contribute

We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.

* [Contributor License Agreement](#contributor-license-agreement)
* [Code Reviews](#code-reviews)
* [Large Language Models](#large-language-models)

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Agreement. You (or your employer) retain the copyright to your contribution;
this simply gives us permission to use and redistribute your contributions as
part of the project. Head over to <https://cla.developers.google.com/> to see
your current agreements on file or to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Code Reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Large Language Models

Do not submit any code or prose written or modified by large language models or
"artificial intelligence" such as GitHub Copilot or ChatGPT to this project.
These tools produce code that looks plausible, which means that not only is it
likely to contain bugs those bugs are likely to be difficult to notice on
review. In addition, because these models were trained indiscriminately and
non-consensually on open-source code with a variety of licenses, it's not
obvious that we have the moral or legal right to redistribute code they
generate.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2024, Google LLC

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# `sync-process`

This package exposes a `SyncProcess` class that allows Node.js to run
a subprocess synchronously *and* interactively.

## Usage

Use `new SyncProcess()` to start running a subprocess. This supports the same
API as [`child_process.spawn()`] other than a few options. You can send input to
the process using `process.stdin`, and receive events from it (stdout, stderr,
or exit) using `process.next()`. This implements [the iterator protocol], but
*not* the iterable protocol because it's intrinsically stateful.

[the iterator protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol
[`child_process.spawn()`]: https://nodejs.org/api/child_process.html#child_processspawncommand-args-options

```js
import {SyncProcess} from 'sync-process';
// or
// const {SyncProcess} = require('sync-process');

const node = new SyncProcess('node', ['--interactive']);

for (;;) {
if (node.next().value.data.toString().endsWith('> ')) break;
}

node.stdin.write("41 * Math.pow(2, 5)\n");
console.log((node.next().value.data.toString().split("\n")[0]));
node.stdin.write(".exit\n");
console.log(`Node exited with exit code ${node.next().value.code}`);
```

## Why synchrony?

See [the `sync-message-port` documentation] for an explanation of why running
code synchronously can be valuable even in an asynchronous ecosystem like
Node.js

[the `sync-message-port` documentation]: https://github.com/sass/sync-message-port?tab=readme-ov-file#why-synchrony

### Why not `child_process.spawnSync()`?

Although Node's built-in [`child_process.spawnSync()`] function does run
synchronously, it's not interactive. It only returns once the process has run to
completion and exited, which means it's not suitable for any long-lived
subprocess that interleaves sending and receiving data, such as when using the
[embedded Sass protocol].

[`child_process.spawnSync()`]: https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options
[embedded Sass protocol]: https://github.com/sass/sass/blob/main/spec/embedded-protocol.md

---

Disclaimer: this is not an official Google product.
7 changes: 7 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const config = {
roots: ['<rootDir>/lib/'],
preset: 'ts-jest',
testEnvironment: 'node',
};

export default config;
Loading