@amritk/nish 0.12.0 → 0.13.0

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.
@@ -28,7 +28,7 @@
28
28
  *
29
29
  * **The compiler resolves the link itself as of 0.6.0** -- the real path of
30
30
  * whatever `argv[0]` named is a candidate for the package root
31
- * ([wp19 §5a](../docs/wp19-stage0-retirement.md) item 4, in `self/`) -- so this
31
+ * ([wp19 §5a](../docs/wp19-stage0-retirement.md) item 4, in `src/`) -- so this
32
32
  * `exec` is no longer what makes a copy work, and the reason it is still here is
33
33
  * the 91 ms above rather than the defect. It also still carries whoever never
34
34
  * ran this script: a shim npm linked and nothing swapped now finds its own
@@ -45,44 +45,54 @@
45
45
  * postinstall that can break `npm ci` is a worse bug than the startup cost it
46
46
  * exists to remove.
47
47
  */
48
- import fs from "node:fs";
49
- import path from "node:path";
50
- import { createRequire } from "node:module";
51
- import { pathToFileURL } from "node:url";
48
+ import fs from "node:fs"
49
+ import path from "node:path"
50
+ import { createRequire } from "node:module"
51
+ import { pathToFileURL } from "node:url"
52
52
 
53
- const root = path.resolve(import.meta.dirname, "..");
53
+ const root = path.resolve(import.meta.dirname, "..")
54
54
 
55
55
  const swap = async () => {
56
56
  // A checkout, not an install. The repository is its own package, so `npm ci`
57
57
  // here installs this package's own optionalDependencies -- and without this
58
58
  // guard, the first `npm ci` after they are published would overwrite the
59
59
  // tracked `bin/nish` with a binary and leave the working tree dirty. The
60
- // landmark is `self/compile.ts`, which is the check `scripts/bootstrap.sh`
61
- // makes and is not in `files`; it used to be `src/launcher.ts`, which stopped
60
+ // landmark is `src/compile.ts`, which is the check `scripts/bootstrap.sh`
61
+ // makes and is not in `files`; it used to be stage0's `src/launcher.ts`, which stopped
62
62
  // being a landmark when the launcher moved into `bin/` and ships.
63
- if (fs.existsSync(path.join(root, "self", "compile.ts"))) return "a checkout, so the shim stays";
63
+ if (fs.existsSync(path.join(root, "src", "compile.ts"))) {
64
+ return "a checkout, so the shim stays"
65
+ }
64
66
 
65
- const shim = path.join(root, "bin", "nish");
66
- if (!fs.existsSync(shim)) return "no bin/nish to replace";
67
+ const shim = path.join(root, "bin", "nish")
68
+ if (!fs.existsSync(shim)) {
69
+ return "no bin/nish to replace"
70
+ }
67
71
 
68
- const packaging = path.join(root, "bin", "packaging.js");
69
- if (!fs.existsSync(packaging)) return "bin/packaging.js is missing";
70
- const { assetFor, platformPackageName } = await import(pathToFileURL(packaging).href);
71
- const asset = assetFor(process.platform, process.arch);
72
- if (asset === null) return `no prebuilt binary for ${process.platform}/${process.arch}`;
72
+ const packaging = path.join(root, "bin", "packaging.js")
73
+ if (!fs.existsSync(packaging)) {
74
+ return "bin/packaging.js is missing"
75
+ }
76
+ const { assetFor, platformPackageName } = await import(pathToFileURL(packaging).href)
77
+ const asset = assetFor(process.platform, process.arch)
78
+ if (asset === null) {
79
+ return `no prebuilt binary for ${process.platform}/${process.arch}`
80
+ }
73
81
 
74
82
  const name = platformPackageName(
75
83
  JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8")).name,
76
84
  asset
77
- );
78
- let binary;
85
+ )
86
+ let binary
79
87
  try {
80
- const manifest = createRequire(import.meta.url).resolve(`${name}/package.json`);
81
- binary = path.join(path.dirname(manifest), "bin", "nish");
88
+ const manifest = createRequire(import.meta.url).resolve(`${name}/package.json`)
89
+ binary = path.join(path.dirname(manifest), "bin", "nish")
82
90
  } catch {
83
- return `${name} is not installed`;
91
+ return `${name} is not installed`
92
+ }
93
+ if (!fs.existsSync(binary)) {
94
+ return `${name} carries no bin/nish`
84
95
  }
85
- if (!fs.existsSync(binary)) return `${name} carries no bin/nish`;
86
96
 
87
97
  // The absolute path is baked in at install time, which is the one thing this
88
98
  // gives up: a `node_modules` copied to a different path without a reinstall
