zig-pug 0.3.3 → 0.3.4

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/index.js CHANGED
@@ -5,13 +5,31 @@
5
5
 
6
6
  const fs = require('fs');
7
7
  const path = require('path');
8
-
9
- // Check if native addon exists
10
- const addonPath = path.join(__dirname, 'build', 'Release', 'zigpug.node');
11
- if (!fs.existsSync(addonPath)) {
8
+ const os = require('os');
9
+
10
+ // Detect platform and architecture
11
+ const platform = os.platform(); // 'linux', 'darwin', 'win32'
12
+ const arch = os.arch(); // 'x64', 'arm64'
13
+ const platformKey = `${platform}-${arch}`;
14
+
15
+ // Try to load prebuilt binary first
16
+ const prebuiltPath = path.join(__dirname, 'prebuilt-binaries', platformKey, 'zigpug.node');
17
+ const builtPath = path.join(__dirname, 'build', 'Release', 'zigpug.node');
18
+
19
+ let binding;
20
+
21
+ if (fs.existsSync(prebuiltPath)) {
22
+ // Use prebuilt binary
23
+ binding = require(prebuiltPath);
24
+ } else if (fs.existsSync(builtPath)) {
25
+ // Use locally built binary
26
+ binding = require(builtPath);
27
+ } else {
12
28
  console.error('');
13
29
  console.error('zig-pug native addon not found!');
14
30
  console.error('');
31
+ console.error(`Platform: ${platformKey}`);
32
+ console.error('');
15
33
  console.error('The native addon needs to be built. Please run:');
16
34
  console.error('');
17
35
  console.error(' cd node_modules/zig-pug && npm run install');
@@ -20,11 +38,9 @@ if (!fs.existsSync(addonPath)) {
20
38
  console.error('');
21
39
  console.error(' cd node_modules/zig-pug && bun run install');
22
40
  console.error('');
23
- throw new Error('zig-pug native addon not built. See instructions above.');
41
+ throw new Error('zig-pug native addon not found. See instructions above.');
24
42
  }
25
43
 
26
- const binding = require('./build/Release/zigpug.node');
27
-
28
44
  /**
29
45
  * PugCompiler class - High-level API for compiling Pug templates
30
46
  */
package/index.mjs CHANGED
@@ -7,17 +7,35 @@ import { createRequire } from 'module';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { dirname, join } from 'path';
9
9
  import { readFileSync, existsSync } from 'fs';
10
+ import os from 'os';
10
11
 
11
12
  const __filename = fileURLToPath(import.meta.url);
12
13
  const __dirname = dirname(__filename);
13
14
  const require = createRequire(import.meta.url);
14
15
 
15
- // Check if native addon exists
16
- const addonPath = join(__dirname, 'build', 'Release', 'zigpug.node');
17
- if (!existsSync(addonPath)) {
16
+ // Detect platform and architecture
17
+ const platform = os.platform(); // 'linux', 'darwin', 'win32'
18
+ const arch = os.arch(); // 'x64', 'arm64'
19
+ const platformKey = `${platform}-${arch}`;
20
+
21
+ // Try to load prebuilt binary first
22
+ const prebuiltPath = join(__dirname, 'prebuilt-binaries', platformKey, 'zigpug.node');
23
+ const builtPath = join(__dirname, 'build', 'Release', 'zigpug.node');
24
+
25
+ let binding;
26
+
27
+ if (existsSync(prebuiltPath)) {
28
+ // Use prebuilt binary
29
+ binding = require(prebuiltPath);
30
+ } else if (existsSync(builtPath)) {
31
+ // Use locally built binary
32
+ binding = require(builtPath);
33
+ } else {
18
34
  console.error('');
19
35
  console.error('zig-pug native addon not found!');
20
36
  console.error('');
37
+ console.error(`Platform: ${platformKey}`);
38
+ console.error('');
21
39
  console.error('The native addon needs to be built. Please run:');
22
40
  console.error('');
23
41
  console.error(' cd node_modules/zig-pug && npm run install');
@@ -26,11 +44,9 @@ if (!existsSync(addonPath)) {
26
44
  console.error('');
27
45
  console.error(' cd node_modules/zig-pug && bun run install');
28
46
  console.error('');
29
- throw new Error('zig-pug native addon not built. See instructions above.');
47
+ throw new Error('zig-pug native addon not found. See instructions above.');
30
48
  }
31
49
 
32
- const binding = require('./build/Release/zigpug.node');
33
-
34
50
  /**
35
51
  * PugCompiler class - High-level API for compiling Pug templates
36
52
  */
package/install.js CHANGED
@@ -7,10 +7,22 @@
7
7
  const { execSync, spawnSync } = require('child_process');
8
8
  const fs = require('fs');
9
9
  const path = require('path');
10
+ const os = require('os');
10
11
 
11
- const addonPath = path.join(__dirname, 'build', 'Release', 'zigpug.node');
12
+ // Detect platform
13
+ const platform = os.platform();
14
+ const arch = os.arch();
15
+ const platformKey = `${platform}-${arch}`;
12
16
 
13
- // Check if addon already exists
17
+ // Check if prebuilt binary exists
18
+ const prebuiltPath = path.join(__dirname, 'prebuilt-binaries', platformKey, 'zigpug.node');
19
+ if (fs.existsSync(prebuiltPath)) {
20
+ console.log(`✓ zig-pug: Using prebuilt binary for ${platformKey}`);
21
+ process.exit(0);
22
+ }
23
+
24
+ // Check if addon already built
25
+ const addonPath = path.join(__dirname, 'build', 'Release', 'zigpug.node');
14
26
  if (fs.existsSync(addonPath)) {
15
27
  console.log('✓ zig-pug native addon already built');
16
28
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zig-pug",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "High-performance Pug template engine powered by Zig and mujs. Native N-API addon with ES5.1 JavaScript support, full UTF-8 (emoji, accents), documentation comments (//!), and fast compilation. Compatible with Node.js and Bun.",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
@@ -18,7 +18,8 @@
18
18
  "clean": "node-gyp clean",
19
19
  "test": "node test/test.js",
20
20
  "build-prebuilts": "./build-prebuilts.sh",
21
- "prepublishOnly": "npm run build-prebuilts"
21
+ "build-binaries": "./build-node-binaries.sh",
22
+ "prepublishOnly": "npm run build-prebuilts && npm run build-binaries"
22
23
  },
23
24
  "keywords": [
24
25
  "pug",
@@ -93,6 +94,7 @@
93
94
  "README.md",
94
95
  "LICENSE",
95
96
  "include/",
96
- "prebuilts/"
97
+ "prebuilts/",
98
+ "prebuilt-binaries/"
97
99
  ]
98
100
  }