File tree 3 files changed +25
-21
lines changed
3 files changed +25
-21
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ module.exports = {
6
6
parserOptions : {
7
7
jsx : true ,
8
8
} ,
9
+ // ignoring the package-specific prepack script here b/c it is not
10
+ // covered by a `tsconfig` which makes eslint throw an error
9
11
ignorePatterns : [ 'scripts/prepack.ts' ] ,
10
12
extends : [ '../../.eslintrc.js' ] ,
11
13
} ;
Original file line number Diff line number Diff line change 1
1
/* eslint-disable no-console */
2
+
2
3
// DO NOT RUN this script yourself!
3
4
// This is invoked from the main `prepack.ts` script in `sentry-javascript/scripts/prepack.ts`.
5
+
4
6
import * as fs from 'fs' ;
5
7
import * as path from 'path' ;
6
8
7
- const BUILD_DIR = 'build' ;
8
9
const PACKAGE_ASSETS = [ 'gatsby-browser.js' , 'gatsby-node.js' ] ;
9
10
10
- // copy package-specific assets to build dir
11
- PACKAGE_ASSETS . forEach ( asset => {
12
- const assetPath = path . resolve ( asset ) ;
13
- try {
14
- if ( ! fs . existsSync ( assetPath ) ) {
15
- console . error ( `Asset ${ asset } does not exist.` ) ;
16
- process . exit ( 1 ) ;
11
+ export function prepack ( buildDir : string ) : void {
12
+ // copy package-specific assets to build dir
13
+ PACKAGE_ASSETS . forEach ( asset => {
14
+ const assetPath = path . resolve ( asset ) ;
15
+ try {
16
+ if ( ! fs . existsSync ( assetPath ) ) {
17
+ console . error ( `Asset ${ asset } does not exist.` ) ;
18
+ }
19
+ fs . copyFileSync ( assetPath , path . resolve ( buildDir , asset ) ) ;
20
+ } catch ( error ) {
21
+ console . error ( `Error while copying ${ asset } to ${ buildDir } ` ) ;
17
22
}
18
- fs . copyFileSync ( assetPath , path . resolve ( BUILD_DIR , asset ) ) ;
19
- } catch ( error ) {
20
- console . error ( `Error while copying ${ asset } to ${ BUILD_DIR } ` ) ;
21
- }
22
- } ) ;
23
+ } ) ;
24
+ }
Original file line number Diff line number Diff line change 6
6
the directory structure inside `build`.
7
7
*/
8
8
9
- import * as childProcess from 'child_process' ;
10
9
import * as fs from 'fs' ;
11
10
import * as fse from 'fs-extra' ;
12
11
import * as path from 'path' ;
@@ -89,19 +88,20 @@ try {
89
88
process . exit ( 1 ) ;
90
89
}
91
90
91
+ async function runPackagePrepack ( packagePrepackPath : string ) : Promise < void > {
92
+ const { prepack } = await import ( packagePrepackPath ) ;
93
+ if ( prepack && typeof prepack === 'function' ) {
94
+ prepack ( buildDir ) ;
95
+ }
96
+ }
97
+
92
98
// execute package specific settings
93
99
// 1. check if a package called `<package-root>/scripts/prepack.ts` exitsts
94
100
// if yes, 2.) execute that script for things that are package-specific
95
101
const packagePrepackPath = path . resolve ( 'scripts' , 'prepack.ts' ) ;
96
102
try {
97
103
if ( fs . existsSync ( packagePrepackPath ) ) {
98
- const proc = childProcess . fork ( packagePrepackPath ) ;
99
- proc . on ( 'exit' , code => {
100
- if ( code !== 0 ) {
101
- console . error ( `Error while executing ${ packagePrepackPath . toString ( ) } ` ) ;
102
- process . exit ( 1 ) ;
103
- }
104
- } ) ;
104
+ void runPackagePrepack ( packagePrepackPath ) ;
105
105
}
106
106
} catch ( error ) {
107
107
console . error ( `Error while trying to access ${ packagePrepackPath . toString ( ) } ` ) ;
You can’t perform that action at this time.
0 commit comments