arethetypeswrong / arethetypeswrong/arethetypeswrong.github.io

How to check globs in exports

Đang mở
#73 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
1.6k
Fork
65
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I wrote a wrapper around the invocation of attw, some may find it helpful:

```js
async function lintPublishedTypes({ cwd }) {
let manifest = await packageJson.read(cwd);
let name = manifest.name;

let entrypoints = [];

for (let [entryGlob, mapping] of Object.entries(manifest['exports'])) {
if (!entryGlob.includes('*')) {
let entry = path.join(name, entryGlob);

entrypoints.push(entry);
continue;
}

const files = globbySync(mapping.types.replace('*', '**/*'), {cwd});

// Map the files to full module paths
const mappedFiles = files.map(file => {
// Now that we found files, we need to map them _back_ to entrypoints.
// Based on the entryGlob, we need to remove the path leading up until the '*',
let toRemove = mapping.types.split('*')[0];
let moduleName = file.split(toRemove)[1];

// we need to chop off the extension IFF the mapping.types includes it
if (mapping.types.endsWith('.d.ts')) {
moduleName = moduleName.replace('.d.ts', '');
}

return moduleName;
});

entrypoints.push(...mappedFiles);
}

entrypoints = entrypoints
// Remove stuff we are going to exclude
.filter(entry => !entry.endsWith('*'))
.filter(entry => !entry.endsWith('addon-main'))
// Remove index files
.filter(entry => !entry.endsWith('index'));

let args = [
'attw', '--pack',
// This does not provide types
'--exclude-entrypoints', 'addon-main',
// We turn this one off because we don't care about CJS consumers
'--ignore-rules', 'cjs-resolves-to-esm',
// Wildcard is not official supported
'--ignore-rules', 'wildcard',
// publint will handle resolving
'--ignore-rules', 'internal-resolution-error',
'--include-entrypoints', ...entrypoints
];

console.info(chalk.blueBright('Running:\n', args.join(' ')));

await execa('pnpm', args, {
cwd,
stdio: 'inherit',
});
}

```

This takes my exports:
```
"exports": {
".": {
"types": "./dist-types/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./dist-types/*.d.ts",
"default": "./dist/*.js"
},
"./test-support": {
"types": "./dist-types/test-support/index.d.ts",
"default": "./dist/test-support/index.js"
},
"./addon-main": "./addon-main.cjs"
},
```

and invokes this command:

```
attw --pack \
--exclude-entrypoints addon-main \
--ignore-rules cjs-resolves-to-esm \
--ignore-rules wildcard \
--ignore-rules internal-resolution-error \
--include-entrypoints \
ember-primitives color-scheme helpers iframe proper-links template-registry utils \
components/dialog components/external-link components/link components/popover components/portal-targets components/portal components/shadowed components/switch components/toggle helpers/service \
test-support/routing \
components/-private/typed-elements components/-private/utils components/dialog/element-state components/dialog/state \
ember-primitives/test-support

```

it's not perfect -- but it's progress

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với wrapper lintPublishedTypes được đề xuất và ánh xạ package exports được hiển thị trong issue. Chạy lệnh attw được hiển thị đối với các entrypoint đã liệt kê, sau đó so sánh cách lệnh này xử lý wildcard exports với danh sách entrypoint được tạo; hoàn thành khi các export được glob có thể được kiểm tra đáng tin cậy mà không cần workaround thủ công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript
Lĩnh vực
devtools
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.