silgi 0.17.7 → 0.17.9

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.
@@ -1,4 +1,4 @@
1
- const version = "0.17.7";
1
+ const version = "0.17.9";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -27,6 +27,7 @@ const dependencies = {
27
27
  "dot-prop": "catalog:",
28
28
  dotenv: "catalog:",
29
29
  "escape-string-regexp": "catalog:",
30
+ exsolve: "^1.0.4",
30
31
  globby: "catalog:",
31
32
  hookable: "catalog:",
32
33
  ignore: "catalog:",
package/dist/cli/dev.mjs CHANGED
@@ -24,6 +24,7 @@ import 'mlly';
24
24
  import 'dev-jiti';
25
25
  import 'node:url';
26
26
  import 'defu';
27
+ import 'exsolve';
27
28
  import 'globby';
28
29
  import 'ignore';
29
30
  import '@oxc-parser/wasm';
@@ -23,6 +23,7 @@ import './compatibility.mjs';
23
23
  import 'semver/functions/satisfies.js';
24
24
  import 'node:url';
25
25
  import 'defu';
26
+ import 'exsolve';
26
27
  import 'globby';
27
28
  import 'ignore';
28
29
  import '@oxc-parser/wasm';
@@ -2,19 +2,20 @@ import { existsSync, promises, readFileSync, writeFileSync, mkdirSync } from 'no
2
2
  import { readdir, readFile } from 'node:fs/promises';
3
3
  import consola$1, { consola } from 'consola';
4
4
  import { createHooks, createDebugger } from 'hookable';
5
- import { join, resolve, isAbsolute, relative, dirname, basename, extname } from 'pathe';
5
+ import { join, resolve, relative, dirname, basename, extname, isAbsolute } from 'pathe';
6
6
  import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
7
- import { relativeWithDot, hash, resolveAlias, resolvePath, writeFile, parseServices, normalizeTemplate, useLogger, addTemplate, initRuntimeConfig, hasError as hasError$1, resolveSilgiPath, isDirectory } from 'silgi/kit';
7
+ import { relativeWithDot, hash, resolveAlias, directoryToURL, writeFile, parseServices, normalizeTemplate, useLogger, addTemplate, initRuntimeConfig, hasError as hasError$1, resolveSilgiPath, isDirectory } from 'silgi/kit';
8
8
  import { runtimeDir } from 'silgi/runtime/meta';
9
9
  import { autoImportTypes } from 'silgi/types';
10
10
  import { scanExports, createUnimport, toExports } from 'unimport';
11
11
  import { c as createRouteRules } from '../_chunks/routeRules.mjs';
12
12
  import { p as prepareEnv } from './env.mjs';
13
- import { resolveModuleExportNames, resolve as resolve$1, resolvePath as resolvePath$1, parseNodeModulePath, lookupNodeModuleSubpath } from 'mlly';
13
+ import { resolveModuleExportNames, resolvePath, parseNodeModulePath, lookupNodeModuleSubpath } from 'mlly';
14
14
  import { createJiti } from 'dev-jiti';
15
15
  import { a as hasInstalledModule, h as hasError } from './compatibility.mjs';
16
- import { pathToFileURL, fileURLToPath } from 'node:url';
16
+ import { fileURLToPath } from 'node:url';
17
17
  import defu, { defu as defu$1 } from 'defu';
18
+ import { resolveModuleURL } from 'exsolve';
18
19
  import { isRelative, withTrailingSlash } from 'ufo';
19
20
  import { globby } from 'globby';
20
21
  import ignore from 'ignore';
@@ -387,70 +388,80 @@ async function installModule(moduleToInstall, silgi = useSilgiCLI(), inlineOptio
387
388
  }
388
389
  }
389
390
 
