diff --git a/.talismanrc b/.talismanrc index 147c4a6..c2708c0 100644 --- a/.talismanrc +++ b/.talismanrc @@ -3,7 +3,7 @@ fileignoreconfig: ignore_detectors: - filecontent - filename: package-lock.json - checksum: 61066aedc29ef5bd8904d1ee2384dad828e8f9aab1a6b0360797ec7926e7f8dd + checksum: 61741bf02cfbc74f1ca4e7b0bda74d27d295616a13a31a95c2d7818fcc3d1cba - filename: .husky/pre-commit checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193 - filename: test/request.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e0d91a2..646eaec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Change log +### Version: 1.3.3 +#### Date: Nov-10-2025 + - Fix: Added 'exports' field to package.json to fix ESM import error where '@contentstack/core' does not provide an export named 'getData' in modern ESM environments (e.g., Nuxt.js, Vite) + ### Version: 1.3.2 #### Date: Oct-27-2025 - Fix: Used common serialize method for query params diff --git a/package-lock.json b/package-lock.json index 26ef15c..6a03c6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/core", - "version": "1.3.2", + "version": "1.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/core", - "version": "1.3.2", + "version": "1.3.3", "license": "MIT", "dependencies": { "axios": "^1.12.2", @@ -2210,7 +2210,8 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.126.tgz", "integrity": "sha512-OTcgaiwfGFBKacvfwuHzzn1KLxH/er8mluiy8/uM3sGXHaRe73RrSIj01jow9t4kJEW633Ov+cOexXeiApTyAw==", "dev": true, - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/@types/normalize-package-data": { "version": "2.4.4", @@ -2332,6 +2333,7 @@ "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", "dev": true, "license": "BSD-2-Clause", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "5.62.0", "@typescript-eslint/types": "5.62.0", @@ -2748,6 +2750,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -2831,6 +2834,7 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -3223,10 +3227,11 @@ } }, "node_modules/axios": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.1.tgz", - "integrity": "sha512-hU4EGxxt+j7TQijx1oYdAjw4xuIp1wRQSsbMFwSthCWeBQur1eF+qJ5iQ5sN3Tw8YRzQNKb8jszgBdMDVqwJcw==", + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.2.tgz", + "integrity": "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==", "license": "MIT", + "peer": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", @@ -3384,9 +3389,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.8.23", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.23.tgz", - "integrity": "sha512-616V5YX4bepJFzNyOfce5Fa8fDJMfoxzOIzDCZwaGL8MKVpFrXqfNUoIpRn9YMI5pXf/VKgzjB4htFMsFKKdiQ==", + "version": "2.8.25", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.25.tgz", + "integrity": "sha512-2NovHVesVF5TXefsGX1yzx1xgr7+m9JQenvz6FQY3qd+YXkKkYiv+vTCc7OriP9mcDZpTC5mAOYN4ocd29+erA==", "dev": true, "license": "Apache-2.0", "bin": { @@ -3456,6 +3461,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.19", "caniuse-lite": "^1.0.30001751", @@ -3622,9 +3628,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001753", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001753.tgz", - "integrity": "sha512-Bj5H35MD/ebaOV4iDLqPEtiliTN29qkGtEHCwawWn4cYm+bPJM2NsaP30vtZcnERClMzp52J4+aw2UNbK4o+zw==", + "version": "1.0.30001754", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001754.tgz", + "integrity": "sha512-x6OeBXueoAceOmotzx3PO4Zpt4rzpeIFsSr6AAePTZxSkXiYDUmpypEl7e2+8NCd9bD7bXjqyef8CJYPC1jfxg==", "dev": true, "funding": [ { @@ -4808,9 +4814,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.244", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.244.tgz", - "integrity": "sha512-OszpBN7xZX4vWMPJwB9illkN/znA8M36GQqQxi6MNy9axWxhOfJyZZJtSLQCpEFLHP2xK33BiWx9aIuIEXVCcw==", + "version": "1.5.249", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.249.tgz", + "integrity": "sha512-5vcfL3BBe++qZ5kuFhD/p8WOM1N9m3nwvJPULJx+4xf2usSlZFJ0qoNYO2fOX4hi3ocuDcmDobtA+5SFr4OmBg==", "dev": true, "license": "ISC" }, @@ -5103,6 +5109,7 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -5410,6 +5417,7 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -7746,6 +7754,7 @@ "integrity": "sha512-N4GT5on8UkZgH0O5LUavMRV1EDEhNTL0KEfRmDIeZHSV7p2XgLoY9t9VDUgL6o+yfdgYHVxuz81G8oB9VG5uyA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jest/core": "^28.1.3", "@jest/types": "^28.1.3", @@ -9732,6 +9741,7 @@ "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", "dev": true, "license": "MIT", + "peer": true, "bin": { "prettier": "bin-prettier.js" }, @@ -11113,9 +11123,9 @@ } }, "node_modules/terser": { - "version": "5.44.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.44.0.tgz", - "integrity": "sha512-nIVck8DK+GM/0Frwd+nIhZ84pR/BX7rmXMfYwyg+Sri5oGVE99/E3KvXqpC2xHFxyqXyGHTKBSioxxplrO4I4w==", + "version": "5.44.1", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.44.1.tgz", + "integrity": "sha512-t/R3R/n0MSwnnazuPpPNVO60LX0SKL45pyl9YlvxIdkH0Of7D5qM2EVe+yASRIlY5pZ73nclYJfNANGWPwFDZw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -11484,6 +11494,7 @@ "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -11730,6 +11741,7 @@ "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -11970,6 +11982,7 @@ "integrity": "sha512-7h/weGm9d/ywQ6qzJ+Xy+r9n/3qgp/thalBbpOi5i223dPXKi04IBtqPN9nTd+jBc7QKfvDbaBnFipYp4sJAUQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", diff --git a/package.json b/package.json index d43a6bb..cfa3194 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,22 @@ { "name": "@contentstack/core", - "version": "1.3.2", + "version": "1.3.3", "type": "commonjs", "main": "./dist/cjs/src/index.js", "types": "./dist/cjs/src/index.d.ts", + "exports": { + ".": { + "import": { + "types": "./dist/types/src/index.d.ts", + "default": "./dist/esm/src/index.js" + }, + "require": { + "types": "./dist/types/src/index.d.ts", + "default": "./dist/cjs/src/index.js" + } + }, + "./package.json": "./package.json" + }, "license": "MIT", "scripts": { "prepare": "npm run build && npm run husky-check", diff --git a/test/esm-exports.spec.ts b/test/esm-exports.spec.ts new file mode 100644 index 0000000..fe70c69 --- /dev/null +++ b/test/esm-exports.spec.ts @@ -0,0 +1,121 @@ +/** + * ESM Exports Test Suite + * + * Purpose: Verify that ESM and CJS builds export correctly and package.json + * has proper exports field configuration for ESM compatibility. + */ + +import * as fs from 'fs'; +import * as path from 'path'; + +describe('ESM Exports Tests', () => { + const distPath = path.join(__dirname, '..', 'dist'); + const esmIndexPath = path.join(distPath, 'esm', 'src', 'index.js'); + const cjsIndexPath = path.join(distPath, 'cjs', 'src', 'index.js'); + const esmRequestPath = path.join(distPath, 'esm', 'src', 'lib', 'request.js'); + const cjsRequestPath = path.join(distPath, 'cjs', 'src', 'lib', 'request.js'); + + describe('ESM Build Exports', () => { + it('should have ESM build index.js file', () => { + expect(fs.existsSync(esmIndexPath)).toBe(true); + }); + + it('should export getData from ESM request.js', () => { + expect(fs.existsSync(esmRequestPath)).toBe(true); + const requestContent = fs.readFileSync(esmRequestPath, 'utf-8'); + expect(requestContent).toContain('export function getData'); + }); + + it('should re-export getData from ESM index.js', () => { + const indexContent = fs.readFileSync(esmIndexPath, 'utf-8'); + expect(indexContent).toContain("export * from './lib/request'"); + }); + + it('should verify getData is a named export in ESM build', () => { + const requestContent = fs.readFileSync(esmRequestPath, 'utf-8'); + expect(requestContent).toMatch(/export\s+(async\s+)?function\s+getData/); + }); + }); + + describe('CJS Build Exports', () => { + it('should have CJS build index.js file', () => { + expect(fs.existsSync(cjsIndexPath)).toBe(true); + }); + + it('should export getData from CJS request.js using exports.getData', () => { + expect(fs.existsSync(cjsRequestPath)).toBe(true); + const requestContent = fs.readFileSync(cjsRequestPath, 'utf-8'); + expect(requestContent).toContain('exports.getData'); + }); + + it('should re-export getData from CJS index.js using __exportStar', () => { + const indexContent = fs.readFileSync(cjsIndexPath, 'utf-8'); + expect(indexContent).toContain('__exportStar(require("./lib/request")'); + }); + }); + + describe('Package.json Exports Configuration', () => { + it('should have exports field in package.json', () => { + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + expect(packageJson.exports).toBeDefined(); + expect(packageJson.exports['.']).toBeDefined(); + }); + + it('should have import condition pointing to ESM build', () => { + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + expect(packageJson.exports['.'].import).toBeDefined(); + const importPath = packageJson.exports['.'].import.default || packageJson.exports['.'].import; + expect(importPath).toContain('esm'); + }); + + it('should have require condition pointing to CJS build', () => { + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + expect(packageJson.exports['.'].require).toBeDefined(); + const requirePath = packageJson.exports['.'].require.default || packageJson.exports['.'].require; + expect(requirePath).toContain('cjs'); + }); + + it('should have types specified for both import and require', () => { + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + const exports = packageJson.exports['.']; + expect(exports.import.types).toBeDefined(); + expect(exports.require.types).toBeDefined(); + expect(exports.import.types).toContain('types'); + expect(exports.require.types).toContain('types'); + }); + + it('should verify ESM build file exists at exports path', () => { + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + const importPath = packageJson.exports['.'].import.default || packageJson.exports['.'].import; + const fullPath = path.join(__dirname, '..', importPath); + expect(fs.existsSync(fullPath)).toBe(true); + }); + + it('should verify CJS build file exists at exports path', () => { + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + const requirePath = packageJson.exports['.'].require.default || packageJson.exports['.'].require; + const fullPath = path.join(__dirname, '..', requirePath); + expect(fs.existsSync(fullPath)).toBe(true); + }); + }); + + describe('Source Code Imports', () => { + it('should be able to import getData as named export from source', async () => { + const { getData } = await import('../src'); + expect(getData).toBeDefined(); + expect(typeof getData).toBe('function'); + }); + + it('should verify getData is available in all exports from source', async () => { + const allExports = await import('../src'); + expect(allExports.getData).toBeDefined(); + expect(typeof allExports.getData).toBe('function'); + }); + }); +});