@g9tm/lynxcontrols-pilot 0.0.0-stage → 2.4.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/README.md +159 -2
- package/catalog/cards/G9PilotHost.md +16 -0
- package/catalog/cards/G9PilotMask.md +10 -0
- package/catalog/cards/G9PilotPanel.md +10 -0
- package/catalog/catalog.json +420 -0
- package/catalog/index.md +7 -0
- package/check/cli.mjs +5 -0
- package/check/index.mjs +137 -0
- package/check/index.test.mjs +180 -0
- package/config/cli.mjs +31 -0
- package/config/index.d.ts +62 -0
- package/config/index.mjs +380 -0
- package/config/index.test.mjs +406 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/anchors.d.ts +39 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.jsx +103 -0
- package/dist/bridge.d.ts +4 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.jsx +143 -0
- package/dist/busy.d.ts +4 -0
- package/dist/busy.d.ts.map +1 -0
- package/dist/busy.jsx +43 -0
- package/dist/commands.d.ts +24 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.jsx +286 -0
- package/dist/consent.d.ts +51 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.jsx +131 -0
- package/dist/explore.d.ts +36 -0
- package/dist/explore.d.ts.map +1 -0
- package/dist/explore.jsx +133 -0
- package/dist/flags.d.ts +69 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.jsx +81 -0
- package/dist/host-core.d.ts +36 -0
- package/dist/host-core.d.ts.map +1 -0
- package/dist/host-core.jsx +90 -0
- package/dist/host-sink.d.ts +43 -0
- package/dist/host-sink.d.ts.map +1 -0
- package/dist/host-sink.jsx +87 -0
- package/dist/index-marks.d.ts +33 -0
- package/dist/index-marks.d.ts.map +1 -0
- package/dist/index-marks.jsx +40 -0
- package/dist/index-observe.d.ts +17 -0
- package/dist/index-observe.d.ts.map +1 -0
- package/dist/index-observe.jsx +14 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +11 -0
- package/dist/info.d.ts +10 -0
- package/dist/info.d.ts.map +1 -0
- package/dist/info.jsx +9 -0
- package/dist/kit.d.ts +67 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.jsx +1 -0
- package/dist/layer.d.ts +4 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.jsx +10 -0
- package/dist/layers.d.ts +4 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.jsx +146 -0
- package/dist/mask.d.ts +20 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.jsx +35 -0
- package/dist/net.d.ts +17 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.jsx +60 -0
- package/dist/observe.d.ts +99 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.jsx +194 -0
- package/dist/off.d.ts +45 -0
- package/dist/off.d.ts.map +1 -0
- package/dist/off.jsx +81 -0
- package/dist/otlp.d.ts +61 -0
- package/dist/otlp.d.ts.map +1 -0
- package/dist/otlp.jsx +141 -0
- package/dist/panel.d.ts +13 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/panel.jsx +182 -0
- package/dist/session.d.ts +42 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.jsx +115 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.jsx +1 -0
- package/dist/watch.d.ts +17 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.jsx +165 -0
- package/doctor/cli.mjs +5 -0
- package/doctor/index.mjs +214 -0
- package/doctor/index.test.mjs +174 -0
- package/gradle/g9pilot.app.gradle +55 -0
- package/gradle/g9pilot.settings.gradle +27 -0
- package/ios/g9pilot.rb +47 -0
- package/package.json +66 -4
- package/rspeedy/index.d.ts +40 -0
- package/rspeedy/index.mjs +100 -0
- package/rspeedy/index.test.mjs +192 -0
package/ios/g9pilot.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @g9tm/lynxcontrols-pilot for an iOS host's Podfile: links G9AppPilot's native bridge ONLY when the build environment
|
|
2
|
+
# carries it (g9pilot.config.json, resolved by the same code as the page's bundle and the Android project).
|
|
3
|
+
#
|
|
4
|
+
# require_relative '<node_modules>/@g9tm/lynxcontrols-pilot/ios/g9pilot'
|
|
5
|
+
# pilot = G9PilotConfig.resolve(from: File.expand_path('..', __dir__)) # the environment: G9_PILOT_ENV (none → off)
|
|
6
|
+
# target 'App' do
|
|
7
|
+
# ...
|
|
8
|
+
# g9pilot_pods(pilot)
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# A build without the bridge does not see the pod (and so not G9Pilot.h): the host's `#if __has_include(<G9Pilot.h>)`
|
|
12
|
+
# twin compiles empty. `G9PilotConfig.native_json(pilot)` is the host's PilotConfig (keys under the build's ceiling, port,
|
|
13
|
+
# consent…) for a resource the host reads at start. Not yet run on a Mac (ledger N-088).
|
|
14
|
+
require 'json'
|
|
15
|
+
|
|
16
|
+
module G9PilotConfig
|
|
17
|
+
CLI = File.expand_path('../config/cli.mjs', __dir__)
|
|
18
|
+
|
|
19
|
+
# The resolved environment (a Hash: profile, modules, native {bridge, devtool}, keys, port, consent, …).
|
|
20
|
+
def self.resolve(env: ENV['G9_PILOT_ENV'], from: Dir.pwd, node: ENV['G9PILOT_NODE'] || 'node')
|
|
21
|
+
run(node, from, env, 'json')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The host's PilotConfig as JSON text (what Gradle puts in BuildConfig.G9PILOT_CONFIG).
|
|
25
|
+
def self.native_json(env: ENV['G9_PILOT_ENV'], from: Dir.pwd, node: ENV['G9PILOT_NODE'] || 'node')
|
|
26
|
+
JSON.generate(run(node, from, env, 'native'))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.run(node, from, env, format)
|
|
30
|
+
args = [node, CLI, '--from', from, '--format', format]
|
|
31
|
+
args += ['--env', env] if env && !env.empty?
|
|
32
|
+
out = IO.popen(args, err: %i[child out], &:read)
|
|
33
|
+
raise "g9pilot: #{out.strip}" unless $?.success?
|
|
34
|
+
JSON.parse(out)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Inside a target: the bridge's pod when the environment carries it (from the package next to this one), and with the
|
|
39
|
+
# `devtool` module Lynx DevTool (its version: `lynx:`, default 4.2.0) — the twin of g9pilot.app.gradle. DevTool's server
|
|
40
|
+
# stays shut until a signed devtool.attach (G9PilotDev.m).
|
|
41
|
+
def g9pilot_pods(resolved, lynx: '4.2.0')
|
|
42
|
+
return unless resolved.dig('native', 'bridge')
|
|
43
|
+
pod 'g9tm-app-pilot-lynx', :path => File.expand_path('../../app-pilot-lynx/ios', __dir__)
|
|
44
|
+
return unless resolved.dig('native', 'devtool')
|
|
45
|
+
pod 'LynxDevtool', lynx, :subspecs => ['Framework']
|
|
46
|
+
pod 'LynxService', lynx, :subspecs => ['Devtool']
|
|
47
|
+
end
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g9tm/lynxcontrols-pilot",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.4.1",
|
|
4
|
+
"description": "G9AppPilot for G9LynxControls apps, by build profile (off, marks, observe, support, full): signed remote control and the always-awake watch, every part optional and absent from a build that does not ask for it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"g9pilot": {
|
|
11
|
+
"source": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.jsx"
|
|
14
|
+
},
|
|
15
|
+
"g9pilot-observe": {
|
|
16
|
+
"source": "./src/index-observe.ts",
|
|
17
|
+
"types": "./dist/index-observe.d.ts",
|
|
18
|
+
"default": "./dist/index-observe.jsx"
|
|
19
|
+
},
|
|
20
|
+
"g9pilot-marks": {
|
|
21
|
+
"source": "./src/index-marks.ts",
|
|
22
|
+
"types": "./dist/index-marks.d.ts",
|
|
23
|
+
"default": "./dist/index-marks.jsx"
|
|
24
|
+
},
|
|
25
|
+
"source": "./src/off.tsx",
|
|
26
|
+
"types": "./dist/off.d.ts",
|
|
27
|
+
"default": "./dist/off.jsx"
|
|
28
|
+
},
|
|
29
|
+
"./rspeedy": {
|
|
30
|
+
"types": "./rspeedy/index.d.ts",
|
|
31
|
+
"default": "./rspeedy/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./config": {
|
|
34
|
+
"types": "./config/index.d.ts",
|
|
35
|
+
"default": "./config/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
"./catalog": "./catalog/catalog.json"
|
|
39
|
+
},
|
|
40
|
+
"bin": {
|
|
41
|
+
"g9pilot-check": "./check/cli.mjs",
|
|
42
|
+
"g9pilot-doctor": "./doctor/cli.mjs"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"rspeedy",
|
|
47
|
+
"config",
|
|
48
|
+
"check",
|
|
49
|
+
"doctor",
|
|
50
|
+
"gradle",
|
|
51
|
+
"ios",
|
|
52
|
+
"README.md",
|
|
53
|
+
"catalog"
|
|
54
|
+
],
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "rslib build"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@g9tm/app-pilot": "0.2.0",
|
|
60
|
+
"@g9tm/app-pilot-devtool": "0.2.0",
|
|
61
|
+
"@g9tm/app-pilot-lynx": "0.2.0",
|
|
62
|
+
"@g9tm/lynxcontrols-foundation": "2.4.1"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@g9tm/lynxcontrols": "2.4.1",
|
|
66
|
+
"@lynx-js/react": ">=0.129.3 <0.130.0"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Options of {@link pluginG9Pilot}. */
|
|
2
|
+
export interface PluginG9PilotOptions {
|
|
3
|
+
/** The build environment of g9pilot.config.json (default: the G9_PILOT_ENV variable; none → profile `off`). */
|
|
4
|
+
readonly environment?: string;
|
|
5
|
+
/** Where to look for g9pilot.config.json (default: the project root, then upward). */
|
|
6
|
+
readonly from?: string;
|
|
7
|
+
/** A module that replaces the bridge's native calls (`./native.ts` of @g9tm/app-pilot-lynx), relative to the root. */
|
|
8
|
+
readonly nativeTransport?: string;
|
|
9
|
+
/** false: no pilot-receipt.json beside the bundle. */
|
|
10
|
+
readonly receipt?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** What a build carries (pilot-receipt.json). */
|
|
14
|
+
export interface G9PilotReceipt {
|
|
15
|
+
readonly package: '@g9tm/lynxcontrols-pilot';
|
|
16
|
+
/** Which entry the bundle resolved: g9pilot (bridge), g9pilot-observe, g9pilot-marks or off. */
|
|
17
|
+
readonly entry: 'g9pilot' | 'g9pilot-observe' | 'g9pilot-marks' | 'off';
|
|
18
|
+
readonly environment: string | null;
|
|
19
|
+
readonly profile: 'off' | 'marks' | 'observe' | 'support' | 'full';
|
|
20
|
+
readonly distribution: 'store' | 'test';
|
|
21
|
+
readonly modules: readonly string[];
|
|
22
|
+
readonly native: { readonly bridge: boolean; readonly devtool: boolean };
|
|
23
|
+
readonly maxScopes: readonly string[];
|
|
24
|
+
readonly config: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The rspeedy / Rsbuild plugin: decides how much of G9AppPilot the bundle carries (see the package README). */
|
|
28
|
+
export declare function pluginG9Pilot(options?: PluginG9PilotOptions): {
|
|
29
|
+
name: string;
|
|
30
|
+
setup(api: unknown): void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The export condition a resolved configuration opens (null: nothing, the empty entry). */
|
|
34
|
+
export declare function conditionOf(resolved: unknown): 'g9pilot' | 'g9pilot-observe' | 'g9pilot-marks' | null;
|
|
35
|
+
|
|
36
|
+
/** The source entry of @g9tm/lynxcontrols-pilot behind a condition (null: the empty entry). */
|
|
37
|
+
export declare function sourceEntry(condition: string | null): string;
|
|
38
|
+
|
|
39
|
+
/** The receipt of a resolved configuration. */
|
|
40
|
+
export declare function receiptOf(resolved: unknown, file: string | null): G9PilotReceipt;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @g9tm/lynxcontrols-pilot/rspeedy: the build plugin that decides how much of G9AppPilot a bundle carries.
|
|
2
|
+
//
|
|
3
|
+
// plugins: [pluginReactLynx(), pluginG9Lynx(), pluginG9Pilot()] // the environment: G9_PILOT_ENV (or `environment`)
|
|
4
|
+
//
|
|
5
|
+
// It resolves `g9pilot.config.json` (config/index.mjs) and
|
|
6
|
+
// · defines the profile's flat constants (`__G9_PILOT_BRIDGE__`, …) so the minifier drops every part that is off;
|
|
7
|
+
// · opens the `g9pilot` export condition only when the profile is not `off` — without it, `@g9tm/lynxcontrols-pilot`
|
|
8
|
+
// resolves to its empty twin (src/off.ts), so a bundle built without the plugin, or with `off`, holds no G9AppPilot
|
|
9
|
+
// code even if the app imports it unguarded;
|
|
10
|
+
// · in a workspace that aliases packages to their sources (the `source` condition), points that alias at the real
|
|
11
|
+
// entry too;
|
|
12
|
+
// · `nativeTransport`: replaces the bridge's `./native.ts` with the app's own (a host that measures the bridge's calls);
|
|
13
|
+
// · writes `pilot-receipt.json` beside the bundle: what this build carries, read by `g9pilot-check`.
|
|
14
|
+
// Plain Node ESM: it runs in the build, never in the Lynx bundle.
|
|
15
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { loadPilotConfig, MODULES, pilotDefines } from '../config/index.mjs';
|
|
19
|
+
|
|
20
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const PACKAGE = '@g9tm/lynxcontrols-pilot';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The export condition a resolved configuration opens: `g9pilot` (the bridge entry), `g9pilot-observe` (the watch, no
|
|
25
|
+
* transport), `g9pilot-marks` (test ids only), or null for nothing (./off.ts).
|
|
26
|
+
*/
|
|
27
|
+
export function conditionOf(resolved) {
|
|
28
|
+
const m = resolved.modules;
|
|
29
|
+
if (m.bridge) return 'g9pilot';
|
|
30
|
+
if (m.oracles || m.vitals || m.blackbox || m.screen) return 'g9pilot-observe';
|
|
31
|
+
if (m.marks) return 'g9pilot-marks';
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The source entry of this package behind `condition` (the workspace alias case), from its own exports map. */
|
|
36
|
+
export function sourceEntry(condition) {
|
|
37
|
+
const manifest = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'));
|
|
38
|
+
const dot = manifest.exports['.'];
|
|
39
|
+
return join(here, '..', condition ? dot[condition].source : dot.source);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What a build carries, written beside the bundle and checked on the artifact. */
|
|
43
|
+
export function receiptOf(resolved, file) {
|
|
44
|
+
return {
|
|
45
|
+
package: PACKAGE,
|
|
46
|
+
entry: conditionOf(resolved) ?? 'off',
|
|
47
|
+
environment: resolved.environment,
|
|
48
|
+
profile: resolved.profile,
|
|
49
|
+
distribution: resolved.distribution,
|
|
50
|
+
modules: MODULES.filter((m) => resolved.modules[m]),
|
|
51
|
+
native: resolved.native,
|
|
52
|
+
maxScopes: resolved.maxScopes,
|
|
53
|
+
config: file,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The plugin. Options: `environment` (else G9_PILOT_ENV), `from` (where to look for g9pilot.config.json; the project
|
|
59
|
+
* root), `nativeTransport` (a module that replaces the bridge's native calls), `receipt` (false: no pilot-receipt.json).
|
|
60
|
+
*/
|
|
61
|
+
export function pluginG9Pilot(options = {}) {
|
|
62
|
+
return {
|
|
63
|
+
name: 'g9:pilot',
|
|
64
|
+
setup(api) {
|
|
65
|
+
const root = options.from ?? api.context?.rootPath ?? process.cwd();
|
|
66
|
+
const { file, resolved } = loadPilotConfig({ from: root, environment: options.environment });
|
|
67
|
+
const condition = conditionOf(resolved);
|
|
68
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
69
|
+
const alias = config.resolve?.alias;
|
|
70
|
+
const next = { source: { define: pilotDefines(resolved) } };
|
|
71
|
+
if (condition && alias && typeof alias === 'object' && `${PACKAGE}$` in alias) {
|
|
72
|
+
next.resolve = { alias: { [`${PACKAGE}$`]: sourceEntry(condition) } };
|
|
73
|
+
}
|
|
74
|
+
return mergeRsbuildConfig(config, next);
|
|
75
|
+
});
|
|
76
|
+
api.modifyBundlerChain?.((chain, { bundler }) => {
|
|
77
|
+
if (condition) {
|
|
78
|
+
const names = chain.resolve.conditionNames.values();
|
|
79
|
+
chain.resolve.conditionNames.clear().merge([condition, ...(names.length ? names : ['...'])]);
|
|
80
|
+
}
|
|
81
|
+
if (condition === 'g9pilot' && options.nativeTransport) {
|
|
82
|
+
const target = resolve(root, options.nativeTransport);
|
|
83
|
+
chain.plugin('g9-pilot-native-transport').use(bundler.NormalModuleReplacementPlugin, [
|
|
84
|
+
/[\\/]native\.ts$/,
|
|
85
|
+
(resource) => {
|
|
86
|
+
if (/app-pilot-lynx|pilot[\\/]packages[\\/]lynx/.test(resource.context ?? '')) resource.request = target;
|
|
87
|
+
},
|
|
88
|
+
]);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (options.receipt !== false) {
|
|
92
|
+
api.onAfterBuild?.(() => {
|
|
93
|
+
const out = api.context?.distPath ?? join(root, 'dist');
|
|
94
|
+
mkdirSync(out, { recursive: true });
|
|
95
|
+
writeFileSync(join(out, 'pilot-receipt.json'), `${JSON.stringify(receiptOf(resolved, file), null, 2)}\n`);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { resolvePilotConfig } from '../config/index.mjs';
|
|
7
|
+
import { conditionOf, pluginG9Pilot, receiptOf, sourceEntry } from './index.mjs';
|
|
8
|
+
|
|
9
|
+
const KEY = { kid: 'qa', publicKey: 'MFkw-public', scopes: ['*'] };
|
|
10
|
+
const CONFIG = {
|
|
11
|
+
keys: [KEY],
|
|
12
|
+
environments: {
|
|
13
|
+
store: { profile: 'off', distribution: 'store' },
|
|
14
|
+
marks: { profile: 'marks' },
|
|
15
|
+
observe: { profile: 'observe' },
|
|
16
|
+
qa: { profile: 'full' },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** A fake Rsbuild api: records what the plugin asks for. */
|
|
21
|
+
function fakeApi(root, alias) {
|
|
22
|
+
const calls = { config: null, chain: null, afterBuild: null, replacement: null };
|
|
23
|
+
const conditions = [];
|
|
24
|
+
const api = {
|
|
25
|
+
context: { rootPath: root, distPath: join(root, 'dist') },
|
|
26
|
+
modifyRsbuildConfig(fn) {
|
|
27
|
+
calls.config = fn(
|
|
28
|
+
{ resolve: alias ? { alias } : {} },
|
|
29
|
+
{ mergeRsbuildConfig: (a, b) => ({ ...a, ...b, merged: b }) },
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
modifyBundlerChain(fn) {
|
|
33
|
+
const chain = {
|
|
34
|
+
resolve: {
|
|
35
|
+
conditionNames: {
|
|
36
|
+
values: () => conditions.slice(),
|
|
37
|
+
clear() {
|
|
38
|
+
conditions.length = 0;
|
|
39
|
+
return this;
|
|
40
|
+
},
|
|
41
|
+
merge(list) {
|
|
42
|
+
conditions.push(...list);
|
|
43
|
+
return this;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
plugin: (name) => ({
|
|
48
|
+
use(Plugin, args) {
|
|
49
|
+
calls.replacement = { name, Plugin, args };
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
fn(chain, { bundler: { NormalModuleReplacementPlugin: class {} } });
|
|
54
|
+
calls.chain = conditions.slice();
|
|
55
|
+
},
|
|
56
|
+
onAfterBuild(fn) {
|
|
57
|
+
calls.afterBuild = fn;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
return { api, calls };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function withApp(run) {
|
|
64
|
+
const dir = mkdtempSync(join(tmpdir(), 'g9pilot-plugin-'));
|
|
65
|
+
try {
|
|
66
|
+
writeFileSync(join(dir, 'g9pilot.config.json'), JSON.stringify(CONFIG));
|
|
67
|
+
return run(dir);
|
|
68
|
+
} finally {
|
|
69
|
+
rmSync(dir, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
test('each profile opens its own export condition, and off opens none', () => {
|
|
74
|
+
const r = (env) => resolvePilotConfig(CONFIG, env);
|
|
75
|
+
assert.equal(conditionOf(r(null)), null);
|
|
76
|
+
assert.equal(conditionOf(r('store')), null);
|
|
77
|
+
assert.equal(conditionOf(r('marks')), 'g9pilot-marks');
|
|
78
|
+
assert.equal(conditionOf(r('observe')), 'g9pilot-observe');
|
|
79
|
+
assert.equal(conditionOf(r('qa')), 'g9pilot');
|
|
80
|
+
// the package's own exports map has an entry behind every condition the plugin opens
|
|
81
|
+
for (const c of ['g9pilot', 'g9pilot-observe', 'g9pilot-marks', null])
|
|
82
|
+
assert.ok(existsSync(sourceEntry(c)), String(c));
|
|
83
|
+
assert.match(sourceEntry(null), /off\.tsx$/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('the plugin: defines, the condition first, the workspace alias, the receipt', () =>
|
|
87
|
+
withApp((dir) => {
|
|
88
|
+
const { api, calls } = fakeApi(dir, { '@g9tm/lynxcontrols-pilot$': '/ws/off.ts', other$: 'x' });
|
|
89
|
+
pluginG9Pilot({ environment: 'qa' }).setup(api);
|
|
90
|
+
assert.equal(calls.config.merged.source.define.__G9_PILOT_BRIDGE__, 'true');
|
|
91
|
+
assert.match(calls.config.merged.resolve.alias['@g9tm/lynxcontrols-pilot$'], /index\.ts$/);
|
|
92
|
+
assert.deepEqual(calls.chain, ['g9pilot', '...']);
|
|
93
|
+
calls.afterBuild();
|
|
94
|
+
const receipt = JSON.parse(readFileSync(join(dir, 'dist', 'pilot-receipt.json'), 'utf8'));
|
|
95
|
+
assert.equal(receipt.profile, 'full');
|
|
96
|
+
assert.equal(receipt.entry, 'g9pilot');
|
|
97
|
+
assert.ok(receipt.modules.includes('devtool'));
|
|
98
|
+
assert.equal(receipt.native.bridge, true);
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
test('off: the defines say false, no condition, the alias stays on the empty entry', () =>
|
|
102
|
+
withApp((dir) => {
|
|
103
|
+
const { api, calls } = fakeApi(dir, { '@g9tm/lynxcontrols-pilot$': '/ws/off.ts' });
|
|
104
|
+
pluginG9Pilot({ environment: 'store' }).setup(api);
|
|
105
|
+
assert.equal(calls.config.merged.source.define.__G9_PILOT_MARKS__, 'false');
|
|
106
|
+
assert.equal(calls.config.merged.resolve, undefined);
|
|
107
|
+
assert.deepEqual(calls.chain, []);
|
|
108
|
+
assert.equal(calls.replacement, null);
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
test('marks: its condition before the bundler’s own', () =>
|
|
112
|
+
withApp((dir) => {
|
|
113
|
+
const { api, calls } = fakeApi(dir);
|
|
114
|
+
// a chain that already names conditions keeps them after ours
|
|
115
|
+
api.modifyBundlerChain = ((orig) => (fn) => {
|
|
116
|
+
const list = ['import', 'default'];
|
|
117
|
+
fn(
|
|
118
|
+
{
|
|
119
|
+
resolve: {
|
|
120
|
+
conditionNames: {
|
|
121
|
+
values: () => list.slice(),
|
|
122
|
+
clear() {
|
|
123
|
+
list.length = 0;
|
|
124
|
+
return this;
|
|
125
|
+
},
|
|
126
|
+
merge(l) {
|
|
127
|
+
list.push(...l);
|
|
128
|
+
return this;
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
plugin: () => ({ use() {} }),
|
|
133
|
+
},
|
|
134
|
+
{ bundler: {} },
|
|
135
|
+
);
|
|
136
|
+
calls.chain = list;
|
|
137
|
+
return orig;
|
|
138
|
+
})(api.modifyBundlerChain);
|
|
139
|
+
pluginG9Pilot({ environment: 'marks', receipt: false }).setup(api);
|
|
140
|
+
assert.deepEqual(calls.chain, ['g9pilot-marks', 'import', 'default']);
|
|
141
|
+
assert.equal(calls.afterBuild, null);
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
test('nativeTransport replaces only the bridge’s own native.ts, only in a bridge build', () =>
|
|
145
|
+
withApp((dir) => {
|
|
146
|
+
const { api, calls } = fakeApi(dir);
|
|
147
|
+
pluginG9Pilot({ environment: 'qa', nativeTransport: 'src/qa/native.ts' }).setup(api);
|
|
148
|
+
assert.equal(calls.replacement.name, 'g9-pilot-native-transport');
|
|
149
|
+
const [pattern, swap] = calls.replacement.args;
|
|
150
|
+
const lib = { context: join('node_modules', '@g9tm', 'app-pilot-lynx', 'src'), request: './native.ts' };
|
|
151
|
+
assert.ok(pattern.test(String(lib.request)) || pattern.test('/x/native.ts'));
|
|
152
|
+
swap(lib);
|
|
153
|
+
assert.equal(lib.request, join(dir, 'src', 'qa', 'native.ts'));
|
|
154
|
+
const own = { context: join(dir, 'src'), request: './native.ts' };
|
|
155
|
+
swap(own);
|
|
156
|
+
assert.equal(own.request, './native.ts', 'the app’s own native.ts is left alone');
|
|
157
|
+
const off = fakeApi(dir);
|
|
158
|
+
pluginG9Pilot({ environment: 'observe', nativeTransport: 'src/qa/native.ts' }).setup(off.api);
|
|
159
|
+
assert.equal(off.calls.replacement, null);
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
test('the environment comes from G9_PILOT_ENV when the option is absent; a bad one fails the build', () =>
|
|
163
|
+
withApp((dir) => {
|
|
164
|
+
const before = process.env.G9_PILOT_ENV;
|
|
165
|
+
try {
|
|
166
|
+
process.env.G9_PILOT_ENV = 'observe';
|
|
167
|
+
const { api, calls } = fakeApi(dir);
|
|
168
|
+
pluginG9Pilot().setup(api);
|
|
169
|
+
assert.equal(calls.config.merged.source.define.__G9_PILOT_ORACLES__, 'true');
|
|
170
|
+
process.env.G9_PILOT_ENV = 'nope';
|
|
171
|
+
assert.throws(() => pluginG9Pilot().setup(fakeApi(dir).api), /no environment "nope"/);
|
|
172
|
+
} finally {
|
|
173
|
+
if (before === undefined) delete process.env.G9_PILOT_ENV;
|
|
174
|
+
else process.env.G9_PILOT_ENV = before;
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
|
|
178
|
+
test('receiptOf: the shape g9pilot-check reads', () => {
|
|
179
|
+
const r = receiptOf(resolvePilotConfig(CONFIG, 'observe'), '/app/g9pilot.config.json');
|
|
180
|
+
assert.deepEqual(Object.keys(r), [
|
|
181
|
+
'package',
|
|
182
|
+
'entry',
|
|
183
|
+
'environment',
|
|
184
|
+
'profile',
|
|
185
|
+
'distribution',
|
|
186
|
+
'modules',
|
|
187
|
+
'native',
|
|
188
|
+
'maxScopes',
|
|
189
|
+
'config',
|
|
190
|
+
]);
|
|
191
|
+
assert.equal(r.entry, 'g9pilot-observe');
|
|
192
|
+
});
|