@dsh-workbench/shared 1.5.2-alpha.2 → 1.5.2-alpha.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.
@@ -15,7 +15,7 @@ export type AdapterSetLoad = {
15
15
  readonly detail: string;
16
16
  readonly cause?: unknown;
17
17
  };
18
- export declare const CORE_METHODS: readonly [readonly ["data", "read"], readonly ["data", "request"], readonly ["data", "requestMany"], readonly ["data", "submit"], readonly ["data", "plan"], readonly ["data", "submitPlan"], readonly ["supply", "resolvePluginSource"], readonly ["supply", "libInstallCommand"], readonly ["supply", "libUninstallCommand"], readonly ["supply", "pluginInstallPlan"], readonly ["supply", "recoveryCommand"], readonly ["supply", "latestVersion"], readonly ["supply", "missingReleaseParts"], readonly ["supply", "probeRelease"], readonly ["supply", "splitNpmSpec"], readonly ["profile", "dirOf"], readonly ["profile", "dshPlugins"], readonly ["profile", "selfUpdateView"], readonly ["probe", "probeUnits"], readonly ["probe", "registerPreflight"], readonly ["probe", "declaredPluginCommands"]];
18
+ export declare const CORE_METHODS: readonly [readonly ["data", "read"], readonly ["data", "request"], readonly ["data", "requestMany"], readonly ["data", "submit"], readonly ["data", "plan"], readonly ["data", "submitPlan"], readonly ["supply", "resolvePluginSource"], readonly ["supply", "libInstallCommand"], readonly ["supply", "libUninstallCommand"], readonly ["supply", "pluginInstallPlan"], readonly ["supply", "recoveryCommand"], readonly ["supply", "latestVersion"], readonly ["supply", "missingReleaseParts"], readonly ["supply", "probeRelease"], readonly ["supply", "versionManifestOf"], readonly ["supply", "splitNpmSpec"], readonly ["profile", "dirOf"], readonly ["profile", "dshPlugins"], readonly ["profile", "selfUpdateView"], readonly ["probe", "probeUnits"], readonly ["probe", "registerPreflight"], readonly ["probe", "declaredPluginCommands"]];
19
19
  export declare function validateAdapterSet(value: unknown, spec: string): AdapterSetLoad;
20
20
  export declare function loadAdapterSet(ctx: DshHostContext, spec: string | undefined): Promise<AdapterSetLoad>;
21
21
  export declare function withDefaultAdapterSet(defaults: AdapterSet, loaded: AdapterSetLoad): AdapterSet;
