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
12 changes: 12 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
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();
20 changes: 20 additions & 0 deletions .ado/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,29 @@ function updateVersionsInFiles(patchVersionPrefix) {
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