vbapm 0.7.0 → 0.8.0

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.
Files changed (59) hide show
  1. package/README.md +40 -0
  2. package/addins/build/vbapm.xlam +0 -0
  3. package/lib/actions/export-project.d.ts +2 -0
  4. package/lib/actions/update-project.d.ts +7 -0
  5. package/lib/{add-source-_Z4tr2ea.js → add-source-BOumGmx7.js} +1 -1
  6. package/lib/addin.d.ts +1 -0
  7. package/lib/bin/vbapm-update.d.ts +2 -0
  8. package/lib/build-project-De7NPBpt.js +3 -0
  9. package/lib/build-target-ooHNsSLD.js +9 -0
  10. package/lib/{create-project-CTAlegO8.js → create-project-BYc3XMZw.js} +1 -1
  11. package/lib/errors.d.ts +2 -0
  12. package/lib/export-project-CgFMyE-g.js +4 -0
  13. package/lib/export-target-C0RYJqUX.js +4 -0
  14. package/lib/{get-target-Ba_ZoGUl.js → get-target-LUoY1UWJ.js} +1 -1
  15. package/lib/index-C61lSPb5.js +1 -0
  16. package/lib/{index-CB6KQLC7.js → index-CBGUBgfk.js} +3 -3
  17. package/lib/{index-_8uEunjn.js → index-ClUEyMCY.js} +1 -1
  18. package/lib/{index-mBZsirl0.js → index-Cp8MNK26.js} +1 -1
  19. package/lib/{index-Cwtynogk.js → index-Dv6JxqGo.js} +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/{init-project-BY-a8CIk.js → init-project-9RKSVG_H.js} +3 -3
  22. package/lib/installer-DPj-zT7L.js +9 -0
  23. package/lib/{load-from-project-wNJg8fme.js → load-from-project-ClF4qaC0.js} +1 -1
  24. package/lib/messages.d.ts +2 -0
  25. package/lib/{project-DFh-2QTw.js → project-BPmPCkUS.js} +4 -4
  26. package/lib/run-macro-C1-aJWu5.js +1 -0
  27. package/lib/{sat-solver-CqS8Vf6C.js → sat-solver-B6RXdyQs.js} +1 -1
  28. package/lib/targets/build-target.d.ts +1 -0
  29. package/lib/targets/export-target.d.ts +3 -1
  30. package/lib/targets/transforms/format-xml.d.ts +2 -0
  31. package/lib/test-project-DXBFZH3o.js +1 -0
  32. package/lib/transform-build-graph-DgRrocSn.js +1 -0
  33. package/lib/transform-target-CYhuozxP.js +2 -0
  34. package/lib/utils/encoding.d.ts +30 -0
  35. package/lib/utils/run.d.ts +4 -1
  36. package/lib/utils/xml.d.ts +14 -0
  37. package/lib/{vbapm-add-QPN5uEGK.js → vbapm-add-CASFjXAL.js} +1 -1
  38. package/lib/vbapm-build-Bhm_pqQW.js +9 -0
  39. package/lib/vbapm-export-8KDCdFOz.js +9 -0
  40. package/lib/{vbapm-init-BMY4x_xq.js → vbapm-init-Ba2xCez2.js} +1 -1
  41. package/lib/{vbapm-new-DLW9SdvJ.js → vbapm-new-YQRNQ4Iq.js} +1 -1
  42. package/lib/{vbapm-run-DzRxAhlD.js → vbapm-run-J-R--noZ.js} +2 -2
  43. package/lib/{vbapm-test-DInh0MDC.js → vbapm-test-C4KWMPLz.js} +1 -1
  44. package/lib/vbapm-update-DnbmW8tc.js +13 -0
  45. package/lib/{vbapm-version-3Xv7JjGv.js → vbapm-version-CRicT8YA.js} +1 -1
  46. package/lib/vbapm.js +2 -1
  47. package/package.json +6 -3
  48. package/run-scripts/run.applescript +18 -7
  49. package/run-scripts/run.ps1 +42 -10
  50. package/lib/build-project-CIZanDh1.js +0 -3
  51. package/lib/build-target-B03OPzeI.js +0 -9
  52. package/lib/export-project-DdTYRyAw.js +0 -4
  53. package/lib/export-target-CEupP86g.js +0 -4
  54. package/lib/installer-C0iBwEpK.js +0 -9
  55. package/lib/run-macro-Ck_8Iku3.js +0 -1
  56. package/lib/test-project-CM-XUOdH.js +0 -1
  57. package/lib/transform-target-DJmqMjY0.js +0 -2
  58. package/lib/vbapm-build-BKtQ6OeP.js +0 -9
  59. package/lib/vbapm-export-4H_qDinP.js +0 -7
