@treeseed/sdk 0.4.4 → 0.4.5

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.
@@ -1,5 +1,6 @@
1
1
  export declare const packageRoot: string;
2
2
  export declare const packageScriptRoot: string;
3
+ export declare const packageDistScriptRoot: string;
3
4
  export declare const runtimeRoot: string;
4
5
  export declare function treeseedWorkspacePackageCheckoutState(root?: string): {
5
6
  mode: string;
@@ -6,7 +6,27 @@ import { createRequire } from "node:module";
6
6
  import { parse as parseYaml } from "yaml";
7
7
  const require2 = createRequire(import.meta.url);
8
8
  const scriptRoot = dirname(fileURLToPath(import.meta.url));
9
- const packageRootFromSource = resolve(scriptRoot, "..", "..", "..");
9
+ function resolveSdkPackageRoot(startDir) {
10
+ let currentDir = startDir;
11
+ while (true) {
12
+ const packageJsonPath = resolve(currentDir, "package.json");
13
+ if (existsSync(packageJsonPath)) {
14
+ try {
15
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
16
+ if (packageJson?.name === "@treeseed/sdk") {
17
+ return currentDir;
18
+ }
19
+ } catch {
20
+ }
21
+ }
22
+ const parentDir = dirname(currentDir);
23
+ if (parentDir === currentDir) {
24
+ return resolve(startDir, "..", "..", "..");
25
+ }
26
+ currentDir = parentDir;
27
+ }
28
+ }
29
+ const packageRootFromSource = resolveSdkPackageRoot(scriptRoot);
10
30
  const treeseedRuntimeRoot = resolve(packageRootFromSource, "src", "treeseed");
11
31
  const TREESEED_DEFAULT_PLUGIN_REFERENCES = [
12
32
  {
@@ -87,6 +107,7 @@ function parseManagedServicesConfig(value) {
87
107
  }
88
108
  const packageRoot = packageRootFromSource;
89
109
  const packageScriptRoot = resolve(packageRoot, "scripts");
110
+ const packageDistScriptRoot = resolve(packageRoot, "dist", "scripts");
90
111
  const runtimeRoot = treeseedRuntimeRoot;
91
112
  function resolvePackageBinary(packageName, binName = packageName) {
92
113
  const packageJsonPath = require2.resolve(`${packageName}/package.json`);
@@ -182,7 +203,15 @@ function createProductionBuildEnv(extraEnv = {}) {
182
203
  }
183
204
  function packageScriptPath(scriptName) {
184
205
  if (extname(scriptName)) {
185
- return resolve(packageScriptRoot, scriptName);
206
+ const directScriptPath = resolve(packageScriptRoot, scriptName);
207
+ if (existsSync(directScriptPath)) {
208
+ return directScriptPath;
209
+ }
210
+ const distScriptPath = resolve(packageDistScriptRoot, scriptName.replace(/\.(ts|mjs)$/u, ".js"));
211
+ if (existsSync(distScriptPath)) {
212
+ return distScriptPath;
213
+ }
214
+ return directScriptPath;
186
215
  }
187
216
  for (const extension of [".js", ".ts", ".mjs"]) {
188
217
  const candidate = resolve(packageScriptRoot, `${scriptName}${extension}`);
@@ -190,6 +219,12 @@ function packageScriptPath(scriptName) {
190
219
  return candidate;
191
220
  }
192
221
  }
222
+ for (const extension of [".js", ".mjs"]) {
223
+ const candidate = resolve(packageDistScriptRoot, `${scriptName}${extension}`);
224
+ if (existsSync(candidate)) {
225
+ return candidate;
226
+ }
227
+ }
193
228
  throw new Error(`Unable to resolve package script "${scriptName}".`);
194
229
  }
195
230
  function withProcessCwd(cwd, action) {
@@ -343,6 +378,7 @@ export {
343
378
  isWorkspaceRoot,
344
379
  loadCliDeployConfig,
345
380
  loadPackageJson,
381
+ packageDistScriptRoot,
346
382
  packageRoot,
347
383
  packageScriptPath,
348
384
  packageScriptRoot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {