From 4faabe66e9b38b0ba71668d990d37bb097fbc58d Mon Sep 17 00:00:00 2001 From: Charis Lam <26616127+charislam@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:18:53 -0500 Subject: [PATCH] test: test node packages --- .github/workflows/build.yml | 160 +++++++++++++++++++++++++++ packages/supa-mdx-lint/package.json | 3 + packages/supa-mdx-lint/src/helper.js | 5 +- packages/supa-mdx-lint/src/index.js | 2 + 4 files changed, 166 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d62941..631e200 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -197,3 +197,163 @@ jobs: name: artifact-npm-binary-distributions path: npm-binary-distributions/*/*.tgz if-no-files-found: "error" + + test-linux: + runs-on: ubuntu-latest + needs: [node, npm-distributions] + strategy: + fail-fast: false + matrix: + node-version: [18, 20, 22] + steps: + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: artifact-npm-binary-distributions + path: ./npm-binary-distributions + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: artifact-pkg-node + path: ./node-pkg + - name: Create package.json + run: | + mkdir test + cd test + cat < package.json + { + "name": "test", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "lint": "supa-mdx-lint --version" + }, + "keywords": [], + "author": "", + "license": "ISC" + } + EOF + - name: Install test packages + working-directory: test + run: | + npm install ../npm-binary-distributions/linux-x64/*.tgz + npm install ../node-pkg/*.tgz + - name: Test lint script + working-directory: test + run: npm run lint + + test-macos: + runs-on: macos-latest + needs: [node, npm-distributions] + strategy: + fail-fast: false + matrix: + node-version: [18, 20, 22] + steps: + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: artifact-npm-binary-distributions + path: ./npm-binary-distributions + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: artifact-pkg-node + path: ./node-pkg + - name: Create package.json + run: | + mkdir test + cd test + cat < package.json + { + "name": "test", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "lint": "supa-mdx-lint --version" + }, + "keywords": [], + "author": "", + "license": "ISC" + } + EOF + - name: Install test packages + working-directory: test + run: | + npm install ../npm-binary-distributions/darwin/*.tgz + npm install ../node-pkg/*.tgz + - name: Test lint script + working-directory: test + run: npm run lint + + test-windows: + runs-on: windows-latest + needs: [node, npm-distributions] + strategy: + fail-fast: false + matrix: + node-version: [18, 20, 22] + steps: + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: artifact-npm-binary-distributions + path: ./npm-binary-distributions + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: artifact-pkg-node + path: ./node-pkg + - name: Create package.json + shell: pwsh + run: | + mkdir test + cd test + $json = @" + { + "name": "test", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "lint": "supa-mdx-lint --version" + }, + "keywords": [], + "author": "", + "license": "ISC" + } + "@ + $json | Out-File -FilePath package.json -Encoding utf8 + - name: Unpack binary tarball + shell: pwsh + run: | + $tarballPath = Get-ChildItem -Path npm-binary-distributions\win32-x64\*.tgz | Select-Object -First 1 + tar -xzf $tarballPath.FullName -C npm-binary-distributions\win32-x64 + Get-ChildItem -Path npm-binary-distributions\win32-x64\package + - name: Install binary + run: | + cd test + npm install ..\npm-binary-distributions\win32-x64\package + - name: Unpack node-pkg tarball + shell: pwsh + run: | + $tarballPath = Get-ChildItem -Path node-pkg\*.tgz | Select-Object -First 1 + mkdir -Path "test\node_modules\supa-mdx-lint-node-pkg" -Force + tar -xzf $tarballPath.FullName -C test\node_modules\supa-mdx-lint-node-pkg + - name: Install main package + run: | + cd test + npm install node_modules\supa-mdx-lint-node-pkg\package + - name: Test lint script + working-directory: test + run: | + cat package.json + cat package-lock.json + ls -r node_modules + ls -r node_modules\@supabase\supa-mdx-lint-win32-x64 + npm run lint diff --git a/packages/supa-mdx-lint/package.json b/packages/supa-mdx-lint/package.json index 836ca4d..a23a885 100644 --- a/packages/supa-mdx-lint/package.json +++ b/packages/supa-mdx-lint/package.json @@ -2,6 +2,9 @@ "name": "@supabase/supa-mdx-lint", "version": "0.1.6-pre", "main": "src/index.js", + "bin": { + "supa-mdx-lint": "src/index.js" + }, "scripts": { "format": "prettier --write .", "format:check": "prettier --check .", diff --git a/packages/supa-mdx-lint/src/helper.js b/packages/supa-mdx-lint/src/helper.js index 06f0993..483c70b 100644 --- a/packages/supa-mdx-lint/src/helper.js +++ b/packages/supa-mdx-lint/src/helper.js @@ -127,9 +127,8 @@ function getBinaryPath() { throwUnsupportedPlatformError(); } - let compatibleBinaryPath; try { - compatibleBinaryPath = require.resolve(`${packageName}/${subpath}`); + return require.resolve(`${packageName}/${subpath}`); } catch { const otherInstalledDistribution = BINARY_DISTRIBUTIONS.find( ({ packageName, subpath }) => { @@ -155,8 +154,6 @@ To fix this, avoid copying the "node_modules" folder, and instead freshly instal It seems like none of the "@supabase/supa-mdx-lint" package's optional dependencies got installed. Please make sure your package manager is configured to install optional dependencies. If you are using npm to install your dependencies, please don't set the "--no-optional", "--ignore-optional", or "--omit=optional" flags. supa-mdx-lint needs the "optionalDependencies" feature in order to install its binary.`); } } - - return compatibleBinaryPath; } /** diff --git a/packages/supa-mdx-lint/src/index.js b/packages/supa-mdx-lint/src/index.js index cfe630a..5b56243 100644 --- a/packages/supa-mdx-lint/src/index.js +++ b/packages/supa-mdx-lint/src/index.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + //@ ts-check "use strict";