@webmate-studio/builder 0.1.2 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
package/src/bundler.js CHANGED
@@ -3,6 +3,9 @@ import esbuildSvelte from 'esbuild-svelte';
3
3
  import fs from 'fs/promises';
4
4
  import path from 'path';
5
5
  import pc from 'picocolors';
6
+ import { createRequire } from 'module';
7
+
8
+ const require = createRequire(import.meta.url);
6
9
 
7
10
  /**
8
11
  * Bundle island JavaScript files with esbuild
@@ -18,12 +21,26 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
18
21
 
19
22
  try {
20
23
  // Resolve paths for dependencies from builder package
24
+ // In npx environment, we need to find where the actual dependencies are installed
21
25
  const builderNodeModules = path.resolve(import.meta.dirname, '../node_modules');
22
26
 
27
+ // Also try to resolve from the process working directory (where components are)
28
+ const cwd = process.cwd();
29
+ const workspaceNodeModules = path.join(cwd, 'node_modules');
30
+
23
31
  // Determine if this file should use JSX loader
24
32
  // Only use JSX for .jsx files (React/Preact), not for .js files (Lit/Alpine/Vue/Vanilla)
25
33
  const useJsxLoader = islandPath.endsWith('.jsx');
26
34
 
35
+ // Try to resolve Svelte package path
36
+ let sveltePackagePath;
37
+ try {
38
+ sveltePackagePath = path.dirname(require.resolve('svelte/package.json'));
39
+ } catch (e) {
40
+ // Svelte not found in builder's node_modules, might be in workspace
41
+ sveltePackagePath = null;
42
+ }
43
+
27
44
  const result = await esbuild.build({
28
45
  entryPoints: [islandPath],
29
46
  bundle: true,
@@ -47,7 +64,12 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
47
64
  // JSX import source (Preact uses preact, React uses react)
48
65
  jsxImportSource: useJsxLoader ? 'preact' : undefined,
49
66
  // Alias vue to the full build (with template compiler)
50
- alias: {
67
+ // Also alias Svelte internal modules if we found the package
68
+ alias: sveltePackagePath ? {
69
+ 'vue': 'vue/dist/vue.esm-bundler.js',
70
+ 'svelte': path.join(sveltePackagePath, 'src/runtime/index.js'),
71
+ 'svelte/internal': path.join(sveltePackagePath, 'src/runtime/internal/index.js')
72
+ } : {
51
73
  'vue': 'vue/dist/vue.esm-bundler.js'
52
74
  },
53
75
  // Define Vue feature flags
@@ -66,8 +88,10 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
66
88
  ],
67
89
  // Don't bundle browser globals
68
90
  external: [],
69
- // Add builder's node_modules to resolve path so framework runtimes can be found
70
- nodePaths: [builderNodeModules],
91
+ // Add multiple resolution paths - try both builder's node_modules and workspace node_modules
92
+ nodePaths: [builderNodeModules, workspaceNodeModules],
93
+ // Enable package.json conditions for proper Svelte module resolution
94
+ conditions: ['svelte', 'browser', 'import'],
71
95
  // Log level
72
96
  logLevel: 'warning'
73
97
  });
@@ -16,8 +16,26 @@ const execAsync = promisify(exec);
16
16
  const __filename = fileURLToPath(import.meta.url);
17
17
  const __dirname = dirname(__filename);
18
18
 
19
- // Find tailwindcss binary in builder package's node_modules
20
- const tailwindBinary = join(__dirname, '..', 'node_modules', '.bin', 'tailwindcss');
19
+ // Find tailwindcss binary - try multiple locations
20
+ import { createRequire } from 'module';
21
+ const require = createRequire(import.meta.url);
22
+
23
+ let tailwindBinary;
24
+ try {
25
+ // Try to resolve tailwindcss package
26
+ const tailwindPackagePath = require.resolve('tailwindcss/package.json');
27
+ const tailwindDir = dirname(tailwindPackagePath);
28
+
29
+ // Check if we're on Windows
30
+ const isWindows = process.platform === 'win32';
31
+ const binName = isWindows ? 'tailwindcss.cmd' : 'tailwindcss';
32
+
33
+ // Use npx to run tailwindcss from the resolved package
34
+ tailwindBinary = `npx tailwindcss`;
35
+ } catch (e) {
36
+ // Fallback to old method
37
+ tailwindBinary = join(__dirname, '..', 'node_modules', '.bin', 'tailwindcss');
38
+ }
21
39
 
22
40
  /**
23
41
  * Extract Tailwind classes from HTML content
@@ -16,8 +16,26 @@ const execAsync = promisify(exec);
16
16
  const __filename = fileURLToPath(import.meta.url);
17
17
  const __dirname = dirname(__filename);
18
18
 
19
- // Find tailwindcss binary in builder package's node_modules
20
- const tailwindBinary = join(__dirname, '..', 'node_modules', '.bin', 'tailwindcss');
19
+ // Find tailwindcss binary - try multiple locations
20
+ import { createRequire } from 'module';
21
+ const require = createRequire(import.meta.url);
22
+
23
+ let tailwindBinary;
24
+ try {
25
+ // Try to resolve tailwindcss package
26
+ const tailwindPackagePath = require.resolve('tailwindcss/package.json');
27
+ const tailwindDir = dirname(tailwindPackagePath);
28
+
29
+ // Check if we're on Windows
30
+ const isWindows = process.platform === 'win32';
31
+ const binName = isWindows ? 'tailwindcss.cmd' : 'tailwindcss';
32
+
33
+ // Use npx to run tailwindcss from the resolved package
34
+ tailwindBinary = `npx tailwindcss`;
35
+ } catch (e) {
36
+ // Fallback to old method
37
+ tailwindBinary = join(__dirname, '..', 'node_modules', '.bin', 'tailwindcss');
38
+ }
21
39
 
22
40
  /**
23
41
  * Extract Tailwind classes from HTML content