zig-pug 0.3.2 → 0.3.3

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,6 +3,26 @@
3
3
  * Powered by Zig and mujs
4
4
  */
5
5
 
6
+ const fs = require('fs');
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)) {
12
+ console.error('');
13
+ console.error('zig-pug native addon not found!');
14
+ console.error('');
15
+ console.error('The native addon needs to be built. Please run:');
16
+ console.error('');
17
+ console.error(' cd node_modules/zig-pug && npm run install');
18
+ console.error('');
19
+ console.error('Or if using Bun:');
20
+ console.error('');
21
+ console.error(' cd node_modules/zig-pug && bun run install');
22
+ console.error('');
23
+ throw new Error('zig-pug native addon not built. See instructions above.');
24
+ }
25
+
6
26
  const binding = require('./build/Release/zigpug.node');
7
27
 
8
28
  /**
package/index.mjs CHANGED
@@ -5,13 +5,30 @@
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
10
 
11
11
  const __filename = fileURLToPath(import.meta.url);
12
12
  const __dirname = dirname(__filename);
13
13
  const require = createRequire(import.meta.url);
14
14
 
15
+ // Check if native addon exists
16
+ const addonPath = join(__dirname, 'build', 'Release', 'zigpug.node');
17
+ if (!existsSync(addonPath)) {
18
+ console.error('');
19
+ console.error('zig-pug native addon not found!');
20
+ console.error('');
21
+ console.error('The native addon needs to be built. Please run:');
22
+ console.error('');
23
+ console.error(' cd node_modules/zig-pug && npm run install');
24
+ console.error('');
25
+ console.error('Or if using Bun:');
26
+ console.error('');
27
+ console.error(' cd node_modules/zig-pug && bun run install');
28
+ console.error('');
29
+ throw new Error('zig-pug native addon not built. See instructions above.');
30
+ }
31
+
15
32
  const binding = require('./build/Release/zigpug.node');
16
33
 
17
34
  /**
package/install.js ADDED
@@ -0,0 +1,58 @@
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
+
11
+ const addonPath = path.join(__dirname, 'build', 'Release', 'zigpug.node');
12
+
13
+ // Check if addon already exists
14
+ if (fs.existsSync(addonPath)) {
15
+ console.log('✓ zig-pug native addon already built');
16
+ process.exit(0);
17
+ }
18
+
19
+ console.log('Building zig-pug native addon...');
20
+
21
+ // Try to find node-gyp (local or global)
22
+ let nodeGyp = 'node-gyp';
23
+
24
+ // Check for local node-gyp first
25
+ const localNodeGyp = path.join(__dirname, 'node_modules', '.bin', 'node-gyp');
26
+ if (fs.existsSync(localNodeGyp)) {
27
+ nodeGyp = localNodeGyp;
28
+ }
29
+
30
+ try {
31
+ // Run node-gyp rebuild
32
+ const result = spawnSync(nodeGyp, ['rebuild'], {
33
+ cwd: __dirname,
34
+ stdio: 'inherit',
35
+ shell: true
36
+ });
37
+
38
+ if (result.status !== 0) {
39
+ throw new Error(`node-gyp exited with code ${result.status}`);
40
+ }
41
+
42
+ console.log('✓ zig-pug native addon built successfully');
43
+ } catch (error) {
44
+ console.error('✗ Failed to build zig-pug native addon');
45
+ console.error('');
46
+ console.error('This package requires node-gyp and build tools to be installed.');
47
+ console.error('Please install node-gyp:');
48
+ console.error('');
49
+ console.error(' npm install -g node-gyp');
50
+ console.error('');
51
+ console.error('Or install it locally in this package:');
52
+ console.error('');
53
+ console.error(' cd node_modules/zig-pug && npm install');
54
+ console.error('');
55
+ console.error('For more information: https://github.com/nodejs/node-gyp#installation');
56
+ console.error('');
57
+ process.exit(1);
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zig-pug",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
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,7 +11,8 @@
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",
@@ -72,10 +73,10 @@
72
73
  "engines": {
73
74
  "node": ">=14.0.0"
74
75
  },
75
- "dependencies": {},
76
- "devDependencies": {
76
+ "dependencies": {
77
77
  "node-gyp": "^10.0.0"
78
78
  },
79
+ "devDependencies": {},
79
80
  "gypfile": true,
80
81
  "binary": {
81
82
  "module_name": "zigpug",
@@ -85,6 +86,7 @@
85
86
  "files": [
86
87
  "index.js",
87
88
  "index.mjs",
89
+ "install.js",
88
90
  "binding.c",
89
91
  "binding.gyp",
90
92
  "common.gypi",