Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fix references to httptoolkit types #81

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,339 changes: 595 additions & 744 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"type": "git",
"url": "https://github.com/nktnet1/import-sync"
},
"version": "2.2.0",
"version": "2.2.1",
"files": [
"dist"
"dist",
"types"
],
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -42,16 +43,16 @@
"license": "MIT",
"description": "Synchronously import dynamic ECMAScript Modules similar to CommonJS require. Basic wrapper around esm for compatibility with both ESM and CJS projects in NodeJS.",
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@commitlint/cli": "^19.1.0",
"@commitlint/config-conventional": "^19.1.0",
"@types/esm": "^3.2.2",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.26",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^27.9.0",
"husky": "^8.0.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"node-fetch": "^3.3.2",
"ts-jest": "^29.1.2",
Expand Down
4 changes: 0 additions & 4 deletions src/httptoolkit-esm-types.d.ts

This file was deleted.

26 changes: 8 additions & 18 deletions src/import.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import esm from '@httptoolkit/esm';

import { ESMOptions, Options } from './types';
import { Options } from './options';
import { findModuleFile, getCallerDirname } from './files';

/**
* Creates an esm-compatible require function that can import ES Modules
*
* @returns an ESM-compatible require function
*/
/* istanbul ignore next */
const createEsmRequire = (esmOptions: ESMOptions) => {
return esm(module, esmOptions);
};

/**
* Returns an ESM-imported module
*
Expand All @@ -21,17 +11,17 @@ const createEsmRequire = (esmOptions: ESMOptions) => {
* @returns the esm imported module
*/
const esmImport = (modulePath: string, options: Options) => {
const esmRequire = createEsmRequire(options.esmOptions);
const esmRequire = esm(module, options.esmOptions);
try {
return esmRequire(modulePath);
} catch (error: any) {
throw new Error(`
Failed to import from:
${modulePath}.
Options:
${JSON.stringify(options)}
Require error message:
${error.stack}
Failed to import from:
${modulePath}.
Options:
${JSON.stringify(options)}
Require error message:
${error.stack}
`);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import importSync from './import';

export default importSync;
export type { Options, ESMOptions } from './types';
export type { Options, ESMOptions } from './options';

module.exports = importSync;
module.exports.default = importSync;
File renamed without changes.
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@
"skipLibCheck": true,
"target": "ES6"
},
"include": [
"src/**/*.ts"
]
"include": [ "src/**/*.ts" , "types/**/*.d.ts" ]
}
4 changes: 4 additions & 0 deletions types/httptoolkit-esm-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '@httptoolkit/esm' {
import Esm from 'esm';
export = Esm;
}
Loading