@wolfstar/http-framework 6.1.0-next-20261002193904 → 6.1.0
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/LICENSE +201 -201
- package/README.md +686 -686
- package/bin/stars.mjs +2 -2
- package/config.d.ts +1 -1
- package/config.js +1 -1
- package/dist/esm/auto-imports.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/schema.d.ts +1 -1
- package/schema.js +1 -1
package/bin/stars.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import '@wolfstar/cli/cli';
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '@wolfstar/cli/cli';
|
package/config.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '@wolfstar/schema';
|
|
1
|
+
export * from '@wolfstar/schema';
|
package/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '@wolfstar/schema';
|
|
1
|
+
export * from '@wolfstar/schema';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-imports.js","names":[],"sources":["../../src/auto-imports.ts"],"sourcesContent":["/**\n * Nuxt-style auto imports for `@wolfstar/http-framework` projects.\n *\n * Wires `unimport` into `tsdown`'s rolldown pipeline: the framework's (and any configured preset's) exports, plus\n * the project's own {@link AutoImportsPluginOptions.dirs}, become usable without an explicit `import` statement, the\n * same way Nuxt's own exports and its `composables`/`utils` directories do. Only usable with the `tsdown` build\n * tool — `tsc` and `none` have no transform step to hook the injection into.\n *\n * @module @wolfstar/http-framework/auto-imports\n */\nimport { resolveModuleExportNames } from 'mlly';\nimport { mkdirSync } from 'node:fs';\nimport { dirname } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { createUnimport, type Import } from 'unimport';\nimport unplugin from 'unimport/unplugin';\nimport type { ResolvedImportsConfig } from '@wolfstar/schema';\n\n/**\n * Export names never auto-imported, even when a preset re-exports them under that name: names generic enough that\n * project code is likely to declare or import its own value with the same identifier.\n *\n * `setup` is `@wolfstar/env-utilities`' env loader, which scaffolded projects import explicitly (as `envRun`) from\n * their own `src/lib/setup/all.ts` — a file that exports a `setup()` of its own, which the default `src/lib/**` dir\n * would otherwise auto-import alongside it and have `unimport` warn about the duplicate on every build.\n */\nconst BLOCKED_EXPORTS: ReadonlySet<string> = new Set(['Client', 'Message', 'Plugin', 'Store', 'setup']);\n\n/**\n * Nuxt matches its own auto-import transform against every JS/TS file variant (`.js .mjs .cjs .ts .mts .cts .jsx\n * .tsx`, see `isJS` in `@nuxt/kit`), not `unimport`'s narrower unplugin default (`/\\.[jt]sx?$/`, which misses\n * `.mjs`/`.cjs`/`.mts`/`.cts`): whether a file gets auto imports must not depend on whether the project happens to\n * use TypeScript.\n */\nconst TRANSFORM_INCLUDE = [/\\.(?:[cm]?[jt]s|[jt]sx)$/];\n\nexport interface AutoImportsPluginOptions extends Pick<ResolvedImportsConfig, 'dirs' | 'presets' | 'exclude' | 'dts'> {\n\t/** Absolute project root, used to resolve `presets` against the project's own `node_modules`. */\n\troot: string;\n}\n\n/**\n * Scans every configured preset package for its export names, from the project's own `node_modules` so the result\n * matches what the project actually has installed. Packages that fail to resolve (not installed, or a preset the\n * user configured for a plugin they do not use) are skipped rather than failing the build.\n */\nasync function scanPresetImports(root: string, presets: readonly string[], excluded: ReadonlySet<string>): Promise<Import[]> {\n\tconst url = pathToFileURL(`${root}/package.json`).href;\n\tconst imports: Import[] = [];\n\n\tawait Promise.all(\n\t\tpresets.map(async (from) => {\n\t\t\tlet names: string[];\n\t\t\ttry {\n\t\t\t\tnames = await resolveModuleExportNames(from, { url });\n\t\t\t} catch {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfor (const name of names) {\n\t\t\t\tif (excluded.has(name)) continue;\n\t\t\t\timports.push({ name, from });\n\t\t\t}\n\t\t})\n\t);\n\n\treturn imports;\n}\n\n/**\n * Builds the rolldown plugin `tsdown.config.ts` adds to `plugins` to enable auto imports, as resolved from\n * {@link StarsImportsConfig} (see `@wolfstar/http-framework/config`).\n */\nexport async function autoImports(options: AutoImportsPluginOptions): Promise<ReturnType<typeof unplugin.rolldown>> {\n\tconst excluded = new Set([...BLOCKED_EXPORTS, ...options.exclude]);\n\tconst imports = await scanPresetImports(options.root, options.presets, excluded);\n\n\t// `unimport`'s unplugin writes `dts` on `buildStart` but does not create its parent directory.\n\tmkdirSync(dirname(options.dts), { recursive: true });\n\n\treturn unplugin.rolldown({\n\t\timports,\n\t\tdirs: [...options.dirs],\n\t\tinclude: TRANSFORM_INCLUDE,\n\t\tdts: options.dts\n\t});\n}\n\n/**\n * Generates the auto imports declaration file's contents without writing it, so `stars prepare --check` can diff it\n * against what is on disk the same way `stars codegen --check` does for i18next types.\n */\nexport async function generateAutoImportsDts(options: Pick<AutoImportsPluginOptions, 'root' | 'dirs' | 'presets' | 'exclude'>): Promise<string> {\n\tconst excluded = new Set([...BLOCKED_EXPORTS, ...options.exclude]);\n\tconst imports = await scanPresetImports(options.root, options.presets, excluded);\n\tconst ctx = createUnimport({ imports, dirs: [...options.dirs] });\n\tawait ctx.init();\n\treturn ctx.generateTypeDeclarations();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,kCAAuC,IAAI,IAAI;CAAC;CAAU;CAAW;CAAU;CAAS;AAAO,CAAC;;;;;;;AAQtG,MAAM,oBAAoB,CAAC,0BAA0B;;;;;;AAYrD,eAAe,kBAAkB,MAAc,SAA4B,UAAkD;CAC5H,MAAM,MAAM,cAAc,GAAG,KAAK,cAAc,CAAC,CAAC;CAClD,MAAM,UAAoB,CAAC;CAE3B,MAAM,QAAQ,IACb,QAAQ,IAAI,OAAO,SAAS;EAC3B,IAAI;EACJ,IAAI;GACH,QAAQ,MAAM,yBAAyB,MAAM,EAAE,IAAI,CAAC;EACrD,QAAQ;GACP;EACD;EAEA,KAAK,MAAM,QAAQ,OAAO;GACzB,IAAI,SAAS,IAAI,IAAI,GAAG;GACxB,QAAQ,KAAK;IAAE;IAAM;GAAK,CAAC;EAC5B;CACD,CAAC,CACF;CAEA,OAAO;AACR;;;;;AAMA,eAAsB,YAAY,SAAkF;CACnH,MAAM,2BAAW,IAAI,IAAI,CAAC,GAAG,iBAAiB,GAAG,QAAQ,OAAO,CAAC;CACjE,MAAM,UAAU,MAAM,kBAAkB,QAAQ,MAAM,QAAQ,SAAS,QAAQ;CAG/E,UAAU,QAAQ,QAAQ,GAAG,GAAG,EAAE,WAAW,KAAK,CAAC;CAEnD,OAAO,SAAS,SAAS;EACxB;EACA,MAAM,CAAC,GAAG,QAAQ,IAAI;EACtB,SAAS;EACT,KAAK,QAAQ;CACd,CAAC;AACF;;;;;AAMA,eAAsB,uBAAuB,SAAmG;CAC/I,MAAM,2BAAW,IAAI,IAAI,CAAC,GAAG,iBAAiB,GAAG,QAAQ,OAAO,CAAC;CACjE,MAAM,UAAU,MAAM,kBAAkB,QAAQ,MAAM,QAAQ,SAAS,QAAQ;CAC/E,MAAM,MAAM,eAAe;EAAE;EAAS,MAAM,CAAC,GAAG,QAAQ,IAAI;CAAE,CAAC;CAC/D,MAAM,IAAI,KAAK;CACf,OAAO,IAAI,yBAAyB;AACrC"}
|
|
1
|
+
{"version":3,"file":"auto-imports.js","names":[],"sources":["../../src/auto-imports.ts"],"sourcesContent":["/**\r\n * Nuxt-style auto imports for `@wolfstar/http-framework` projects.\r\n *\r\n * Wires `unimport` into `tsdown`'s rolldown pipeline: the framework's (and any configured preset's) exports, plus\r\n * the project's own {@link AutoImportsPluginOptions.dirs}, become usable without an explicit `import` statement, the\r\n * same way Nuxt's own exports and its `composables`/`utils` directories do. Only usable with the `tsdown` build\r\n * tool — `tsc` and `none` have no transform step to hook the injection into.\r\n *\r\n * @module @wolfstar/http-framework/auto-imports\r\n */\r\nimport { resolveModuleExportNames } from 'mlly';\r\nimport { mkdirSync } from 'node:fs';\r\nimport { dirname } from 'node:path';\r\nimport { pathToFileURL } from 'node:url';\r\nimport { createUnimport, type Import } from 'unimport';\r\nimport unplugin from 'unimport/unplugin';\r\nimport type { ResolvedImportsConfig } from '@wolfstar/schema';\r\n\r\n/**\r\n * Export names never auto-imported, even when a preset re-exports them under that name: names generic enough that\r\n * project code is likely to declare or import its own value with the same identifier.\r\n *\r\n * `setup` is `@wolfstar/env-utilities`' env loader, which scaffolded projects import explicitly (as `envRun`) from\r\n * their own `src/lib/setup/all.ts` — a file that exports a `setup()` of its own, which the default `src/lib/**` dir\r\n * would otherwise auto-import alongside it and have `unimport` warn about the duplicate on every build.\r\n */\r\nconst BLOCKED_EXPORTS: ReadonlySet<string> = new Set(['Client', 'Message', 'Plugin', 'Store', 'setup']);\r\n\r\n/**\r\n * Nuxt matches its own auto-import transform against every JS/TS file variant (`.js .mjs .cjs .ts .mts .cts .jsx\r\n * .tsx`, see `isJS` in `@nuxt/kit`), not `unimport`'s narrower unplugin default (`/\\.[jt]sx?$/`, which misses\r\n * `.mjs`/`.cjs`/`.mts`/`.cts`): whether a file gets auto imports must not depend on whether the project happens to\r\n * use TypeScript.\r\n */\r\nconst TRANSFORM_INCLUDE = [/\\.(?:[cm]?[jt]s|[jt]sx)$/];\r\n\r\nexport interface AutoImportsPluginOptions extends Pick<ResolvedImportsConfig, 'dirs' | 'presets' | 'exclude' | 'dts'> {\r\n\t/** Absolute project root, used to resolve `presets` against the project's own `node_modules`. */\r\n\troot: string;\r\n}\r\n\r\n/**\r\n * Scans every configured preset package for its export names, from the project's own `node_modules` so the result\r\n * matches what the project actually has installed. Packages that fail to resolve (not installed, or a preset the\r\n * user configured for a plugin they do not use) are skipped rather than failing the build.\r\n */\r\nasync function scanPresetImports(root: string, presets: readonly string[], excluded: ReadonlySet<string>): Promise<Import[]> {\r\n\tconst url = pathToFileURL(`${root}/package.json`).href;\r\n\tconst imports: Import[] = [];\r\n\r\n\tawait Promise.all(\r\n\t\tpresets.map(async (from) => {\r\n\t\t\tlet names: string[];\r\n\t\t\ttry {\r\n\t\t\t\tnames = await resolveModuleExportNames(from, { url });\r\n\t\t\t} catch {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tfor (const name of names) {\r\n\t\t\t\tif (excluded.has(name)) continue;\r\n\t\t\t\timports.push({ name, from });\r\n\t\t\t}\r\n\t\t})\r\n\t);\r\n\r\n\treturn imports;\r\n}\r\n\r\n/**\r\n * Builds the rolldown plugin `tsdown.config.ts` adds to `plugins` to enable auto imports, as resolved from\r\n * {@link StarsImportsConfig} (see `@wolfstar/http-framework/config`).\r\n */\r\nexport async function autoImports(options: AutoImportsPluginOptions): Promise<ReturnType<typeof unplugin.rolldown>> {\r\n\tconst excluded = new Set([...BLOCKED_EXPORTS, ...options.exclude]);\r\n\tconst imports = await scanPresetImports(options.root, options.presets, excluded);\r\n\r\n\t// `unimport`'s unplugin writes `dts` on `buildStart` but does not create its parent directory.\r\n\tmkdirSync(dirname(options.dts), { recursive: true });\r\n\r\n\treturn unplugin.rolldown({\r\n\t\timports,\r\n\t\tdirs: [...options.dirs],\r\n\t\tinclude: TRANSFORM_INCLUDE,\r\n\t\tdts: options.dts\r\n\t});\r\n}\r\n\r\n/**\r\n * Generates the auto imports declaration file's contents without writing it, so `stars prepare --check` can diff it\r\n * against what is on disk the same way `stars codegen --check` does for i18next types.\r\n */\r\nexport async function generateAutoImportsDts(options: Pick<AutoImportsPluginOptions, 'root' | 'dirs' | 'presets' | 'exclude'>): Promise<string> {\r\n\tconst excluded = new Set([...BLOCKED_EXPORTS, ...options.exclude]);\r\n\tconst imports = await scanPresetImports(options.root, options.presets, excluded);\r\n\tconst ctx = createUnimport({ imports, dirs: [...options.dirs] });\r\n\tawait ctx.init();\r\n\treturn ctx.generateTypeDeclarations();\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,kCAAuC,IAAI,IAAI;CAAC;CAAU;CAAW;CAAU;CAAS;AAAO,CAAC;;;;;;;AAQtG,MAAM,oBA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