22
33import * as Fs from "fs" ;
44import * as Os from "os" ;
5- import * as Url from "url" ;
65import * as List from "rescript/lib/es6/List.js" ;
76import * as Path from "path" ;
87import * as $$Array from "rescript/lib/es6/Array.js" ;
@@ -37,76 +36,8 @@ let Node = {
3736 OS : OS
3837} ;
3938
40- let dirname = Path . dirname ( Url . fileURLToPath ( import . meta. url ) ) ;
41-
42- let compilerDir = Path . join ( dirname , ".." , ".examples-tests" ) ;
43-
44- let rescriptBin = Path . join ( compilerDir , "node_modules" , ".bin" , "rescript" ) ;
45-
4639let bscBin = Path . join ( "cli" , "bsc" ) ;
4740
48- let rescriptCoreCompiled = Path . join ( compilerDir , "node_modules" , "@rescript" , "core" , "lib" , "ocaml" ) ;
49-
50- function makePackageJson ( coreVersion ) {
51- return "{\n \"name\": \"test-compiler-examples\",\n \"version\": \"1.0.0\",\n \"dependencies\": {\n \"@rescript/core\": \"file:rescript-core-" + coreVersion + ".tgz\",\n \"rescript\": \"11.1.4\"\n }\n}\n" ;
52- }
53-
54- let rescriptJson = "{\n \"name\": \"dummy\",\n \"sources\": {\n \"dir\": \"dummy\",\n \"subdirs\": true\n },\n \"bs-dependencies\": [\n \"@rescript/core\"\n ],\n \"bsc-flags\": [\n \"-open RescriptCore\"\n ]\n}" ;
55-
56- function prepareCompiler ( ) {
57- let corePath = Path . join ( compilerDir , ".." ) ;
58- if ( ! Fs . existsSync ( compilerDir ) ) {
59- Fs . mkdirSync ( compilerDir ) ;
60- }
61- Child_process . execFileSync ( "npm" , [
62- "pack" ,
63- corePath
64- ] , {
65- stdio : "ignore" ,
66- cwd : compilerDir
67- } ) ;
68- let dict = JSON . parse ( Fs . readFileSync ( Path . join ( corePath , "package.json" ) ) ) ;
69- let currentCoreVersion ;
70- if ( typeof dict === "object" && ! Array . isArray ( dict ) ) {
71- let s = dict [ "version" ] ;
72- if ( typeof s === "string" ) {
73- currentCoreVersion = s ;
74- } else {
75- throw {
76- RE_EXN_ID : "Assert_failure" ,
77- _1 : [
78- "DocTest.res" ,
79- 127 ,
80- 11
81- ] ,
82- Error : new Error ( )
83- } ;
84- }
85- } else {
86- throw {
87- RE_EXN_ID : "Assert_failure" ,
88- _1 : [
89- "DocTest.res" ,
90- 129 ,
91- 9
92- ] ,
93- Error : new Error ( )
94- } ;
95- }
96- Fs . writeFileSync ( Path . join ( compilerDir , "package.json" ) , makePackageJson ( currentCoreVersion ) ) ;
97- Fs . writeFileSync ( Path . join ( compilerDir , "rescript.json" ) , rescriptJson ) ;
98- let dummyFolder = Path . join ( compilerDir , "dummy" ) ;
99- if ( ! Fs . existsSync ( dummyFolder ) ) {
100- Fs . mkdirSync ( dummyFolder ) ;
101- }
102- Child_process . execFileSync ( "npm" , [ "install" ] , {
103- cwd : compilerDir
104- } ) ;
105- Child_process . execFileSync ( rescriptBin , [ "build" ] , {
106- cwd : compilerDir
107- } ) ;
108- }
109-
11041function createFileInTempDir ( id ) {
11142 return Path . join ( Os . tmpdir ( ) , id ) ;
11243}
@@ -117,8 +48,6 @@ async function testCode(id, code) {
11748 await Promises . writeFile ( tempFileName + ".res" , code ) ;
11849 let args = [
11950 tempFileName + ".res" ,
120- "-I" ,
121- rescriptCoreCompiled ,
12251 "-w" ,
12352 "-3-109"
12453 ] ;
@@ -342,14 +271,7 @@ let Docgen;
342271export {
343272 Node ,
344273 Docgen ,
345- dirname ,
346- compilerDir ,
347- rescriptBin ,
348274 bscBin ,
349- rescriptCoreCompiled ,
350- makePackageJson ,
351- rescriptJson ,
352- prepareCompiler ,
353275 createFileInTempDir ,
354276 testCode ,
355277 extractDocFromFile ,
@@ -358,4 +280,4 @@ export {
358280 main ,
359281 exitCode ,
360282}
361- /* dirname Not a pure module */
283+ /* bscBin Not a pure module */
0 commit comments