WIP - add extractor, generate snippet_data
This commit is contained in:
50
node_modules/gatsby-core-utils/dist/cpu-core-count.js
generated
vendored
Normal file
50
node_modules/gatsby-core-utils/dist/cpu-core-count.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @type {import('../index').cpuCoreCount}
|
||||
*/
|
||||
const cpuCoreCount = ignoreEnvVar => {
|
||||
try {
|
||||
let coreCount = require(`./physical-cpu-count`) || 1;
|
||||
|
||||
if (ignoreEnvVar) {
|
||||
// Return the physical CPU count,
|
||||
// or default to 1 if we can't detect
|
||||
return coreCount;
|
||||
}
|
||||
|
||||
if (typeof process.env.GATSBY_CPU_COUNT !== `undefined`) {
|
||||
const coreCountArg = Number(process.env.GATSBY_CPU_COUNT) || process.env.GATSBY_CPU_COUNT;
|
||||
|
||||
switch (typeof coreCountArg) {
|
||||
case `string`:
|
||||
// Leave at Default CPU count if coreCountArg === `physical_cores`
|
||||
// CPU count === logical CPU count
|
||||
// throw error if we have a problem counting logical cores
|
||||
if (coreCountArg === `logical_cores`) {
|
||||
coreCount = require(`os`).cpus().length;
|
||||
|
||||
if (typeof coreCount !== `number`) {
|
||||
throw new Error(`process.env.GATSBY_CPU_COUNT is set to 'logical_cores' but there was a problem finding the number of logical cores`);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case `number`:
|
||||
// CPU count === passed in count
|
||||
coreCount = coreCountArg;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return coreCount;
|
||||
} catch (err) {
|
||||
throw new Error(`There has been a problem counting the number of CPU cores`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = cpuCoreCount;
|
||||
14
node_modules/gatsby-core-utils/dist/create-content-digest.js
generated
vendored
Normal file
14
node_modules/gatsby-core-utils/dist/create-content-digest.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
const crypto = require(`crypto`);
|
||||
/**
|
||||
* @type {import('../index').createContentDigest}
|
||||
*/
|
||||
|
||||
|
||||
const createContentDigest = input => {
|
||||
const content = typeof input !== `string` ? JSON.stringify(input) : input;
|
||||
return crypto.createHash(`md5`).update(content).digest(`hex`);
|
||||
};
|
||||
|
||||
module.exports = createContentDigest;
|
||||
6
node_modules/gatsby-core-utils/dist/index.js
generated
vendored
Normal file
6
node_modules/gatsby-core-utils/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
exports.createContentDigest = require(`./create-content-digest`);
|
||||
exports.joinPath = require(`./path`).joinPath;
|
||||
exports.cpuCoreCount = require(`./cpu-core-count`);
|
||||
exports.urlResolve = require(`./url`).resolve;
|
||||
22
node_modules/gatsby-core-utils/dist/path.js
generated
vendored
Normal file
22
node_modules/gatsby-core-utils/dist/path.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.joinPath = joinPath;
|
||||
|
||||
const path = require(`path`);
|
||||
|
||||
const os = require(`os`);
|
||||
/**
|
||||
* @type {import('../index').joinPath}
|
||||
*/
|
||||
|
||||
|
||||
function joinPath(...paths) {
|
||||
const joinedPath = path.join(...paths);
|
||||
|
||||
if (os.platform() === `win32`) {
|
||||
return joinedPath.replace(/\\/g, `\\\\`);
|
||||
}
|
||||
|
||||
return joinedPath;
|
||||
}
|
||||
52
node_modules/gatsby-core-utils/dist/physical-cpu-count.js
generated
vendored
Normal file
52
node_modules/gatsby-core-utils/dist/physical-cpu-count.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
// Forked from physical-cpu-count package from npm
|
||||
const os = require(`os`);
|
||||
|
||||
const childProcess = require(`child_process`);
|
||||
|
||||
function exec(command) {
|
||||
const output = childProcess.execSync(command, {
|
||||
encoding: `utf8`
|
||||
});
|
||||
return output;
|
||||
}
|
||||
/*
|
||||
* Fallback if child process fails to receive CPU count
|
||||
*/
|
||||
|
||||
|
||||
function fallbackToNodeJSCheck() {
|
||||
const cores = os.cpus().filter(function (cpu, index) {
|
||||
const hasHyperthreading = cpu.model.includes(`Intel`);
|
||||
const isOdd = index % 2 === 1;
|
||||
return !hasHyperthreading || isOdd;
|
||||
});
|
||||
return cores.length;
|
||||
}
|
||||
|
||||
const platform = os.platform();
|
||||
|
||||
function getPhysicalCpuCount() {
|
||||
try {
|
||||
if (platform === `linux`) {
|
||||
const output = exec(`lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l`);
|
||||
return Number(output.trim());
|
||||
}
|
||||
|
||||
if (platform === `darwin`) {
|
||||
const output = exec(`sysctl -n hw.physicalcpu_max`);
|
||||
return Number(output.trim());
|
||||
}
|
||||
|
||||
if (platform === `win32`) {
|
||||
const output = exec(`WMIC CPU Get NumberOfCores`);
|
||||
return output.replace(/\r/g, ``).split(`\n`).map(line => Number(line)).filter(value => !isNaN(value)).reduce((sum, number) => sum + number, 0);
|
||||
}
|
||||
} catch (err) {// carry on
|
||||
}
|
||||
|
||||
return fallbackToNodeJSCheck();
|
||||
}
|
||||
|
||||
module.exports = getPhysicalCpuCount();
|
||||
1
node_modules/gatsby-core-utils/dist/true-case-path.js
generated
vendored
Normal file
1
node_modules/gatsby-core-utils/dist/true-case-path.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
"use strict";
|
||||
22
node_modules/gatsby-core-utils/dist/url.js
generated
vendored
Normal file
22
node_modules/gatsby-core-utils/dist/url.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.resolve = resolve;
|
||||
|
||||
const path = require(`path`);
|
||||
|
||||
const os = require(`os`);
|
||||
/**
|
||||
* @type {import('../index').urlResolve}
|
||||
*/
|
||||
|
||||
|
||||
function resolve(...segments) {
|
||||
const joinedPath = path.join(...segments);
|
||||
|
||||
if (os.platform() === `win32`) {
|
||||
return joinedPath.replace(/\\/g, `/`);
|
||||
}
|
||||
|
||||
return joinedPath;
|
||||
}
|
||||
Reference in New Issue
Block a user