Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.64] Fix publish builds by removing workspace from package.json before publish #866

Merged
merged 9 commits into from
Oct 28, 2021
2 changes: 1 addition & 1 deletion .ado/npmOfficePack.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function doPublish(fakeMode) {
if (!onlyTagSource) {
// -------- Generating Android Artifacts with JavaDoc
const depsEnvPrefix = "REACT_NATIVE_BOOST_PATH=" + path.join(process.env.BUILD_SOURCESDIRECTORY, "build_deps");
const gradleCommand = path.join(process.env.BUILD_SOURCESDIRECTORY, "gradlew") + " installArchives";
const gradleCommand = path.join(process.env.BUILD_SOURCESDIRECTORY, "gradlew") + " installArchives -Pparam=\"excludeLibs\"";
exec( depsEnvPrefix + " " + gradleCommand );

// undo uncommenting javadoc setting
Expand Down
18 changes: 18 additions & 0 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ jobs:
script: node scripts/bump-oss-version.js --nightly
condition: eq(variables['Build.SourceBranchName'], 'master')

# Publish will fail if package.json is marked as private
- task: CmdLine@2
displayName: Remove workspace config from package.json
inputs:
script: node .ado/removeWorkspaceConfig.js

- script: npm publish --tag $(npmDistTag) --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$(npmAuthToken)
displayName: Publish react-native-macos to npmjs.org

# Put the private flag back so that the removal does not get committed by the tag release step
- task: CmdLine@2
displayName: Restore package.json workspace config
inputs:
script: node .ado/restoreWorkspaceConfig.js

- task: CmdLine@2
displayName: 'Tag published release'
inputs:
Expand Down Expand Up @@ -137,6 +149,12 @@ jobs:
inputs:
script: node .ado/bumpOfficeFileVersions.js

# Publish will fail if package.json is marked as private
- task: CmdLine@2
displayName: Remove workspace config from package.json
inputs:
script: node .ado/removeWorkspaceConfig.js

- task: CmdLine@2
displayName: gradlew installArchives
inputs:
Expand Down
3 changes: 3 additions & 0 deletions .ado/removeWorkspaceConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-check
const {removeWorkspaceConfig} = require('./versionUtils');
removeWorkspaceConfig();
3 changes: 3 additions & 0 deletions .ado/restoreWorkspaceConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-check
const {restoreWorkspaceConfig} = require('./versionUtils');
restoreWorkspaceConfig();
25 changes: 23 additions & 2 deletions .ado/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require("fs");
const path = require("path");
const semver = require('semver');
const {execSync} = require('child_process');

const pkgJsonPath = path.resolve(__dirname, "../package.json");
let publishBranchName = '';
Expand Down Expand Up @@ -41,15 +42,35 @@ function updateVersionsInFiles(patchVersionPrefix) {
}

pkgJson.version = releaseVersion;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Updating package.json to version ${releaseVersion}`);
console.log(`Bumping files to version ${releaseVersion}`);
execSync(`node ./scripts/bump-oss-version.js --rnmpublish ${releaseVersion}`, {stdio: 'inherit'});

return {releaseVersion, branchVersionSuffix};
}


const workspaceJsonPath = path.resolve(require('os').tmpdir(), 'rnpkg.json');

function removeWorkspaceConfig() {
let {pkgJson} = gatherVersionInfo();
fs.writeFileSync(workspaceJsonPath, JSON.stringify(pkgJson, null, 2));
delete pkgJson.private;
delete pkgJson.workspaces;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Removing workspace config from package.json to prepare to publish.`);
}

function restoreWorkspaceConfig() {
let pkgJson = JSON.parse(fs.readFileSync(workspaceJsonPath, "utf8"));
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Restoring workspace config from package.json`);
}

module.exports = {
gatherVersionInfo,
publishBranchName,
pkgJsonPath,
removeWorkspaceConfig,
restoreWorkspaceConfig,
updateVersionsInFiles
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ensure scripts always have Unix newlines, even on Windows.
*.command text eol=lf
*.sh text eol=lf
# Windows files should use crlf line endings
# https://help.github.com/articles/dealing-with-line-endings/
*.bat text eol=crlf
Loading