@php-wasm/cli-util
Advanced tools
+8
-8
@@ -1,7 +0,7 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("fs"),P=require("path"),T=require("@php-wasm/util"),j=require("fast-xml-parser"),A=require("jsonc-parser");function X(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const c=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,c.get?c:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const v=X(A);async function _(s,a,n){const c=n==="win32"?"junction":"dir";f.symlinkSync(s,a,c)}async function B(s){try{f.lstatSync(s).isSymbolicLink()&&f.unlinkSync(s)}catch{}}function R(s,a){return a.filter(n=>{const c=P.resolve(n.hostPath),h=P.join(s,P.sep);return c===s||c.startsWith(h)})}const x={ignoreAttributes:!1,attributeNamePrefix:"",preserveOrder:!0,cdataPropName:"__cdata",commentPropName:"__xmlComment",allowBooleanAttributes:!0,trimValues:!0},k={ignoreAttributes:x.ignoreAttributes,attributeNamePrefix:x.attributeNamePrefix,preserveOrder:x.preserveOrder,cdataPropName:x.cdataPropName,commentPropName:x.commentPropName,suppressBooleanAttributes:!x.allowBooleanAttributes,format:!0,indentBy:" "},C={allowEmptyContent:!0,allowTrailingComma:!0};function M(s,a){var E,I,D,F,L,O;const{name:n,host:c,port:h,mappings:p,ideKey:o}=a,u=new j.XMLParser(x),g=(()=>{try{return u.parse(s,!0)}catch{throw new Error("PhpStorm configuration file is not valid XML.")}})(),m={server:[{}],":@":{name:n,host:`${c}:${h}`,use_path_mappings:"true"}};p&&p.length&&(m.server[0].path_mappings=p.map(e=>({mapping:[],":@":{"local-root":`$PROJECT_DIR$/${T.toPosixPath(P.relative(a.projectDir,e.hostPath))}`,"remote-root":e.vfsPath}})));let t=g==null?void 0:g.find(e=>!!(e!=null&&e.project));if(t){const e=(E=t[":@"])==null?void 0:E.version;if(e===void 0)throw new Error('PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but the <project> configuration has no version number.');if(e!=="4")throw new Error(`PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but we found a <project> configuration with version "${e}".`)}t===void 0&&(t={project:[],":@":{version:"4"}},g.push(t));let r=(I=t.project)==null?void 0:I.find(e=>{var S;return!!(e!=null&&e.component)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)==="PhpServers"});r===void 0&&(r={component:[],":@":{name:"PhpServers"}},t.project===void 0&&(t.project=[]),t.project.push(r));let l=(D=r.component)==null?void 0:D.find(e=>!!(e!=null&&e.servers));l===void 0&&(l={servers:[]},r.component===void 0&&(r.component=[]),r.component.push(l));const y=(F=l.servers)==null?void 0:F.findIndex(e=>{var S;return!!(e!=null&&e.server)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)===n});(y===void 0||y<0)&&(l.servers===void 0&&(l.servers=[]),l.servers.push(m));let d=(L=t.project)==null?void 0:L.find(e=>{var S;return!!(e!=null&&e.component)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)==="RunManager"});if(d===void 0&&(d={component:[],":@":{name:"RunManager"}},t.project===void 0&&(t.project=[]),t.project.push(d)),(((O=d.component)==null?void 0:O.findIndex(e=>{var S;return!!(e!=null&&e.configuration)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)===n}))??-1)<0){const e={configuration:[{method:[],":@":{v:"2"}}],":@":{name:n,type:"PhpRemoteDebugRunConfigurationType",factoryName:"PHP Remote Debug",filter_connections:"FILTER",server_name:n,session_id:o}};d.component===void 0&&(d.component=[]),d.component.push(e)}const b=new j.XMLBuilder(k).build(g);try{u.parse(b,!0)}catch{throw new Error("The resulting PhpStorm configuration file is not valid XML.")}return b}function N(s,a){var m,t;const{name:n,mappings:c}=a,h=[];let p=s,o=v.parseTree(p,h,C);if(o===void 0||h.length)throw new Error("VS Code configuration file is not valid JSON.");let u=v.findNodeAtLocation(o,["configurations"]);if(u===void 0||u.children===void 0){const r=v.modify(p,["configurations"],[],{});p=v.applyEdits(p,r),o=v.parseTree(p,[],C),u=v.findNodeAtLocation(o,["configurations"])}const g=(m=u==null?void 0:u.children)==null?void 0:m.findIndex(r=>{var l;return((l=v.findNodeAtLocation(r,["name"]))==null?void 0:l.value)===n});if(g===void 0||g<0){const r={name:n,type:"php",request:"launch",port:9003};c&&c.length&&(r.pathMappings=c.reduce((d,i)=>(d[i.vfsPath]=`\${workspaceFolder}/${T.toPosixPath(P.relative(a.workspaceDir,i.hostPath))}`,d),{}));const l=((t=u==null?void 0:u.children)==null?void 0:t.length)||0,y=v.modify(p,["configurations",l],r,{formattingOptions:{insertSpaces:!0,tabSize:4,eol:` | ||
| `}});p=$(p,y)}return p}async function q({name:s,ides:a,host:n,port:c,cwd:h,mounts:p,ideKey:o="PHPWASMCLI"}){const u=p?R(h,p):[],g={};if(a.includes("phpstorm")){const m=".idea/workspace.xml",t=P.join(h,m);if(!f.existsSync(t)){if(f.existsSync(P.dirname(t)))f.writeFileSync(t,`<?xml version="1.0" encoding="UTF-8"?> | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("fs"),P=require("path"),k=require("@php-wasm/util"),j=require("fast-xml-parser"),X=require("jsonc-parser");function B(o){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:()=>o[t]})}}return r.default=o,Object.freeze(r)}const v=B(X),M="PHPWASMCLI";async function R(o,r,t){const a=t==="win32"?"junction":"dir";p.symlinkSync(o,r,a)}async function q(o){try{p.lstatSync(o).isSymbolicLink()&&p.unlinkSync(o)}catch{}}function O(o,r){return r.filter(t=>{const a=P.resolve(t.hostPath),h=P.join(o,P.sep);return a===o||a.startsWith(h)})}const x={ignoreAttributes:!1,attributeNamePrefix:"",preserveOrder:!0,cdataPropName:"__cdata",commentPropName:"__xmlComment",allowBooleanAttributes:!0,trimValues:!0},_={ignoreAttributes:x.ignoreAttributes,attributeNamePrefix:x.attributeNamePrefix,preserveOrder:x.preserveOrder,cdataPropName:x.cdataPropName,commentPropName:x.commentPropName,suppressBooleanAttributes:!x.allowBooleanAttributes,format:!0,indentBy:" "},C={allowEmptyContent:!0,allowTrailingComma:!0};function A(o,r){var b,I,D,F,L,T;const{name:t,host:a,port:h,mappings:f,ideKey:i}=r,u=new j.XMLParser(x),g=(()=>{try{return u.parse(o,!0)}catch{throw new Error("PhpStorm configuration file is not valid XML.")}})(),m={server:[{}],":@":{name:t,host:`${a}:${h}`,use_path_mappings:"true"}};f&&f.length&&(m.server[0].path_mappings=f.map(e=>({mapping:[],":@":{"local-root":`$PROJECT_DIR$/${k.toPosixPath(P.relative(r.projectDir,e.hostPath))}`,"remote-root":e.vfsPath}})));let n=g==null?void 0:g.find(e=>!!(e!=null&&e.project));if(n){const e=(b=n[":@"])==null?void 0:b.version;if(e===void 0)throw new Error('PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but the <project> configuration has no version number.');if(e!=="4")throw new Error(`PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but we found a <project> configuration with version "${e}".`)}n===void 0&&(n={project:[],":@":{version:"4"}},g.push(n));let s=(I=n.project)==null?void 0:I.find(e=>{var S;return!!(e!=null&&e.component)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)==="PhpServers"});s===void 0&&(s={component:[],":@":{name:"PhpServers"}},n.project===void 0&&(n.project=[]),n.project.push(s));let l=(D=s.component)==null?void 0:D.find(e=>!!(e!=null&&e.servers));l===void 0&&(l={servers:[]},s.component===void 0&&(s.component=[]),s.component.push(l));const y=(F=l.servers)==null?void 0:F.findIndex(e=>{var S;return!!(e!=null&&e.server)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)===t});(y===void 0||y<0)&&(l.servers===void 0&&(l.servers=[]),l.servers.push(m));let d=(L=n.project)==null?void 0:L.find(e=>{var S;return!!(e!=null&&e.component)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)==="RunManager"});if(d===void 0&&(d={component:[],":@":{name:"RunManager"}},n.project===void 0&&(n.project=[]),n.project.push(d)),(((T=d.component)==null?void 0:T.findIndex(e=>{var S;return!!(e!=null&&e.configuration)&&((S=e==null?void 0:e[":@"])==null?void 0:S.name)===t}))??-1)<0){const e={configuration:[{method:[],":@":{v:"2"}}],":@":{name:t,type:"PhpRemoteDebugRunConfigurationType",factoryName:"PHP Remote Debug",filter_connections:"FILTER",server_name:t,session_id:i}};d.component===void 0&&(d.component=[]),d.component.push(e)}const E=new j.XMLBuilder(_).build(g);try{u.parse(E,!0)}catch{throw new Error("The resulting PhpStorm configuration file is not valid XML.")}return E}function N(o,r){var m,n;const{name:t,mappings:a}=r,h=[];let f=o,i=v.parseTree(f,h,C);if(i===void 0||h.length)throw new Error("VS Code configuration file is not valid JSON.");let u=v.findNodeAtLocation(i,["configurations"]);if(u===void 0||u.children===void 0){const s=v.modify(f,["configurations"],[],{});f=v.applyEdits(f,s),i=v.parseTree(f,[],C),u=v.findNodeAtLocation(i,["configurations"])}const g=(m=u==null?void 0:u.children)==null?void 0:m.findIndex(s=>{var l;return((l=v.findNodeAtLocation(s,["name"]))==null?void 0:l.value)===t});if(g===void 0||g<0){const s={name:t,type:"php",request:"launch",port:9003};a&&a.length&&(s.pathMappings=a.reduce((d,c)=>(d[c.vfsPath]=`\${workspaceFolder}/${k.toPosixPath(P.relative(r.workspaceDir,c.hostPath))}`,d),{}));const l=((n=u==null?void 0:u.children)==null?void 0:n.length)||0,y=v.modify(f,["configurations",l],s,{formattingOptions:{insertSpaces:!0,tabSize:4,eol:` | ||
| `}});f=$(f,y)}return f}async function V({name:o,ides:r,host:t,port:a,cwd:h,mounts:f,ideKey:i=M}){const u=f?O(h,f):[],g={};if(r.includes("phpstorm")){const m=".idea/workspace.xml",n=P.join(h,m);if(!p.existsSync(n)){if(p.existsSync(P.dirname(n)))p.writeFileSync(n,`<?xml version="1.0" encoding="UTF-8"?> | ||
| <project version="4"> | ||
| </project>`);else if(a.length==1)throw new Error("PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory.")}if(f.existsSync(t)){const r=f.readFileSync(t,"utf8"),l=M(r,{name:s,host:n,port:c,projectDir:h,mappings:u,ideKey:o});f.writeFileSync(t,l),g.phpstorm=m}}if(a.includes("vscode")){const m=".vscode/launch.json",t=P.join(h,m);if(!f.existsSync(t)){if(f.existsSync(P.dirname(t)))f.writeFileSync(t,`{ | ||
| </project>`);else if(r.length==1)throw new Error("PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory.")}if(p.existsSync(n)){const s=p.readFileSync(n,"utf8"),l=A(s,{name:o,host:t,port:a,projectDir:h,mappings:u,ideKey:i});p.writeFileSync(n,l),g.phpstorm=m}}if(r.includes("vscode")){const m=".vscode/launch.json",n=P.join(h,m);if(!p.existsSync(n)){if(p.existsSync(P.dirname(n)))p.writeFileSync(n,`{ | ||
| "configurations": [] | ||
| }`);else if(a.length==1)throw new Error("VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory.")}if(f.existsSync(t)){const r=f.readFileSync(t,"utf-8"),l=N(r,{name:s,workspaceDir:h,mappings:u});l!==r&&(f.writeFileSync(t,l),g.vscode=m)}}return g}async function V(s,a){var h,p,o,u;const n=P.join(a,".idea/workspace.xml");if(f.existsSync(n)){const g=f.readFileSync(n,"utf8"),m=new j.XMLParser(x),t=(()=>{try{return m.parse(g,!0)}catch{throw new Error("PhpStorm configuration file is not valid XML.")}})(),r=t.find(i=>!!(i!=null&&i.project)),l=(h=r==null?void 0:r.project)==null?void 0:h.find(i=>{var w;return!!(i!=null&&i.component)&&((w=i==null?void 0:i[":@"])==null?void 0:w.name)==="PhpServers"}),y=(p=l==null?void 0:l.component)==null?void 0:p.find(i=>!!(i!=null&&i.servers)),d=(o=y==null?void 0:y.servers)==null?void 0:o.findIndex(i=>{var w;return!!(i!=null&&i.server)&&((w=i==null?void 0:i[":@"])==null?void 0:w.name)===s});if(d!==void 0&&d>=0){y.servers.splice(d,1);const w=new j.XMLBuilder(k).build(t);try{m.parse(w,!0)}catch{throw new Error("The resulting PhpStorm configuration file is not valid XML.")}w===`<?xml version="1.0" encoding="UTF-8"?> | ||
| }`);else if(r.length==1)throw new Error("VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory.")}if(p.existsSync(n)){const s=p.readFileSync(n,"utf-8"),l=N(s,{name:o,workspaceDir:h,mappings:u});l!==s&&(p.writeFileSync(n,l),g.vscode=m)}}return g}async function J(o,r){var h,f,i,u;const t=P.join(r,".idea/workspace.xml");if(p.existsSync(t)){const g=p.readFileSync(t,"utf8"),m=new j.XMLParser(x),n=(()=>{try{return m.parse(g,!0)}catch{throw new Error("PhpStorm configuration file is not valid XML.")}})(),s=n.find(c=>!!(c!=null&&c.project)),l=(h=s==null?void 0:s.project)==null?void 0:h.find(c=>{var w;return!!(c!=null&&c.component)&&((w=c==null?void 0:c[":@"])==null?void 0:w.name)==="PhpServers"}),y=(f=l==null?void 0:l.component)==null?void 0:f.find(c=>!!(c!=null&&c.servers)),d=(i=y==null?void 0:y.servers)==null?void 0:i.findIndex(c=>{var w;return!!(c!=null&&c.server)&&((w=c==null?void 0:c[":@"])==null?void 0:w.name)===o});if(d!==void 0&&d>=0){y.servers.splice(d,1);const w=new j.XMLBuilder(_).build(n);try{m.parse(w,!0)}catch{throw new Error("The resulting PhpStorm configuration file is not valid XML.")}w===`<?xml version="1.0" encoding="UTF-8"?> | ||
| <project version="4"> | ||
@@ -11,12 +11,12 @@ <component name="PhpServers"> | ||
| </component> | ||
| </project>`?f.unlinkSync(n):f.writeFileSync(n,w)}}const c=P.join(a,".vscode/launch.json");if(f.existsSync(c)){const g=[],m=f.readFileSync(c,"utf-8"),t=v.parseTree(m,g,C);if(t===void 0||g.length)throw new Error("VS Code configuration file is not valid JSON.");const r=v.findNodeAtLocation(t,["configurations"]),l=(u=r==null?void 0:r.children)==null?void 0:u.findIndex(y=>{var d;return((d=v.findNodeAtLocation(y,["name"]))==null?void 0:d.value)===s});if(l!==void 0&&l>=0){const y=v.modify(m,["configurations",l],void 0,{formattingOptions:{insertSpaces:!0,tabSize:4,eol:` | ||
| </project>`?p.unlinkSync(t):p.writeFileSync(t,w)}}const a=P.join(r,".vscode/launch.json");if(p.existsSync(a)){const g=[],m=p.readFileSync(a,"utf-8"),n=v.parseTree(m,g,C);if(n===void 0||g.length)throw new Error("VS Code configuration file is not valid JSON.");const s=v.findNodeAtLocation(n,["configurations"]),l=(u=s==null?void 0:s.children)==null?void 0:u.findIndex(y=>{var d;return((d=v.findNodeAtLocation(y,["name"]))==null?void 0:d.value)===o});if(l!==void 0&&l>=0){const y=v.modify(m,["configurations",l],void 0,{formattingOptions:{insertSpaces:!0,tabSize:4,eol:` | ||
| `}}),d=$(m,y);d===`{ | ||
| "configurations": [] | ||
| }`?f.unlinkSync(c):f.writeFileSync(c,d)}}}function $(s,a){const n=[],c=v.applyEdits(s,a);if(n.length=0,v.parseTree(c,n,C),n.length){const h=n.map(o=>({message:v.printParseErrorCode(o.error),offset:o.offset,length:o.length,fragment:c.slice(Math.max(0,o.offset-20),Math.min(c.length,o.offset+o.length+10))})).map(o=>`${o.message} at ${o.offset}:${o.length} (${o.fragment})`),p=a.map(o=>`At ${o.offset}:${o.length} - (${o.content})`);throw new Error(`VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents of your ".vscode/launch.json" file. | ||
| }`?p.unlinkSync(a):p.writeFileSync(a,d)}}}function U({cwd:o,mounts:r,pathSkippings:t}){return{pathMappings:o&&r?O(o,r):void 0,pathSkippings:t}}function $(o,r){const t=[],a=v.applyEdits(o,r);if(t.length=0,v.parseTree(a,t,C),t.length){const h=t.map(i=>({message:v.printParseErrorCode(i.error),offset:i.offset,length:i.length,fragment:a.slice(Math.max(0,i.offset-20),Math.min(a.length,i.offset+i.length+10))})).map(i=>`${i.message} at ${i.offset}:${i.length} (${i.fragment})`),f=r.map(i=>`At ${i.offset}:${i.length} - (${i.content})`);throw new Error(`VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents of your ".vscode/launch.json" file. | ||
| Applied edits: ${p.join(` | ||
| Applied edits: ${f.join(` | ||
| `)} | ||
| The errors are: ${h.join(` | ||
| `)}`)}return c}exports.addXdebugIDEConfig=q;exports.clearXdebugIDEConfig=V;exports.createTempDirSymlink=_;exports.removeTempDirSymlink=B;exports.updatePhpStormConfig=M;exports.updateVSCodeConfig=N; | ||
| `)}`)}return a}exports.DEFAULT_IDE_KEY=M;exports.addXdebugIDEConfig=V;exports.clearXdebugIDEConfig=J;exports.createTempDirSymlink=R;exports.makeXdebugConfig=U;exports.removeTempDirSymlink=q;exports.updatePhpStormConfig=A;exports.updateVSCodeConfig=N; | ||
| //# sourceMappingURL=index.cjs.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/cli-util/src/lib/xdebug-path-mappings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { toPosixPath } from '@php-wasm/util';\nimport type { Mount } from './mounts';\nimport {\n\ttype X2jOptions,\n\ttype XmlBuilderOptions,\n\tXMLParser,\n\tXMLBuilder,\n} from 'fast-xml-parser';\nimport * as JSONC from 'jsonc-parser';\n\n/**\n * Create a symlink to a tempory directory.\n *\n * The symlink is created to access the system temp dir\n * inside the current debugging directory.\n *\n * @param nativeDirPath The system temp dir path.\n * @param symlinkPath The symlink name.\n */\nexport async function createTempDirSymlink(\n\tnativeDirPath: string,\n\tsymlinkPath: string,\n\tplatform: string\n) {\n\tconst type =\n\t\tplatform === 'win32'\n\t\t\t? // On Windows, creating a 'dir' symlink can require elevated permissions.\n\t\t\t\t// In this case, let's make junction points because they function like\n\t\t\t\t// symlinks and do not require elevated permissions.\n\t\t\t\t'junction'\n\t\t\t: 'dir';\n\tfs.symlinkSync(nativeDirPath, symlinkPath, type);\n}\n\n/**\n * Remove the given temporary directory symlink if it exists.\n *\n * @param symlinkPath The symlink path.\n */\nexport async function removeTempDirSymlink(symlinkPath: string) {\n\ttry {\n\t\tconst stats = fs.lstatSync(symlinkPath);\n\t\tif (stats.isSymbolicLink()) {\n\t\t\tfs.unlinkSync(symlinkPath);\n\t\t}\n\t} catch {\n\t\t// Symlink does not exist or cannot be accessed, nothing to remove\n\t}\n}\n\n/**\n * Filters out mounts that are not in the current working directory\n *\n * @param mounts The mounts list.\n */\nfunction filterLocalMounts(cwd: string, mounts: Mount[]) {\n\treturn mounts.filter((mount) => {\n\t\tconst absoluteHostPath = path.resolve(mount.hostPath);\n\t\tconst cwdChildPrefix = path.join(cwd, path.sep);\n\t\treturn (\n\t\t\t// If auto-mounting from the current directory,\n\t\t\t// the entire project directory can be mapped.\n\t\t\tabsoluteHostPath === cwd ||\n\t\t\tabsoluteHostPath.startsWith(cwdChildPrefix)\n\t\t);\n\t});\n}\n\nexport type IDEConfig = {\n\t/**\n\t * The name of the configuration within the IDE configuration.\n\t */\n\tname: string;\n\t/**\n\t * The IDEs to configure.\n\t */\n\tides: string[];\n\t/**\n\t * The web server host.\n\t */\n\thost: string;\n\t/**\n\t * The web server port.\n\t */\n\tport: number;\n\t/**\n\t * The current working directory to consider for debugger path mapping.\n\t */\n\tcwd: string;\n\t/**\n\t * The mounts to consider for debugger path mapping.\n\t */\n\tmounts?: Mount[];\n\t/**\n\t * The IDE key to use for the debug configuration. Defaults to 'PLAYGROUNDCLI'.\n\t */\n\tideKey?: string;\n};\n\ntype PhpStormConfigMetaData = {\n\tname?: string;\n\tversion?: string;\n\thost?: string;\n\tuse_path_mappings?: string;\n\t'local-root'?: string;\n\t'remote-root'?: string;\n\t/**\n\t * The type of the server.\n\t */\n\ttype?: 'PhpRemoteDebugRunConfigurationType';\n\tfactoryName?: string;\n\tfilter_connections?: 'FILTER';\n\tserver_name?: string;\n\tsession_id?: string;\n\tv?: string;\n};\n\ntype PhpStormConfigNode = {\n\t':@'?: PhpStormConfigMetaData;\n\tproject?: PhpStormConfigNode[];\n\tcomponent?: PhpStormConfigNode[];\n\tservers?: PhpStormConfigNode[];\n\tserver?: PhpStormConfigNode[];\n\tpath_mappings?: PhpStormConfigNode[];\n\tmapping?: PhpStormConfigNode[];\n\tconfiguration?: PhpStormConfigNode[];\n\tmethod?: PhpStormConfigNode[];\n};\n\ntype VSCodeConfigMetaData = {\n\t[key: string]: string;\n};\n\ntype VSCodeConfigNode = {\n\tname: string;\n\ttype: string;\n\trequest: string;\n\tport: number;\n\tpathMappings?: VSCodeConfigMetaData;\n};\n\nconst xmlParserOptions: X2jOptions = {\n\tignoreAttributes: false,\n\tattributeNamePrefix: '',\n\tpreserveOrder: true,\n\tcdataPropName: '__cdata',\n\tcommentPropName: '__xmlComment',\n\tallowBooleanAttributes: true,\n\ttrimValues: true,\n};\nconst xmlBuilderOptions: XmlBuilderOptions = {\n\tignoreAttributes: xmlParserOptions.ignoreAttributes,\n\tattributeNamePrefix: xmlParserOptions.attributeNamePrefix,\n\tpreserveOrder: xmlParserOptions.preserveOrder,\n\tcdataPropName: xmlParserOptions.cdataPropName,\n\tcommentPropName: xmlParserOptions.commentPropName,\n\tsuppressBooleanAttributes: !xmlParserOptions.allowBooleanAttributes,\n\tformat: true,\n\tindentBy: '\\t',\n};\n\nconst jsoncParseOptions: JSONC.ParseOptions = {\n\tallowEmptyContent: true,\n\tallowTrailingComma: true,\n};\n\nexport type PhpStormConfigOptions = {\n\tname: string;\n\thost: string;\n\tport: number;\n\tprojectDir: string;\n\tmappings?: Mount[];\n\tideKey: string;\n};\n\n/**\n * Pure function to update PHPStorm XML config with XDebug server and run configuration.\n *\n * @param xmlContent The original XML content of workspace.xml\n * @param options Configuration options for the server\n * @returns Updated XML content\n * @throws Error if XML is invalid or configuration is incompatible\n */\nexport function updatePhpStormConfig(\n\txmlContent: string,\n\toptions: PhpStormConfigOptions\n): string {\n\tconst { name, host, port, mappings, ideKey } = options;\n\n\tconst xmlParser = new XMLParser(xmlParserOptions);\n\n\t// Parse the XML\n\tconst config: PhpStormConfigNode[] = (() => {\n\t\ttry {\n\t\t\treturn xmlParser.parse(xmlContent, true);\n\t\t} catch {\n\t\t\tthrow new Error('PhpStorm configuration file is not valid XML.');\n\t\t}\n\t})();\n\n\t// Create the server element with path mappings\n\tconst serverElement: PhpStormConfigNode = {\n\t\tserver: [{}],\n\t\t':@': {\n\t\t\tname,\n\t\t\t// NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port)\n\t\t\t// is provided in `host`. The separate `port` field is ignored or misinterpreted,\n\t\t\t// so we rely solely on host: \"host:port\".\n\t\t\thost: `${host}:${port}`,\n\t\t\tuse_path_mappings: 'true',\n\t\t},\n\t};\n\n\tif (mappings && mappings.length) {\n\t\tserverElement.server![0].path_mappings = mappings.map((mapping) => ({\n\t\t\tmapping: [],\n\t\t\t':@': {\n\t\t\t\t'local-root': `$PROJECT_DIR$/${toPosixPath(\n\t\t\t\t\tpath.relative(options.projectDir, mapping.hostPath)\n\t\t\t\t)}`,\n\t\t\t\t'remote-root': mapping.vfsPath,\n\t\t\t},\n\t\t}));\n\t}\n\n\t// Find or create project element\n\tlet projectElement = config?.find((c: PhpStormConfigNode) => !!c?.project);\n\tif (projectElement) {\n\t\tconst projectVersion = projectElement[':@']?.version;\n\t\tif (projectVersion === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t'but the <project> configuration has no version number.'\n\t\t\t);\n\t\t} else if (projectVersion !== '4') {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t`but we found a <project> configuration with version \"${projectVersion}\".`\n\t\t\t);\n\t\t}\n\t}\n\tif (projectElement === undefined) {\n\t\tprojectElement = {\n\t\t\tproject: [],\n\t\t\t':@': { version: '4' },\n\t\t};\n\t\tconfig.push(projectElement);\n\t}\n\n\t// Find or create PhpServers component\n\tlet componentElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t);\n\tif (componentElement === undefined) {\n\t\tcomponentElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'PhpServers' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(componentElement);\n\t}\n\n\t// Find or create servers element\n\tlet serversElement = componentElement.component?.find(\n\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t);\n\tif (serversElement === undefined) {\n\t\tserversElement = { servers: [] };\n\n\t\tif (componentElement.component === undefined) {\n\t\t\tcomponentElement.component = [];\n\t\t}\n\n\t\tcomponentElement.component.push(serversElement);\n\t}\n\n\t// Check if server already exists\n\tconst serverElementIndex = serversElement.servers?.findIndex(\n\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t);\n\n\t// Only add server if it doesn't exist\n\tif (serverElementIndex === undefined || serverElementIndex < 0) {\n\t\tif (serversElement.servers === undefined) {\n\t\t\tserversElement.servers = [];\n\t\t}\n\n\t\tserversElement.servers.push(serverElement);\n\t}\n\n\t// Find or create RunManager component\n\tlet runManagerElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'RunManager'\n\t);\n\tif (runManagerElement === undefined) {\n\t\trunManagerElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'RunManager' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(runManagerElement);\n\t}\n\n\t// Check if run configuration already exists\n\tconst existingConfigIndex =\n\t\trunManagerElement.component?.findIndex(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.configuration && c?.[':@']?.name === name\n\t\t) ?? -1;\n\n\t// Only add run configuration if it doesn't exist\n\tif (existingConfigIndex < 0) {\n\t\tconst runConfigElement: PhpStormConfigNode = {\n\t\t\tconfiguration: [\n\t\t\t\t{\n\t\t\t\t\tmethod: [],\n\t\t\t\t\t':@': { v: '2' },\n\t\t\t\t},\n\t\t\t],\n\t\t\t':@': {\n\t\t\t\tname: name,\n\t\t\t\ttype: 'PhpRemoteDebugRunConfigurationType',\n\t\t\t\tfactoryName: 'PHP Remote Debug',\n\t\t\t\tfilter_connections: 'FILTER',\n\t\t\t\tserver_name: name,\n\t\t\t\tsession_id: ideKey,\n\t\t\t},\n\t\t};\n\n\t\tif (runManagerElement.component === undefined) {\n\t\t\trunManagerElement.component = [];\n\t\t}\n\n\t\trunManagerElement.component.push(runConfigElement);\n\t}\n\n\t// Build the updated XML\n\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\tconst xml = xmlBuilder.build(config);\n\n\t// Validate the generated XML\n\ttry {\n\t\txmlParser.parse(xml, true);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t);\n\t}\n\n\treturn xml;\n}\n\nexport type VSCodeConfigOptions = {\n\tname: string;\n\tworkspaceDir: string;\n\tmappings?: Mount[];\n};\n\n/**\n * Pure function to update VS Code launch.json config with XDebug configuration.\n *\n * @param jsonContent The original JSON content of launch.json\n * @param options Configuration options\n * @returns Updated JSON content\n * @throws Error if JSON is invalid\n */\nexport function updateVSCodeConfig(\n\tjsonContent: string,\n\toptions: VSCodeConfigOptions\n): string {\n\tconst { name, mappings } = options;\n\n\tconst errors: JSONC.ParseError[] = [];\n\n\tlet content = jsonContent;\n\tlet root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\tif (root === undefined || errors.length) {\n\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t}\n\n\t// Find or create configurations array\n\tlet configurationsNode = JSONC.findNodeAtLocation(root, ['configurations']);\n\n\tif (\n\t\tconfigurationsNode === undefined ||\n\t\tconfigurationsNode.children === undefined\n\t) {\n\t\tconst edits = JSONC.modify(content, ['configurations'], [], {});\n\t\tcontent = JSONC.applyEdits(content, edits);\n\n\t\troot = JSONC.parseTree(content, [], jsoncParseOptions);\n\t\tconfigurationsNode = JSONC.findNodeAtLocation(root!, [\n\t\t\t'configurations',\n\t\t]);\n\t}\n\n\t// Check if configuration already exists\n\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t(child: any) =>\n\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t);\n\n\t// Only add configuration if it doesn't exist\n\tif (configurationIndex === undefined || configurationIndex < 0) {\n\t\tconst configuration: VSCodeConfigNode = {\n\t\t\tname: name,\n\t\t\ttype: 'php',\n\t\t\trequest: 'launch',\n\t\t\tport: 9003,\n\t\t};\n\n\t\tif (mappings && mappings.length) {\n\t\t\tconfiguration.pathMappings = mappings.reduce((acc, mount) => {\n\t\t\t\tacc[mount.vfsPath] = `\\${workspaceFolder}/${toPosixPath(\n\t\t\t\t\tpath.relative(options.workspaceDir, mount.hostPath)\n\t\t\t\t)}`;\n\t\t\t\treturn acc;\n\t\t\t}, {} as VSCodeConfigMetaData);\n\t\t}\n\n\t\t// Get the current length to append at the end\n\t\tconst currentLength = configurationsNode?.children?.length || 0;\n\n\t\tconst edits = JSONC.modify(\n\t\t\tcontent,\n\t\t\t['configurations', currentLength],\n\t\t\tconfiguration,\n\t\t\t{\n\t\t\t\tformattingOptions: {\n\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\ttabSize: 4,\n\t\t\t\t\teol: '\\n',\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\n\t\tcontent = jsoncApplyEdits(content, edits);\n\t}\n\n\treturn content;\n}\n\n/**\n * Implement necessary parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param mounts The mounts options.\n */\nexport async function addXdebugIDEConfig({\n\tname,\n\tides,\n\thost,\n\tport,\n\tcwd,\n\tmounts,\n\tideKey = 'PHPWASMCLI',\n}: IDEConfig) {\n\tconst mappings = mounts ? filterLocalMounts(cwd, mounts) : [];\n\tconst modifiedConfig: Record<string, string> = {};\n\n\t// PHPstorm\n\tif (ides.includes('phpstorm')) {\n\t\tconst phpStormRelativeConfigFilePath = '.idea/workspace.xml';\n\t\tconst phpStormConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tphpStormRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(phpStormConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tphpStormConfigFilePath,\n\t\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n</project>'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\t\tconst updatedXml = updatePhpStormConfig(contents, {\n\t\t\t\tname,\n\t\t\t\thost,\n\t\t\t\tport,\n\t\t\t\tprojectDir: cwd,\n\t\t\t\tmappings,\n\t\t\t\tideKey,\n\t\t\t});\n\t\t\tfs.writeFileSync(phpStormConfigFilePath, updatedXml);\n\t\t\tmodifiedConfig['phpstorm'] = phpStormRelativeConfigFilePath;\n\t\t}\n\t}\n\n\t// VSCode\n\tif (ides.includes('vscode')) {\n\t\tconst vsCodeRelativeConfigFilePath = '.vscode/launch.json';\n\t\tconst vsCodeConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tvsCodeRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(vsCodeConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tvsCodeConfigFilePath,\n\t\t\t\t\t'{\\n \"configurations\": []\\n}'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\t\tconst updatedJson = updateVSCodeConfig(content, {\n\t\t\t\tname,\n\t\t\t\tworkspaceDir: cwd,\n\t\t\t\tmappings,\n\t\t\t});\n\n\t\t\t// Only write and track the file if changes were made\n\t\t\tif (updatedJson !== content) {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, updatedJson);\n\t\t\t\tmodifiedConfig['vscode'] = vsCodeRelativeConfigFilePath;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn modifiedConfig;\n}\n\n/**\n * Remove stale parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param cwd The current working directory.\n */\nexport async function clearXdebugIDEConfig(name: string, cwd: string) {\n\tconst phpStormConfigFilePath = path.join(cwd, '.idea/workspace.xml');\n\t// PhpStorm\n\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\tconst xmlParser = new XMLParser(xmlParserOptions);\n\t\t// NOTE: Using an IIFE so `config` can remain const.\n\t\tconst config: PhpStormConfigNode[] = (() => {\n\t\t\ttry {\n\t\t\t\treturn xmlParser.parse(contents, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\t\t})();\n\n\t\tconst projectElement = config.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.project\n\t\t);\n\t\tconst componentElement = projectElement?.project?.find(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t\t);\n\t\tconst serversElement = componentElement?.component?.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t\t);\n\t\tconst serverElementIndex = serversElement?.servers?.findIndex(\n\t\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t\t);\n\n\t\tif (serverElementIndex !== undefined && serverElementIndex >= 0) {\n\t\t\tserversElement!.servers!.splice(serverElementIndex, 1);\n\n\t\t\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\t\t\tconst xml = xmlBuilder.build(config);\n\n\t\t\ttry {\n\t\t\t\txmlParser.parse(xml, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\txml ===\n\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n\t<component name=\"PhpServers\">\\n\t\t<servers></servers>\\n\t</component>\\n</project>'\n\t\t\t) {\n\t\t\t\tfs.unlinkSync(phpStormConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(phpStormConfigFilePath, xml);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst vsCodeConfigFilePath = path.join(cwd, '.vscode/launch.json');\n\t// VSCode\n\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\tconst errors: JSONC.ParseError[] = [];\n\n\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\tconst root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\t\tif (root === undefined || errors.length) {\n\t\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t\t}\n\n\t\tconst configurationsNode = JSONC.findNodeAtLocation(root, [\n\t\t\t'configurations',\n\t\t]);\n\n\t\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t\t(child: any) =>\n\t\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t\t);\n\n\t\tif (configurationIndex !== undefined && configurationIndex >= 0) {\n\t\t\tconst edits = JSONC.modify(\n\t\t\t\tcontent,\n\t\t\t\t['configurations', configurationIndex],\n\t\t\t\tundefined,\n\t\t\t\t{\n\t\t\t\t\tformattingOptions: {\n\t\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\t\ttabSize: 4,\n\t\t\t\t\t\teol: '\\n',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tconst json = jsoncApplyEdits(content, edits);\n\t\t\tif (json === '{\\n \"configurations\": []\\n}') {\n\t\t\t\tfs.unlinkSync(vsCodeConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, json);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction jsoncApplyEdits(content: string, edits: JSONC.Edit[]) {\n\tconst errors: JSONC.ParseError[] = [];\n\tconst json = JSONC.applyEdits(content, edits);\n\n\terrors.length = 0;\n\n\tJSONC.parseTree(json, errors, jsoncParseOptions);\n\n\tif (errors.length) {\n\t\tconst formattedErrors = errors\n\t\t\t.map((error) => {\n\t\t\t\treturn {\n\t\t\t\t\tmessage: JSONC.printParseErrorCode(error.error),\n\t\t\t\t\toffset: error.offset,\n\t\t\t\t\tlength: error.length,\n\t\t\t\t\tfragment: json.slice(\n\t\t\t\t\t\tMath.max(0, error.offset - 20),\n\t\t\t\t\t\tMath.min(json.length, error.offset + error.length + 10)\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.map(\n\t\t\t\t(error) =>\n\t\t\t\t\t`${error.message} at ${error.offset}:${error.length} (${error.fragment})`\n\t\t\t);\n\t\tconst formattedEdits = edits.map(\n\t\t\t(edit) => `At ${edit.offset}:${edit.length} - (${edit.content})`\n\t\t);\n\t\tthrow new Error(\n\t\t\t`VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely ` +\n\t\t\t\t`a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents ` +\n\t\t\t\t`of your \".vscode/launch.json\" file. \\n\\n Applied edits: ${formattedEdits.join(\n\t\t\t\t\t'\\n'\n\t\t\t\t)}\\n\\n The errors are: ${formattedErrors.join('\\n')}`\n\t\t);\n\t}\n\n\treturn json;\n}\n"],"names":["createTempDirSymlink","nativeDirPath","symlinkPath","platform","type","fs","removeTempDirSymlink","filterLocalMounts","cwd","mounts","mount","absoluteHostPath","path","cwdChildPrefix","xmlParserOptions","xmlBuilderOptions","jsoncParseOptions","updatePhpStormConfig","xmlContent","options","name","host","port","mappings","ideKey","xmlParser","XMLParser","config","serverElement","mapping","toPosixPath","projectElement","c","projectVersion","_a","componentElement","_b","serversElement","_c","serverElementIndex","_d","runManagerElement","_e","_f","runConfigElement","xml","XMLBuilder","updateVSCodeConfig","jsonContent","errors","content","root","JSONC","configurationsNode","edits","configurationIndex","child","configuration","acc","currentLength","jsoncApplyEdits","addXdebugIDEConfig","ides","modifiedConfig","phpStormRelativeConfigFilePath","phpStormConfigFilePath","contents","updatedXml","vsCodeRelativeConfigFilePath","vsCodeConfigFilePath","updatedJson","clearXdebugIDEConfig","json","formattedErrors","error","formattedEdits","edit"],"mappings":"qeAqBA,eAAsBA,EACrBC,EACAC,EACAC,EACC,CACD,MAAMC,EACLD,IAAa,QAIX,WACC,MACJE,EAAG,YAAYJ,EAAeC,EAAaE,CAAI,CAChD,CAOA,eAAsBE,EAAqBJ,EAAqB,CAC/D,GAAI,CACWG,EAAG,UAAUH,CAAW,EAC5B,kBACTG,EAAG,WAAWH,CAAW,CAE3B,MAAQ,CAER,CACD,CAOA,SAASK,EAAkBC,EAAaC,EAAiB,CACxD,OAAOA,EAAO,OAAQC,GAAU,CAC/B,MAAMC,EAAmBC,EAAK,QAAQF,EA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AM,OAAS,EAAE,CAAA,CACvD,EAED,EACA,IACCA,GACA,GAAGA,EAAM,OAAO,OAAOA,EAAM,MAAM,IAAIA,EAAM,MAAM,KAAKA,EAAM,QAAQ,GAAA,EAEnEC,EAAiBrB,EAAM,IAC3BsB,GAAS,MAAMA,EAAK,MAAM,IAAIA,EAAK,MAAM,OAAOA,EAAK,OAAO,GAAA,EAE9D,MAAM,IAAI,MACT;AAAA;AAAA,kBAE4DD,EAAe,KACzE;AAAA,CAAA,CACA;AAAA;AAAA,mBAAwBF,EAAgB,KAAK;AAAA,CAAI,CAAC,EAAA,CAEtD,CAEA,OAAOD,CACR"} | ||
| {"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/cli-util/src/lib/xdebug-path-mappings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { toPosixPath } from '@php-wasm/util';\nimport type { Mount } from './mounts';\nimport {\n\ttype X2jOptions,\n\ttype XmlBuilderOptions,\n\tXMLParser,\n\tXMLBuilder,\n} from 'fast-xml-parser';\nimport * as JSONC from 'jsonc-parser';\n\nexport interface XdebugOptions {\n\tideKey?: string;\n\tpathMappings?: Mount[];\n\tpathSkippings?: string[];\n}\n\nexport const DEFAULT_IDE_KEY = 'PHPWASMCLI';\n\n/**\n * Create a symlink to a tempory directory.\n *\n * The symlink is created to access the system temp dir\n * inside the current debugging directory.\n *\n * @param nativeDirPath The system temp dir path.\n * @param symlinkPath The symlink name.\n */\nexport async function createTempDirSymlink(\n\tnativeDirPath: string,\n\tsymlinkPath: string,\n\tplatform: string\n) {\n\tconst type =\n\t\tplatform === 'win32'\n\t\t\t? // On Windows, creating a 'dir' symlink can require elevated permissions.\n\t\t\t\t// In this case, let's make junction points because they function like\n\t\t\t\t// symlinks and do not require elevated permissions.\n\t\t\t\t'junction'\n\t\t\t: 'dir';\n\tfs.symlinkSync(nativeDirPath, symlinkPath, type);\n}\n\n/**\n * Remove the given temporary directory symlink if it exists.\n *\n * @param symlinkPath The symlink path.\n */\nexport async function removeTempDirSymlink(symlinkPath: string) {\n\ttry {\n\t\tconst stats = fs.lstatSync(symlinkPath);\n\t\tif (stats.isSymbolicLink()) {\n\t\t\tfs.unlinkSync(symlinkPath);\n\t\t}\n\t} catch {\n\t\t// Symlink does not exist or cannot be accessed, nothing to remove\n\t}\n}\n\n/**\n * Filters out mounts that are not in the current working directory\n *\n * @param mounts The mounts list.\n */\nfunction filterLocalMounts(cwd: string, mounts: Mount[]) {\n\treturn mounts.filter((mount) => {\n\t\tconst absoluteHostPath = path.resolve(mount.hostPath);\n\t\tconst cwdChildPrefix = path.join(cwd, path.sep);\n\t\treturn (\n\t\t\t// If auto-mounting from the current directory,\n\t\t\t// the entire project directory can be mapped.\n\t\t\tabsoluteHostPath === cwd ||\n\t\t\tabsoluteHostPath.startsWith(cwdChildPrefix)\n\t\t);\n\t});\n}\n\nexport type XdebugConfig = {\n\t/**\n\t * The current working directory to consider for debugger path mapping.\n\t */\n\tcwd?: string;\n\t/**\n\t * The mounts to consider for debugger path mapping.\n\t */\n\tmounts?: Mount[];\n\t/**\n\t * The paths to consider for debugger path skipping.\n\t */\n\tpathSkippings?: string[];\n};\n\nexport type IDEConfig = {\n\t/**\n\t * The name of the configuration within the IDE configuration.\n\t */\n\tname: string;\n\t/**\n\t * The IDEs to configure.\n\t */\n\tides: string[];\n\t/**\n\t * The web server host.\n\t */\n\thost: string;\n\t/**\n\t * The web server port.\n\t */\n\tport: number;\n\t/**\n\t * The current working directory to consider for debugger path mapping.\n\t */\n\tcwd: string;\n\t/**\n\t * The mounts to consider for debugger path mapping.\n\t */\n\tmounts?: Mount[];\n\t/**\n\t * The IDE key to use for the debug configuration. Defaults to 'PHPWASMCLI'.\n\t */\n\tideKey?: string;\n};\n\ntype PhpStormConfigMetaData = {\n\tname?: string;\n\tversion?: string;\n\thost?: string;\n\tuse_path_mappings?: string;\n\t'local-root'?: string;\n\t'remote-root'?: string;\n\t/**\n\t * The type of the server.\n\t */\n\ttype?: 'PhpRemoteDebugRunConfigurationType';\n\tfactoryName?: string;\n\tfilter_connections?: 'FILTER';\n\tserver_name?: string;\n\tsession_id?: string;\n\tv?: string;\n};\n\ntype PhpStormConfigNode = {\n\t':@'?: PhpStormConfigMetaData;\n\tproject?: PhpStormConfigNode[];\n\tcomponent?: PhpStormConfigNode[];\n\tservers?: PhpStormConfigNode[];\n\tserver?: PhpStormConfigNode[];\n\tpath_mappings?: PhpStormConfigNode[];\n\tmapping?: PhpStormConfigNode[];\n\tconfiguration?: PhpStormConfigNode[];\n\tmethod?: PhpStormConfigNode[];\n};\n\ntype VSCodeConfigMetaData = {\n\t[key: string]: string;\n};\n\ntype VSCodeConfigNode = {\n\tname: string;\n\ttype: string;\n\trequest: string;\n\tport: number;\n\tpathMappings?: VSCodeConfigMetaData;\n};\n\nconst xmlParserOptions: X2jOptions = {\n\tignoreAttributes: false,\n\tattributeNamePrefix: '',\n\tpreserveOrder: true,\n\tcdataPropName: '__cdata',\n\tcommentPropName: '__xmlComment',\n\tallowBooleanAttributes: true,\n\ttrimValues: true,\n};\nconst xmlBuilderOptions: XmlBuilderOptions = {\n\tignoreAttributes: xmlParserOptions.ignoreAttributes,\n\tattributeNamePrefix: xmlParserOptions.attributeNamePrefix,\n\tpreserveOrder: xmlParserOptions.preserveOrder,\n\tcdataPropName: xmlParserOptions.cdataPropName,\n\tcommentPropName: xmlParserOptions.commentPropName,\n\tsuppressBooleanAttributes: !xmlParserOptions.allowBooleanAttributes,\n\tformat: true,\n\tindentBy: '\\t',\n};\n\nconst jsoncParseOptions: JSONC.ParseOptions = {\n\tallowEmptyContent: true,\n\tallowTrailingComma: true,\n};\n\nexport type PhpStormConfigOptions = {\n\tname: string;\n\thost: string;\n\tport: number;\n\tprojectDir: string;\n\tmappings?: Mount[];\n\tideKey: string;\n};\n\n/**\n * Pure function to update PHPStorm XML config with Xdebug server and run configuration.\n *\n * @param xmlContent The original XML content of workspace.xml\n * @param options Configuration options for the server\n * @returns Updated XML content\n * @throws Error if XML is invalid or configuration is incompatible\n */\nexport function updatePhpStormConfig(\n\txmlContent: string,\n\toptions: PhpStormConfigOptions\n): string {\n\tconst { name, host, port, mappings, ideKey } = options;\n\n\tconst xmlParser = new XMLParser(xmlParserOptions);\n\n\t// Parse the XML\n\tconst config: PhpStormConfigNode[] = (() => {\n\t\ttry {\n\t\t\treturn xmlParser.parse(xmlContent, true);\n\t\t} catch {\n\t\t\tthrow new Error('PhpStorm configuration file is not valid XML.');\n\t\t}\n\t})();\n\n\t// Create the server element with path mappings\n\tconst serverElement: PhpStormConfigNode = {\n\t\tserver: [{}],\n\t\t':@': {\n\t\t\tname,\n\t\t\t// NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port)\n\t\t\t// is provided in `host`. The separate `port` field is ignored or misinterpreted,\n\t\t\t// so we rely solely on host: \"host:port\".\n\t\t\thost: `${host}:${port}`,\n\t\t\tuse_path_mappings: 'true',\n\t\t},\n\t};\n\n\tif (mappings && mappings.length) {\n\t\tserverElement.server![0].path_mappings = mappings.map((mapping) => ({\n\t\t\tmapping: [],\n\t\t\t':@': {\n\t\t\t\t'local-root': `$PROJECT_DIR$/${toPosixPath(\n\t\t\t\t\tpath.relative(options.projectDir, mapping.hostPath)\n\t\t\t\t)}`,\n\t\t\t\t'remote-root': mapping.vfsPath,\n\t\t\t},\n\t\t}));\n\t}\n\n\t// Find or create project element\n\tlet projectElement = config?.find((c: PhpStormConfigNode) => !!c?.project);\n\tif (projectElement) {\n\t\tconst projectVersion = projectElement[':@']?.version;\n\t\tif (projectVersion === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t'but the <project> configuration has no version number.'\n\t\t\t);\n\t\t} else if (projectVersion !== '4') {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t`but we found a <project> configuration with version \"${projectVersion}\".`\n\t\t\t);\n\t\t}\n\t}\n\tif (projectElement === undefined) {\n\t\tprojectElement = {\n\t\t\tproject: [],\n\t\t\t':@': { version: '4' },\n\t\t};\n\t\tconfig.push(projectElement);\n\t}\n\n\t// Find or create PhpServers component\n\tlet componentElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t);\n\tif (componentElement === undefined) {\n\t\tcomponentElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'PhpServers' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(componentElement);\n\t}\n\n\t// Find or create servers element\n\tlet serversElement = componentElement.component?.find(\n\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t);\n\tif (serversElement === undefined) {\n\t\tserversElement = { servers: [] };\n\n\t\tif (componentElement.component === undefined) {\n\t\t\tcomponentElement.component = [];\n\t\t}\n\n\t\tcomponentElement.component.push(serversElement);\n\t}\n\n\t// Check if server already exists\n\tconst serverElementIndex = serversElement.servers?.findIndex(\n\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t);\n\n\t// Only add server if it doesn't exist\n\tif (serverElementIndex === undefined || serverElementIndex < 0) {\n\t\tif (serversElement.servers === undefined) {\n\t\t\tserversElement.servers = [];\n\t\t}\n\n\t\tserversElement.servers.push(serverElement);\n\t}\n\n\t// Find or create RunManager component\n\tlet runManagerElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'RunManager'\n\t);\n\tif (runManagerElement === undefined) {\n\t\trunManagerElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'RunManager' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(runManagerElement);\n\t}\n\n\t// Check if run configuration already exists\n\tconst existingConfigIndex =\n\t\trunManagerElement.component?.findIndex(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.configuration && c?.[':@']?.name === name\n\t\t) ?? -1;\n\n\t// Only add run configuration if it doesn't exist\n\tif (existingConfigIndex < 0) {\n\t\tconst runConfigElement: PhpStormConfigNode = {\n\t\t\tconfiguration: [\n\t\t\t\t{\n\t\t\t\t\tmethod: [],\n\t\t\t\t\t':@': { v: '2' },\n\t\t\t\t},\n\t\t\t],\n\t\t\t':@': {\n\t\t\t\tname: name,\n\t\t\t\ttype: 'PhpRemoteDebugRunConfigurationType',\n\t\t\t\tfactoryName: 'PHP Remote Debug',\n\t\t\t\tfilter_connections: 'FILTER',\n\t\t\t\tserver_name: name,\n\t\t\t\tsession_id: ideKey,\n\t\t\t},\n\t\t};\n\n\t\tif (runManagerElement.component === undefined) {\n\t\t\trunManagerElement.component = [];\n\t\t}\n\n\t\trunManagerElement.component.push(runConfigElement);\n\t}\n\n\t// Build the updated XML\n\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\tconst xml = xmlBuilder.build(config);\n\n\t// Validate the generated XML\n\ttry {\n\t\txmlParser.parse(xml, true);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t);\n\t}\n\n\treturn xml;\n}\n\nexport type VSCodeConfigOptions = {\n\tname: string;\n\tworkspaceDir: string;\n\tmappings?: Mount[];\n};\n\n/**\n * Pure function to update VS Code JSON config with Xdebug configuration.\n *\n * @param jsonContent The original JSON content of launch.json\n * @param options Configuration options\n * @returns Updated JSON content\n * @throws Error if JSON is invalid\n */\nexport function updateVSCodeConfig(\n\tjsonContent: string,\n\toptions: VSCodeConfigOptions\n): string {\n\tconst { name, mappings } = options;\n\n\tconst errors: JSONC.ParseError[] = [];\n\n\tlet content = jsonContent;\n\tlet root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\tif (root === undefined || errors.length) {\n\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t}\n\n\t// Find or create configurations array\n\tlet configurationsNode = JSONC.findNodeAtLocation(root, ['configurations']);\n\n\tif (\n\t\tconfigurationsNode === undefined ||\n\t\tconfigurationsNode.children === undefined\n\t) {\n\t\tconst edits = JSONC.modify(content, ['configurations'], [], {});\n\t\tcontent = JSONC.applyEdits(content, edits);\n\n\t\troot = JSONC.parseTree(content, [], jsoncParseOptions);\n\t\tconfigurationsNode = JSONC.findNodeAtLocation(root!, [\n\t\t\t'configurations',\n\t\t]);\n\t}\n\n\t// Check if configuration already exists\n\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t(child: any) =>\n\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t);\n\n\t// Only add configuration if it doesn't exist\n\tif (configurationIndex === undefined || configurationIndex < 0) {\n\t\tconst configuration: VSCodeConfigNode = {\n\t\t\tname: name,\n\t\t\ttype: 'php',\n\t\t\trequest: 'launch',\n\t\t\tport: 9003,\n\t\t};\n\n\t\tif (mappings && mappings.length) {\n\t\t\tconfiguration.pathMappings = mappings.reduce((acc, mount) => {\n\t\t\t\tacc[mount.vfsPath] = `\\${workspaceFolder}/${toPosixPath(\n\t\t\t\t\tpath.relative(options.workspaceDir, mount.hostPath)\n\t\t\t\t)}`;\n\t\t\t\treturn acc;\n\t\t\t}, {} as VSCodeConfigMetaData);\n\t\t}\n\n\t\t// Get the current length to append at the end\n\t\tconst currentLength = configurationsNode?.children?.length || 0;\n\n\t\tconst edits = JSONC.modify(\n\t\t\tcontent,\n\t\t\t['configurations', currentLength],\n\t\t\tconfiguration,\n\t\t\t{\n\t\t\t\tformattingOptions: {\n\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\ttabSize: 4,\n\t\t\t\t\teol: '\\n',\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\n\t\tcontent = jsoncApplyEdits(content, edits);\n\t}\n\n\treturn content;\n}\n\n/**\n * Implement necessary parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param mounts The mounts options.\n */\nexport async function addXdebugIDEConfig({\n\tname,\n\tides,\n\thost,\n\tport,\n\tcwd,\n\tmounts,\n\tideKey = DEFAULT_IDE_KEY,\n}: IDEConfig) {\n\tconst mappings = mounts ? filterLocalMounts(cwd, mounts) : [];\n\tconst modifiedConfig: Record<string, string> = {};\n\n\t// PHPstorm\n\tif (ides.includes('phpstorm')) {\n\t\tconst phpStormRelativeConfigFilePath = '.idea/workspace.xml';\n\t\tconst phpStormConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tphpStormRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(phpStormConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tphpStormConfigFilePath,\n\t\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n</project>'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\t\tconst updatedXml = updatePhpStormConfig(contents, {\n\t\t\t\tname,\n\t\t\t\thost,\n\t\t\t\tport,\n\t\t\t\tprojectDir: cwd,\n\t\t\t\tmappings,\n\t\t\t\tideKey,\n\t\t\t});\n\t\t\tfs.writeFileSync(phpStormConfigFilePath, updatedXml);\n\t\t\tmodifiedConfig['phpstorm'] = phpStormRelativeConfigFilePath;\n\t\t}\n\t}\n\n\t// VSCode\n\tif (ides.includes('vscode')) {\n\t\tconst vsCodeRelativeConfigFilePath = '.vscode/launch.json';\n\t\tconst vsCodeConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tvsCodeRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(vsCodeConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tvsCodeConfigFilePath,\n\t\t\t\t\t'{\\n \"configurations\": []\\n}'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\t\tconst updatedJson = updateVSCodeConfig(content, {\n\t\t\t\tname,\n\t\t\t\tworkspaceDir: cwd,\n\t\t\t\tmappings,\n\t\t\t});\n\n\t\t\t// Only write and track the file if changes were made\n\t\t\tif (updatedJson !== content) {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, updatedJson);\n\t\t\t\tmodifiedConfig['vscode'] = vsCodeRelativeConfigFilePath;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn modifiedConfig;\n}\n\n/**\n * Remove stale parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param cwd The current working directory.\n */\nexport async function clearXdebugIDEConfig(name: string, cwd: string) {\n\tconst phpStormConfigFilePath = path.join(cwd, '.idea/workspace.xml');\n\t// PhpStorm\n\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\tconst xmlParser = new XMLParser(xmlParserOptions);\n\t\t// NOTE: Using an IIFE so `config` can remain const.\n\t\tconst config: PhpStormConfigNode[] = (() => {\n\t\t\ttry {\n\t\t\t\treturn xmlParser.parse(contents, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\t\t})();\n\n\t\tconst projectElement = config.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.project\n\t\t);\n\t\tconst componentElement = projectElement?.project?.find(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t\t);\n\t\tconst serversElement = componentElement?.component?.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t\t);\n\t\tconst serverElementIndex = serversElement?.servers?.findIndex(\n\t\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t\t);\n\n\t\tif (serverElementIndex !== undefined && serverElementIndex >= 0) {\n\t\t\tserversElement!.servers!.splice(serverElementIndex, 1);\n\n\t\t\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\t\t\tconst xml = xmlBuilder.build(config);\n\n\t\t\ttry {\n\t\t\t\txmlParser.parse(xml, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\txml ===\n\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n\t<component name=\"PhpServers\">\\n\t\t<servers></servers>\\n\t</component>\\n</project>'\n\t\t\t) {\n\t\t\t\tfs.unlinkSync(phpStormConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(phpStormConfigFilePath, xml);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst vsCodeConfigFilePath = path.join(cwd, '.vscode/launch.json');\n\t// VSCode\n\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\tconst errors: JSONC.ParseError[] = [];\n\n\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\tconst root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\t\tif (root === undefined || errors.length) {\n\t\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t\t}\n\n\t\tconst configurationsNode = JSONC.findNodeAtLocation(root, [\n\t\t\t'configurations',\n\t\t]);\n\n\t\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t\t(child: any) =>\n\t\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t\t);\n\n\t\tif (configurationIndex !== undefined && configurationIndex >= 0) {\n\t\t\tconst edits = JSONC.modify(\n\t\t\t\tcontent,\n\t\t\t\t['configurations', configurationIndex],\n\t\t\t\tundefined,\n\t\t\t\t{\n\t\t\t\t\tformattingOptions: {\n\t\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\t\ttabSize: 4,\n\t\t\t\t\t\teol: '\\n',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tconst json = jsoncApplyEdits(content, edits);\n\t\t\tif (json === '{\\n \"configurations\": []\\n}') {\n\t\t\t\tfs.unlinkSync(vsCodeConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, json);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Implement path mapping and path skipping in Xdebug.\n *\n * @param name The configuration name.\n * @param mounts The mounts options.\n * @param pathSkippings The skipping paths options.\n * @returns Xdebug options\n */\nexport function makeXdebugConfig({\n\tcwd,\n\tmounts,\n\tpathSkippings,\n}: XdebugConfig): XdebugOptions {\n\tconst pathMappings =\n\t\tcwd && mounts ? filterLocalMounts(cwd, mounts) : undefined;\n\n\treturn { pathMappings, pathSkippings };\n}\n\nfunction jsoncApplyEdits(content: string, edits: JSONC.Edit[]) {\n\tconst errors: JSONC.ParseError[] = [];\n\tconst json = JSONC.applyEdits(content, edits);\n\n\terrors.length = 0;\n\n\tJSONC.parseTree(json, errors, jsoncParseOptions);\n\n\tif (errors.length) {\n\t\tconst formattedErrors = errors\n\t\t\t.map((error) => {\n\t\t\t\treturn {\n\t\t\t\t\tmessage: JSONC.printParseErrorCode(error.error),\n\t\t\t\t\toffset: error.offset,\n\t\t\t\t\tlength: error.length,\n\t\t\t\t\tfragment: json.slice(\n\t\t\t\t\t\tMath.max(0, error.offset - 20),\n\t\t\t\t\t\tMath.min(json.length, error.offset + error.length + 10)\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.map(\n\t\t\t\t(error) =>\n\t\t\t\t\t`${error.message} at ${error.offset}:${error.length} (${error.fragment})`\n\t\t\t);\n\t\tconst formattedEdits = edits.map(\n\t\t\t(edit) => `At ${edit.offset}:${edit.length} - (${edit.content})`\n\t\t);\n\t\tthrow new Error(\n\t\t\t`VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely ` +\n\t\t\t\t`a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents ` +\n\t\t\t\t`of your \".vscode/launch.json\" file. \\n\\n Applied edits: ${formattedEdits.join(\n\t\t\t\t\t'\\n'\n\t\t\t\t)}\\n\\n The errors are: ${formattedErrors.join('\\n')}`\n\t\t);\n\t}\n\n\treturn json;\n}\n"],"names":["DEFAULT_IDE_KEY","createTempDirSymlink","nativeDirPath","symlinkPath","platform","type","fs","removeTempDirSymlink","filterLocalMounts","cwd","mounts","mount","absoluteHostPath","path","cwdChildPrefix","xmlParserOptions","xmlBuilderOptions","jsoncParseOptions","updatePhpStormConfig","xmlContent","options","name","host","port","mappings","ideKey","xmlParser","XMLParser","config","serverElement","mapping","toPosixPath","projectElement","c","projectVersion","_a","componentElement","_b","serversElement","_c","serverElementIndex","_d","runManagerElement","_e","_f","runConfigElement","xml","XMLBuilder","updateVSCodeConfig","jsonContent","errors","content","root","JSONC","configurationsNode","edits","configurationIndex","child","configuration","acc","currentLength","jsoncApplyEdits","addXdebugIDEConfig","ides","modifiedConfig","phpStormRelativeConfigFilePath","phpStormConfigFilePath","contents","updatedXml","vsCodeRelativeConfigFilePath","vsCodeConfigFilePath","updatedJson","clearXdebugIDEConfig","json","makeXdebugConfig","pathSkippings","formattedErrors","error","formattedEdits","edit"],"mappings":"qeAkBaA,EAAkB,aAW/B,eAAsBC,EACrBC,EACAC,EACAC,EACC,CACD,MAAMC,EACLD,IAAa,QAIX,WACC,MACJE,EAAG,YAAYJ,EAAeC,EAAaE,CAAI,CAChD,CAOA,eAAsBE,EAAqBJ,EAAqB,CAC/D,GAAI,CACWG,EAAG,UAAUH,CAAW,EAC5B,kBACTG,EAAG,WAAWH,CAAW,CAE3B,MAAQ,CAER,CACD,CAOA,SAASK,EAAkBC,EAAaC,EAAiB,CACxD,OAAOA,EAAO,OAAQC,GAAU,CAC/B,MAAMC,EAAmBC,EAAK,QAAQF,EAAM,QAAQ,EAC9CG,EAAiBD,EAAK,KAAKJ,EAAKI,EAAK,GAAG,EAC9C,OAGCD,IAAqBH,GACrBG,EAAiB,WAAWE,CAAc,CAE5C,CAAC,CACF,CA0FA,MAAMC,EAA+B,CACpC,iBAAkB,GAClB,oBAAqB,GACrB,cAAe,GACf,cAAe,UACf,gBAAiB,eACjB,uBAAwB,GACxB,WAAY,EACb,EACMC,EAAuC,CAC5C,iBAAkBD,EAAiB,iBACnC,oBAAqBA,EAAiB,oBACtC,cAAeA,EAAiB,cAChC,cAAeA,EAAiB,cAChC,gBAAiBA,EAAiB,gBAClC,0BAA2B,CAACA,EAAiB,uBAC7C,OAAQ,GACR,SAAU,GACX,EAEME,EAAwC,CAC7C,kBAAmB,GACnB,mBAAoB,EACrB,EAmBO,SAASC,EACfC,EACAC,EACS,iBACT,KAAM,CAAE,KAAAC,EAAM,KAAAC,EAAM,KAAAC,EAAM,SAAAC,EAAU,OAAAC,GAAWL,EAEzCM,EAAY,IAAIC,EAAAA,UAAUZ,CAAgB,EAG1Ca,GAAgC,IAAM,CAC3C,GAAI,CACH,OAAOF,EAAU,MAAMP,EAAY,EAAI,CACxC,MAAQ,CACP,MAAM,IAAI,MAAM,+CAA+C,CAChE,CACD,GAAA,EAGMU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gC,CAI/B,MAAO,CAAE,aAFRlE,GAAOC,EAASF,EAAkBC,EAAKC,CAAM,EAAI,OAE3B,cAAAiE,CAAA,CACxB,CAEA,SAASd,EAAgBV,EAAiBI,EAAqB,CAC9D,MAAML,EAA6B,CAAA,EAC7BuB,EAAOpB,EAAM,WAAWF,EAASI,CAAK,EAM5C,GAJAL,EAAO,OAAS,EAEhBG,EAAM,UAAUoB,EAAMvB,EAAQjC,CAAiB,EAE3CiC,EAAO,OAAQ,CAClB,MAAM0B,EAAkB1B,EACtB,IAAK2B,IACE,CACN,QAASxB,EAAM,oBAAoBwB,EAAM,KAAK,EAC9C,OAAQA,EAAM,OACd,OAAQA,EAAM,OACd,SAAUJ,EAAK,MACd,KAAK,IAAI,EAAGI,EAAM,OAAS,EAAE,EAC7B,KAAK,IAAIJ,EAAK,OAAQI,EAAM,OAASA,EAAM,OAAS,EAAE,CAAA,CACvD,EAED,EACA,IACCA,GACA,GAAGA,EAAM,OAAO,OAAOA,EAAM,MAAM,IAAIA,EAAM,MAAM,KAAKA,EAAM,QAAQ,GAAA,EAEnEC,EAAiBvB,EAAM,IAC3BwB,GAAS,MAAMA,EAAK,MAAM,IAAIA,EAAK,MAAM,OAAOA,EAAK,OAAO,GAAA,EAE9D,MAAM,IAAI,MACT;AAAA;AAAA,kBAE4DD,EAAe,KACzE;AAAA,CAAA,CACA;AAAA;AAAA,mBAAwBF,EAAgB,KAAK;AAAA,CAAI,CAAC,EAAA,CAEtD,CAEA,OAAOH,CACR"} |
+117
-107
@@ -1,8 +0,9 @@ | ||
| import a from "fs"; | ||
| import f from "fs"; | ||
| import P from "path"; | ||
| import { toPosixPath as k } from "@php-wasm/util"; | ||
| import { XMLParser as T, XMLBuilder as A } from "fast-xml-parser"; | ||
| import { toPosixPath as D } from "@php-wasm/util"; | ||
| import { XMLParser as T, XMLBuilder as $ } from "fast-xml-parser"; | ||
| import * as v from "jsonc-parser"; | ||
| async function J(d, f, s) { | ||
| const p = s === "win32" ? ( | ||
| const O = "PHPWASMCLI"; | ||
| async function q(c, a, r) { | ||
| const p = r === "win32" ? ( | ||
| // On Windows, creating a 'dir' symlink can require elevated permissions. | ||
@@ -13,17 +14,17 @@ // In this case, let's make junction points because they function like | ||
| ) : "dir"; | ||
| a.symlinkSync(d, f, p); | ||
| f.symlinkSync(c, a, p); | ||
| } | ||
| async function q(d) { | ||
| async function H(c) { | ||
| try { | ||
| a.lstatSync(d).isSymbolicLink() && a.unlinkSync(d); | ||
| f.lstatSync(c).isSymbolicLink() && f.unlinkSync(c); | ||
| } catch { | ||
| } | ||
| } | ||
| function M(d, f) { | ||
| return f.filter((s) => { | ||
| const p = P.resolve(s.hostPath), h = P.join(d, P.sep); | ||
| function A(c, a) { | ||
| return a.filter((r) => { | ||
| const p = P.resolve(r.hostPath), h = P.join(c, P.sep); | ||
| return ( | ||
| // If auto-mounting from the current directory, | ||
| // the entire project directory can be mapped. | ||
| p === d || p.startsWith(h) | ||
| p === c || p.startsWith(h) | ||
| ); | ||
@@ -40,3 +41,3 @@ }); | ||
| trimValues: !0 | ||
| }, D = { | ||
| }, M = { | ||
| ignoreAttributes: x.ignoreAttributes, | ||
@@ -54,7 +55,7 @@ attributeNamePrefix: x.attributeNamePrefix, | ||
| }; | ||
| function O(d, f) { | ||
| var E, b, I, F, L, $; | ||
| const { name: s, host: p, port: h, mappings: l, ideKey: t } = f, m = new T(x), g = (() => { | ||
| function _(c, a) { | ||
| var E, b, I, F, L, k; | ||
| const { name: r, host: p, port: h, mappings: l, ideKey: t } = a, m = new T(x), g = (() => { | ||
| try { | ||
| return m.parse(d, !0); | ||
| return m.parse(c, !0); | ||
| } catch { | ||
@@ -66,3 +67,3 @@ throw new Error("PhpStorm configuration file is not valid XML."); | ||
| ":@": { | ||
| name: s, | ||
| name: r, | ||
| // NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port) | ||
@@ -78,4 +79,4 @@ // is provided in `host`. The separate `port` field is ignored or misinterpreted, | ||
| ":@": { | ||
| "local-root": `$PROJECT_DIR$/${k( | ||
| P.relative(f.projectDir, e.hostPath) | ||
| "local-root": `$PROJECT_DIR$/${D( | ||
| P.relative(a.projectDir, e.hostPath) | ||
| )}`, | ||
@@ -111,14 +112,14 @@ "remote-root": e.vfsPath | ||
| }, n.project === void 0 && (n.project = []), n.project.push(o)); | ||
| let i = (I = o.component) == null ? void 0 : I.find( | ||
| let s = (I = o.component) == null ? void 0 : I.find( | ||
| (e) => !!(e != null && e.servers) | ||
| ); | ||
| i === void 0 && (i = { servers: [] }, o.component === void 0 && (o.component = []), o.component.push(i)); | ||
| const y = (F = i.servers) == null ? void 0 : F.findIndex( | ||
| s === void 0 && (s = { servers: [] }, o.component === void 0 && (o.component = []), o.component.push(s)); | ||
| const y = (F = s.servers) == null ? void 0 : F.findIndex( | ||
| (e) => { | ||
| var S; | ||
| return !!(e != null && e.server) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === s; | ||
| return !!(e != null && e.server) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === r; | ||
| } | ||
| ); | ||
| (y === void 0 || y < 0) && (i.servers === void 0 && (i.servers = []), i.servers.push(u)); | ||
| let c = (L = n.project) == null ? void 0 : L.find( | ||
| (y === void 0 || y < 0) && (s.servers === void 0 && (s.servers = []), s.servers.push(u)); | ||
| let d = (L = n.project) == null ? void 0 : L.find( | ||
| (e) => { | ||
@@ -129,9 +130,9 @@ var S; | ||
| ); | ||
| if (c === void 0 && (c = { | ||
| if (d === void 0 && (d = { | ||
| component: [], | ||
| ":@": { name: "RunManager" } | ||
| }, n.project === void 0 && (n.project = []), n.project.push(c)), ((($ = c.component) == null ? void 0 : $.findIndex( | ||
| }, n.project === void 0 && (n.project = []), n.project.push(d)), (((k = d.component) == null ? void 0 : k.findIndex( | ||
| (e) => { | ||
| var S; | ||
| return !!(e != null && e.configuration) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === s; | ||
| return !!(e != null && e.configuration) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === r; | ||
| } | ||
@@ -147,13 +148,13 @@ )) ?? -1) < 0) { | ||
| ":@": { | ||
| name: s, | ||
| name: r, | ||
| type: "PhpRemoteDebugRunConfigurationType", | ||
| factoryName: "PHP Remote Debug", | ||
| filter_connections: "FILTER", | ||
| server_name: s, | ||
| server_name: r, | ||
| session_id: t | ||
| } | ||
| }; | ||
| c.component === void 0 && (c.component = []), c.component.push(e); | ||
| d.component === void 0 && (d.component = []), d.component.push(e); | ||
| } | ||
| const C = new A(D).build(g); | ||
| const C = new $(M).build(g); | ||
| try { | ||
@@ -168,6 +169,6 @@ m.parse(C, !0); | ||
| } | ||
| function _(d, f) { | ||
| function B(c, a) { | ||
| var u, n; | ||
| const { name: s, mappings: p } = f, h = []; | ||
| let l = d, t = v.parseTree(l, h, j); | ||
| const { name: r, mappings: p } = a, h = []; | ||
| let l = c, t = v.parseTree(l, h, j); | ||
| if (t === void 0 || h.length) | ||
@@ -184,4 +185,4 @@ throw new Error("VS Code configuration file is not valid JSON."); | ||
| (o) => { | ||
| var i; | ||
| return ((i = v.findNodeAtLocation(o, ["name"])) == null ? void 0 : i.value) === s; | ||
| var s; | ||
| return ((s = v.findNodeAtLocation(o, ["name"])) == null ? void 0 : s.value) === r; | ||
| } | ||
@@ -191,3 +192,3 @@ ); | ||
| const o = { | ||
| name: s, | ||
| name: r, | ||
| type: "php", | ||
@@ -197,8 +198,8 @@ request: "launch", | ||
| }; | ||
| p && p.length && (o.pathMappings = p.reduce((c, r) => (c[r.vfsPath] = `\${workspaceFolder}/${k( | ||
| P.relative(f.workspaceDir, r.hostPath) | ||
| )}`, c), {})); | ||
| const i = ((n = m == null ? void 0 : m.children) == null ? void 0 : n.length) || 0, y = v.modify( | ||
| p && p.length && (o.pathMappings = p.reduce((d, i) => (d[i.vfsPath] = `\${workspaceFolder}/${D( | ||
| P.relative(a.workspaceDir, i.hostPath) | ||
| )}`, d), {})); | ||
| const s = ((n = m == null ? void 0 : m.children) == null ? void 0 : n.length) || 0, y = v.modify( | ||
| l, | ||
| ["configurations", i], | ||
| ["configurations", s], | ||
| o, | ||
@@ -218,13 +219,13 @@ { | ||
| } | ||
| async function H({ | ||
| name: d, | ||
| ides: f, | ||
| host: s, | ||
| async function U({ | ||
| name: c, | ||
| ides: a, | ||
| host: r, | ||
| port: p, | ||
| cwd: h, | ||
| mounts: l, | ||
| ideKey: t = "PHPWASMCLI" | ||
| ideKey: t = O | ||
| }) { | ||
| const m = l ? M(h, l) : [], g = {}; | ||
| if (f.includes("phpstorm")) { | ||
| const m = l ? A(h, l) : [], g = {}; | ||
| if (a.includes("phpstorm")) { | ||
| const u = ".idea/workspace.xml", n = P.join( | ||
@@ -234,5 +235,5 @@ h, | ||
| ); | ||
| if (!a.existsSync(n)) { | ||
| if (a.existsSync(P.dirname(n))) | ||
| a.writeFileSync( | ||
| if (!f.existsSync(n)) { | ||
| if (f.existsSync(P.dirname(n))) | ||
| f.writeFileSync( | ||
| n, | ||
@@ -243,3 +244,3 @@ `<?xml version="1.0" encoding="UTF-8"?> | ||
| ); | ||
| else if (f.length == 1) | ||
| else if (a.length == 1) | ||
| throw new Error( | ||
@@ -249,6 +250,6 @@ "PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory." | ||
| } | ||
| if (a.existsSync(n)) { | ||
| const o = a.readFileSync(n, "utf8"), i = O(o, { | ||
| name: d, | ||
| host: s, | ||
| if (f.existsSync(n)) { | ||
| const o = f.readFileSync(n, "utf8"), s = _(o, { | ||
| name: c, | ||
| host: r, | ||
| port: p, | ||
@@ -259,6 +260,6 @@ projectDir: h, | ||
| }); | ||
| a.writeFileSync(n, i), g.phpstorm = u; | ||
| f.writeFileSync(n, s), g.phpstorm = u; | ||
| } | ||
| } | ||
| if (f.includes("vscode")) { | ||
| if (a.includes("vscode")) { | ||
| const u = ".vscode/launch.json", n = P.join( | ||
@@ -268,5 +269,5 @@ h, | ||
| ); | ||
| if (!a.existsSync(n)) { | ||
| if (a.existsSync(P.dirname(n))) | ||
| a.writeFileSync( | ||
| if (!f.existsSync(n)) { | ||
| if (f.existsSync(P.dirname(n))) | ||
| f.writeFileSync( | ||
| n, | ||
@@ -277,3 +278,3 @@ `{ | ||
| ); | ||
| else if (f.length == 1) | ||
| else if (a.length == 1) | ||
| throw new Error( | ||
@@ -283,9 +284,9 @@ "VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory." | ||
| } | ||
| if (a.existsSync(n)) { | ||
| const o = a.readFileSync(n, "utf-8"), i = _(o, { | ||
| name: d, | ||
| if (f.existsSync(n)) { | ||
| const o = f.readFileSync(n, "utf-8"), s = B(o, { | ||
| name: c, | ||
| workspaceDir: h, | ||
| mappings: m | ||
| }); | ||
| i !== o && (a.writeFileSync(n, i), g.vscode = u); | ||
| s !== o && (f.writeFileSync(n, s), g.vscode = u); | ||
| } | ||
@@ -295,7 +296,7 @@ } | ||
| } | ||
| async function W(d, f) { | ||
| async function W(c, a) { | ||
| var h, l, t, m; | ||
| const s = P.join(f, ".idea/workspace.xml"); | ||
| if (a.existsSync(s)) { | ||
| const g = a.readFileSync(s, "utf8"), u = new T(x), n = (() => { | ||
| const r = P.join(a, ".idea/workspace.xml"); | ||
| if (f.existsSync(r)) { | ||
| const g = f.readFileSync(r, "utf8"), u = new T(x), n = (() => { | ||
| try { | ||
@@ -309,19 +310,19 @@ return u.parse(g, !0); | ||
| })(), o = n.find( | ||
| (r) => !!(r != null && r.project) | ||
| ), i = (h = o == null ? void 0 : o.project) == null ? void 0 : h.find( | ||
| (r) => { | ||
| (i) => !!(i != null && i.project) | ||
| ), s = (h = o == null ? void 0 : o.project) == null ? void 0 : h.find( | ||
| (i) => { | ||
| var w; | ||
| return !!(r != null && r.component) && ((w = r == null ? void 0 : r[":@"]) == null ? void 0 : w.name) === "PhpServers"; | ||
| return !!(i != null && i.component) && ((w = i == null ? void 0 : i[":@"]) == null ? void 0 : w.name) === "PhpServers"; | ||
| } | ||
| ), y = (l = i == null ? void 0 : i.component) == null ? void 0 : l.find( | ||
| (r) => !!(r != null && r.servers) | ||
| ), c = (t = y == null ? void 0 : y.servers) == null ? void 0 : t.findIndex( | ||
| (r) => { | ||
| ), y = (l = s == null ? void 0 : s.component) == null ? void 0 : l.find( | ||
| (i) => !!(i != null && i.servers) | ||
| ), d = (t = y == null ? void 0 : y.servers) == null ? void 0 : t.findIndex( | ||
| (i) => { | ||
| var w; | ||
| return !!(r != null && r.server) && ((w = r == null ? void 0 : r[":@"]) == null ? void 0 : w.name) === d; | ||
| return !!(i != null && i.server) && ((w = i == null ? void 0 : i[":@"]) == null ? void 0 : w.name) === c; | ||
| } | ||
| ); | ||
| if (c !== void 0 && c >= 0) { | ||
| y.servers.splice(c, 1); | ||
| const w = new A(D).build(n); | ||
| if (d !== void 0 && d >= 0) { | ||
| y.servers.splice(d, 1); | ||
| const w = new $(M).build(n); | ||
| try { | ||
@@ -339,8 +340,8 @@ u.parse(w, !0); | ||
| </component> | ||
| </project>` ? a.unlinkSync(s) : a.writeFileSync(s, w); | ||
| </project>` ? f.unlinkSync(r) : f.writeFileSync(r, w); | ||
| } | ||
| } | ||
| const p = P.join(f, ".vscode/launch.json"); | ||
| if (a.existsSync(p)) { | ||
| const g = [], u = a.readFileSync(p, "utf-8"), n = v.parseTree(u, g, j); | ||
| const p = P.join(a, ".vscode/launch.json"); | ||
| if (f.existsSync(p)) { | ||
| const g = [], u = f.readFileSync(p, "utf-8"), n = v.parseTree(u, g, j); | ||
| if (n === void 0 || g.length) | ||
@@ -350,12 +351,12 @@ throw new Error("VS Code configuration file is not valid JSON."); | ||
| "configurations" | ||
| ]), i = (m = o == null ? void 0 : o.children) == null ? void 0 : m.findIndex( | ||
| ]), s = (m = o == null ? void 0 : o.children) == null ? void 0 : m.findIndex( | ||
| (y) => { | ||
| var c; | ||
| return ((c = v.findNodeAtLocation(y, ["name"])) == null ? void 0 : c.value) === d; | ||
| var d; | ||
| return ((d = v.findNodeAtLocation(y, ["name"])) == null ? void 0 : d.value) === c; | ||
| } | ||
| ); | ||
| if (i !== void 0 && i >= 0) { | ||
| if (s !== void 0 && s >= 0) { | ||
| const y = v.modify( | ||
| u, | ||
| ["configurations", i], | ||
| ["configurations", s], | ||
| void 0, | ||
@@ -370,13 +371,20 @@ { | ||
| } | ||
| ), c = N(u, y); | ||
| c === `{ | ||
| ), d = N(u, y); | ||
| d === `{ | ||
| "configurations": [] | ||
| }` ? a.unlinkSync(p) : a.writeFileSync(p, c); | ||
| }` ? f.unlinkSync(p) : f.writeFileSync(p, d); | ||
| } | ||
| } | ||
| } | ||
| function N(d, f) { | ||
| const s = [], p = v.applyEdits(d, f); | ||
| if (s.length = 0, v.parseTree(p, s, j), s.length) { | ||
| const h = s.map((t) => ({ | ||
| function z({ | ||
| cwd: c, | ||
| mounts: a, | ||
| pathSkippings: r | ||
| }) { | ||
| return { pathMappings: c && a ? A(c, a) : void 0, pathSkippings: r }; | ||
| } | ||
| function N(c, a) { | ||
| const r = [], p = v.applyEdits(c, a); | ||
| if (r.length = 0, v.parseTree(p, r, j), r.length) { | ||
| const h = r.map((t) => ({ | ||
| message: v.printParseErrorCode(t.error), | ||
@@ -391,3 +399,3 @@ offset: t.offset, | ||
| (t) => `${t.message} at ${t.offset}:${t.length} (${t.fragment})` | ||
| ), l = f.map( | ||
| ), l = a.map( | ||
| (t) => `At ${t.offset}:${t.length} - (${t.content})` | ||
@@ -410,9 +418,11 @@ ); | ||
| export { | ||
| H as addXdebugIDEConfig, | ||
| O as DEFAULT_IDE_KEY, | ||
| U as addXdebugIDEConfig, | ||
| W as clearXdebugIDEConfig, | ||
| J as createTempDirSymlink, | ||
| q as removeTempDirSymlink, | ||
| O as updatePhpStormConfig, | ||
| _ as updateVSCodeConfig | ||
| q as createTempDirSymlink, | ||
| z as makeXdebugConfig, | ||
| H as removeTempDirSymlink, | ||
| _ as updatePhpStormConfig, | ||
| B as updateVSCodeConfig | ||
| }; | ||
| //# sourceMappingURL=index.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../../../../packages/php-wasm/cli-util/src/lib/xdebug-path-mappings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { toPosixPath } from '@php-wasm/util';\nimport type { Mount } from './mounts';\nimport {\n\ttype X2jOptions,\n\ttype XmlBuilderOptions,\n\tXMLParser,\n\tXMLBuilder,\n} from 'fast-xml-parser';\nimport * as JSONC from 'jsonc-parser';\n\n/**\n * Create a symlink to a tempory directory.\n *\n * The symlink is created to access the system temp dir\n * inside the current debugging directory.\n *\n * @param nativeDirPath The system temp dir path.\n * @param symlinkPath The symlink name.\n */\nexport async function createTempDirSymlink(\n\tnativeDirPath: string,\n\tsymlinkPath: string,\n\tplatform: string\n) {\n\tconst type =\n\t\tplatform === 'win32'\n\t\t\t? // On Windows, creating a 'dir' symlink can require elevated permissions.\n\t\t\t\t// In this case, let's make junction points because they function like\n\t\t\t\t// symlinks and do not require elevated permissions.\n\t\t\t\t'junction'\n\t\t\t: 'dir';\n\tfs.symlinkSync(nativeDirPath, symlinkPath, type);\n}\n\n/**\n * Remove the given temporary directory symlink if it exists.\n *\n * @param symlinkPath The symlink path.\n */\nexport async function removeTempDirSymlink(symlinkPath: string) {\n\ttry {\n\t\tconst stats = fs.lstatSync(symlinkPath);\n\t\tif (stats.isSymbolicLink()) {\n\t\t\tfs.unlinkSync(symlinkPath);\n\t\t}\n\t} catch {\n\t\t// Symlink does not exist or cannot be accessed, nothing to remove\n\t}\n}\n\n/**\n * Filters out mounts that are not in the current working directory\n *\n * @param mounts The mounts list.\n */\nfunction filterLocalMounts(cwd: string, mounts: Mount[]) {\n\treturn mounts.filter((mount) => {\n\t\tconst absoluteHostPath = path.resolve(mount.hostPath);\n\t\tconst cwdChildPrefix = path.join(cwd, path.sep);\n\t\treturn (\n\t\t\t// If auto-mounting from the current directory,\n\t\t\t// the entire project directory can be mapped.\n\t\t\tabsoluteHostPath === cwd ||\n\t\t\tabsoluteHostPath.startsWith(cwdChildPrefix)\n\t\t);\n\t});\n}\n\nexport type IDEConfig = {\n\t/**\n\t * The name of the configuration within the IDE configuration.\n\t */\n\tname: string;\n\t/**\n\t * The IDEs to configure.\n\t */\n\tides: string[];\n\t/**\n\t * The web server host.\n\t */\n\thost: string;\n\t/**\n\t * The web server port.\n\t */\n\tport: number;\n\t/**\n\t * The current working directory to consider for debugger path mapping.\n\t */\n\tcwd: string;\n\t/**\n\t * The mounts to consider for debugger path mapping.\n\t */\n\tmounts?: Mount[];\n\t/**\n\t * The IDE key to use for the debug configuration. Defaults to 'PLAYGROUNDCLI'.\n\t */\n\tideKey?: string;\n};\n\ntype PhpStormConfigMetaData = {\n\tname?: string;\n\tversion?: string;\n\thost?: string;\n\tuse_path_mappings?: string;\n\t'local-root'?: string;\n\t'remote-root'?: string;\n\t/**\n\t * The type of the server.\n\t */\n\ttype?: 'PhpRemoteDebugRunConfigurationType';\n\tfactoryName?: string;\n\tfilter_connections?: 'FILTER';\n\tserver_name?: string;\n\tsession_id?: string;\n\tv?: string;\n};\n\ntype PhpStormConfigNode = {\n\t':@'?: PhpStormConfigMetaData;\n\tproject?: PhpStormConfigNode[];\n\tcomponent?: PhpStormConfigNode[];\n\tservers?: PhpStormConfigNode[];\n\tserver?: PhpStormConfigNode[];\n\tpath_mappings?: PhpStormConfigNode[];\n\tmapping?: PhpStormConfigNode[];\n\tconfiguration?: PhpStormConfigNode[];\n\tmethod?: PhpStormConfigNode[];\n};\n\ntype VSCodeConfigMetaData = {\n\t[key: string]: string;\n};\n\ntype VSCodeConfigNode = {\n\tname: string;\n\ttype: string;\n\trequest: string;\n\tport: number;\n\tpathMappings?: VSCodeConfigMetaData;\n};\n\nconst xmlParserOptions: X2jOptions = {\n\tignoreAttributes: false,\n\tattributeNamePrefix: '',\n\tpreserveOrder: true,\n\tcdataPropName: '__cdata',\n\tcommentPropName: '__xmlComment',\n\tallowBooleanAttributes: true,\n\ttrimValues: true,\n};\nconst xmlBuilderOptions: XmlBuilderOptions = {\n\tignoreAttributes: xmlParserOptions.ignoreAttributes,\n\tattributeNamePrefix: xmlParserOptions.attributeNamePrefix,\n\tpreserveOrder: xmlParserOptions.preserveOrder,\n\tcdataPropName: xmlParserOptions.cdataPropName,\n\tcommentPropName: xmlParserOptions.commentPropName,\n\tsuppressBooleanAttributes: !xmlParserOptions.allowBooleanAttributes,\n\tformat: true,\n\tindentBy: '\\t',\n};\n\nconst jsoncParseOptions: JSONC.ParseOptions = {\n\tallowEmptyContent: true,\n\tallowTrailingComma: true,\n};\n\nexport type PhpStormConfigOptions = {\n\tname: string;\n\thost: string;\n\tport: number;\n\tprojectDir: string;\n\tmappings?: Mount[];\n\tideKey: string;\n};\n\n/**\n * Pure function to update PHPStorm XML config with XDebug server and run configuration.\n *\n * @param xmlContent The original XML content of workspace.xml\n * @param options Configuration options for the server\n * @returns Updated XML content\n * @throws Error if XML is invalid or configuration is incompatible\n */\nexport function updatePhpStormConfig(\n\txmlContent: string,\n\toptions: PhpStormConfigOptions\n): string {\n\tconst { name, host, port, mappings, ideKey } = options;\n\n\tconst xmlParser = new XMLParser(xmlParserOptions);\n\n\t// Parse the XML\n\tconst config: PhpStormConfigNode[] = (() => {\n\t\ttry {\n\t\t\treturn xmlParser.parse(xmlContent, true);\n\t\t} catch {\n\t\t\tthrow new Error('PhpStorm configuration file is not valid XML.');\n\t\t}\n\t})();\n\n\t// Create the server element with path mappings\n\tconst serverElement: PhpStormConfigNode = {\n\t\tserver: [{}],\n\t\t':@': {\n\t\t\tname,\n\t\t\t// NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port)\n\t\t\t// is provided in `host`. The separate `port` field is ignored or misinterpreted,\n\t\t\t// so we rely solely on host: \"host:port\".\n\t\t\thost: `${host}:${port}`,\n\t\t\tuse_path_mappings: 'true',\n\t\t},\n\t};\n\n\tif (mappings && mappings.length) {\n\t\tserverElement.server![0].path_mappings = mappings.map((mapping) => ({\n\t\t\tmapping: [],\n\t\t\t':@': {\n\t\t\t\t'local-root': `$PROJECT_DIR$/${toPosixPath(\n\t\t\t\t\tpath.relative(options.projectDir, mapping.hostPath)\n\t\t\t\t)}`,\n\t\t\t\t'remote-root': mapping.vfsPath,\n\t\t\t},\n\t\t}));\n\t}\n\n\t// Find or create project element\n\tlet projectElement = config?.find((c: PhpStormConfigNode) => !!c?.project);\n\tif (projectElement) {\n\t\tconst projectVersion = projectElement[':@']?.version;\n\t\tif (projectVersion === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t'but the <project> configuration has no version number.'\n\t\t\t);\n\t\t} else if (projectVersion !== '4') {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t`but we found a <project> configuration with version \"${projectVersion}\".`\n\t\t\t);\n\t\t}\n\t}\n\tif (projectElement === undefined) {\n\t\tprojectElement = {\n\t\t\tproject: [],\n\t\t\t':@': { version: '4' },\n\t\t};\n\t\tconfig.push(projectElement);\n\t}\n\n\t// Find or create PhpServers component\n\tlet componentElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t);\n\tif (componentElement === undefined) {\n\t\tcomponentElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'PhpServers' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(componentElement);\n\t}\n\n\t// Find or create servers element\n\tlet serversElement = componentElement.component?.find(\n\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t);\n\tif (serversElement === undefined) {\n\t\tserversElement = { servers: [] };\n\n\t\tif (componentElement.component === undefined) {\n\t\t\tcomponentElement.component = [];\n\t\t}\n\n\t\tcomponentElement.component.push(serversElement);\n\t}\n\n\t// Check if server already exists\n\tconst serverElementIndex = serversElement.servers?.findIndex(\n\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t);\n\n\t// Only add server if it doesn't exist\n\tif (serverElementIndex === undefined || serverElementIndex < 0) {\n\t\tif (serversElement.servers === undefined) {\n\t\t\tserversElement.servers = [];\n\t\t}\n\n\t\tserversElement.servers.push(serverElement);\n\t}\n\n\t// Find or create RunManager component\n\tlet runManagerElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'RunManager'\n\t);\n\tif (runManagerElement === undefined) {\n\t\trunManagerElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'RunManager' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(runManagerElement);\n\t}\n\n\t// Check if run configuration already exists\n\tconst existingConfigIndex =\n\t\trunManagerElement.component?.findIndex(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.configuration && c?.[':@']?.name === name\n\t\t) ?? -1;\n\n\t// Only add run configuration if it doesn't exist\n\tif (existingConfigIndex < 0) {\n\t\tconst runConfigElement: PhpStormConfigNode = {\n\t\t\tconfiguration: [\n\t\t\t\t{\n\t\t\t\t\tmethod: [],\n\t\t\t\t\t':@': { v: '2' },\n\t\t\t\t},\n\t\t\t],\n\t\t\t':@': {\n\t\t\t\tname: name,\n\t\t\t\ttype: 'PhpRemoteDebugRunConfigurationType',\n\t\t\t\tfactoryName: 'PHP Remote Debug',\n\t\t\t\tfilter_connections: 'FILTER',\n\t\t\t\tserver_name: name,\n\t\t\t\tsession_id: ideKey,\n\t\t\t},\n\t\t};\n\n\t\tif (runManagerElement.component === undefined) {\n\t\t\trunManagerElement.component = [];\n\t\t}\n\n\t\trunManagerElement.component.push(runConfigElement);\n\t}\n\n\t// Build the updated XML\n\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\tconst xml = xmlBuilder.build(config);\n\n\t// Validate the generated XML\n\ttry {\n\t\txmlParser.parse(xml, true);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t);\n\t}\n\n\treturn xml;\n}\n\nexport type VSCodeConfigOptions = {\n\tname: string;\n\tworkspaceDir: string;\n\tmappings?: Mount[];\n};\n\n/**\n * Pure function to update VS Code launch.json config with XDebug configuration.\n *\n * @param jsonContent The original JSON content of launch.json\n * @param options Configuration options\n * @returns Updated JSON content\n * @throws Error if JSON is invalid\n */\nexport function updateVSCodeConfig(\n\tjsonContent: string,\n\toptions: VSCodeConfigOptions\n): string {\n\tconst { name, mappings } = options;\n\n\tconst errors: JSONC.ParseError[] = [];\n\n\tlet content = jsonContent;\n\tlet root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\tif (root === undefined || errors.length) {\n\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t}\n\n\t// Find or create configurations array\n\tlet configurationsNode = JSONC.findNodeAtLocation(root, ['configurations']);\n\n\tif (\n\t\tconfigurationsNode === undefined ||\n\t\tconfigurationsNode.children === undefined\n\t) {\n\t\tconst edits = JSONC.modify(content, ['configurations'], [], {});\n\t\tcontent = JSONC.applyEdits(content, edits);\n\n\t\troot = JSONC.parseTree(content, [], jsoncParseOptions);\n\t\tconfigurationsNode = JSONC.findNodeAtLocation(root!, [\n\t\t\t'configurations',\n\t\t]);\n\t}\n\n\t// Check if configuration already exists\n\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t(child: any) =>\n\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t);\n\n\t// Only add configuration if it doesn't exist\n\tif (configurationIndex === undefined || configurationIndex < 0) {\n\t\tconst configuration: VSCodeConfigNode = {\n\t\t\tname: name,\n\t\t\ttype: 'php',\n\t\t\trequest: 'launch',\n\t\t\tport: 9003,\n\t\t};\n\n\t\tif (mappings && mappings.length) {\n\t\t\tconfiguration.pathMappings = mappings.reduce((acc, mount) => {\n\t\t\t\tacc[mount.vfsPath] = `\\${workspaceFolder}/${toPosixPath(\n\t\t\t\t\tpath.relative(options.workspaceDir, mount.hostPath)\n\t\t\t\t)}`;\n\t\t\t\treturn acc;\n\t\t\t}, {} as VSCodeConfigMetaData);\n\t\t}\n\n\t\t// Get the current length to append at the end\n\t\tconst currentLength = configurationsNode?.children?.length || 0;\n\n\t\tconst edits = JSONC.modify(\n\t\t\tcontent,\n\t\t\t['configurations', currentLength],\n\t\t\tconfiguration,\n\t\t\t{\n\t\t\t\tformattingOptions: {\n\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\ttabSize: 4,\n\t\t\t\t\teol: '\\n',\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\n\t\tcontent = jsoncApplyEdits(content, edits);\n\t}\n\n\treturn content;\n}\n\n/**\n * Implement necessary parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param mounts The mounts options.\n */\nexport async function addXdebugIDEConfig({\n\tname,\n\tides,\n\thost,\n\tport,\n\tcwd,\n\tmounts,\n\tideKey = 'PHPWASMCLI',\n}: IDEConfig) {\n\tconst mappings = mounts ? filterLocalMounts(cwd, mounts) : [];\n\tconst modifiedConfig: Record<string, string> = {};\n\n\t// PHPstorm\n\tif (ides.includes('phpstorm')) {\n\t\tconst phpStormRelativeConfigFilePath = '.idea/workspace.xml';\n\t\tconst phpStormConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tphpStormRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(phpStormConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tphpStormConfigFilePath,\n\t\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n</project>'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\t\tconst updatedXml = updatePhpStormConfig(contents, {\n\t\t\t\tname,\n\t\t\t\thost,\n\t\t\t\tport,\n\t\t\t\tprojectDir: cwd,\n\t\t\t\tmappings,\n\t\t\t\tideKey,\n\t\t\t});\n\t\t\tfs.writeFileSync(phpStormConfigFilePath, updatedXml);\n\t\t\tmodifiedConfig['phpstorm'] = phpStormRelativeConfigFilePath;\n\t\t}\n\t}\n\n\t// VSCode\n\tif (ides.includes('vscode')) {\n\t\tconst vsCodeRelativeConfigFilePath = '.vscode/launch.json';\n\t\tconst vsCodeConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tvsCodeRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(vsCodeConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tvsCodeConfigFilePath,\n\t\t\t\t\t'{\\n \"configurations\": []\\n}'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\t\tconst updatedJson = updateVSCodeConfig(content, {\n\t\t\t\tname,\n\t\t\t\tworkspaceDir: cwd,\n\t\t\t\tmappings,\n\t\t\t});\n\n\t\t\t// Only write and track the file if changes were made\n\t\t\tif (updatedJson !== content) {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, updatedJson);\n\t\t\t\tmodifiedConfig['vscode'] = vsCodeRelativeConfigFilePath;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn modifiedConfig;\n}\n\n/**\n * Remove stale parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param cwd The current working directory.\n */\nexport async function clearXdebugIDEConfig(name: string, cwd: string) {\n\tconst phpStormConfigFilePath = path.join(cwd, '.idea/workspace.xml');\n\t// PhpStorm\n\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\tconst xmlParser = new XMLParser(xmlParserOptions);\n\t\t// NOTE: Using an IIFE so `config` can remain const.\n\t\tconst config: PhpStormConfigNode[] = (() => {\n\t\t\ttry {\n\t\t\t\treturn xmlParser.parse(contents, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\t\t})();\n\n\t\tconst projectElement = config.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.project\n\t\t);\n\t\tconst componentElement = projectElement?.project?.find(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t\t);\n\t\tconst serversElement = componentElement?.component?.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t\t);\n\t\tconst serverElementIndex = serversElement?.servers?.findIndex(\n\t\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t\t);\n\n\t\tif (serverElementIndex !== undefined && serverElementIndex >= 0) {\n\t\t\tserversElement!.servers!.splice(serverElementIndex, 1);\n\n\t\t\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\t\t\tconst xml = xmlBuilder.build(config);\n\n\t\t\ttry {\n\t\t\t\txmlParser.parse(xml, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\txml ===\n\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n\t<component name=\"PhpServers\">\\n\t\t<servers></servers>\\n\t</component>\\n</project>'\n\t\t\t) {\n\t\t\t\tfs.unlinkSync(phpStormConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(phpStormConfigFilePath, xml);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst vsCodeConfigFilePath = path.join(cwd, '.vscode/launch.json');\n\t// VSCode\n\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\tconst errors: JSONC.ParseError[] = [];\n\n\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\tconst root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\t\tif (root === undefined || errors.length) {\n\t\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t\t}\n\n\t\tconst configurationsNode = JSONC.findNodeAtLocation(root, [\n\t\t\t'configurations',\n\t\t]);\n\n\t\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t\t(child: any) =>\n\t\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t\t);\n\n\t\tif (configurationIndex !== undefined && configurationIndex >= 0) {\n\t\t\tconst edits = JSONC.modify(\n\t\t\t\tcontent,\n\t\t\t\t['configurations', configurationIndex],\n\t\t\t\tundefined,\n\t\t\t\t{\n\t\t\t\t\tformattingOptions: {\n\t\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\t\ttabSize: 4,\n\t\t\t\t\t\teol: '\\n',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tconst json = jsoncApplyEdits(content, edits);\n\t\t\tif (json === '{\\n \"configurations\": []\\n}') {\n\t\t\t\tfs.unlinkSync(vsCodeConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, json);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction jsoncApplyEdits(content: string, edits: JSONC.Edit[]) {\n\tconst errors: JSONC.ParseError[] = [];\n\tconst json = JSONC.applyEdits(content, edits);\n\n\terrors.length = 0;\n\n\tJSONC.parseTree(json, errors, jsoncParseOptions);\n\n\tif (errors.length) {\n\t\tconst formattedErrors = errors\n\t\t\t.map((error) => {\n\t\t\t\treturn {\n\t\t\t\t\tmessage: JSONC.printParseErrorCode(error.error),\n\t\t\t\t\toffset: error.offset,\n\t\t\t\t\tlength: error.length,\n\t\t\t\t\tfragment: json.slice(\n\t\t\t\t\t\tMath.max(0, error.offset - 20),\n\t\t\t\t\t\tMath.min(json.length, error.offset + error.length + 10)\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.map(\n\t\t\t\t(error) =>\n\t\t\t\t\t`${error.message} at ${error.offset}:${error.length} (${error.fragment})`\n\t\t\t);\n\t\tconst formattedEdits = edits.map(\n\t\t\t(edit) => `At ${edit.offset}:${edit.length} - (${edit.content})`\n\t\t);\n\t\tthrow new Error(\n\t\t\t`VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely ` +\n\t\t\t\t`a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents ` +\n\t\t\t\t`of your \".vscode/launch.json\" file. \\n\\n Applied edits: ${formattedEdits.join(\n\t\t\t\t\t'\\n'\n\t\t\t\t)}\\n\\n The errors are: ${formattedErrors.join('\\n')}`\n\t\t);\n\t}\n\n\treturn json;\n}\n"],"names":["createTempDirSymlink","nativeDirPath","symlinkPath","platform","type","fs","removeTempDirSymlink","filterLocalMounts","cwd","mounts","mount","absoluteHostPath","path","cwdChildPrefix","xmlParserOptions","xmlBuilderOptions","jsoncParseOptions","updatePhpStormConfig","xmlContent","options","name","host","port","mappings","ideKey","xmlParser","XMLParser","config","serverElement","mapping","toPosixPath","projectElement","c","projectVersion","_a","componentElement","_b","serversElement","_c","serverElementIndex","_d","runManagerElement","_e","_f","runConfigElement","xml","XMLBuilder","updateVSCodeConfig","jsonContent","errors","content","root","JSONC","configurationsNode","edits","configurationIndex","child","configuration","acc","currentLength","jsoncApplyEdits","addXdebugIDEConfig","ides","modifiedConfig","phpStormRelativeConfigFilePath","phpStormConfigFilePath","contents","updatedXml","vsCodeRelativeConfigFilePath","vsCodeConfigFilePath","updatedJson","clearXdebugIDEConfig","json","formattedErrors","error","formattedEdits","edit"],"mappings":";;;;;AAqBA,eAAsBA,EACrBC,GACAC,GACAC,GACC;AACD,QAAMC,IACLD,MAAa;AAAA;AAAA;AAAA;AAAA,IAIX;AAAA,MACC;AACJ,EAAAE,EAAG,YAAYJ,GAAeC,GAAaE,CAAI;AAChD;AAOA,eAAsBE,EAAqBJ,GAAqB;AAC/D,MAAI;AAEH,IADcG,EAAG,UAAUH,CAAW,EAC5B,oBACTG,EAAG,WAAWH,CAAW;AAAA,EAE3B,QAAQ;AAAA,EAER;AACD;AAOA,SAASK,EAAkBC,GAAaC,GAAiB;AACxD,SAAOA,EAAO,OAAO,CAACC,MAAU;AAC/B,UAAMC,IAAmBC,EAAK,QAAQF,EAAM,QAAQ,GAC9CG,IAAiBD,EAAK,KAAKJ,GAAKI,EAAK,GAAG;AAC9C;AAAA;AAAA;AAAA,MAGCD,MAAqBH,KACrBG,EAAiB,WAAWE,CAAc;AAAA;AAAA,EAE5C,CAAC;AACF;AA2EA,MAAMC,IAA+B;AAAA,EACpC,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,eAAe;AAAA,EACf,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,YAAY;AACb,GACMC,IAAuC;AAAA,EAC5C,kBAAkBD,EAAiB;AAAA,EACnC,qBAAqBA,EAAiB;AAAA,EACtC,eAAeA,EAAiB;AAAA,EAChC,eAAeA,EAAiB;AAAA,EAChC,iBAAiBA,EAAiB;AAAA,EAClC,2BAA2B,CAACA,EAAiB;AAAA,EAC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A,MAAA,CACA;AAAA;AAAA,mBAAwBF,EAAgB,KAAK;AAAA,CAAI,CAAC;AAAA,IAAA;AAAA,EAEtD;AAEA,SAAOD;AACR;"} | ||
| {"version":3,"file":"index.js","sources":["../../../../packages/php-wasm/cli-util/src/lib/xdebug-path-mappings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { toPosixPath } from '@php-wasm/util';\nimport type { Mount } from './mounts';\nimport {\n\ttype X2jOptions,\n\ttype XmlBuilderOptions,\n\tXMLParser,\n\tXMLBuilder,\n} from 'fast-xml-parser';\nimport * as JSONC from 'jsonc-parser';\n\nexport interface XdebugOptions {\n\tideKey?: string;\n\tpathMappings?: Mount[];\n\tpathSkippings?: string[];\n}\n\nexport const DEFAULT_IDE_KEY = 'PHPWASMCLI';\n\n/**\n * Create a symlink to a tempory directory.\n *\n * The symlink is created to access the system temp dir\n * inside the current debugging directory.\n *\n * @param nativeDirPath The system temp dir path.\n * @param symlinkPath The symlink name.\n */\nexport async function createTempDirSymlink(\n\tnativeDirPath: string,\n\tsymlinkPath: string,\n\tplatform: string\n) {\n\tconst type =\n\t\tplatform === 'win32'\n\t\t\t? // On Windows, creating a 'dir' symlink can require elevated permissions.\n\t\t\t\t// In this case, let's make junction points because they function like\n\t\t\t\t// symlinks and do not require elevated permissions.\n\t\t\t\t'junction'\n\t\t\t: 'dir';\n\tfs.symlinkSync(nativeDirPath, symlinkPath, type);\n}\n\n/**\n * Remove the given temporary directory symlink if it exists.\n *\n * @param symlinkPath The symlink path.\n */\nexport async function removeTempDirSymlink(symlinkPath: string) {\n\ttry {\n\t\tconst stats = fs.lstatSync(symlinkPath);\n\t\tif (stats.isSymbolicLink()) {\n\t\t\tfs.unlinkSync(symlinkPath);\n\t\t}\n\t} catch {\n\t\t// Symlink does not exist or cannot be accessed, nothing to remove\n\t}\n}\n\n/**\n * Filters out mounts that are not in the current working directory\n *\n * @param mounts The mounts list.\n */\nfunction filterLocalMounts(cwd: string, mounts: Mount[]) {\n\treturn mounts.filter((mount) => {\n\t\tconst absoluteHostPath = path.resolve(mount.hostPath);\n\t\tconst cwdChildPrefix = path.join(cwd, path.sep);\n\t\treturn (\n\t\t\t// If auto-mounting from the current directory,\n\t\t\t// the entire project directory can be mapped.\n\t\t\tabsoluteHostPath === cwd ||\n\t\t\tabsoluteHostPath.startsWith(cwdChildPrefix)\n\t\t);\n\t});\n}\n\nexport type XdebugConfig = {\n\t/**\n\t * The current working directory to consider for debugger path mapping.\n\t */\n\tcwd?: string;\n\t/**\n\t * The mounts to consider for debugger path mapping.\n\t */\n\tmounts?: Mount[];\n\t/**\n\t * The paths to consider for debugger path skipping.\n\t */\n\tpathSkippings?: string[];\n};\n\nexport type IDEConfig = {\n\t/**\n\t * The name of the configuration within the IDE configuration.\n\t */\n\tname: string;\n\t/**\n\t * The IDEs to configure.\n\t */\n\tides: string[];\n\t/**\n\t * The web server host.\n\t */\n\thost: string;\n\t/**\n\t * The web server port.\n\t */\n\tport: number;\n\t/**\n\t * The current working directory to consider for debugger path mapping.\n\t */\n\tcwd: string;\n\t/**\n\t * The mounts to consider for debugger path mapping.\n\t */\n\tmounts?: Mount[];\n\t/**\n\t * The IDE key to use for the debug configuration. Defaults to 'PHPWASMCLI'.\n\t */\n\tideKey?: string;\n};\n\ntype PhpStormConfigMetaData = {\n\tname?: string;\n\tversion?: string;\n\thost?: string;\n\tuse_path_mappings?: string;\n\t'local-root'?: string;\n\t'remote-root'?: string;\n\t/**\n\t * The type of the server.\n\t */\n\ttype?: 'PhpRemoteDebugRunConfigurationType';\n\tfactoryName?: string;\n\tfilter_connections?: 'FILTER';\n\tserver_name?: string;\n\tsession_id?: string;\n\tv?: string;\n};\n\ntype PhpStormConfigNode = {\n\t':@'?: PhpStormConfigMetaData;\n\tproject?: PhpStormConfigNode[];\n\tcomponent?: PhpStormConfigNode[];\n\tservers?: PhpStormConfigNode[];\n\tserver?: PhpStormConfigNode[];\n\tpath_mappings?: PhpStormConfigNode[];\n\tmapping?: PhpStormConfigNode[];\n\tconfiguration?: PhpStormConfigNode[];\n\tmethod?: PhpStormConfigNode[];\n};\n\ntype VSCodeConfigMetaData = {\n\t[key: string]: string;\n};\n\ntype VSCodeConfigNode = {\n\tname: string;\n\ttype: string;\n\trequest: string;\n\tport: number;\n\tpathMappings?: VSCodeConfigMetaData;\n};\n\nconst xmlParserOptions: X2jOptions = {\n\tignoreAttributes: false,\n\tattributeNamePrefix: '',\n\tpreserveOrder: true,\n\tcdataPropName: '__cdata',\n\tcommentPropName: '__xmlComment',\n\tallowBooleanAttributes: true,\n\ttrimValues: true,\n};\nconst xmlBuilderOptions: XmlBuilderOptions = {\n\tignoreAttributes: xmlParserOptions.ignoreAttributes,\n\tattributeNamePrefix: xmlParserOptions.attributeNamePrefix,\n\tpreserveOrder: xmlParserOptions.preserveOrder,\n\tcdataPropName: xmlParserOptions.cdataPropName,\n\tcommentPropName: xmlParserOptions.commentPropName,\n\tsuppressBooleanAttributes: !xmlParserOptions.allowBooleanAttributes,\n\tformat: true,\n\tindentBy: '\\t',\n};\n\nconst jsoncParseOptions: JSONC.ParseOptions = {\n\tallowEmptyContent: true,\n\tallowTrailingComma: true,\n};\n\nexport type PhpStormConfigOptions = {\n\tname: string;\n\thost: string;\n\tport: number;\n\tprojectDir: string;\n\tmappings?: Mount[];\n\tideKey: string;\n};\n\n/**\n * Pure function to update PHPStorm XML config with Xdebug server and run configuration.\n *\n * @param xmlContent The original XML content of workspace.xml\n * @param options Configuration options for the server\n * @returns Updated XML content\n * @throws Error if XML is invalid or configuration is incompatible\n */\nexport function updatePhpStormConfig(\n\txmlContent: string,\n\toptions: PhpStormConfigOptions\n): string {\n\tconst { name, host, port, mappings, ideKey } = options;\n\n\tconst xmlParser = new XMLParser(xmlParserOptions);\n\n\t// Parse the XML\n\tconst config: PhpStormConfigNode[] = (() => {\n\t\ttry {\n\t\t\treturn xmlParser.parse(xmlContent, true);\n\t\t} catch {\n\t\t\tthrow new Error('PhpStorm configuration file is not valid XML.');\n\t\t}\n\t})();\n\n\t// Create the server element with path mappings\n\tconst serverElement: PhpStormConfigNode = {\n\t\tserver: [{}],\n\t\t':@': {\n\t\t\tname,\n\t\t\t// NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port)\n\t\t\t// is provided in `host`. The separate `port` field is ignored or misinterpreted,\n\t\t\t// so we rely solely on host: \"host:port\".\n\t\t\thost: `${host}:${port}`,\n\t\t\tuse_path_mappings: 'true',\n\t\t},\n\t};\n\n\tif (mappings && mappings.length) {\n\t\tserverElement.server![0].path_mappings = mappings.map((mapping) => ({\n\t\t\tmapping: [],\n\t\t\t':@': {\n\t\t\t\t'local-root': `$PROJECT_DIR$/${toPosixPath(\n\t\t\t\t\tpath.relative(options.projectDir, mapping.hostPath)\n\t\t\t\t)}`,\n\t\t\t\t'remote-root': mapping.vfsPath,\n\t\t\t},\n\t\t}));\n\t}\n\n\t// Find or create project element\n\tlet projectElement = config?.find((c: PhpStormConfigNode) => !!c?.project);\n\tif (projectElement) {\n\t\tconst projectVersion = projectElement[':@']?.version;\n\t\tif (projectVersion === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t'but the <project> configuration has no version number.'\n\t\t\t);\n\t\t} else if (projectVersion !== '4') {\n\t\t\tthrow new Error(\n\t\t\t\t'PhpStorm IDE integration only supports <project version=\"4\"> in workspace.xml, ' +\n\t\t\t\t\t`but we found a <project> configuration with version \"${projectVersion}\".`\n\t\t\t);\n\t\t}\n\t}\n\tif (projectElement === undefined) {\n\t\tprojectElement = {\n\t\t\tproject: [],\n\t\t\t':@': { version: '4' },\n\t\t};\n\t\tconfig.push(projectElement);\n\t}\n\n\t// Find or create PhpServers component\n\tlet componentElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t);\n\tif (componentElement === undefined) {\n\t\tcomponentElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'PhpServers' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(componentElement);\n\t}\n\n\t// Find or create servers element\n\tlet serversElement = componentElement.component?.find(\n\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t);\n\tif (serversElement === undefined) {\n\t\tserversElement = { servers: [] };\n\n\t\tif (componentElement.component === undefined) {\n\t\t\tcomponentElement.component = [];\n\t\t}\n\n\t\tcomponentElement.component.push(serversElement);\n\t}\n\n\t// Check if server already exists\n\tconst serverElementIndex = serversElement.servers?.findIndex(\n\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t);\n\n\t// Only add server if it doesn't exist\n\tif (serverElementIndex === undefined || serverElementIndex < 0) {\n\t\tif (serversElement.servers === undefined) {\n\t\t\tserversElement.servers = [];\n\t\t}\n\n\t\tserversElement.servers.push(serverElement);\n\t}\n\n\t// Find or create RunManager component\n\tlet runManagerElement = projectElement.project?.find(\n\t\t(c: PhpStormConfigNode) =>\n\t\t\t!!c?.component && c?.[':@']?.name === 'RunManager'\n\t);\n\tif (runManagerElement === undefined) {\n\t\trunManagerElement = {\n\t\t\tcomponent: [],\n\t\t\t':@': { name: 'RunManager' },\n\t\t};\n\n\t\tif (projectElement.project === undefined) {\n\t\t\tprojectElement.project = [];\n\t\t}\n\n\t\tprojectElement.project.push(runManagerElement);\n\t}\n\n\t// Check if run configuration already exists\n\tconst existingConfigIndex =\n\t\trunManagerElement.component?.findIndex(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.configuration && c?.[':@']?.name === name\n\t\t) ?? -1;\n\n\t// Only add run configuration if it doesn't exist\n\tif (existingConfigIndex < 0) {\n\t\tconst runConfigElement: PhpStormConfigNode = {\n\t\t\tconfiguration: [\n\t\t\t\t{\n\t\t\t\t\tmethod: [],\n\t\t\t\t\t':@': { v: '2' },\n\t\t\t\t},\n\t\t\t],\n\t\t\t':@': {\n\t\t\t\tname: name,\n\t\t\t\ttype: 'PhpRemoteDebugRunConfigurationType',\n\t\t\t\tfactoryName: 'PHP Remote Debug',\n\t\t\t\tfilter_connections: 'FILTER',\n\t\t\t\tserver_name: name,\n\t\t\t\tsession_id: ideKey,\n\t\t\t},\n\t\t};\n\n\t\tif (runManagerElement.component === undefined) {\n\t\t\trunManagerElement.component = [];\n\t\t}\n\n\t\trunManagerElement.component.push(runConfigElement);\n\t}\n\n\t// Build the updated XML\n\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\tconst xml = xmlBuilder.build(config);\n\n\t// Validate the generated XML\n\ttry {\n\t\txmlParser.parse(xml, true);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t);\n\t}\n\n\treturn xml;\n}\n\nexport type VSCodeConfigOptions = {\n\tname: string;\n\tworkspaceDir: string;\n\tmappings?: Mount[];\n};\n\n/**\n * Pure function to update VS Code JSON config with Xdebug configuration.\n *\n * @param jsonContent The original JSON content of launch.json\n * @param options Configuration options\n * @returns Updated JSON content\n * @throws Error if JSON is invalid\n */\nexport function updateVSCodeConfig(\n\tjsonContent: string,\n\toptions: VSCodeConfigOptions\n): string {\n\tconst { name, mappings } = options;\n\n\tconst errors: JSONC.ParseError[] = [];\n\n\tlet content = jsonContent;\n\tlet root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\tif (root === undefined || errors.length) {\n\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t}\n\n\t// Find or create configurations array\n\tlet configurationsNode = JSONC.findNodeAtLocation(root, ['configurations']);\n\n\tif (\n\t\tconfigurationsNode === undefined ||\n\t\tconfigurationsNode.children === undefined\n\t) {\n\t\tconst edits = JSONC.modify(content, ['configurations'], [], {});\n\t\tcontent = JSONC.applyEdits(content, edits);\n\n\t\troot = JSONC.parseTree(content, [], jsoncParseOptions);\n\t\tconfigurationsNode = JSONC.findNodeAtLocation(root!, [\n\t\t\t'configurations',\n\t\t]);\n\t}\n\n\t// Check if configuration already exists\n\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t(child: any) =>\n\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t);\n\n\t// Only add configuration if it doesn't exist\n\tif (configurationIndex === undefined || configurationIndex < 0) {\n\t\tconst configuration: VSCodeConfigNode = {\n\t\t\tname: name,\n\t\t\ttype: 'php',\n\t\t\trequest: 'launch',\n\t\t\tport: 9003,\n\t\t};\n\n\t\tif (mappings && mappings.length) {\n\t\t\tconfiguration.pathMappings = mappings.reduce((acc, mount) => {\n\t\t\t\tacc[mount.vfsPath] = `\\${workspaceFolder}/${toPosixPath(\n\t\t\t\t\tpath.relative(options.workspaceDir, mount.hostPath)\n\t\t\t\t)}`;\n\t\t\t\treturn acc;\n\t\t\t}, {} as VSCodeConfigMetaData);\n\t\t}\n\n\t\t// Get the current length to append at the end\n\t\tconst currentLength = configurationsNode?.children?.length || 0;\n\n\t\tconst edits = JSONC.modify(\n\t\t\tcontent,\n\t\t\t['configurations', currentLength],\n\t\t\tconfiguration,\n\t\t\t{\n\t\t\t\tformattingOptions: {\n\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\ttabSize: 4,\n\t\t\t\t\teol: '\\n',\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\n\t\tcontent = jsoncApplyEdits(content, edits);\n\t}\n\n\treturn content;\n}\n\n/**\n * Implement necessary parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param mounts The mounts options.\n */\nexport async function addXdebugIDEConfig({\n\tname,\n\tides,\n\thost,\n\tport,\n\tcwd,\n\tmounts,\n\tideKey = DEFAULT_IDE_KEY,\n}: IDEConfig) {\n\tconst mappings = mounts ? filterLocalMounts(cwd, mounts) : [];\n\tconst modifiedConfig: Record<string, string> = {};\n\n\t// PHPstorm\n\tif (ides.includes('phpstorm')) {\n\t\tconst phpStormRelativeConfigFilePath = '.idea/workspace.xml';\n\t\tconst phpStormConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tphpStormRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(phpStormConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tphpStormConfigFilePath,\n\t\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n</project>'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\t\tconst updatedXml = updatePhpStormConfig(contents, {\n\t\t\t\tname,\n\t\t\t\thost,\n\t\t\t\tport,\n\t\t\t\tprojectDir: cwd,\n\t\t\t\tmappings,\n\t\t\t\tideKey,\n\t\t\t});\n\t\t\tfs.writeFileSync(phpStormConfigFilePath, updatedXml);\n\t\t\tmodifiedConfig['phpstorm'] = phpStormRelativeConfigFilePath;\n\t\t}\n\t}\n\n\t// VSCode\n\tif (ides.includes('vscode')) {\n\t\tconst vsCodeRelativeConfigFilePath = '.vscode/launch.json';\n\t\tconst vsCodeConfigFilePath = path.join(\n\t\t\tcwd,\n\t\t\tvsCodeRelativeConfigFilePath\n\t\t);\n\n\t\t// Create a template config file if the IDE directory exists,\n\t\t// or throw an error if IDE integration is requested but the directory is missing.\n\t\tif (!fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tif (fs.existsSync(path.dirname(vsCodeConfigFilePath))) {\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\tvsCodeConfigFilePath,\n\t\t\t\t\t'{\\n \"configurations\": []\\n}'\n\t\t\t\t);\n\t\t\t} else if (ides.length == 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\t\tconst updatedJson = updateVSCodeConfig(content, {\n\t\t\t\tname,\n\t\t\t\tworkspaceDir: cwd,\n\t\t\t\tmappings,\n\t\t\t});\n\n\t\t\t// Only write and track the file if changes were made\n\t\t\tif (updatedJson !== content) {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, updatedJson);\n\t\t\t\tmodifiedConfig['vscode'] = vsCodeRelativeConfigFilePath;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn modifiedConfig;\n}\n\n/**\n * Remove stale parameters and path mappings in IDE configuration files.\n *\n * @param name The configuration name.\n * @param cwd The current working directory.\n */\nexport async function clearXdebugIDEConfig(name: string, cwd: string) {\n\tconst phpStormConfigFilePath = path.join(cwd, '.idea/workspace.xml');\n\t// PhpStorm\n\tif (fs.existsSync(phpStormConfigFilePath)) {\n\t\tconst contents = fs.readFileSync(phpStormConfigFilePath, 'utf8');\n\t\tconst xmlParser = new XMLParser(xmlParserOptions);\n\t\t// NOTE: Using an IIFE so `config` can remain const.\n\t\tconst config: PhpStormConfigNode[] = (() => {\n\t\t\ttry {\n\t\t\t\treturn xmlParser.parse(contents, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\t\t})();\n\n\t\tconst projectElement = config.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.project\n\t\t);\n\t\tconst componentElement = projectElement?.project?.find(\n\t\t\t(c: PhpStormConfigNode) =>\n\t\t\t\t!!c?.component && c?.[':@']?.name === 'PhpServers'\n\t\t);\n\t\tconst serversElement = componentElement?.component?.find(\n\t\t\t(c: PhpStormConfigNode) => !!c?.servers\n\t\t);\n\t\tconst serverElementIndex = serversElement?.servers?.findIndex(\n\t\t\t(c: PhpStormConfigNode) => !!c?.server && c?.[':@']?.name === name\n\t\t);\n\n\t\tif (serverElementIndex !== undefined && serverElementIndex >= 0) {\n\t\t\tserversElement!.servers!.splice(serverElementIndex, 1);\n\n\t\t\tconst xmlBuilder = new XMLBuilder(xmlBuilderOptions);\n\t\t\tconst xml = xmlBuilder.build(config);\n\n\t\t\ttry {\n\t\t\t\txmlParser.parse(xml, true);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The resulting PhpStorm configuration file is not valid XML.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\txml ===\n\t\t\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<project version=\"4\">\\n\t<component name=\"PhpServers\">\\n\t\t<servers></servers>\\n\t</component>\\n</project>'\n\t\t\t) {\n\t\t\t\tfs.unlinkSync(phpStormConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(phpStormConfigFilePath, xml);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst vsCodeConfigFilePath = path.join(cwd, '.vscode/launch.json');\n\t// VSCode\n\tif (fs.existsSync(vsCodeConfigFilePath)) {\n\t\tconst errors: JSONC.ParseError[] = [];\n\n\t\tconst content = fs.readFileSync(vsCodeConfigFilePath, 'utf-8');\n\t\tconst root = JSONC.parseTree(content, errors, jsoncParseOptions);\n\n\t\tif (root === undefined || errors.length) {\n\t\t\tthrow new Error('VS Code configuration file is not valid JSON.');\n\t\t}\n\n\t\tconst configurationsNode = JSONC.findNodeAtLocation(root, [\n\t\t\t'configurations',\n\t\t]);\n\n\t\tconst configurationIndex = configurationsNode?.children?.findIndex(\n\t\t\t(child: any) =>\n\t\t\t\tJSONC.findNodeAtLocation(child, ['name'])?.value === name\n\t\t);\n\n\t\tif (configurationIndex !== undefined && configurationIndex >= 0) {\n\t\t\tconst edits = JSONC.modify(\n\t\t\t\tcontent,\n\t\t\t\t['configurations', configurationIndex],\n\t\t\t\tundefined,\n\t\t\t\t{\n\t\t\t\t\tformattingOptions: {\n\t\t\t\t\t\tinsertSpaces: true,\n\t\t\t\t\t\ttabSize: 4,\n\t\t\t\t\t\teol: '\\n',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tconst json = jsoncApplyEdits(content, edits);\n\t\t\tif (json === '{\\n \"configurations\": []\\n}') {\n\t\t\t\tfs.unlinkSync(vsCodeConfigFilePath);\n\t\t\t} else {\n\t\t\t\tfs.writeFileSync(vsCodeConfigFilePath, json);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Implement path mapping and path skipping in Xdebug.\n *\n * @param name The configuration name.\n * @param mounts The mounts options.\n * @param pathSkippings The skipping paths options.\n * @returns Xdebug options\n */\nexport function makeXdebugConfig({\n\tcwd,\n\tmounts,\n\tpathSkippings,\n}: XdebugConfig): XdebugOptions {\n\tconst pathMappings =\n\t\tcwd && mounts ? filterLocalMounts(cwd, mounts) : undefined;\n\n\treturn { pathMappings, pathSkippings };\n}\n\nfunction jsoncApplyEdits(content: string, edits: JSONC.Edit[]) {\n\tconst errors: JSONC.ParseError[] = [];\n\tconst json = JSONC.applyEdits(content, edits);\n\n\terrors.length = 0;\n\n\tJSONC.parseTree(json, errors, jsoncParseOptions);\n\n\tif (errors.length) {\n\t\tconst formattedErrors = errors\n\t\t\t.map((error) => {\n\t\t\t\treturn {\n\t\t\t\t\tmessage: JSONC.printParseErrorCode(error.error),\n\t\t\t\t\toffset: error.offset,\n\t\t\t\t\tlength: error.length,\n\t\t\t\t\tfragment: json.slice(\n\t\t\t\t\t\tMath.max(0, error.offset - 20),\n\t\t\t\t\t\tMath.min(json.length, error.offset + error.length + 10)\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.map(\n\t\t\t\t(error) =>\n\t\t\t\t\t`${error.message} at ${error.offset}:${error.length} (${error.fragment})`\n\t\t\t);\n\t\tconst formattedEdits = edits.map(\n\t\t\t(edit) => `At ${edit.offset}:${edit.length} - (${edit.content})`\n\t\t);\n\t\tthrow new Error(\n\t\t\t`VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely ` +\n\t\t\t\t`a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents ` +\n\t\t\t\t`of your \".vscode/launch.json\" file. \\n\\n Applied edits: ${formattedEdits.join(\n\t\t\t\t\t'\\n'\n\t\t\t\t)}\\n\\n The errors are: ${formattedErrors.join('\\n')}`\n\t\t);\n\t}\n\n\treturn json;\n}\n"],"names":["DEFAULT_IDE_KEY","createTempDirSymlink","nativeDirPath","symlinkPath","platform","type","fs","removeTempDirSymlink","filterLocalMounts","cwd","mounts","mount","absoluteHostPath","path","cwdChildPrefix","xmlParserOptions","xmlBuilderOptions","jsoncParseOptions","updatePhpStormConfig","xmlContent","options","name","host","port","mappings","ideKey","xmlParser","XMLParser","config","serverElement","mapping","toPosixPath","projectElement","c","projectVersion","_a","componentElement","_b","serversElement","_c","serverElementIndex","_d","runManagerElement","_e","_f","runConfigElement","xml","XMLBuilder","updateVSCodeConfig","jsonContent","errors","content","root","JSONC","configurationsNode","edits","configurationIndex","child","configuration","acc","currentLength","jsoncApplyEdits","addXdebugIDEConfig","ides","modifiedConfig","phpStormRelativeConfigFilePath","phpStormConfigFilePath","contents","updatedXml","vsCodeRelativeConfigFilePath","vsCodeConfigFilePath","updatedJson","clearXdebugIDEConfig","json","makeXdebugConfig","pathSkippings","formattedErrors","error","formattedEdits","edit"],"mappings":";;;;;AAkBO,MAAMA,IAAkB;AAW/B,eAAsBC,EACrBC,GACAC,GACAC,GACC;AACD,QAAMC,IACLD,MAAa;AAAA;AAAA;AAAA;AAAA,IAIX;AAAA,MACC;AACJ,EAAAE,EAAG,YAAYJ,GAAeC,GAAaE,CAAI;AAChD;AAOA,eAAsBE,EAAqBJ,G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gC;AAI/B,SAAO,EAAE,cAFRlE,KAAOC,IAASF,EAAkBC,GAAKC,CAAM,IAAI,QAE3B,eAAAiE,EAAA;AACxB;AAEA,SAASd,EAAgBV,GAAiBI,GAAqB;AAC9D,QAAML,IAA6B,CAAA,GAC7BuB,IAAOpB,EAAM,WAAWF,GAASI,CAAK;AAM5C,MAJAL,EAAO,SAAS,GAEhBG,EAAM,UAAUoB,GAAMvB,GAAQjC,CAAiB,GAE3CiC,EAAO,QAAQ;AAClB,UAAM0B,IAAkB1B,EACtB,IAAI,CAAC2B,OACE;AAAA,MACN,SAASxB,EAAM,oBAAoBwB,EAAM,KAAK;AAAA,MAC9C,QAAQA,EAAM;AAAA,MACd,QAAQA,EAAM;AAAA,MACd,UAAUJ,EAAK;AAAA,QACd,KAAK,IAAI,GAAGI,EAAM,SAAS,EAAE;AAAA,QAC7B,KAAK,IAAIJ,EAAK,QAAQI,EAAM,SAASA,EAAM,SAAS,EAAE;AAAA,MAAA;AAAA,IACvD,EAED,EACA;AAAA,MACA,CAACA,MACA,GAAGA,EAAM,OAAO,OAAOA,EAAM,MAAM,IAAIA,EAAM,MAAM,KAAKA,EAAM,QAAQ;AAAA,IAAA,GAEnEC,IAAiBvB,EAAM;AAAA,MAC5B,CAACwB,MAAS,MAAMA,EAAK,MAAM,IAAIA,EAAK,MAAM,OAAOA,EAAK,OAAO;AAAA,IAAA;AAE9D,UAAM,IAAI;AAAA,MACT;AAAA;AAAA,kBAE4DD,EAAe;AAAA,QACzE;AAAA;AAAA,MAAA,CACA;AAAA;AAAA,mBAAwBF,EAAgB,KAAK;AAAA,CAAI,CAAC;AAAA,IAAA;AAAA,EAEtD;AAEA,SAAOH;AACR;"} |
| import type { Mount } from './mounts'; | ||
| export interface XdebugOptions { | ||
| ideKey?: string; | ||
| pathMappings?: Mount[]; | ||
| pathSkippings?: string[]; | ||
| } | ||
| export declare const DEFAULT_IDE_KEY = "PHPWASMCLI"; | ||
| /** | ||
@@ -18,2 +24,16 @@ * Create a symlink to a tempory directory. | ||
| export declare function removeTempDirSymlink(symlinkPath: string): Promise<void>; | ||
| export type XdebugConfig = { | ||
| /** | ||
| * The current working directory to consider for debugger path mapping. | ||
| */ | ||
| cwd?: string; | ||
| /** | ||
| * The mounts to consider for debugger path mapping. | ||
| */ | ||
| mounts?: Mount[]; | ||
| /** | ||
| * The paths to consider for debugger path skipping. | ||
| */ | ||
| pathSkippings?: string[]; | ||
| }; | ||
| export type IDEConfig = { | ||
@@ -45,3 +65,3 @@ /** | ||
| /** | ||
| * The IDE key to use for the debug configuration. Defaults to 'PLAYGROUNDCLI'. | ||
| * The IDE key to use for the debug configuration. Defaults to 'PHPWASMCLI'. | ||
| */ | ||
@@ -59,3 +79,3 @@ ideKey?: string; | ||
| /** | ||
| * Pure function to update PHPStorm XML config with XDebug server and run configuration. | ||
| * Pure function to update PHPStorm XML config with Xdebug server and run configuration. | ||
| * | ||
@@ -74,3 +94,3 @@ * @param xmlContent The original XML content of workspace.xml | ||
| /** | ||
| * Pure function to update VS Code launch.json config with XDebug configuration. | ||
| * Pure function to update VS Code JSON config with Xdebug configuration. | ||
| * | ||
@@ -97,1 +117,10 @@ * @param jsonContent The original JSON content of launch.json | ||
| export declare function clearXdebugIDEConfig(name: string, cwd: string): Promise<void>; | ||
| /** | ||
| * Implement path mapping and path skipping in Xdebug. | ||
| * | ||
| * @param name The configuration name. | ||
| * @param mounts The mounts options. | ||
| * @param pathSkippings The skipping paths options. | ||
| * @returns Xdebug options | ||
| */ | ||
| export declare function makeXdebugConfig({ cwd, mounts, pathSkippings, }: XdebugConfig): XdebugOptions; |
+3
-3
| { | ||
| "name": "@php-wasm/cli-util", | ||
| "version": "3.1.2", | ||
| "version": "3.1.3", | ||
| "description": "Utilities for PHP.wasm related CLIs", | ||
@@ -34,3 +34,3 @@ "repository": { | ||
| "license": "GPL-2.0-or-later", | ||
| "gitHead": "4a2f8903e9d4a58e33382f8f888ef94d42d913dc", | ||
| "gitHead": "54bb87ba4c9624ec02f60194a2f1938b3f42477b", | ||
| "engines": { | ||
@@ -43,3 +43,3 @@ "node": ">=20.10.0", | ||
| "jsonc-parser": "3.3.1", | ||
| "@php-wasm/util": "3.1.2" | ||
| "@php-wasm/util": "3.1.3" | ||
| }, | ||
@@ -46,0 +46,0 @@ "packageManager": "npm@10.9.2", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
106844
3.37%574
7.29%+ Added
- Removed
Updated