functionalscript 0.0.494 → 0.0.495

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.
@@ -1,7 +1,7 @@
1
1
  # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
3
 
4
- name: node CI
4
+ name: CI
5
5
 
6
6
  on:
7
7
  push:
@@ -10,7 +10,7 @@ on:
10
10
  pull_request:
11
11
 
12
12
  jobs:
13
- build:
13
+ node:
14
14
 
15
15
  runs-on: ubuntu-latest
16
16
 
@@ -29,3 +29,23 @@ jobs:
29
29
  - run: npm test
30
30
  - run: npm run version
31
31
  - run: npm pack
32
+
33
+ deno:
34
+
35
+ runs-on: ubuntu-latest
36
+
37
+ steps:
38
+ - uses: actions/checkout@v2
39
+ - uses: denoland/setup-deno@v1
40
+ with:
41
+ deno-version: v1.x
42
+ - run: deno run --quiet --allow-read --allow-env --allow-net --allow-hrtime ./dev/test.mjs
43
+
44
+ bun:
45
+
46
+ runs-on: ubuntu-latest
47
+
48
+ steps:
49
+ - uses: actions/checkout@v2
50
+ - run: curl https://bun.sh/install | bash
51
+ - run: /home/runner/.bun/bin/bun ./dev/test.mjs
@@ -10,7 +10,7 @@ on:
10
10
  pull_request:
11
11
 
12
12
  jobs:
13
- build:
13
+ COM:
14
14
 
15
15
  strategy:
16
16
  matrix:
