frontend-hamroun 1.1.41 → 1.1.42

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 (2) hide show
  1. package/bin/cli.js +42 -36
  2. package/package.json +2 -1
package/bin/cli.js CHANGED
@@ -8,7 +8,6 @@ import { fileURLToPath } from 'url';
8
8
  import chalk from 'chalk';
9
9
  import { createSpinner } from 'nanospinner';
10
10
  import { createServer } from 'http';
11
- import * as esbuild from 'esbuild';
12
11
 
13
12
  const __filename = fileURLToPath(import.meta.url);
14
13
  const __dirname = path.dirname(__filename);
@@ -16,42 +15,49 @@ const __dirname = path.dirname(__filename);
16
15
  async function createDevServer(options = {}) {
17
16
  const { port = 3000, isSSR = false } = options;
18
17
 
19
- const ctx = await esbuild.context({
20
- entryPoints: ['src/main.tsx'],
21
- bundle: true,
22
- outdir: 'dist',
23
- format: 'esm',
24
- platform: isSSR ? 'node' : 'browser',
25
- sourcemap: true,
26
- loader: { '.tsx': 'tsx', '.ts': 'tsx' },
27
- jsxFactory: '_jsx',
28
- jsxFragment: '_Fragment',
29
- banner: {
30
- js: `import { jsx as _jsx, Fragment as _Fragment } from 'frontend-hamroun';`,
31
- }
32
- });
33
-
34
- await ctx.watch();
35
-
36
- const server = createServer((req, res) => {
37
- const url = new URL(req.url || '', `http://${req.headers.host}`);
18
+ try {
19
+ const esbuild = await import('esbuild');
38
20
 
39
- if (url.pathname === '/') {
40
- res.writeHead(200, { 'Content-Type': 'text/html' });
41
- res.end(fs.readFileSync('index.html', 'utf8'));
42
- } else if (url.pathname.endsWith('.js')) {
43
- res.writeHead(200, { 'Content-Type': 'application/javascript' });
44
- res.end(fs.readFileSync(path.join('dist', url.pathname), 'utf8'));
45
- } else {
46
- res.writeHead(404);
47
- res.end();
48
- }
49
- });
50
-
51
- server.listen(port);
52
- console.log(chalk.green(`Development server running at http://localhost:${port}`));
53
-
54
- return { server, ctx };
21
+ const ctx = await esbuild.context({
22
+ entryPoints: ['src/main.tsx'],
23
+ bundle: true,
24
+ outdir: 'dist',
25
+ format: 'esm',
26
+ platform: isSSR ? 'node' : 'browser',
27
+ sourcemap: true,
28
+ loader: { '.tsx': 'tsx', '.ts': 'tsx' },
29
+ jsxFactory: '_jsx',
30
+ jsxFragment: '_Fragment',
31
+ banner: {
32
+ js: `import { jsx as _jsx, Fragment as _Fragment } from 'frontend-hamroun';`,
33
+ }
34
+ });
35
+
36
+ await ctx.watch();
37
+
38
+ const server = createServer((req, res) => {
39
+ const url = new URL(req.url || '', `http://${req.headers.host}`);
40
+
41
+ if (url.pathname === '/') {
42
+ res.writeHead(200, { 'Content-Type': 'text/html' });
43
+ res.end(fs.readFileSync('index.html', 'utf8'));
44
+ } else if (url.pathname.endsWith('.js')) {
45
+ res.writeHead(200, { 'Content-Type': 'application/javascript' });
46
+ res.end(fs.readFileSync(path.join('dist', url.pathname), 'utf8'));
47
+ } else {
48
+ res.writeHead(404);
49
+ res.end();
50
+ }
51
+ });
52
+
53
+ server.listen(port);
54
+ console.log(chalk.green(`Development server running at http://localhost:${port}`));
55
+
56
+ return { server, ctx };
57
+ } catch (error) {
58
+ console.error('Failed to load esbuild:', error);
59
+ throw error;
60
+ }
55
61
  }
56
62
 
57
63
  async function init() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.1.41",
3
+ "version": "1.1.42",
4
4
  "description": "A lightweight frontend framework with hooks and virtual DOM",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -61,6 +61,7 @@
61
61
  "dependencies": {
62
62
  "chalk": "^5.3.0",
63
63
  "commander": "^11.0.0",
64
+ "esbuild": "^0.19.2",
64
65
  "fs-extra": "^11.1.1",
65
66
  "inquirer": "^9.2.10",
66
67
  "nanospinner": "^1.1.0"