Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs 子进程调用devs 获取不了环境变量 #791

Open
wss-git opened this issue Mar 12, 2024 · 1 comment
Open

nodejs 子进程调用devs 获取不了环境变量 #791

wss-git opened this issue Mar 12, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@wss-git
Copy link
Member

wss-git commented Mar 12, 2024

如下所示,e.js 可以获得 环境变量。但是 s.yaml 无法转换

index.js

const { spawn } = require('child_process')
const fs = require('fs')

async function customSpawnSync(cmd, times) {
  return new Promise((resolve, reject) => {
    const child = spawn(cmd, {
      shell: true,
      stdio: 'inherit',
      // encoding: 'utf-8',
      env: { ...process.env, times }
    });

    child.on('error', reject)
    // 子进程结束时输出
    child.on('close', resolve);
  })
}

(async () => {
  for (let times = 7; times <= 8; times++) {
    await customSpawnSync('node e', times)
  }
})()

e.js

console.log('process.env.times:: ', process.env.times)

s.yaml

edition: 1.0.0
name: component-test
access: default

vars:
  service:
    internetAccess: true
    name: lib1-base
  times: ${env('times')}

services:
  puppeteer:
    component: fc
    props:
      region: cn-qingdao
      service: ${vars.service}
      function:
        name: puppeteer-${vars.times}
        handler: index.handler
        timeout: 60
        runtime: nodejs14
        cpu: 0.05
        diskSize: 512
        instanceConcurrency: 1
        memorySize: 128
        codeUri: ./puppeteer
@wss-git wss-git added the bug Something isn't working label Mar 12, 2024
@zxypro1
Copy link
Collaborator

zxypro1 commented Mar 12, 2024

发下s preview结果看一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants