Skip to content

Commit

Permalink
Merge pull request #81 from nktnet1/2.2.1
Browse files Browse the repository at this point in the history
Refactor fix references to httptoolkit types
  • Loading branch information
nktnet1 committed Mar 13, 2024
2 parents 7f2c00d + d23be11 commit fab7eb1
Show file tree
Hide file tree
Showing 8 changed files with 617 additions and 777 deletions.
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;
}

0 comments on commit fab7eb1

Please sign in to comment.