silgi 0.17.8 → 0.18.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/dist/_chunks/index.mjs +2 -1
- package/dist/cli/dev.mjs +1 -0
- package/dist/cli/prepare.mjs +1 -0
- package/dist/cli/writeTypesAndFiles.mjs +58 -46
- package/dist/kit/index.d.mts +2 -1
- package/dist/kit/index.d.ts +2 -1
- package/dist/kit/index.mjs +6 -2
- package/dist/meta/index.d.mts +2 -1
- package/dist/meta/index.d.ts +2 -1
- package/package.json +2 -1
package/dist/_chunks/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = "0.
|
|
1
|
+
const version = "0.18.0";
|
|
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
package/dist/cli/prepare.mjs
CHANGED
|
@@ -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,
|
|
5
|
+
import { join, resolve, relative, dirname, basename, extname, isAbsolute } from 'pathe';
|
|
6
6
|
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
7
|
-
import { relativeWithDot, hash, resolveAlias,
|
|
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,
|
|
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 {
|
|
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,81 @@ async function installModule(moduleToInstall, silgi = useSilgiCLI(), inlineOptio
|
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
|
|
390
|
-
const
|
|
391
|
-
async function _resolveSilgiModule(
|
|
392
|
-
let
|
|
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
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
403
|
+
try {
|
|
404
|
+
console.log(silgi.options.conditions);
|
|
405
|
+
const src = resolveModuleURL(silgiModule, {
|
|
406
|
+
from: silgi.options.modulesDir.map((m) => directoryToURL(m.replace(/\/node_modules\/?$/, "/"))),
|
|
407
|
+
suffixes: ["silgi", "silgi/index", "module", "module/index", "", "index"],
|
|
408
|
+
extensions: [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]
|
|
409
|
+
// Maybe add https://github.com/unjs/exsolve/blob/dfff3e9bbc4a3a173a2d56b9b9ff731ab15598be/src/resolve.ts#L7
|
|
410
|
+
// conditions: silgi.options.conditions,
|
|
411
|
+
});
|
|
412
|
+
resolvedModulePath = fileURLToPath(src);
|
|
413
|
+
const resolvedSilgiModule = await jiti.import(src, { default: true });
|
|
414
|
+
if (typeof resolvedSilgiModule !== "function") {
|
|
415
|
+
throw new TypeError(`Nuxt module should be a function: ${silgiModule}.`);
|
|
416
|
+
}
|
|
417
|
+
silgiModule = await jiti.import(src, {
|
|
418
|
+
default: true,
|
|
419
|
+
conditions: silgi.options.conditions
|
|
420
|
+
});
|
|
421
|
+
const moduleMetadataPath = new URL("module.json", src);
|
|
422
|
+
if (existsSync(moduleMetadataPath)) {
|
|
423
|
+
buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
|
|
424
|
+
} else {
|
|
425
|
+
if (typeof silgiModule === "function") {
|
|
426
|
+
const meta = await silgiModule.getMeta?.();
|
|
427
|
+
const _exports = await scanExports(resolvedModulePath, true);
|
|
428
|
+
buildTimeModuleMeta = {
|
|
429
|
+
...meta,
|
|
430
|
+
exports: _exports.map(({ from, ...rest }) => rest)
|
|
431
|
+
};
|
|
425
432
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
433
|
+
}
|
|
434
|
+
} catch (error) {
|
|
435
|
+
const code = error.code;
|
|
436
|
+
if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
|
|
437
|
+
throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
|
|
438
|
+
}
|
|
439
|
+
if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
|
|
440
|
+
const module = MissingModuleMatcher.exec(error.message)?.[1];
|
|
441
|
+
if (module && !module.includes(silgiModule)) {
|
|
442
|
+
throw new TypeError(`Error while importing module \`${silgiModule}\`: ${error}`);
|
|
431
443
|
}
|
|
432
|
-
logger$1.error(`Error while importing module \`${mod}\`: ${error}`);
|
|
433
|
-
throw error;
|
|
434
444
|
}
|
|
435
445
|
}
|
|
436
446
|
}
|
|
437
447
|
if (!buildTimeModuleMeta) {
|
|
438
|
-
throw new Error(`Module ${
|
|
448
|
+
throw new Error(`Module ${silgiModule} is not a valid Silgi module`);
|
|
439
449
|
}
|
|
440
|
-
if (typeof
|
|
450
|
+
if (typeof silgiModule === "function") {
|
|
441
451
|
if (silgi.scanModules.some((m) => m.meta?.configKey === buildTimeModuleMeta.configKey)) {
|
|
442
452
|
throw new Error(`Module with key \`${buildTimeModuleMeta.configKey}\` already exists`);
|
|
443
453
|
}
|
|
444
|
-
const options = await
|
|
454
|
+
const options = await silgiModule.getOptions?.() || {};
|
|
445
455
|
if (options) {
|
|
446
456
|
silgi.options._c12.config[buildTimeModuleMeta.configKey] = defu(
|
|
447
457
|
silgi.options._c12.config[buildTimeModuleMeta.configKey] || {},
|
|
448
458
|
options || {}
|
|
449
459
|
);
|
|
460
|
+
} else {
|
|
461
|
+
throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
|
|
450
462
|
}
|
|
451
463
|
silgi.scanModules.push({
|
|
452
464
|
meta: buildTimeModuleMeta,
|
|
453
|
-
entryPath:
|
|
465
|
+
entryPath: resolvedModulePath || "",
|
|
454
466
|
installed: false,
|
|
455
467
|
options
|
|
456
468
|
});
|
|
@@ -2126,7 +2138,7 @@ async function writeTypesAndFiles(silgi) {
|
|
|
2126
2138
|
}
|
|
2127
2139
|
let path = resolveAlias$1(i.from, silgi.options.alias);
|
|
2128
2140
|
if (isAbsolute(path)) {
|
|
2129
|
-
const resolvedPath = await resolvePath
|
|
2141
|
+
const resolvedPath = await resolvePath(i.from, {
|
|
2130
2142
|
url: silgi.options.nodeModulesDirs
|
|
2131
2143
|
}).catch(() => null);
|
|
2132
2144
|
if (resolvedPath) {
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -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 });
|
|
@@ -296,6 +299,7 @@ async function isDirectory(path) {
|
|
|
296
299
|
return (await promises.lstat(path)).isDirectory();
|
|
297
300
|
}
|
|
298
301
|
function resolveAlias(path, alias) {
|
|
302
|
+
alias ||= tryUseSilgiCLI()?.options.alias || {};
|
|
299
303
|
return resolveAlias$1(path, alias || {});
|
|
300
304
|
}
|
|
301
305
|
function createResolver(base) {
|
|
@@ -571,4 +575,4 @@ function isValidIp(ip) {
|
|
|
571
575
|
return false;
|
|
572
576
|
}
|
|
573
577
|
|
|
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 };
|
|
578
|
+
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 };
|
package/dist/meta/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = "0.
|
|
1
|
+
const version = "0.18.0";
|
|
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/meta/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = "0.
|
|
1
|
+
const version = "0.18.0";
|
|
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.
|
|
4
|
+
"version": "0.18.0",
|
|
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",
|