@treeseed/core 0.4.0 → 0.4.2

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.
@@ -4,7 +4,6 @@ import { dirname, resolve } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import { createRequire } from 'node:module';
7
- import { packageRoot } from './package-tools.js';
8
7
  const require = createRequire(import.meta.url);
9
8
  const requiredPackages = [
10
9
  { name: '@treeseed/sdk', dir: 'packages/sdk', build: true },
@@ -64,8 +63,31 @@ function run(command, args, options = {}) {
64
63
  throw new Error(`Command failed: ${rendered}`);
65
64
  }
66
65
  }
66
+ function findPackageRoot(startPath) {
67
+ let current = dirname(startPath);
68
+ while (true) {
69
+ const packageJsonPath = resolve(current, 'package.json');
70
+ if (existsSync(packageJsonPath)) {
71
+ return { root: current, packageJsonPath };
72
+ }
73
+ const parent = dirname(current);
74
+ if (parent === current) {
75
+ throw new Error(`Unable to resolve package root from "${startPath}".`);
76
+ }
77
+ current = parent;
78
+ }
79
+ }
80
+ function installedPackageRoot(root, packageName) {
81
+ const segments = packageName.startsWith('@') ? packageName.split('/') : [packageName];
82
+ const packageRoot = resolve(root, 'node_modules', ...segments);
83
+ const packageJsonPath = resolve(packageRoot, 'package.json');
84
+ if (!existsSync(packageJsonPath)) {
85
+ throw new Error(`Unable to resolve installed package "${packageName}" from "${root}".`);
86
+ }
87
+ return { root: packageRoot, packageJsonPath };
88
+ }
67
89
  function resolvePackageBinary(packageName, binName = packageName, root = process.cwd()) {
68
- const packageJsonPath = require.resolve(`${packageName}/package.json`, { paths: [root, packageRoot] });
90
+ const { packageJsonPath } = installedPackageRoot(root, packageName);
69
91
  const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
70
92
  const binField = packageJson.bin;
71
93
  const relativePath = typeof binField === 'string' ? binField : binField?.[binName];
@@ -75,13 +97,6 @@ function resolvePackageBinary(packageName, binName = packageName, root = process
75
97
  return resolve(dirname(packageJsonPath), relativePath);
76
98
  }
77
99
  function runStarlightPatchFromRegistry(root) {
78
- const corePackageJsonPath = require.resolve('@treeseed/core/package.json', { paths: [root, packageRoot] });
79
- const coreRoot = dirname(corePackageJsonPath);
80
- const patchScriptPath = resolve(coreRoot, 'dist', 'scripts', 'patch-starlight-content-path.js');
81
- if (existsSync(patchScriptPath)) {
82
- run(process.execPath, [patchScriptPath], { cwd: root });
83
- return;
84
- }
85
100
  const treeseedBin = resolvePackageBinary('@treeseed/cli', 'treeseed', root);
86
101
  run(process.execPath, [treeseedBin, 'starlight:patch'], { cwd: root });
87
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Treeseed Research Hub package for Astro, Starlight, knowledge-factory content, and forms.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -31,34 +31,34 @@
31
31
  "bin": {
32
32
  "treeseed-workspace-bootstrap": "./dist/scripts/workspace-bootstrap.js"
33
33
  },
34
- "scripts": {
34
+ "scripts": {
35
35
  "setup": "npm install",
36
36
  "setup:ci": "npm ci",
37
37
  "build:dist": "node ./scripts/run-ts.mjs ./scripts/build-dist.ts",
38
38
  "prepack": "npm run build:dist",
39
39
  "starlight:patch": "node ./scripts/run-ts.mjs ./scripts/patch-starlight-content-path.ts",
40
40
  "precheck": "npm run starlight:patch",
41
- "check": "node ./scripts/run-ts.mjs ./scripts/run-fixture-astro-command.ts check",
42
- "prebuild": "npm run starlight:patch && node ./scripts/run-ts.mjs ./scripts/aggregate-book.ts",
43
- "build": "TREESEED_LOCAL_DEV_MODE=cloudflare node ./scripts/run-ts.mjs ./scripts/run-fixture-astro-command.ts build",
44
- "preview": "node ./scripts/run-ts.mjs ./scripts/run-fixture-astro-command.ts preview",
45
- "test:unit": "vitest run --config ./vitest.config.ts",
46
- "test": "npm run test:unit",
47
- "lint": "npm run fixtures:check && npm run starlight:patch && npm run build:dist",
48
- "verify:direct": "npm run release:verify",
49
- "verify:local": "node --input-type=module -e \"process.env.TREESEED_VERIFY_DRIVER='direct'; await import('@treeseed/sdk/scripts/verify-driver')\"",
50
- "verify:action": "node --input-type=module -e \"process.env.TREESEED_VERIFY_DRIVER='act'; await import('@treeseed/sdk/scripts/verify-driver')\"",
51
- "verify": "node --input-type=module -e \"await import('@treeseed/sdk/scripts/verify-driver')\"",
52
- "test:smoke": "node ./scripts/run-ts.mjs ./scripts/test-smoke.ts",
53
- "fixtures:resolve": "node ./scripts/run-ts.mjs ./scripts/fixture-tools.ts resolve",
54
- "fixtures:check": "node ./scripts/run-ts.mjs ./scripts/fixture-tools.ts check",
55
- "release:setup": "npm run setup:ci",
56
- "release:check-tag": "node ./scripts/run-ts.mjs ./scripts/assert-release-tag-version.ts",
57
- "release:verify": "node ./scripts/run-ts.mjs ./scripts/release-verify.ts",
41
+ "check": "node ./scripts/run-ts.mjs ./scripts/run-fixture-astro-command.ts check",
42
+ "prebuild": "npm run starlight:patch && node ./scripts/run-ts.mjs ./scripts/aggregate-book.ts",
43
+ "build": "TREESEED_LOCAL_DEV_MODE=cloudflare node ./scripts/run-ts.mjs ./scripts/run-fixture-astro-command.ts build",
44
+ "preview": "node ./scripts/run-ts.mjs ./scripts/run-fixture-astro-command.ts preview",
45
+ "test:unit": "vitest run --config ./vitest.config.ts",
46
+ "test": "npm run test:unit",
47
+ "lint": "npm run fixtures:check && npm run starlight:patch && npm run build:dist",
48
+ "verify:direct": "npm run release:verify",
49
+ "verify:local": "node --input-type=module -e \"process.env.TREESEED_VERIFY_DRIVER='direct'; await import('@treeseed/sdk/scripts/verify-driver')\"",
50
+ "verify:action": "node --input-type=module -e \"process.env.TREESEED_VERIFY_DRIVER='act'; await import('@treeseed/sdk/scripts/verify-driver')\"",
51
+ "verify": "node --input-type=module -e \"await import('@treeseed/sdk/scripts/verify-driver')\"",
52
+ "test:smoke": "node ./scripts/run-ts.mjs ./scripts/test-smoke.ts",
53
+ "fixtures:resolve": "node ./scripts/run-ts.mjs ./scripts/fixture-tools.ts resolve",
54
+ "fixtures:check": "node ./scripts/run-ts.mjs ./scripts/fixture-tools.ts check",
55
+ "release:setup": "npm run setup:ci",
56
+ "release:check-tag": "node ./scripts/run-ts.mjs ./scripts/assert-release-tag-version.ts",
57
+ "release:verify": "node ./scripts/run-ts.mjs ./scripts/release-verify.ts",
58
58
  "release:publish": "node ./scripts/run-ts.mjs ./scripts/publish-package.ts"
59
59
  },
60
60
  "dependencies": {
61
- "@treeseed/sdk": "^0.4.0",
61
+ "@treeseed/sdk": "^0.4.2",
62
62
  "@astrojs/check": "^0.9.8",
63
63
  "@astrojs/cloudflare": "^12.6.13",
64
64
  "@astrojs/sitemap": "3.7.0",