Files
plugins-marketplace/scripts/registry.test.mjs
T
chrnx 2ce1e0c4e5 feat: accept npm plugins only when they are ESM only
green-tea is ESM end to end and its Node floor is moving up; a CJS or
dual package brings a require path that is the first thing to break.
The check lives in readEntry, so it bites on CI with every other
registry check, and validate.mjs inherits it when it is written.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-24 09:53:32 -05:00

39 lines
1.5 KiB
JavaScript

// Pure pieces of the registry reader. Network calls are not tested here; `CI=true npm run build`
// exercises them against the live registries.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { isEsmOnly, byNewest, npmReadme } from './registry.mjs';
test('isEsmOnly: type module with ESM exports passes', () => {
assert.equal(isEsmOnly({ type: 'module', exports: { '.': { import: './dist/index.js', types: './dist/index.d.ts' } } }), true);
});
test('isEsmOnly: no type module is CJS', () => {
assert.equal(isEsmOnly({ main: './index.js' }), false);
});
test('isEsmOnly: dual package is rejected', () => {
assert.equal(isEsmOnly({ type: 'module', exports: { '.': { import: './index.js', require: './index.cjs' } } }), false);
});
test('isEsmOnly: a .cjs anywhere in exports or main is rejected', () => {
assert.equal(isEsmOnly({ type: 'module', exports: { './legacy': './legacy.cjs' } }), false);
assert.equal(isEsmOnly({ type: 'module', main: './index.cjs' }), false);
});
test('byNewest: releases outrank their prereleases, betas order numerically', () => {
assert.deepEqual(byNewest(['26.9.0-beta.2', '26.9.0', '26.9.0-beta.10', '26.8.1']), [
'26.9.0',
'26.9.0-beta.10',
'26.9.0-beta.2',
'26.8.1',
]);
});
test('npmReadme: npm placeholder means no README', () => {
assert.equal(npmReadme({ readme: 'ERROR: No README data found!' }), '');
assert.equal(npmReadme({}), '');
assert.equal(npmReadme({ readme: '# hi' }), '# hi');
});