jspackr 0.2.0 → 0.4.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Kaloka Radia Nanda
3
+ Copyright (c) 2026 Kaloka Radia Nanda
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,66 +1,120 @@
1
1
  # jspackr
2
2
 
3
- A minimal JavaScript bundler powered by esbuild.
4
- Fast, simple, and focused on doing one thing well.
3
+ <img src='./logo.svg' width=150>
5
4
 
6
- ## Why jspackr?
5
+ `jspackr` is a small JavaScript bundler CLI implemented in Go and powered by [esbuild](https://esbuild.github.io/). It bundles one entry file and can minify output, generate source maps, print a size report, and rebuild when files under the entry file's directory change.
7
6
 
8
- jspackr exists because sometimes you just want to:
7
+ ## Features
9
8
 
10
- - bundle a JavaScript entry file
11
- - optionally minify it
12
- - see which files actually make your bundle big
9
+ - Bundle JavaScript with esbuild into ESM, IIFE, or CommonJS output.
10
+ - ESM output supports top-level `await`.
11
+ - Optional whitespace, syntax, and identifier minification.
12
+ - Linked or inline source maps.
13
+ - Build size report and watch mode.
14
+ - JSON configuration plus command line overrides.
13
15
 
14
- No config files.
15
- No plugins.
16
- No framework cosplay.
16
+ ## Requirements and supported platforms
17
17
 
18
- Run it, get your bundle, move on.
18
+ The Go source uses Go 1.22 or newer. Go can compile the CLI for Windows, Linux, and macOS on amd64 and arm64. The npm package currently contains a Linux x64 binary only; its launcher reports a clear error on other platforms. For other targets, install from source with Go.
19
19
 
20
- ## Features
20
+ ## Installation
21
21
 
22
- - ⚡ Extremely fast bundling via esbuild
23
- - ✂️ Optional minification
24
- - 📊 Simple build report to see top contributors
25
- - 🧠 Sensible CLI UX with shorthand flags
26
- - 🔄️ Watch mode for development
27
- - 🗺️ Source maps support (none, linked, inline)
22
+ Install with Go:
28
23
 
29
- ## Installation
24
+ ```sh
25
+ go install github.com/kalokaradia/jspackr/src/main@latest
26
+ ```
30
27
 
31
- For now, build from source:
28
+ The resulting `jspackr` executable must be on your `PATH`. The npm package is also available for Linux x64:
32
29
 
33
- ```bash
30
+ ```sh
34
31
  npm install -g jspackr
35
32
  ```
36
33
 
37
- ## Usage
34
+ ## Quick start
38
35
 
39
- -> Basic usage:
36
+ ```sh
37
+ jspackr --input src/index.js --out dist/bundle.js
38
+ jspackr -i src/index.js -o dist/app.js --minify --report
39
+ jspackr -i src/index.js -o dist/app.js --watch
40
+ jspackr -i src/index.js -o dist/app.mjs --format esm
41
+ ```
40
42
 
41
- ```bash
42
- jspackr src/index.js
43
+ The output directory is created when needed. Existing output files prompt before overwrite; use `--force`/`--yes` to skip that prompt. `--no-confirm` skips all confirmation prompts.
44
+ If no `--config`/`-c` path is provided, jspackr loads `jspackr.config.json` from the current directory when that file exists.
45
+
46
+ ## CLI options
47
+
48
+ | Option | Meaning |
49
+ | -------------------- | ------------------------------------------------------- |
50
+ | `-i`, `--input` | Entry JavaScript file (required) |
51
+ | `-o`, `--out` | Output file; defaults to `dist/bundle.js` |
52
+ | `-c`, `--config` | Read a JSON configuration file |
53
+ | `-m`, `--minify` | Enable esbuild minification |
54
+ | `-s`, `--source` | Source map mode: `none`, `l` (linked), or `in` (inline) |
55
+ | `--format` | Output format: `esm`, `iife`, or `cjs` (default: `iife`) |
56
+ | `-r`, `--report` | Print bundle size information |
57
+ | `-w`, `--watch` | Rebuild after changes under the entry file's directory |
58
+ | `--log-level` | `debug`, `info`, `warn`, or `error` |
59
+ | `-f`, `--force` | Skip output overwrite confirmation |
60
+ | `-y`, `--yes` | Automatically confirm overwrite prompts |
61
+ | `-n`, `--no-confirm` | Skip all confirmation prompts |
62
+ | `-h`, `--help` | Show help |
63
+ | `-v`, `--version` | Show CLI version |
64
+
65
+ Example `jspackr.config.json`:
66
+
67
+ ```json
68
+ {
69
+ "input": "./src/index.js",
70
+ "output": "./dist/bundle.js",
71
+ "minify": true,
72
+ "report": true,
73
+ "sourcemap": "l",
74
+ "format": "esm",
75
+ "watch": false,
76
+ "logLevel": "info"
77
+ }
43
78
  ```
44
79
 
45
- -> With options:
80
+ CLI values override config values when supplied. Boolean CLI flags turn a config option on; they do not turn a config option off.
81
+
82
+ Use `--format esm` to preserve ES module output and bundle entry points that use top-level `await`. The default `iife` keeps the classic self-executing bundle behavior. `cjs` emits CommonJS. When running an ESM output file with Node.js, use an `.mjs` extension or configure the containing package with `"type": "module"`.
83
+
84
+ Configuration supports the same build and confirmation options: `input`, `output`, `minify`, `report`, `sourcemap`, `format`, `watch`, `logLevel`, `force`, `yes`, and `noConfirm`. Source map values are `none`, `l` (linked), and `in` (inline); log levels are `debug`, `info`, `warn`, and `error`.
85
+
86
+ ## Development
46
87
 
47
- ```bash
48
- jspackr -i src/index.js -o dist/app.js -m -r -w
88
+ The implementation is organized into `src/main` (CLI orchestration), `src/config` (JSON configuration and validation), `src/core/builder` (esbuild integration), `src/core/watcher` (file watching), `src/cli` (terminal output), and `src/utils` (shared helpers).
89
+
90
+ ```sh
91
+ go mod download
92
+ go build ./...
93
+ go test ./...
94
+ go vet ./...
95
+ go test -race ./...
96
+ ```
97
+
98
+ ## Build and release
99
+
100
+ Build locally with `go build -o jspackr ./src/main`. Set the version in release binaries with:
101
+
102
+ ```sh
103
+ go build -ldflags "-X main.version=0.4.0" -o jspackr ./src/main
49
104
  ```
50
105
 
51
- ## CLI Options
106
+ For cross compilation, set `GOOS` and `GOARCH`, for example `GOOS=windows GOARCH=amd64`, `GOOS=linux GOARCH=arm64`, or `GOOS=darwin GOARCH=arm64`. Release maintainers should keep the git tag, npm `version`, and injected CLI version aligned. npm binary artifacts are currently maintained for Linux x64 only.
107
+
108
+ ## Troubleshooting
109
+
110
+ - `input path does not exist`: check the entry file path relative to the current working directory.
111
+ - npm reports an unsupported platform: use `go install` on Windows, macOS, or non-x64 Linux; those prebuilt binaries are not currently shipped in npm.
112
+ - Output overwrite prompt: pass `--force` in scripts that intentionally replace an existing bundle.
113
+
114
+ ## Contributing
52
115
 
53
- | Flag | Long Form | Description |
54
- | ---- | --------------- | ----------------------------------------- |
55
- | -i | --input \<file> | Entry file |
56
- | -o | --out \<file> | Output file (default: dist/bundle.js) |
57
- | -m | --minify | Minify output |
58
- | -r | --report | Show build report |
59
- | -s | --source <mode> | Source map: none, l (linked), in (inline) |
60
- | -w | --watch | Enable watch mode |
61
- | -h | --help | Show help |
116
+ Please use `gofmt` for Go files, add focused tests for behavior changes, and run the development checks above. Keep the CLI and configuration compatible unless a change is explicitly documented.
62
117
 
63
- ---
118
+ ## License
64
119
 
65
- Created with ❤️ by Kaloka Radia Nanda
66
- Licensed under the MIT License.
120
+ MIT. See [LICENSE](LICENSE).
Binary file
Binary file
Binary file
Binary file
Binary file
package/index.js ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { spawnSync } = require("node:child_process");
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+
9
+ const platformMap = {
10
+ linux: "linux",
11
+ darwin: "darwin",
12
+ win32: "win32",
13
+ };
14
+
15
+ const archMap = {
16
+ x64: "x64",
17
+ arm64: "arm64",
18
+ };
19
+
20
+ const platform = platformMap[process.platform];
21
+ const arch = archMap[process.arch];
22
+
23
+ if (!platform || !arch) {
24
+ console.error(
25
+ `jspackr: unsupported platform or architecture: ${process.platform}/${process.arch}`,
26
+ );
27
+ console.error(
28
+ "Supported platforms: Linux, macOS, and Windows on x64 or arm64.",
29
+ );
30
+ process.exit(1);
31
+ }
32
+
33
+ const extension = platform === "win32" ? ".exe" : "";
34
+
35
+ const binaryName = `jspackr-${platform}-${arch}${extension}`;
36
+ const binary = path.join(__dirname, "bin", binaryName);
37
+
38
+ if (!fs.existsSync(binary)) {
39
+ console.error(`jspackr: bundled binary is missing: ${binary}`);
40
+ console.error("Reinstall the package or install jspackr manually with Go:");
41
+ console.error("go install github.com/kalokaradia/jspackr/src/main@latest");
42
+ process.exit(1);
43
+ }
44
+
45
+ if (platform !== "win32") {
46
+ try {
47
+ fs.chmodSync(binary, 0o755);
48
+ } catch (error) {
49
+ console.error(
50
+ `jspackr: cannot make bundled binary executable: ${error.message}`,
51
+ );
52
+ process.exit(1);
53
+ }
54
+ }
55
+
56
+ const result = spawnSync(binary, process.argv.slice(2), {
57
+ stdio: "inherit",
58
+ });
59
+
60
+ if (result.error) {
61
+ console.error(
62
+ `jspackr: could not start bundled binary: ${result.error.message}`,
63
+ );
64
+ process.exit(1);
65
+ }
66
+
67
+ process.exit(result.status ?? 1);
package/package.json CHANGED
@@ -1,24 +1,42 @@
1
1
  {
2
- "name": "jspackr",
3
- "version": "0.2.0",
4
- "description": "A minimal JavaScript bundler powered by esbuild",
5
- "bin": {
6
- "jspackr": "bin/jspackr"
7
- },
8
- "files": [
9
- "bin/jspackr",
10
- "README.md",
11
- "LICENSE"
12
- ],
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/kalokaradia/jspackr"
16
- },
17
- "keywords": [
18
- "bundler",
19
- "esbuild",
20
- "javascript",
21
- "cli"
22
- ],
23
- "license": "MIT"
2
+ "name": "jspackr",
3
+ "version": "0.4.0",
4
+ "description": "A fast and modern JavaScript bundler powered by esbuild",
5
+ "bin": {
6
+ "jspackr": "index.js"
7
+ },
8
+ "files": [
9
+ "bin/*",
10
+ "index.js",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/kalokaradia/jspackr.git"
17
+ },
18
+ "keywords": [
19
+ "bundler",
20
+ "esbuild",
21
+ "javascript",
22
+ "cli",
23
+ "build-tool",
24
+ "minifier"
25
+ ],
26
+ "categories": [
27
+ "Formatters"
28
+ ],
29
+ "author": "Kaloka Radia Nanda",
30
+ "license": "MIT",
31
+ "homepage": "https://github.com/kalokaradia/jspackr#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/kalokaradia/jspackr/issues"
34
+ },
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "preferGlobal": true,
39
+ "dependencies": {
40
+ "jspackr": "file:jspackr-0.4.0.tgz"
41
+ }
24
42
  }