| 16 | const rootPath = join(import.meta.dirname, '../'); |
| 17 | |
| 18 | async function main(outPath) { |
| 19 | // `vsce ls` needs to run with a CWD of what will be packaged. |
| 20 | // There is no way to provide this via args. |
| 21 | const {stdout, stderr} = await exec( |
| 22 | `node ${join(rootPath, `node_modules/@vscode/vsce/vsce`)} ls`, |
| 23 | { |
| 24 | cwd: join(rootPath, 'vsix_sandbox'), |
| 25 | }, |
| 26 | ); |
| 27 | |
| 28 | if (stderr) { |
| 29 | console.error(stderr); |
| 30 | throw new Error('Failed with error. See above.'); |
| 31 | } |
| 32 | |
| 33 | const paths = stdout.trim().split('\n').filter(Boolean); |
| 34 | const resultSet = new Set(); |
| 35 | |
| 36 | for (const filePath of paths) { |
| 37 | if (filePath.startsWith('node_modules/') && !filePath.includes('@angular')) { |
| 38 | // Regex to capture 'node_modules/' followed by either: |
| 39 | // - A scoped package (e.g., @vscode/vsce) |
| 40 | // - A standard package (e.g., typescript) |
| 41 | // It stops matching before the next slash after the package name. |
| 42 | const match = filePath.match(/^(node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+))/); |
| 43 | if (match) { |
| 44 | resultSet.add(match[1]); |
| 45 | } |
| 46 | } else { |
| 47 | // Add non-node_modules or @angular/ paths directly |
| 48 | resultSet.add(filePath); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | await writeFile(outPath, Array.from(resultSet).sort().join('\n')); |
| 53 | } |
| 54 | |
| 55 | const argv = process.argv.slice(2); |
| 56 | if (argv.length !== 1) { |