Skip to content
Open
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"node": ">=14.17.0"
},
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.esm.json & tsc -p tsconfig.cjs.json",
"prepare": "rimraf dist && tsc -p tsconfig.esm.json & tsc -p tsconfig.cjs.json",
"build": "rimraf dist && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/write-dist-package-jsons.cjs && npm run verify:dist",
"prepare": "npm run build",
"verify:dist": "node scripts/verify-dist-exports.cjs",
"lint": "eslint **/*.ts --ignore-path .eslintignore",
"lint:fix": "eslint **/*.ts --ignore-path .eslintignore --fix"
},
Expand Down
26 changes: 26 additions & 0 deletions scripts/verify-dist-exports.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const assert = require('node:assert/strict');
const path = require('node:path');
const { pathToFileURL } = require('node:url');

async function main() {
const rootDir = path.resolve(__dirname, '..');
const cjsEntry = path.join(rootDir, 'dist', 'cjs', 'index.js');
const esmEntry = pathToFileURL(
path.join(rootDir, 'dist', 'esm', 'index.js')
).href;

const cjsSdk = require(cjsEntry);
const esmSdk = await import(esmEntry);

assert.equal(cjsSdk.OrderStatus.Created, 'CREATED');
assert.equal(cjsSdk.CaptureStatus.Completed, 'COMPLETED');
assert.equal(esmSdk.OrderStatus.Created, 'CREATED');
assert.equal(esmSdk.CaptureStatus.Completed, 'COMPLETED');

console.log('Verified ESM and CJS dist exports');
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
16 changes: 16 additions & 0 deletions scripts/write-dist-package-jsons.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');
const path = require('path');

const rootDir = path.resolve(__dirname, '..');
const distPackages = [
{ dir: path.join(rootDir, 'dist', 'esm'), type: 'module' },
{ dir: path.join(rootDir, 'dist', 'cjs'), type: 'commonjs' },
];

for (const { dir, type } of distPackages) {
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(
path.join(dir, 'package.json'),
JSON.stringify({ type }, null, 2) + '\n'
);
}