Skip to content

UpperCod/devserver-replace-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@devserver/replace-import

utilities for the replacement of imports in js files.

Example

@devserver/replace-import

import { readFile } from "fs/promise";
import { replaceImport } from "@devserver/replace-import";

readFile("my.js", "utf8").then((code) => {
    replaceImport({
        code,
        /**
         * Resolve allows you to solve the import in a
         * personalized way, being useful to point to
         * a CDN or a local resource
         * @param {string} module  - Name of the module imported by the JS code
         * @return {string|Promise<string>}
         */
        async resolve(module) {
            return module;
        },
    });
});

@devserver/replace-import/export-map

It allows to solve a pkg from NPM based on the export format of NodeJs#packages_self_referencing_a_package_using_its_name.

import { exportMap } from "@devserver/replace-import/export-map";

const folders = {
    ".": "./core.js",
    "./html": "./html.js",
    "./utils/*": "./u/*.js",
};

exportMap(folders, ""); //"./core.js"

@devserver/replace-import/resolve

It allows to solve the NPM modules through the reading of NPM packages

import { resolve } from "@devserver/replace-import/resolve";

(await resolve("atomico")).href; // file://...node_modules/atomico/core.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published