Skip to content

Commit c032728

Browse files
committed
Switch to ES modules
1 parent 7da028e commit c032728

10 files changed

+204
-123
lines changed

.npmignore

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
src/*
2-
dist/test/*
3-
build.sh
4-
.jshintrc
5-
.gitignore
6-
static/bundle.js
7-
static/bundle.js.map
1+
dist/test/*

build.sh

-3
This file was deleted.

package-lock.json

+64-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
{
22
"name": "basho-eval",
3-
"version": "5.0.1",
3+
"version": "6.0.0",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "src/index.ts",
47
"author": "Jeswin Kumar<[email protected]>",
58
"repository": {
69
"type": "git",
710
"url": "https://github.com/bashojs/basho-eval"
811
},
912
"scripts": {
10-
"transpile": "./build.sh",
11-
"test": "./build.sh && mocha dist/test/test.js"
13+
"clean": "rimraf ./dist",
14+
"build": "npm run clean && mkdir -p dist && npx tsc && cp src/test/square.js dist/test/",
15+
"test": "node --experimental-specifier-resolution=node node_modules/mocha/lib/cli/cli.js dist/test/test.js"
1216
},
13-
"main": "dist/index.js",
14-
"types": "dist/index.d.ts",
1517
"dependencies": {
16-
"@types/node": "^16.4.10",
17-
"lazily-async": "^1.0.3"
18+
"@types/node": "^16.6.2",
19+
"lazily-async": "^2.0.1"
1820
},
1921
"devDependencies": {
2022
"@types/mocha": "^9.0.0",
2123
"@types/should": "^13.0.0",
2224
"left-pad": "^1.3.0",
2325
"mocha": "^9.0.3",
24-
"should": "^13.2.3"
26+
"rimraf": "^3.0.2",
27+
"should": "^13.2.3",
28+
"typescript": "^4.3.5"
2529
},
2630
"license": "MIT"
2731
}

src/index.ts

+31-28
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
BashoLogFn,
66
ExpressionStackEntry,
77
BashoEvaluationResult,
8-
EvaluationEnv
8+
EvaluationEnv,
99
} from "./types";
1010
import { PipelineValue, PipelineItem } from "./pipeline";
1111
import jsExpression from "./operators/jsExpression";
@@ -17,7 +17,7 @@ import execShellCommand from "./operators/execShellCommand";
1717
import onError from "./operators/onError";
1818
import filter from "./operators/filter";
1919
import recurse from "./operators/recurse";
20-
import doImport from "./operators/doImport";
20+
import { defaultImport, namedImport } from "./operators/doImport";
2121
import log from "./operators/log";
2222
import flatMap from "./operators/flatMap";
2323
import namedExpression from "./operators/namedExpression";
@@ -67,7 +67,7 @@ function createProxy(): EvaluationStack {
6767
const outer = evalScope.slice(-1)[0];
6868
outer[prop] = value;
6969
return true;
70-
}
70+
},
7171
};
7272

7373
const proxy = new Proxy(evalScope, handler);
@@ -76,7 +76,7 @@ function createProxy(): EvaluationStack {
7676
create: () => evalScope.push({}),
7777
unwind: () => evalScope.pop(),
7878
value: evalScope,
79-
proxy
79+
proxy,
8080
};
8181
}
8282

@@ -108,7 +108,7 @@ export async function createStackAndEvaluate(
108108
args,
109109
[],
110110
evalScope,
111-
Seq.of(pipedValues.map(x => new PipelineValue(x))),
111+
Seq.of(pipedValues.map((x) => new PipelineValue(x))),
112112
mustPrint,
113113
onLog,
114114
onWrite,
@@ -145,70 +145,73 @@ export async function evaluateInternal(
145145
): Promise<BashoEvaluationResult> {
146146
const cases: Array<[(arg: string) => boolean, OperatorFn]> = [
147147
/* Enumerate sequence into an array */
148-
[x => x === "-a", toArray],
148+
[(x) => x === "-a", toArray],
149149

150150
/* Combine multiple named streams */
151-
[x => x === "-c", combineStreams],
151+
[(x) => x === "-c", combineStreams],
152152

153153
/* Define an expression */
154-
[x => x === "-d", defineExpression],
154+
[(x) => x === "-d", defineExpression],
155155

156156
/* Execute shell command */
157-
[x => x === "-e", execShellCommand],
157+
[(x) => x === "-e", execShellCommand],
158158

159159
/* Error handling */
160-
[x => x === "--error", onError],
160+
[(x) => x === "--error", onError],
161161

162162
/* Filter */
163-
[x => x === "-f", filter],
163+
[(x) => x === "-f", filter],
164164

165165
/* Recurse/Goto */
166-
[x => x === "-g", recurse],
166+
[(x) => x === "-g", recurse],
167+
168+
/* Import default export from a module */
169+
[(x) => x === "--import" || x === "-i", defaultImport()],
167170

168-
/* Named Export */
169-
[x => x === "--import" || x === "-i", doImport],
171+
/* Import named export from a module */
172+
[(x) => x === "--named-import", namedImport()],
170173

171174
/* JS expressions */
172-
[x => x === "-j", jsExpression(1)],
175+
[(x) => x === "-j", jsExpression(1)],
173176

174177
/* Treats input as JSON */
175-
[x => x === "--json", asJson],
178+
[(x) => x === "--json", asJson],
176179

177180
/* Logging */
178-
[x => x === "-l", log],
181+
[(x) => x === "-l", log],
179182

180183
/* Flatmap */
181-
[x => x === "-m", flatMap],
184+
[(x) => x === "-m", flatMap],
182185

183186
/* Named Expressions */
184-
[x => x === "-n", namedExpression],
187+
[(x) => x === "-n", namedExpression],
185188

186189
/* Error handling. Handled by shell, ignore */
187-
[x => x === "--ignoreerror" || x === "--printerror", errorHandler],
190+
[(x) => x === "--ignoreerror" || x === "--printerror", errorHandler],
188191

189192
/* Print */
190-
[x => x === "-p", print],
193+
[(x) => x === "-p", print],
191194

192195
/* Reduce */
193-
[x => x === "-r", reduce],
196+
[(x) => x === "-r", reduce],
194197

195198
/* Seek a named result */
196-
[x => x === "-s", seek],
199+
[(x) => x === "-s", seek],
197200

198201
/* Convert input to a single string */
199-
[x => x === "--str", asString],
202+
[(x) => x === "--str", asString],
200203

201204
/* Define a subroutine */
202-
[x => x === "--sub", subroutine],
205+
[(x) => x === "--sub", subroutine],
203206

204207
/* Terminate the pipeline */
205-
[x => x === "-t", terminate],
208+
[(x) => x === "-t", terminate],
206209

207210
/* Writing */
208-
[x => x === "-w", write],
211+
[(x) => x === "-w", write],
209212

210213
/* Everything else as a JS expression */
211-
[x => isFirstParam, jsExpression(0)]
214+
[(x) => isFirstParam, jsExpression(0)],
212215
];
213216

214217
return args.length

0 commit comments

Comments
 (0)