3
3
// @ts -check
4
4
5
5
/*
6
- * Requires the version matching `rescript` binary to be `npm link`ed in this
7
- * project. Or in other words: You need to build cmij files with the same
8
- * rescript version as the compiler bundle.
6
+ * You need to build cmij files with the same rescript version as the compiler bundle.
9
7
*
10
8
* This script extracts all cmi / cmj files of the rescript/lib/ocaml and all
11
9
* dependencies listed in the project root's rescript.json, creates cmij.js
@@ -27,6 +25,7 @@ const RESCRIPT_COMPILER_ROOT_DIR = path.join(
27
25
".." ,
28
26
".." ,
29
27
) ;
28
+
30
29
const PLAYGROUND_DIR = path . join ( RESCRIPT_COMPILER_ROOT_DIR , "playground" ) ;
31
30
32
31
// The playground-bundling root dir
@@ -36,9 +35,7 @@ const PROJECT_ROOT_DIR = path.join(import.meta.dirname, "..");
36
35
const PACKAGES_DIR = path . join ( PLAYGROUND_DIR , "packages" ) ;
37
36
38
37
// Making sure this directory exists, since it's not checked in to git
39
- if ( ! fs . existsSync ( PACKAGES_DIR ) ) {
40
- fs . mkdirSync ( PACKAGES_DIR , { recursive : true } ) ;
41
- }
38
+ fs . mkdirSync ( PACKAGES_DIR , { recursive : true } ) ;
42
39
43
40
/**
44
41
* @param {string } cmd
@@ -53,32 +50,26 @@ function e(cmd) {
53
50
console . log ( "<<<<<<" ) ;
54
51
}
55
52
56
- e ( "npm install" ) ;
57
- e ( `npm link ${ RESCRIPT_COMPILER_ROOT_DIR } ` ) ;
58
- e ( "npx rescript clean" ) ;
59
- e ( "npx rescript" ) ;
53
+ e ( "yarn install" ) ;
54
+ e ( "yarn rescript clean" ) ;
55
+ e ( "yarn rescript" ) ;
60
56
61
57
const packages = resConfig [ "bs-dependencies" ] ;
62
58
63
59
// We need to build the compiler's builtin modules as a separate cmij.
64
60
// Otherwise we can't use them for compilation within the playground.
65
61
function buildCompilerCmij ( ) {
66
62
const rescriptLibOcamlFolder = path . join (
67
- PROJECT_ROOT_DIR ,
68
- "node_modules" ,
69
- "rescript" ,
63
+ RESCRIPT_COMPILER_ROOT_DIR ,
70
64
"lib" ,
71
65
"ocaml" ,
72
66
) ;
73
67
74
68
const outputFolder = path . join ( PACKAGES_DIR , "compiler-builtins" ) ;
69
+ fs . mkdirSync ( outputFolder , { recursive : true } ) ;
75
70
76
71
const cmijFile = path . join ( outputFolder , "cmij.cjs" ) ;
77
72
78
- if ( ! fs . existsSync ( outputFolder ) ) {
79
- fs . mkdirSync ( outputFolder , { recursive : true } ) ;
80
- }
81
-
82
73
e (
83
74
`find ${ rescriptLibOcamlFolder } -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${ cmijFile } -I ${ rescriptLibOcamlFolder } ` ,
84
75
) ;
@@ -87,27 +78,24 @@ function buildCompilerCmij() {
87
78
function buildThirdPartyCmijs ( ) {
88
79
for ( const pkg of packages ) {
89
80
const libOcamlFolder = path . join (
90
- PROJECT_ROOT_DIR ,
81
+ RESCRIPT_COMPILER_ROOT_DIR ,
91
82
"node_modules" ,
92
83
pkg ,
93
84
"lib" ,
94
85
"ocaml" ,
95
86
) ;
96
87
const libEs6Folder = path . join (
97
- PROJECT_ROOT_DIR ,
88
+ RESCRIPT_COMPILER_ROOT_DIR ,
98
89
"node_modules" ,
99
90
pkg ,
100
91
"lib" ,
101
92
"es6" ,
102
93
) ;
103
94
const outputFolder = path . join ( PACKAGES_DIR , pkg ) ;
95
+ fs . mkdirSync ( outputFolder , { recursive : true } ) ;
104
96
105
97
const cmijFile = path . join ( outputFolder , "cmij.cjs" ) ;
106
98
107
- if ( ! fs . existsSync ( outputFolder ) ) {
108
- fs . mkdirSync ( outputFolder , { recursive : true } ) ;
109
- }
110
-
111
99
e ( `find ${ libEs6Folder } -name '*.js' -exec cp {} ${ outputFolder } \\;` ) ;
112
100
e (
113
101
`find ${ libOcamlFolder } -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${ cmijFile } -I ${ libOcamlFolder } ` ,
@@ -116,7 +104,7 @@ function buildThirdPartyCmijs() {
116
104
}
117
105
118
106
function bundleStdlibJs ( ) {
119
- e ( "npm run bundle" ) ;
107
+ e ( "yarn bundle" ) ;
120
108
}
121
109
122
110
buildCompilerCmij ( ) ;
0 commit comments