Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(napi/transform): export react refresh options #5533

Merged

Conversation

underfin
Copy link
Contributor

@underfin underfin commented Sep 6, 2024

No description provided.

Copy link

graphite-app bot commented Sep 6, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@underfin
Copy link
Contributor Author

underfin commented Sep 6, 2024

Not sure the ci check error git diff --exit-code. My local napi-cli version is correct to generate binding files.

Copy link

codspeed-hq bot commented Sep 6, 2024

CodSpeed Performance Report

Merging #5533 will not alter performance

Comparing underfin:napi-tranform-reac-refresh-options (ca4208c) with main (919d17f)

Summary

✅ 29 untouched benchmarks

@IWANABETHATGUY
Copy link
Contributor

IWANABETHATGUY commented Sep 7, 2024

I got same diff after run pnpm build

diff
diff --git a/napi/transform/index.d.ts b/napi/transform/index.d.ts
index e0c6fc555..c7081c9d3 100644
--- a/napi/transform/index.d.ts
+++ b/napi/transform/index.d.ts
@@ -1,36 +1,35 @@
-/* tslint:disable */
-/* eslint-disable */
-
/* auto-generated by NAPI-RS */
-
-export interface TypeScriptBindingOptions {
-  jsxPragma?: string
-  jsxPragmaFrag?: string
-  onlyRemoveTypeImports?: boolean
-  allowNamespaces?: boolean
-  allowDeclareFields?: boolean
-  /**
-   * Also generate a `.d.ts` declaration file for TypeScript files.
-   *
-   * The source file must be compliant with all
-   * [`isolatedDeclarations`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations)
-   * requirements.
-   *
-   * @default false
-   */
-  declaration?: boolean
+/* eslint-disable */
+export interface ArrowFunctionsBindingOptions {
 /**
-   * Rewrite or remove TypeScript import/export declaration extensions.
-   *
-   * - When set to `rewrite`, it will change `.ts`, `.mts`, `.cts` extensions to `.js`, `.mjs`, `.cjs` respectively.
-   * - When set to `remove`, it will remove `.ts`/`.mts`/`.cts`/`.tsx` extension entirely.
-   * - When set to `true`, it's equivalent to `rewrite`.
-   * - When set to `false` or omitted, no changes will be made to the extensions.
+   * This option enables the following:
+   * * Wrap the generated function in .bind(this) and keeps uses of this inside the function as-is, instead of using a renamed this.
+   * * Add a runtime check to ensure the functions are not instantiated.
+   * * Add names to arrow functions.
  *
  * @default false
  */
-  rewriteImportExtensions?: 'rewrite' | 'remove' | boolean
+  spec?: boolean
+}
+
+export interface Es2015BindingOptions {
+  /** Transform arrow functions into function expressions. */
+  arrowFunction?: ArrowFunctionsBindingOptions
+}
+
+/** TypeScript Isolated Declarations for Standalone DTS Emit */
+export declare function isolatedDeclaration(filename: string, sourceText: string, options: IsolatedDeclarationsOptions): IsolatedDeclarationsResult
+
+export interface IsolatedDeclarationsOptions {
+  sourcemap: boolean
}
+
+export interface IsolatedDeclarationsResult {
+  code: string
+  map?: SourceMap
+  errors: Array<string>
+}
+
/**
* Configure how TSX and JSX are transformed.
*
@@ -117,6 +116,7 @@ export interface ReactBindingOptions {
 /** Enable react fast refresh transform */
 refresh?: ReactRefreshBindingOptions
}
+
export interface ReactRefreshBindingOptions {
 /**
  * Specify the identifier of the refresh registration variable.
@@ -132,21 +132,30 @@ export interface ReactRefreshBindingOptions {
 refreshSig?: string
 emitFullSignatures?: boolean
}
-export interface ArrowFunctionsBindingOptions {
-  /**
-   * This option enables the following:
-   * * Wrap the generated function in .bind(this) and keeps uses of this inside the function as-is, instead of using a renamed this.
-   * * Add a runtime check to ensure the functions are not instantiated.
-   * * Add names to arrow functions.
-   *
-   * @default false
-   */
-  spec?: boolean
-}
-export interface Es2015BindingOptions {
-  /** Transform arrow functions into function expressions. */
-  arrowFunction?: ArrowFunctionsBindingOptions
+
+export interface SourceMap {
+  file?: string
+  mappings?: string
+  sourceRoot?: string
+  sources?: Array<string | undefined | null>
+  sourcesContent?: Array<string | undefined | null>
+  names?: Array<string>
}
+
+/**
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version.
+ *
+ * @param filename The name of the file being transformed. If this is a
+ * relative path, consider setting the {@link TransformOptions#cwd} option..
+ * @param sourceText the source code itself
+ * @param options The options for the transformation. See {@link
+ * TransformOptions} for more information.
+ *
+ * @returns an object containing the transformed code, source maps, and any
+ * errors that occurred during parsing or transformation.
+ */
+export declare function transform(filename: string, sourceText: string, options?: TransformOptions | undefined | null): TransformResult
+
/**
* Options for transforming a JavaScript or TypeScript file.
*
@@ -182,24 +191,7 @@ export interface TransformOptions {
  */
 sourcemap?: boolean
}
-export interface SourceMap {
-  file?: string
-  mappings?: string
-  sourceRoot?: string
-  sources?: Array<string | undefined | null>
-  sourcesContent?: Array<string | undefined | null>
-  names?: Array<string>
-}
-export interface IsolatedDeclarationsResult {
-  code: string
-  map?: SourceMap
-  errors: Array<string>
-}
-export interface IsolatedDeclarationsOptions {
-  sourcemap: boolean
-}
-/** TypeScript Isolated Declarations for Standalone DTS Emit */
-function isolatedDeclaration(filename: string, sourceText: string, options: IsolatedDeclarationsOptions): IsolatedDeclarationsResult
+
export interface TransformResult {
 /**
  * The transformed code.
@@ -239,16 +231,33 @@ export interface TransformResult {
  */
 errors: Array<string>
}
-/**
- * Transpile a JavaScript or TypeScript into a target ECMAScript version.
- *
- * @param filename The name of the file being transformed. If this is a
- * relative path, consider setting the {@link TransformOptions#cwd} option..
- * @param sourceText the source code itself
- * @param options The options for the transformation. See {@link
- * TransformOptions} for more information.
- *
- * @returns an object containing the transformed code, source maps, and any
- * errors that occurred during parsing or transformation.
- */
-function transform(filename: string, sourceText: string, options?: TransformOptions | undefined | null): TransformResult
+
+export interface TypeScriptBindingOptions {
+  jsxPragma?: string
+  jsxPragmaFrag?: string
+  onlyRemoveTypeImports?: boolean
+  allowNamespaces?: boolean
+  allowDeclareFields?: boolean
+  /**
+   * Also generate a `.d.ts` declaration file for TypeScript files.
+   *
+   * The source file must be compliant with all
+   * [`isolatedDeclarations`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations)
+   * requirements.
+   *
+   * @default false
+   */
+  declaration?: boolean
+  /**
+   * Rewrite or remove TypeScript import/export declaration extensions.
+   *
+   * - When set to `rewrite`, it will change `.ts`, `.mts`, `.cts` extensions to `.js`, `.mjs`, `.cjs` respectively.
+   * - When set to `remove`, it will remove `.ts`/`.mts`/`.cts`/`.tsx` extension entirely.
+   * - When set to `true`, it's equivalent to `rewrite`.
+   * - When set to `false` or omitted, no changes will be made to the extensions.
+   *
+   * @default false
+   */
+  rewriteImportExtensions?: 'rewrite' | 'remove' | boolean
+}
+
diff --git a/napi/transform/index.js b/napi/transform/index.js
index 405b84e01..e1092b640 100644
--- a/napi/transform/index.js
+++ b/napi/transform/index.js
@@ -1,316 +1,365 @@
-/* tslint:disable */
+// prettier-ignore
/* eslint-disable */
-/* prettier-ignore */
-
/* auto-generated by NAPI-RS */

