@rust-js/build 0.0.1 → 0.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.
Files changed (3) hide show
  1. package/build.js +12 -6
  2. package/cargo.js +12 -7
  3. package/package.json +1 -1
package/build.js CHANGED
@@ -161,16 +161,22 @@ export function createNativeBuilder({ root, rustJs = findCompiler(root), resourc
161
161
  return { flags, react };
162
162
  }
163
163
 
164
+ // The Rust a Cargo build runs: the compiler's, as it says it was built
165
+ // with, as an app in Cargo mode has no resources; without a compiler, the
166
+ // resources' pin, for the committed JS's fallback.
167
+ const toolchain = async () => (existsSync(rustJs) ? (await compilerIdentity()).toolchain : pinned());
168
+
164
169
  return {
165
- /** A Cargo workspace's check (ADR 0101), with the pinned toolchain, this
166
- * compiler, and the React the project has installed. */
170
+ /** A Cargo workspace's check (ADR 0101), with the compiler's toolchain,
171
+ * this compiler, and the React the project has installed. */
167
172
  async checkCargo(options) {
168
- checkRuntime(root, (await compilerIdentity()).version);
169
- return checkCargo({ ...options, toolchain: pinned(), compiler: rustJs, react: installedReact(root) ?? undefined });
173
+ const identity = await compilerIdentity();
174
+ checkRuntime(root, identity.version);
175
+ return checkCargo({ ...options, toolchain: identity.toolchain, compiler: rustJs, react: installedReact(root) ?? undefined });
170
176
  },
171
177
  /** The workspace of a Cargo manifest, and its target directory. */
172
- cargoWorkspace(options) {
173
- return cargoWorkspace({ ...options, toolchain: pinned() });
178
+ async cargoWorkspace(options) {
179
+ return cargoWorkspace({ ...options, toolchain: await toolchain() });
174
180
  },
175
181
  watchFiles: [...metadataInputs, ...(bindings.length ? [join(repo, "package.json")] : []), ...compilerInputs, ...Object.values(externs)],
176
182
  prepare,
package/cargo.js CHANGED
@@ -5,7 +5,7 @@ import { execFile } from "node:child_process";
5
5
  import { createHash } from "node:crypto";
6
6
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7
7
  import { tmpdir } from "node:os";
8
- import { dirname, join, relative, resolve, sep } from "node:path";
8
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
9
9
  import { promisify } from "node:util";
10
10
 
11
11
  import { fingerprint } from "./publish.js";
@@ -195,15 +195,20 @@ export function writeInSource(manifests) {
195
195
  for (const { modules } of manifests) {
196
196
  for (const { file, map } of modules) {
197
197
  const to = moved.get(file);
198
- const text = readFileSync(file, "utf8").replace(/((?:from|import)\s*\(?\s*)"(\.{1,2}\/[^"]+)"/g, (whole, lead, spec) => {
199
- const target = moved.get(resolve(dirname(file), spec));
200
- if (!target) return whole;
201
- const path = relative(dirname(to), target);
202
- return `${lead}"${path.startsWith(".") ? path : `./${path}`}"`;
203
- });
198
+ const text = readFileSync(file, "utf8")
199
+ .replace(/((?:from|import)\s*\(?\s*)"(\.{1,2}\/[^"]+)"/g, (whole, lead, spec) => {
200
+ const target = moved.get(resolve(dirname(file), spec));
201
+ if (!target) return whole;
202
+ const path = relative(dirname(to), target);
203
+ return `${lead}"${path.startsWith(".") ? path : `./${path}`}"`;
204
+ })
205
+ // Its map is beside it, by its name now, where a root of another
206
+ // name, `src/App.rs`'s, was written as the build's `lib.js`.
207
+ .replace(/^\/\/# sourceMappingURL=\S+$/m, `//# sourceMappingURL=${basename(to)}.map`);
204
208
  write(to, text);
205
209
  if (map && existsSync(map)) {
206
210
  const json = JSON.parse(readFileSync(map, "utf8"));
211
+ json.file = basename(to);
207
212
  json.sources = (json.sources ?? []).map((path) => relative(dirname(to), resolve(dirname(map), path)));
208
213
  write(`${to}.map`, JSON.stringify(json));
209
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rust-js/build",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "description": "Build preparation, manifests, and publication for rust-js hosts.",
6
6
  "license": "MIT",