Skip to content

Releases: jespertheend/fake-imports

v0.10.0

18 Nov 14:59
Compare
Choose a tag to compare

This release makes some improvement in the way modules were marked as real.
In the past, it was not possible to both fake/redirect a module and mark it as real.
Usually this is not an issue, but in some rare cases you might want to make a faked module import itself.
In that case it can be useful to mark the self imported module as real.

BREAKING: The useUnresolved option is now called exactMatch to make it describe more clearly what it does.
The behavior was also adjusted slightly: When the option was used in the past, it used to also match paths relative to the import.meta.url of the Importer. This is now no longer the case, and when exactMatch is used it truly only matches that exact specifier.

v0.9.2

11 Nov 11:52
Compare
Choose a tag to compare

Update readme

v0.9.1

10 Nov 22:07
Compare
Choose a tag to compare
  • Allow redirected modules to import themselves (#25)
  • Published an npm package (#26)

v0.8.1

15 Mar 22:26
Compare
Choose a tag to compare
v0.8.1 Pre-release
Pre-release
chore: Use jsdelivr instead of unpkg

v0.8.0

05 Feb 14:16
Compare
Choose a tag to compare
v0.8.0 Pre-release
Pre-release

This release improves the error message for circular imports. It now shows the paths relative to your provided import.meta.url so that you can easily copy them to makeReal or fakeModule.

v0.7.0

29 Jan 22:52
4ef36d6
Compare
Choose a tag to compare
v0.7.0 Pre-release
Pre-release
Include pre-releases in readme badge

v0.6.1

24 Sep 23:16
Compare
Choose a tag to compare
v0.6.1 Pre-release
Pre-release

This release includes the following:

  • Show full import chain for circular imports (#23)
    Due to how object urls work, circular imports are unfortunately not supported. So when importing a module containing a circular import chain, an error is thrown.
    Before this update it was difficult to figure out what file needed to be excluded in order to resolve the circular import.
    This update shows the import chain in the error message, making this much easier.
error: (in promise) Error: Circular imports are not supported:
main.js -> circular1.js -> circular2.js -> circular3.js -> circular1.js
  • Don't fail resolving imports when invalid specifiers are made real 715e1a5
    Previously, when making an invalid specifier real using importer.makeReal("./Foo.js") an error would be thrown when importing something, even when it was completely unrelated to the invalid specifier provided earlier. And since import map entries are made real by default, this would cause all imports to fail if your import map contained an invalid entry.

v0.6.0

01 May 22:42
Compare
Choose a tag to compare
v0.6.0 Pre-release
Pre-release

Excluding imports from faking (#15)

Mark specific modules as real to prevent them from being imported as blob urls which could potentially be slow:

const importer = new Importer(import.meta.url);
importer.makeReal("./Foo.js");

More info about this in the readme.

BREAKING: Setting import maps is now a constructor option (#18)

Setting import maps is no longer done via importer.setImportMap() but is now a constructor option:

const importer = new Importer(import.meta.url, {
  importMap: "./path/to/importMap.json",
});

BREAKING: Automatically mark import map entries as real (#19)

All entries from import maps are automatically marked as real. To prevent this, set makeImportMapEntriesReal to false.

const importer = new Importer(import.meta.url, {
  importMap: "./path/to/importMap.json",
  makeImportMapEntriesReal: false,
});

v0.5.0

30 Apr 21:38
Compare
Choose a tag to compare
v0.5.0 Pre-release
Pre-release

Support for import maps (#2)

You can now set an import map using importer.setImportMap():

const importer1 = new Importer(import.meta.url);
importer1.setImportMap("../import-map.json"); // import relatively to the current file

const importer2 = new Importer(import.meta.url);
importer2.setImportMap("https://example.com/import-map.json"); // import from a remote location

const importer3 = new Importer(import.meta.url);
importer3.setImportMap({
 "imports": {
   "./foo.js": "https://example.com/foo.js",
   "./bar.js": "https://example.com/bar.js",
 },
});

Similar to how this works in browsers, you can only set an import map once and only before importing anything.

Support for TypeScript imports (#14)

Previously the created blob urls would always get the text/javascript mime type, causing Deno to use the JavaScript parser on every file, even if the file was a TypeScript file. This update takes the content-type header from any remote files, or looks at the file extension and sets the correct mime type for created blob urls.

Better stack traces during import errors (#9)

If an error occurs during the importer.import() call, any blob urls in the message or stack trace are now replaced with the original file paths. Making it easier to debug any import issues.

BREAKING: Don't allow root imports without prefixed / ./ or ../ (#12)

This makes the behaviour more in line with what browsers and Deno are already doing.
This update also removes support for passing in URL objects to the import() method. If you want to pass in urls, serialize them first using URL.href, i.e.:

const url = new URL("https://example.com");
importer.import(url.href);

Other

  • Show the importer path when a network error occurs (#8)
  • Support export from syntax (#10)

v0.4.0

30 Mar 20:57
Compare
Choose a tag to compare
v0.4.0 Pre-release
Pre-release

BREAKING: Faster coverage map generation

Coverage map generation performance has been improved significantly for larger files (1k+ lines).
The tradeoff was made to make coverage maps less acurate, by using a diff algorithm that only groups per line, rather than per character.

BREAKING: Remove finishCoverageMapWrites()

finishCoverageMapWrites() was supposed to prevent Deno tests from failing because of pending promises, but in reality the opposite was true. When importing a module before a test was started, the promises that would write coverage maps to disk had a chance to resolve during tests, causing Deno sanitizers to complain.

Generally you would want to wait for the coverage maps to be written to disk right after you import a module, so this is now done automatically.
This means it might take a little longer for dynamic import promises to resolve, but if you don't have coverage map generation enabled this does not affect performance.