Skip to content

Commit

Permalink
Update npm scripts (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Aug 28, 2024
1 parent 86299a8 commit dc7d75a
Show file tree
Hide file tree
Showing 22 changed files with 186 additions and 57 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
restore-keys: |
${{ runner.os }}-connect-es-ci-
- name: make
run: make ci && make checkdiff
run: make ci
- name: Check changed files
run: node scripts/gh-diffcheck.js
40 changes: 0 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,41 @@ $(BIN)/node16: Makefile
@touch $(@)

$(BUILD)/protoc-gen-connect-es: node_modules tsconfig.base.json packages/protoc-gen-connect-es/tsconfig.json $(shell find packages/protoc-gen-connect-es/src -name '*.ts')
npm run -w packages/protoc-gen-connect-es clean
npm run -w packages/protoc-gen-connect-es build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect: $(GEN)/connect node_modules packages/connect/package.json packages/connect/scripts/* tsconfig.base.json packages/connect/tsconfig.json $(shell find packages/connect/src -name '*.ts') packages/connect/*.js
npm run -w packages/connect clean
npm run -w packages/connect build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect-node: $(BUILD)/connect $(BUILD)/connect-conformance packages/connect-node/tsconfig.json $(shell find packages/connect-node/src -name '*.ts')
npm run -w packages/connect-node clean
npm run -w packages/connect-node build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect-fastify: $(BUILD)/connect $(BUILD)/connect-node packages/connect-fastify/tsconfig.json $(shell find packages/connect-fastify/src -name '*.ts')
npm run -w packages/connect-fastify clean
npm run -w packages/connect-fastify build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect-express: $(BUILD)/connect $(BUILD)/connect-node packages/connect-express/tsconfig.json $(shell find packages/connect-express/src -name '*.ts')
npm run -w packages/connect-express clean
npm run -w packages/connect-express build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect-next: $(BUILD)/connect $(BUILD)/connect-node packages/connect-next/tsconfig.json $(shell find packages/connect-next/src -name '*.ts')
npm run -w packages/connect-next clean
npm run -w packages/connect-next build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect-web: $(GEN)/connect-web $(BUILD)/connect $(BUILD)/connect-conformance packages/connect-web/tsconfig.json $(shell find packages/connect-web/src -name '*.ts')
npm run -w packages/connect-web clean
npm run -w packages/connect-web build
@mkdir -p $(@D)
@touch $(@)

$(BUILD)/connect-conformance: $(GEN)/connect-conformance $(BUILD)/connect packages/connect-conformance/tsconfig.json $(shell find packages/connect-conformance/src -name '*.ts')
npm run -w packages/connect-conformance clean
npm run -w packages/connect-conformance build
@mkdir -p $(@D)
@touch $(@)
Expand All @@ -112,7 +104,6 @@ $(BUILD)/example: $(GEN)/example $(BUILD)/connect-web packages/example/tsconfig.
@touch $(@)

$(BUILD)/connect-migrate: packages/connect-migrate/package.json packages/connect-migrate/tsconfig.json $(shell find packages/connect-migrate/src -name '*.ts')
npm run -w packages/connect-migrate clean
npm run -w packages/connect-migrate build
@mkdir -p $(@D)
@touch $(@)
Expand Down Expand Up @@ -257,34 +248,3 @@ format: node_modules ## Format all files, adding license headers
.PHONY: bench
bench: node_modules $(GEN)/connect-web-bench $(BUILD)/connect-web ## Benchmark code size
npm run -w packages/connect-web-bench bundle-size

.PHONY: setversion
setversion: ## Set a new version in for the project, i.e. make setversion SET_VERSION=1.2.3
node scripts/set-workspace-version.js $(SET_VERSION)
npm ci
$(MAKE) all

# Recommended procedure:
# 1. Set a new version with the target `setversion`
# 2. Commit and push all changes
# 3. Login with `npm login`
# 4. Run this target, publishing to npmjs.com
# 5. Tag the release
.PHONY: release
release: all ## Release npm packages
@[ -z "$(shell git status --short)" ] || (echo "Uncommitted changes found." && exit 1);
npm publish \
--workspace packages/connect \
--workspace packages/connect-web \
--workspace packages/connect-node \
--workspace packages/connect-fastify \
--workspace packages/connect-express \
--workspace packages/connect-next \
--workspace packages/protoc-gen-connect-es \
--workspace packages/connect-migrate \

.PHONY: checkdiff
checkdiff:
@# Used in CI to verify that `make` does not produce a diff
test -z "$$(git status --porcelain | tee /dev/stderr)"

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"./packages/connect-conformance",
"./packages/connect-cloudflare"
],
"scripts": {
"clean": "git clean -Xdf",
"setversion": "node scripts/set-workspace-version.js",
"postsetversion": "npm run all",
"all": "make",
"release": "npm run all && node scripts/release.js"
},
"type": "module",
"engineStrict": true,
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/connect-conformance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"scripts": {
"generate": "buf generate buf.build/connectrpc/conformance:v1.0.2",
"clean": "rm -rf ./dist/*",
"postgenerate": "license-header src/gen",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm",
"postbuild": "connectconformance --version",
"build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/src/package.json '{\"type\":\"commonjs\"}'",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/connect-express"
},
"scripts": {
"clean": "rm -rf ./dist/*",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/connect-fastify"
},
"scripts": {
"clean": "rm -rf ./dist/*",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"connect-migrate": "bin/connect-migrate"
},
"scripts": {
"clean": "rm -rf ./dist/cjs/*",
"prebuild": "rm -rf ./dist/*",
"build": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs",
"test": "jasmine --config=jasmine.json",
"build+test": "npm run build && npm run test"
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/connect-next"
},
"scripts": {
"clean": "rm -rf ./dist/*",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/connect-node"
},
"scripts": {
"clean": "rm -rf ./dist/*",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node10 --verbatimModuleSyntax false --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-web-bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"bundle-size": "tsx src/report.ts",
"generate": "buf generate",
"postgenerate": "license-header ."
"postgenerate": "license-header src/gen"
},
"dependencies": {
"@bufbuild/buf": "^1.36.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/connect-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/connect-web"
},
"scripts": {
"clean": "rm -rf ./dist/*",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
Expand All @@ -23,6 +23,7 @@
"conformance:client:node:callback": "connectconformance --mode client --conf ./conformance/conformance-web-node.yaml -v --known-failing @./conformance/known-failing-callback-client.txt -- ./conformance/client.ts --browser node --useCallbackClient",
"jasmine": "jasmine --config=jasmine.json",
"generate": "buf generate --template browserstack/buf.gen.yaml",
"postgenerate": "license-header browserstack/gen",
"karma:browserstack": "karma start browserstack/karma.browserstack.conf.cjs"
},
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion packages/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"directory": "packages/connect"
},
"scripts": {
"clean": "rm -rf ./dist/*",
"generate": "buf generate",
"postgenerate": "license-header src/protocol-grpc/gen",
"prebuild": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm && node scripts/update-user-agent.mjs",
"build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
Expand Down
3 changes: 3 additions & 0 deletions packages/connect/src/protocol-connect/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ describe("Connect transport", function () {
}
});
});
// Special handling of set-cookie is available since Node.js v20.0.0,
// v18.14.1, v16.19.1, but not in headers-polyfill 3.1.2.
// Also see https://github.com/nodejs/undici/releases/tag/v5.19.0
if ("getSetCookie" in new Headers()) {
describe("when there is support for set-cookie", function () {
// eslint-disable-next-line @typescript-eslint/require-await
Expand Down
2 changes: 1 addition & 1 deletion packages/protoc-gen-connect-es/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"node": ">=16.0.0"
},
"scripts": {
"clean": "rm -rf ./dist/cjs/*",
"prebuild": "rm -rf ./dist/*",
"build": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs"
},
"preferUnplugged": true,
Expand Down
36 changes: 36 additions & 0 deletions scripts/gh-diffcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021-2024 The Connect Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { execSync } from "node:child_process";

if (gitUncommitted()) {
process.stdout.write(
"::error::Uncommitted changes found. Please make sure this branch is up to date, and run the command locally (for example `npx turbo format`). " +
"Verify the changes are what you want and commit them.\n",
);
execSync("git --no-pager diff", {
stdio: "inherit",
});
process.exit(1);
}

/**
* @returns {boolean}
*/
function gitUncommitted() {
const out = execSync("git status --porcelain", {
encoding: "utf-8",
});
return out.trim().length > 0;
}
Loading

0 comments on commit dc7d75a

Please sign in to comment.