1- "use strict" ;
2-
3- const { cpSync, existsSync, mkdirSync, rmSync } = require ( "node:fs" ) ;
4- const path = require ( "node:path" ) ;
1+ import { cpSync , existsSync , mkdirSync , rmSync } from "node:fs" ;
2+ import path from "node:path" ;
3+ import {
4+ macOnlyNativeModules ,
5+ runtimeNativeModules ,
6+ } from "../runtime-dependencies" ;
57
68const ARCH_X64 = 1 ;
79const ARCH_ARM64 = 3 ;
810
9- function copyDep ( name , rootNodeModules , localNodeModules ) {
11+ type BeforePackContext = {
12+ packager : { platform : { name : string } } ;
13+ arch : number ;
14+ } ;
15+
16+ function copyDep (
17+ name : string ,
18+ rootNodeModules : string ,
19+ localNodeModules : string ,
20+ ) : boolean {
1021 const src = path . join ( rootNodeModules , name ) ;
1122 if ( ! existsSync ( src ) ) {
1223 const localSrc = path . join ( localNodeModules , name ) ;
@@ -31,15 +42,19 @@ function copyDep(name, rootNodeModules, localNodeModules) {
3142 return true ;
3243}
3344
34- function copyRequiredDep ( name , rootNodeModules , localNodeModules ) {
45+ function copyRequiredDep (
46+ name : string ,
47+ rootNodeModules : string ,
48+ localNodeModules : string ,
49+ ) : void {
3550 if ( ! copyDep ( name , rootNodeModules , localNodeModules ) ) {
3651 throw new Error (
3752 `[before-pack] required native dependency "${ name } " not found in node_modules` ,
3853 ) ;
3954 }
4055}
4156
42- module . exports = async function beforePack ( context ) {
57+ export default async function beforePack ( context : BeforePackContext ) {
4358 const platformName = context . packager . platform . name ;
4459 const arch = context . arch ;
4560
@@ -50,26 +65,7 @@ module.exports = async function beforePack(context) {
5065 console . log ( `[before-pack] root node_modules: ${ rootNodeModules } ` ) ;
5166 console . log ( `[before-pack] local node_modules: ${ localNodeModules } ` ) ;
5267
53- const commonDeps = [
54- "node-pty" ,
55- "node-addon-api" ,
56- "@parcel/watcher" ,
57- "micromatch" ,
58- "is-glob" ,
59- "detect-libc" ,
60- "braces" ,
61- "picomatch" ,
62- "is-extglob" ,
63- "fill-range" ,
64- "to-regex-range" ,
65- "is-number" ,
66- "better-sqlite3" ,
67- "bindings" ,
68- "file-uri-to-path" ,
69- "prebuild-install" ,
70- ] ;
71-
72- for ( const dep of commonDeps ) {
68+ for ( const dep of runtimeNativeModules ) {
7369 copyDep ( dep , rootNodeModules , localNodeModules ) ;
7470 }
7571
@@ -79,8 +75,9 @@ module.exports = async function beforePack(context) {
7975 ? "@parcel/watcher-darwin-x64"
8076 : "@parcel/watcher-darwin-arm64" ;
8177 copyRequiredDep ( watcherPkg , rootNodeModules , localNodeModules ) ;
82- copyDep ( "file-icon" , rootNodeModules , localNodeModules ) ;
83- copyDep ( "p-map" , rootNodeModules , localNodeModules ) ;
78+ for ( const dep of macOnlyNativeModules ) {
79+ copyDep ( dep , rootNodeModules , localNodeModules ) ;
80+ }
8481 } else if ( platformName === "win" ) {
8582 const watcherPkg =
8683 arch === ARCH_ARM64
@@ -100,4 +97,4 @@ module.exports = async function beforePack(context) {
10097 rmSync ( watcherBuild , { recursive : true , force : true } ) ;
10198 console . log ( "[before-pack] removed @parcel/watcher/build" ) ;
10299 }
103- } ;
100+ }
0 commit comments