@procedures/node 0.25.0 → 0.26.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/CHANGELOG.md +22 -0
- package/README.md +49 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/fresh-bundle.d.ts +47 -0
- package/dist/fresh-bundle.d.ts.map +1 -0
- package/dist/fresh-bundle.js +292 -0
- package/dist/fresh-bundle.js.map +1 -0
- package/package.json +22 -4
- package/src/fresh-bundle.ts +335 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @procedures/node
|
|
2
2
|
|
|
3
|
+
## 0.26.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- de95e59: New subpath `@procedures/node/fresh-bundle` (roadmap O49): a launcher that starts a TypeScript entry from an esbuild bundle in a cache folder. It comes from jarvis (jarvis#80).
|
|
8
|
+
|
|
9
|
+
- `launch(spec)` starts the last build only when each source and each file of `spec.inputs` has the content hash of the build. Otherwise it makes a new build in a child process. When the build fails, it starts the source through `tsx`.
|
|
10
|
+
- `freshEntry(spec)` gives the entry file of the fresh build, or `undefined`. `build(spec)` makes a build in this process.
|
|
11
|
+
- `esbuild` and `tsx` are optional peer dependencies. The package root does not load the subpath, and an import of the root does not need them.
|
|
12
|
+
|
|
13
|
+
This release changes no behavior of the procedures. jarvis can import `launch` from `@procedures/node/fresh-bundle` and remove its copy of `fresh-bundle.mjs`.
|
|
14
|
+
- @procedures/client@0.26.1
|
|
15
|
+
- @procedures/shell@0.26.1
|
|
16
|
+
|
|
17
|
+
## 0.26.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [a16af64]
|
|
22
|
+
- @procedures/client@0.26.0
|
|
23
|
+
- @procedures/shell@0.26.0
|
|
24
|
+
|
|
3
25
|
## 0.25.0
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -380,6 +380,55 @@ import { registerNodeProcedures } from "@procedures/node";
|
|
|
380
380
|
registerNodeProcedures();
|
|
381
381
|
```
|
|
382
382
|
|
|
383
|
+
## The fresh bundle: a fast start for a TypeScript CLI
|
|
384
|
+
|
|
385
|
+
The subpath `@procedures/node/fresh-bundle` starts a TypeScript entry from an esbuild bundle in a cache folder. The package root does not load it, and it registers no procedure.
|
|
386
|
+
|
|
387
|
+
- The launcher starts the last build only when each file of that build has the same content hash. These files are the sources that esbuild compiled and the files of `inputs`.
|
|
388
|
+
- When a file changed, the launcher makes a new build in a child process. An edit that keeps the size and the modification time also makes a new build.
|
|
389
|
+
- When the build fails, the launcher starts the source through `tsx`. It writes the error output to `build-error.txt` in the cache folder.
|
|
390
|
+
- Each package in `node_modules` stays outside the bundle. It loads from the file that Node.js resolves from its importer, at the same version as under `tsx`.
|
|
391
|
+
- Each file of the bundle keeps its own `import.meta.url`, `import.meta.dirname` and `import.meta.filename`. A different use of `import.meta` makes the build fail.
|
|
392
|
+
- The bundle is an ES module. Use the launcher in a project with `"type": "module"`.
|
|
393
|
+
- A build that no launch used for 6 hours goes away at the next build.
|
|
394
|
+
|
|
395
|
+
Add the optional peer dependencies `esbuild` and `tsx` to the project:
|
|
396
|
+
|
|
397
|
+
```sh
|
|
398
|
+
pnpm add @procedures/node esbuild tsx
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Write the launcher in JavaScript, so that Node.js starts it without a build:
|
|
402
|
+
|
|
403
|
+
```js
|
|
404
|
+
// bin/cli.mjs
|
|
405
|
+
import { join } from "node:path";
|
|
406
|
+
import { fileURLToPath } from "node:url";
|
|
407
|
+
import { launch } from "@procedures/node/fresh-bundle";
|
|
408
|
+
|
|
409
|
+
const root = fileURLToPath(new URL("..", import.meta.url));
|
|
410
|
+
|
|
411
|
+
await launch({
|
|
412
|
+
entry: join(root, "src", "cli.ts"),
|
|
413
|
+
// A folder that Git ignores. A new install removes it.
|
|
414
|
+
outDir: join(root, "node_modules", ".cache", "my-cli"),
|
|
415
|
+
// The files that decide a build in addition to the sources
|
|
416
|
+
inputs: [
|
|
417
|
+
join(root, "package.json"),
|
|
418
|
+
join(root, "pnpm-lock.yaml"),
|
|
419
|
+
join(root, "tsconfig.json"),
|
|
420
|
+
fileURLToPath(import.meta.url),
|
|
421
|
+
],
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
| Export | Description |
|
|
426
|
+
|---|---|
|
|
427
|
+
| `launch(spec)` | It starts the fresh build of the entry, else a new build, else the source through `tsx`. In the entry, `process.argv[1]` is the entry. |
|
|
428
|
+
| `freshEntry(spec)` | It gives the entry file of the fresh build, or `undefined` when a file changed. |
|
|
429
|
+
| `build(spec)` | It makes a build in this process. The process needs the flag `--experimental-import-meta-resolve`. |
|
|
430
|
+
| `FreshBundleSpec` | The type of `spec`: the absolute paths `entry`, `outDir` and `inputs`, and the optional module name `esbuild` (the default is `esbuild`). |
|
|
431
|
+
|
|
383
432
|
## Related Packages
|
|
384
433
|
|
|
385
434
|
- `@procedures/client` - Core client framework
|