You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

create-esm-loader

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-esm-loader - npm Package Compare versions

Comparing version

to
0.1.2

17

lib/create-loader.js

@@ -63,3 +63,3 @@ // # create-loader.js

const hook = id => (...args) => this.handleStack(id, ...args);
const resolve = hook('resolve');
const resolve = shortCircuit(hook('resolve'));
const getFormat = hook('format');

@@ -113,3 +113,3 @@ const getSource = hook('fetch');

// `load()` function has to be composed manually!
const load = async function(url, ctx, defaultLoad) {
const load = shortCircuit(async function(url, ctx, defaultLoad) {

@@ -148,3 +148,3 @@ // If the format was already specified by the resolve hook, we

};
});
return { resolve, load };

@@ -233,2 +233,13 @@

// See #4. In Node 18.6 we now need to specify explicitly that we're
// short-circuiting, which is what this function does.
function shortCircuit(fn) {
return async function(...args) {
return {
shortCircuit: true,
...await fn(...args),
};
}
}
// # normalize(loader)

@@ -235,0 +246,0 @@ // Properly normalizes a loader definition.

2

package.json
{
"name": "create-esm-loader",
"version": "0.1.1",
"version": "0.1.2",
"description": "A utility library for creating Node loader hooks",

@@ -5,0 +5,0 @@ "type": "module",

@@ -239,2 +239,5 @@ # create-esm-loader

```js
import createLoader from 'create-esm-loader'
import ts from 'typescript'
const tsLoader = {

@@ -254,9 +257,11 @@ resolve(specifier, opts) {

transform(source, opts) {
return {
source: ts.transpileModule(String(source), {
const { url } = opts
if (url.endsWith('.ts')) {
const { outputText } = ts.transpileModule(String(source), {
compilerOptions: {
module: ts.ModuleKind.ES2020,
},
}),
};
})
return { source: outputText };
}
},

@@ -292,1 +297,9 @@ };

```
### 3. Loaders in the Wild
You can find an active [list of loaders][loaderlist] that use
`create-esm-loader`, here:
[loaderlist]: https://www.npmjs.com/package/create-esm-loader?activeTab=dependents