Skip to content

Commit

Permalink
Publish native packages separately
Browse files Browse the repository at this point in the history
  • Loading branch information
padmaia committed Aug 11, 2021
1 parent 44112e8 commit 7420620
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -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'}}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions packages/next/build/swc/npm/.gitignore
@@ -0,0 +1 @@
next-swc.*.node
2 changes: 1 addition & 1 deletion packages/next/package.json
Expand Up @@ -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": [
Expand Down
32 changes: 26 additions & 6 deletions scripts/prepublish-native.js → scripts/publish-native.js
Expand Up @@ -3,19 +3,23 @@
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) {
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(
Expand All @@ -28,11 +32,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(
Expand All @@ -47,4 +65,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')
})()

0 comments on commit 7420620

Please sign in to comment.