@clary-so/measure 0.4.7 → 0.4.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.
package/esbuild-bin.mjs CHANGED
@@ -1,44 +1,43 @@
1
1
  import * as esbuild from "esbuild";
2
- import { writeFileSync } from "fs";
2
+ import { readFileSync, writeFileSync } from "fs";
3
+ import { fileURLToPath } from "url";
4
+ import { dirname, join } from "path";
3
5
 
4
- // Step 1: Bundle just React into its own file
5
- await esbuild.build({
6
- absWorkingDir: new URL(".", import.meta.url).pathname,
7
- stdin: {
8
- contents: `module.exports = require("react");`,
9
- resolveDir: ".",
10
- },
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+
8
+ // Bundle the CLI entry with react, ink, react-reconciler, and yoga all inlined.
9
+ // Keep node builtins and heavy deps (express, socket.io) external.
10
+ const result = await esbuild.build({
11
+ absWorkingDir: __dirname,
12
+ entryPoints: ["dist/server/bin.js"],
11
13
  bundle: true,
12
14
  platform: "node",
13
15
  target: "node18",
14
- outfile: "dist/react-bundled.js",
16
+ outfile: "dist/bin-bundled.js",
17
+ // Keep native/heavy deps external — they don't have React conflicts
18
+ external: [
19
+ "express",
20
+ "cors",
21
+ "socket.io",
22
+ "commander",
23
+ "@clary-so/*",
24
+ // yoga has a native .node binary that can't be bundled
25
+ "yoga-layout-prebuilt",
26
+ ],
27
+ // Ensure single React instance by letting esbuild deduplicate
28
+ alias: {
29
+ // Force all react requires to resolve from this package's node_modules
30
+ react: join(__dirname, "node_modules/react"),
31
+ },
15
32
  define: {
16
33
  "process.env.NODE_ENV": '"production"',
17
34
  },
35
+ logLevel: "info",
18
36
  });
19
37
 
20
- // Step 2: Create a wrapper that patches require('react') to use our bundled copy,
21
- // then runs the original bin
22
- const wrapper = `#!/usr/bin/env node
23
- "use strict";
24
- const path = require("path");
25
- const Module = require("module");
26
-
27
- // Load our single bundled React instance
28
- const bundledReact = require(path.join(__dirname, "react-bundled.js"));
29
-
30
- // Patch require so all packages resolve to the same React instance
31
- const origResolve = Module._resolveFilename;
32
- Module._resolveFilename = function(request, parent, ...args) {
33
- if (request === "react") {
34
- return path.join(__dirname, "react-bundled.js");
35
- }
36
- return origResolve.call(this, request, parent, ...args);
37
- };
38
-
39
- // Now load the actual bin
40
- require("./server/bin.js");
41
- `;
38
+ // Strip duplicate shebang if present
39
+ let code = readFileSync(join(__dirname, "dist/bin-bundled.js"), "utf8");
40
+ code = code.replace(/^(#!.*\n)(#!.*\n)/, "$1");
41
+ writeFileSync(join(__dirname, "dist/bin-bundled.js"), code);
42
42
 
43
- writeFileSync(new URL("dist/bin-bundled.js", import.meta.url), wrapper);
44
- console.log("Created bin-bundled.js wrapper");
43
+ console.log("Bundled bin-bundled.js");
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@clary-so/measure",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "author": {
5
5
  "name": "Almouro",
6
6
  "email": "alexandrem@bam.tech"
7
7
  },
8
8
  "license": "MIT",
9
9
  "bin": {
10
- "perf-profiler-measure": "dist/server/bin.js"
10
+ "perf-profiler-measure": "dist/bin-bundled.js"
11
11
  },
12
12
  "bundledDependencies": [
13
13
  "react",
@@ -42,7 +42,7 @@
42
42
  "supertest": "^6.3.4"
43
43
  },
44
44
  "scripts": {
45
- "build": "yarn parcel build src/webapp/index.html",
45
+ "build": "yarn parcel build src/webapp/index.html && node esbuild-bin.mjs",
46
46
  "start": "yarn parcel src/webapp/index.html"
47
47
  },
48
48
  "publishConfig": {