zig-pug 0.3.2 → 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
@@ -3,7 +3,43 @@
3
3
  * Powered by Zig and mujs
4
4
  */
5
5
 
6
- const binding = require('./build/Release/zigpug.node');
6
+ const fs = require('fs');
7
+ const path = require('path');
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 {
28
+ console.error('');
29
+ console.error('zig-pug native addon not found!');
30
+ console.error('');
31
+ console.error(`Platform: ${platformKey}`);
32
+ console.error('');
33
+ console.error('The native addon needs to be built. Please run:');
34
+ console.error('');
35
+ console.error(' cd node_modules/zig-pug && npm run install');
36
+ console.error('');
37
+ console.error('Or if using Bun:');
38
+ console.error('');
39
+ console.error(' cd node_modules/zig-pug && bun run install');
40
+ console.error('');
41
+ throw new Error('zig-pug native addon not found. See instructions above.');
42
+ }
7
43
 
8
44
  /**
9
45
  * PugCompiler class - High-level API for compiling Pug templates
package/index.mjs CHANGED
@@ -5,14 +5,47 @@
5
5
 
6
6
  import { createRequire } from 'module';
7
7
  import { fileURLToPath } from 'url';
8
- import { dirname } from 'path';
9
- import { readFileSync } from 'fs';
8
+ import { dirname, join } from 'path';
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
- const binding = require('./build/Release/zigpug.node');
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 {
34
+ console.error('');
35
+ console.error('zig-pug native addon not found!');
36
+ console.error('');
37
+ console.error(`Platform: ${platformKey}`);
38
+ console.error('');
39
+ console.error('The native addon needs to be built. Please run:');
40
+ console.error('');
41
+ console.error(' cd node_modules/zig-pug && npm run install');
42
+ console.error('');
43
+ console.error('Or if using Bun:');
44
+ console.error('');
45
+ console.error(' cd node_modules/zig-pug && bun run install');
46
+ console.error('');
47
+ throw new Error('zig-pug native addon not found. See instructions above.');
48
+ }
16
49
 
17
50
  /**
18
51
  * PugCompiler class - High-level API for compiling Pug templates
package/install.js ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Installation script for zig-pug
4
+ * Builds the native addon if it doesn't exist
5
+ */
6
+
7
+ const { execSync, spawnSync } = require('child_process');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+
12
+ // Detect platform
13
+ const platform = os.platform();
14
+ const arch = os.arch();
15
+ const platformKey = `${platform}-${arch}`;
16
+
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');
26
+ if (fs.existsSync(addonPath)) {
27
+ console.log('✓ zig-pug native addon already built');
28
+ process.exit(0);
29
+ }
30
+
31
+ console.log('Building zig-pug native addon...');
32
+
33
+ // Try to find node-gyp (local or global)
34
+ let nodeGyp = 'node-gyp';
35
+
36
+ // Check for local node-gyp first
37
+ const localNodeGyp = path.join(__dirname, 'node_modules', '.bin', 'node-gyp');
38
+ if (fs.existsSync(localNodeGyp)) {
39
+ nodeGyp = localNodeGyp;
40
+ }
41
+
42
+ try {
43
+ // Run node-gyp rebuild
44
+ const result = spawnSync(nodeGyp, ['rebuild'], {
45
+ cwd: __dirname,
46
+ stdio: 'inherit',
47
+ shell: true
48
+ });
49
+
50
+ if (result.status !== 0) {
51
+ throw new Error(`node-gyp exited with code ${result.status}`);
52
+ }
53
+
54
+ console.log('✓ zig-pug native addon built successfully');
55
+ } catch (error) {
56
+ console.error('✗ Failed to build zig-pug native addon');
57
+ console.error('');
58
+ console.error('This package requires node-gyp and build tools to be installed.');
59
+ console.error('Please install node-gyp:');
60
+ console.error('');
61
+ console.error(' npm install -g node-gyp');
62
+ console.error('');
63
+ console.error('Or install it locally in this package:');
64
+ console.error('');
65
+ console.error(' cd node_modules/zig-pug && npm install');
66
+ console.error('');
67
+ console.error('For more information: https://github.com/nodejs/node-gyp#installation');
68
+ console.error('');
69
+ process.exit(1);
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zig-pug",
3
- "version": "0.3.2",
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",
@@ -11,13 +11,15 @@
11
11
  }
12
12
  },
13
13
  "scripts": {
14
- "install": "node-gyp rebuild",
14
+ "install": "node install.js",
15
+ "postinstall": "node install.js",
15
16
  "build": "node-gyp configure build",
16
17
  "rebuild": "node-gyp rebuild",
17
18
  "clean": "node-gyp clean",
18
19
  "test": "node test/test.js",
19
20
  "build-prebuilts": "./build-prebuilts.sh",
20
- "prepublishOnly": "npm run build-prebuilts"
21
+ "build-binaries": "./build-node-binaries.sh",
22
+ "prepublishOnly": "npm run build-prebuilts && npm run build-binaries"
21
23
  },
22
24
  "keywords": [
23
25
  "pug",
@@ -72,10 +74,10 @@
72
74
  "engines": {
73
75
  "node": ">=14.0.0"
74
76
  },
75
- "dependencies": {},
76
- "devDependencies": {
77
+ "dependencies": {
77
78
  "node-gyp": "^10.0.0"
78
79
  },
80
+ "devDependencies": {},
79
81
  "gypfile": true,
80
82
  "binary": {
81
83
  "module_name": "zigpug",
@@ -85,12 +87,14 @@
85
87
  "files": [
86
88
  "index.js",
87
89
  "index.mjs",
90
+ "install.js",
88
91
  "binding.c",
89
92
  "binding.gyp",
90
93
  "common.gypi",
91
94
  "README.md",
92
95
  "LICENSE",
93
96
  "include/",
94
- "prebuilts/"
97
+ "prebuilts/",
98
+ "prebuilt-binaries/"
95
99
  ]
96
100
  }