Skip to content

Commit d9423c5

Browse files
committed
fix(publish): package preparation
1 parent c695073 commit d9423c5

File tree

1 file changed

+22
-1
lines changed
  • packages/plugin-tools/src/generators/publish

1 file changed

+22
-1
lines changed

packages/plugin-tools/src/generators/publish/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import parseVersionString from 'parse-version-string';
44
import { Observable } from 'rxjs';
55
import { spawn } from 'child_process';
66
import * as path from 'path';
7-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
7+
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs';
88
import { Tree, serializeJson } from '@nx/devkit';
99

1010
interface ISemVer {
@@ -88,6 +88,25 @@ export default async function (tree: Tree, schema: Schema) {
8888
await new Promise<void>((resolve, reject) => {
8989
// console.log(options.args);
9090
let cnt = 0;
91+
const cleanPackage = () => {
92+
// helps remove unwanted properties which may be added by other tooling
93+
const p = publishPackages[cnt];
94+
const packageJsonPath = path.resolve(workspaceDir, 'dist', 'packages', p, 'package.json');
95+
let packageJson: any = readFileSync(packageJsonPath, { encoding: 'utf-8' });
96+
if (packageJson) {
97+
packageJson = jsonParse(packageJson);
98+
// we don't need module or type properties at the moment
99+
delete packageJson['module'];
100+
delete packageJson['type'];
101+
writeFileSync(packageJsonPath, serializeJson(packageJson));
102+
103+
const angularNpmIgnorePath = path.resolve(workspaceDir, 'dist', 'packages', p, 'angular', '.npmignore');
104+
// remove .npmignore as we don't need it in angular folder if found
105+
if (existsSync(angularNpmIgnorePath)) {
106+
unlinkSync(angularNpmIgnorePath);
107+
}
108+
}
109+
};
91110
const buildPackage = () => {
92111
const p = publishPackages[cnt];
93112

@@ -105,6 +124,8 @@ export default async function (tree: Tree, schema: Schema) {
105124
child.on('close', (res) => {
106125
console.log('build finished with code:', res);
107126
child.kill();
127+
// cleanup anything with the package not needed
128+
cleanPackage();
108129
cnt++;
109130
if (cnt === publishPackages.length) {
110131
console.log(`✅ Successfully built ${packageVersions.map((p) => `${p.name}:${p.version}`).join(',')}`);

0 commit comments

Comments
 (0)