Skip to content

Commit

Permalink
feat(extensions): allow github extensions to be installed through dev…
Browse files Browse the repository at this point in the history
…elopment mode (#5002)

* Add workspace folder filter argument for diagnostics

* Update documentation and list options

* Make github extensions installation work through development mode
  • Loading branch information
asmodeus812 committed May 7, 2024
1 parent 48bae5f commit e1999ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/modules/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe('Installer', () => {
describe('getInfo()', () => {
it('should get install arguments', async () => {
let installer = new Installer(__dirname, 'npm', 'https://github.com/')
expect(installer.getInstallArguments('pnpm', 'https://github.com/')).toEqual(['install', '--production', '--config.strict-peer-dependencies=false'])
expect(installer.getInstallArguments('npm', '')).toEqual(['install', '--ignore-scripts', '--no-lockfile', '--omit=dev', '--legacy-peer-deps', '--no-global'])
expect(installer.getInstallArguments('yarn', '')).toEqual(['install', '--ignore-scripts', '--no-lockfile', '--production', '--ignore-engines'])
expect(installer.getInstallArguments('pnpm', 'https://github.com/')).toEqual({ env: 'development', args: ['install'] })
expect(installer.getInstallArguments('npm', '')).toEqual({ env: 'production', args: ['install', '--ignore-scripts', '--no-lockfile', '--omit=dev', '--legacy-peer-deps', '--no-global'] })
expect(installer.getInstallArguments('yarn', '')).toEqual({ env: 'production', args: ['install', '--ignore-scripts', '--no-lockfile', '--production', '--ignore-engines'] })
})

it('should getInfo from url', async () => {
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('Installer', () => {
fs.mkdirSync(tmpfolder)
let installer = new Installer(tmpfolder, npm, 'coc-omni')
let spy = jest.spyOn(installer, 'getInstallArguments').mockImplementation(() => {
return ['--error']
return { env: 'production', args: ['--error'] }
})
let fn = async () => {
await installer.installDependencies(tmpfolder, ['a', 'b'])
Expand Down
37 changes: 20 additions & 17 deletions src/extension/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,28 @@ export class Installer extends EventEmitter implements IInstaller {
return path.dirname(jsonFile)
}

public getInstallArguments(exePath: string, url: string | undefined): string[] {
public getInstallArguments(exePath: string, url: string | undefined): { env: string, args: string[] } {
let env = 'production'
let args = ['install', '--ignore-scripts', '--no-lockfile']
if (url && url.startsWith('https://github.com')) {
args = ['install']
env = 'development'
} else {
if (isNpmCommand(exePath)) {
args.push('--omit=dev')
args.push('--legacy-peer-deps')
args.push('--no-global')
}
if (isYarn(exePath)) {
args.push('--production')
args.push('--ignore-engines')
}
if (isPnpm(exePath)) {
args.push('--production')
args.push('--config.strict-peer-dependencies=false')
}
}
if (isNpmCommand(exePath)) {
args.push('--omit=dev')
args.push('--legacy-peer-deps')
args.push('--no-global')
}
if (isYarn(exePath)) {
args.push('--production')
args.push('--ignore-engines')
}
if (isPnpm(exePath)) {
args.push('--production')
args.push('--config.strict-peer-dependencies=false')
}
return args
return { env, args }
}

private readLines(key: string, stream: NodeJS.ReadableStream): void {
Expand All @@ -234,13 +237,13 @@ export class Installer extends EventEmitter implements IInstaller {
public installDependencies(folder: string, dependencies: string[]): Promise<void> {
if (dependencies.length == 0) return Promise.resolve()
return new Promise<void>((resolve, reject) => {
let args = this.getInstallArguments(this.npm, this.url)
let {env, args} = this.getInstallArguments(this.npm, this.url)
this.log(`Installing dependencies by: ${this.npm} ${args.join(' ')}.`)
const cmd = process.platform === 'win32' && this.npm.includes(' ') ? `"${this.npm}"` : this.npm
const child = child_process.spawn(cmd, args, {
cwd: folder,
shell: process.platform === 'win32',
env: Object.assign(process.env, { NODE_ENV: 'production' })
env: Object.assign(process.env, { NODE_ENV: env })
})
this.readLines('[npm stdout]', child.stdout)
this.readLines('[npm stderr]', child.stderr)
Expand Down

0 comments on commit e1999ee

Please sign in to comment.