Skip to content
Closed
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
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,27 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload %GITHUB_REF:~10% dotslash-windows-arm64.%GITHUB_REF:~10%.tar.gz
shell: cmd

npm-publish:
# This job depends on release assets uploaded by the previous jobs.
# Keep this job's dependencies in sync with node/platforms.js.
needs: [macos, windows, windows-arm64, linux-musl-x86_64, linux-musl-arm64]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: node
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build -- --tag ${GITHUB_REF#refs/tags/}
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/test-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: JavaScript chores

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: node
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
/target
**/node_modules
node/bin/*/
9 changes: 9 additions & 0 deletions node/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"overrides": [
{
"files": "bin/dotslash",
"options": { "parser": "babel" }
}
]
}
42 changes: 42 additions & 0 deletions node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# DotSlash: simplified executable deployment

[DotSlash](https://dotslash-cli.com/docs/) (`dotslash`) is a command-line tool that lets you represent a set of
platform-specific, heavyweight executables with an equivalent small,
easy-to-read text file. In turn, this makes it efficient to store executables in
source control without hurting repository size. This paves the way for checking
build toolchains and other tools directly into the repo, reducing dependencies
on the host environment and thereby facilitating reproducible builds.

The `fb-dotslash` npm package allows you to use DotSlash in your Node.js projects without having to install DotSlash globally. This is particularly useful for package authors, who have traditionally needed to either include binaries for _all_ platforms or manage their own download and caching in a postinstall script.

## Using DotSlash in an npm package

First, you'll need to write a [DotSlash file](https://dotslash-cli.com/docs/dotslash-file/) that describes the binary you want to distribute.

If your npm package declares `fb-dotslash` as a dependency, any commands executed as part of `npm run` and `npm exec` will have `dotslash` available on the `PATH`. This means you can, for example, directly reference DotSlash files in your `package.json` scripts with no further setup:

```json
{
"name": "my-package",
"scripts": {
"foo": "path/to/dotslash/file"
},
"dependencies": {
"fb-dotslash": "^0.5.7"
}
}
```

If you need to use `dotslash` in some other context, you can use `require('fb-dotslash')` to get the path to the DotSlash executable appropriate for the current platform:

```js
const dotslash = require('fb-dotslash');
const {spawnSync} = require('child_process');
spawnSync(dotslash, ['path/to/dotslash/file'], {stdio: 'inherit']);
```

## License

DotSlash is licensed under both the MIT license and Apache-2.0 license; the
exact terms can be found in the [LICENSE-MIT](https://github.com/facebook/dotslash/blob/main/LICENSE-MIT) and
[LICENSE-APACHE](https://github.com/facebook/dotslash/blob/main/LICENSE-APACHE) files, respectively.
22 changes: 22 additions & 0 deletions node/bin/dotslash
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*/

'use strict';

const spawn = require('child_process').spawn;

const input = process.argv.slice(2);
const bin = require('../');

if (bin !== null) {
spawn(bin, input, { stdio: 'inherit' }).on('exit', process.exit);
} else {
throw new Error('Platform not supported.');
}
14 changes: 14 additions & 0 deletions node/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is dual-licensed under either the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree or the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree. You may select, at your option, one of the
* above-listed licenses.
*
* @format
*/

declare const binaryPath: string;
export = binaryPath;
20 changes: 20 additions & 0 deletions node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is dual-licensed under either the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree or the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree. You may select, at your option, one of the
* above-listed licenses.
*/

'use strict';

const os = require('os');
const path = require('path');
const { artifactsByPlatformAndArch } = require('./platforms');

const artifacts = artifactsByPlatformAndArch[os.platform()];
const { slug, binary } = artifacts[os.arch()] ?? artifacts['*'];

module.exports = path.join(__dirname, 'bin', slug, binary);
15 changes: 15 additions & 0 deletions node/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is dual-licensed under either the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree or the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree. You may select, at your option, one of the
* above-listed licenses.
*
* @format
* @flow strict-local
*/

declare var binaryPath: string;
module.exports = binaryPath;
38 changes: 38 additions & 0 deletions node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "fb-dotslash",
"version": "0.0.0-dev",
"bin": {
"dotslash": "bin/dotslash"
},
"description": "Command-line tool to facilitate fetching an executable, caching it, and then running it.",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/dotslash.git"
},
"homepage": "https://dotslash-cli.com/",
"bugs": "https://github.com/facebook/dotslash/issues",
"contributors": [
"Michael Bolin <bolinfest@gmail.com>",
"Andres Suarez <zertosh@gmail.com>",
"Moti Zilberman <motiz88@gmail.com>"
],
"main": "index.js",
"files": [
"bin",
"platforms.js",
"index.js",
"index.js.flow",
"index.d.ts"
],
"scripts": {
"clean": "node scripts/clean-package",
"build": "npm run fix && node scripts/build-package",
"fix": "prettier --write .",
"lint": "prettier --check ."
},
"license": "(MIT OR Apache-2.0)",
"engines": {
"node": ">=20"
},
"devDependencies": {
"prettier": "3.6.2"
}
}
47 changes: 47 additions & 0 deletions node/platforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is dual-licensed under either the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree or the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree. You may select, at your option, one of the
* above-listed licenses.
*/

module.exports = {
// Keep in sync with .github/workflows/release.yml - the 'npm-publish' job's dependencies
// MUST include the build job for each artifact listed below.
artifactsByPlatformAndArch: {
linux: {
arm64: {
// Build job: 'linux-musl-arm64'
slug: 'linux-musl.aarch64',
binary: 'dotslash',
},
x64: {
// Build job: 'linux-musl-x86_64'
slug: 'linux-musl.x86_64',
binary: 'dotslash',
},
},
darwin: {
'*': {
// Build job: 'macos'
slug: 'macos',
binary: 'dotslash',
},
},
win32: {
arm64: {
// Build job: 'windows-arm64'
slug: 'windows-arm64',
binary: 'dotslash.exe',
},
x64: {
// Build job: 'windows'
slug: 'windows',
binary: 'dotslash.exe',
},
},
},
};
Loading
Loading