-const { existsSync, readFileSync } = require('fs')
-const { join } = require('path')
-
-const { platform, arch } = process
+const { readFileSync } = require('fs')

let nativeBinding = null
-let localFileExisted = false
-let loadError = null
+const loadErrors = []

-function isMusl() {
-  // For Node 10
-  if (!process.report || typeof process.report.getReport !== 'function') {
-    try {
-      const lddPath = require('child_process').execSync('which ldd').toString().trim()
-      return readFileSync(lddPath, 'utf8').includes('musl')
-    } catch (e) {
+const isMusl = () => {
+  let musl = false
+  if (process.platform === 'linux') {
+    musl = isMuslFromFilesystem()
+    if (musl === null) {
+      musl = isMuslFromReport()
+    }
+    if (musl === null) {
+      musl = isMuslFromChildProcess()
+    }
+  }
+  return musl
+}
+
+const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
+
+const isMuslFromFilesystem = () => {
+  try {
+    return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
+  } catch {
+    return null
+  }
+}
+
+const isMuslFromReport = () => {
+  const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
+  if (!report) {
+    return null
+  }
+  if (report.header && report.header.glibcVersionRuntime) {
+    return false
+  }
+  if (Array.isArray(report.sharedObjects)) {
+    if (report.sharedObjects.some(isFileMusl)) {
     return true
   }
-  } else {
-    const { glibcVersionRuntime } = process.report.getReport().header
-    return !glibcVersionRuntime
 }
+  return false
}

-switch (platform) {
-  case 'android':
-    switch (arch) {
-      case 'arm64':
-        localFileExisted = existsSync(join(__dirname, 'index.android-arm64.node'))
+const isMuslFromChildProcess = () => {
+  try {
+    return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
+  } catch (e) {
+    // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
+    return false
+  }
+}
+
+function requireNative() {
+  if (process.platform === 'android') {
+    if (process.arch === 'arm64') {
+      try {
+        return require('./transform.android-arm64.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-android-arm64')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else if (process.arch === 'arm') {
+      try {
+        return require('./transform.android-arm-eabi.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-android-arm-eabi')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else {
+      loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
+    }
+  } else if (process.platform === 'win32') {
+    if (process.arch === 'x64') {
+      try {
+        return require('./transform.win32-x64-msvc.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-win32-x64-msvc')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else if (process.arch === 'ia32') {
+      try {
+        return require('./transform.win32-ia32-msvc.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-win32-ia32-msvc')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else if (process.arch === 'arm64') {
+      try {
+        return require('./transform.win32-arm64-msvc.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-win32-arm64-msvc')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else {
+      loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
+    }
+  } else if (process.platform === 'darwin') {
+    try {
+        return require('./transform.darwin-universal.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-darwin-universal')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    if (process.arch === 'x64') {
+      try {
+        return require('./transform.darwin-x64.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-darwin-x64')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else if (process.arch === 'arm64') {
+      try {
+        return require('./transform.darwin-arm64.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-darwin-arm64')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else {
+      loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
+    }
+  } else if (process.platform === 'freebsd') {
+    if (process.arch === 'x64') {
+      try {
+        return require('./transform.freebsd-x64.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-freebsd-x64')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else if (process.arch === 'arm64') {
+      try {
+        return require('./transform.freebsd-arm64.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-freebsd-arm64')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else {
+      loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
+    }
+  } else if (process.platform === 'linux') {
+    if (process.arch === 'x64') {
+      if (isMusl()) {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.android-arm64.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-android-arm64')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      case 'arm':
-        localFileExisted = existsSync(join(__dirname, 'index.android-arm-eabi.node'))
+        return require('./transform.linux-x64-musl.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-x64-musl')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+      } else {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.android-arm-eabi.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-android-arm-eabi')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      default:
-        throw new Error(`Unsupported architecture on Android ${arch}`)
-    }
-    break
-  case 'win32':
-    switch (arch) {
-      case 'x64':
-        localFileExisted = existsSync(
-          join(__dirname, 'index.win32-x64-msvc.node')
-        )
+        return require('./transform.linux-x64-gnu.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-x64-gnu')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+      }
+    } else if (process.arch === 'arm64') {
+      if (isMusl()) {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.win32-x64-msvc.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-win32-x64-msvc')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      case 'ia32':
-        localFileExisted = existsSync(
-          join(__dirname, 'index.win32-ia32-msvc.node')
-        )
+        return require('./transform.linux-arm64-musl.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-arm64-musl')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+      } else {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.win32-ia32-msvc.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-win32-ia32-msvc')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      case 'arm64':
-        localFileExisted = existsSync(
-          join(__dirname, 'index.win32-arm64-msvc.node')
-        )
+        return require('./transform.linux-arm64-gnu.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-arm64-gnu')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+      }
+    } else if (process.arch === 'arm') {
+      if (isMusl()) {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.win32-arm64-msvc.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-win32-arm64-msvc')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      default:
-        throw new Error(`Unsupported architecture on Windows: ${arch}`)
-    }
-    break
-  case 'darwin':
-    localFileExisted = existsSync(join(__dirname, 'index.darwin-universal.node'))
-    try {
-      if (localFileExisted) {
-        nativeBinding = require('./index.darwin-universal.node')
+        return require('./transform.linux-arm-musleabihf.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-arm-musleabihf')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
     } else {
-        nativeBinding = require('@oxc-transform/binding-darwin-universal')
+        try {
+        return require('./transform.linux-arm-gnueabihf.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-arm-gnueabihf')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
     }
-      break
-    } catch {}
-    switch (arch) {
-      case 'x64':
-        localFileExisted = existsSync(join(__dirname, 'index.darwin-x64.node'))
+    } else if (process.arch === 'riscv64') {
+      if (isMusl()) {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.darwin-x64.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-darwin-x64')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      case 'arm64':
-        localFileExisted = existsSync(
-          join(__dirname, 'index.darwin-arm64.node')
-        )
+        return require('./transform.linux-riscv64-musl.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-riscv64-musl')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+      } else {
       try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.darwin-arm64.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-darwin-arm64')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      default:
-        throw new Error(`Unsupported architecture on macOS: ${arch}`)
+        return require('./transform.linux-riscv64-gnu.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-riscv64-gnu')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+      }
+    } else if (process.arch === 'ppc64') {
+      try {
+        return require('./transform.linux-ppc64-gnu.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-ppc64-gnu')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else if (process.arch === 's390x') {
+      try {
+        return require('./transform.linux-s390x-gnu.node')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+      try {
+        return require('@oxc-transform/binding-linux-s390x-gnu')
+      } catch (e) {
+        loadErrors.push(e)
+      }
+
+    } else {
+      loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
   }
-    break
-  case 'freebsd':
-    if (arch !== 'x64') {
-      throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
+  } else {
+    loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
+  }
+}
+
+nativeBinding = requireNative()
+
+if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
+  try {
+    nativeBinding = require('./transform.wasi.cjs')
+  } catch (err) {
+    if (process.env.NAPI_RS_FORCE_WASI) {
+      console.error(err)
   }
-    localFileExisted = existsSync(join(__dirname, 'index.freebsd-x64.node'))
+  }
+  if (!nativeBinding) {
   try {
-      if (localFileExisted) {
-        nativeBinding = require('./index.freebsd-x64.node')
-      } else {
-        nativeBinding = require('@oxc-transform/binding-freebsd-x64')
+      nativeBinding = require('@oxc-transform/binding-wasm32-wasi')
+    } catch (err) {
+      if (process.env.NAPI_RS_FORCE_WASI) {
+        console.error(err)
     }
-    } catch (e) {
-      loadError = e
-    }
-    break
-  case 'linux':
-    switch (arch) {
-      case 'x64':
-        if (isMusl()) {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-x64-musl.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-x64-musl.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-x64-musl')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        } else {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-x64-gnu.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-x64-gnu.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-x64-gnu')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        }
-        break
-      case 'arm64':
-        if (isMusl()) {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-arm64-musl.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-arm64-musl.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-arm64-musl')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        } else {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-arm64-gnu.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-arm64-gnu.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-arm64-gnu')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        }
-        break
-      case 'arm':
-        if (isMusl()) {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-arm-musleabihf.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-arm-musleabihf.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-arm-musleabihf')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        } else {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-arm-gnueabihf.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-arm-gnueabihf.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-arm-gnueabihf')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        }
-        break
-      case 'riscv64':
-        if (isMusl()) {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-riscv64-musl.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-riscv64-musl.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-riscv64-musl')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        } else {
-          localFileExisted = existsSync(
-            join(__dirname, 'index.linux-riscv64-gnu.node')
-          )
-          try {
-            if (localFileExisted) {
-              nativeBinding = require('./index.linux-riscv64-gnu.node')
-            } else {
-              nativeBinding = require('@oxc-transform/binding-linux-riscv64-gnu')
-            }
-          } catch (e) {
-            loadError = e
-          }
-        }
-        break
-      case 's390x':
-        localFileExisted = existsSync(
-          join(__dirname, 'index.linux-s390x-gnu.node')
-        )
-        try {
-          if (localFileExisted) {
-            nativeBinding = require('./index.linux-s390x-gnu.node')
-          } else {
-            nativeBinding = require('@oxc-transform/binding-linux-s390x-gnu')
-          }
-        } catch (e) {
-          loadError = e
-        }
-        break
-      default:
-        throw new Error(`Unsupported architecture on Linux: ${arch}`)
   }
-    break
-  default:
-    throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
+  }
}

if (!nativeBinding) {
-  if (loadError) {
-    throw loadError
+  if (loadErrors.length > 0) {
+    // TODO Link to documentation with potential fixes
+    //  - The package owner could build/publish bindings for this arch
+    //  - The user may need to bundle the correct files
+    //  - The user may need to re-install node_modules to get new packages
+    throw new Error('Failed to load native binding', { cause: loadErrors })
 }
 throw new Error(`Failed to load native binding`)
}

-const { isolatedDeclaration, transform } = nativeBinding
-
-module.exports.isolatedDeclaration = isolatedDeclaration
-module.exports.transform = transform
+module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration
+module.exports.transform = nativeBinding.transform

@IWANABETHATGUY
Copy link
Contributor

I think you could revert the changes that are auto-generated, the issue related to ci should be solved

@Boshen Boshen force-pushed the napi-tranform-reac-refresh-options branch from 1e1b1a6 to ca4208c Compare September 7, 2024 16:36
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 7, 2024
Copy link

graphite-app bot commented Sep 7, 2024

Merge activity

  • Sep 7, 12:37 PM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 7, 12:44 PM EDT: Boshen added this pull request to the Graphite merge queue.
  • Sep 7, 12:48 PM EDT: The Graphite merge queue couldn't merge this PR because it failed for an unknown reason (Stack merges are not currently supported for forked repositories. Please create a branch in the target repository in order to merge).

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 7, 2024
@Dunqing Dunqing merged commit aba9194 into oxc-project:main Sep 8, 2024
27 checks passed
@underfin underfin deleted the napi-tranform-reac-refresh-options branch September 9, 2024 02:28
Boshen added a commit that referenced this pull request Sep 11, 2024
## [0.28.0] - 2024-09-11

- afc4548 ast: [**BREAKING**] Educe byte size of
`TaggedTemplateExpression::quasi` by `Boxing` it (#5679) (Boshen)

- 7415e85 ast: [**BREAKING**] Reduce byte size of
`TSImportType::attributes` by `Box`ing it (#5678) (Boshen)

- ee4fb42 ast: [**BREAKING**] Reduce size of `WithClause` by `Box`ing it
(#5677) (Boshen)

- 1fa3e56 semantic: [**BREAKING**] Rename `SymbolTable::iter` to
`symbol_ids` (#5621) (overlookmotel)

- 96a1552 semantic: [**BREAKING**] Remove `SymbolTable::iter_rev`
(#5620) (overlookmotel)

- 4a8aec1 span: [**BREAKING**] Change `SourceType::js` to
`SourceType::cjs` and `SourceType::mjs` (#5606) (Boshen)

- 603817b oxc: [**BREAKING**] Add `SourceType::Unambiguous`; parse `.js`
as unambiguous (#5557) (Boshen)

- b060525 semantic: [**BREAKING**] Remove `source_type` argument from
`SemanticBuilder::new` (#5553) (Boshen)

### Features

- 2da5ad1 ast: Add `JSXElementName::get_identifier` method (#5556)
(overlookmotel)
- 2016bae coverage: Add regular expression idempotency test (#5676)
(Boshen)
- 68c3cf5 minifier: Fold `void 1` -> `void 0` (#5670) (Boshen)
- c6bbf94 minifier: Constant fold unary expression (#5669) (Boshen)
- 86256ea minifier: Constant fold `typeof` (#5666) (Boshen)
- e698418 napi/transform: Align output `SourceMap` with Rollup's
`ExistingRawSourceMap` (#5657) (Boshen)
- aba9194 napi/transform: Export react refresh options (#5533)
(underfin)
- 642295c semantic: Add `SymbolTable::delete_resolved_reference` method
(#5558) (overlookmotel)
- b3cbd56 span: `format_compact_str!` macro (#5610) (overlookmotel)
- 95a6d99 transformer: Enable the react refresh plugin in enable_all
(#5630) (Dunqing)
- 7b543df transformer/react: Handle `refresh_sig` and `refresh_reg`
options correctly (#5638) (Dunqing)
- 17226dd traverse: Add methods for deleting references (#5559)
(overlookmotel)

### Bug Fixes

- d62defb codegen: Do not print trailing commas for `ArrayExpression`
(#5551) (Boshen)
- 1bc08e2 coverage: Parse babel unambiguously (#5579) (Boshen)
- 28b934c coverage: Apply `always_strict` to test262 and typescript per
the specifcation (#5555) (Boshen)
- b9bf544 isolated-declarations: False positive for setter method in
`interface` (#5681) (Dunqing)
- 6e8409a isolated-declarations: Bindings referenced in
`TSModuleDeclaration` are removed incorrectly (#5680) (Dunqing)
- b8f8dd6 minifier/replace_global_defines: Do not replace shadowed
identifiers (#5691) (Boshen)
- 304ce25 regular_expression: Keep LegacyOctalEscape raw digits for
`to_string` (#5692) (leaysgur)
- 0511d55 regular_expression: Report more MayContainStrings error in
(nested)class (#5661) (leaysgur)
- 41582ea regular_expression: Improve RegExp `to_string()` results
(#5635) (leaysgur)
- 28aad28 regular_expression: Handle `-` in `/[\-]/u` as escaped
character (#5631) (leaysgur)
- f9e3a41 semantic: Bind `SymbolId` to function name in `if (foo)
function id() {}` (#5673) (Boshen)
- f49e6eb span: Treat `.js` as `module` file (reverts the previous
breaking change) (#5612) (Boshen)
- 919d17f transform_conformance: Only print semantic mismatch errors
when output is correct (#5589) (Boshen)
- 505d064 transformer: JSX transform delete references for
`JSXClosingElement`s (#5560) (overlookmotel)
- 9b7ecc7 transformer: RegExp transform only set span on final
expression (#5508) (overlookmotel)
- d1ece19 transformer: RegExp transform handle `Term::Quantifier`
(#5501) (overlookmotel)
- a1afd48 transformer/react: Incorrect scope_id for var hoisted in fast
refresh plugin (#5695) (Dunqing)
- f2f5e5a transformer/react: Missing scope_id for function in fast
refresh plugin (#5693) (Dunqing)
- a891c31 transformer/react: Refresh plugin has incorrect reference
flags (#5656) (Dunqing)
- 3e8b96f transformer/react: The refresh plugin cannot handle member
expressions with React hooks (#5655) (Dunqing)
- 0739b5f transformer/react: Don't transform declaration of function
overloads (#5642) (Dunqing)
- 3bf6aaf transformer/react: Support `emit_full_signatures` option in
refresh plugin (#5629) (Dunqing)
- 36d864a transformer/react: Don't transform if the variable does not
have a value reference (#5528) (Dunqing)

### Performance

- e8013d2 traverse: Faster string operations generating UIDs (#5626)
(overlookmotel)
- 4996874 traverse: `generate_uid` cache available binding names (#5611)
(overlookmotel)

### Documentation

- fefbbc1 sourcemap: Add trailing newline to README (#5539)
(overlookmotel)
- 9282647 transformer: Comment on RegExp transform for potential
improvement (#5514) (overlookmotel)
- 1c051ae traverse: Correct code comment 2 (#5607) (overlookmotel)
- 2e24a15 traverse: Correct code comment (#5604) (overlookmotel)

### Refactor

- 14ee086 ast: Inline `AstKind::as_*` methods (#5547) (overlookmotel)
- 2de6ea0 index, traverse: Remove unnecessary type annotations (#5650)
(overlookmotel)
- 0ac420d linter: Use meaningful names for diagnostic parameters (#5564)
(Don Isaac)
- 2da42ef regular_expression: Improve AST docs with refactoring
may_contain_strings (#5665) (leaysgur)
- dec1395 regular_expression: Align diagnostics (#5543) (leaysgur)
- 731ffaa semantic: Compare nodes by pointer equality (#5686)
(overlookmotel)
- 067f9b5 semantic: Introduce `IsGlobalReference` trait (#5672) (Boshen)
- d22a9b7 semantic: `SymbolTable::is_empty` use `is_empty` (#5622)
(overlookmotel)
- 3d190a5 span: Move `CompactStr` into separate file (#5609)
(overlookmotel)
- 5532628 span: Put types and impl in the same mod file (Boshen)
- ce71982 transformer: Shorten code in JSX transform (#5554)
(overlookmotel)
- 758a10c transformer: RegExp transform reuse var (#5527)
(overlookmotel)
- fad0a05 transformer: RegExp transform unbox early (#5504)
(overlookmotel)
- 19cdcc5 traverse: Revert changes to `walk.rs` (#5652) (overlookmotel)-
26d9235 Enable clippy::ref_as_ptr (#5577) (夕舞八弦)

### Styling

- e52d006 traverse: Fix formatting of traverse codegen (#5651)
(overlookmotel)
- 97e99bd traverse: Remove excess line break (#5603) (overlookmotel)-
694f032 Add trailing line breaks to `package.json` files (#5542)
(overlookmotel)

### Testing

- 2e367c9 traverse: Enable tests for `oxc_traverse` crate (#5625)
(overlookmotel)- dc92489 Add trailing line breaks to conformance
fixtures (#5541) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants