This repository was archived by the owner on Nov 20, 2023. It is now read-only.
File tree 4 files changed +82
-40
lines changed
4 files changed +82
-40
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { execSync } from "child_process" ;
2
+ import esbuild from "esbuild" ;
3
+ import path from "path" ;
4
+ import { fileURLToPath } from "url" ;
5
+ import fs from "fs/promises" ;
6
+
7
+ const dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
8
+
9
+ const options = {
10
+ bundle : true ,
11
+ entryPoints : [ path . join ( dirname , "src/index.ts" ) ] ,
12
+ minify : false ,
13
+ outdir : path . join ( dirname , "dist" ) ,
14
+ platform : "node" ,
15
+ plugins : [ {
16
+ name : "wasm" ,
17
+ setup ( build ) {
18
+ build . onLoad ( { filter : / \. w a s m $ / } , async ( args ) => ( {
19
+ contents : await fs . readFile ( args . path ) ,
20
+ loader : "binary"
21
+ } ) ) ;
22
+ }
23
+ } ] ,
24
+ sourcemap : false ,
25
+ target : "es6"
26
+ } ;
27
+
28
+ Promise . all ( [
29
+ esbuild . build ( {
30
+ ...options ,
31
+ format : "esm" ,
32
+ outExtension : { ".js" : ".mjs" } ,
33
+ banner : {
34
+ js : `import { createRequire } from "module"; const require = createRequire(import.meta.url);` ,
35
+ }
36
+ } ) ,
37
+ esbuild . build ( {
38
+ ...options ,
39
+ format : "cjs" ,
40
+ outExtension : { ".js" : ".cjs" }
41
+ } )
42
+ ] ) . then ( ( [ esm , cjs ] ) => {
43
+ // When we're done building the output, we'll want to additionally build the
44
+ // typescript declarations file.
45
+ if ( esm . errors . length + cjs . errors . length === 0 ) {
46
+ execSync ( "./node_modules/.bin/tsc" ) ;
47
+ }
48
+ } ) ;
Original file line number Diff line number Diff line change 2
2
"name" : " node-syntax-tree" ,
3
3
"version" : " 0.1.0" ,
4
4
"description" : " A node package for accessing Syntax Tree through WASM" ,
5
- "main" : " dist/index.js" ,
6
- "scripts" : {},
5
+ "main" : " dist/index.cjs" ,
6
+ "module" : " dist/index.mjs" ,
7
+ "typings" : " dist/index.d.ts" ,
8
+ "scripts" : {
9
+ "test" : " node test.mjs"
10
+ },
7
11
"repository" : {
8
12
"type" : " git" ,
9
13
"url" : " git+https://github.com/ruby-syntax-tree/node-syntax-tree.git"
Original file line number Diff line number Diff line change
1
+ import assert from "node:assert" ;
2
+ import test from "node:test" ;
3
+
4
+ import createSyntaxTree from "./dist/index.mjs" ;
5
+
6
+ const syntaxTree = await createSyntaxTree ( ) ;
7
+
8
+ test ( "handlers.haml.format" , ( ) => {
9
+ assert . equal ( syntaxTree . handlers . haml . format ( "= foo" ) , "= foo\n" ) ;
10
+ } ) ;
11
+
12
+ test ( "handlers.haml.parse" , ( ) => {
13
+ assert . equal (
14
+ syntaxTree . handlers . haml . parse ( "= foo" ) ,
15
+ `(root children=[(script text=" foo")])\n`
16
+ ) ;
17
+ } ) ;
18
+
19
+ test ( "handlers.ruby.format" , ( ) => {
20
+ assert . equal ( syntaxTree . handlers . ruby . format ( "1+1" ) , "1 + 1\n" ) ;
21
+ } ) ;
22
+
23
+ test ( "handlers.ruby.parse" , ( ) => {
24
+ assert . equal (
25
+ syntaxTree . handlers . ruby . parse ( "foo" ) ,
26
+ `(program (statements ((vcall (ident "foo")))))\n`
27
+ ) ;
28
+ } ) ;
You can’t perform that action at this time.
0 commit comments