33// @ts -check
44
55/*
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.
97 *
108 * This script extracts all cmi / cmj files of the rescript/lib/ocaml and all
119 * dependencies listed in the project root's rescript.json, creates cmij.js
@@ -27,6 +25,7 @@ const RESCRIPT_COMPILER_ROOT_DIR = path.join(
2725 ".." ,
2826 ".." ,
2927) ;
28+
3029const PLAYGROUND_DIR = path . join ( RESCRIPT_COMPILER_ROOT_DIR , "playground" ) ;
3130
3231// The playground-bundling root dir
@@ -36,9 +35,7 @@ const PROJECT_ROOT_DIR = path.join(import.meta.dirname, "..");
3635const PACKAGES_DIR = path . join ( PLAYGROUND_DIR , "packages" ) ;
3736
3837// 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 } ) ;
4239
4340/**
4441 * @param {string } cmd
@@ -53,32 +50,26 @@ function e(cmd) {
5350 console . log ( "<<<<<<" ) ;
5451}
5552
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" ) ;
6056
6157const packages = resConfig [ "bs-dependencies" ] ;
6258
6359// We need to build the compiler's builtin modules as a separate cmij.
6460// Otherwise we can't use them for compilation within the playground.
6561function buildCompilerCmij ( ) {
6662 const rescriptLibOcamlFolder = path . join (
67- PROJECT_ROOT_DIR ,
68- "node_modules" ,
69- "rescript" ,
63+ RESCRIPT_COMPILER_ROOT_DIR ,
7064 "lib" ,
7165 "ocaml" ,
7266 ) ;
7367
7468 const outputFolder = path . join ( PACKAGES_DIR , "compiler-builtins" ) ;
69+ fs . mkdirSync ( outputFolder , { recursive : true } ) ;
7570
7671 const cmijFile = path . join ( outputFolder , "cmij.cjs" ) ;
7772
78- if ( ! fs . existsSync ( outputFolder ) ) {
79- fs . mkdirSync ( outputFolder , { recursive : true } ) ;
80- }
81-
8273 e (
8374 `find ${ rescriptLibOcamlFolder } -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${ cmijFile } -I ${ rescriptLibOcamlFolder } ` ,
8475 ) ;
@@ -87,27 +78,24 @@ function buildCompilerCmij() {
8778function buildThirdPartyCmijs ( ) {
8879 for ( const pkg of packages ) {
8980 const libOcamlFolder = path . join (
90- PROJECT_ROOT_DIR ,
81+ RESCRIPT_COMPILER_ROOT_DIR ,
9182 "node_modules" ,
9283 pkg ,
9384 "lib" ,
9485 "ocaml" ,
9586 ) ;
9687 const libEs6Folder = path . join (
97- PROJECT_ROOT_DIR ,
88+ RESCRIPT_COMPILER_ROOT_DIR ,
9889 "node_modules" ,
9990 pkg ,
10091 "lib" ,
10192 "es6" ,
10293 ) ;
10394 const outputFolder = path . join ( PACKAGES_DIR , pkg ) ;
95+ fs . mkdirSync ( outputFolder , { recursive : true } ) ;
10496
10597 const cmijFile = path . join ( outputFolder , "cmij.cjs" ) ;
10698
107- if ( ! fs . existsSync ( outputFolder ) ) {
108- fs . mkdirSync ( outputFolder , { recursive : true } ) ;
109- }
110-
11199 e ( `find ${ libEs6Folder } -name '*.js' -exec cp {} ${ outputFolder } \\;` ) ;
112100 e (
113101 `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() {
116104}
117105
118106function bundleStdlibJs ( ) {
119- e ( "npm run bundle" ) ;
107+ e ( "yarn bundle" ) ;
120108}
121109
122110buildCompilerCmij ( ) ;
0 commit comments