wp-advads 1.0.36 → 1.0.37

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,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "wp-advads",
4
- "version": "1.0.36",
4
+ "version": "1.0.37",
5
5
  "description": "Create an Advanced Ads WordPress plugin ecosystem.",
6
6
  "author": {
7
7
  "name": "Shakeeb Ahmed",
@@ -64,17 +64,33 @@ function run( commitMessages ) {
64
64
  }
65
65
 
66
66
  process.stdout.write('Building plugin resources...')
67
- let buildScript
67
+ let pkg
68
68
  try {
69
- buildScript = JSON.parse( fs.readFileSync( 'package.json', 'utf8' ) ).scripts?.build
69
+ pkg = JSON.parse( fs.readFileSync( 'package.json', 'utf8' ) )
70
70
  } catch {
71
- buildScript = null
71
+ pkg = {}
72
72
  }
73
+ const buildScript = pkg.scripts?.build
74
+ const usesWpScripts = Object.values( pkg.scripts || {} ).some( ( script ) => /\bwp-scripts\b/.test( script ) )
73
75
 
74
76
  if ( ! buildScript ) {
75
77
  onSameLine(`${logSymbols.warning} No package.json build script, skipping`)
78
+ } else if ( /\bwp-advads\b/.test( buildScript ) || process.env.WP_ADVADS_BUILDING ) {
79
+ if ( usesWpScripts ) {
80
+ await runExec( 'npx wp-scripts build', {
81
+ env: { ...process.env, WP_ADVADS_BUILDING: '1' },
82
+ } )
83
+ onSameLine(`${logSymbols.success} Built plugin resources`);
84
+ if ( Array.isArray( commitMessages ) ) {
85
+ commitMessages.push( 'Build plugin resources' )
86
+ }
87
+ } else {
88
+ onSameLine(`${logSymbols.warning} Skipping recursive npm run build`)
89
+ }
76
90
  } else {
77
- await runExec( 'npm run build' )
91
+ await runExec( 'npm run build', {
92
+ env: { ...process.env, WP_ADVADS_BUILDING: '1' },
93
+ } )
78
94
  onSameLine(`${logSymbols.success} Built plugin resources`);
79
95
  if ( Array.isArray( commitMessages ) ) {
80
96
  commitMessages.push( 'Build plugin resources' )
@@ -136,6 +136,39 @@ test( 'resource build is skipped when package.json has no build script', async (
136
136
  } )
137
137
  } )
138
138
 
139
+ test( 'resource build is skipped when scripts.build invokes wp-advads', async () => {
140
+ await withPackage( { scripts: { build: 'rm -rf assets/dist && npx wp-advads build' } }, async () => {
141
+ await runBuild()
142
+
143
+ assert.equal(
144
+ execCalls.some( ( call ) => call.cmd === 'npm run build' ),
145
+ false
146
+ )
147
+ assert.equal( potCalled, true )
148
+ } )
149
+ } )
150
+
151
+ test( 'resource build runs wp-scripts when scripts.build invokes wp-advads', async () => {
152
+ await withPackage( {
153
+ scripts: {
154
+ build: 'rm -rf assets/dist && npx wp-advads build',
155
+ start: 'wp-scripts start',
156
+ },
157
+ }, async () => {
158
+ await runBuild()
159
+
160
+ assert.equal(
161
+ execCalls.some( ( call ) => call.cmd === 'npm run build' ),
162
+ false
163
+ )
164
+ assert.equal(
165
+ execCalls.some( ( call ) => call.cmd === 'npx wp-scripts build' ),
166
+ true
167
+ )
168
+ assert.equal( potCalled, true )
169
+ } )
170
+ } )
171
+
139
172
  test( 'composer dump receives COMPOSER_VENDOR_DIR packages', async () => {
140
173
  await runBuild()
141
174