Skip to content

Commit a186688

Browse files
authored
Fix for publishing from stable branches (#867)
1 parent 4baf0f3 commit a186688

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

.ado/publish.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,21 @@ jobs:
6464
script: node scripts/bump-oss-version.js --nightly
6565
condition: eq(variables['Build.SourceBranchName'], 'master')
6666

67+
# Publish will fail if package.json is marked as private
68+
- task: CmdLine@2
69+
displayName: Remove workspace config from package.json
70+
inputs:
71+
script: node .ado/removeWorkspaceConfig.js
72+
6773
- script: npm publish --tag $(npmDistTag) --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$(npmAuthToken)
6874
displayName: Publish react-native-macos to npmjs.org
6975

76+
# Put the private flag back so that the removal does not get committed by the tag release step
77+
- task: CmdLine@2
78+
displayName: Restore package.json workspace config
79+
inputs:
80+
script: node .ado/restoreWorkspaceConfig.js
81+
7082
- task: CmdLine@2
7183
displayName: 'Tag published release'
7284
inputs:

.ado/removeWorkspaceConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-check
2+
const {removeWorkspaceConfig} = require('./versionUtils');
3+
removeWorkspaceConfig();

.ado/restoreWorkspaceConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-check
2+
const {restoreWorkspaceConfig} = require('./versionUtils');
3+
restoreWorkspaceConfig();

.ado/versionUtils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,28 @@ function updateVersionsInFiles(patchVersionPrefix) {
4747
return {releaseVersion, branchVersionSuffix};
4848
}
4949

50+
const workspaceJsonPath = path.resolve(require('os').tmpdir(), 'rnpkg.json');
51+
52+
function removeWorkspaceConfig() {
53+
let {pkgJson} = gatherVersionInfo();
54+
fs.writeFileSync(workspaceJsonPath, JSON.stringify(pkgJson, null, 2));
55+
delete pkgJson.private;
56+
delete pkgJson.workspaces;
57+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
58+
console.log(`Removing workspace config from package.json to prepare to publish.`);
59+
}
60+
61+
function restoreWorkspaceConfig() {
62+
let pkgJson = JSON.parse(fs.readFileSync(workspaceJsonPath, "utf8"));
63+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
64+
console.log(`Restoring workspace config from package.json`);
65+
}
66+
5067
module.exports = {
5168
gatherVersionInfo,
5269
publishBranchName,
5370
pkgJsonPath,
71+
removeWorkspaceConfig,
72+
restoreWorkspaceConfig,
5473
updateVersionsInFiles
5574
}

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Ensure scripts always have Unix newlines, even on Windows.
22
*.command text eol=lf
33
*.sh text eol=lf
4+
# Windows files should use crlf line endings
5+
# https://help.github.com/articles/dealing-with-line-endings/
6+
*.bat text eol=crlf

0 commit comments

Comments
 (0)