<commit_before>#!/usr/bin/env node

const path = require('path')
const { readFile, readdir, writeFile } = require('fs/promises')
const { copy } = require('fs-extra')
const { execSync } = require('child_process')

const cwd = process.cwd()

;(async function () {
  try {
    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 publish
    let nativePackagesDir = path.join(cwd, 'packages/next-swc/crates/napi/npm')
    let platforms = (await readdir(nativePackagesDir)).filter(
      (name) => !name.startsWith('.')
    )

    for (let platform of platforms) {
      try {
        let binaryName = `next-swc.${platform}.node`
        await copy(
          path.join(cwd, 'packages/next-swc/native', binaryName),
          path.join(nativePackagesDir, platform, binaryName)
        )
        let pkg = JSON.parse(
          await readFile(path.join(nativePackagesDir, platform, 'package.json'))
        )
        pkg.version = version
        await writeFile(
          path.join(nativePackagesDir, platform, 'package.json'),
          JSON.stringify(pkg, null, 2)
        )
        execSync(
          `npm publish ${path.join(
            nativePackagesDir,
            platform
          )} --access public ${
            gitref.includes('canary') ? ' --tag canary' : ''
          }`
        )
      } catch (err) {
        // don't block publishing other versions on single platform error
        console.error(`Failed to publish`, platform)
        throw err
      }
      // lerna publish in next step will fail if git status is not clean
      execSync(
        `git update-index --skip-worktree ${path.join(
          nativePackagesDir,
          platform,
          'package.json'
        )}`
      )<commit_msg>Tolerate already published error for retrying (#40812)<commit_after>#!/usr/bin/env node

const path = require('path')
const { readFile, readdir, writeFile } = require('fs/promises')
const { copy } = require('fs-extra')
const { execSync } = require('child_process')

const cwd = process.cwd()

;(async function () {
  try {
    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 publish
    let nativePackagesDir = path.join(cwd, 'packages/next-swc/crates/napi/npm')
    let platforms = (await readdir(nativePackagesDir)).filter(
      (name) => !name.startsWith('.')
    )

    for (let platform of platforms) {
      try {
        let binaryName = `next-swc.${platform}.node`
        await copy(
          path.join(cwd, 'packages/next-swc/native', binaryName),
          path.join(nativePackagesDir, platform, binaryName)
        )
        let pkg = JSON.parse(
          await readFile(path.join(nativePackagesDir, platform, 'package.json'))
        )
        pkg.version = version
        await writeFile(
          path.join(nativePackagesDir, platform, 'package.json'),
          JSON.stringify(pkg, null, 2)
        )
        execSync(
          `npm publish ${path.join(
            nativePackagesDir,
            platform
          )} --access public ${
            gitref.includes('canary') ? ' --tag canary' : ''
          }`
        )
      } catch (err) {
        // don't block publishing other versions on single platform error
        console.error(`Failed to publish`, platform)

        if (
          err.message &&
          err.message.includes(
            'You cannot publish over the previously published versions'
          )
        ) {
          console.error('Ignoring already published error', platform)
        } else {
          throw err
        }
      }
      // lerna publish in next step will fail if git status is not clean
      execSync(
        `git update-index --skip-worktree ${path.join(
          nativePackagesDir,
          platform,
          'package.json'
        )}`
      )
{'fraction_non_alphanumeric': 0.12056561647233938, 'fraction_numerical': 0.0027288514016373107, 'mean_word_length': 2.1183294663573085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5292838', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1159, 'n_words': 292}