diff --git a/.changeset/beige-falcons-mate.md b/.changeset/beige-falcons-mate.md new file mode 100644 index 000000000..641aa9c43 --- /dev/null +++ b/.changeset/beige-falcons-mate.md @@ -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. diff --git a/packages/ilib-assemble/package.json b/packages/ilib-assemble/package.json index 84bed8c0d..e077d3cab 100644 --- a/packages/ilib-assemble/package.json +++ b/packages/ilib-assemble/package.json @@ -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" diff --git a/packages/ilib-data-utils/package.json b/packages/ilib-data-utils/package.json index d603945f7..6ff429a6c 100644 --- a/packages/ilib-data-utils/package.json +++ b/packages/ilib-data-utils/package.json @@ -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", diff --git a/packages/ilib-lint-common/package.json b/packages/ilib-lint-common/package.json index 19a7edc45..ed903f73c 100644 --- a/packages/ilib-lint-common/package.json +++ b/packages/ilib-lint-common/package.json @@ -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" diff --git a/packages/ilib-lint-python-gnu/package.json b/packages/ilib-lint-python-gnu/package.json index e1ab0e89f..fedbab2f4 100644 --- a/packages/ilib-lint-python-gnu/package.json +++ b/packages/ilib-lint-python-gnu/package.json @@ -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" }, diff --git a/packages/ilib-lint-python/package.json b/packages/ilib-lint-python/package.json index 2db0e0941..ccba405a2 100644 --- a/packages/ilib-lint-python/package.json +++ b/packages/ilib-lint-python/package.json @@ -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" }, diff --git a/packages/ilib-lint-react/package.json b/packages/ilib-lint-react/package.json index af2a6d975..3ff4a3f64 100644 --- a/packages/ilib-lint-react/package.json +++ b/packages/ilib-lint-react/package.json @@ -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" }, diff --git a/packages/ilib-lint/package.json b/packages/ilib-lint/package.json index c13de81e5..291b545d4 100644 --- a/packages/ilib-lint/package.json +++ b/packages/ilib-lint/package.json @@ -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": [ diff --git a/packages/ilib-tools-common/package.json b/packages/ilib-tools-common/package.json index d03d4001b..d55cb1545 100644 --- a/packages/ilib-tools-common/package.json +++ b/packages/ilib-tools-common/package.json @@ -1,6 +1,7 @@ { "name": "ilib-tools-common", "version": "1.12.1", + "main": "./lib/index.js", "module": "./src/index.js", "exports": { ".": { diff --git a/packages/tmxtool/package.json b/packages/tmxtool/package.json index ba71439b9..313ac3216 100644 --- a/packages/tmxtool/package.json +++ b/packages/tmxtool/package.json @@ -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" diff --git a/scripts/check-package-exports.js b/scripts/check-package-exports.js new file mode 100644 index 000000000..a7c8779a9 --- /dev/null +++ b/scripts/check-package-exports.js @@ -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"); + } +}