Skip to content

Commit 3b38de7

Browse files
committed
wip: converting imports
1 parent 42e36ab commit 3b38de7

File tree

11 files changed

+43
-25
lines changed

11 files changed

+43
-25
lines changed

npmDepsHash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha256-LHQ8nB8ewWjKMgdkS1oguQKaFk1IsAroYdZ21Z7bnME=
1+
sha256-YnXZgZFFew+nEbpxAnslWboXViBWXyRmtJ6xwLDEosg=

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
"nexpect": "^0.6.0",
167167
"node-gyp-build": "^4.8.4",
168168
"nodemon": "^3.0.1",
169-
"polykey": "^2.0.0",
169+
"polykey": "^2.0.3",
170170
"prettier": "^3.0.0",
171171
"shelljs": "^0.8.5",
172172
"shx": "^0.3.4",

scripts/build.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import url from 'node:url';
77
import process from 'node:process';
88
import childProcess from 'node:child_process';
99
import esbuild from 'esbuild';
10-
import polykey from 'polykey';
10+
import config from 'polykey/config.js';
1111
import packageJSON from '../package.json' assert { type: 'json' };
1212

1313
const projectPath = path.dirname(
@@ -52,10 +52,10 @@ async function main(argv = process.argv) {
5252
versionMetadata: {
5353
version: packageJSON.version,
5454
commitHash: gitHead,
55-
libVersion: polykey.config.version,
56-
libSourceVersion: polykey.config.sourceVersion,
57-
libStateVersion: polykey.config.stateVersion.toString(),
58-
libNetworkVersion: polykey.config.networkVersion.toString(),
55+
libVersion: config.version,
56+
libSourceVersion: config.sourceVersion,
57+
libStateVersion: config.stateVersion.toString(),
58+
libNetworkVersion: config.networkVersion.toString(),
5959
},
6060
};
6161
console.error('Writing build metadata (build.json):');

src/CommandPolykey.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class CommandPolykey extends commander.Command {
2525

2626
public constructor({
2727
exitHandlers,
28-
fs = require('fs'),
28+
fs,
2929
}: {
3030
exitHandlers: binUtils.ExitHandlers;
31-
fs?: FileSystem;
31+
fs: FileSystem;
3232
}) {
3333
super();
3434
this.fs = fs;

src/polykey.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import process from 'process';
1616
* If the worker manager is used, it must be stopped gracefully with the PolykeyAgent
1717
*/
1818
import 'threads';
19+
import url from 'node:url';
1920
process.removeAllListeners('SIGINT');
2021
process.removeAllListeners('SIGTERM');
2122

@@ -254,8 +255,11 @@ async function main(argv = process.argv): Promise<number> {
254255
}
255256
}
256257

257-
if (require.main === module) {
258-
void main();
258+
if (import.meta.url.startsWith('file:')) {
259+
const modulePath = url.fileURLToPath(import.meta.url);
260+
if (process.argv[1] === modulePath) {
261+
void main();
262+
}
259263
}
260264

261265
export default main;

src/secrets/CommandList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CommandList extends CommandPolykey {
2121
this.addOption(binOptions.clientPort);
2222
this.action(async (secretPath, options) => {
2323
const { default: PolykeyClient } = await import(
24-
'polykey/dist/PolykeyClient'
24+
'polykey/PolykeyClient.js'
2525
);
2626
const clientOptions = await binProcessors.processClientOptions(
2727
options.nodePath,

src/secrets/CommandMkdir.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CommandMkdir extends CommandPolykey {
2626
binParsers.parseSecretPath(path),
2727
);
2828
const { default: PolykeyClient } = await import(
29-
'polykey/dist/PolykeyClient'
29+
'polykey/PolykeyClient.js'
3030
);
3131
const clientOptions = await binProcessors.processClientOptions(
3232
options.nodePath,

src/secrets/CommandRemove.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CommandRemove extends CommandPolykey {
2525
binParsers.parseSecretPath(path),
2626
);
2727
const { default: PolykeyClient } = await import(
28-
'polykey/dist/PolykeyClient'
28+
'polykey/PolykeyClient.js'
2929
);
3030
const clientOptions = await binProcessors.processClientOptions(
3131
options.nodePath,

src/utils/processors.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Status from 'polykey/status/Status.js';
1616
import * as clientUtils from 'polykey/client/utils.js';
1717
import { arrayZip, promise } from 'polykey/utils/index.js';
1818
import config from 'polykey/config.js';
19+
import * as utils from './utils.js';
1920
import * as errors from '../errors.js';
2021

2122
/**
@@ -175,9 +176,10 @@ async function processPassword(
175176
*/
176177
async function processNewPassword(
177178
passwordNewFile?: string,
178-
fs: FileSystem = require('fs'),
179+
fs?: FileSystem,
179180
existing: boolean = false,
180181
): Promise<string> {
182+
fs = await utils.importFS(fs);
181183
let passwordNew: string | undefined;
182184
if (passwordNewFile != null) {
183185
try {
@@ -217,8 +219,9 @@ async function processNewPassword(
217219
*/
218220
async function processRecoveryCode(
219221
recoveryCodeFile?: string,
220-
fs: FileSystem = require('fs'),
222+
fs?: FileSystem,
221223
): Promise<RecoveryCode | undefined> {
224+
fs = await utils.importFS(fs);
222225
let recoveryCode: string | undefined;
223226
if (recoveryCodeFile != null) {
224227
try {
@@ -258,13 +261,14 @@ async function processClientOptions(
258261
nodeId?: NodeId,
259262
clientHost?: string,
260263
clientPort?: number,
261-
fs = require('fs'),
264+
fs?: FileSystem,
262265
logger = new Logger(processClientOptions.name),
263266
): Promise<{
264267
nodeId: NodeId;
265268
clientHost: string;
266269
clientPort: number;
267270
}> {
271+
fs = await utils.importFS(fs);
268272
if (nodeId != null && clientHost != null && clientPort != null) {
269273
return {
270274
nodeId,
@@ -321,7 +325,7 @@ async function processClientStatus(
321325
nodeId?: NodeId,
322326
clientHost?: string,
323327
clientPort?: number,
324-
fs = require('fs'),
328+
fs?: FileSystem,
325329
logger = new Logger(processClientStatus.name),
326330
): Promise<
327331
| {
@@ -346,6 +350,7 @@ async function processClientStatus(
346350
clientPort: number;
347351
}
348352
> {
353+
fs = await utils.importFS(fs);
349354
if (nodeId != null && clientHost != null && clientPort != null) {
350355
return {
351356
statusInfo: undefined,
@@ -426,8 +431,9 @@ async function processClientStatus(
426431
*/
427432
async function processAuthentication(
428433
passwordFile?: string,
429-
fs: FileSystem = require('fs'),
434+
fs?: FileSystem,
430435
): Promise<{ authorization?: string }> {
436+
fs = await utils.importFS(fs);
431437
if (passwordFile != null) {
432438
let password;
433439
try {

0 commit comments

Comments
 (0)