import-sync
Advanced tools
Comparing version 0.0.3 to 1.0.2
@@ -38,3 +38,3 @@ "use strict"; | ||
const filePath = path_1.default.join(opts.basePath, relativePath); | ||
const es6Require = createEs6Require(options.esmOptions); | ||
const es6Require = createEs6Require(opts.esmOptions); | ||
try { | ||
@@ -41,0 +41,0 @@ return es6Require(filePath); |
@@ -33,3 +33,3 @@ import path from 'path'; | ||
const filePath = path.join(opts.basePath, relativePath); | ||
const es6Require = createEs6Require(options.esmOptions); | ||
const es6Require = createEs6Require(opts.esmOptions); | ||
try { | ||
@@ -36,0 +36,0 @@ return es6Require(filePath); |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.3", | ||
"version": "1.0.2", | ||
"files": [ | ||
@@ -49,4 +49,4 @@ "dist" | ||
"@types/node": "^20.8.6", | ||
"@typescript-eslint/eslint-plugin": "^6.7.5", | ||
"@typescript-eslint/parser": "^6.7.5", | ||
"@typescript-eslint/eslint-plugin": "^6.8.0", | ||
"@typescript-eslint/parser": "^6.8.0", | ||
"eslint": "^8.51.0", | ||
@@ -53,0 +53,0 @@ "eslint-plugin-jest": "^27.4.2", |
@@ -7,8 +7,8 @@ <div align="center"> | ||
| ||
<!-- [![codecov](https://codecov.io/gh/nktnet1/import-sync/branch/main/graph/badge.svg?token=RAC7SKJTGU)](https://codecov.io/gh/nktnet1/import-sync) | ||
[![codecov](https://codecov.io/gh/nktnet1/import-sync/branch/main/graph/badge.svg?token=RAC7SKJTGU)](https://codecov.io/gh/nktnet1/import-sync) | ||
| ||
[![Maintainability](https://api.codeclimate.com/v1/badges/2cc2478a1b5a2f293149/maintainability)](https://codeclimate.com/github/nktnet1/import-sync/maintainability) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/aaae5cf33d58299ed722/maintainability)](https://codeclimate.com/github/nktnet1/import-sync/maintainability) | ||
| ||
[![Snyk Security](https://snyk.io/test/github/nktnet1/import-sync/badge.svg)](https://snyk.io/test/github/nktnet1/import-sync) | ||
--> | ||
| ||
[![GitHub top language](https://img.shields.io/github/languages/top/nktnet1/import-sync)](https://github.com/search?q=repo%3Anktnet1%2Fimport-sync++language%3ATypeScript&type=code) | ||
@@ -28,10 +28,10 @@ | ||
<!-- [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nktnet1_import-sync&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=nktnet1_import-sync) | ||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nktnet1_import-sync&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=nktnet1_import-sync) | ||
| ||
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/65161ae4d1c646ed83c9ef47b0a11473)](https://app.codacy.com/gh/nktnet1/import-sync/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) | ||
| ||
[![DeepSource](https://app.deepsource.com/gh/nktnet1/import-sync.svg/?label=active+issues&show_trend=true&token=OTP6tE2be4X1kvxZRsxRh25e)](https://app.deepsource.com/gh/nktnet1/import-sync/) | ||
[![DeepSource](https://app.deepsource.com/gh/nktnet1/import-sync.svg/?label=active+issues&show_trend=true&token=r1frerF1-N2Mhrc7ZXIC1uNa)](https://app.deepsource.com/gh/nktnet1/import-sync/) | ||
| ||
[![codebeat badge](https://codebeat.co/badges/8bdb4562-0492-4c1c-8b02-e69c94373d60)](https://codebeat.co/projects/github-com-nktnet1-import-sync-main) | ||
--> | ||
[![codebeat badge](https://codebeat.co/badges/acc44573-9938-4a14-bc41-7eb6a58dffbb)](https://codebeat.co/projects/github-com-nktnet1-import-sync-main) | ||
| ||
[![GitHub stars](https://img.shields.io/github/stars/nktnet1/import-sync.svg?style=social)](https://github.com/nktnet1/import-sync/stargazers) | ||
@@ -108,3 +108,3 @@ | ||
const { someFunction } = importSync( | ||
'someModule.mjs', | ||
'someModule', | ||
{ basePath: process.cwd() } | ||
@@ -118,4 +118,12 @@ ); | ||
const { someFunction } = importSync( | ||
'someModule.mjs', | ||
{ basePath: process.cwd() } | ||
'someModule', | ||
{ | ||
esmOptions: { | ||
cjs: { | ||
cache: true | ||
}, | ||
mode: 'all', | ||
force: 'true', | ||
} | ||
} | ||
); | ||
@@ -131,6 +139,6 @@ ``` | ||
Path to the module relative to the current file, similar to CommonJS [require](https://nodejs.org/api/modules.html#requireid). For example, | ||
- `'../animals/cats.js'` | ||
- `'./dogs.mjs'` | ||
- `'minimal'` | ||
- import-sync will look for `'./minimal.js'` before `'minimal.mjs'`, then throws an Error if neither files exist. | ||
- `'../animals/cats.js'` | ||
- `'./dogs.mjs'` | ||
- `'minimal'` | ||
- `importSync` will look for `'./minimal.js'` before `'./minimal.mjs'` | ||
@@ -177,4 +185,9 @@ Note that `option.basePath` can be provided to alter this behaviour. | ||
The `importSync` function returns the exported module content similar to NodeJS [require](https://nodejs.org/api/modules.html#requireid). | ||
The `importSync` function returns the exported module content similar to NodeJS | ||
[require](https://nodejs.org/api/modules.html#requireid). | ||
If an unknown file path is provided a default | ||
[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error) | ||
object is thrown. | ||
## 3. License | ||
@@ -222,3 +235,3 @@ | ||
There are currently no plans to fix this issue, as the built-in NodeJS | ||
[require](https://nodejs.org/api/modules.html#requireid) function should be used | ||
[require](https://nodejs.org/api/modules.html#requireid) function should simply be used | ||
instead when importing CommonJS modules. | ||
@@ -239,3 +252,3 @@ | ||
Initially, the [esm](https://github.com/standard-things/esm) library looked promising. However, when the global dryrun script was executed in a mock student's project directory, the following error occured: | ||
Initially, the [esm](https://github.com/standard-things/esm) library looked promising. However, when the global dryrun script was executed in a mock student's project directory, the following error occurred: | ||
@@ -258,3 +271,3 @@ > Error [ERR_REQUIRE_ESM]: require() of ES Module /import/ravel/5/z5313515/project-backend/src/auth.js not supported.<br/> | ||
- this library utilises [deasync](https://github.com/abbr/deasync), which when used in NodeJS for Jest tests, could hang indefinitely as seen in Jest's issue [#9729](https://github.com/jestjs/jest/issues/9729) | ||
- since COMP1531 uses Jest as the sole testing framework, [deasync](https://github.com/abbr/deasync) could not be used as a dependency | ||
- since COMP1531 uses Jest as the sole testing framework, [deasync](https://github.com/abbr/deasync) was ruled out | ||
4. Other async-to-sync conversions for dynamic [import()](https://nodejs.org/api/esm.html#import-expressions) | ||
@@ -278,2 +291,2 @@ - [synckit](https://github.com/un-ts/synckit): worker_threads, Jest and external imports did not work (unclear reason) | ||
which removes the exception through module extension and serves as a satisfactory workaround. | ||
which removes the exception through module extension and serves as a satisfactory workaround. This reduced the codebase of **import-sync** to simply a wrapper around [esm](https://www.youtube.com/watch?v=jQS-nEFxJeU). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26593
1
282