functionalscript 0.0.422 → 0.0.423

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.
@@ -12,4 +12,4 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - run: curl https://bun.sh/install | bash
15
- - run: /home/runner/.bun/bin/bun ./test.f.cjs
15
+ - run: /home/runner/.bun/bin/bun ./test.mjs
@@ -14,4 +14,4 @@ jobs:
14
14
  - uses: denoland/setup-deno@v1
15
15
  with:
16
16
  deno-version: v1.x
17
- - run: deno run --allow-read --allow-env ./denotest.mjs
17
+ - run: deno run --allow-read --allow-env --allow-net ./test.mjs
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.422",
3
+ "version": "0.0.423",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
7
7
  "tsc": "tsc",
8
8
  "test": "tsc && npm run test-only",
9
9
  "version": "node ./nodejs/version/main.cjs",
10
- "test-only": "node --trace-uncaught ./test.f.cjs"
10
+ "test-only": "node --trace-uncaught ./test.mjs"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -1,69 +1,70 @@
1
- // import * as fs from "https://deno.land/std/node/fs.ts"
2
-
3
1
  /**
4
- * @type {{
5
- * readonly readDir: (path: string | URL) => AsyncIterable<DirEntry>,
6
- * readonly readTextFile: (path: string | URL) => Promise<string>,
7
- * }}
2
+ * @typedef {{
3
+ * readonly withFileTypes: true
4
+ * }} Options
8
5
  */
9
- const {
10
- readDir,
11
- readTextFile,
12
- } = Deno
13
6
 
14
7
  /**
15
8
  * @typedef {{
16
- * readonly isDirectory: boolean
17
- * readonly isFile: boolean
18
- * readonly isSymlink: boolean
19
9
  * readonly name: string
20
- * }} DirEntry
10
+ * readonly isDirectory: () => boolean
11
+ * }} Dirent
21
12
  */
22
13
 
23
- /** @typedef {{ exports?: unknown }} Module */
24
-
25
- /** @typedef {(name: string) => unknown} Require */
26
-
27
14
  /**
28
15
  * @typedef {{
29
- * [k in string]: Function
30
- * }} FunctionMap
16
+ * readonly readdir: (path: string, options: Options) => Promise<readonly Dirent[]>
17
+ * readonly readFile: (path: string, options: 'utf8') => Promise<Buffer>
18
+ * }} FsPromises
31
19
  */
32
20
 
33
- /** @type {(path: string) => Promise<FunctionMap>} */
34
- const dir = async p => {
21
+ /** @type {FsPromises} */
22
+ const { readdir, readFile } = await import(globalThis.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
23
+
24
+ const load = async() => {
35
25
  /** @type {FunctionMap} */
36
26
  const map = {}
37
27
  /** @type {(path: string) => Promise<void>} */
38
28
  const f = async p => {
39
- for await (const i of readDir(p)) {
29
+ for (const i of await readdir(p, { withFileTypes: true })) {
40
30
  const { name } = i
41
31
  if (!name.startsWith('.')) {
42
32
  const file = `${p}/${name}`
43
- if (i.isDirectory) {
33
+ if (i.isDirectory()) {
44
34
  if (!['node_modules', 'target'].includes(name)) {
45
35
  await f(file)
46
36
  }
47
37
  } else if (name.endsWith('.f.cjs')) {
48
38
  console.log(`loading ${file}`)
49
- const source = await readTextFile(file)
39
+ const source = await readFile(file, 'utf8')
50
40
  map[file] = Function('module', 'require', `"use strict";${source}`)
51
41
  }
52
42
  }
53
43
  }
54
44
  }
55
- await f(p)
45
+ await f('.')
56
46
  return map
57
47
  }
58
48
 
49
+ const map = await load()
50
+
51
+ /** @typedef {{ exports?: unknown }} Module */
52
+
53
+ /** @typedef {(name: string) => unknown} Require */
54
+
55
+ /**
56
+ * @typedef {{
57
+ * [k in string]: Function
58
+ * }} FunctionMap
59
+ */
60
+
59
61
  /**
60
62
  * @typedef {{
61
63
  * [k in string]: unknown
62
64
  * }} ModuleMap
63
65
  */
64
66
 
65
- const run = async () => {
66
- const m = await dir('.')
67
+ const build = async () => {
67
68
  /** @type {ModuleMap} */
68
69
  const d = {}
69
70
  /** @type {(base: readonly string[]) => (i: string) => (k: string) => unknown} */
@@ -79,7 +80,7 @@ const run = async () => {
79
80
  /** @type {Module} */
80
81
  const me = {}
81
82
  console.log(`${i}building ${pathStr}`)
82
- m[pathStr](me, req(newBase)(`${i}| `))
83
+ map[pathStr](me, req(newBase)(`${i}| `))
83
84
  const newResult = me.exports
84
85
  d[pathStr] = newResult
85
86
  return newResult
@@ -88,9 +89,10 @@ const run = async () => {
88
89
  }
89
90
  }
90
91
  const r = req(['.'])('')
91
- for (const k of Object.keys(m)) {
92
+ for (const k of Object.keys(map)) {
92
93
  r(k)
93
94
  }
95
+ return d
94
96
  }
95
97
 
96
- run()
98
+ const modules = await build()
package/tsconfig.json CHANGED
@@ -97,5 +97,5 @@
97
97
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
98
98
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
99
99
  },
100
- "exclude": ["target", "denotest.mjs"]
100
+ "exclude": ["target", "test.mjs"]
101
101
  }