@@ -99,35 +109,35 @@ const swap = async () => {
99
109
  // have ended up in, the shell would expand them. A home directory with a `$`
100
110
  // in it is unusual and entirely legal. In POSIX sh nothing is special inside
101
111
  // single quotes, so the only thing to handle is a single quote itself.
102
- const shellQuote = (value) => `'${value.split("'").join(`'\\''`)}'`;
103
- const target = shellQuote(binary);
112
+ const shellQuote = (value) => `'${value.split("'").join(`'\\''`)}'`
113
+ const target = shellQuote(binary)
104
114
  const script =
105
115
  "#!/bin/sh\n" +
106
116
  "# Written by scripts/postinstall.mjs. `npm rebuild` regenerates it.\n" +
107
117
  `if [ -x ${target} ]; then exec ${target} "$@"; fi\n` +
108
118
  // Exit 3 is this project's toolchain code: the compiler could not be run,
109
119
  // which is exactly what has happened (docs/wp12-release.md, "Exit codes").
110
- 'echo "nish: the prebuilt compiler is not where it was installed; run \'npm rebuild\' to repoint this" >&2\n' +
111
- "exit 3\n";
112
- const temp = `${shim}.${process.pid}.tmp`;
120
+ "echo \"nish: the prebuilt compiler is not where it was installed; run 'npm rebuild' to repoint this\" >&2\n" +
121
+ "exit 3\n"
122
+ const temp = `${shim}.${process.pid}.tmp`
113
123
  try {
114
- fs.writeFileSync(temp, script);
115
- fs.chmodSync(temp, 0o755);
116
- fs.renameSync(temp, shim);
124
+ fs.writeFileSync(temp, script)
125
+ fs.chmodSync(temp, 0o755)
126
+ fs.renameSync(temp, shim)
117
127
  } catch (err) {
118
128
  try {
119
- fs.rmSync(temp, { force: true });
129
+ fs.rmSync(temp, { force: true })
120
130
  } catch {
121
131
  // Nothing to do about it, and it is not worth a second message.
122
132
  }
123
- throw err;
133
+ throw err
124
134
  }
125
- return `bin/nish now execs the native compiler in ${name}`;
126
- };
135
+ return `bin/nish now execs the native compiler in ${name}`
136
+ }
127
137
 
128
138
  try {
129
- console.log(`nish: ${await swap()}`);
139
+ console.log(`nish: ${await swap()}`)
130
140
  } catch (err) {
131
141
  // Deliberately not an error: the shim is still there and still works.
132
- console.log(`nish: keeping the node launcher (${err instanceof Error ? err.message : String(err)})`);
142
+ console.log(`nish: keeping the node launcher (${err instanceof Error ? err.message : String(err)})`)
133
143
  }
@@ -51,13 +51,13 @@ text_sum() { # text_sum <object>: every .text* secti
51
51
  }
52
52
  sect() { size -A "$2" | awk -v s="$1" '$1 == s { print $2 }'; }
53
53
  "${CC:-clang}" -Oz -c runtime/runtime.c -o build/size/runtime.o
54
- "${CC:-clang}" -Oz -c runtime/runtime_os.c -o build/size/runtime_os.o
54
+ "${CC:-clang}" -Oz -c runtime/runtime-os.c -o build/size/runtime_os.o
55
55
  row runtime "$(text_sum build/size/runtime.o)" \
56
56
  "clang -Oz -c runtime/runtime.c && size -A (.text*; budget 3584)"
57
57
  row runtime_os "$(text_sum build/size/runtime_os.o)" \
58
- "clang -Oz -c runtime/runtime_os.c && size -A (.text*; budget 1280)"
58
+ "clang -Oz -c runtime/runtime-os.c && size -A (.text*; budget 1280)"
59
59
  row rodata "$(sect .rodata build/size/runtime.o)" "the core object's .rodata (no budget; the Ryu tables live here)"
60
- # `scripts/build.sh` compiles runtime_os.c beside any runtime.c it is handed, so naming the
60
+ # `scripts/build.sh` compiles runtime-os.c beside any runtime.c it is handed, so naming the
61
61
  # core here builds the whole runtime -- and `--gc-sections` then drops whatever this module
62
62
  # never calls, which for `examples/add.ts` is all of it.
63
63
  for p in debug speed size; do
package/scripts/smoke.sh CHANGED
@@ -17,7 +17,7 @@
17
17
  # link, or run with the expected status. Binaries and IR go to build/smoke/.
18
18
  # Needs clang on PATH.
19
19
  set -uo pipefail
20
- cd "$(dirname "$0")/.."
20
+ cd "$(dirname "$0")/.." || exit
21
21
 
22
22
  examples=${1:-examples}
23
23
  out=build/smoke
package/std/README.md CHANGED
@@ -4,7 +4,7 @@ Nish modules written in Nish, for Nish programs to import. There is no magic
4
4
  here and — with three exceptions, `threads.ts`, `collections.ts` and `map.ts` —
5
5
  nothing the compiler knows about: a module in this directory is an ordinary Nish source file, compiled as part of
6
6
  whatever program imports it, and subject to the same rules as `examples/` or
7
- `self/` ([`docs/LANGUAGE.md`](../docs/LANGUAGE.md) is the style guide).
7
+ `src/` ([`docs/LANGUAGE.md`](../docs/LANGUAGE.md) is the style guide).
8
8
 
9
9
  | Module | What it is |
10
10
  | --- | --- |
@@ -130,7 +130,7 @@ that are *not* this package.
130
130
  stdout. `tests/link/std_text_f64` is the same corpus under
131
131
  `--number-mode f64`, which is where a module that spelled its widths and forgot
132
132
  a `toI32` is caught.
133
- - **`std/` is not on the compiler's dependency list.** Nothing in `self/`
133
+ - **`std/` is not on the compiler's dependency list.** Nothing in `src/`
134
134
  imports it, and nothing should: the compiler is the thing that has to
135
135
  build before the library means anything.
136
136