@@ -21,6 +21,7 @@ export const CORE_METHODS = [
21
21
  ['supply', 'latestVersion'],
22
22
  ['supply', 'missingReleaseParts'],
23
23
  ['supply', 'probeRelease'],
24
+ ['supply', 'versionManifestOf'],
24
25
  ['supply', 'splitNpmSpec'],
25
26
  ['profile', 'dirOf'],
26
27
  ['profile', 'dshPlugins'],
@@ -55,6 +55,13 @@ export interface SupplyMissingPartsOptions {
55
55
  readonly version: string;
56
56
  readonly force?: boolean;
57
57
  }
58
+ export interface SupplyVersionManifestOptions {
59
+ readonly seam: Seam;
60
+ readonly name: string;
61
+ readonly version: string;
62
+ readonly registry: string;
63
+ readonly force?: boolean;
64
+ }
58
65
  export interface SupplyProbeReleaseOptions {
59
66
  readonly seam: Seam;
60
67
  readonly package: string;
@@ -83,6 +90,7 @@ export interface EnvSupplyPort {
83
90
  latestVersion(options: SupplyLatestOptions): Promise<string | undefined>;
84
91
  missingReleaseParts(options: SupplyMissingPartsOptions): Promise<readonly string[]>;
85
92
  probeRelease(options: SupplyProbeReleaseOptions): Promise<SupplyRelease | undefined>;
93
+ versionManifestOf(options: SupplyVersionManifestOptions): Promise<Readonly<Record<string, unknown>> | undefined>;
86
94
  splitNpmSpec(spec: string): SupplyNpmRef | undefined;
87
95
  }
88
96
  export interface ModulePort {
@@ -21,6 +21,7 @@ export function supplyPortOf(ctx) {
21
21
  latestVersion: (options) => env.latestVersion(options),
22
22
  missingReleaseParts: (options) => env.missingReleaseParts(options),
23
23
  probeRelease: (options) => env.probeRelease(options),
24
+ versionManifestOf: (options) => env.versionManifestOf(options),
24
25
  splitNpmSpec: (spec) => env.splitNpmSpec(spec),
25
26
  isolatedRoot: () => modules.isolatedRoot(),
26
27
  isolatedHome: () => modules.isolatedHome(),
@@ -6,6 +6,7 @@ export interface ReleaseProbe {
6
6
  latestVersion(options: LatestVersionOptions): Promise<string | undefined>;
7
7
  missingReleaseParts(options: MissingPartsOptions): Promise<readonly string[]>;
8
8
  probeRelease(options: ProbeReleaseOptions): Promise<PluginRelease | undefined>;
9
+ versionManifestOf(options: VersionManifestOptions): Promise<Readonly<Record<string, unknown>> | undefined>;
9
10
  reset(): void;
10
11
  }
11
12
  export declare function createReleaseProbe(input?: {
@@ -19,6 +20,14 @@ interface LatestVersionOptions {
19
20
  readonly prereleaseChannels?: readonly string[];
20
21
  readonly cacheDir?: string | undefined;
21
22
  }
23
+ interface VersionManifestOptions {
24
+ readonly seam: Seam;
25
+ readonly name: string;
26
+ readonly version: string;
27
+ readonly registry: string;
28
+ readonly force?: boolean;
29
+ readonly cacheDir?: string | undefined;
30
+ }
22
31
  interface MissingPartsOptions {
23
32
  readonly seam: Seam;
24
33
  readonly name: string;
@@ -65,15 +65,18 @@ function versionCacheTtl(value) {
65
65
  export function createReleaseProbe(input = {}) {
66
66
  const latestCache = new Map();
67
67
  const existsCache = new Map();
68
+ const manifestCache = new Map();
68
69
  const head = input.head ?? defaultHead;
69
70
  const ready = (call) => versionExists(existsCache, { ...call, head });
70
71
  return {
71
72
  latestVersion: async (options) => latestVersionOf(latestCache, ready, options),
72
73
  missingReleaseParts: async (options) => missingPartsOf(ready, options),
73
74
  probeRelease: async (options) => probeOf(latestCache, ready, options),
75
+ versionManifestOf: async (options) => manifestOfVersion(manifestCache, options),
74
76
  reset: () => {
75
77
  latestCache.clear();
76
78
  existsCache.clear();
79
+ manifestCache.clear();
77
80
  },
78
81
  };
79
82
  }
@@ -152,6 +155,23 @@ async function versionExists(existsCache, options) {
152
155
  existsCache.set(key, entry);
153
156
  return entry;
154
157
  }
158
+ async function manifestOfVersion(cache, options) {
159
+ const { seam, name, version, registry, force = false, cacheDir } = options;
160
+ const key = `${registry}|${name}@${version}`;
161
+ const hit = cache.get(key);
162
+ const ttl = hit?.value === undefined ? VERSION_CHECK_FAILURE_TTL_MS : VERSION_CHECK_TTL_MS;
163
+ if (!force && hit !== undefined && now() - hit.at < ttl)
164
+ return hit.value;
165
+ const pnpm = process.env.DSH_WB_PNPM?.trim() ?? '';
166
+ const spec = `${quoteShellArg(`${name}@${version}`)} engines peerDependencies name --json --registry ${quoteShellArg(registry)}${cacheFlag(cacheDir)}`;
167
+ const found = await viewOnce(seam, [`npm view ${spec}`, `${pnpm === '' ? 'pnpm' : pnpm} view ${spec}`]);
168
+ const parsed = found.ok ? parseJsonLoose(found.stdout) : undefined;
169
+ const value = typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
170
+ ? parsed
171
+ : undefined;
172
+ cache.set(key, { at: now(), value });
173
+ return value;
174
+ }
155
175
  async function missingPartsOf(ready, options) {
156
176
  const { seam, name, registry, version, force = false, cacheDir } = options;
157
177
  const checked = await Promise.all(RELEASE_PACKAGES.filter((part) => part !== name).map(async (part) => ({
@@ -42,6 +42,7 @@ const supply = {
42
42
  latestVersion: async () => undefined,
43
43
  missingReleaseParts: async () => [],
44
44
  probeRelease: async () => undefined,
45
+ versionManifestOf: async () => undefined,
45
46
  splitNpmSpec: () => undefined,
46
47
  };
47
48
  const modules = {
@@ -130,6 +131,7 @@ export function fakeAdapterSet(overrides = {}) {
130
131
  latestVersion: release.latestVersion,
131
132
  missingReleaseParts: release.missingReleaseParts,
132
133
  probeRelease: release.probeRelease,
134
+ versionManifestOf: release.versionManifestOf,
133
135
  };
134
136
  return {
135
137
  apiVersion: ADAPTER_SET_API_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/shared",
3
- "version": "1.5.2-alpha.2",
3
+ "version": "1.5.2-alpha.3",
4
4
  "description": "工作台与模块共享的纯代码与契约类型:类型、纯逻辑、哑组件、平台解析。宿主侧的东西从 /host 进(不影响浏览器产物)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -76,6 +76,7 @@ const FULL = `{
76
76
  latestVersion: async () => undefined,
77
77
  missingReleaseParts: async () => [],
78
78
  probeRelease: async () => undefined,
79
+ versionManifestOf: async () => undefined,
79
80
  splitNpmSpec: () => undefined,
80
81
  },
81
82
  profile: {
@@ -56,6 +56,7 @@ export const CORE_METHODS = [
56
56
  ['supply', 'latestVersion'],
57
57
  ['supply', 'missingReleaseParts'],
58
58
  ['supply', 'probeRelease'],
59
+ ['supply', 'versionManifestOf'],
59
60
  ['supply', 'splitNpmSpec'],
60
61
  ['profile', 'dirOf'],
61
62
  ['profile', 'dshPlugins'],
@@ -75,6 +75,14 @@ export interface SupplyMissingPartsOptions {
75
75
  readonly force?: boolean;
76
76
  }
77
77
 
78
+ export interface SupplyVersionManifestOptions {
79
+ readonly seam: Seam;
80
+ readonly name: string;
81
+ readonly version: string;
82
+ readonly registry: string;
83
+ readonly force?: boolean;
84
+ }
85
+
78
86
  export interface SupplyProbeReleaseOptions {
79
87
  readonly seam: Seam;
80
88
  readonly package: string;
@@ -101,6 +109,7 @@ export interface EnvSupplyPort {
101
109
  latestVersion(options: SupplyLatestOptions): Promise<string | undefined>;
102
110
  missingReleaseParts(options: SupplyMissingPartsOptions): Promise<readonly string[]>;
103
111
  probeRelease(options: SupplyProbeReleaseOptions): Promise<SupplyRelease | undefined>;
112
+ versionManifestOf(options: SupplyVersionManifestOptions): Promise<Readonly<Record<string, unknown>> | undefined>;
104
113
  splitNpmSpec(spec: string): SupplyNpmRef | undefined;
105
114
  }
106
115
 
@@ -26,6 +26,7 @@ export function supplyPortOf(ctx: DshHostContext): SupplyPort {
26
26
  latestVersion: (options) => env.latestVersion(options),
27
27
  missingReleaseParts: (options) => env.missingReleaseParts(options),
28
28
  probeRelease: (options) => env.probeRelease(options),
29
+ versionManifestOf: (options) => env.versionManifestOf(options),
29
30
  splitNpmSpec: (spec) => env.splitNpmSpec(spec),
30
31
  isolatedRoot: () => modules.isolatedRoot(),
31
32
  isolatedHome: () => modules.isolatedHome(),
@@ -60,6 +60,29 @@ afterEach(() => {
60
60
  vi.useRealTimers();
61
61
  });
62
62
 
63
+ describe('某一版的 engines / peers 自己问:市场据此判兼容', () => {
64
+ it('★ 解析成清单字段;同一版第二次直接走缓存', async () => {
65
+ const { probe, seam, fake } = harness((call) =>
66
+ String(call.command).includes('engines')
67
+ ? { stdout: JSON.stringify({ name: 'p', version: '1.2.3', engines: { dsh: '>=0.2.3' } }) }
68
+ : {},
69
+ );
70
+
71
+ const manifest = await probe.versionManifestOf({ seam, name: 'p', version: '1.2.3', registry: REGISTRY });
72
+ expect(manifest).toEqual({ name: 'p', version: '1.2.3', engines: { dsh: '>=0.2.3' } });
73
+
74
+ const again = await probe.versionManifestOf({ seam, name: 'p', version: '1.2.3', registry: REGISTRY });
75
+ expect(again).toEqual(manifest);
76
+ expect(fake.calls.filter((call) => String(call.command).includes('engines'))).toHaveLength(1);
77
+ });
78
+
79
+ it('★ 问不到就是 undefined(调用方据此给「未验证」,不假装兼容)', async () => {
80
+ const { probe, seam } = harness(() => ({}));
81
+
82
+ expect(await probe.versionManifestOf({ seam, name: 'q', version: '9.9.9', registry: REGISTRY })).toBeUndefined();
83
+ });
84
+ });
85
+
63
86
  describe('查新版那一次网络请求', () => {
64
87
  it('★ 按 registry 问一次、拿网络那档超时,不是本地账本那档', async () => {
65
88
  const { fake, probe, seam } = harness([{ stdout: '1.1.5\n' }]);
@@ -90,12 +90,14 @@ export interface ReleaseProbe {
90
90
  latestVersion(options: LatestVersionOptions): Promise<string | undefined>;
91
91
  missingReleaseParts(options: MissingPartsOptions): Promise<readonly string[]>;
92
92
  probeRelease(options: ProbeReleaseOptions): Promise<PluginRelease | undefined>;
93
+ versionManifestOf(options: VersionManifestOptions): Promise<Readonly<Record<string, unknown>> | undefined>;
93
94
  reset(): void;
94
95
  }
95
96
 
96
97
  export function createReleaseProbe(input: { readonly head?: TarballHead | undefined } = {}): ReleaseProbe {
97
98
  const latestCache = new Map<string, CacheEntry>();
98
99
  const existsCache = new Map<string, ExistsEntry>();
100
+ const manifestCache = new Map<string, ManifestEntry>();
99
101
  const head = input.head ?? defaultHead;
100
102
  const ready = (call: { seam: Seam; name: string; version: string; registry: string; force: boolean; cacheDir?: string | undefined }) =>
101
103
  versionExists(existsCache, { ...call, head });
@@ -104,9 +106,11 @@ export function createReleaseProbe(input: { readonly head?: TarballHead | undefi
104
106
  latestVersion: async (options) => latestVersionOf(latestCache, ready, options),
105
107
  missingReleaseParts: async (options) => missingPartsOf(ready, options),
106
108
  probeRelease: async (options) => probeOf(latestCache, ready, options),
109
+ versionManifestOf: async (options) => manifestOfVersion(manifestCache, options),
107
110
  reset: () => {
108
111
  latestCache.clear();
109
112
  existsCache.clear();
113
+ manifestCache.clear();
110
114
  },
111
115
  };
112
116
  }
@@ -120,6 +124,20 @@ interface LatestVersionOptions {
120
124
  readonly cacheDir?: string | undefined;
121
125
  }
122
126
 
127
+ interface VersionManifestOptions {
128
+ readonly seam: Seam;
129
+ readonly name: string;
130
+ readonly version: string;
131
+ readonly registry: string;
132
+ readonly force?: boolean;
133
+ readonly cacheDir?: string | undefined;
134
+ }
135
+
136
+ interface ManifestEntry {
137
+ readonly at: number;
138
+ readonly value: Readonly<Record<string, unknown>> | undefined;
139
+ }
140
+
123
141
  interface MissingPartsOptions {
124
142
  readonly seam: Seam;
125
143
  readonly name: string;
@@ -267,6 +285,27 @@ async function versionExists(
267
285
  return entry;
268
286
  }
269
287
 
288
+ async function manifestOfVersion(
289
+ cache: Map<string, ManifestEntry>,
290
+ options: VersionManifestOptions,
291
+ ): Promise<Readonly<Record<string, unknown>> | undefined> {
292
+ const { seam, name, version, registry, force = false, cacheDir } = options;
293
+ const key = `${registry}|${name}@${version}`;
294
+ const hit = cache.get(key);
295
+ const ttl = hit?.value === undefined ? VERSION_CHECK_FAILURE_TTL_MS : VERSION_CHECK_TTL_MS;
296
+ if (!force && hit !== undefined && now() - hit.at < ttl) return hit.value;
297
+ const pnpm = process.env.DSH_WB_PNPM?.trim() ?? '';
298
+ const spec = `${quoteShellArg(`${name}@${version}`)} engines peerDependencies name --json --registry ${quoteShellArg(registry)}${cacheFlag(cacheDir)}`;
299
+ const found = await viewOnce(seam, [`npm view ${spec}`, `${pnpm === '' ? 'pnpm' : pnpm} view ${spec}`]);
300
+ const parsed = found.ok ? parseJsonLoose(found.stdout) : undefined;
301
+ const value =
302
+ typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
303
+ ? (parsed as Readonly<Record<string, unknown>>)
304
+ : undefined;
305
+ cache.set(key, { at: now(), value });
306
+ return value;
307
+ }
308
+
270
309
  async function missingPartsOf(
271
310
  ready: ReadyOf,
272
311
  options: {
@@ -66,6 +66,7 @@ const supply: EnvSupplyPort = {
66
66
  latestVersion: async () => undefined,
67
67
  missingReleaseParts: async () => [],
68
68
  probeRelease: async () => undefined,
69
+ versionManifestOf: async () => undefined,
69
70
  splitNpmSpec: () => undefined,
70
71
  };
71
72
 
@@ -161,6 +162,7 @@ export function fakeAdapterSet(overrides: Partial<AdapterSet> = {}): AdapterSet
161
162
  latestVersion: release.latestVersion,
162
163
  missingReleaseParts: release.missingReleaseParts,
163
164
  probeRelease: release.probeRelease,
165
+ versionManifestOf: release.versionManifestOf,
164
166
  };
165
167
  return {
166
168
  apiVersion: ADAPTER_SET_API_VERSION,