@locker/cli 0.28.3

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/bin/lws.mjs ADDED
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { hideBin } from 'yargs/helpers';
4
+ import yargs from 'yargs/yargs';
5
+
6
+ import { SUPPORTED_BROWSERS } from '../src/constants.mjs';
7
+ import { runRepl } from '../src/repl.mjs';
8
+ import { runComponent, runEval } from '../src/runner.mjs';
9
+
10
+ function buildSharedOptions(y) {
11
+ return (
12
+ y
13
+ .option('browser', {
14
+ describe: 'Browser to use',
15
+ choices: SUPPORTED_BROWSERS,
16
+ default: 'chromium',
17
+ type: 'string',
18
+ })
19
+ .option('headed', {
20
+ describe: 'Open a visible browser window',
21
+ type: 'boolean',
22
+ default: false,
23
+ })
24
+ .option('key', {
25
+ describe: 'Sandbox key identifier',
26
+ type: 'string',
27
+ default: 'cli',
28
+ })
29
+ .option('port', {
30
+ describe: 'Server port (0 = auto-select)',
31
+ type: 'number',
32
+ default: 0,
33
+ })
34
+ // `nargs: 1` is load-bearing: with just `array: true`, yargs
35
+ // greedily consumes every following argument up to the next
36
+ // flag, including the positional `code-or-file`. Pinning each
37
+ // flag to one value per occurrence gives the user the
38
+ // "repeatable scalar" shape that argv-order injection needs.
39
+ .option('before', {
40
+ describe:
41
+ 'Inject a system-mode <script> BEFORE sandbox code (repeatable, argv-order)',
42
+ type: 'string',
43
+ array: true,
44
+ nargs: 1,
45
+ })
46
+ .option('after', {
47
+ describe:
48
+ 'Inject a system-mode <script> AFTER sandbox code (repeatable, argv-order)',
49
+ type: 'string',
50
+ array: true,
51
+ nargs: 1,
52
+ })
53
+ .option('endowments', {
54
+ describe:
55
+ 'Endowments object: path to .json/.js/.mjs/.cjs file, or inline JSON string. Exposed inside the sandbox as the 4th arg of evaluateInSandbox.',
56
+ type: 'string',
57
+ })
58
+ .option('timeout', {
59
+ describe:
60
+ 'Abort the sandbox evaluation after this many milliseconds and exit non-zero',
61
+ type: 'number',
62
+ })
63
+ // --json is the structured-output mode: a single envelope on
64
+ // stdout at exit, info()/debug() suppressed, errors carried in
65
+ // the envelope (ok:false). Consumers parse one line and get
66
+ // both result and timing.
67
+ .option('json', {
68
+ describe:
69
+ 'Emit a single JSON envelope on stdout; suppress info/debug; exit code still reflects success',
70
+ type: 'boolean',
71
+ default: false,
72
+ })
73
+ // Verbosity: --quiet suppresses info() and result() in text
74
+ // mode (errors still print to stderr). --verbose enables
75
+ // debug(). The two are mutually exclusive; the runner resolves
76
+ // precedence (--quiet wins if both are passed) but we surface
77
+ // the conflict at argv parse for clarity.
78
+ .option('quiet', {
79
+ describe: 'Suppress info/debug output; only errors print',
80
+ type: 'boolean',
81
+ default: false,
82
+ })
83
+ .option('verbose', {
84
+ describe: 'Print debug-level information to stderr',
85
+ type: 'boolean',
86
+ default: false,
87
+ })
88
+ .check((argv) => {
89
+ if (argv.quiet && argv.verbose) {
90
+ throw new Error('--quiet and --verbose are mutually exclusive; pick one');
91
+ }
92
+ return true;
93
+ })
94
+ );
95
+ }
96
+
97
+ await yargs(hideBin(process.argv))
98
+ .scriptName('lws')
99
+ .usage('$0 <command> [options]')
100
+ .command(
101
+ 'eval <code-or-file>',
102
+ 'Evaluate JavaScript inside the LWS sandbox',
103
+ (y) =>
104
+ buildSharedOptions(y)
105
+ .positional('code-or-file', {
106
+ describe: 'JavaScript string, path to a .js file, or "-" for stdin',
107
+ type: 'string',
108
+ })
109
+ .option('watch', {
110
+ describe: 'Re-evaluate when the source file changes (requires a file path)',
111
+ type: 'boolean',
112
+ default: false,
113
+ })
114
+ .check((argv) => {
115
+ // --watch streams a separator-delimited log across many
116
+ // re-runs; --json promises a single envelope at exit. The
117
+ // two output contracts are mutually exclusive, so reject at
118
+ // parse rather than silently ignoring one.
119
+ if (argv.watch === true && argv.json === true) {
120
+ throw new Error('--watch and --json are mutually exclusive; pick one');
121
+ }
122
+ return true;
123
+ }),
124
+ async (argv) => {
125
+ const exitCode = await runEval(argv);
126
+ process.exit(exitCode);
127
+ },
128
+ )
129
+ .command(
130
+ 'component <directory>',
131
+ 'Compile and render an LWC component inside the LWS sandbox',
132
+ (y) =>
133
+ buildSharedOptions(y)
134
+ .positional('directory', {
135
+ describe:
136
+ 'Path to an LWC component directory (must contain <name>.js + <name>.html)',
137
+ type: 'string',
138
+ })
139
+ .option('name', {
140
+ describe: 'Custom element tag name (default: derived from directory name)',
141
+ type: 'string',
142
+ })
143
+ .option('namespace', {
144
+ describe: 'LWC namespace',
145
+ type: 'string',
146
+ default: 'c',
147
+ })
148
+ // Explicit LWC namespace-root paths layered before the
149
+ // implicit grandparent default. Repeatable; argv-order is
150
+ // preserved (first match wins in the resolver). nargs: 1
151
+ // pins each occurrence to one value so the positional
152
+ // <directory> doesn't get consumed.
153
+ .option('lwc-modules', {
154
+ describe: 'Additional LWC namespace-root directory (repeatable, argv-order)',
155
+ type: 'string',
156
+ array: true,
157
+ nargs: 1,
158
+ })
159
+ .option('watch', {
160
+ describe: 'Re-compile and reload when files in the directory change',
161
+ type: 'boolean',
162
+ default: false,
163
+ })
164
+ .check((argv) => {
165
+ if (argv.watch === true && argv.json === true) {
166
+ throw new Error('--watch and --json are mutually exclusive; pick one');
167
+ }
168
+ return true;
169
+ }),
170
+ async (argv) => {
171
+ const exitCode = await runComponent(argv);
172
+ process.exit(exitCode);
173
+ },
174
+ )
175
+ .command(
176
+ 'repl',
177
+ 'Interactive REPL against a persistent LWS sandbox',
178
+ (y) =>
179
+ buildSharedOptions(y).check((argv) => {
180
+ // --json emits a single envelope at exit, which is
181
+ // incompatible with an interactive prompt that streams
182
+ // output line by line. Reject at argv parse so users
183
+ // don't get a silent half-broken REPL.
184
+ if (argv.json === true) {
185
+ throw new Error(
186
+ '--json is not supported in `lws repl` (interactive prompt has no terminal envelope)',
187
+ );
188
+ }
189
+ return true;
190
+ }),
191
+ async (argv) => {
192
+ const exitCode = await runRepl(argv);
193
+ process.exit(exitCode);
194
+ },
195
+ )
196
+ .demandCommand(1, 'Specify a subcommand: eval, component, repl')
197
+ .strict()
198
+ .fail((msg, err, y) => {
199
+ if (err) {
200
+ process.stderr.write(`${err.message}\n`);
201
+ } else if (msg) {
202
+ process.stderr.write(`${msg}\n\n`);
203
+ process.stderr.write(`${y.help()}\n`);
204
+ }
205
+ process.exit(1);
206
+ })
207
+ .help()
208
+ .version()
209
+ .parseAsync();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (C) 2026 salesforce.com, inc.
3
+ */
4
+ 'use strict';
5
+ /*! version: 0.28.3 */
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.mjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (C) 2026 salesforce.com, inc.
3
+ */
4
+
5
+ /*! version: 0.28.3 */