diff --git a/extra/meta.cjs b/extra/meta.cjs new file mode 100644 index 000000000..0e1e1148c --- /dev/null +++ b/extra/meta.cjs @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getRequire = exports.getDirName = void 0; + +function getDirName() { + return __dirname; +} +exports.getDirName = getDirName; + +function getRequire() { + return require; +} +exports.getRequire = getRequire; diff --git a/extra/meta.mjs b/extra/meta.mjs new file mode 100644 index 000000000..aecdf4ee8 --- /dev/null +++ b/extra/meta.mjs @@ -0,0 +1,8 @@ +import { createRequire } from 'node:module'; +import { fileURLToPath } from 'node:url'; +export function getDirName() { + return fileURLToPath(new URL('.', import.meta.url)); +} +export function getRequire() { + return createRequire(import.meta.url); +} diff --git a/package.json b/package.json index fbcc6ed88..9d215ae59 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,9 @@ "module": "./esm/lib/opencv4nodejs.js", "typings": "./typings/index.d.ts", "scripts": { - "build": "tsc --pretty --project tsconfig.json && tsc --pretty --project tsconfig-esm.json", + "build": "tsc --pretty --project tsconfig.json && tsc --pretty --project tsconfig-esm.json && npm run copyfile", "build-types": "rimraf types && tsc --pretty --project tsconfig-types.json", + "copyfile": "shx cp extra/meta.mjs esm/lib/meta.js && shx cp extra/meta.cjs cjs/lib/meta.js", "prepack": "npm run build", "install_old": "node bin/install.js auto", "install_Mac": "CXXFLAGS=\"-std=c++17 -Wno-c++11-narrowing -Wno-c++17-extensions -Wno-c++17-attribute-extensions\" node ./bin/install.js --version 4.5.3 build", @@ -89,6 +90,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "progress": "^2.0.3", "rimraf": "^5.0.5", + "shx": "^0.3.4", "typescript": "^5.4.5" }, "files": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7fc5972a0..0f2581edf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,6 +64,9 @@ devDependencies: rimraf: specifier: ^5.0.5 version: 5.0.5 + shx: + specifier: ^0.3.4 + version: 0.3.4 typescript: specifier: ^5.4.5 version: 5.4.5 @@ -1600,6 +1603,11 @@ packages: side-channel: 1.0.6 dev: true + /interpret@1.4.0: + resolution: {integrity: sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==} + engines: {node: '>= 0.10'} + dev: true + /ip-address@9.0.5: resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==} engines: {node: '>= 12'} @@ -2303,6 +2311,13 @@ packages: resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==} dev: true + /rechoir@0.6.2: + resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==} + engines: {node: '>= 0.10'} + dependencies: + resolve: 1.22.8 + dev: true + /reflect.getprototypeof@1.0.6: resolution: {integrity: sha512-fmfw4XgoDke3kdI6h4xcUz1dG8uaiv5q9gcEwLS4Pnth2kxT+GZ7YehS1JTMGBQmtV7Y4GFGbs2re2NqhdozUg==} engines: {node: '>= 0.4'} @@ -2456,6 +2471,25 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + /shelljs@0.8.5: + resolution: {integrity: sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==} + engines: {node: '>=4'} + hasBin: true + dependencies: + glob: 7.2.3 + interpret: 1.4.0 + rechoir: 0.6.2 + dev: true + + /shx@0.3.4: + resolution: {integrity: sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==} + engines: {node: '>=6'} + hasBin: true + dependencies: + minimist: 1.2.8 + shelljs: 0.8.5 + dev: true + /side-channel@1.0.6: resolution: {integrity: sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==} engines: {node: '>= 0.4'} diff --git a/src/lib/opencv4nodejs.ts b/src/lib/opencv4nodejs.ts index fd38a6c84..c58db7969 100644 --- a/src/lib/opencv4nodejs.ts +++ b/src/lib/opencv4nodejs.ts @@ -5,6 +5,7 @@ import extendWithJsSources from './src/index.js'; import { getOpenCV } from './cvloader.js'; import type * as openCV from '../../typings/index.js'; export type * as openCV from '../../typings/index.js'; +export { getDirName, getRequire } from "./meta.js" declare type OpenCVType = typeof openCV; diff --git a/types/lib/cvloader.d.ts b/types/lib/cvloader.d.ts index 51e79d8df..751795b29 100644 --- a/types/lib/cvloader.d.ts +++ b/types/lib/cvloader.d.ts @@ -1,5 +1,5 @@ import { type OpenCVBuildEnvParams } from '@u4/opencv-build'; -import type * as openCV from '../../typings/index'; +import type * as openCV from '../../typings/index.js'; declare type OpenCVType = typeof openCV; export declare function getOpenCV(opt?: OpenCVBuildEnvParams): OpenCVType; export default getOpenCV; diff --git a/types/lib/meta.d.ts b/types/lib/meta.d.ts new file mode 100644 index 000000000..fbdc60b8d --- /dev/null +++ b/types/lib/meta.d.ts @@ -0,0 +1,3 @@ +/// +export declare function getDirName(): string; +export declare function getRequire(): NodeRequire; diff --git a/types/lib/opencv4nodejs.d.ts b/types/lib/opencv4nodejs.d.ts index d30f24cf9..ad18b1378 100644 --- a/types/lib/opencv4nodejs.d.ts +++ b/types/lib/opencv4nodejs.d.ts @@ -1,7 +1,8 @@ -import type * as openCV from '../../typings/index'; -export type * as openCV from '../../typings/index'; +import type * as openCV from '../../typings/index.js'; +export type * as openCV from '../../typings/index.js'; export declare const cv: typeof openCV; declare const defExport: { [key: string]: any; }; +export { getDirName, getRequire } from "./meta.js"; export default defExport; diff --git a/types/lib/src/deprecations.d.ts b/types/lib/src/deprecations.d.ts index ca2ce178e..d7c27d55e 100644 --- a/types/lib/src/deprecations.d.ts +++ b/types/lib/src/deprecations.d.ts @@ -1,2 +1,2 @@ -import type * as openCV from '../../../typings/index'; +import type * as openCV from '../../../typings/index.js'; export default function (cv: typeof openCV): void; diff --git a/types/lib/src/drawUtils.d.ts b/types/lib/src/drawUtils.d.ts index 2125e1e05..fc0660e24 100644 --- a/types/lib/src/drawUtils.d.ts +++ b/types/lib/src/drawUtils.d.ts @@ -1,5 +1,5 @@ -import type * as openCV from '../../../typings/index'; -import { Mat, Rect, Vec3 } from '../../../typings/index'; +import type * as openCV from '../../../typings/index.js'; +import { Mat, Rect, Vec3 } from '../../../typings/index.js'; export interface TextParams { fontType: number; fontSize: number; diff --git a/types/lib/src/index.d.ts b/types/lib/src/index.d.ts index 68e129c35..e3942e11d 100644 --- a/types/lib/src/index.d.ts +++ b/types/lib/src/index.d.ts @@ -1,2 +1,2 @@ -import * as OpenCV from '../../../typings/index'; +import * as OpenCV from '../../../typings/index.js'; export default function extendWithJsSources(cv: typeof OpenCV): typeof OpenCV; diff --git a/types/lib/src/misc.d.ts b/types/lib/src/misc.d.ts index 9156b494d..9d47b77ff 100644 --- a/types/lib/src/misc.d.ts +++ b/types/lib/src/misc.d.ts @@ -1,5 +1,5 @@ -import type * as openCV from '../../../typings/index'; -import type { Mat, Rect } from '../../../typings/index'; +import type * as openCV from '../../../typings/index.js'; +import type { Mat, Rect } from '../../../typings/index.js'; export declare const allTypes: readonly ["CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S", "CV_32F", "CV_64F", "CV_8UC1", "CV_8UC2", "CV_8UC3", "CV_8UC4", "CV_8SC1", "CV_8SC2", "CV_8SC3", "CV_8SC4", "CV_16UC1", "CV_16UC2", "CV_16UC3", "CV_16UC4", "CV_16SC1", "CV_16SC2", "CV_16SC3", "CV_16SC4", "CV_32SC1", "CV_32SC2", "CV_32SC3", "CV_32SC4", "CV_32FC1", "CV_32FC2", "CV_32FC3", "CV_32FC4", "CV_64FC1", "CV_64FC2", "CV_64FC3", "CV_64FC4"]; export type MatTypes = typeof allTypes[number]; /**