From 93e6eb9687372baf2d17d6069bc05325e4df6536 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Wed, 7 May 2025 13:31:16 -0700 Subject: [PATCH] chore: core npm prepare handling --- .github/workflows/npm_release_core.yml | 2 +- packages/core/project.json | 13 +++++++++++ tools/scripts/build-finish.ts | 30 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tools/scripts/build-finish.ts diff --git a/.github/workflows/npm_release_core.yml b/.github/workflows/npm_release_core.yml index 7b3eb9d3c..65b50ea8f 100644 --- a/.github/workflows/npm_release_core.yml +++ b/.github/workflows/npm_release_core.yml @@ -37,7 +37,7 @@ jobs: # TODO: build ui-mobile-base first - name: Build @nativescript/core - run: npx nx run core:build + run: npx nx run core:build.npm - name: Publish @nativescript/core working-directory: dist/packages/core diff --git a/packages/core/project.json b/packages/core/project.json index 09d328b0e..92685feb5 100644 --- a/packages/core/project.json +++ b/packages/core/project.json @@ -62,6 +62,19 @@ }, "dependsOn": ["^build"] }, + "build.npm": { + "executor": "nx:run-commands", + "options": { + "commands": ["node tools/scripts/build-finish.ts core"], + "parallel": false + }, + "outputs": ["{workspaceRoot}/dist/packages/core"], + "dependsOn": [ + { + "target": "build" + } + ] + }, "test": { "executor": "@nx/vite:test", "outputs": ["{options.reportsDirectory}"], diff --git a/tools/scripts/build-finish.ts b/tools/scripts/build-finish.ts new file mode 100644 index 000000000..9f2975468 --- /dev/null +++ b/tools/scripts/build-finish.ts @@ -0,0 +1,30 @@ +const path = require('path'); +const fs = require('fs-extra'); +const { serializeJson, parseJson } = require('@nx/devkit'); + +const rootDir = path.resolve(path.join(__dirname, '..', '..')); + +const cmdArgs = process.argv.slice(2); +const packageName = cmdArgs[0]; +const publish = cmdArgs[1] === 'publish'; + +const packagePath = path.join('packages', packageName, 'package.json'); +const packageJson = JSON.parse(fs.readFileSync(packagePath)); +const npmPackageName = packageJson.name; +console.log(`Building ${npmPackageName}...${publish ? 'and publishing.' : ''}`); + +function cleanPackage() { + // helps remove unwanted properties which may be added by other tooling + const packageJsonPath = path.resolve(rootDir, 'dist', 'packages', packageName, 'package.json'); + let packageJson = fs.readFileSync(packageJsonPath, { encoding: 'utf-8' }); + if (packageJson) { + packageJson = parseJson(packageJson); + // we don't need module or type properties at the moment + delete packageJson['module']; + delete packageJson['type']; + fs.writeFileSync(packageJsonPath, serializeJson(packageJson)); + } +} + +cleanPackage(); +console.log(`${npmPackageName} ready to publish.`);