diff --git a/.github/actions/setup-npm-demos-npm/action.yml b/.github/actions/setup-npm-demos-npm/action.yml deleted file mode 100644 index 76f23d1e..00000000 --- a/.github/actions/setup-npm-demos-npm/action.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: "Setup demo npm" -description: "A composite action to setup npm for npm demo" - -runs: - using: "composite" - steps: - - name: Get Node.js version - id: get-node-version - shell: bash - run: echo "node_version=$(grep node .tool-versions | cut -d' ' -f2)" >> $GITHUB_OUTPUT - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: ${{ steps.get-node-version.outputs.node_version }} - - name: npm cache - id: cache-node-modules - uses: actions/cache@v4 - with: - path: demos/npm/node_modules - key: ${{ runner.os }}-npm-packages-npm-demo-${{ hashFiles('demos/npm/package-lock.json') }} - - name: Install dependencies - shell: bash - if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: npm ci --prefix demos/npm diff --git a/.github/actions/setup-npm-demos-react/action.yml b/.github/actions/setup-npm-demos-react/action.yml deleted file mode 100644 index 589e5911..00000000 --- a/.github/actions/setup-npm-demos-react/action.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: "Setup react demo npm" -description: "A composite action to setup npm for react demo" - -runs: - using: "composite" - steps: - - name: Get Node.js version - id: get-node-version - shell: bash - run: echo "node_version=$(grep node .tool-versions | cut -d' ' -f2)" >> $GITHUB_OUTPUT - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: ${{ steps.get-node-version.outputs.node_version }} - - name: npm cache - id: cache-node-modules - uses: actions/cache@v4 - with: - path: demos/react/node_modules - key: ${{ runner.os }}-npm-packages-react-demo-${{ hashFiles('demos/react/package-lock.json') }} - - name: Install dependencies - shell: bash - if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: npm ci --prefix demos/react diff --git a/.github/actions/setup-npm/action.yml b/.github/actions/setup-npm/action.yml deleted file mode 100644 index c7332016..00000000 --- a/.github/actions/setup-npm/action.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: "Setup npm" -description: "A composite action to setup npm" - -runs: - using: "composite" - steps: - - name: Get Node.js version - id: get-node-version - shell: bash - run: echo "node_version=$(grep node .tool-versions | cut -d' ' -f2)" >> $GITHUB_OUTPUT - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: ${{ steps.get-node-version.outputs.node_version }} - - name: npm cache - id: cache-node-modules - uses: actions/cache@v4 - with: - path: node_modules - key: ${{ runner.os }}-npm-packages-${{ hashFiles('package-lock.json') }} - - name: Install dependencies - shell: bash - if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: npm ci diff --git a/.github/actions/setup-pnpm-demos-npm/action.yml b/.github/actions/setup-pnpm-demos-npm/action.yml new file mode 100644 index 00000000..2489bf7c --- /dev/null +++ b/.github/actions/setup-pnpm-demos-npm/action.yml @@ -0,0 +1,31 @@ +name: "Setup demo pnpm" +description: "A composite action to setup pnpm for npm demo" + +runs: + using: "composite" + steps: + - name: Get Node.js version + id: get-node-version + shell: bash + run: echo "node_version=$(grep node .tool-versions | cut -d' ' -f2)" >> $GITHUB_OUTPUT + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ steps.get-node-version.outputs.node_version }} + - name: Install pnpm + uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 + with: + version: 10.11.0 + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - name: Setup pnpm cache + uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-npm-demo-${{ hashFiles('demos/npm/pnpm-lock.yaml') }} + restore-keys: ${{ runner.os }}-pnpm-store- + - name: Install dependencies + shell: bash + run: pnpm --prefix demos/npm install --frozen-lockfile diff --git a/.github/actions/setup-pnpm-demos-react/action.yml b/.github/actions/setup-pnpm-demos-react/action.yml new file mode 100644 index 00000000..8af94f58 --- /dev/null +++ b/.github/actions/setup-pnpm-demos-react/action.yml @@ -0,0 +1,31 @@ +name: "Setup react demo pnpm" +description: "A composite action to setup pnpm for react demo" + +runs: + using: "composite" + steps: + - name: Get Node.js version + id: get-node-version + shell: bash + run: echo "node_version=$(grep node .tool-versions | cut -d' ' -f2)" >> $GITHUB_OUTPUT + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ steps.get-node-version.outputs.node_version }} + - name: Install pnpm + uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 + with: + version: 10.11.0 + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - name: Setup pnpm cache + uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-react-demo-${{ hashFiles('demos/react/pnpm-lock.yaml') }} + restore-keys: ${{ runner.os }}-pnpm-store- + - name: Install dependencies + shell: bash + run: pnpm --prefix demos/react install --frozen-lockfile diff --git a/.github/actions/setup-pnpm/action.yml b/.github/actions/setup-pnpm/action.yml new file mode 100644 index 00000000..88f433c3 --- /dev/null +++ b/.github/actions/setup-pnpm/action.yml @@ -0,0 +1,31 @@ +name: "Setup pnpm" +description: "A composite action to setup pnpm" + +runs: + using: "composite" + steps: + - name: Get Node.js version + id: get-node-version + shell: bash + run: echo "node_version=$(grep node .tool-versions | cut -d' ' -f2)" >> $GITHUB_OUTPUT + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ steps.get-node-version.outputs.node_version }} + - name: Install pnpm + uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 + with: + version: 10.11.0 + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - name: Setup pnpm cache + uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: ${{ runner.os }}-pnpm-store- + - name: Install dependencies + shell: bash + run: pnpm install --frozen-lockfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2914c0d1..e2e794d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,13 +77,16 @@ jobs: - name: Patch version run: ./scripts/patch-version.sh "${{ github.ref_name }}" + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm + - name: Setup registry access run: | echo '@optable:registry=https://registry.npmjs.org/' > ~/.npmrc echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_CI_ACCESS_TOKEN }}" >> ~/.npmrc - name: Publish to NPM - run: npm publish --access public + run: pnpm publish --access public --no-git-checks deploy-sdk-to-gcs: needs: [deploy-sdk-to-npm, define-gcs-versions-to-update] diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index c1adbe7d..f17e92f7 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -19,14 +19,14 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup npm - uses: ./.github/actions/setup-npm + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm - name: Patch build.json version run: ./scripts/patch-version.sh "${{ inputs.version }}" - name: Build web production - run: npm run build-web -- --mode=production + run: pnpm build-web --mode=production - name: Upload artifacts uses: actions/upload-artifact@v4 @@ -41,14 +41,14 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup npm - uses: ./.github/actions/setup-npm + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm - name: Patch build.json version run: ./scripts/patch-version.sh "${{ inputs.version }}" - name: Transpile lib - run: npm run build-lib + run: pnpm build-lib - name: Upload artifacts uses: actions/upload-artifact@v4 @@ -99,14 +99,14 @@ jobs: path: lib/dist # SDK has a dependency on third-party js-sha256, we need to install node_modules in the root directory - - name: Setup npm - uses: ./.github/actions/setup-npm + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm - - name: Setup npm react demo - uses: ./.github/actions/setup-npm-demos-react + - name: Setup pnpm react demo + uses: ./.github/actions/setup-pnpm-demos-react - name: Build react demo - run: npm run build + run: pnpm run build - name: Upload artifacts uses: actions/upload-artifact@v4 @@ -124,11 +124,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup npm demos npm - uses: ./.github/actions/setup-npm-demos-npm + - name: Setup pnpm demos npm + uses: ./.github/actions/setup-pnpm-demos-npm - name: Build npm-demo - run: npm run build + run: pnpm run build - name: Upload artifacts uses: actions/upload-artifact@v4 diff --git a/.github/workflows/reusable-lint-test.yml b/.github/workflows/reusable-lint-test.yml index 1b11b16e..655d11d6 100644 --- a/.github/workflows/reusable-lint-test.yml +++ b/.github/workflows/reusable-lint-test.yml @@ -8,11 +8,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup npm - uses: ./.github/actions/setup-npm + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm - name: Test - run: npm run test + run: pnpm test prettier: runs-on: ubuntu-22.04 @@ -20,11 +20,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup npm - uses: ./.github/actions/setup-npm + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm - name: Run prettier - run: npm run format + run: pnpm format - name: Check if prettier changed files run: git diff --exit-code || (echo "ESLint fixed some files. Please commit the changes." && exit 1) diff --git a/.gitignore b/.gitignore index 686d3f63..e6809560 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ demos/**/*.html !demos/react/src/index.html !demos/index-nocookies.html !demos/index.html + +# pnpm +.pnpm-debug.log diff --git a/.prettierignore b/.prettierignore index aeb004d8..7c81f7a7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,4 +7,5 @@ lib/dist # demos demos *.svg -prebid.js \ No newline at end of file +prebid.js +pnpm-lock.yaml diff --git a/.tool-versions b/.tool-versions index 2fa10abe..d9c22262 100644 --- a/.tool-versions +++ b/.tool-versions @@ -2,3 +2,4 @@ nodejs 22.12.0 semver 3.3.0 mkcert 1.4.4 pre-commit 4.0.1 +pnpm 10.11.0 diff --git a/Makefile b/Makefile index 33dc3edc..5f800e92 100644 --- a/Makefile +++ b/Makefile @@ -2,22 +2,22 @@ .PHONY: test-sdk test: deps - npm run test + pnpm test .PHONY: build-web build-web: deps - npm run build-web -- --mode=production + pnpm build-web -- --mode=production .PHONY: build-lib build-lib: deps - npm run build-lib + pnpm build-lib .PHONY: build build: build-web build-lib .PHONY: deps deps: - npm ci + pnpm install --frozen-lockfile export SDK_URI ?= https://localhost:8181/sdk.js export DCN_HOST ?= ca.edge.optable.co @@ -65,13 +65,13 @@ demo-html: .PHONY: demo-react demo-react: build-lib - npm --prefix demos/react ci - npm --prefix demos/react run build + pnpm --prefix demos/react install --frozen-lockfile + pnpm --prefix demos/react run build .PHONY: demo-npm demo-npm: - npm --prefix demos/npm ci - npm --prefix demos/npm run build + pnpm --prefix demos/npm install --frozen-lockfile + pnpm --prefix demos/npm run build .PHONY: certs certs: diff --git a/README.md b/README.md index 86398493..c1b1580f 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ JavaScript SDK for integrating with an [Optable Data Connectivity Node (DCN)](ht ## Contents - [Installing](#installing) - - [npm module](#npm-module) - - [script tag](#script-tag) + - [NPM module](#npm-module) + - [Script tag](#script-tag) - [Versioning](#versioning) - [Domains and Cookies](#domains-and-cookies) - [LocalStorage](#localstorage) -- [Using the npm module](#using-the-npm-module) +- [Using the NPM module](#using-the-npm-module) - [Identify API](#identify-api) - [Profile API](#profile-api) - [Targeting API](#targeting-api) @@ -32,22 +32,25 @@ JavaScript SDK for integrating with an [Optable Data Connectivity Node (DCN)](ht ## Installing -The [Optable](https://optable.co/) web SDK can be installed as a ES6 compatible [npm](https://www.npmjs.com/) module paired with module bundlers such as [webpack](https://webpack.js.org/) or [browserify](http://browserify.org/), or can be loaded on a webpage directly by referencing a release build from the page HTML via a `