sdc-build-wp 5.0.2 → 5.0.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.
@@ -99,6 +99,9 @@ export default class ScriptsComponent extends BaseComponent {
99
99
  if (!this.project.isRunning) { return; }
100
100
  try {
101
101
  await this.process();
102
+ if (this.project.components.blocks && (path.endsWith('.js') || path.endsWith('.jsx') || path.endsWith('.ts') || path.endsWith('.tsx'))) {
103
+ await this.checkAndRebuildAffectedBlocks(path);
104
+ }
102
105
  } catch (error) {
103
106
  console.error(error);
104
107
  this.log('error', `Failed to process scripts`);
@@ -106,6 +109,35 @@ export default class ScriptsComponent extends BaseComponent {
106
109
  });
107
110
  }
108
111
 
112
+ async checkAndRebuildAffectedBlocks(changedPath) {
113
+ if (!this.project.components.blocks || !this.project.components.blocks.globs) {
114
+ return;
115
+ }
116
+ const affectedBlocks = new Set();
117
+ for (const blockPath of this.project.components.blocks.globs) {
118
+ try {
119
+ const dependencies = await this.project.components.blocks.getBlockDependencies(blockPath);
120
+ if (dependencies.includes(changedPath)) {
121
+ affectedBlocks.add(blockPath);
122
+ }
123
+ } catch (error) {
124
+ console.error(error);
125
+ }
126
+ }
127
+
128
+ if (!affectedBlocks.size) { return; }
129
+ for (const blockPath of affectedBlocks) {
130
+ try {
131
+ if (this.project.components.server?.server) {
132
+ this.project.components.server.server.notify('Building block...', 5000);
133
+ }
134
+ await this.project.components.blocks.process(blockPath);
135
+ } catch (error) {
136
+ //
137
+ }
138
+ }
139
+ }
140
+
109
141
  async lint(entry, options) {
110
142
  try {
111
143
  const eslint = new ESLint({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Custom WordPress build process.",
5
5
  "engines": {
6
6
  "node": ">=22"