|
| 1 | +# Table of contents |
| 2 | + |
| 3 | +- [generateImportMapForProject](#generateImportMapForProject) |
| 4 | + - [importMapFile](#importMapFile) |
| 5 | + - [importMapFileRelativeUrl](#importMapFileRelativeUrl) |
| 6 | + - [importMapFileLog](#importMapFileLog) |
| 7 | +- [getImportMapFromFile](#getImportMapFromFile) |
| 8 | + - [importMapFileUrl](#importMapFileUrl) |
| 9 | + |
| 10 | +# generateImportMapForProject |
| 11 | + |
| 12 | +`generateImportMapForProject` is an async function receiving an array of promise resolving to importmaps. It awaits for every importmap, compose them into one and write it into a file. |
| 13 | + |
| 14 | +> This function is meant to be responsible of generating the final importMap file that a project uses. |
| 15 | +
|
| 16 | +For example code below will generate an import map from node_modules + a file + an inline importmap. |
| 17 | + |
| 18 | +```js |
| 19 | +import { |
| 20 | + getImportMapFromNodeModules, |
| 21 | + getImportMapFromFile, |
| 22 | + generateImportMapForProject, |
| 23 | +} from "@jsenv/node-module-import-map" |
| 24 | + |
| 25 | +const projectDirectoryUrl = new URL("./", import.meta.url) |
| 26 | +const customImportMapFileUrl = new URL("./import-map-custom.importmap", projectDirectoryUrl) |
| 27 | + |
| 28 | +await generateImportMapForProject( |
| 29 | + [ |
| 30 | + getImportMapFromNodeModules({ |
| 31 | + projectDirectoryUrl, |
| 32 | + projectPackageDevDependenciesIncluded: true, |
| 33 | + }), |
| 34 | + getImportMapFromFile(customImportMapFileUrl), |
| 35 | + { |
| 36 | + imports: { |
| 37 | + foo: "./bar.js", |
| 38 | + }, |
| 39 | + }, |
| 40 | + ], |
| 41 | + { |
| 42 | + projectDirectoryUrl, |
| 43 | + importMapFileRelativeUrl: "./import-map.importmap", |
| 44 | + }, |
| 45 | +) |
| 46 | +``` |
| 47 | +
|
| 48 | +— source code at [src/generateImportMapForProject.js](../src/generateImportMapForProject.js). |
| 49 | +
|
| 50 | +## importMapFile |
| 51 | +
|
| 52 | +`importMapFile` parameter is a boolean controling if importMap is written to a file. This parameters is optional and enabled by default. |
| 53 | +
|
| 54 | +## importMapFileRelativeUrl |
| 55 | +
|
| 56 | +`importMapFileRelativeUrl` parameter is a string controlling where importMap file is written. This parameter is optional and by default it's `"./import-map.importmap"`. |
| 57 | +
|
| 58 | +## importMapFileLog |
| 59 | +
|
| 60 | +`importMapFileLog` parameter a boolean controlling if there is log in the terminal when importMap file is written. This parameter is optional and by default it's enabled. |
| 61 | +
|
| 62 | +# getImportMapFromFile |
| 63 | +
|
| 64 | +`getImportMapFromFile` is an async function reading importmap from a file. |
| 65 | +
|
| 66 | +```js |
| 67 | +import { getImportMapFromFile } from "@jsenv/node-module-import-map" |
| 68 | + |
| 69 | +const importMapFileUrl = new URL("./import-map.importmap", import.meta.url) |
| 70 | +const importMap = await getImportMapFromFile(importMapFileUrl) |
| 71 | +``` |
| 72 | +
|
| 73 | +— source code at [src/getImportMapFromFile.js](../src/getImportMapFromFile.js). |
| 74 | +
|
| 75 | +## importMapFileUrl |
| 76 | +
|
| 77 | +`importMapFileUrl` parameter a string or an url leading to the importmap file. This parameter is **required**. |
0 commit comments