@@ -8,6 +8,8 @@ param(
8
8
  [Parameter(Position=2)]
9
9
  [string]$Command,
10
10
 
11
+ [switch]$KeepOpen,
12
+
11
13
  [Parameter(Position=3, ValueFromRemainingArguments=$true)]
12
14
  [string[]]$MacroArgs
13
15
  )
@@ -90,6 +92,7 @@ function RunMacro {
90
92
 
91
93
  class Excel {
92
94
  hidden [object]$App
95
+ hidden [bool]$BackgroundBuild = $false
93
96
  hidden [bool]$ExcelWasOpen = $false
94
97
  hidden [object]$Workbook
95
98
  hidden [bool]$WorkbookWasOpen = $false
@@ -106,13 +109,29 @@ class Excel {
106
109
  }
107
110
 
108
111
  hidden [void] OpenExcel() {
109
- try {
110
- $this.App = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
111
- $this.ExcelWasOpen = $true
112
- } catch {
112
+ # When VBA_BACKGROUND_BUILD is set, always create a new hidden instance
113
+ # instead of attaching to an already-running (visible) Excel process.
114
+ # This prevents the application window from flashing during automated runs.
115
+ $this.BackgroundBuild = $env:VBA_BACKGROUND_BUILD -match '^(1|true|yes)$'
116
+
117
+ if (-not $this.BackgroundBuild) {
118
+ try {
119
+ $this.App = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
120
+ $this.ExcelWasOpen = $true
121
+ } catch {
122
+ # Excel not running; fall through to create a new instance
123
+ }
124
+ }
125
+
126
+ if (-not $this.ExcelWasOpen) {
113
127
  try {
114
128
  $this.App = New-Object -ComObject "Excel.Application"
115
- $this.App.Visible = $false
129
+ $this.App.Visible = if ($this.BackgroundBuild) { $false } else { $true }
130
+ $this.App.ScreenUpdating = $false
131
+ $this.App.DisplayStatusBar = $false
132
+ $this.App.PrintCommunication = $false
133
+ $this.App.EnableAnimations = $false
134
+ $this.App.EnableEvents = $false
116
135
  } catch {
117
136
  Fail "ERROR #5: Failed to open Excel - $($_.Exception.Message)"
118
137
  }
@@ -147,17 +166,29 @@ class Excel {
147
166
  # Open the workbook
148
167
  try {
149
168
  $this.Workbook = $this.App.Workbooks.Open($Path)
169
+ # Workbooks.Open() can flip Excel back to visible; re-enforce
170
+ # invisible mode if we created this instance for automation.
171
+ # Also apply workbook-level performance flags now that a workbook is open.
172
+ if ($this.BackgroundBuild) {
173
+ $this.App.Visible = $false
174
+ try { $this.App.Calculation = -4135 } catch {} # xlCalculationManual — requires an open workbook
175
+
176
+ }
150
177
  } catch {
151
178
  Fail "ERROR #6: Failed to open workbook - $($_.Exception.Message)"
152
179
  }
153
180
  }
154
181
 
155
- [void] Dispose() {
156
- if (-not $this.WorkbookWasOpen -and $null -ne $this.Workbook) {
182
+ [void] Dispose([bool]$KeepOpen) {
183
+ # A file that was open before we started is never closed by us
184
+ $closeWorkbook = -not $this.WorkbookWasOpen -and -not $KeepOpen
185
+
186
+ if ($closeWorkbook -and $null -ne $this.Workbook) {
157
187
  $this.Workbook.Close($true)
158
188
  $this.Workbook = $null
159
189
  }
160
- if (-not $this.ExcelWasOpen -and $null -ne $this.App) {
190
+ # Quit Excel only if we launched it AND we are not keeping the file open
191
+ if (-not $this.ExcelWasOpen -and -not $KeepOpen -and $null -ne $this.App) {
161
192
  $this.App.Quit()
162
193
  [System.Runtime.InteropServices.Marshal]::ReleaseComObject($this.App) | Out-Null
163
194
  $this.App = $null
@@ -174,6 +205,7 @@ function Run {
174
205
  [string]$AppName,
175
206
  [string]$FilePath,
176
207
  [string]$MacroName,
208
+ [bool]$KeepOpen,
177
209
  [string[]]$MacroArgValues
178
210
  )
179
211
 
@@ -183,7 +215,7 @@ function Run {
183
215
  try {
184
216
  $result = $excel.Run($FilePath, $MacroName, $MacroArgValues)
185
217
  } finally {
186
- $excel.Dispose()
218
+ $excel.Dispose($KeepOpen)
187
219
  }
188
220
  }
189
221
  default {
@@ -214,5 +246,5 @@ foreach ($arg in $MacroArgs) {
214
246
  $UnescapedArgs += Unescape $arg
215
247
  }
216
248
 
217
- Run $AppName $File $Command $UnescapedArgs
249
+ Run $AppName $File $Command $KeepOpen.IsPresent $UnescapedArgs
218
250
  exit 0
@@ -1,3 +0,0 @@
1
- "use strict";var e=require("./installer-C0iBwEpK.js"),r=require("./project-DFh-2QTw.js"),t=require("./index-CB6KQLC7.js"),i=require("./build-target-B03OPzeI.js");require("assert"),require("./transform-target-DJmqMjY0.js"),require("fs");var n=require("./get-target-Ba_ZoGUl.js");exports.buildProject=async function(a={}){e.env.reporter.log(e.Message.BuildProjectLoading,"[1/3] Loading project...");const s=await r.loadProject(),{target:o,blankTarget:g}=n.getTarget(s,a.target),c=await r.fetchDependencies(s),d=s.packages.map(e=>{const i=r.toDependency(e);return t.isRegistryDependency(i)?`${e.id} registry+${i.registry}`:`${e.id} ${e.source}`});e.env.reporter.log(e.Message.BuildTargetBuilding,e.dedent`
2
- \n[2/3] Building target "${o.type}" for "${s.manifest.name}"...
3
- ${d.length?`\nDependencies:\n${d.join("\n")}`:""}`),await i.buildTarget(o,{project:s,dependencies:c,blankTarget:g},a);const l=!s.hasDirtyLockfile;return e.env.reporter.log(e.Message.BuildLockfileWriting,"\n[3/3] Writing lockfile..."+(l?" (skipped, no changes)":"")),l||await r.writeLockfile(s.paths.root,s),e.join(s.paths.dir,"build",o.filename)};
@@ -1,9 +0,0 @@
1
- "use strict";var t=require("./installer-C0iBwEpK.js"),a=require("./transform-target-DJmqMjY0.js");require("assert");var r=require("./load-from-project-wNJg8fme.js"),e=require("path"),i=require("./project-DFh-2QTw.js");const o=t=>/1004/.test(t),n=(a,r)=>t.dedent`
2
- Failed to build target "${a.name}", it is currently open.
3
-
4
- Please close "${r}" and try again.
5
- `;async function s(a,r){if(!await t.pathExistsExports.pathExists(r.path))throw new t.CliError(t.ErrorCode.TargetNotFound,`Target "${r.name}" not found at "${r.path}".`);const e=t.join(a.paths.staging,r.filename);try{await t.mkdirsExports.ensureDir(a.paths.staging),await i.zip(r.path,e)}catch(a){throw new t.CliError(t.ErrorCode.TargetCreateFailed,`Failed to create project for target "${r.name}".`,a)}return e}exports.buildTarget=async function(i,p,c={}){const{project:l}=p;let m;try{m=p.blankTarget?await a.createDocument(l,i,{staging:!0}):await s(l,i)}catch(a){if(!t.isRunError(a)||!a.result.errors.some(o))throw a;const r=t.join(l.paths.build,i.filename);throw new t.CliError(t.ErrorCode.TargetIsOpen,n(i,r))}await async function(i,o,n,s={}){const{project:p,dependencies:c}=o,l=t.join(p.paths.staging,"import");await t.mkdirsExports.ensureDir(l),await t.emptyExports.emptyDir(l);const m=await r.loadFromProject(p,c,s),w=await async function(a,r){const i=await t.parallel(a.components,async a=>{const i=t.join(r,a.filename);if(await t.writeFile(i,a.code),a.binaryPath){const i=t.join(r,e.basename(a.binaryPath));if(!a.details.binary)throw new Error(`Binary data missing for component "${a.name}"`);await t.writeFile(i,a.details.binary)}return{name:a.name,path:i}});return{name:a.name,components:i,references:a.references}}(m,l);try{await a.importGraph(p,i,w,n,s)}catch(a){throw new t.CliError(t.ErrorCode.TargetImportFailed,`Failed to import project for target "${i.name}".`,a)}finally{await t.removeExports.remove(l)}}(i,p,m,c);try{await async function(a,r){const e=t.join(a.paths.backup,r.filename),i=t.join(a.paths.build,r.filename);await t.pathExistsExports.pathExists(e)&&await t.removeExports.remove(e);if(await t.pathExistsExports.pathExists(i)){await t.mkdirsExports.ensureDir(a.paths.backup);try{await t.moveExports.move(i,e)}catch(a){throw new t.CliError(t.ErrorCode.TargetIsOpen,n(r,i))}}}(l,i);const a=t.join(l.paths.build,i.filename);await t.moveExports.move(m,a)}catch(a){throw await async function(a,r){const e=t.join(a.paths.backup,r.filename),i=t.join(a.paths.build,r.filename);if(!await t.pathExistsExports.pathExists(e))return;try{await t.copyExports.copy(e,i)}catch(a){throw new t.CliError(t.ErrorCode.TargetRestoreFailed,t.dedent`
6
- Failed to automatically restore backup from "${e}" to "${i}".
7
-
8
- The previous version can be moved back manually, if desired.
9
- `,a)}}(l,i),a}finally{await t.removeExports.remove(m)}};
@@ -1,4 +0,0 @@
1
- "use strict";var e=require("./installer-C0iBwEpK.js"),t=require("./transform-target-DJmqMjY0.js"),r=require("./project-DFh-2QTw.js");require("assert"),require("fs");var a=require("./export-target-CEupP86g.js");exports.exportProject=async function(o={}){e.env.reporter.log(e.Message.ExportProjectLoading,"[1/3] Loading project...");const i=await r.loadProject();if(!o.target&&!i.manifest.target)throw new e.CliError(e.ErrorCode.ExportNoTarget,e.dedent`
2
- No default target found for project,
3
- use --target TYPE to export from a specific target.
4
- `);let n,s=!1;if(i.manifest.target)o.target&&o.target!==i.manifest.target.type||(n=i.manifest.target);else{const t=o.target,r=i.manifest.name;n={type:t,name:r,path:`targets/${t}`,filename:`${e.sanitize(r)}.${t}`},s=!0}if(!n)throw new e.CliError(e.ErrorCode.ExportNoMatching,`No matching target found for type "${o.target}" in project.`);const p=await r.fetchDependencies(i);let g;try{o.completed?g=o.completed:(g=e.join(i.paths.staging,"export"),e.env.reporter.log(e.Message.ExportToStaging,`\n[2/3] Exporting src from "${n.filename}"`),await e.mkdirsExports.ensureDir(g),await e.emptyExports.emptyDir(g),await t.exportTo(i,n,g,o)),e.env.reporter.log(e.Message.ExportToProject,"\n[3/3] Updating project"),await a.exportTarget(n,{project:i,dependencies:p,blankTarget:s},g)}catch(e){throw e}finally{g&&await e.removeExports.remove(g)}};
@@ -1,4 +0,0 @@
1
- "use strict";var e=require("./installer-C0iBwEpK.js"),n=require("./index-CB6KQLC7.js"),t=require("path"),r=require("./load-from-project-wNJg8fme.js"),o=require("./transform-target-DJmqMjY0.js");require("assert");var a=require("./project-DFh-2QTw.js");async function s(t,r){const o=e.env.reporter.progress("Updating src files"),a=o.start,s=o.done;o.start=()=>{},o.done=()=>{},a(),await e.parallel(r.components.changed,e=>i(e.details.path,e),{progress:o}),await e.parallel(r.components.added,async n=>{const r=e.join(t.paths.dir,"src",n.filename);n.details.path=r,await i(r,n)},{progress:o}),await e.parallel(r.components.removed,async n=>{await e.removeExports.remove(n.details.path)},{progress:o}),await async function(t,r){for(const n of r.components.added){const r={name:n.name,path:e.join(t.paths.dir,`src/${n.filename}`)};t.manifest.src.push(r)}for(const e of r.components.removed){const n=t.manifest.src.findIndex(n=>n.name===e.name);t.manifest.src.splice(n,1)}for(let e of r.references.added)t.manifest.references.push(e);for(const e of r.references.removed){const n=t.manifest.references.findIndex(n=>n.name===e.name);t.manifest.references.splice(n,1)}await n.writeManifest(t.manifest,t.paths.dir)}(t,r),s()}async function i(n,r){const o=t.dirname(n);if(await e.mkdirsExports.ensureDir(o),await e.writeFile(n,r.code),r.binaryPath){if(!r.details.binary)throw new Error(`Binary data missing for component "${r.name}"`);await e.writeFile(e.join(o,r.binaryPath),r.details.binary)}}const c=[".frx"];async function p(n){const a=o.walk(n,{directories:!1}).filter(e=>"project.json"!==e&&!e.startsWith("target")&&!e.startsWith("staged")&&!(e=>!(""!==t.extname(e)))(e)).map(t=>e.join(n,t)),{name:s,references:i}=await async function(n){const t=e.join(n,"project.json");if(!await e.pathExistsExports.pathExists(t))return{name:"VBAProject",references:[]};return await e.jsonfileExports.readJson(t)}(n),p={},d=a.filter(e=>{if(!function(e){return c.includes(t.extname(e))}(e))return!0;const n=m(e);return p[n]=e,!1}),f=await e.parallel(d,async n=>{const o=m(n),a=r.extensionToType[t.extname(n)],s=await e.readFile(n),i=p[o]&&await e.readFile(p[o]);if(!a)throw new e.CliError(e.ErrorCode.ComponentUnrecognized,`Unrecognized component extension "${t.extname(n)}" (at "${n}").`);return new r.Component(a,s,{binary:i})},{progress:e.env.reporter.progress("Loading exported components")});return f.sort(r.byComponentName),{name:s,components:f,references:i,fromDependencies:{components:new Map,references:new Map}}}function m(e){return t.basename(e,t.extname(e))}async function d(n,r,s){let i=e.join(n.paths.build,r.filename);const c=e.join(s,"target");if(!await e.pathExistsExports.pathExists(i))throw new e.CliError(e.ErrorCode.ExportTargetNotFound,e.dedent`
2
- Could not find built target for type "${r.type}"
3
- (checked "${i}").
4
- `);if(!e.env.isWindows){const n=e.join(s,"staged",r.filename);await e.pathExistsExports.pathExists(n)||(await e.mkdirsExports.ensureDir(t.dirname(n)),await e.copyExports.copy(i,n)),i=n}return await e.mkdirsExports.ensureDir(c),await a.unzip(i,c,{filter:o.filterTarget,map:o.mapTarget}),c}exports.exportTarget=async function(n,t,a){const{project:i,dependencies:c,blankTarget:m}=t;let f;m||(f=await d(i,n,a));const l=await r.loadFromProject(i,c),u=await p(a),w=function(e,n){const t={components:{added:[],changed:[],removed:[]},references:{added:[],changed:[],removed:[]}},o={components:new Map,references:new Map};for(const n of e.components)o.components.set(n.name,n);for(const n of e.references)o.references.set(n.name,n);for(const r of n.components){const n=r.name,a=o.components.get(n);o.components.delete(n),a&&e.fromDependencies.components.has(a)||(a?r.code!==a.code&&(r.details.path=a.details.path,t.components.changed.push(r)):t.components.added.push(r))}for(const e of o.components.values())t.components.removed.push(e);t.components.added.sort(r.byComponentName),t.components.changed.sort(r.byComponentName),t.components.removed.sort(r.byComponentName);for(const r of n.references){const n=r.name,a=o.references.get(n);o.references.delete(n),a&&e.fromDependencies.references.has(a)||(a?r.guid===a.guid&&r.major===a.major&&r.minor===a.minor||t.references.changed.push(r):t.references.added.push(r))}for(const e of o.references.values())t.references.removed.push(e);return t}(l,await o.toSrc(u));await s(i,w),m||(await e.removeExports.remove(n.path),await e.copyExports.copy(f,n.path)),await e.removeExports.remove(a)},exports.extractTarget=d;