importmapify 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -17
- package/deno.json +1 -1
- package/dist/mod.d.mts +6 -4
- package/dist/mod.mjs +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ npx importmapify --root . --out import_map.json
|
|
|
43
43
|
| `--no-config` | | Skip config file discovery | off |
|
|
44
44
|
| `--check` | | Exit 1 if the output file is stale, without writing it | off |
|
|
45
45
|
| `--stdout` | | Print the map instead of writing it | off |
|
|
46
|
+
| `--quiet` | `-q` | Suppress the `Wrote <path>` confirmation (written to stderr) | off |
|
|
46
47
|
|
|
47
48
|
Add global and test-scoped dependencies from the CLI:
|
|
48
49
|
|
|
@@ -61,9 +62,21 @@ order (first match wins): `importmapify.config.{mjs,cjs,js,ts,mts,cts}`, then `.
|
|
|
61
62
|
|
|
62
63
|
```js
|
|
63
64
|
// importmapify.config.mjs
|
|
65
|
+
import { defineConfig } from 'importmapify';
|
|
66
|
+
|
|
67
|
+
export default defineConfig({
|
|
68
|
+
packages: { dreamcli: 'jsr:@kjanat/dreamcli@^3' },
|
|
69
|
+
extensions: ['ts'],
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or annotate a plain object, no import:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
/** @type {import('importmapify').Config} */
|
|
64
77
|
export default {
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
packages: { dreamcli: 'jsr:@kjanat/dreamcli@^3' },
|
|
79
|
+
extensions: ['ts'],
|
|
67
80
|
};
|
|
68
81
|
```
|
|
69
82
|
|
|
@@ -72,9 +85,8 @@ Then `npx importmapify` reads it automatically. Point at a specific file with `-
|
|
|
72
85
|
|
|
73
86
|
Explicitly-passed flags override the config, which overrides built-in defaults: `--import`/`--package`/`--scope` merge
|
|
74
87
|
onto the config's records with flag keys winning; `--condition`/`--ext` replace; `--root`/`--manifest`/`--out` win when
|
|
75
|
-
passed. Configs are imported natively; a TypeScript config needs a runtime
|
|
76
|
-
|
|
77
|
-
> = 22.6), so on older Node use a `.mjs`/`.cjs`/`.js` config.
|
|
88
|
+
passed. Configs are imported natively; a TypeScript config needs a type-stripping runtime (Bun, Deno, or Node \>= 22.6);
|
|
89
|
+
on older Node use a `.mjs`/`.cjs`/`.js` config.
|
|
78
90
|
|
|
79
91
|
## Library
|
|
80
92
|
|
|
@@ -95,13 +107,13 @@ const out = writeImportMap({
|
|
|
95
107
|
});
|
|
96
108
|
```
|
|
97
109
|
|
|
98
|
-
| Export | Signature
|
|
99
|
-
| ----------------- |
|
|
100
|
-
| `defineConfig` | `(
|
|
101
|
-
| `createImportMap` | `(options: CreateImportMapOptions) => ImportMapDocument`
|
|
102
|
-
| `formatImportMap` | `(map: ImportMapDocument) => string`
|
|
103
|
-
| `writeImportMap` | `(options: WriteImportMapOptions) => string`
|
|
104
|
-
| `packageEntries` | `(name: string, target: string) => Record<string, string>`
|
|
110
|
+
| Export | Signature | Purpose |
|
|
111
|
+
| ----------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
112
|
+
| `defineConfig` | `(config: Config) => Config` | Identity helper that types a config object for export and reuse. |
|
|
113
|
+
| `createImportMap` | `(options: CreateImportMapOptions) => ImportMapDocument` | Build the import map in memory. |
|
|
114
|
+
| `formatImportMap` | `(map: ImportMapDocument) => string` | Serialize to the canonical sorted, tab-indented JSON text. |
|
|
115
|
+
| `writeImportMap` | `(options: WriteImportMapOptions) => string` | Build, serialize, and write to disk; returns the written path. |
|
|
116
|
+
| `packageEntries` | `(name: string, target: string) => Record<string, string>` | Build the bare and trailing-slash entry pair a package needs to resolve its subpaths. |
|
|
105
117
|
|
|
106
118
|
`CreateImportMapOptions`:
|
|
107
119
|
|
|
@@ -121,6 +133,8 @@ resolved against `root` and accepts a relative path, an absolute path, or a `fil
|
|
|
121
133
|
automatically against `out`'s directory, so a nested `out` (for example `.cache/maps/import_map.json`) still produces
|
|
122
134
|
targets that resolve correctly from the map's own location.
|
|
123
135
|
|
|
136
|
+
`Config` is an alias for `WriteImportMapOptions` — the shape a config file's default export and `defineConfig` take.
|
|
137
|
+
|
|
124
138
|
`defineConfig` returns its argument unchanged; it exists only to type a config object for export and reuse without a
|
|
125
139
|
manual annotation.
|
|
126
140
|
|
|
@@ -398,11 +412,10 @@ import { writeImportMap } from 'importmapify';
|
|
|
398
412
|
const root = '/path/to/source-tree';
|
|
399
413
|
const importMap = writeImportMap({ root, out: 'import_map.json' });
|
|
400
414
|
|
|
401
|
-
const documentation = execFileSync(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
);
|
|
415
|
+
const documentation = execFileSync('deno', ['doc', '--import-map', importMap, '--json', 'src/index.ts'], {
|
|
416
|
+
cwd: root,
|
|
417
|
+
encoding: 'utf8',
|
|
418
|
+
});
|
|
406
419
|
```
|
|
407
420
|
|
|
408
421
|
### `@deno/doc`
|
package/deno.json
CHANGED
package/dist/mod.d.mts
CHANGED
|
@@ -33,6 +33,8 @@ interface WriteImportMapOptions extends CreateImportMapOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
readonly out?: string | URL;
|
|
35
35
|
}
|
|
36
|
+
/** An importmapify config: the shape a config file's default export and {@linkcode defineConfig} take. */
|
|
37
|
+
type Config = WriteImportMapOptions;
|
|
36
38
|
/**
|
|
37
39
|
* Expand a package's exact and patterned `imports` into a Deno import map.
|
|
38
40
|
*
|
|
@@ -129,9 +131,9 @@ declare function packageEntries(name: string, target: string): Record<string, st
|
|
|
129
131
|
* writeImportMap(config);
|
|
130
132
|
* ```
|
|
131
133
|
*
|
|
132
|
-
* @param
|
|
133
|
-
* @returns The same `
|
|
134
|
+
* @param config Import map configuration, with an optional `out`.
|
|
135
|
+
* @returns The same `config` value, typed as {@link Config}.
|
|
134
136
|
*/
|
|
135
|
-
declare function defineConfig(
|
|
137
|
+
declare function defineConfig(config: Config): Config;
|
|
136
138
|
//#endregion
|
|
137
|
-
export { type CreateImportMapOptions, type ImportMapDocument, type WriteImportMapOptions, createImportMap, defineConfig, formatImportMap, packageEntries, writeImportMap };
|
|
139
|
+
export { type Config, type CreateImportMapOptions, type ImportMapDocument, type WriteImportMapOptions, createImportMap, defineConfig, formatImportMap, packageEntries, writeImportMap };
|
package/dist/mod.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { bold, cyan, detectHyperlinkSupport } from "ansispeck";
|
|
|
3
3
|
import { CLIError, cli, command, flag } from "dreamcli";
|
|
4
4
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import path, { dirname } from "node:path";
|
|
6
|
-
import { cwd } from "node:process";
|
|
6
|
+
import { argv, cwd } from "node:process";
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
8
|
//#region src/expand.ts
|
|
9
9
|
function escapeRegExp(value) {
|
|
@@ -471,16 +471,18 @@ function packageEntries(name, target) {
|
|
|
471
471
|
* writeImportMap(config);
|
|
472
472
|
* ```
|
|
473
473
|
*
|
|
474
|
-
* @param
|
|
475
|
-
* @returns The same `
|
|
474
|
+
* @param config Import map configuration, with an optional `out`.
|
|
475
|
+
* @returns The same `config` value, typed as {@link Config}.
|
|
476
476
|
*/
|
|
477
|
-
function defineConfig(
|
|
478
|
-
return
|
|
477
|
+
function defineConfig(config) {
|
|
478
|
+
return config;
|
|
479
479
|
}
|
|
480
480
|
//#endregion
|
|
481
481
|
//#region src/cli.ts
|
|
482
482
|
const EXAMPLE_TOKEN = /(?:'[^']*'|"[^"]*"|\S)+/g;
|
|
483
|
+
const JSON_MODE = argv.includes("--json");
|
|
483
484
|
function highlightExample(example) {
|
|
485
|
+
if (JSON_MODE) return example;
|
|
484
486
|
const tokens = example.match(EXAMPLE_TOKEN);
|
|
485
487
|
if (tokens === null) return example;
|
|
486
488
|
return tokens.map((token, index) => index === 0 ? bold(token) : token.startsWith("-") ? cyan(token) : token).join(" ");
|