diff --git a/.chronus/changes/copilot-remove-build-artifacts-from-npm-2026-7-7-14-35-46.md b/.chronus/changes/copilot-remove-build-artifacts-from-npm-2026-7-7-14-35-46.md new file mode 100644 index 00000000000..c0e84aa8cbf --- /dev/null +++ b/.chronus/changes/copilot-remove-build-artifacts-from-npm-2026-7-7-14-35-46.md @@ -0,0 +1,17 @@ +--- +changeKind: fix +packages: + - "@typespec/emitter-framework" + - "@typespec/http-canonicalization" + - "@typespec/http-client" + - "@typespec/http-client-js" + - "@typespec/http-server-js" + - "@typespec/http-specs" + - "@typespec/mutator-framework" + - "@typespec/protobuf" + - "@typespec/spec-api" + - "@typespec/spec-coverage-sdk" + - "@typespec/spector" +--- + +Exclude build artifacts from published packages \ No newline at end of file diff --git a/eng/common/scripts/package-files.test.ts b/eng/common/scripts/package-files.test.ts new file mode 100644 index 00000000000..9db3aa7cebb --- /dev/null +++ b/eng/common/scripts/package-files.test.ts @@ -0,0 +1,19 @@ +import { existsSync, readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { expect, it } from "vitest"; + +it("requires publishable packages to declare their published files", () => { + const packagesDir = new URL("../../../packages", import.meta.url); + const packagesWithoutFiles = readdirSync(packagesDir, { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .filter((entry) => { + const packageJsonPath = join(packagesDir.pathname, entry.name, "package.json"); + if (!existsSync(packageJsonPath)) return false; + + const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")); + return packageJson.private !== true && packageJson.files === undefined; + }) + .map((entry) => entry.name); + + expect(packagesWithoutFiles).toEqual([]); +}); diff --git a/packages/emitter-framework/package.json b/packages/emitter-framework/package.json index d3c61094183..212b1e6c343 100644 --- a/packages/emitter-framework/package.json +++ b/packages/emitter-framework/package.json @@ -7,6 +7,9 @@ "type": "git", "url": "git+https://github.com/microsoft/typespec.git" }, + "files": [ + "dist/**" + ], "scripts": { "build": "alloy build", "clean": "rimraf ./dist", diff --git a/packages/http-canonicalization/package.json b/packages/http-canonicalization/package.json index 2270a2ef972..4fca5426a0b 100644 --- a/packages/http-canonicalization/package.json +++ b/packages/http-canonicalization/package.json @@ -26,6 +26,9 @@ "import": "./dist/src/index.js" } }, + "files": [ + "dist/**" + ], "keywords": [], "author": "", "license": "MIT", diff --git a/packages/http-client-js/package.json b/packages/http-client-js/package.json index dfd095a80ab..9e05a5f1256 100644 --- a/packages/http-client-js/package.json +++ b/packages/http-client-js/package.json @@ -36,6 +36,10 @@ "import": "./dist/src/components/index.js" } }, + "files": [ + "dist/**", + "!dist/test/**" + ], "keywords": [ "typespec", "javascript", diff --git a/packages/http-client/package.json b/packages/http-client/package.json index 084ed248838..562d5c20d50 100644 --- a/packages/http-client/package.json +++ b/packages/http-client/package.json @@ -22,6 +22,11 @@ "import": "./dist/src/components/index.js" } }, + "files": [ + "lib/*.tsp", + "dist/**", + "!dist/test/**" + ], "peerDependencies": { "@alloy-js/core": "catalog:", "@alloy-js/typescript": "catalog:", diff --git a/packages/http-server-js/package.json b/packages/http-server-js/package.json index 80657e3f9f2..00707aa7467 100644 --- a/packages/http-server-js/package.json +++ b/packages/http-server-js/package.json @@ -31,6 +31,11 @@ "bin": { "hsjs-scaffold": "./cmd/hsjs-scaffold.mjs" }, + "files": [ + "dist/**", + "cmd/**", + "!dist/test/**" + ], "scripts": { "clean": "rimraf ./dist ./temp", "build": "pnpm build:helpers && pnpm build:src", diff --git a/packages/http-specs/package.json b/packages/http-specs/package.json index c3800fc2371..3a651e7f290 100644 --- a/packages/http-specs/package.json +++ b/packages/http-specs/package.json @@ -5,6 +5,11 @@ "description": "Spec scenarios and mock apis", "main": "dist/index.js", "type": "module", + "files": [ + "dist/**", + "specs/**", + "assets/**" + ], "scripts": { "watch": "tsc -p ./tsconfig.build.json --watch", "build": "tsc -p ./tsconfig.build.json && pnpm validate-scenarios && pnpm build:smoke", diff --git a/packages/mutator-framework/package.json b/packages/mutator-framework/package.json index 23c927bdaae..b2f9c4f37ff 100644 --- a/packages/mutator-framework/package.json +++ b/packages/mutator-framework/package.json @@ -26,6 +26,9 @@ "import": "./dist/src/index.js" } }, + "files": [ + "dist/**" + ], "keywords": [], "author": "", "license": "MIT", diff --git a/packages/protobuf/package.json b/packages/protobuf/package.json index 3e8ed2d0272..3dcea13b9d7 100644 --- a/packages/protobuf/package.json +++ b/packages/protobuf/package.json @@ -29,6 +29,11 @@ }, "type": "module", "tspMain": "lib/proto.tsp", + "files": [ + "lib/*.tsp", + "dist/**", + "!dist/test/**" + ], "scripts": { "clean": "rimraf ./dist ./temp", "build": "pnpm gen-extern-signature && tsc -p tsconfig.build.json && pnpm lint-typespec-library", diff --git a/packages/spec-api/package.json b/packages/spec-api/package.json index ee932b2c7d7..f0e778d54a4 100644 --- a/packages/spec-api/package.json +++ b/packages/spec-api/package.json @@ -8,6 +8,9 @@ "import": "./dist/index.js" } }, + "files": [ + "dist/**" + ], "scripts": { "watch": "tsc -p ./tsconfig.build.json --watch", "build": "tsc -p ./tsconfig.build.json", diff --git a/packages/spec-coverage-sdk/package.json b/packages/spec-coverage-sdk/package.json index 7c391a29d46..69642b0397d 100644 --- a/packages/spec-coverage-sdk/package.json +++ b/packages/spec-coverage-sdk/package.json @@ -4,6 +4,9 @@ "description": "Spec utility to manage the reported coverage", "main": "dist/index.js", "type": "module", + "files": [ + "dist/**" + ], "scripts": { "watch": "tsc -p ./tsconfig.build.json --watch", "build": "tsc -p ./tsconfig.build.json", diff --git a/packages/spector/package.json b/packages/spector/package.json index ef98b4a546a..d1a7121285e 100644 --- a/packages/spector/package.json +++ b/packages/spector/package.json @@ -12,6 +12,12 @@ "bin": { "tsp-spector": "./cmd/cli.mjs" }, + "files": [ + "lib/*.tsp", + "dist/**", + "cmd/**", + "!dist/test/**" + ], "scripts": { "watch": "tsc -p ./tsconfig.build.json --watch", "build": "pnpm gen-extern-signature && tsc -p tsconfig.build.json",