390
- const logger$1 = consola;
391
- async function _resolveSilgiModule(mod, silgi) {
392
- let _url;
391
+ const MissingModuleMatcher = /Cannot find module\s+['"]?([^'")\s]+)['"]?/i;
392
+ async function _resolveSilgiModule(silgiModule, silgi) {
393
+ let resolvedModulePath;
393
394
  let buildTimeModuleMeta = {};
394
395
  const jiti = createJiti(silgi.options.rootDir, {
395
396
  alias: silgi.options.alias
396
397
  });
397
- if (typeof mod === "string") {
398
- const paths = /* @__PURE__ */ new Set();
399
- mod = resolveAlias(mod, silgi.options.alias);
400
- if (isRelative(mod)) {
401
- mod = resolve(silgi.options.rootDir, mod);
398
+ if (typeof silgiModule === "string") {
399
+ silgiModule = resolveAlias(silgiModule, silgi.options.alias);
400
+ if (isRelative(silgiModule)) {
401
+ silgiModule = resolve(silgi.options.rootDir, silgiModule);
402
402
  }
403
- paths.add(join(mod, "module"));
404
- paths.add(mod);
405
- for (const path of paths) {
406
- try {
407
- const src = isAbsolute(path) ? pathToFileURL(await resolvePath(path, { fallbackToOriginal: false, extensions: silgi.options.extensions })).href : await resolve$1(path, { url: silgi.options.modulesDir.map((m) => pathToFileURL(m.replace(/\/node_modules\/?$/, ""))), extensions: silgi.options.extensions });
408
- mod = await jiti.import(src, {
409
- default: true,
410
- conditions: silgi.options.conditions
411
- });
412
- _url = fileURLToPath(new URL(src));
413
- const moduleMetadataPath = new URL("module.json", src);
414
- if (existsSync(moduleMetadataPath)) {
415
- buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
416
- } else {
417
- if (typeof mod === "function") {
418
- const meta = await mod.getMeta?.();
419
- const _exports = await scanExports(_url, true);
420
- buildTimeModuleMeta = {
421
- ...meta,
422
- exports: _exports.map(({ from, ...rest }) => rest)
423
- };
424
- }
403
+ try {
404
+ const src = resolveModuleURL(silgiModule, {
405
+ from: silgi.options.modulesDir.map((m) => directoryToURL(m.replace(/\/node_modules\/?$/, "/"))),
406
+ suffixes: ["silgi", "silgi/index", "module", "module/index", "", "index"],
407
+ extensions: [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"],
408
+ conditions: silgi.options.conditions
409
+ });
410
+ console.log("src:", src);
411
+ resolvedModulePath = fileURLToPath(src);
412
+ const resolvedSilgiModule = await jiti.import(src, { default: true });
413
+ if (typeof resolvedSilgiModule !== "function") {
414
+ throw new TypeError(`Nuxt module should be a function: ${silgiModule}.`);
415
+ }
416
+ silgiModule = await jiti.import(src, {
417
+ default: true,
418
+ conditions: silgi.options.conditions
419
+ });
420
+ const moduleMetadataPath = new URL("module.json", src);
421
+ if (existsSync(moduleMetadataPath)) {
422
+ buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
423
+ } else {
424
+ if (typeof silgiModule === "function") {
425
+ const meta = await silgiModule.getMeta?.();
426
+ const _exports = await scanExports(resolvedModulePath, true);
427
+ buildTimeModuleMeta = {
428
+ ...meta,
429
+ exports: _exports.map(({ from, ...rest }) => rest)
430
+ };
425
431
  }
426
- break;
427
- } catch (error) {
428
- const code = error.code;
429
- if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
430
- continue;
432
+ }
433
+ } catch (error) {
434
+ const code = error.code;
435
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
436
+ throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
437
+ }
438
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
439
+ const module = MissingModuleMatcher.exec(error.message)?.[1];
440
+ if (module && !module.includes(silgiModule)) {
441
+ throw new TypeError(`Error while importing module \`${silgiModule}\`: ${error}`);
431
442
  }
432
- logger$1.error(`Error while importing module \`${mod}\`: ${error}`);
433
- throw error;
434
443
  }
435
444
  }
436
445
  }
437
446
  if (!buildTimeModuleMeta) {
438
- throw new Error(`Module ${mod} is not a valid Silgi module`);
447
+ throw new Error(`Module ${silgiModule} is not a valid Silgi module`);
439
448
  }
440
- if (typeof mod === "function") {
449
+ if (typeof silgiModule === "function") {
441
450
  if (silgi.scanModules.some((m) => m.meta?.configKey === buildTimeModuleMeta.configKey)) {
442
451
  throw new Error(`Module with key \`${buildTimeModuleMeta.configKey}\` already exists`);
443
452
  }
444
- const options = await mod.getOptions?.() || {};
453
+ const options = await silgiModule.getOptions?.() || {};
445
454
  if (options) {
446
455
  silgi.options._c12.config[buildTimeModuleMeta.configKey] = defu(
447
456
  silgi.options._c12.config[buildTimeModuleMeta.configKey] || {},
448
457
  options || {}
449
458
  );
459
+ } else {
460
+ throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
450
461
  }
451
462
  silgi.scanModules.push({
452
463
  meta: buildTimeModuleMeta,
453
- entryPath: _url,
464
+ entryPath: resolvedModulePath || "",
454
465
  installed: false,
455
466
  options
456
467
  });
@@ -1516,7 +1527,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
1516
1527
 
1517
1528
  function serializeToJs(obj, indent = 2, level = 0) {
1518
1529
  if (obj === null || obj === void 0) {
1519
- return String(obj);
1530
+ return obj === void 0 ? "undefined as any" : String(obj);
1520
1531
  }
1521
1532
  if (typeof obj === "function") {
1522
1533
  return obj.toString();
@@ -2126,7 +2137,7 @@ async function writeTypesAndFiles(silgi) {
2126
2137
  }
2127
2138
  let path = resolveAlias$1(i.from, silgi.options.alias);
2128
2139
  if (isAbsolute(path)) {
2129
- const resolvedPath = await resolvePath$1(i.from, {
2140
+ const resolvedPath = await resolvePath(i.from, {
2130
2141
  url: silgi.options.nodeModulesDirs
2131
2142
  }).catch(() => null);
2132
2143
  if (resolvedPath) {
@@ -6,6 +6,7 @@ import { IncomingMessage } from 'node:http';
6
6
 
7
7
  declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
8
8
 
9
+ declare function directoryToURL(dir: string): URL;
9
10
  /**
10
11
  * Resolve a module from a given root path using an algorithm patterned on
11
12
  * the upcoming `import.meta.resolve`. It returns a file URL
@@ -149,4 +150,4 @@ declare const MODE_RE: RegExp;
149
150
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
150
151
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
151
152
 
152
- export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
153
+ export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
@@ -6,6 +6,7 @@ import { IncomingMessage } from 'node:http';
6
6
 
7
7
  declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
8
8
 
9
+ declare function directoryToURL(dir: string): URL;
9
10
  /**
10
11
  * Resolve a module from a given root path using an algorithm patterned on
11
12
  * the upcoming `import.meta.resolve`. It returns a file URL
@@ -149,4 +150,4 @@ declare const MODE_RE: RegExp;
149
150
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
150
151
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
151
152
 
152
- export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
153
+ export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
@@ -1,5 +1,6 @@
1
1
  import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
2
2
  export { h as hasError } from '../cli/compatibility.mjs';
3
+ import { pathToFileURL, fileURLToPath } from 'node:url';
3
4
  import { resolvePath as resolvePath$1 } from 'mlly';
4
5
  import fsp from 'node:fs/promises';
5
6
  import consola, { consola as consola$1 } from 'consola';
@@ -12,7 +13,6 @@ import { useSilgi, tryUseSilgiCLI, useSilgiCLI, tryUseSilgi } from 'silgi/core';
12
13
  import { defu } from 'defu';
13
14
  import { withLeadingSlash } from 'ufo';
14
15
  import { existsSync, promises } from 'node:fs';
15
- import { fileURLToPath } from 'node:url';
16
16
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
17
17
  import destr from 'destr';
18
18
  import { klona } from 'klona';
@@ -20,6 +20,9 @@ import { hash as hash$2 } from 'silgi/kit';
20
20
  import 'semver/functions/satisfies.js';
21
21
  import 'silgi/meta';
22
22
 
23
+ function directoryToURL(dir) {
24
+ return pathToFileURL(`${dir}/`);
25
+ }
23
26
  async function tryResolveModule(id, url = import.meta.url) {
24
27
  try {
25
28
  return await resolvePath$1(id, { url });
@@ -571,4 +574,4 @@ function isValidIp(ip) {
571
574
  return false;
572
575
  }
573
576
 
574
- export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
577
+ export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
@@ -1,4 +1,4 @@
1
- const version = "0.17.7";
1
+ const version = "0.17.9";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -27,6 +27,7 @@ const dependencies = {
27
27
  "dot-prop": "catalog:",
28
28
  dotenv: "catalog:",
29
29
  "escape-string-regexp": "catalog:",
30
+ exsolve: "^1.0.4",
30
31
  globby: "catalog:",
31
32
  hookable: "catalog:",
32
33
  ignore: "catalog:",
@@ -1,4 +1,4 @@
1
- const version = "0.17.7";
1
+ const version = "0.17.9";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -27,6 +27,7 @@ const dependencies = {
27
27
  "dot-prop": "catalog:",
28
28
  dotenv: "catalog:",
29
29
  "escape-string-regexp": "catalog:",
30
+ exsolve: "^1.0.4",
30
31
  globby: "catalog:",
31
32
  hookable: "catalog:",
32
33
  ignore: "catalog:",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.17.7",
4
+ "version": "0.17.9",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -126,6 +126,7 @@
126
126
  "dot-prop": "^9.0.0",
127
127
  "dotenv": "^16.4.7",
128
128
  "escape-string-regexp": "^5.0.0",
129
+ "exsolve": "^1.0.4",
129
130
  "globby": "^14.1.0",
130
131
  "hookable": "^5.5.3",
131
132
  "ignore": "^7.0.3",