houdini-svelte 3.0.0 → 3.0.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.
@@ -125,6 +125,8 @@ if (PLATFORM_OVERRIDE === 'wasm') {
125
125
  }
126
126
 
127
127
  // --- Native binary path ---
128
+ const attempted = [];
129
+
128
130
  function getBinaryPath() {
129
131
  if (MANUAL_BINARY_PATH && fs.existsSync(MANUAL_BINARY_PATH)) {
130
132
  return MANUAL_BINARY_PATH;
@@ -138,36 +140,82 @@ function getBinaryPath() {
138
140
  process.stderr.write(`[houdini-svelte] Unknown platform "${PLATFORM_OVERRIDE}". Valid values: ${Object.keys(BINARY_DISTRIBUTION_PACKAGES).join(', ')}, wasm\n`);
139
141
  process.exit(1);
140
142
  }
141
- return path.join(__dirname, binaryName);
143
+ return path.join(__dirname, '..', binaryName);
142
144
  }
143
145
 
146
+ // module resolution from the shim's own location: real installs, and any
147
+ // environment that provides NODE_PATH (pnpm scripts do)
144
148
  try {
145
149
  const platformPackagePath = require.resolve(`${platformSpecificPackageName}/package.json`);
146
150
  return path.join(path.dirname(platformPackagePath), 'bin', binaryName);
147
151
  } catch {
148
- const siblingPath = path.join(__dirname, '..', platformSpecificPackageName, 'bin', binaryName);
149
- if (fs.existsSync(siblingPath)) return siblingPath;
150
-
151
- const pnpmMatch = __dirname.match(/(.+\/node_modules\/)\.pnpm\/[^/]+\/node_modules\//);
152
- if (pnpmMatch) {
153
- const pnpmDir = path.join(pnpmMatch[1], '.pnpm');
154
- try {
155
- const packageJSON = require(path.join(__dirname, '..', 'package.json'));
156
- const entry = `${platformSpecificPackageName}@${packageJSON.version}`;
157
- const found = fs.readdirSync(pnpmDir).find(e => e === entry);
158
- if (found) {
159
- const p = path.join(pnpmDir, found, 'node_modules', platformSpecificPackageName, 'bin', binaryName);
160
- if (fs.existsSync(p)) return p;
161
- }
162
- } catch {}
163
- }
152
+ attempted.push(`require.resolve('${platformSpecificPackageName}') from ${__dirname}`);
153
+ }
154
+
155
+ // module resolution from the invoking project: a linked development setup puts
156
+ // the platform package in the project's node_modules, which the walk from the
157
+ // shim's realpath (inside the linked repo) never visits
158
+ try {
159
+ const platformPackagePath = require.resolve(`${platformSpecificPackageName}/package.json`, {
160
+ paths: [process.cwd()],
161
+ });
162
+ return path.join(path.dirname(platformPackagePath), 'bin', binaryName);
163
+ } catch {
164
+ attempted.push(`require.resolve('${platformSpecificPackageName}') from ${process.cwd()}`);
165
+ }
164
166
 
165
- return path.join(__dirname, binaryName);
167
+ // flat node_modules: the platform package next to this one
168
+ const siblingPath = path.join(__dirname, '..', platformSpecificPackageName, 'bin', binaryName);
169
+ if (fs.existsSync(siblingPath)) return siblingPath;
170
+ attempted.push(siblingPath);
171
+
172
+ // monorepo build layout: the shim lives at <pkg>/build/houdini-svelte/bin and the
173
+ // platform package at <pkg>/build/<platform package>
174
+ const buildSiblingPath = path.join(__dirname, '..', '..', platformSpecificPackageName, 'bin', binaryName);
175
+ if (fs.existsSync(buildSiblingPath)) return buildSiblingPath;
176
+ attempted.push(buildSiblingPath);
177
+
178
+ const pnpmMatch = __dirname.match(/(.+\/node_modules\/)\.pnpm\/[^/]+\/node_modules\//);
179
+ if (pnpmMatch) {
180
+ const pnpmDir = path.join(pnpmMatch[1], '.pnpm');
181
+ try {
182
+ const packageJSON = require(path.join(__dirname, '..', 'package.json'));
183
+ const entry = `${platformSpecificPackageName}@${packageJSON.version}`;
184
+ const found = fs.readdirSync(pnpmDir).find(e => e === entry);
185
+ if (found) {
186
+ const p = path.join(pnpmDir, found, 'node_modules', platformSpecificPackageName, 'bin', binaryName);
187
+ if (fs.existsSync(p)) return p;
188
+ }
189
+ attempted.push(path.join(pnpmDir, entry, 'node_modules', platformSpecificPackageName, 'bin', binaryName));
190
+ } catch {}
166
191
  }
192
+
193
+ // the binary postInstall downloads into the package root when no platform
194
+ // package could be installed (the shim lives in bin/, one level down)
195
+ return path.join(__dirname, '..', binaryName);
196
+ }
197
+
198
+ // Refuse to exec ourselves: when every resolution attempt fails, the final
199
+ // candidate (the postInstall download location) can be this very script — exec'ing
200
+ // it recurses forever, forking a new node per iteration until the machine chokes.
201
+ // A missing binary must be a loud error, never a spawn loop.
202
+ const binaryPath = getBinaryPath();
203
+ let realBinaryPath = null;
204
+ try {
205
+ realBinaryPath = fs.realpathSync(binaryPath);
206
+ } catch {}
207
+ if (!realBinaryPath || realBinaryPath === fs.realpathSync(__filename)) {
208
+ attempted.push(binaryPath);
209
+ process.stderr.write(
210
+ `[houdini-svelte] Could not locate the houdini-svelte binary for ${process.platform}-${process.arch}. Tried:\n` +
211
+ attempted.map((p) => ` - ${p}\n`).join('') +
212
+ `Install the platform package for your system or point HOUDINI_SVELTE_BINARY_PATH at the binary.\n`
213
+ );
214
+ process.exit(1);
167
215
  }
168
216
 
169
217
  try {
170
- execFileSync(getBinaryPath(), process.argv.slice(2), { stdio: 'inherit' });
218
+ execFileSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
171
219
  } catch (error) {
172
220
  process.exit(error.status || 1);
173
221
  }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "houdini-svelte",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/HoudiniGraphql/houdini.git"
7
7
  },
8
8
  "dependencies": {
9
+ "@jridgewell/sourcemap-codec": "^1.5.0",
9
10
  "@sveltejs/kit": "^2.63.0",
10
11
  "estree-walker": "^3.0.3",
11
12
  "rollup": "^4.61.1",
@@ -18,13 +19,13 @@
18
19
  "svelte": "^5.19.0"
19
20
  },
20
21
  "optionalDependencies": {
21
- "houdini-svelte-darwin-x64": "3.0.0",
22
- "houdini-svelte-darwin-arm64": "3.0.0",
23
- "houdini-svelte-linux-x64": "3.0.0",
24
- "houdini-svelte-linux-arm64": "3.0.0",
25
- "houdini-svelte-win32-x64": "3.0.0",
26
- "houdini-svelte-win32-arm64": "3.0.0",
27
- "houdini-svelte-wasm": "3.0.0"
22
+ "houdini-svelte-darwin-x64": "3.0.2",
23
+ "houdini-svelte-darwin-arm64": "3.0.2",
24
+ "houdini-svelte-linux-x64": "3.0.2",
25
+ "houdini-svelte-linux-arm64": "3.0.2",
26
+ "houdini-svelte-win32-x64": "3.0.2",
27
+ "houdini-svelte-win32-arm64": "3.0.2",
28
+ "houdini-svelte-wasm": "3.0.2"
28
29
  },
29
30
  "exports": {
30
31
  "./package.json": "./package.json",
package/postInstall.js CHANGED
@@ -5,7 +5,7 @@ const https = require('https')
5
5
  const child_process = require('child_process')
6
6
 
7
7
  // Adjust the version you want to install. You can also make this dynamic.
8
- const BINARY_DISTRIBUTION_VERSION = '3.0.0'
8
+ const BINARY_DISTRIBUTION_VERSION = '3.0.2'
9
9
 
10
10
  // Windows binaries end with .exe so we need to special case them.
11
11
  const binaryName = process.platform === 'win32' ? 'houdini-svelte.exe' : 'houdini-svelte'
@@ -5,3 +5,7 @@ export default function apply_transforms(framework: Framework, page: TransformPa
5
5
  code: string;
6
6
  map?: SourceMapInput;
7
7
  }>;
8
+ export declare function offset_script_sourcemap(rawMap: {
9
+ mappings: string;
10
+ names?: string[];
11
+ }, linesBefore: number, filepath: string, content: string): SourceMapInput;
@@ -1,3 +1,4 @@
1
+ import { decode, encode } from "@jridgewell/sourcemap-codec";
1
2
  import { printJS, parseJS } from "houdini";
2
3
  import { runPipeline, formatErrors } from "houdini";
3
4
  import * as recast from "recast";
@@ -23,7 +24,7 @@ async function apply_transforms(framework, page) {
23
24
  position = { start: 0, end: 0 };
24
25
  }
25
26
  } else {
26
- script = parseJS(page.content);
27
+ script = parseJS(page.content, void 0, page.filepath);
27
28
  }
28
29
  } catch (e) {
29
30
  return { code: page.content, map: page.map };
@@ -46,7 +47,7 @@ async function apply_transforms(framework, page) {
46
47
  if (rawMap) {
47
48
  const linesBefore = page.content.slice(0, position.start).split("\n").length - 1;
48
49
  const mapObj = typeof rawMap.toJSON === "function" ? rawMap.toJSON() : rawMap;
49
- map2 = { ...mapObj, mappings: ";".repeat(linesBefore) + mapObj.mappings };
50
+ map2 = offset_script_sourcemap(mapObj, linesBefore, page.filepath, page.content);
50
51
  }
51
52
  return {
52
53
  code: replace_tag_content(page.content, position.start, position.end, scriptCode),
@@ -59,6 +60,25 @@ async function apply_transforms(framework, page) {
59
60
  });
60
61
  return { code, map };
61
62
  }
63
+ function offset_script_sourcemap(rawMap, linesBefore, filepath, content) {
64
+ const decoded = decode(rawMap.mappings);
65
+ for (const line of decoded) {
66
+ for (const segment of line) {
67
+ if (segment.length >= 4) {
68
+ ;
69
+ segment[2] += linesBefore;
70
+ }
71
+ }
72
+ }
73
+ const generatedShift = Array.from({ length: linesBefore }, () => []);
74
+ return {
75
+ version: 3,
76
+ sources: [filepath],
77
+ sourcesContent: [content],
78
+ names: rawMap.names ?? [],
79
+ mappings: encode([...generatedShift, ...decoded])
80
+ };
81
+ }
62
82
  function replace_tag_content(source, start, end, insert) {
63
83
  if (start === 0 && end === 0) {
64
84
  return `<script>${insert}</script>${source}`;
@@ -67,5 +87,6 @@ function replace_tag_content(source, start, end, insert) {
67
87
  }
68
88
  const replace_between = (origin, startIndex, endIndex, insertion) => origin.substring(0, startIndex) + insertion + origin.substring(endIndex);
69
89
  export {
70
- apply_transforms as default
90
+ apply_transforms as default,
91
+ offset_script_sourcemap
71
92
  };