Skip to content

Commit

Permalink
build: skip publishing private packages (#4995)
Browse files Browse the repository at this point in the history
Fixes #4865
  • Loading branch information
sofisl committed Mar 14, 2023
1 parent c77f2b7 commit d982753
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/mono-repo-publish/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export function listChangedSubmodules(
excludeGlobs: string[] = []
): string[] {
const globs = excludeGlobs.map(glob => new mm.Minimatch(glob));
// Only checking for package.jsons in submodules that were changed
// Not checking the top-level package.json
let files = prFiles.filter(file =>
file.match(/\/package\.json$|^package\.json$/)
Expand Down Expand Up @@ -123,6 +122,16 @@ function publish(
execSync: typeof childProcess.execSync,
rmSync: typeof fs.rmSync
): ExecutionOutput {
if (fs.existsSync(resolve(directory, 'package.json'))) {
const pkg = JSON.parse(
fs.readFileSync(resolve(directory, 'package.json'), 'utf-8')
);
if (pkg.private) {
return {
output: 'skipping publication ${directory}/package.json is private',
};
}
}
const installCommand = stat(resolve(directory, 'package-lock.json'))
? 'ci'
: 'i';
Expand Down
9 changes: 9 additions & 0 deletions packages/mono-repo-publish/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,13 @@ describe('mono-repo publish', () => {
'npm publish --access=public'
);
});

it('skips package if package is set to private', () => {
const output = core.publishSubmodules(
['test/sample-private-package'],
false
);
console.log(output);
assert.deepStrictEqual(output, []);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "googleapis-samples",
"description": "The following samples show basic usage of various APIs.",
"repository": "google/google-api-nodejs-client",
"license": "Apache-2.0",
"private": true,
"engines": {
"node": ">=12.0.0"
},
"files": [
"**/*.js",
"!test/"
],
"scripts": {
"prepare": "cd typescript && tsc && cd ..",
"test": "mocha"
},
"dependencies": {
"@google-cloud/local-auth": "^2.0.0",
"express": "^4.17.1",
"googleapis": "^112.0.0",
"googleapis-common": "^6.0.0",
"nconf": "^0.12.0",
"open": "^8.0.0",
"server-destroy": "^1.0.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^5.0.0",
"mocha": "^9.0.0",
"nock": "^13.0.0",
"proxyquire": "^2.1.3",
"typescript": "^4.6.4"
}
}

0 comments on commit d982753

Please sign in to comment.