Skip to content

Suggestion: Add support for a simple config file instead of requiring to switch from CLI to API usage #80

@kayahr

Description

@kayahr

Currently I use the CLI of importmap-node-module like this in package.json:

{
    "scripts": {
        "build:importmap" : "importmap-node-module lib/importmap.js"
    }
}

This usage is small and simple. Sometimes the importmap needs to include dev dependencies, so I simply add the --dev option. But sometimes a nasty dependency like axios comes along with incomplete export definitions, so I have to configure a manual package override. But the CLI doesn't support this, so I have to switch completely to the more complicated API usage:

create-importmap.js:

import { writeImportmaps } from "@jsenv/importmap-node-module";

await writeImportmaps({
    directoryUrl: new URL("./", import.meta.url),
    importmaps: {
        "lib/importmap.js": {
            nodeMappings: {
                devDependencies: true
            }
        }
    },
    packagesManualOverrides: {
        "axios": {
            exports: "./dist/esm/axios.js"
        }
    }
});

And when someday axios finally fixes this problem I would migrate back to the simpler CLI usage.

It would be nice if importmap-node-module would support an optional JSON config file where overrides could be configured without switching from CLI to API usage. It does not have to support EVERYTHING, keep it simple. CLI usage only allows ONE importmap, so it is sufficient when the config file also only contains additional configuration options for this single importmap generation. Example:

importmap.config.json:

{
    "manualImportmap": {
        "imports": {
            "#env": "./env.js",
        },
    },
    "packageManualOverrides": {
        "axios": {
            "exports": "./dist/esm/axios.js"
        }
    }
}

This would be much easier to use and understand in scenarious where only a single importmap is needed. For more complex scenarios, where more than one importmap needs to be generated, a switch to the API is still required of course.

An alternative to reading the config from a JSON file would be reading the config from a custom package.json property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions