fix(packaging): expose Ajv from CJS validator subpaths (#2431)
This commit is contained in:
parent
ddba550fa9
commit
1b90c96d11
1 changed files with 37 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { execFileSync } from 'node:child_process';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
|
|
@ -7,6 +8,7 @@ import { beforeAll, describe, expect, test } from 'vitest';
|
|||
|
||||
const pkgDir = join(dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const distDir = join(pkgDir, 'dist');
|
||||
const requireDist = createRequire(join(pkgDir, 'package.json'));
|
||||
const NODE_ONLY = /\b(child_process|cross-spawn|node:stream|node:child_process)\b/;
|
||||
// Anchored at start-of-line so JSDoc-example `from 'ajv'` strings in vendored chunks don't match.
|
||||
const VALIDATOR_BACKEND_IMPORT = /^import[^\n]*?from\s+["'](?:ajv|ajv-formats|@cfworker\/json-schema)["']/m;
|
||||
|
|
@ -67,4 +69,15 @@ describe('@modelcontextprotocol/client root entry is browser-safe', () => {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('CJS AJV validator subpath exposes Ajv at runtime', () => {
|
||||
const { Ajv, AjvJsonSchemaValidator, addFormats } = requireDist(
|
||||
'./dist/validators/ajv.cjs'
|
||||
) as typeof import('../../src/validators/ajv');
|
||||
|
||||
const ajv = new Ajv({ strict: false, allErrors: true });
|
||||
addFormats(ajv);
|
||||
|
||||
expect(new AjvJsonSchemaValidator(ajv)).toBeInstanceOf(AjvJsonSchemaValidator);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue