diff --git a/.changeset/mrt-utilities-strip-dev-exports.md b/.changeset/mrt-utilities-strip-dev-exports.md new file mode 100644 index 00000000..2e884560 --- /dev/null +++ b/.changeset/mrt-utilities-strip-dev-exports.md @@ -0,0 +1,5 @@ +--- +'@salesforce/mrt-utilities': patch +--- + +Fix package export resolution for consumers by stripping `development` export conditions during `prepack`, so published tarballs always resolve to shipped `dist` files. diff --git a/packages/mrt-utilities/package.json b/packages/mrt-utilities/package.json index 44dd9f54..d0bf4eda 100644 --- a/packages/mrt-utilities/package.json +++ b/packages/mrt-utilities/package.json @@ -102,7 +102,9 @@ "test": "c8 mocha --forbid-only \"test/**/*.test.ts\"", "test:ci": "c8 mocha --forbid-only --reporter json --reporter-option output=test-results.json \"test/**/*.test.ts\"", "test:agent": "mocha --forbid-only --reporter min \"test/**/*.test.ts\"", - "test:watch": "mocha --watch \"test/**/*.test.ts\"" + "test:watch": "mocha --watch \"test/**/*.test.ts\"", + "prepack": "node scripts/strip-dev-exports.cjs", + "postpack": "git checkout package.json" }, "dependencies": { "@aws-sdk/client-cloudwatch": "3.952.0", diff --git a/packages/mrt-utilities/scripts/strip-dev-exports.cjs b/packages/mrt-utilities/scripts/strip-dev-exports.cjs new file mode 100644 index 00000000..63c5174a --- /dev/null +++ b/packages/mrt-utilities/scripts/strip-dev-exports.cjs @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025, Salesforce, Inc. + * SPDX-License-Identifier: Apache-2 + * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0 + */ + +/** + * Strips "development" conditions from package.json exports before packing. + * + * The "development" condition maps to TypeScript source files (./src/...) + * which are not included in the published package. This prevents + * MODULE_NOT_FOUND errors when consumers install the package from npm. + * + * Called by the "prepack" script; "postpack" restores via git checkout. + */ +/* eslint-disable @typescript-eslint/no-require-imports */ +const fs = require('fs'); +const path = require('path'); + +const pkgPath = path.join(__dirname, '..', 'package.json'); +const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); + +let stripped = 0; + +if (pkg.exports) { + for (const [, value] of Object.entries(pkg.exports)) { + if (value && typeof value === 'object' && 'development' in value) { + delete value.development; + stripped++; + } + } +} + +if (stripped > 0) { + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); + console.log(`Stripped "development" condition from ${stripped} export(s)`); +}