6
6
*/
7
7
8
8
import * as fs from 'fs' ;
9
-
9
+ import * as fse from 'fs-extra' ;
10
10
import * as path from 'path' ;
11
11
12
- const BUILD_DIR = 'build' ;
12
+ const NPM_BUILD_DIR = 'build/npm ' ;
13
13
const ASSETS = [ 'README.md' , 'LICENSE' , 'package.json' , '.npmignore' ] ;
14
14
const ENTRY_POINTS = [ 'main' , 'module' , 'types' ] ;
15
15
16
16
// check if build dir exists
17
17
try {
18
- if ( ! fs . existsSync ( path . resolve ( BUILD_DIR ) ) ) {
19
- console . error ( `Directory ${ BUILD_DIR } DOES NOT exist` ) ;
18
+ if ( ! fs . existsSync ( path . resolve ( NPM_BUILD_DIR ) ) ) {
19
+ console . error ( `Directory ${ NPM_BUILD_DIR } DOES NOT exist` ) ;
20
20
console . error ( "This script should only be executed after you've run `yarn build`." ) ;
21
21
process . exit ( 1 ) ;
22
22
}
23
23
} catch ( error ) {
24
- console . error ( `Error while looking up directory ${ BUILD_DIR } ` ) ;
24
+ console . error ( `Error while looking up directory ${ NPM_BUILD_DIR } ` ) ;
25
25
process . exit ( 1 ) ;
26
26
}
27
27
@@ -33,24 +33,40 @@ ASSETS.forEach(asset => {
33
33
console . error ( `Asset ${ asset } does not exist.` ) ;
34
34
process . exit ( 1 ) ;
35
35
}
36
- fs . copyFileSync ( assetPath , path . resolve ( BUILD_DIR , asset ) ) ;
36
+ fs . copyFileSync ( assetPath , path . resolve ( NPM_BUILD_DIR , asset ) ) ;
37
37
} catch ( error ) {
38
- console . error ( `Error while copying ${ asset } to ${ BUILD_DIR } ` ) ;
38
+ console . error ( `Error while copying ${ asset } to ${ NPM_BUILD_DIR } ` ) ;
39
39
process . exit ( 1 ) ;
40
40
}
41
41
} ) ;
42
42
43
+ // TODO remove in v7! Until then:
44
+ // copy CDN bundles into npm dir to temporarily keep bundles in npm tarball
45
+ // inside the tarball, they are located in `build/`
46
+ const npmTmpBundlesPath = path . resolve ( NPM_BUILD_DIR , 'build' ) ;
47
+ const cdnBundlesPaht = path . resolve ( 'build' , 'bundles' ) ;
48
+ try {
49
+ if ( ! fs . existsSync ( npmTmpBundlesPath ) ) {
50
+ fs . mkdirSync ( npmTmpBundlesPath ) ;
51
+ }
52
+ fse . copy ( cdnBundlesPaht , npmTmpBundlesPath ) ;
53
+ } catch ( error ) {
54
+ console . error ( `Error while tmp copying CDN bundles to ${ NPM_BUILD_DIR } ` ) ;
55
+ }
56
+ // end remove
57
+
43
58
// package.json modifications
44
- const packageJsonPath = path . resolve ( BUILD_DIR , 'package.json' ) ;
59
+ const packageJsonPath = path . resolve ( NPM_BUILD_DIR , 'package.json' ) ;
45
60
const pkgJson : { [ key : string ] : unknown } = require ( packageJsonPath ) ;
46
61
47
62
// modify entry points to point to correct paths (i.e. strip out the build directory)
48
63
ENTRY_POINTS . filter ( entryPoint => pkgJson [ entryPoint ] ) . forEach ( entryPoint => {
49
- pkgJson [ entryPoint ] = ( pkgJson [ entryPoint ] as string ) . replace ( `${ BUILD_DIR } /` , '' ) ;
64
+ pkgJson [ entryPoint ] = ( pkgJson [ entryPoint ] as string ) . replace ( `${ NPM_BUILD_DIR } /` , '' ) ;
50
65
} ) ;
51
66
52
67
delete pkgJson . scripts ;
53
68
delete pkgJson . volta ;
69
+ delete pkgJson . jest ;
54
70
55
71
// write modified package.json to file (pretty-printed with 2 spaces)
56
72
try {
0 commit comments