@webjourney/vite-plugins 1.2.9 → 1.2.10-1

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/dist/build.js CHANGED
@@ -1,8 +1,8 @@
1
+ import { JSDOM } from 'jsdom';
1
2
  import { execSync } from 'node:child_process';
2
- import { createRequire } from 'node:module';
3
3
  import fs from 'node:fs';
4
+ import { createRequire } from 'node:module';
4
5
  import path from 'node:path';
5
- import { JSDOM } from 'jsdom';
6
6
  export async function buildWithSSR(options = {}) {
7
7
  const { projectRoot = process.cwd(), appPath = 'src/App.tsx', clientBuildOptions = '--base=\'./\'' } = options;
8
8
  const toAbsolute = (p) => path.resolve(projectRoot, p);
@@ -86,6 +86,7 @@ async function prerender(projectRoot) {
86
86
  // Setup globals for React SSR
87
87
  const originalWindow = global.window;
88
88
  const originalDocument = global.document;
89
+ const originalConsoleError = console.error;
89
90
  Object.defineProperty(global, 'window', {
90
91
  writable: true,
91
92
  configurable: true,
@@ -96,6 +97,32 @@ async function prerender(projectRoot) {
96
97
  configurable: true,
97
98
  value: dom.window.document,
98
99
  });
100
+ // Track if we're in a warning block (for multi-line warnings with stack traces)
101
+ let suppressingWarning = false;
102
+ // Suppress known SSR warnings from React and Radix UI
103
+ const filterWarnings = (...args) => {
104
+ const message = args[0]?.toString() || '';
105
+ // Filter out common SSR warnings
106
+ const ignoredWarnings = [
107
+ 'Warning: ',
108
+ ];
109
+ if (ignoredWarnings.some(warning => message.includes(warning))) {
110
+ suppressingWarning = true;
111
+ return true; // Suppress the warning
112
+ }
113
+ // Check if this looks like a stack trace continuation (indented lines starting with "at")
114
+ if (suppressingWarning && message.trim().startsWith('at ')) {
115
+ return true; // Suppress stack trace lines
116
+ }
117
+ // Reset suppression for non-stack-trace lines
118
+ suppressingWarning = false;
119
+ return suppressingWarning;
120
+ };
121
+ console.error = (...args) => {
122
+ if (!filterWarnings(...args)) {
123
+ originalConsoleError(...args);
124
+ }
125
+ };
99
126
  // Import the server entry after setting up globals
100
127
  const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
101
128
  const { render } = await import(entryServerPath);
@@ -103,44 +130,51 @@ async function prerender(projectRoot) {
103
130
  const require = createRequire(path.join(projectRoot, 'package.json'));
104
131
  const reactDomServerPath = require.resolve('react-dom/server');
105
132
  const { renderToString } = await import(reactDomServerPath);
106
- // Extract routes from App.tsx
107
- const routes = await extractRoutes(projectRoot);
108
- console.log(` Found ${routes.length} route(s): ${routes.join(', ')}`);
109
- for (const route of routes) {
110
- // Render the app HTML
111
- const appHtml = renderToString(render(route));
112
- // Replace the empty root div with the rendered content
113
- let html = template.replace('<div id="root"></div>', `<div id="root">${appHtml}</div>`);
114
- // Adjust asset paths based on route depth
115
- if (route !== '/') {
116
- const depth = route.split('/').filter(Boolean).length;
117
- const prefix = '../'.repeat(depth);
118
- // Replace asset references: ./assets/ -> ../assets/ or ../../assets/ etc
119
- html = html.replace(/\.\/assets\//g, `${prefix}assets/`);
120
- }
121
- // Write the pre-rendered HTML
122
- const filePath = route === '/'
123
- ? toAbsolute('dist/index.html')
124
- : toAbsolute(`dist${route}/index.html`);
125
- // Ensure directory exists
126
- const dir = path.dirname(filePath);
127
- if (!fs.existsSync(dir)) {
128
- fs.mkdirSync(dir, { recursive: true });
133
+ try {
134
+ // Extract routes from App.tsx
135
+ const routes = await extractRoutes(projectRoot);
136
+ console.log(` Found ${routes.length} route(s): ${routes.join(', ')}`);
137
+ for (const route of routes) {
138
+ // Render the app HTML
139
+ const appHtml = renderToString(render(route));
140
+ // Replace the empty root div with the rendered content
141
+ let html = template.replace('<div id="root"></div>', `<div id="root">${appHtml}</div>`);
142
+ // Adjust asset paths based on route depth
143
+ if (route !== '/') {
144
+ const depth = route.split('/').filter(Boolean).length;
145
+ const prefix = '../'.repeat(depth);
146
+ // Replace asset references: ./assets/ -> ../assets/ or ../../assets/ etc
147
+ html = html.replace(/\.\/assets\//g, `${prefix}assets/`);
148
+ }
149
+ // Write the pre-rendered HTML
150
+ const filePath = route === '/'
151
+ ? toAbsolute('dist/index.html')
152
+ : toAbsolute(`dist${route}/index.html`);
153
+ // Ensure directory exists
154
+ const dir = path.dirname(filePath);
155
+ if (!fs.existsSync(dir)) {
156
+ fs.mkdirSync(dir, { recursive: true });
157
+ }
158
+ fs.writeFileSync(filePath, html);
159
+ console.log(` Pre-rendered: ${route}`);
129
160
  }
130
- fs.writeFileSync(filePath, html);
131
- console.log(` Pre-rendered: ${route}`);
132
- }
133
- // Clean up
134
- if (originalWindow !== undefined) {
135
- global.window = originalWindow;
136
- }
137
- else {
138
- delete global.window;
161
+ // Wait for any pending console messages to flush
162
+ await new Promise(resolve => setTimeout(resolve, 10));
139
163
  }
140
- if (originalDocument !== undefined) {
141
- global.document = originalDocument;
142
- }
143
- else {
144
- delete global.document;
164
+ finally {
165
+ // Clean up - always restore console methods even if there's an error
166
+ console.error = originalConsoleError;
167
+ if (originalWindow !== undefined) {
168
+ global.window = originalWindow;
169
+ }
170
+ else {
171
+ delete global.window;
172
+ }
173
+ if (originalDocument !== undefined) {
174
+ global.document = originalDocument;
175
+ }
176
+ else {
177
+ delete global.document;
178
+ }
145
179
  }
146
180
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EA0MrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAvOb,MAAM,MAAM,MAAM;;;;;;;6BAiNT,MAAM;KA0BlC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EA6OrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBA1Qb,MAAM,MAAM,MAAM;;;;;;;6BAoPT,MAAM;KA0BlC"}
package/dist/index.js CHANGED
@@ -116,6 +116,19 @@ export function webjourneyElementTagger() {
116
116
  modified = true;
117
117
  }
118
118
  }
119
+ // Handle anchor elements
120
+ if (tagName === 'a') {
121
+ // Check if anchor has href attribute
122
+ const hasHref = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
123
+ t.isJSXIdentifier(attr.name) &&
124
+ attr.name.name === 'href');
125
+ if (hasHref) {
126
+ // Generate unique ID: filename:line
127
+ const elementId = `${relativePath}:${lineNumber}`;
128
+ openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('link')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
129
+ modified = true;
130
+ }
131
+ }
119
132
  }
120
133
  });
121
134
  if (modified) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.9",
3
+ "version": "1.2.10-1",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",