-
Notifications
You must be signed in to change notification settings - Fork 930
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(examples): compatible with legacy openssl when running webpack
- Loading branch information
1 parent
1f8b48c
commit 46dff5f
Showing
3 changed files
with
159 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,61 @@ | ||
const { exec } = require('shelljs'); | ||
|
||
const scriptString = process.argv.slice(2).join(' '); | ||
|
||
const execOptions = { stdio: 'inherit' }; | ||
function runScript(scriptStr) { | ||
const result = exec(scriptStr, execOptions); | ||
const runScript = (scriptStr) => { | ||
console.log(`Full command execute: "${scriptStr}"`); | ||
const result = exec(scriptStr, { stdio: 'inherit' }); | ||
if (result.code !== 0) { | ||
console.error(`❌ execute cmd - "${scriptStr}" error: ${result.stderr}`); | ||
console.error(`❌ Execute cmd - "${scriptStr}" error: ${result.stderr}`); | ||
process.exit(1); | ||
} | ||
} | ||
}; | ||
|
||
console.log(`Start to execute cmd "${scriptString}"`); | ||
let envPrefixStr = 'cross-env-os os="Windows_NT,Linux,Darwin" minVersion=17 NODE_OPTIONS=--openssl-legacy-provider'; | ||
const isArmCpu = !!require('os').arch() | ||
.toLowerCase() | ||
.includes('arm'); | ||
if (isArmCpu) { | ||
envPrefixStr = ''; | ||
const toNum = (originalNum) => { | ||
const num = `${originalNum}`; | ||
const versionList = num.split('.'); | ||
const currentSplitLength = versionList.length; | ||
if (currentSplitLength !== 4) { | ||
let index = currentSplitLength; | ||
while (index < 4) { | ||
versionList.push('0'); | ||
index += 1; | ||
} | ||
} | ||
const r = ['0000', '000', '00', '0', '']; | ||
for (let i = 0; i < versionList.length; i += 1) { | ||
let len = versionList[i].length; | ||
if (len > 4) { | ||
len = 4; | ||
versionList[i] = versionList[i].slice(0, 4); | ||
} | ||
versionList[i] = r[len] + versionList[i]; | ||
} | ||
return versionList.join(''); | ||
}; | ||
|
||
const versionCompare = (targetVer, currentVer) => { | ||
if (!targetVer || !currentVer) return 1; | ||
const numA = toNum(currentVer); | ||
const numB = toNum(targetVer); | ||
if (numA === numB) { | ||
return 0; | ||
} | ||
return numA < numB ? -1 : 1; | ||
}; | ||
|
||
const LEGACY_OPENSSL_VERSION = '3.0.0'; | ||
const scriptString = process.argv.slice(2).join(' '); | ||
let envPrefixStr = ''; | ||
|
||
console.log(`Start to execute cmd: "${scriptString}"`); | ||
console.log(`Current openssl version: ${process.versions.openssl}`); | ||
|
||
const result = /^(\d+\.\d+\.\d+).*$/.exec(process.versions.openssl.toString().trim()); | ||
if (result && result[1]) { | ||
const currentVersion = result[1]; | ||
const compareResult = versionCompare(LEGACY_OPENSSL_VERSION, currentVersion); | ||
if (compareResult >= 0) { | ||
envPrefixStr += 'NODE_OPTIONS=--openssl-legacy-provider'; | ||
} | ||
} | ||
|
||
runScript(`${envPrefixStr} ${scriptString}`); // start to execute cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,61 @@ | ||
const { exec } = require('shelljs'); | ||
|
||
const scriptString = process.argv.slice(2).join(' '); | ||
|
||
const execOptions = { stdio: 'inherit' }; | ||
function runScript(scriptStr) { | ||
const result = exec(scriptStr, execOptions); | ||
const runScript = (scriptStr) => { | ||
console.log(`Full command execute: "${scriptStr}"`); | ||
const result = exec(scriptStr, { stdio: 'inherit' }); | ||
if (result.code !== 0) { | ||
console.error(`❌ execute cmd - "${scriptStr}" error: ${result.stderr}`); | ||
console.error(`❌ Execute cmd - "${scriptStr}" error: ${result.stderr}`); | ||
process.exit(1); | ||
} | ||
} | ||
}; | ||
|
||
console.log(`Start to execute cmd "${scriptString}"`); | ||
let envPrefixStr = 'cross-env-os os="Windows_NT,Linux,Darwin" minVersion=17 NODE_OPTIONS=--openssl-legacy-provider'; | ||
const isArmCpu = !!require('os').arch() | ||
.toLowerCase() | ||
.includes('arm'); | ||
if (isArmCpu) { | ||
envPrefixStr = ''; | ||
const toNum = (originalNum) => { | ||
const num = `${originalNum}`; | ||
const versionList = num.split('.'); | ||
const currentSplitLength = versionList.length; | ||
if (currentSplitLength !== 4) { | ||
let index = currentSplitLength; | ||
while (index < 4) { | ||
versionList.push('0'); | ||
index += 1; | ||
} | ||
} | ||
const r = ['0000', '000', '00', '0', '']; | ||
for (let i = 0; i < versionList.length; i += 1) { | ||
let len = versionList[i].length; | ||
if (len > 4) { | ||
len = 4; | ||
versionList[i] = versionList[i].slice(0, 4); | ||
} | ||
versionList[i] = r[len] + versionList[i]; | ||
} | ||
return versionList.join(''); | ||
}; | ||
|
||
const versionCompare = (targetVer, currentVer) => { | ||
if (!targetVer || !currentVer) return 1; | ||
const numA = toNum(currentVer); | ||
const numB = toNum(targetVer); | ||
if (numA === numB) { | ||
return 0; | ||
} | ||
return numA < numB ? -1 : 1; | ||
}; | ||
|
||
const LEGACY_OPENSSL_VERSION = '3.0.0'; | ||
const scriptString = process.argv.slice(2).join(' '); | ||
let envPrefixStr = ''; | ||
|
||
console.log(`Start to execute cmd: "${scriptString}"`); | ||
console.log(`Current openssl version: ${process.versions.openssl}`); | ||
|
||
const result = /^(\d+\.\d+\.\d+).*$/.exec(process.versions.openssl.toString().trim()); | ||
if (result && result[1]) { | ||
const currentVersion = result[1]; | ||
const compareResult = versionCompare(LEGACY_OPENSSL_VERSION, currentVersion); | ||
if (compareResult >= 0) { | ||
envPrefixStr += 'NODE_OPTIONS=--openssl-legacy-provider'; | ||
} | ||
} | ||
|
||
runScript(`${envPrefixStr} ${scriptString}`); // start to execute cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,61 @@ | ||
const { exec } = require('shelljs'); | ||
|
||
const scriptString = process.argv.slice(2).join(' '); | ||
|
||
const execOptions = { stdio: 'inherit' }; | ||
function runScript(scriptStr) { | ||
const result = exec(scriptStr, execOptions); | ||
const runScript = (scriptStr) => { | ||
console.log(`Full command execute: "${scriptStr}"`); | ||
const result = exec(scriptStr, { stdio: 'inherit' }); | ||
if (result.code !== 0) { | ||
console.error(`❌ execute cmd - "${scriptStr}" error: ${result.stderr}`); | ||
console.error(`❌ Execute cmd - "${scriptStr}" error: ${result.stderr}`); | ||
process.exit(1); | ||
} | ||
} | ||
}; | ||
|
||
console.log(`Start to execute cmd "${scriptString}"`); | ||
let envPrefixStr = 'cross-env-os os="Windows_NT,Linux,Darwin" minVersion=17 NODE_OPTIONS=--openssl-legacy-provider'; | ||
const isArmCpu = !!require('os').arch() | ||
.toLowerCase() | ||
.includes('arm'); | ||
if (isArmCpu) { | ||
envPrefixStr = ''; | ||
const toNum = (originalNum) => { | ||
const num = `${originalNum}`; | ||
const versionList = num.split('.'); | ||
const currentSplitLength = versionList.length; | ||
if (currentSplitLength !== 4) { | ||
let index = currentSplitLength; | ||
while (index < 4) { | ||
versionList.push('0'); | ||
index += 1; | ||
} | ||
} | ||
const r = ['0000', '000', '00', '0', '']; | ||
for (let i = 0; i < versionList.length; i += 1) { | ||
let len = versionList[i].length; | ||
if (len > 4) { | ||
len = 4; | ||
versionList[i] = versionList[i].slice(0, 4); | ||
} | ||
versionList[i] = r[len] + versionList[i]; | ||
} | ||
return versionList.join(''); | ||
}; | ||
|
||
const versionCompare = (targetVer, currentVer) => { | ||
if (!targetVer || !currentVer) return 1; | ||
const numA = toNum(currentVer); | ||
const numB = toNum(targetVer); | ||
if (numA === numB) { | ||
return 0; | ||
} | ||
return numA < numB ? -1 : 1; | ||
}; | ||
|
||
const LEGACY_OPENSSL_VERSION = '3.0.0'; | ||
const scriptString = process.argv.slice(2).join(' '); | ||
let envPrefixStr = ''; | ||
|
||
console.log(`Start to execute cmd: "${scriptString}"`); | ||
console.log(`Current openssl version: ${process.versions.openssl}`); | ||
|
||
const result = /^(\d+\.\d+\.\d+).*$/.exec(process.versions.openssl.toString().trim()); | ||
if (result && result[1]) { | ||
const currentVersion = result[1]; | ||
const compareResult = versionCompare(LEGACY_OPENSSL_VERSION, currentVersion); | ||
if (compareResult >= 0) { | ||
envPrefixStr += 'NODE_OPTIONS=--openssl-legacy-provider'; | ||
} | ||
} | ||
|
||
runScript(`${envPrefixStr} ${scriptString}`); // start to execute cmd |