@locker/cli 0.28.3 → 0.28.5
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/README.md +195 -0
- package/bin/lws.mjs +185 -30
- package/dist/index.cjs.js +1 -1
- package/dist/index.mjs.js +1 -1
- package/dist/lws-sandbox.js +149 -46
- package/dist/purify.js +2 -2
- package/package.json +7 -5
- package/src/compile-lwc.mjs +37 -0
- package/src/config-resolver.mjs +269 -0
- package/src/constants.mjs +18 -0
- package/src/gates.mjs +132 -0
- package/src/output.mjs +19 -0
- package/src/playwright-check.mjs +65 -0
- package/src/repl.mjs +15 -0
- package/src/runner.mjs +68 -0
- package/src/sandbox-entry.ts +25 -0
- package/src/wire-mock.mjs +733 -0
package/src/runner.mjs
CHANGED
|
@@ -14,12 +14,14 @@ import {
|
|
|
14
14
|
throwCompletion,
|
|
15
15
|
} from './completion.mjs';
|
|
16
16
|
import { buildEndowmentsRegisterScript, loadEndowments } from './endowments.mjs';
|
|
17
|
+
import { buildGateInitScript, resolveGates, toShortGateNames } from './gates.mjs';
|
|
17
18
|
import { resolveInput } from './input-resolver.mjs';
|
|
18
19
|
import { Output } from './output.mjs';
|
|
19
20
|
import { Server } from './server.mjs';
|
|
20
21
|
import { transform } from './transform.mjs';
|
|
21
22
|
import { awaitAndEmitUpgradeNotice, startVersionCheckForCLI } from './version-check.mjs';
|
|
22
23
|
import { assertWatchableEvalOrigin, rerunBanner, watchPaths } from './watcher.mjs';
|
|
24
|
+
import { loadWireMockOverrides } from './wire-mock.mjs';
|
|
23
25
|
|
|
24
26
|
const require = createRequire(import.meta.url);
|
|
25
27
|
// `private: true` in package.json is the pre-publish signal that skips
|
|
@@ -94,6 +96,29 @@ async function resolveCompletion(browser, output) {
|
|
|
94
96
|
return exitCodeFor(completion);
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
// Queue the feature-gate init script on the browser BEFORE it navigates to
|
|
100
|
+
// a harness page. The script publishes the resolved gate list (karma
|
|
101
|
+
// defaults + --gates-on, minus --gates-off) on the window slot that
|
|
102
|
+
// sandbox-entry.ts reads at IIFE init, so the gater Set is settled before
|
|
103
|
+
// the first evaluateInSandbox builds a SandboxRecord. addInitScript (not
|
|
104
|
+
// addScriptTag) is mandatory: it runs before every page script, including
|
|
105
|
+
// component.html's `<script src="/_bundle/component.js">`, whose
|
|
106
|
+
// evaluateInSandbox call would otherwise freeze the gate reads before any
|
|
107
|
+
// appended <script> could register them. Also records the resolved set on
|
|
108
|
+
// `output` two ways: the --verbose `gates:` stderr line and the additive
|
|
109
|
+
// `gates` field of the --json envelope, both in the short-name form
|
|
110
|
+
// engineers use (`changesSince.264`, not the fully-qualified internal
|
|
111
|
+
// name). Returns the resolved (fully-qualified) list. MUST be called
|
|
112
|
+
// before browser.goto.
|
|
113
|
+
async function injectGates(browser, argv, output) {
|
|
114
|
+
const gates = resolveGates({ on: argv.gatesOn, off: argv.gatesOff });
|
|
115
|
+
await browser.addInitScript({ content: buildGateInitScript(gates) });
|
|
116
|
+
const shortNames = toShortGateNames(gates);
|
|
117
|
+
output.setGates(shortNames);
|
|
118
|
+
output.debug(`gates: ${shortNames.join(', ') || '(none)'}`);
|
|
119
|
+
return gates;
|
|
120
|
+
}
|
|
121
|
+
|
|
97
122
|
export async function runEval(argv) {
|
|
98
123
|
// Watch mode owns a persistent browser/server lifecycle (launch once,
|
|
99
124
|
// re-evaluate on change), which is the inverse of the one-shot path's
|
|
@@ -151,6 +176,10 @@ export async function runEval(argv) {
|
|
|
151
176
|
await browser.launch();
|
|
152
177
|
output.timing.end('browser-launch');
|
|
153
178
|
|
|
179
|
+
// Gate init runs before navigation so sandbox-entry.ts registers
|
|
180
|
+
// the resolved gates at IIFE init, before any evaluateInSandbox.
|
|
181
|
+
await injectGates(browser, argv, output);
|
|
182
|
+
|
|
154
183
|
await browser.goto(`${server.origin}${EVAL_HARNESS_PATH}`, { waitUntil: 'load' });
|
|
155
184
|
// The harness already loaded purify.js + lws-sandbox.js (assigning
|
|
156
185
|
// window.evaluateInSandbox). Verify before injecting user code.
|
|
@@ -332,6 +361,7 @@ export async function runComponent(argv) {
|
|
|
332
361
|
const directory = path.resolve(process.cwd(), argv.directory);
|
|
333
362
|
|
|
334
363
|
output.timing.start('compile');
|
|
364
|
+
const wireMockOverrides = await loadWireMockOverrides(argv['wire-fixtures']);
|
|
335
365
|
const compiled = await compileComponent({
|
|
336
366
|
directory,
|
|
337
367
|
name: argv.name,
|
|
@@ -340,6 +370,17 @@ export async function runComponent(argv) {
|
|
|
340
370
|
// yargs gives us the array on argv['lwc-modules'] when --lwc-modules
|
|
341
371
|
// is passed at least once; default to [] when absent.
|
|
342
372
|
lwcModules: argv['lwc-modules'] ?? [],
|
|
373
|
+
// Wire auto-mocking (D16). argv.wireMode is undefined (off),
|
|
374
|
+
// 'success', or 'error'. Each mocked adapter emits a
|
|
375
|
+
// `[wire mock] ...` marker to stderr so the run is unmistakably
|
|
376
|
+
// flagged as using fabricated data.
|
|
377
|
+
wireMode: argv.wireMode,
|
|
378
|
+
wireMockOverrides,
|
|
379
|
+
// info(), not debug(): a wire mock means the render used
|
|
380
|
+
// fabricated data and is NOT a true production render, so the
|
|
381
|
+
// marker must be visible by default (suppressed only under
|
|
382
|
+
// --quiet / --json, which opt out of all info by contract).
|
|
383
|
+
onWireMock: (line) => output.info(line),
|
|
343
384
|
});
|
|
344
385
|
output.timing.end('compile');
|
|
345
386
|
tmpDir = compiled.tmpDir;
|
|
@@ -362,6 +403,13 @@ export async function runComponent(argv) {
|
|
|
362
403
|
await browser.launch();
|
|
363
404
|
output.timing.end('browser-launch');
|
|
364
405
|
|
|
406
|
+
// Gate init, like endowments below, must be queued via
|
|
407
|
+
// addInitScript before goto: the component bundle's
|
|
408
|
+
// evaluateInSandbox runs synchronously during navigation, so the
|
|
409
|
+
// gater Set has to be settled before then. Gates are queued first
|
|
410
|
+
// so the slot exists when sandbox-entry.ts reads it at IIFE init.
|
|
411
|
+
await injectGates(browser, argv, output);
|
|
412
|
+
|
|
365
413
|
// Endowments registration must happen BEFORE `browser.goto`
|
|
366
414
|
// because the harness page loads the component bundle via
|
|
367
415
|
// `<script src="/_bundle/component.js">` synchronously during
|
|
@@ -543,6 +591,11 @@ async function runEvalWatch(argv) {
|
|
|
543
591
|
});
|
|
544
592
|
await browser.launch();
|
|
545
593
|
|
|
594
|
+
// Gate init is queued ONCE here: addInitScript persists across
|
|
595
|
+
// navigations, and the resolved gate set is fixed for the session,
|
|
596
|
+
// so it applies to every cycle's fresh `goto` below.
|
|
597
|
+
await injectGates(browser, argv, output);
|
|
598
|
+
|
|
546
599
|
// One re-evaluation cycle: re-read the file (it may have changed),
|
|
547
600
|
// re-transform, navigate to a fresh harness page, replay
|
|
548
601
|
// endowments/before, inject the transformed bundle, run after. A fresh
|
|
@@ -671,6 +724,12 @@ async function runComponentWatch(argv) {
|
|
|
671
724
|
});
|
|
672
725
|
await browser.launch();
|
|
673
726
|
|
|
727
|
+
// Gate init is queued ONCE here, before the endowments script and the
|
|
728
|
+
// first goto: addInitScript persists across reloads and the resolved
|
|
729
|
+
// gate set is fixed for the session, so it applies to every re-compile
|
|
730
|
+
// cycle's navigation below.
|
|
731
|
+
await injectGates(browser, argv, output);
|
|
732
|
+
|
|
674
733
|
// Endowments register via addInitScript, which applies to every
|
|
675
734
|
// subsequent navigation, so register once before the first goto rather
|
|
676
735
|
// than on each re-run. Component-directory changes (the watch target)
|
|
@@ -683,6 +742,12 @@ async function runComponentWatch(argv) {
|
|
|
683
742
|
});
|
|
684
743
|
}
|
|
685
744
|
|
|
745
|
+
// Wire-mock overrides (D16) are loaded once, like endowments: the
|
|
746
|
+
// override JSON files are not the watch target (the component
|
|
747
|
+
// directory is), so a one-time load matches the watch scope. Each
|
|
748
|
+
// re-compile reuses the same override Map.
|
|
749
|
+
const wireMockOverrides = await loadWireMockOverrides(argv['wire-fixtures']);
|
|
750
|
+
|
|
686
751
|
const runOnce = async () => {
|
|
687
752
|
const compiled = await compileComponent({
|
|
688
753
|
directory,
|
|
@@ -690,6 +755,9 @@ async function runComponentWatch(argv) {
|
|
|
690
755
|
namespace: argv.namespace,
|
|
691
756
|
sandboxKey: argv.key,
|
|
692
757
|
lwcModules: argv['lwc-modules'] ?? [],
|
|
758
|
+
wireMode: argv.wireMode,
|
|
759
|
+
wireMockOverrides,
|
|
760
|
+
onWireMock: (line) => output.info(line),
|
|
693
761
|
});
|
|
694
762
|
output.result(compiled.code);
|
|
695
763
|
output.debug(`compiled component → ${compiled.bundleFile} (tag: ${compiled.tag})`);
|
package/src/sandbox-entry.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { evaluateInSandbox } from '@locker/sandbox';
|
|
2
|
+
import { registerGaterEnabledFeatures } from '@locker/shared';
|
|
2
3
|
|
|
3
4
|
// Expose evaluateInSandbox on the window global so the browser harness page
|
|
4
5
|
// (eval.html / component.html) can invoke it against source delivered by the
|
|
5
6
|
// CLI's local server. This is the minimal, non-Aura entry point for the LWS
|
|
6
7
|
// sandbox IIFE consumed by @locker/cli.
|
|
7
8
|
(window as any).evaluateInSandbox = evaluateInSandbox;
|
|
9
|
+
|
|
10
|
+
// Feature-gate registration for a run. The runner resolves the effective
|
|
11
|
+
// gate list on the Node side (gates.mjs: the @locker/shared baseline
|
|
12
|
+
// LWS_DEFAULT_GATER_FEATURES, plus --gates-on, minus --gates-off) and
|
|
13
|
+
// publishes it on this window slot via addInitScript BEFORE the page
|
|
14
|
+
// navigates. Reading and registering it
|
|
15
|
+
// HERE, at IIFE init, is what makes the gates honored: this entry shares
|
|
16
|
+
// the bundled @locker/shared module graph with @locker/sandbox, so
|
|
17
|
+
// registerGaterEnabledFeatures writes into the very same gater Set that
|
|
18
|
+
// the sandbox's internal isGaterEnabledFeature reads. Because the slot is
|
|
19
|
+
// set before navigation and this code runs before any evaluateInSandbox
|
|
20
|
+
// call, the Set is settled before the first SandboxRecord (which freezes
|
|
21
|
+
// the gate reads for a key) is built.
|
|
22
|
+
//
|
|
23
|
+
// The slot name string is the wire contract with gates.mjs GATES_WINDOW_SLOT;
|
|
24
|
+
// the two live in different bundles (this IIFE vs. the Node runner) and
|
|
25
|
+
// cannot import a shared constant, so the literal is duplicated by design.
|
|
26
|
+
// Bracket (string-key) access, not dot access: the slot name is a wire-
|
|
27
|
+
// protocol key, and the bracket form keeps it out of no-underscore-dangle's
|
|
28
|
+
// identifier check, matching how the sibling endowments slot is referenced.
|
|
29
|
+
const gates = (window as any)['__lwsCLIGates'];
|
|
30
|
+
if (Array.isArray(gates)) {
|
|
31
|
+
registerGaterEnabledFeatures(gates);
|
|
32
|
+
}
|