diff --git a/.eslintignore b/.eslintignore deleted file mode 120000 index 3e4e48b..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -.gitignore \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index e3e89d2..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,48 +0,0 @@ -const copyrightTemplate = `/* - * Copyright (c) 2018-Present, Spotify AB. - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -`; - -module.exports = { - extends: [ - //"plugin:@typescript-eslint/recommended", - 'prettier', - 'prettier/@typescript-eslint' - ], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint', 'notice'], - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module', - ecmaFeatures: { - jsx: true - } - }, - rules: { - 'notice/notice': [ - 'error', - { - template: copyrightTemplate, - onNonMatchingHeader: 'replace' - } - ] - } -}; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9792a90 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: ci + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8 + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm typecheck + - run: pnpm lint + - run: pnpm test + - run: pnpm build + - run: pnpm validate + - name: Build demo + working-directory: demo + run: pnpm build diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..17b295c --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,52 @@ +name: pages + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: pages + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8 + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm build + - name: Build demo + working-directory: demo + run: pnpm build + - name: Generate typedoc + run: pnpm gen:docs + - name: Stage typedoc under demo/dist/docs + run: cp -R docs demo/dist/docs + - uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0 + - uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 + with: + path: demo/dist + + deploy: + needs: build + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - id: deployment + uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fdbd76b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: release + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + environment: npm + permissions: + contents: read + id-token: write # npm provenance + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8 + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 22 + cache: pnpm + registry-url: https://registry.npmjs.org + - run: pnpm install --frozen-lockfile + - run: pnpm typecheck + - run: pnpm test + - run: pnpm build + - run: pnpm validate + - run: pnpm publish --provenance --access public --no-git-checks diff --git a/.gitignore b/.gitignore index e6d416e..04fd153 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,11 @@ build release dist dist-debug +docs .cache-debug .cache-demo demo/.cache coverage +*.tgz +demo/monaco-declarations/*.d.ts +test-results diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..5ee7abd --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm exec lint-staged diff --git a/.pinact.yaml b/.pinact.yaml new file mode 100644 index 0000000..a57366d --- /dev/null +++ b/.pinact.yaml @@ -0,0 +1,5 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/suzuki-shunsuke/pinact/refs/heads/main/json-schema/pinact.json +# pinact - https://github.com/suzuki-shunsuke/pinact +version: 3 +min_age: + value: 7 diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..544138b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index bdf6f9a..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - singleQuote: true -}; \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f6b0877..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: node_js -before_install: -- npm i -g npm@6.8 -cache: npm -node_js: -- '10' -script: -- npm run setup:ci -- npm run build -- npm test -- --coverage -- npm run predeploy:demo -deploy: - - provider: npm - email: kibysayshi@gmail.com - skip_cleanup: true - api_key: - secure: LFF+TBDO2lguN5rpciP09qUKWIoVVWA2arapTtX+zGMZHBa7QmDV+iBDZSLkf+5iJAgrgXsehIazXyQ7HKDad59y5kjJBOtQOqcSkENn1RTx10FHGvH/lrsO6FxLa5JD0r2cd9KdUjz2EC+4AlgrJo8wr6SKA2/cNOZ2gMVV/6cZVS/sPWfDx9Y1EDQwWlT+74G/vj4FFI+cuHQ2t28aywguaYdMQXPlORo0hXOde4JysewvO2mXcP9viMLg2qckEOeNo0ONDoQtJc4ZDJo7AmOqKmbf14sUQU04ejaw4RLveTe+ebkLYFKC72ABR0RN/VJIlUR78MZXTpJ9tM9A3iLRz1J4ca++3HQMcHQKOG+4P6lSk3bjyUg2pqrYLeUVzAoDIBABJUy0rbhiDMluKiPizO+Y9MmBf57d68+Ks+7ptDuVdYu6J01oyep0D2Mx25IlpgVOORMY05K1CbbWKNAdL8zn54SifqbCDVfDRgrMD0+iQC2D8gKMtOhap3OwtZWOEysUf5wwDz4cEzaeDcL5iOPwxKc6CpjyhdchJDxWozZTA+2wtSAUoddQ4c/iQM1FFQYQ5IugdVOA4/f66aWGftT0CzImT4jC1EHFF6QqAC5R5NAmpt6WaHDt3T/kmSIwXpDxnVq80nzK4t6k1VYjjQhum+IYMq1bx3g6DOM= - on: - tags: true - repo: spotify/NFPlayerJS - branch: master - - provider: pages - github-token: $GITHUB_TOKEN - skip_cleanup: true - keep-history: true - local-dir: demo/dist/ - on: - branch: master diff --git a/README.md b/README.md index 2e1c5ef..a227d50 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@

- NFPlayerJS + NFPlayerJS

[![License](https://img.shields.io/github/license/spotify/NFPlayerJS.svg)](LICENSE) -[![Spotify FOSS Slack](https://slackin.spotify.com/badge.svg)](https://slackin.spotify.com) -[![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/spotify/NFPlayerJS)](http://clayallsopp.github.io/readme-score?url=https://github.com/spotify/NFPlayerJS) A JavaScript/TypeScript audio engine for the Web and Server capable of multitrack time stretching, pitch shifting, declarative effects, faster than realtime processing, and more! -Developed at Spotify 2017-2018, Discontinued and handed over to new maintainers January 2023 +Developed at Spotify 2017-2018, Discontinued and handed over to new maintainers January 2023 # Getting Started (Browser) 🚀 -1. Install the player: `npm install --save nf-player` -2. Describe your audio experience using [NFGrapher][nfgrapher] `npm install --save nf-grapher`, or use a prebuilt [JSON Score](./fixtures). +1. Install the player: `pnpm add nf-player` +2. Describe your audio experience using [NFGrapher][nfgrapher] (`pnpm add nf-grapher`), or use a prebuilt [JSON Score](./fixtures). 3. Listen to it! ```js @@ -22,7 +20,7 @@ Developed at Spotify 2017-2018, Discontinued and handed over to new maintainers import { SmartPlayer, TimeInstant } from 'nf-player'; import * as ScoreJSON from './your-score.json'; -(async function() { +(async function () { // Create player. By default it uses Web Audio to insert audio data into // the current audio device. const p = new SmartPlayer(); @@ -47,7 +45,7 @@ There are also in-progress [API Docs][api docs]. A [CLI](./src/cli.ts) also ships with this package! ```sh -$ npx nf-player save --duration 120 --input-file ./fixtures/roxanne-30s-preview-shifted-infinite.json --output-file ./roxanne.wav +$ pnpm dlx nf-player save --duration 120 --input-file ./fixtures/roxanne-30s-preview-shifted-infinite.json --output-file ./roxanne.wav ``` The above command will load the Score JSON, download the audio files, and render 120 seconds of audio to a file called `tng.wav`. This should happen in about 5 seconds of realtime, depending on your computer and internet connection. @@ -117,42 +115,46 @@ See the [Playground][playground]! # Development 🏗 -Clone this repo, then: +Requires Node ≥20 and [pnpm](https://pnpm.io/). ```sh -$ npm install +$ pnpm install # installs the package + the demo workspace +$ pnpm build # build the library (tsdown → dist/, ESM + CJS + .d.ts) +$ pnpm test # vitest +$ pnpm typecheck # tsc -b (whole solution) +$ pnpm lint ``` -To build the library and start the development environment: +To run the demo / playground locally: ```sh -$ npm start +$ pnpm --filter ./demo dev ``` -To build and publish the demo to [gh-pages](playground) manually, run: +The demo also exposes a cut-down debug entry at `demo/debug.html` (source: `demo/src/debug.ts`) for poking at single Scores or scripts. -```sh -$ npm run deploy:demo:manual -``` +# Deployment / Publishing / Release 🚢 -Otherwise the demo is actually built and deployed on each push to master. +### Publishing: -There is also a more cut-down [debug environment](./debug-harness/index.ts) useful for debugging / developing single Scores or scripts: +1. Bump the version: `pnpm version ` +2. push, then cut a GitHub Release. Publishing occurs via [`release.yml`](./.github/workflows/release.yml). -```sh -$ npm run debug-harness -``` +### Demo Deployment: -# Deployment / Publishing / Release 🚢 +- The demo is deployed to GitHub Pages automatically by `pages.yml` on each push to `main`. -### Publishing: +### CI workflow actions (SHA-pinned): -- `npm version [major|minor|patch]`, then PR. -- TravisCI will attempt to publish any tagged commit. +Third-party GitHub Actions in `.github/workflows/*.yml` are pinned to full commit SHAs for safety. To bump them, use [pinact](https://github.com/suzuki-shunsuke/pinact): -### Demo Deployment: +```sh +$ brew install suzuki-shunsuke/pinact/pinact +$ pinact run --update # resolves each tag to its latest SHA, rewrites in place +$ pinact run --verify # verify SHA ↔ comment match + min-age policy +``` -- The demo is deployed automatically on master builds using the TravisCI gh-pages provider. +Project policy lives in [`.pinact.yaml`](./.pinact.yaml). # Contributing 💖⌨️ @@ -174,6 +176,6 @@ To comply with section 6 of the LGPL, SoundTouch can be swapped out at runtime b "Reasonable" is ambiguous, of course. In this case, it means "expected CPU usage if audio is the primary purpose of the experience". For example, an authoring tool or enhanced listening experience. It's still unclear to if CPU usage is low enough for a background task like listening to a playlist. -[nfgrapher]: https://github.com/spotify/NFGrapher -[playground]: https://spotify.github.io/NFPlayerJS/ -[api docs]: https://spotify.github.io/NFPlayerJS/docs/ +[nfgrapher]: https://github.com/nativeformat/NFGrapher +[playground]: https://nativeformat.github.io/NFPlayerJS/ +[api docs]: https://nativeformat.github.io/NFPlayerJS/docs/ diff --git a/debug-harness/declarations.d.ts b/debug-harness/declarations.d.ts deleted file mode 100644 index edcdf47..0000000 --- a/debug-harness/declarations.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018-Present, Spotify AB. - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -declare module '*.wav'; -declare module '*.mp3'; diff --git a/demo.tsconfig.json b/demo.tsconfig.json new file mode 100644 index 0000000..43f39d6 --- /dev/null +++ b/demo.tsconfig.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig.json", + "compilerOptions": { + "composite": true, + "noEmit": true, + "tsBuildInfoFile": "./node_modules/.cache/tsbuildinfo/demo.tsbuildinfo", + "strict": true, + "target": "ES2022", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "module": "preserve", + "customConditions": ["source"], + "jsx": "react-jsx", + "esModuleInterop": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true + }, + "include": ["demo/src/**/*"] +} diff --git a/demo/.npmrc b/demo/.npmrc deleted file mode 100644 index 38f11c6..0000000 --- a/demo/.npmrc +++ /dev/null @@ -1 +0,0 @@ -registry=https://registry.npmjs.org diff --git a/debug-harness/index.html b/demo/debug.html similarity index 60% rename from debug-harness/index.html rename to demo/debug.html index 1eff22d..3594ebb 100644 --- a/debug-harness/index.html +++ b/demo/debug.html @@ -1,14 +1,12 @@ - + NF Debug Harness - - - + - \ No newline at end of file + diff --git a/demo/src/index.html b/demo/index.html similarity index 79% rename from demo/src/index.html rename to demo/index.html index f383656..0806af9 100644 --- a/demo/src/index.html +++ b/demo/index.html @@ -6,7 +6,7 @@ Native Format Smart Player, JS Edition - +