示例工程 24-module-resolution
24-module-resolution/03-exports-conditions/main.test.mjs
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { run } from './dist/main.js';
const here = dirname(fileURLToPath(import.meta.url));
test('package.json exports 用 types 条件指向声明文件', () => {
assert.deepEqual(run(), []);
const pkg = JSON.parse(readFileSync(join(here, 'fixtures', 'pkg', 'package.json'), 'utf8'));
assert.deepEqual(Object.keys(pkg.exports['.']), ['types', 'import', 'default']);
assert.equal(pkg.exports['.'].types, './index.d.ts');
});