Skip to content

Commit 93e6eb9

Browse files
committed
chore: core npm prepare handling
1 parent bc887df commit 93e6eb9

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

.github/workflows/npm_release_core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
# TODO: build ui-mobile-base first
3939
- name: Build @nativescript/core
40-
run: npx nx run core:build
40+
run: npx nx run core:build.npm
4141

4242
- name: Publish @nativescript/core
4343
working-directory: dist/packages/core

packages/core/project.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@
6262
},
6363
"dependsOn": ["^build"]
6464
},
65+
"build.npm": {
66+
"executor": "nx:run-commands",
67+
"options": {
68+
"commands": ["node tools/scripts/build-finish.ts core"],
69+
"parallel": false
70+
},
71+
"outputs": ["{workspaceRoot}/dist/packages/core"],
72+
"dependsOn": [
73+
{
74+
"target": "build"
75+
}
76+
]
77+
},
6578
"test": {
6679
"executor": "@nx/vite:test",
6780
"outputs": ["{options.reportsDirectory}"],

tools/scripts/build-finish.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const path = require('path');
2+
const fs = require('fs-extra');
3+
const { serializeJson, parseJson } = require('@nx/devkit');
4+
5+
const rootDir = path.resolve(path.join(__dirname, '..', '..'));
6+
7+
const cmdArgs = process.argv.slice(2);
8+
const packageName = cmdArgs[0];
9+
const publish = cmdArgs[1] === 'publish';
10+
11+
const packagePath = path.join('packages', packageName, 'package.json');
12+
const packageJson = JSON.parse(fs.readFileSync(packagePath));
13+
const npmPackageName = packageJson.name;
14+
console.log(`Building ${npmPackageName}...${publish ? 'and publishing.' : ''}`);
15+
16+
function cleanPackage() {
17+
// helps remove unwanted properties which may be added by other tooling
18+
const packageJsonPath = path.resolve(rootDir, 'dist', 'packages', packageName, 'package.json');
19+
let packageJson = fs.readFileSync(packageJsonPath, { encoding: 'utf-8' });
20+
if (packageJson) {
21+
packageJson = parseJson(packageJson);
22+
// we don't need module or type properties at the moment
23+
delete packageJson['module'];
24+
delete packageJson['type'];
25+
fs.writeFileSync(packageJsonPath, serializeJson(packageJson));
26+
}
27+
}
28+
29+
cleanPackage();
30+
console.log(`${npmPackageName} ready to publish.`);

0 commit comments

Comments
 (0)