fix(esm): improve ESM compatibility and modernize package configuration
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartspawn',
|
||||
version: '3.0.3',
|
||||
version: '3.0.4',
|
||||
description: 'A node module for smart subprocess handling with support for promises and streamlined subprocess communication.'
|
||||
}
|
||||
|
||||
+30
-1
@@ -1,4 +1,33 @@
|
||||
export * from './smartspawn.classes.threadsimple.js';
|
||||
export * from './smartspawn.wrap.js';
|
||||
|
||||
export * from 'threads';
|
||||
import { createRequire } from 'module';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
export interface IThreadsModule {
|
||||
BlobWorker: new (...args: unknown[]) => unknown;
|
||||
DefaultSerializer: unknown;
|
||||
Pool: unknown;
|
||||
Thread: {
|
||||
terminate: (threadArg: unknown) => Promise<void> | void;
|
||||
events?: (threadArg: unknown) => unknown;
|
||||
};
|
||||
Transfer: (payloadArg: unknown, transferablesArg?: Transferable[]) => unknown;
|
||||
Worker: new (workerPathArg: string | URL, optionsArg?: unknown) => unknown;
|
||||
registerSerializer: (serializerArg: unknown) => void;
|
||||
spawn: <T = unknown>(workerArg: unknown, optionsArg?: unknown) => Promise<T>;
|
||||
}
|
||||
|
||||
const threads = require('threads') as IThreadsModule;
|
||||
|
||||
export const {
|
||||
BlobWorker,
|
||||
DefaultSerializer,
|
||||
Pool,
|
||||
Thread,
|
||||
Transfer,
|
||||
Worker,
|
||||
registerSerializer,
|
||||
spawn,
|
||||
} = threads;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import * as plugins from './smartspawn.plugins.js';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as childProcess from 'child_process';
|
||||
|
||||
export class ThreadSimple {
|
||||
public workerPath: string;
|
||||
public threadChildProcess: childProcess.ChildProcess;
|
||||
public threadChildProcess!: childProcess.ChildProcess;
|
||||
public forkOptions: childProcess.ForkOptions;
|
||||
public argvArgs: string[];
|
||||
constructor(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartspawn.plugins.js';
|
||||
|
||||
export const packageBase = plugins.path.join(__dirname, '../');
|
||||
export const packageBase = plugins.path.join(plugins.path.dirname(plugins.url.fileURLToPath(import.meta.url)), '../');
|
||||
export const typescriptwrapJs = plugins.path.join(packageBase, 'assets/typescriptwrap.js');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import * as threads from 'threads';
|
||||
import * as url from 'url';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { path, smartpromise, threads };
|
||||
export { path, smartpromise, url };
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import * as spawnWrap from 'spawn-wrap';
|
||||
import { createRequire } from 'module';
|
||||
|
||||
let unwrap: any = null;
|
||||
const require = createRequire(import.meta.url);
|
||||
const spawnWrap = require('spawn-wrap') as (
|
||||
spawnArgvArg: string[],
|
||||
envArg?: NodeJS.ProcessEnv,
|
||||
) => () => void;
|
||||
|
||||
export const startSpawnWrap = (filePath: string, cliArgs: string[] = [], envArgs: any = {}) => {
|
||||
let unwrap: (() => void) | null = null;
|
||||
|
||||
export const startSpawnWrap = (filePath: string, cliArgs: string[] = [], envArgs: NodeJS.ProcessEnv = {}) => {
|
||||
const spawnArray = [filePath];
|
||||
for (const cliArg of cliArgs) {
|
||||
spawnArray.push(cliArg);
|
||||
|
||||
Reference in New Issue
Block a user