Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incomplete package entrypoint definitions #42

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/beige-falcons-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"ilib-lint-python-gnu": patch
"ilib-tools-common": patch
"ilib-lint-common": patch
"ilib-lint-python": patch
"ilib-data-utils": patch
"ilib-lint-react": patch
"ilib-assemble": patch
"ilib-lint": patch
"tmxtool": patch
---

Unified package entrypoint definitions. This should help resolve edge cases where older packages (like Jest 26) were unable to correctly load some of them.
3 changes: 2 additions & 1 deletion packages/ilib-assemble/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "ilib-assemble",
"version": "1.3.1",
"main": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"bin": {
"ilib-assemble": "./src/index.js",
"ilib-assemble.bat": "./ilib-assemble.bat"
Expand Down
6 changes: 6 additions & 0 deletions packages/ilib-data-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"version": "1.2.2",
"main": "./lib/index.js",
"module": "./src/index.js",
"exports": {
".": {
"require": "./lib/index.js",
"import": "./src/index.js"
}
},
"description": "Utilities used to generate locale data for ilib packages",
"keywords": [
"internationalization",
Expand Down
3 changes: 2 additions & 1 deletion packages/ilib-lint-common/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "ilib-lint-common",
"version": "3.1.1",
"module": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"exports": {
".": {
"import": "./src/index.js"
Expand Down
7 changes: 3 additions & 4 deletions packages/ilib-lint-python-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "ilib-lint-python-gnu",
"version": "2.0.2",
"main": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"exports": {
".": {
"default": {
"default": "./src/index.js"
}
"import": "./src/index.js"
},
"./package.json": "./package.json"
},
Expand Down
7 changes: 3 additions & 4 deletions packages/ilib-lint-python/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "ilib-lint-python",
"version": "2.0.2",
"main": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"exports": {
".": {
"default": {
"default": "./src/index.js"
}
"import": "./src/index.js"
},
"./package.json": "./package.json"
},
Expand Down
7 changes: 3 additions & 4 deletions packages/ilib-lint-react/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "ilib-lint-react",
"version": "2.0.2",
"main": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"exports": {
".": {
"default": {
"default": "./src/index.js"
}
"import": "./src/index.js"
},
"./package.json": "./package.json"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/ilib-lint/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "ilib-lint",
"version": "2.7.1",
"module": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"bin": "./src/index.js",
"description": "A linter for i18n issues for any type of project",
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions packages/ilib-tools-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "ilib-tools-common",
"version": "1.12.1",
"main": "./lib/index.js",
"module": "./src/index.js",
"exports": {
".": {
Expand Down
3 changes: 2 additions & 1 deletion packages/tmxtool/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "tmxtool",
"version": "1.0.3",
"main": "./src/index.js",
"type": "module",
"main": "./src/index.js",
"module": "./src/index.js",
"bin": {
"tmxtool": "./src/index.js",
"tmxtool.bat": "./tmxtool.bat"
Expand Down
51 changes: 51 additions & 0 deletions scripts/check-package-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Usage: node scripts/check-package-exports.js
// This script checks that all packages have correct entrypoint fields

const fs = require("fs");

const packageFiles = fs
.readdirSync("packages")
.map((package) => `packages/${package}/package.json`)
.filter((file) => fs.existsSync(file));
for (const path of packageFiles) {
console.log(`Processing ${path}`);
const data = fs.readFileSync(path, "utf8");
const pkg = JSON.parse(data);

const { main, module } = pkg;

const type = pkg.type ?? "commonjs";

// either { exports: { .: { import, require } } } or { exports: { import, require } }
const exportsRoot = pkg.exports?.["."] ?? pkg.exports;

if (!main) {
// main should be present regardless of type
// because it's the default entry point for a package in Node.js
// if type is commonjs, it should point to a commonjs file,
// if type is module, it should point to an es module file
console.error("No main field found");
}

if (type === "module" && !module) {
// module should be present if type is module
// this is not officially required, but often used for ESM entry point
console.error("Type is module, but no module field found");
}

if (main && module && main !== module && !exportsRoot) {
// when both main and module are present and are different,
// this means that the package provides both CJS and ESM code;
// in this case, per Node documentation, the package should have an exports field
// with separate import and require: https://nodejs.org/api/packages.html#conditional-exports
console.error("Main and module are different, but no exports field found");
}

if (exportsRoot && (!type || type === "commonjs") && !exportsRoot.require) {
console.error("Exports are present and type is commonjs, but no require field found in exports");
}

if (exportsRoot && type === "module" && !exportsRoot.import) {
console.error("Exports are present and type is module, but no import field found in exports");
}
}
Loading