@@ -11,18 +11,23 @@ import * as fse from 'fs-extra';
11
11
import * as path from 'path' ;
12
12
13
13
const NPM_BUILD_DIR = 'build/npm' ;
14
+ const BUILD_DIR = 'build' ;
15
+
14
16
const ASSETS = [ 'README.md' , 'LICENSE' , 'package.json' , '.npmignore' ] ;
15
17
const ENTRY_POINTS = [ 'main' , 'module' , 'types' ] ;
16
18
19
+ const packageWithBundles = ! process . argv . includes ( '-noBundles' ) ;
20
+ const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR ;
21
+
17
22
// check if build dir exists
18
23
try {
19
- if ( ! fs . existsSync ( path . resolve ( NPM_BUILD_DIR ) ) ) {
20
- console . error ( `Directory ${ NPM_BUILD_DIR } DOES NOT exist` ) ;
24
+ if ( ! fs . existsSync ( path . resolve ( buildDir ) ) ) {
25
+ console . error ( `Directory ${ buildDir } DOES NOT exist` ) ;
21
26
console . error ( "This script should only be executed after you've run `yarn build`." ) ;
22
27
process . exit ( 1 ) ;
23
28
}
24
29
} catch ( error ) {
25
- console . error ( `Error while looking up directory ${ NPM_BUILD_DIR } ` ) ;
30
+ console . error ( `Error while looking up directory ${ buildDir } ` ) ;
26
31
process . exit ( 1 ) ;
27
32
}
28
33
@@ -34,9 +39,9 @@ ASSETS.forEach(asset => {
34
39
console . error ( `Asset ${ asset } does not exist.` ) ;
35
40
process . exit ( 1 ) ;
36
41
}
37
- fs . copyFileSync ( assetPath , path . resolve ( NPM_BUILD_DIR , asset ) ) ;
42
+ fs . copyFileSync ( assetPath , path . resolve ( buildDir , asset ) ) ;
38
43
} catch ( error ) {
39
- console . error ( `Error while copying ${ asset } to ${ NPM_BUILD_DIR } ` ) ;
44
+ console . error ( `Error while copying ${ asset } to ${ buildDir } ` ) ;
40
45
process . exit ( 1 ) ;
41
46
}
42
47
} ) ;
@@ -45,28 +50,30 @@ ASSETS.forEach(asset => {
45
50
// copy CDN bundles into npm dir to temporarily keep bundles in npm tarball
46
51
// inside the tarball, they are located in `build/`
47
52
// for now, copy it by default, unless explicitly forbidden via an command line arg
48
- const tmpCopyBundles = ! process . argv . includes ( '-skipBundleCopy' ) ;
53
+ const tmpCopyBundles = packageWithBundles && ! process . argv . includes ( '-skipBundleCopy' ) ;
49
54
if ( tmpCopyBundles ) {
50
- const npmTmpBundlesPath = path . resolve ( NPM_BUILD_DIR , 'build' ) ;
55
+ const npmTmpBundlesPath = path . resolve ( buildDir , 'build' ) ;
51
56
const cdnBundlesPath = path . resolve ( 'build' , 'bundles' ) ;
52
57
try {
53
58
if ( ! fs . existsSync ( npmTmpBundlesPath ) ) {
54
59
fs . mkdirSync ( npmTmpBundlesPath ) ;
55
60
}
56
61
void fse . copy ( cdnBundlesPath , npmTmpBundlesPath ) ;
57
62
} catch ( error ) {
58
- console . error ( `Error while tmp copying CDN bundles to ${ NPM_BUILD_DIR } ` ) ;
63
+ console . error ( `Error while tmp copying CDN bundles to ${ buildDir } ` ) ;
59
64
process . exit ( 1 ) ;
60
65
}
61
66
}
67
+ // end remove
68
+
62
69
// package.json modifications
63
- const packageJsonPath = path . resolve ( NPM_BUILD_DIR , 'package.json' ) ;
70
+ const packageJsonPath = path . resolve ( buildDir , 'package.json' ) ;
64
71
// eslint-disable-next-line @typescript-eslint/no-var-requires
65
72
const pkgJson : { [ key : string ] : unknown } = require ( packageJsonPath ) ;
66
73
67
74
// modify entry points to point to correct paths (i.e. strip out the build directory)
68
75
ENTRY_POINTS . filter ( entryPoint => pkgJson [ entryPoint ] ) . forEach ( entryPoint => {
69
- pkgJson [ entryPoint ] = ( pkgJson [ entryPoint ] as string ) . replace ( `${ NPM_BUILD_DIR } /` , '' ) ;
76
+ pkgJson [ entryPoint ] = ( pkgJson [ entryPoint ] as string ) . replace ( `${ buildDir } /` , '' ) ;
70
77
} ) ;
71
78
72
79
delete pkgJson . scripts ;
0 commit comments