@mearl/preset 3.0.0-beta.7 → 3.0.0-beta.9

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/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { PresetError, validatePreset, clonePresetDefaults } from './manifest.js';
2
2
  export { mergePresetDefaults, resolvePreset } from './resolve.js';
3
3
  export type * from './types.js';
4
+ export { parseSetupManagement, setupManagementCommand, setupRuntimeCompatible } from './management.js';
5
+ export type { SetupManagement } from './management.js';
4
6
  export { prepareNodeBundleSnapshot, prepareCapabilitySnapshot, verifyCapabilitySnapshot, verifyCapabilityActivation, validateCapabilityConfig, resolveCapabilityConfig, MAX_CAPABILITY_SELECTION_BYTES } from './capabilitySnapshot.js';
5
7
  export type { CapabilitySelection, CapabilitySnapshot, CapabilityActivation } from './capabilitySnapshot.js';
6
8
  export { parseToolboxCatalogs } from './toolboxCatalogs.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { PresetError, validatePreset, clonePresetDefaults } from './manifest.js';
2
2
  export { mergePresetDefaults, resolvePreset } from './resolve.js';
3
+ export { parseSetupManagement, setupManagementCommand, setupRuntimeCompatible } from './management.js';
3
4
  export { prepareNodeBundleSnapshot, prepareCapabilitySnapshot, verifyCapabilitySnapshot, verifyCapabilityActivation, validateCapabilityConfig, resolveCapabilityConfig, MAX_CAPABILITY_SELECTION_BYTES } from './capabilitySnapshot.js';
4
5
  export { parseToolboxCatalogs } from './toolboxCatalogs.js';
@@ -0,0 +1,10 @@
1
+ export interface SetupManagement {
2
+ package: string;
3
+ version: string;
4
+ registry?: string;
5
+ runtime?: string;
6
+ }
7
+ /** Declarative installation guidance; never accepts commands, arguments or executable hooks. */
8
+ export declare function parseSetupManagement(value: unknown): SetupManagement | undefined;
9
+ export declare function setupManagementCommand(setup: SetupManagement): string;
10
+ export declare function setupRuntimeCompatible(setup: SetupManagement, version: string, targetLine?: string): boolean;
@@ -0,0 +1,36 @@
1
+ import { valid, validRange, satisfies, subset } from 'semver';
2
+ import { isJsonObject, PresetError } from './manifest.js';
3
+ /** Declarative installation guidance; never accepts commands, arguments or executable hooks. */
4
+ export function parseSetupManagement(value) {
5
+ if (value === undefined)
6
+ return;
7
+ const invalid = () => { throw new PresetError('PRESET_INVALID', 'Invalid defaults.management.setup declaration'); };
8
+ if (!isJsonObject(value) || Object.keys(value).some(key => key !== 'setup') || !isJsonObject(value.setup))
9
+ return invalid();
10
+ const setup = value.setup;
11
+ if (Object.keys(setup).some(key => !['package', 'version', 'registry', 'runtime'].includes(key)) ||
12
+ typeof setup.package !== 'string' || setup.package.length > 214 || !/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(setup.package) ||
13
+ typeof setup.version !== 'string' || setup.version.length > 64 || !(valid(setup.version) === setup.version || /^[a-z][a-z0-9.-]*$/.test(setup.version)))
14
+ return invalid();
15
+ if (setup.registry !== undefined) {
16
+ if (typeof setup.registry !== 'string' || setup.registry.length > 2048 || !/^https:\/\/[a-zA-Z0-9./:_-]+$/.test(setup.registry))
17
+ return invalid();
18
+ try {
19
+ const url = new URL(setup.registry);
20
+ if (!url.hostname || url.username || url.password || url.search || url.hash)
21
+ return invalid();
22
+ }
23
+ catch {
24
+ return invalid();
25
+ }
26
+ }
27
+ if (setup.runtime !== undefined && (typeof setup.runtime !== 'string' || setup.runtime.length > 128 || !validRange(setup.runtime)))
28
+ return invalid();
29
+ return { ...setup };
30
+ }
31
+ export function setupManagementCommand(setup) {
32
+ return `npx${setup.registry ? ` --registry=${setup.registry}` : ''} ${setup.package}@${setup.version}`;
33
+ }
34
+ export function setupRuntimeCompatible(setup, version, targetLine) {
35
+ return !setup.runtime || (satisfies(version, setup.runtime, { includePrerelease: true }) && (!targetLine || subset(targetLine, setup.runtime, { includePrerelease: true })));
36
+ }
package/dist/resolve.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parseToolboxCatalogs } from './toolboxCatalogs.js';
2
+ import { parseSetupManagement } from './management.js';
2
3
  import { satisfies, valid } from 'semver';
3
4
  import { clonePresetDefaults, isJsonObject, PresetError, validatePreset } from './manifest.js';
4
5
  const kinds = ['packages', 'skills', 'providers'];
@@ -128,6 +129,7 @@ export async function resolvePreset(source, options) {
128
129
  return result;
129
130
  };
130
131
  const result = await load(sourceUrl(source));
132
+ parseSetupManagement(result.defaults.management);
131
133
  const extension = result.defaults.extension;
132
134
  if (isJsonObject(extension))
133
135
  parseToolboxCatalogs(extension.toolCatalogs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/preset",
3
- "version": "3.0.0-beta.7",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "Browser-compatible preset validation, inheritance and capability resolution for Mearl",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",