@peers-app/peers-sdk 0.23.7 → 0.23.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,8 +44,8 @@ export declare function importExistingPackage(dataContext: DataContext, deps: IP
44
44
  * Create a new Peers package from the package template.
45
45
  *
46
46
  * Validates git/Node.js/npm first so a missing toolchain does not leave a
47
- * half-copied package directory. Then clones the template repo, patches IDs
48
- * and metadata, runs npm install + build, initializes a fresh git repo, and
47
+ * half-copied package directory. Then clones the template repo, patches
48
+ * isolated-package IDs and metadata, runs npm install + build, initializes a fresh git repo, and
49
49
  * delegates to {@link installPackageFromBundles} to register the dev bundle.
50
50
  *
51
51
  * When `location` already exists and contains a valid Peers package manifest,
@@ -15,6 +15,13 @@ const package_dev_tools_1 = require("./package-dev-tools");
15
15
  const package_installer_1 = require("./package-installer");
16
16
  const DEFAULT_TEMPLATE_REPO = "https://github.com/peers-app/peers-package-template.git";
17
17
  const TEMPLATE_CACHE_DIR = ".peers-package-template";
18
+ function patchTemplateTokens(contents, values) {
19
+ return contents
20
+ .replaceAll("<package-name>", values.packageName)
21
+ .replaceAll("<package-id>", values.packageId)
22
+ .replaceAll("<app-screen-id>", values.appScreenId)
23
+ .replaceAll("<contract-id>", values.contractId);
24
+ }
18
25
  /**
19
26
  * Convert a human-readable package name to a filesystem-safe folder slug.
20
27
  * "My Widget" → "my-widget", "camelCase Thing" → "camel-case-thing"
@@ -172,8 +179,8 @@ async function importExistingPackage(dataContext, deps, opts) {
172
179
  * Create a new Peers package from the package template.
173
180
  *
174
181
  * Validates git/Node.js/npm first so a missing toolchain does not leave a
175
- * half-copied package directory. Then clones the template repo, patches IDs
176
- * and metadata, runs npm install + build, initializes a fresh git repo, and
182
+ * half-copied package directory. Then clones the template repo, patches
183
+ * isolated-package IDs and metadata, runs npm install + build, initializes a fresh git repo, and
177
184
  * delegates to {@link installPackageFromBundles} to register the dev bundle.
178
185
  *
179
186
  * When `location` already exists and contains a valid Peers package manifest,
@@ -216,16 +223,23 @@ async function createPackage(dataContext, deps, opts) {
216
223
  }
217
224
  delete packageObj.repository;
218
225
  await deps.fs.writeFile(packageJsonPath, JSON.stringify(packageObj, null, 2));
219
- // Patch src/consts.ts placeholders
220
- const constsPath = deps.resolvePath(location, "src", "consts.ts");
221
- if (await deps.fs.exists(constsPath)) {
222
- let consts = await deps.fs.readFile(constsPath);
223
- consts = consts
224
- .replace("<package-name>", opts.name)
225
- .replace("<package-id>", packageId)
226
- .replace("<app-screen-id>", appScreenId)
227
- .replace("<contract-id>", contractId);
228
- await deps.fs.writeFile(constsPath, consts);
226
+ // Patch the isolated template's canonical IDs. consts.ts remains supported for custom
227
+ // legacy templates created before isolated package artifacts became the default.
228
+ const templateValues = {
229
+ packageId,
230
+ packageName: opts.name,
231
+ appScreenId,
232
+ contractId,
233
+ };
234
+ for (const relativePath of [
235
+ ["src", "ids.json"],
236
+ ["src", "consts.ts"],
237
+ ]) {
238
+ const templatePath = deps.resolvePath(location, ...relativePath);
239
+ if (await deps.fs.exists(templatePath)) {
240
+ const contents = await deps.fs.readFile(templatePath);
241
+ await deps.fs.writeFile(templatePath, patchTemplateTokens(contents, templateValues));
242
+ }
229
243
  }
230
244
  // Initialize as a new project: remove template git history, install, build, fresh git
231
245
  await deps.shell.exec("rm -rf .git", { cwd: location });
@@ -122,24 +122,27 @@ describe("createPackage", () => {
122
122
  peers: {},
123
123
  repository: { url: "https://github.com/peers-app/peers-package-template" },
124
124
  });
125
- const constsContent = 'export const packageId = "<package-id>";\n' +
126
- 'export const packageName = "<package-name>";\n' +
127
- 'export const appScreenId = "<app-screen-id>";\n' +
128
- 'export const contractId = "<contract-id>";\n';
125
+ const idsContent = JSON.stringify({
126
+ packageId: "<package-id>",
127
+ packageName: "<package-name>",
128
+ screenId: "<app-screen-id>",
129
+ contractId: "<contract-id>",
130
+ stateObservableName: "state",
131
+ });
129
132
  const deps = makeMockDeps({});
130
133
  const dc = mockDataContext();
131
- // Simulate: location doesn't exist, cache doesn't exist either, consts.ts exists after copy
134
+ // Simulate: location and cache do not exist; ids.json exists after the template copy.
132
135
  deps.fs.exists.mockImplementation(async (path) => {
133
136
  if (path === "/packages/my-widget")
134
137
  return false;
135
138
  if (path === "/packages/.peers-package-template")
136
139
  return false;
137
- if (path.includes("consts.ts"))
140
+ if (path.includes("ids.json"))
138
141
  return true;
139
142
  return false;
140
143
  });
141
144
  deps.fs.readJson.mockResolvedValue(JSON.parse(templatePkgJson));
142
- deps.fs.readFile.mockResolvedValue(constsContent);
145
+ deps.fs.readFile.mockResolvedValue(idsContent);
143
146
  const pvarSetter = jest.fn();
144
147
  mockGroupDeviceVar.mockReturnValue(pvarSetter);
145
148
  const mockPv = { packageVersionId: "pv001", packageId: "pkg001" };
@@ -167,15 +170,14 @@ describe("createPackage", () => {
167
170
  expect(writtenPkgJson.author).toBe("Test User");
168
171
  expect(writtenPkgJson.peers.packageId).toMatch(/^[a-z0-9]{25}$/);
169
172
  expect(writtenPkgJson.repository).toBeUndefined();
170
- // Verify consts.ts was patched
171
- const constsWriteCall = deps.fs.writeFile.mock.calls.find((c) => c[0].includes("consts.ts"));
172
- expect(constsWriteCall).toBeTruthy();
173
- const writtenConsts = constsWriteCall[1];
174
- expect(writtenConsts).not.toContain("<package-id>");
175
- expect(writtenConsts).not.toContain("<package-name>");
176
- expect(writtenConsts).not.toContain("<app-screen-id>");
177
- expect(writtenConsts).not.toContain("<contract-id>");
178
- expect(writtenConsts).toContain("My Widget");
173
+ // Verify the isolated package ID source was patched.
174
+ const idsWriteCall = deps.fs.writeFile.mock.calls.find((c) => c[0].includes("ids.json"));
175
+ expect(idsWriteCall).toBeTruthy();
176
+ const writtenIds = JSON.parse(idsWriteCall[1]);
177
+ expect(writtenIds.packageId).toMatch(/^[a-z0-9]{25}$/);
178
+ expect(writtenIds.contractId).toMatch(/^[a-z0-9]{25}$/);
179
+ expect(writtenIds.screenId).toMatch(/^[a-z0-9]{25}$/);
180
+ expect(writtenIds.packageName).toBe("My Widget");
179
181
  // Verify initialization commands
180
182
  expect(deps.shell.exec).toHaveBeenCalledWith("rm -rf .git", { cwd: "/packages/my-widget" });
181
183
  expect(deps.shell.exec).toHaveBeenCalledWith("npm install", { cwd: "/packages/my-widget" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.23.7",
3
+ "version": "0.23.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"