diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..91e428e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: "Test" + +on: + pull_request: + types: [opened, synchronize, reopened] + +# Only allow one workflow run at a time per PR +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + test: + name: "Test" + runs-on: ["ubuntu-latest"] + env: + TZ: "Europe/Rome" + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + - name: "Set up Node.js" + uses: actions/setup-node@v4 + with: + node-version: "22.x" + cache: "npm" + + - name: "Test the package" + run: npm cit --quiet + timeout-minutes: 5 \ No newline at end of file diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..374161e --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,33 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: "Publish to npm" + +on: + release: + types: ["created"] + +jobs: + build: + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: npm cit + timeout-minutes: 5 + + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: https://registry.npmjs.org/ + - run: npm ci + - run: npm publish --provenance + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_TOKEN}} diff --git a/README.md b/README.md index 7759660..5c768bd 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,9 @@ postTask(() => { trackEvent("something-happened"); }, "background"); ``` + +## Formats + +This package is equally available as ESM and CJS and has a single, default +export. +The code is identical between the formats except on the exporting itself. \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 6587509..f200e05 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT +// Copyright © 2024 Adevinta declare module "post-task" { /** diff --git a/index.mjs b/index.mjs index e396976..ff51c8e 100644 --- a/index.mjs +++ b/index.mjs @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT +// Copyright © 2024 Adevinta /** * The priority of the task: these are the priorities of the Scheduler API. @@ -12,20 +13,20 @@ * The task will be executed as soon as possible, in idle time, but guaranteed within the timeout. * @type {PriorityConfigurationFallback} */ -const priorityIdleTimeouts = Object.freeze({ - background: 1000, - "user-visible": 100, - "user-blocking": 50, +const priorityIdleTimeouts = Object.create(null, { + background: { value: 1000, enumerable: true }, + "user-visible": { value: 100, enumerable: true }, + "user-blocking": { value: 50, enumerable: true }, }); /** * The timeouts used for setTimeout, which define the delay before the task is executed. * @type {PriorityConfigurationFallback} */ -const priorityCallbackDelays = Object.freeze({ - background: 150, - "user-visible": 0, - "user-blocking": 0, +const priorityCallbackDelays = Object.create(null, { + background: { value: 150, enumerable: true }, + "user-visible": { value: 0, enumerable: true }, + "user-blocking": { value: 0, enumerable: true }, }); /** @typedef {() => void} Task */ diff --git a/package.json b/package.json index 19d1c35..53ad915 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "post-task", "version": "1.1.3", - "description": "A polyfill for the Scheduler API with a pre-configured progressively-enhanced function which allows for task division.", + "description": "A polyfill for the Scheduler API with a pre-configured progressively-enhanced function helps to split long-running tasks into chunks.", "type": "module", "exports": { "types": "./index.d.ts",