Skip to content

Commit e7e885a

Browse files
committed
fix: remove type module from package.json
1 parent f3b15e7 commit e7e885a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/scripts/build-finish.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,39 @@ function finishPreparation() {
5050
.catch((err) => console.error(err));
5151
}
5252

53+
function removeTypeModule() {
54+
const packageJsonPath = path.join('dist', 'packages', packageName, 'package.json');
55+
if (!fs.existsSync(packageJsonPath)) {
56+
console.warn(`Package JSON not found at ${packageJsonPath}. Skipping removal of "type": "module".`);
57+
return;
58+
}
59+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
60+
let changed = false;
61+
if (packageJson.type === 'module') {
62+
delete packageJson.type;
63+
changed = true;
64+
}
65+
if (packageJson.types?.endsWith('.d.d.ts')) {
66+
delete packageJson.types;
67+
changed = true;
68+
}
69+
if (packageJson.module) {
70+
delete packageJson.module;
71+
changed = true;
72+
}
73+
if (changed) {
74+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
75+
console.log(`Removed "type": "module" and related fields from ${packageJsonPath}.`);
76+
} else {
77+
console.log(`No changes needed in ${packageJsonPath}.`);
78+
}
79+
}
80+
5381
if (fs.existsSync(path.join(rootDir, 'packages', packageName, 'angular'))) {
5482
// package has angular specific src, build it first
5583
buildAngular();
5684
} else {
5785
finishPreparation();
5886
}
87+
88+
removeTypeModule();

0 commit comments

Comments
 (0)