From cdf928e43487a72108e14999c6e732e2ad6bd0d8 Mon Sep 17 00:00:00 2001 From: Maia Teegarden Date: Wed, 11 Aug 2021 16:41:16 -0700 Subject: [PATCH] Publish native packages separately --- .github/workflows/build_test_deploy.yml | 12 ++++--- packages/next/build/swc/npm/.gitignore | 1 + packages/next/package.json | 2 +- ...prepublish-native.js => publish-native.js} | 35 +++++++++++++++---- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 packages/next/build/swc/npm/.gitignore rename scripts/{prepublish-native.js => publish-native.js} (57%) diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 70e558f31fe8f27..53ceba2afadb445 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -60,7 +60,11 @@ jobs: - uses: actions/download-artifact@v2 with: name: next-swc-binaries - path: packages/next/native + path: packages/next/build/swc/dist + # Only check linux build for now, mac builds can sometimes be different even with the same code + - run: | + mv ./packages/next/build/swc/dist/next-swc.linux-x64-gnu.node \ + ./packages/next/native/next-swc.linux-x64-gnu.node - run: ./scripts/check-pre-compiled.sh if: ${{needs.build.outputs.docsChange != 'docs only change'}} @@ -260,8 +264,8 @@ jobs: - uses: actions/download-artifact@v2 with: name: next-swc-binaries - path: packages/next/native - - run: ./scripts/prepublish-native.js + path: packages/next/build/swc/dist + - run: ./scripts/publish-native.js $GITHUB_REF - run: ./scripts/publish-release.sh releaseStats: @@ -325,7 +329,7 @@ jobs: id: binary-cache uses: actions/cache@v2 with: - path: packages/next/native/** + path: packages/next/native/next-swc.*.node key: next-swc-nightly-2021-03-25-${{ matrix.target }}-${{ hashFiles('packages/next/build/swc/**') }} - name: 'Build' if: steps.binary-cache.outputs.cache-hit != 'true' diff --git a/packages/next/build/swc/npm/.gitignore b/packages/next/build/swc/npm/.gitignore new file mode 100644 index 000000000000000..b193075caa3a2a7 --- /dev/null +++ b/packages/next/build/swc/npm/.gitignore @@ -0,0 +1 @@ +next-swc.*.node \ No newline at end of file diff --git a/packages/next/package.json b/packages/next/package.json index 84dfaa352455cda..51c364a69d9477b 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -54,7 +54,7 @@ "types": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "typescript": "tsc --noEmit --declaration", "ncc-compiled": "ncc cache clean && taskr ncc", - "build-native": "npx -p @napi-rs/cli napi build --platform --release --cargo-cwd build/swc native" + "build-native": "npx -p @napi-rs/cli@1.2.1 napi build --platform --release --cargo-cwd build/swc native" }, "taskr": { "requires": [ diff --git a/scripts/prepublish-native.js b/scripts/publish-native.js similarity index 57% rename from scripts/prepublish-native.js rename to scripts/publish-native.js index 803c45ba3d653cb..583f0a9091a9d9c 100755 --- a/scripts/prepublish-native.js +++ b/scripts/publish-native.js @@ -3,19 +3,26 @@ const path = require('path') const { readFile, readdir, writeFile } = require('fs/promises') const { copy } = require('fs-extra') +const util = require('util') +const exec = util.promisify(require('child_process').exec) const cwd = process.cwd() ;(async function () { let version = JSON.parse(await readFile(path.join(cwd, 'lerna.json'))).version + let gitref = process.argv.slice(2)[0] - // Copy binaries to package folders, update version, and copy package folders to packages directory + // Copy binaries to package folders, update version, and publish let nativePackagesDir = path.join(cwd, 'packages/next/build/swc/npm') let nativePackages = await readdir(nativePackagesDir) + let publishPromises = [] for (let nativePackage of nativePackages) { + if (nativePackage === '.gitignore') { + continue + } let binaryName = `next-swc.${nativePackage.substr(9)}.node` await copy( - path.join(cwd, 'packages/next/native', binaryName), + path.join(cwd, 'packages/next/build/swc/dist', binaryName), path.join(nativePackagesDir, nativePackage, binaryName) ) let pkg = JSON.parse( @@ -28,11 +35,25 @@ const cwd = process.cwd() path.join(nativePackagesDir, nativePackage, 'package.json'), JSON.stringify(pkg, null, 2) ) + publishPromises.push( + exec( + `npm publish ${path.join(nativePackagesDir, nativePackage)}${ + gitref.contains('canary') ? ' --tag canary' : '' + }` + ) + ) + // lerna publish in next step will fail if git status is not clean + publishPromises.push( + exec( + `git update-index --skip-worktree ${path.join( + nativePackagesDir, + nativePackage, + 'package.json' + )}` + ) + ) } - await copy( - path.join(cwd, 'packages/next/build/swc/npm'), - path.join(cwd, 'packages') - ) + await Promise.all(publishPromises) // Update optional dependencies versions let nextPkg = JSON.parse( @@ -47,4 +68,6 @@ const cwd = process.cwd() path.join(path.join(cwd, 'packages/next/package.json')), JSON.stringify(nextPkg, null, 2) ) + // lerna publish in next step will fail if git status is not clean + await exec('git update-index --skip-worktree packages/next/package.json') })()