package/dev/module.mjs CHANGED
@@ -84,6 +84,16 @@ export const fs = () => import(self.Deno ? 'https://deno.land/std/node/fs/promis
84
84
  /** @type {(code: number) => never} */
85
85
  export const exit = self.Deno ? self.Deno.exit : process.exit
86
86
 
87
+ /** @type {(v: string) => string|undefined} */
88
+ export const env =
89
+ self.Deno ? self.Deno.env.get :
90
+ a => {
91
+ const r = Object.getOwnPropertyDescriptor(process.env, a)
92
+ return r === void 0 ? void 0 :
93
+ typeof r.get === 'function' ? r.get() :
94
+ r.value
95
+ }
96
+
87
97
  export const loadModuleMap = async () => {
88
98
  const { readdir, readFile } = await fs();
89
99
 
@@ -37,9 +37,11 @@ const result = require('../../types/result/module.f.cjs')
37
37
  * @typedef {{
38
38
  * readonly moduleMap: ModuleMap,
39
39
  * readonly log: Log<T>,
40
+ * readonly error: Log<T>,
40
41
  * readonly measure: Measure<T>,
41
42
  * readonly state: T,
42
- * readonly tryCatch: <R>(f: () => R) => result.Result<R, unknown>
43
+ * readonly tryCatch: <R>(f: () => R) => result.Result<R, unknown>,
44
+ * readonly env: (n: string) => string|undefined
43
45
  * }} Input
44
46
  */
45
47
 
@@ -67,54 +69,62 @@ const addFail = delta => ts => ({ ...ts, time: ts.time + delta, fail: ts.fail +
67
69
 
68
70
  /** @type {<T>(input: Input<T>) => readonly[number, T]} */
69
71
  const main = input => {
70
- let { moduleMap, log, measure, tryCatch, state } = input
72
+ let { moduleMap, log, error, measure, tryCatch, env, state } = input
73
+ const isGitHub = env('GITHUB_ACTION') !== void 0
71
74
  /** @typedef {input extends Input<infer T> ? T : never} T */
72
- /** @type {(i: string) => (v: unknown) => (fs: FullState<T>) => FullState<T>} */
73
- const test = i => v => ([ts, state]) => {
74
- const next = test(`${i}| `)
75
- switch (typeof v) {
76
- case 'function': {
77
- if (v.length === 0) {
78
- const [[s, r], delta, state0] = measure(() => tryCatch(/** @type {() => unknown} */(v)))(state)
79
- state = state0
80
- if (s === 'error') {
81
- ts = addFail(delta)(ts)
82
- state = log(`${i}() ${fgRed}error${reset}, ${delta} ms`)(state)
83
- state = log(`${fgRed}${r}${reset}`)(state)
84
- } else {
85
- ts = addPass(delta)(ts)
86
- state = log(`${i}() ${fgGreen}ok${reset}, ${delta} ms`)(state)
75
+ /** @type {(k: readonly[string, Module]) => (fs: FullState<T>) => FullState<T>} */
76
+ const f = ([k, v]) => {
77
+ /** @type {(i: string) => (v: unknown) => (fs: FullState<T>) => FullState<T>} */
78
+ const test = i => v => ([ts, state]) => {
79
+ const next = test(`${i}| `)
80
+ switch (typeof v) {
81
+ case 'function': {
82
+ if (v.length === 0) {
83
+ const [[s, r], delta, state0] = measure(() => tryCatch(/** @type {() => unknown} */(v)))(state)
84
+ state = state0
85
+ if (s === 'error') {
86
+ ts = addFail(delta)(ts)
87
+ if (isGitHub) {
88
+ // https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions
89
+ // https://github.com/OndraM/ci-detector/blob/main/src/Ci/GitHubActions.php
90
+ state = error(`::error file=${k},line=1,title=[3]['a']()::${r}`)(state)
91
+ } else {
92
+ state = error(`${i}() ${fgRed}error${reset}, ${delta} ms`)(state)
93
+ state = error(`${fgRed}${r}${reset}`)(state)
94
+ }
95
+ } else {
96
+ ts = addPass(delta)(ts)
97
+ state = log(`${i}() ${fgGreen}ok${reset}, ${delta} ms`)(state)
98
+ }
99
+ [ts, state] = next(r)([ts, state])
87
100
  }
88
- [ts, state] = next(r)([ts, state])
101
+ break
89
102
  }
90
- break
91
- }
92
- case 'object': {
93
- if (v !== null) {
94
- /** @type {(k: readonly[string|number, unknown]) => (fs: FullState<T>) => FullState<T>} */
95
- const f = ([k, v]) => ([time, state]) => {
96
- state = log(`${i}${k}:`)(state);
97
- [time, state] = next(v)([time, state])
98
- return [time, state]
103
+ case 'object': {
104
+ if (v !== null) {
105
+ /** @type {(k: readonly[string|number, unknown]) => (fs: FullState<T>) => FullState<T>} */
106
+ const f = ([k, v]) => ([time, state]) => {
107
+ state = log(`${i}${k}:`)(state);
108
+ [time, state] = next(v)([time, state])
109
+ return [time, state]
110
+ }
111
+ [ts, state] = fold
112
+ (f)
113
+ ([ts, state])
114
+ (v instanceof Array ? list.entries(v) : Object.entries(v))
99
115
  }
100
- [ts, state] = fold
101
- (f)
102
- ([ts, state])
103
- (v instanceof Array ? list.entries(v) : Object.entries(v))
116
+ break
104
117
  }
105
- break
106
118
  }
119
+ return [ts, state]
107
120
  }
108
- return [ts, state]
109
- }
110
- const next = test('| ')
111
- /** @type {(k: readonly[string, Module]) => (fs: FullState<T>) => FullState<T>} */
112
- const f = ([k, v]) => ([ts, state]) => {
113
- if (isTest(k)) {
114
- state = log(`testing ${k}`)(state);
115
- [ts, state] = next(v.exports)([ts, state])
121
+ return ([ts, state]) => {
122
+ if (isTest(k)) {
123
+ state = log(`testing ${k}`)(state);
124
+ [ts, state] = test('| ')(v.exports)([ts, state])
125
+ }
126
+ return [ts, state]
116
127
  }
117
- return [ts, state]
118
128
  }
119
129
  /** @type {TestState} */
120
130
  let ts = { time: 0, pass: 0, fail: 0 };
package/dev/test.mjs CHANGED
@@ -1,10 +1,8 @@
1
- import { loadModuleMap, exit } from './module.mjs'
1
+ import { loadModuleMap, exit, env } from './module.mjs'
2
2
 
3
- const consoleLog = console.log
4
-
5
- /** @type {(s: string) => <T>(_: T) => T} */
6
- const log = s => state => {
7
- consoleLog(s)
3
+ /** @type {(f: (s: string) => void) => (s: string) => <T>(_: T) => T} */
4
+ const anyLog = f => s => state => {
5
+ f(s)
8
6
  return state
9
7
  }
10
8
 
@@ -50,9 +48,11 @@ const main = async() => {
50
48
  const f = moduleMap['./dev/test/module.f.cjs'].exports
51
49
  const r = f({
52
50
  moduleMap,
53
- log,
51
+ log: anyLog(console.log),
52
+ error: anyLog(console.error),
54
53
  measure,
55
54
  tryCatch,
55
+ env,
56
56
  })
57
57
  exit(r[0])
58
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.494",
3
+ "version": "0.0.495",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -1,17 +0,0 @@
1
- name: bun
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
- pull_request:
8
-
9
- jobs:
10
- build:
11
-
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - uses: actions/checkout@v2
16
- - run: curl https://bun.sh/install | bash
17
- - run: /home/runner/.bun/bin/bun ./dev/test.mjs
@@ -1,19 +0,0 @@
1
- name: deno
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
- pull_request:
8
-
9
- jobs:
10
- build:
11
-
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - uses: actions/checkout@v2
16
- - uses: denoland/setup-deno@v1
17
- with:
18
- deno-version: v1.x
19
- - run: deno run --allow-read --allow-env --allow-net --allow-hrtime ./dev/test.mjs