Skip to content

Commit fd067f7

Browse files
Merge pull request #153 from contentstack/development
Development
2 parents 4822074 + 1fb666f commit fd067f7

File tree

5 files changed

+171
-20
lines changed

5 files changed

+171
-20
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: package-lock.json
6-
checksum: 61066aedc29ef5bd8904d1ee2384dad828e8f9aab1a6b0360797ec7926e7f8dd
6+
checksum: 61741bf02cfbc74f1ca4e7b0bda74d27d295616a13a31a95c2d7818fcc3d1cba
77
- filename: .husky/pre-commit
88
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
99
- filename: test/request.spec.ts

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change log
22

3+
### Version: 1.3.3
4+
#### Date: Nov-10-2025
5+
- 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)
6+
37
### Version: 1.3.2
48
#### Date: Oct-27-2025
59
- Fix: Used common serialize method for query params

package-lock.json

Lines changed: 31 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
{
22
"name": "@contentstack/core",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"type": "commonjs",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/cjs/src/index.d.ts",
7+
"exports": {
8+
".": {
9+
"import": {
10+
"types": "./dist/types/src/index.d.ts",
11+
"default": "./dist/esm/src/index.js"
12+
},
13+
"require": {
14+
"types": "./dist/types/src/index.d.ts",
15+
"default": "./dist/cjs/src/index.js"
16+
}
17+
},
18+
"./package.json": "./package.json"
19+
},
720
"license": "MIT",
821
"scripts": {
922
"prepare": "npm run build && npm run husky-check",

test/esm-exports.spec.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* ESM Exports Test Suite
3+
*
4+
* Purpose: Verify that ESM and CJS builds export correctly and package.json
5+
* has proper exports field configuration for ESM compatibility.
6+
*/
7+
8+
import * as fs from 'fs';
9+
import * as path from 'path';
10+
11+
describe('ESM Exports Tests', () => {
12+
const distPath = path.join(__dirname, '..', 'dist');
13+
const esmIndexPath = path.join(distPath, 'esm', 'src', 'index.js');
14+
const cjsIndexPath = path.join(distPath, 'cjs', 'src', 'index.js');
15+
const esmRequestPath = path.join(distPath, 'esm', 'src', 'lib', 'request.js');
16+
const cjsRequestPath = path.join(distPath, 'cjs', 'src', 'lib', 'request.js');
17+
18+
describe('ESM Build Exports', () => {
19+
it('should have ESM build index.js file', () => {
20+
expect(fs.existsSync(esmIndexPath)).toBe(true);
21+
});
22+
23+
it('should export getData from ESM request.js', () => {
24+
expect(fs.existsSync(esmRequestPath)).toBe(true);
25+
const requestContent = fs.readFileSync(esmRequestPath, 'utf-8');
26+
expect(requestContent).toContain('export function getData');
27+
});
28+
29+
it('should re-export getData from ESM index.js', () => {
30+
const indexContent = fs.readFileSync(esmIndexPath, 'utf-8');
31+
expect(indexContent).toContain("export * from './lib/request'");
32+
});
33+
34+
it('should verify getData is a named export in ESM build', () => {
35+
const requestContent = fs.readFileSync(esmRequestPath, 'utf-8');
36+
expect(requestContent).toMatch(/export\s+(async\s+)?function\s+getData/);
37+
});
38+
});
39+
40+
describe('CJS Build Exports', () => {
41+
it('should have CJS build index.js file', () => {
42+
expect(fs.existsSync(cjsIndexPath)).toBe(true);
43+
});
44+
45+
it('should export getData from CJS request.js using exports.getData', () => {
46+
expect(fs.existsSync(cjsRequestPath)).toBe(true);
47+
const requestContent = fs.readFileSync(cjsRequestPath, 'utf-8');
48+
expect(requestContent).toContain('exports.getData');
49+
});
50+
51+
it('should re-export getData from CJS index.js using __exportStar', () => {
52+
const indexContent = fs.readFileSync(cjsIndexPath, 'utf-8');
53+
expect(indexContent).toContain('__exportStar(require("./lib/request")');
54+
});
55+
});
56+
57+
describe('Package.json Exports Configuration', () => {
58+
it('should have exports field in package.json', () => {
59+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
60+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
61+
expect(packageJson.exports).toBeDefined();
62+
expect(packageJson.exports['.']).toBeDefined();
63+
});
64+
65+
it('should have import condition pointing to ESM build', () => {
66+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
67+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
68+
expect(packageJson.exports['.'].import).toBeDefined();
69+
const importPath = packageJson.exports['.'].import.default || packageJson.exports['.'].import;
70+
expect(importPath).toContain('esm');
71+
});
72+
73+
it('should have require condition pointing to CJS build', () => {
74+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
75+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
76+
expect(packageJson.exports['.'].require).toBeDefined();
77+
const requirePath = packageJson.exports['.'].require.default || packageJson.exports['.'].require;
78+
expect(requirePath).toContain('cjs');
79+
});
80+
81+
it('should have types specified for both import and require', () => {
82+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
83+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
84+
const exports = packageJson.exports['.'];
85+
expect(exports.import.types).toBeDefined();
86+
expect(exports.require.types).toBeDefined();
87+
expect(exports.import.types).toContain('types');
88+
expect(exports.require.types).toContain('types');
89+
});
90+
91+
it('should verify ESM build file exists at exports path', () => {
92+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
93+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
94+
const importPath = packageJson.exports['.'].import.default || packageJson.exports['.'].import;
95+
const fullPath = path.join(__dirname, '..', importPath);
96+
expect(fs.existsSync(fullPath)).toBe(true);
97+
});
98+
99+
it('should verify CJS build file exists at exports path', () => {
100+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
101+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
102+
const requirePath = packageJson.exports['.'].require.default || packageJson.exports['.'].require;
103+
const fullPath = path.join(__dirname, '..', requirePath);
104+
expect(fs.existsSync(fullPath)).toBe(true);
105+
});
106+
});
107+
108+
describe('Source Code Imports', () => {
109+
it('should be able to import getData as named export from source', async () => {
110+
const { getData } = await import('../src');
111+
expect(getData).toBeDefined();
112+
expect(typeof getData).toBe('function');
113+
});
114+
115+
it('should verify getData is available in all exports from source', async () => {
116+
const allExports = await import('../src');
117+
expect(allExports.getData).toBeDefined();
118+
expect(typeof allExports.getData).toBe('function');
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)