jam 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -250
- package/bin/jam.js +31 -0
- package/lib/platform.js +72 -0
- package/lib/resolve-binary.js +30 -0
- package/lib/resolve-optional-package.js +43 -0
- package/package.json +28 -28
- package/.npmignore +0 -6
- package/.travis.yml +0 -3
- package/LICENSE +0 -21
- package/Makefile +0 -67
- package/example/file1.txt +0 -1
- package/example/file2.txt +0 -1
- package/example/file3.txt +0 -1
- package/example/map.js +0 -29
- package/example/promise.js +0 -21
- package/index.js +0 -6
- package/lib/jam.js +0 -333
- package/test/helpers.js +0 -347
- package/test/jam.js +0 -121
package/README.md
CHANGED
|
@@ -1,276 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
# jam
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Jam is an application server for isolated JavaScript. It runs JavaScript (and TypeScript) per request with isolated execution contexts, inspired by the PHP-FPM model.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
$ npm install jam --save
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
JAM is another kind of async framework that tries to have as minimum boilerplate code as
|
|
10
|
-
possible with sensible defaults. (Or as sensible as I can make it; PR and ideas welcome.)
|
|
11
|
-
|
|
12
|
-
JAM wants you to get right in to building your `async` chain as soon as possible.
|
|
13
|
-
|
|
14
|
-
JAM also aims to bundle with itself some "combinators" (or just "helpers") which helps you
|
|
15
|
-
manipulate arguments and functions that are being passed around in the chain with ease.
|
|
16
|
-
There is only a handful of them right now, but I will add more whenever I see a good use
|
|
17
|
-
for one.
|
|
18
|
-
|
|
19
|
-
# HOW TO
|
|
20
|
-
|
|
21
|
-
JAM functions must accept a `next` argument first thing which you should call as soon as
|
|
22
|
-
your asynchronous processing is done:
|
|
23
|
-
|
|
24
|
-
Let's start with the simplest possible invocation of jam:
|
|
25
|
-
|
|
26
|
-
```js
|
|
27
|
-
var chain = jam( function(next) { next(); } );
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**JAM will starts executing your chain as soon as `nextTick`.** So, in the event loop time
|
|
31
|
-
you have been allocated, you can add as many methods as you like and the chain will start
|
|
32
|
-
executing as soon your loop finishes. No more steps necessary!
|
|
33
|
-
|
|
34
|
-
You may think that this poses a problem but I find that most (if not all) of the cases
|
|
35
|
-
where you want to do multiple asynchronous calls, you will build all your calls in a
|
|
36
|
-
single run loop. So this is a non-issue.
|
|
37
|
-
|
|
38
|
-
To add a method to the chain, simply invoke the result from the last JAM invocation as a
|
|
39
|
-
function like this:
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
chain = chain( function secondStep(next) { next(); } );
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
JAM expects most asynchronous method calls to be executed serially so that is what the
|
|
46
|
-
chain does by default when you start adding methods to the chain.
|
|
47
|
-
|
|
48
|
-
Since JAM return values are just functions, you don't even need to hold it in a variable
|
|
49
|
-
if you like extra brevity of code:
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
jam( function firstStep(next) { next(); } )
|
|
53
|
-
( function secondStep(next) { next(); } )
|
|
54
|
-
( function lastStep() { } );
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
JAM also handles `Error`s for you. Note:
|
|
58
|
-
|
|
59
|
-
* The convention here is that the last function in the chain is often the one that will
|
|
60
|
-
handle all errors in the chain.
|
|
61
|
-
* The last function does not need any more `next()` since it's the last one.
|
|
62
|
-
|
|
63
|
-
JAM convention utilizes the two facts above to pass any `Error` that happens in the chain
|
|
64
|
-
to the last function as first argument.
|
|
65
|
-
|
|
66
|
-
So if you need error handling, write the last function as a standard node.js callback:
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
jam(function erroneous(next) {
|
|
70
|
-
next(new Error('naw!');
|
|
71
|
-
})
|
|
72
|
-
(function handler(err) {
|
|
73
|
-
if (err) { console.log(err.stack); }
|
|
74
|
-
});
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Additionally, JAM also passes anything else given to the `next()` function to the next one
|
|
78
|
-
as arguments as well so you can do this:
|
|
79
|
-
|
|
80
|
-
```js
|
|
81
|
-
jam(function(next) { fs.readFile('filename.txt', next); })
|
|
82
|
-
(function(next, data) {
|
|
83
|
-
console.log("FILE DATA:\r\n" + data);
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
This is much better than if JAM put `next()` as the last argument since some functions
|
|
88
|
-
calls your `callback` with more arguments than you need (or aware of) thus making your
|
|
89
|
-
code dependent on the number of arguments given.
|
|
90
|
-
|
|
91
|
-
Passing `next` as first argument eliminates the dependency since you can bind as many
|
|
92
|
-
arguments as you want and the `next()` is still passed as first argument always.
|
|
93
|
-
|
|
94
|
-
Since this pattern allows you to pass functions verbatim, JAM also helps you binds the
|
|
95
|
-
funciton context as well if you supply the context object as the second argument:
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
var myObj =
|
|
99
|
-
{ text: 'HELLO'
|
|
100
|
-
, echo: function() { console.log(this.text); }
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
jam(myObj.echo, myObj); // executes myObj.echo with this === myObj
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Additionally, there are helpers available that lets you build JAM chains more easily.
|
|
107
|
-
|
|
108
|
-
# HELPERS
|
|
5
|
+
## Install
|
|
109
6
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Or feel free to ping me [@chakrit](http://twitter.com/chakrit) on Twitter or open a GH
|
|
114
|
-
issue for questions.
|
|
115
|
-
|
|
116
|
-
#### identity( )
|
|
117
|
-
|
|
118
|
-
```js
|
|
119
|
-
jam(function first(next) { next('one'); })
|
|
120
|
-
(jam.identity)
|
|
121
|
-
(function second(err, arg) {
|
|
122
|
-
assert(arg === 'one'); // passese
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Passes arguments it receives to the next function in the chain without any modification.
|
|
127
|
-
Also useful as a starting point when building a complex jam chain (i.e. in a for loops
|
|
128
|
-
that re-uses the jam return values.)
|
|
129
|
-
|
|
130
|
-
See `nextTick()` below.
|
|
131
|
-
|
|
132
|
-
#### nextTick( )
|
|
133
|
-
|
|
134
|
-
```js
|
|
135
|
-
jam( function firstStep(next) { next(); } )
|
|
136
|
-
( jam.nextTick )
|
|
137
|
-
( function badSecondStep(next) { next(); } );
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g jam
|
|
9
|
+
jam --help
|
|
138
10
|
```
|
|
139
11
|
|
|
140
|
-
|
|
141
|
-
as soon as you call `next()`. This may pose a problem for some code that does not expect
|
|
142
|
-
asynchronous functions to execute immeditaely.
|
|
12
|
+
## Usage
|
|
143
13
|
|
|
144
|
-
|
|
145
|
-
sure it executes on `process.nextTick`.
|
|
14
|
+
Create a `scripts/app.ts` file:
|
|
146
15
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
function handleFileContent(e, file) {
|
|
16
|
+
```ts
|
|
17
|
+
export default {
|
|
18
|
+
fetch(request: Request): Response {
|
|
19
|
+
return new Response("Hello from Jam");
|
|
20
|
+
}
|
|
153
21
|
};
|
|
154
|
-
|
|
155
|
-
// parallel handleFileContent jam
|
|
156
|
-
['file1.txt', 'file2.txt', 'file3.txt'].forEach(function(file) {
|
|
157
|
-
jam(jam.return(file))
|
|
158
|
-
(jam.call(fs.readFile)) // no function() needed!
|
|
159
|
-
(handleFileContent);
|
|
160
|
-
});
|
|
161
22
|
```
|
|
162
23
|
|
|
163
|
-
|
|
164
|
-
it) without modifying or wrapping code for the rest of the chains.
|
|
165
|
-
|
|
166
|
-
#### call( func, [args...] )
|
|
167
|
-
|
|
168
|
-
```js
|
|
169
|
-
jam(jam.call(findTheRightFile))
|
|
170
|
-
(jam.call(fs.readFile))
|
|
171
|
-
(function(e, fileContent) {
|
|
172
|
-
// fileContent is the content of the right file
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
This helper lets you call standard node.js functions that expect callbacks at the end.
|
|
177
|
-
Additionally, any arguments that would normally be given to the chain function would be
|
|
178
|
-
used to call the function instead (`next()` is then added at the end of the arguments
|
|
179
|
-
list).
|
|
180
|
-
|
|
181
|
-
#### each and map( array, iterator( next, element, index ) )
|
|
182
|
-
|
|
183
|
-
```js
|
|
184
|
-
var FILES = 'file1.txt,file2.txt,file3.txt'.split(',');
|
|
24
|
+
Start Jam, pointing it at the scripts folder:
|
|
185
25
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
})(function(e, result) {
|
|
190
|
-
var cat = result.join('');
|
|
191
|
-
console.log(cat);
|
|
192
|
-
|
|
193
|
-
});
|
|
26
|
+
```sh
|
|
27
|
+
jam ./scripts
|
|
194
28
|
```
|
|
195
29
|
|
|
196
|
-
|
|
197
|
-
of `next()` and the element to process. If no array is given, the method assumes that the
|
|
198
|
-
previous step in the chain produce something that looks like an array.
|
|
199
|
-
|
|
200
|
-
Internally a new JAM chain is built and a chain step is added for each element.
|
|
201
|
-
|
|
202
|
-
The next step in the JAM chain will receive the original array verbatim, or the
|
|
203
|
-
transformed result in case of `map`.
|
|
30
|
+
Now make a request. Jam maps `/app` to `app.ts`.
|
|
204
31
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
### promise( chain )
|
|
208
|
-
|
|
209
|
-
```js
|
|
210
|
-
var chain = jam(jam.identity); // or any existing chain
|
|
211
|
-
fs.readFile('file1.txt', chain.promise()); // adds a step to "wait" for fs.readFile result
|
|
212
|
-
|
|
213
|
-
chain(function(e, content) {
|
|
214
|
-
console.log("Content of file1 is:");
|
|
215
|
-
console.log(content);
|
|
216
|
-
});
|
|
32
|
+
```sh
|
|
33
|
+
curl http://localhost:3000/app
|
|
217
34
|
```
|
|
218
35
|
|
|
219
|
-
|
|
220
|
-
the JAM chain. This callback accepts the standard node.js callback signature of
|
|
221
|
-
`function(e, args)` and upon calling, will pass any given arguments properly into the
|
|
222
|
-
`next` function in the JAM chain.
|
|
223
|
-
|
|
224
|
-
This function is useful when you have already started a JAM chain and want to include an
|
|
225
|
-
asynchronous function into the chain but do not want to wrap the initial call into the
|
|
226
|
-
chain as well (so you can create a `.promise()` callback from the chain and pass that
|
|
227
|
-
instead effectively making the chain wait for the callback.)
|
|
228
|
-
|
|
229
|
-
This function works regardless of wether the callback or the JAM chain is called first and
|
|
230
|
-
will pass arguments and handle errors properly in both cases.
|
|
231
|
-
|
|
232
|
-
See the `example/promise.js` file for more information.
|
|
233
|
-
|
|
234
|
-
# LICENSE
|
|
235
|
-
|
|
236
|
-
MIT (see LICENSE file for the full text.)
|
|
237
|
-
|
|
238
|
-
# SUPPORT / CONTRIBUTE
|
|
239
|
-
|
|
240
|
-
Pull requests and/or ideas welcome.
|
|
241
|
-
|
|
242
|
-
Please open a [new GitHub Issue](https://github.com/chakrit/jam/issues/new) for any bugs
|
|
243
|
-
you find or if you just had a question.
|
|
36
|
+
Edit the file and make the same request again. The next request runs the updated script immediately, with no rebuilds or restarts.
|
|
244
37
|
|
|
245
|
-
|
|
38
|
+
## Documentation
|
|
246
39
|
|
|
247
|
-
|
|
248
|
-
* Nullify calls, in case you don't want any arguments passed.
|
|
249
|
-
* Parellel map() ?
|
|
40
|
+
To learn more, see [the documentation](https://github.com/mjackson/jam/tree/main/docs).
|
|
250
41
|
|
|
251
|
-
|
|
42
|
+
## How platform binaries are downloaded
|
|
252
43
|
|
|
253
|
-
|
|
254
|
-
with it.
|
|
44
|
+
The `jam` package uses platform-specific optional dependencies. During install, npm picks the matching package for your OS/CPU target:
|
|
255
45
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
`(function() { })` block at the end because that's what you're usually doing all the time
|
|
261
|
-
anyway taking care of all those JS variable scopes. Plus it is easier to
|
|
262
|
-
copy/paste/reorder the steps as well.
|
|
46
|
+
- [`jam-darwin-arm64`](https://www.npmjs.com/package/jam-darwin-arm64)
|
|
47
|
+
- [`jam-darwin-x64`](https://www.npmjs.com/package/jam-darwin-x64)
|
|
48
|
+
- [`jam-linux-x64`](https://www.npmjs.com/package/jam-linux-x64)
|
|
49
|
+
- [`jam-linux-arm64`](https://www.npmjs.com/package/jam-linux-arm64)
|
|
263
50
|
|
|
264
|
-
|
|
265
|
-
to run asynchronous functions where most of the time you just want to reduce the amount of
|
|
266
|
-
nesting in your code.
|
|
51
|
+
Current support is macOS (`darwin`) and Linux glibc builds. Linux musl and Windows targets are not published yet.
|
|
267
52
|
|
|
268
|
-
|
|
269
|
-
sane defaults and then provide helpers for bringing edge cases into this minimal interface
|
|
270
|
-
neatly so you can just get your stuff done without worrying about wether you are using the
|
|
271
|
-
right async call or if you have the right number of arguments.
|
|
53
|
+
## Environment overrides
|
|
272
54
|
|
|
273
|
-
|
|
55
|
+
- `JAM_LIBC=glibc|musl`: override Linux libc detection.
|
|
56
|
+
- `JAM_BINARY_PATH=<path>`: run a specific local binary instead of the optional dependency binary.
|
|
274
57
|
|
|
275
|
-
|
|
58
|
+
## Local development
|
|
276
59
|
|
|
60
|
+
Install dependencies with optional dependencies enabled so the matching platform package is available.
|
package/bin/jam.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
let { spawnSync } = require("node:child_process");
|
|
5
|
+
|
|
6
|
+
let { resolveBinaryPath } = require("../lib/resolve-binary");
|
|
7
|
+
|
|
8
|
+
function main() {
|
|
9
|
+
try {
|
|
10
|
+
let binaryPath = resolveBinaryPath();
|
|
11
|
+
let result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
12
|
+
stdio: "inherit",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (result.error) throw result.error;
|
|
16
|
+
|
|
17
|
+
if (typeof result.status === "number") {
|
|
18
|
+
process.exit(result.status);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (result.signal) {
|
|
22
|
+
process.kill(process.pid, result.signal);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`[jam] ${error.message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
main();
|
package/lib/platform.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function parseNodeLibcFromReport(report) {
|
|
4
|
+
if (!report || !report.header) return null;
|
|
5
|
+
if (report.header.glibcVersionRuntime) return "glibc";
|
|
6
|
+
|
|
7
|
+
let reportText = JSON.stringify(report).toLowerCase();
|
|
8
|
+
if (reportText.includes("musl")) return "musl";
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function detectLibc(runtime) {
|
|
13
|
+
if (runtime.platform !== "linux") return null;
|
|
14
|
+
|
|
15
|
+
let forced = runtime.env.JAM_LIBC;
|
|
16
|
+
if (forced === "glibc" || forced === "musl") return forced;
|
|
17
|
+
|
|
18
|
+
let fromReport = parseNodeLibcFromReport(runtime.report);
|
|
19
|
+
if (fromReport) return fromReport;
|
|
20
|
+
|
|
21
|
+
return "glibc";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveTarget(platform, arch, libc) {
|
|
25
|
+
if (platform === "darwin" && arch === "arm64") return "darwin-arm64";
|
|
26
|
+
if (platform === "darwin" && arch === "x64") return "darwin-x64";
|
|
27
|
+
|
|
28
|
+
if (platform === "linux" && arch === "x64" && libc === "glibc") return "linux-x64";
|
|
29
|
+
if (platform === "linux" && arch === "arm64" && libc === "glibc") return "linux-arm64";
|
|
30
|
+
if (platform === "linux" && libc === "musl") {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Linux musl is not supported yet: platform=${platform} arch=${arch} libc=${libc}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Unsupported platform for Jam npm package: platform=${platform} arch=${arch} libc=${libc || "n/a"}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function binaryFileName(platform) {
|
|
42
|
+
return platform === "win32" ? "jam.exe" : "jam";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getRuntimeDescriptor(overrides) {
|
|
46
|
+
let platform = overrides?.platform ?? process.platform;
|
|
47
|
+
let arch = overrides?.arch ?? process.arch;
|
|
48
|
+
let report =
|
|
49
|
+
overrides?.report ??
|
|
50
|
+
(process.report && typeof process.report.getReport === "function"
|
|
51
|
+
? process.report.getReport()
|
|
52
|
+
: null);
|
|
53
|
+
let env = overrides?.env ?? process.env;
|
|
54
|
+
|
|
55
|
+
let libc = detectLibc({ platform, env, report });
|
|
56
|
+
let target = resolveTarget(platform, arch, libc);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
arch,
|
|
60
|
+
libc,
|
|
61
|
+
platform,
|
|
62
|
+
target,
|
|
63
|
+
binaryName: binaryFileName(platform),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
binaryFileName,
|
|
69
|
+
detectLibc,
|
|
70
|
+
getRuntimeDescriptor,
|
|
71
|
+
resolveTarget,
|
|
72
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let {
|
|
4
|
+
packageNameForTarget,
|
|
5
|
+
resolveOptionalPackageBinaryPath,
|
|
6
|
+
} = require("./resolve-optional-package");
|
|
7
|
+
let { getRuntimeDescriptor } = require("./platform");
|
|
8
|
+
|
|
9
|
+
function resolveBinaryPath() {
|
|
10
|
+
let fromEnv = process.env.JAM_BINARY_PATH;
|
|
11
|
+
if (fromEnv) return fromEnv;
|
|
12
|
+
|
|
13
|
+
let descriptor = getRuntimeDescriptor();
|
|
14
|
+
let optionalPath = resolveOptionalPackageBinaryPath(descriptor);
|
|
15
|
+
if (optionalPath) return optionalPath;
|
|
16
|
+
|
|
17
|
+
let packageName = packageNameForTarget(descriptor.target);
|
|
18
|
+
|
|
19
|
+
if (!packageName) {
|
|
20
|
+
throw new Error(`No optional dependency package is configured for ${descriptor.target}.`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Jam optional dependency package not installed for ${descriptor.target}: ${packageName}. Try reinstalling with optional dependencies enabled.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
resolveBinaryPath,
|
|
30
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let fs = require("node:fs");
|
|
4
|
+
let path = require("node:path");
|
|
5
|
+
|
|
6
|
+
let TARGET_TO_PACKAGE = {
|
|
7
|
+
"darwin-arm64": "jam-darwin-arm64",
|
|
8
|
+
"darwin-x64": "jam-darwin-x64",
|
|
9
|
+
"linux-x64": "jam-linux-x64",
|
|
10
|
+
"linux-arm64": "jam-linux-arm64",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function packageNameForTarget(target) {
|
|
14
|
+
return TARGET_TO_PACKAGE[target] || null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function packageRootFromName(packageName) {
|
|
18
|
+
try {
|
|
19
|
+
let packageJsonPath = require.resolve(`${packageName}/package.json`, {
|
|
20
|
+
paths: [path.join(__dirname, "..")],
|
|
21
|
+
});
|
|
22
|
+
return path.dirname(packageJsonPath);
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolveOptionalPackageBinaryPath(runtimeDescriptor) {
|
|
29
|
+
let packageName = packageNameForTarget(runtimeDescriptor.target);
|
|
30
|
+
if (!packageName) return null;
|
|
31
|
+
|
|
32
|
+
let packageRoot = packageRootFromName(packageName);
|
|
33
|
+
if (!packageRoot) return null;
|
|
34
|
+
|
|
35
|
+
let binaryPath = path.join(packageRoot, "bin", runtimeDescriptor.binaryName);
|
|
36
|
+
if (!fs.existsSync(binaryPath)) return null;
|
|
37
|
+
return binaryPath;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
packageNameForTarget,
|
|
42
|
+
resolveOptionalPackageBinaryPath,
|
|
43
|
+
};
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jam",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"test": "make test"
|
|
8
|
-
},
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "An application server for isolated JavaScript",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "commonjs",
|
|
9
7
|
"repository": {
|
|
10
8
|
"type": "git",
|
|
11
|
-
"url": "git://github.com/
|
|
9
|
+
"url": "git+https://github.com/mjackson/jam.git",
|
|
10
|
+
"directory": "packages/jam"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/mjackson/jam",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mjackson/jam/issues"
|
|
12
15
|
},
|
|
13
|
-
"
|
|
14
|
-
"jam"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
16
|
+
"bin": {
|
|
17
|
+
"jam": "bin/jam.js"
|
|
18
|
+
},
|
|
19
|
+
"optionalDependencies": {
|
|
20
|
+
"jam-darwin-arm64": "0.7.1",
|
|
21
|
+
"jam-darwin-x64": "0.7.1",
|
|
22
|
+
"jam-linux-x64": "0.7.1",
|
|
23
|
+
"jam-linux-arm64": "0.7.1"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"bin",
|
|
27
|
+
"lib",
|
|
28
|
+
"README.md"
|
|
19
29
|
],
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"readmeFilename": "README.md",
|
|
23
|
-
"directories": {
|
|
24
|
-
"test": "test",
|
|
25
|
-
"lib": "lib"
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
26
32
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"mocha-istanbul": "~0.2.0",
|
|
30
|
-
"mocha": "~1.12.0",
|
|
31
|
-
"plato": "~0.6.1",
|
|
32
|
-
"chai": "~1.7.2",
|
|
33
|
-
"sinon": "~1.7.3",
|
|
34
|
-
"groc": "~0.4.0"
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node test/platform.test.js && node test/resolve-optional-package.test.js"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|
package/.npmignore
DELETED
package/.travis.yml
DELETED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
Copyright (c) 2013 Chakrit Wichian <service@chakrit.net> (http://chakrit.net)
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
in the Software without restriction, including without limitation the rights
|
|
7
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
furnished to do so, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
20
|
-
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
-
|
package/Makefile
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
BIN := $(shell pwd)/node_modules/.bin
|
|
3
|
-
|
|
4
|
-
GLOBALS := __coverage__,buffertools,SlowBuffer,events,util,task
|
|
5
|
-
TEST_ENV := test
|
|
6
|
-
|
|
7
|
-
# Project files definition
|
|
8
|
-
TEST_FILES := $(wildcard test/**/*.js) $(wildcard test/*.js)
|
|
9
|
-
LIB_FILES := $(wildcard lib/**/*.js) $(wildcard lib/*.js)
|
|
10
|
-
COV_FILES := $(LIB_FILES:lib/%.js=lib-cov/%.js)
|
|
11
|
-
|
|
12
|
-
INDEX_FILE = index.js
|
|
13
|
-
MAIN_FILE = lib/jam.js
|
|
14
|
-
|
|
15
|
-
# Test parameters so we can configure these via make
|
|
16
|
-
TEST_TIMEOUT = 100
|
|
17
|
-
TEST_REPORTER = list
|
|
18
|
-
TDD_REPORTER = min
|
|
19
|
-
COVER_REPORTER = mocha-istanbul
|
|
20
|
-
|
|
21
|
-
# Command-line tools options
|
|
22
|
-
MOCHA_OPTS = --bail --timeout $(TEST_TIMEOUT) --reporter $(TEST_REPORTER) --globals $(GLOBALS)
|
|
23
|
-
MOCHA_TDD_OPTS = $(MOCHA_OPTS) --watch --reporter $(TDD_REPORTER)
|
|
24
|
-
MOCHA_COVER_OPTS = $(MOCHA_OPTS) --reporter $(COVER_REPORTER)
|
|
25
|
-
ISTANBUL_OPTS = instrument --variable global.__coverage__ --no-compact
|
|
26
|
-
PLATO_OPTS = -d html-report/
|
|
27
|
-
GROC_OPTS = -t lib/ -o doc/ --no-whitespace-after-token false --index $(MAIN_FILE)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
default: node_modules
|
|
31
|
-
|
|
32
|
-
node_modules:
|
|
33
|
-
npm install
|
|
34
|
-
|
|
35
|
-
# File transformations
|
|
36
|
-
lib-cov/%.js: lib/%.js
|
|
37
|
-
@mkdir -p $(@D)
|
|
38
|
-
$(BIN)/istanbul $(ISTANBUL_OPTS) --output $@ $<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# Testing
|
|
42
|
-
test: node_modules
|
|
43
|
-
NODE_ENV=$(TEST_ENV) $(BIN)/mocha $(MOCHA_OPTS) $(TEST_FILES)
|
|
44
|
-
tdd: node_modules
|
|
45
|
-
NODE_ENV=$(TEST_ENV) $(BIN)/mocha $(MOCHA_TDD_OPTS) $(TEST_FILES)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# Code instrumentation
|
|
49
|
-
instrument: node_modules $(COV_FILES)
|
|
50
|
-
cover: instrument
|
|
51
|
-
NODE_ENV=$(TEST_ENV) JAM_COVER=1 $(BIN)/mocha $(MOCHA_COVER_OPTS) $(TEST_FILES)
|
|
52
|
-
complex:
|
|
53
|
-
$(BIN)/plato $(PLATO_OPTS) $(LIB_FILES)
|
|
54
|
-
|
|
55
|
-
doc:
|
|
56
|
-
$(BIN)/groc $(GROC_OPTS) $(LIB_FILES)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# Cleans
|
|
60
|
-
clean:
|
|
61
|
-
-rm -Rf lib-cov/
|
|
62
|
-
-rm -Rf html-report/
|
|
63
|
-
-rm -Rf doc/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.PHONY: debug default test tdd clean doc doc-gh instrument cover complex
|
|
67
|
-
|
package/example/file1.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a - First! I am the very very first file.
|
package/example/file2.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
b - I am the second file, residing in B. 2nd's not a bad place, ain't it?
|
package/example/file3.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
c - I'm the last one. I get to write the ending!
|