Skip to content

Commit

Permalink
chore: lintfixed
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed May 17, 2023
1 parent d217e38 commit b1a8d0e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 59 deletions.
20 changes: 10 additions & 10 deletions scripts/postversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const platform = os.platform();

/* eslint-disable no-console */
async function main() {
console.error('Updating the package.json with optional native dependencies and package-lock.json');
console.error(
'Updating the package.json with optional native dependencies and package-lock.json',
);
const optionalDepsNative = [];
for (const key in packageJSON.optionalDependencies) {
if (key.startsWith(packageJSON.name)) {
Expand All @@ -35,18 +37,16 @@ async function main() {
'--package-lock-only',
'--save-optional',
'--save-exact',
...optionalDepsNative
...optionalDepsNative,
];
console.error('Running npm install:');
console.error(['npm', ...installArgs].join(' '));
childProcess.execFileSync(
'npm', installArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
}
);
childProcess.execFileSync('npm', installArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
});
}
}
/* eslint-enable no-console */
Expand Down
37 changes: 17 additions & 20 deletions scripts/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function main(argv = process.argv) {
break;
default:
console.error('Unsupported architecture');
process.exitCode = 1
process.exitCode = 1;
return process.exitCode;
}
let targetVendor;
Expand All @@ -68,18 +68,15 @@ async function main(argv = process.argv) {
targetVendor = 'pc';
targetSystem = 'windows';
targetABI = 'msvc';
break
break;
default:
console.error('Unsupported platform');
process.exitCode = 1;
return process.exitCode;
}
const target = [
targetArch,
targetVendor,
targetSystem,
targetABI
].filter((s) => s != null).join('-');
const target = [targetArch, targetVendor, targetSystem, targetABI]
.filter((s) => s != null)
.join('-');
const projectRoot = path.join(__dirname, '..');
const prebuildPath = path.join(projectRoot, 'prebuild');
await fs.promises.mkdir(prebuildPath, {
Expand All @@ -89,37 +86,37 @@ async function main(argv = process.argv) {
const cargoTOML = await fs.promises.readFile(cargoTOMLPath, 'utf-8');
const cargoTOMLVersion = cargoTOML.match(/version\s*=\s*"(.*)"/)?.[1];
if (packageJSON.version !== cargoTOMLVersion) {
console.error('Make sure that Cargo.toml version matches the package.json version');
console.error(
'Make sure that Cargo.toml version matches the package.json version',
);
process.exitCode = 1;
return process.exitCode;
}
await fs.promises.writeFile(cargoTOMLPath, cargoTOML, { encoding: 'utf-8' });
const buildPath = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'prebuild-')
path.join(os.tmpdir(), 'prebuild-'),
);
const buildArgs = [
'build',
buildPath,
`--target=${target}`,
...(production ? ['--release', '--strip']: [])
...(production ? ['--release', '--strip'] : []),
];
console.error('Running napi build:');
console.error(['napi', ...buildArgs].join(' '));
childProcess.execFileSync(
'napi', buildArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
}
);
childProcess.execFileSync('napi', buildArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
});
// Rename to `name-platform-arch.node`
const buildNames = await fs.promises.readdir(buildPath);
const buildName = buildNames.find((filename) => /\.node$/.test(filename));
const name = path.basename(buildName, '.node');
await fs.promises.copyFile(
path.join(buildPath, buildName),
path.join(prebuildPath, `${name}-${platform}-${arch}.node`)
path.join(prebuildPath, `${name}-${platform}-${arch}.node`),
);
await fs.promises.rm(buildPath, {
recursive: true,
Expand Down
32 changes: 12 additions & 20 deletions scripts/prepublishOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ async function main(argv = process.argv) {
const projectRoot = path.join(__dirname, '..');
const prebuildPath = path.join(projectRoot, 'prebuild');
const prepublishOnlyPath = path.join(projectRoot, 'prepublishOnly');
const buildNames = (
await fs.promises.readdir(prebuildPath)
).filter((filename) => /^(?:[^-]+)-(?:[^-]+)-(?:[^-]+)$/.test(filename));
const buildNames = (await fs.promises.readdir(prebuildPath)).filter(
(filename) => /^(?:[^-]+)-(?:[^-]+)-(?:[^-]+)$/.test(filename),
);
if (buildNames.length < 1) {
console.error(
'You must prebuild at least 1 native object with the filename of `name-platform-arch` before prepublish'
'You must prebuild at least 1 native object with the filename of `name-platform-arch` before prepublish',
);
process.exitCode = 1;
return process.exitCode;
Expand All @@ -64,15 +64,15 @@ async function main(argv = process.argv) {
// This is `@org/name-platform-arch`, uses `posix` to force usage of `/`
const packageName = path.posix.join(orgName ?? '', name);
const constraints = name.match(
/^(?:[^-]+)-(?<platform>[^-]+)-(?<arch>[^-]+)$/
/^(?:[^-]+)-(?<platform>[^-]+)-(?<arch>[^-]+)$/,
);
// This will be `prebuild/name-platform-arch.node`
const buildPath = path.join(prebuildPath, buildName);
// This will be `prepublishOnly/@org/name-platform-arch`
const packagePath = path.join(prepublishOnlyPath, packageName);
console.error('Packaging:', packagePath);
await fs.promises.rm(packagePath, {
recursive: true
recursive: true,
});
await fs.promises.mkdir(packagePath, { recursive: true });
const nativePackageJSON = {
Expand All @@ -86,31 +86,23 @@ async function main(argv = process.argv) {
license: packageJSON.license,
repository: packageJSON.repository,
main: 'node.napi.node',
os: [
constraints.groups.platform
],
cpu: [
...(constraints.groups.arch.split('+'))
],
os: [constraints.groups.platform],
cpu: [...constraints.groups.arch.split('+')],
};
const packageJSONPath = path.join(packagePath, 'package.json');
console.error(`Writing ${packageJSONPath}`);
const packageJSONString = JSON.stringify(nativePackageJSON, null, 2);
console.error(packageJSONString);
await fs.promises.writeFile(
packageJSONPath,
packageJSONString,
{
encoding: 'utf8'
}
);
await fs.promises.writeFile(packageJSONPath, packageJSONString, {
encoding: 'utf8',
});
const packageBuildPath = path.join(packagePath, 'node.napi.node');
console.error(`Copying ${buildPath} to ${packageBuildPath}`);
await fs.promises.copyFile(buildPath, packageBuildPath);
const publishArgs = [
'publish',
packagePath,
...(tag != null ? [`--tag=${tag}`]: []),
...(tag != null ? [`--tag=${tag}`] : []),
'--access=public',
...(dryRun ? ['--dry-run'] : []),
];
Expand Down
26 changes: 17 additions & 9 deletions src/native/quiche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ const prebuildPath = path.join(projectRoot, 'prebuild');
* try require on all npm targets second.
*/
function requireBinding(targets: Array<string>): Quiche {
const prebuildTargets = targets.map((target) => `quic-${target}.node`);
const prebuildTargets = targets.map((target) =>
path.join(prebuildPath, `quic-${target}.node`),
);
for (const prebuildTarget of prebuildTargets) {
const prebuildBindingPath = path.join(
prebuildPath,
prebuildTarget
);
try {
return require(prebuildBindingPath);
return require(prebuildTarget);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') throw e;
}
Expand All @@ -73,7 +71,9 @@ function requireBinding(targets: Array<string>): Quiche {
}
}
throw new Error(
`Failed requiring possible native bindings: ${prebuildTargets.concat(npmTargets)}`
`Failed requiring possible native bindings: ${prebuildTargets.concat(
npmTargets,
)}`,
);
}

Expand Down Expand Up @@ -102,10 +102,18 @@ switch (process.platform) {
case 'darwin':
switch (process.arch) {
case 'x64':
nativeBinding = requireBinding(['darwin-x64', 'darwin-x64+arm64', 'darwin-arm64+x64']);
nativeBinding = requireBinding([
'darwin-x64',
'darwin-x64+arm64',
'darwin-arm64+x64',
]);
break;
case 'arm64':
nativeBinding = requireBinding(['darwin-arm64', 'darwin-arm64+x64', 'darwin-x64+arm64']);
nativeBinding = requireBinding([
'darwin-arm64',
'darwin-arm64+x64',
'darwin-x64+arm64',
]);
break;
default:
throw new Error(`Unsupported architecture on macOS: ${process.arch}`);
Expand Down

0 comments on commit b1a8d0e

Please sign in to comment.