rw-elements-tools 1.3.0 → 1.3.2

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.
@@ -116,42 +116,34 @@ async function buildOne(sharedFiles, sourcePath, projectRoot, minify = true) {
116
116
 
117
117
  // Read the component source
118
118
  let componentContent = await fs.promises.readFile(sourcePath, 'utf8');
119
+ const hasExportLine = /exports\.transformHook\s*=/.test(componentContent);
119
120
 
120
- // Remove any existing exports.transformHook line (we'll add our own export marker)
121
- componentContent = componentContent.replace(/^\s*exports\.transformHook\s*=.*$/gm, '').trim();
121
+ // Ensure the expected CommonJS export is present exactly once
122
+ if (!hasExportLine) {
123
+ componentContent = `${componentContent.trim()}\nexports.transformHook = transformHook;`;
124
+ }
122
125
 
123
- // Concatenate everything and add an ESM export marker for DCE
124
- // esbuild will keep transformHook and anything it references, drop the rest
126
+ // Concatenate everything
125
127
  const combinedSource = `
126
128
  ${sharedPieces.join('\n\n')}
127
129
 
128
130
  ${componentContent}
129
-
130
- export { transformHook };
131
131
  `;
132
132
 
133
- // Use esbuild transform with DCE
134
- // minifySyntax: true enables dead code elimination
135
- // When minify=true, also minify whitespace and identifiers
133
+ // Minify whitespace only (keep identifier names); enable syntax minification for small size
136
134
  const result = await transform(combinedSource, {
137
135
  loader: 'js',
138
136
  target: 'es2018',
139
- minifySyntax: true, // Always enable DCE
140
- minifyWhitespace: minify, // Minify whitespace when minify=true
141
- minifyIdentifiers: minify, // Minify variable names when minify=true
142
- format: 'esm',
137
+ minifySyntax: minify,
138
+ minifyWhitespace: minify,
139
+ minifyIdentifiers: false,
140
+ format: 'cjs',
143
141
  legalComments: 'none',
144
142
  });
145
143
 
146
- let code = result.code;
147
-
148
- // Replace ESM export with CommonJS-style assignment
149
- code = code.replace(/export\s*\{\s*transformHook\s*(as\s+\w+)?\s*\}\s*;?\s*$/m, 'exports.transformHook = transformHook;');
150
-
151
- // Only add banner in non-minified mode to save bytes
152
144
  const banner = minify ? '' : `// AUTO-GENERATED: do not edit. Edit hooks.source.js instead.\n`;
153
145
 
154
- await fs.promises.writeFile(outputPath, banner + code, 'utf8');
146
+ await fs.promises.writeFile(outputPath, banner + result.code, 'utf8');
155
147
 
156
148
  console.log(`[hooks] Wrote ${path.relative(projectRoot, outputPath)}`);
157
149
  }
@@ -145,19 +145,19 @@ const ButtonFontAndTextStyles = [
145
145
  }
146
146
  },
147
147
  {
148
- title: "Line Height",
149
- id: "globalButtonFontAndTextStylesLineHeight",
150
- format: "leading-{{value}}",
148
+ title: "Spacing",
149
+ id: "globalButtonFontAndTextStylesLetterSpacing",
150
+ format: "tracking-{{value}}",
151
151
  slider: {
152
- use: "LineHeight",
152
+ use: "LetterSpacing",
153
153
  }
154
154
  },
155
155
  {
156
- title: "Letter Spacing",
157
- id: "globalButtonFontAndTextStylesLetterSpacing",
158
- format: "tracking-{{value}}",
156
+ title: "Line Height",
157
+ id: "globalButtonFontAndTextStylesLineHeight",
158
+ format: "leading-{{value}}",
159
159
  slider: {
160
- use: "LetterSpacing",
160
+ use: "LineHeight",
161
161
  }
162
162
  },
163
163
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rw-elements-tools",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Build tools for RapidWeaver Elements packs - generates properties.json and hooks.js files",
5
5
  "author": "Elements Platform",
6
6
  "license": "MIT",