Skip to content

Commit 9654308

Browse files
authored
fix: publish registry-compatible SDK dependencies (#811)
## Problem The published v2 prereleases cannot be installed outside this monorepo: Node ships `@reflag/flag-evaluation: workspace:*`, React/Vue ship `@reflag/browser-sdk: workspace:^`, and React Native ships `@reflag/react-sdk: workspace:^`. Changesets publishes package directories through npm, which does **not** perform Yarn's workspace-range rewriting. Successful workspace builds and `yarn pack` checks therefore missed the broken published manifests. ## Changes - Use registry-compatible dependency versions in Node, React, Vue and React Native, including Native's development dependency on Node. Yarn still transparently links the matching v2 workspaces locally. - Preserve the published evaluator `2.0.0` and the existing v1 OpenFeature dependencies. - Validate every non-private workspace manifest before the normal Changesets publish command. Reject `workspace:` ranges in dependency, optional, peer and development dependency sections; private examples can keep them. - Run guard regressions in the existing CI release-safeguard suite. Exercise actual Changesets prerelease versioning to verify regular semver dependency ranges advance correctly, and retain local-link/v1-isolation checks. - Add patch Changesets for the four affected SDKs. The current release plan selects `2.0.0-next.2` for Node, React, Vue and React Native; Browser's existing prerelease needs no packaging change. ## Verification - `yarn install --immutable` - `yarn test:release`: **17 passing release safeguards** - `yarn lerna run test:ci --stream --concurrency 1`: **1,015 passing tests plus 48 Browser E2E cases** across Chromium, Firefox and WebKit - Sequential evaluator, Node, Browser, React, Vue, Native, both OpenFeature providers and CLI builds; Management TypeScript build from its checked-in generated sources - `yarn docs`, `yarn fmt`, `yarn lint:fix`, and whitespace checks. Lint has no errors and retains the existing generated Next.js triple-slash-reference warning. - Packed all five SDKs using npm's underlying `pacote` directory packer, without Yarn manifest rewriting. Installed the candidate artifacts through a temporary loopback registry into a fresh external Yarn consumer, using registry dependencies without workspace links or resolutions. Strict direct-value TypeScript checks pass for all five SDKs; Node/evaluator/Browser/React/Vue runtime imports pass. These are locally packed current-version candidates, not newly published releases. - Negative control: the publication guard rejects all four original broken source manifests. **Local build limitation:** the root `yarn build` stops at Management SDK generation because Java is not installed. All package builds listed above, the Management TypeScript build, docs and the full test target pass; the full generator-backed build remains for CI. ## Scope and rollout No package publication, npm-tag changes, deployment, live flag/configuration changes or application migration is included. A reviewed version/release PR and corrected prerelease publication are still required; already published versions cannot be overwritten. The separate, uncommitted CLI v2 generator work is intentionally not bundled into this packaging fix and remains an application-migration prerequisite.
1 parent 144e5c3 commit 9654308

11 files changed

Lines changed: 245 additions & 20 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@reflag/node-sdk": patch
3+
"@reflag/react-sdk": patch
4+
"@reflag/vue-sdk": patch
5+
"@reflag/react-native-sdk": patch
6+
---
7+
8+
Replace workspace-only dependency ranges with registry-compatible versions so the published SDKs can be installed outside the monorepo. Keep local workspace linking and the existing v1 OpenFeature dependencies unchanged.

‎package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
"dev": "lerna run dev --parallel",
1717
"build": "lerna run build --stream",
1818
"test:ci": "lerna run test:ci --stream",
19-
"test:release": "node --test scripts/release-channel.test.mjs",
19+
"test:release": "node --test scripts/release-channel.test.mjs scripts/publish-manifests.test.mjs",
20+
"check:publish-manifests": "node scripts/publish-manifests.mjs",
2021
"test": "lerna run test --stream",
2122
"format": "yarn fmt:fix && yarn lint:fix",
2223
"lint": "yarn oxlint .",
2324
"lint:ci": "yarn oxlint .",
2425
"version-packages": "changeset version && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install",
2526
"release-packages": "yarn build && yarn release",
26-
"release": "changeset publish",
27+
"release": "yarn check:publish-manifests && changeset publish",
2728
"docs": "./docs.sh",
2829
"lint:fix": "yarn oxlint --fix .",
2930
"fmt": "yarn oxfmt --check .",

‎packages/browser-sdk/test/release.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ const bootstrapRequire = createRequire(
2323
describe("framework v1/v2 release isolation", () => {
2424
test("uses workspace v2 for React, Vue and React Native", () => {
2525
expect(browser.version).toMatch(/^2\.\d+\.\d+(?:-next\.\d+)?$/);
26-
expect(react.dependencies["@reflag/browser-sdk"]).toBe("workspace:^");
27-
expect(vue.dependencies["@reflag/browser-sdk"]).toBe("workspace:^");
26+
expect(react.dependencies["@reflag/browser-sdk"]).toBe(
27+
`^${browser.version}`,
28+
);
29+
expect(vue.dependencies["@reflag/browser-sdk"]).toBe(`^${browser.version}`);
2830
expect(native.version).toMatch(/^2\.\d+\.\d+(?:-next\.\d+)?$/);
29-
expect(native.dependencies["@reflag/react-sdk"]).toBe("workspace:^");
31+
expect(native.dependencies["@reflag/react-sdk"]).toBe(`^${react.version}`);
3032
expect(nativeRequire.resolve("@reflag/react-sdk")).toBe(
3133
resolve(__dirname, "../../react-sdk/dist/reflag-react-sdk.umd.js"),
3234
);

‎packages/flag-evaluation/test/release.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as legacy from "@reflag/flag-evaluation-v1";
66

77
import nodeSdk from "../../node-sdk/package.json";
88
import openfeature from "../../openfeature-node-provider/package.json";
9+
import evaluator from "../package.json";
910

1011
describe("v1/v2 release isolation", () => {
1112
it("resolves the legacy alias to the published package, not this workspace", () => {
@@ -17,7 +18,12 @@ describe("v1/v2 release isolation", () => {
1718
});
1819

1920
it("moves the v2 Node SDK onto the collection evaluator", () => {
20-
expect(nodeSdk.dependencies["@reflag/flag-evaluation"]).toBe("workspace:*");
21+
expect(nodeSdk.dependencies["@reflag/flag-evaluation"]).toBe(
22+
evaluator.version,
23+
);
24+
expect(require.resolve("@reflag/flag-evaluation/package.json")).toBe(
25+
resolve(__dirname, "../package.json"),
26+
);
2127
expect(nodeSdk.dependencies).not.toHaveProperty(
2228
"@reflag/flag-evaluation-v1",
2329
);

‎packages/node-sdk/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@aws-sdk/client-s3": "^3.888.0",
3636
"@googleapis/storage": "21.2.0",
3737
"@redis/client": "^5.11.0",
38-
"@reflag/flag-evaluation": "workspace:*"
38+
"@reflag/flag-evaluation": "2.0.0"
3939
},
4040
"devDependencies": {
4141
"@babel/core": "~7.29.6",

‎packages/react-native-sdk/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
},
3838
"dependencies": {
3939
"@react-native-async-storage/async-storage": "^2.2.0",
40-
"@reflag/react-sdk": "workspace:^",
40+
"@reflag/react-sdk": "^2.0.0-next.1",
4141
"react-native-sse": "^1.2.1"
4242
},
4343
"devDependencies": {
44-
"@reflag/node-sdk": "workspace:*",
44+
"@reflag/node-sdk": "2.0.0-next.1",
4545
"@reflag/tsconfig": "^0.0.2",
4646
"@types/node": "^22.12.0",
4747
"@types/react": "^19.0.12",

‎packages/react-sdk/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"fmt:fix": "oxfmt --write ."
4141
},
4242
"dependencies": {
43-
"@reflag/browser-sdk": "workspace:^",
43+
"@reflag/browser-sdk": "^2.0.0-next.1",
4444
"fast-equals": "^5.2.2"
4545
},
4646
"devDependencies": {

‎packages/vue-sdk/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"fmt:fix": "oxfmt --write ."
3939
},
4040
"dependencies": {
41-
"@reflag/browser-sdk": "workspace:^"
41+
"@reflag/browser-sdk": "^2.0.0-next.1"
4242
},
4343
"devDependencies": {
4444
"@reflag/tsconfig": "^0.0.2",

‎scripts/publish-manifests.mjs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { execFileSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
3+
import { join, resolve } from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
6+
export function assertPublishableManifest(manifest) {
7+
if (manifest.private) return;
8+
9+
// Changesets uses npm to publish directories, not Yarn's pack command.
10+
// Source manifests must therefore be installable without Yarn rewriting them.
11+
for (const field of [
12+
"dependencies",
13+
"optionalDependencies",
14+
"peerDependencies",
15+
"devDependencies",
16+
]) {
17+
for (const [name, range] of Object.entries(manifest[field] ?? {})) {
18+
if (range.startsWith("workspace:")) {
19+
throw new Error(
20+
`${manifest.name}: ${field}.${name} uses ${range}; Changesets does not rewrite workspace ranges. Use a registry-compatible version.`,
21+
);
22+
}
23+
}
24+
}
25+
}
26+
27+
export function checkPublishManifests(root) {
28+
const workspaces = execFileSync("yarn", ["workspaces", "list", "--json"], {
29+
cwd: root,
30+
encoding: "utf8",
31+
});
32+
for (const line of workspaces.trim().split("\n")) {
33+
const { location } = JSON.parse(line);
34+
const manifest = JSON.parse(
35+
readFileSync(join(root, location, "package.json"), "utf8"),
36+
);
37+
assertPublishableManifest(manifest);
38+
}
39+
}
40+
41+
if (
42+
process.argv[1] &&
43+
resolve(process.argv[1]) === fileURLToPath(import.meta.url)
44+
) {
45+
checkPublishManifests(fileURLToPath(new URL("../", import.meta.url)));
46+
}

‎scripts/publish-manifests.test.mjs‎

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync } from "node:child_process";
3+
import {
4+
mkdirSync,
5+
mkdtempSync,
6+
readFileSync,
7+
rmSync,
8+
writeFileSync,
9+
} from "node:fs";
10+
import { tmpdir } from "node:os";
11+
import { dirname, join } from "node:path";
12+
import { test } from "node:test";
13+
import { fileURLToPath } from "node:url";
14+
15+
import {
16+
assertPublishableManifest,
17+
checkPublishManifests,
18+
} from "./publish-manifests.mjs";
19+
20+
const root = fileURLToPath(new URL("../", import.meta.url));
21+
22+
for (const field of [
23+
"dependencies",
24+
"optionalDependencies",
25+
"peerDependencies",
26+
"devDependencies",
27+
]) {
28+
test(`rejects workspace ranges in published ${field}`, () => {
29+
for (const range of ["workspace:*", "workspace:^", "workspace:~2.0.0"]) {
30+
assert.throws(
31+
() =>
32+
assertPublishableManifest({
33+
name: "@reflag/example",
34+
[field]: { "@reflag/browser-sdk": range },
35+
}),
36+
(error) =>
37+
error.message.includes(
38+
`@reflag/example: ${field}.@reflag/browser-sdk uses ${range}`,
39+
),
40+
);
41+
}
42+
});
43+
}
44+
45+
test("accepts registry versions and preserves explicit v1 aliases", () => {
46+
assert.doesNotThrow(() =>
47+
assertPublishableManifest({
48+
name: "@reflag/example",
49+
dependencies: {
50+
"@reflag/flag-evaluation": "2.0.0",
51+
"@reflag/browser-sdk": "^2.0.0-next.1",
52+
"@reflag/node-sdk-v1": "npm:@reflag/node-sdk@1.8.3",
53+
},
54+
}),
55+
);
56+
assert.doesNotThrow(() =>
57+
assertPublishableManifest({ name: "no-dependencies" }),
58+
);
59+
});
60+
61+
test("private examples can continue to require workspace dependencies", () => {
62+
assert.doesNotThrow(() =>
63+
assertPublishableManifest({
64+
name: "private-example",
65+
private: true,
66+
dependencies: { "@reflag/node-sdk": "workspace:^" },
67+
}),
68+
);
69+
});
70+
71+
test("all publishable workspace manifests are registry-compatible", () => {
72+
checkPublishManifests(root);
73+
});
74+
75+
test("the normal release path checks source manifests before publication", () => {
76+
const { scripts } = JSON.parse(
77+
readFileSync(join(root, "package.json"), "utf8"),
78+
);
79+
assert.equal(
80+
scripts["check:publish-manifests"],
81+
"node scripts/publish-manifests.mjs",
82+
);
83+
assert.equal(
84+
scripts.release,
85+
"yarn check:publish-manifests && changeset publish",
86+
);
87+
assert.ok(
88+
scripts["test:release"].includes("scripts/publish-manifests.test.mjs"),
89+
);
90+
});
91+
92+
test("Changesets advances registry-compatible ranges with the next prerelease", () => {
93+
const directory = mkdtempSync(join(tmpdir(), "reflag-registry-ranges-"));
94+
const writeJSON = (path, value) => {
95+
const file = join(directory, path);
96+
mkdirSync(dirname(file), { recursive: true });
97+
writeFileSync(file, JSON.stringify(value));
98+
};
99+
const readJSON = (path) =>
100+
JSON.parse(readFileSync(join(directory, path), "utf8"));
101+
try {
102+
writeJSON("package.json", {
103+
name: "release-fixture",
104+
private: true,
105+
packageManager: "yarn@4.10.3",
106+
workspaces: ["packages/*"],
107+
});
108+
writeFileSync(join(directory, "yarn.lock"), "");
109+
writeJSON(".changeset/config.json", {
110+
changelog: false,
111+
commit: false,
112+
fixed: [],
113+
linked: [],
114+
access: "public",
115+
baseBranch: "main",
116+
updateInternalDependencies: "patch",
117+
ignore: [],
118+
});
119+
writeJSON("packages/browser-sdk/package.json", {
120+
name: "@reflag/browser-sdk",
121+
version: "2.0.0-next.1",
122+
});
123+
writeJSON("packages/react-sdk/package.json", {
124+
name: "@reflag/react-sdk",
125+
version: "2.0.0-next.1",
126+
dependencies: { "@reflag/browser-sdk": "^2.0.0-next.1" },
127+
});
128+
writeJSON(".changeset/pre.json", {
129+
mode: "pre",
130+
tag: "next",
131+
initialVersions: {
132+
"@reflag/browser-sdk": "2.0.0-next.0",
133+
"@reflag/react-sdk": "2.0.0-next.0",
134+
},
135+
changesets: ["sdk-major"],
136+
});
137+
for (const [name, type] of [
138+
["sdk-major", "major"],
139+
["packaging-fix", "patch"],
140+
]) {
141+
writeFileSync(
142+
join(directory, `.changeset/${name}.md`),
143+
`---\n"@reflag/browser-sdk": ${type}\n"@reflag/react-sdk": ${type}\n---\n\nSDK release\n`,
144+
);
145+
}
146+
execFileSync(
147+
process.execPath,
148+
[fileURLToPath(import.meta.resolve("@changesets/cli/bin.js")), "version"],
149+
{ cwd: directory, stdio: "pipe" },
150+
);
151+
assert.equal(
152+
readJSON("packages/browser-sdk/package.json").version,
153+
"2.0.0-next.2",
154+
);
155+
const react = readJSON("packages/react-sdk/package.json");
156+
assert.equal(react.version, "2.0.0-next.2");
157+
assert.equal(react.dependencies["@reflag/browser-sdk"], "^2.0.0-next.2");
158+
assertPublishableManifest(react);
159+
} finally {
160+
rmSync(directory, { recursive: true, force: true });
161+
}
162+
});

0 commit comments

Comments
 (0)