nuxt-skill-hub 0.1.0 → 0.1.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/dist/module.d.mts +0 -5
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -46
- package/package.json +1 -4
- package/dist/runtime/eslint/no-redundant-import.d.ts +0 -2
- package/dist/runtime/eslint/no-redundant-import.js +0 -114
- package/dist/runtime/eslint/plugin.d.ts +0 -9
- package/dist/runtime/eslint/plugin.js +0 -5
package/dist/module.d.mts
CHANGED
|
@@ -49,11 +49,6 @@ interface ModuleOptions {
|
|
|
49
49
|
moduleAuthoring?: boolean;
|
|
50
50
|
generationMode?: SkillHubGenerationMode;
|
|
51
51
|
remote?: boolean | SkillHubRemoteOptions;
|
|
52
|
-
/**
|
|
53
|
-
* Auto-register ESLint rule to remove redundant imports when @nuxt/eslint is installed.
|
|
54
|
-
* @default true
|
|
55
|
-
*/
|
|
56
|
-
eslint?: boolean;
|
|
57
52
|
}
|
|
58
53
|
interface SkillHubContribution {
|
|
59
54
|
packageName: string;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { glob } from 'tinyglobby';
|
|
|
18
18
|
import { createConsola } from 'consola';
|
|
19
19
|
import { colorize } from 'consola/utils';
|
|
20
20
|
|
|
21
|
-
const version = "0.1.
|
|
21
|
+
const version = "0.1.1";
|
|
22
22
|
const packageJson = {
|
|
23
23
|
version: version};
|
|
24
24
|
|
|
@@ -3026,49 +3026,6 @@ Configure \`skillHub.skillName\`, \`skillHub.targets\`, or set \`skillHub.genera
|
|
|
3026
3026
|
);
|
|
3027
3027
|
}
|
|
3028
3028
|
|
|
3029
|
-
function createAutoImportAddon(nuxt) {
|
|
3030
|
-
let unimport;
|
|
3031
|
-
let nitroUnimport;
|
|
3032
|
-
const hook = nuxt.hook;
|
|
3033
|
-
hook("imports:context", (context) => {
|
|
3034
|
-
unimport = context;
|
|
3035
|
-
});
|
|
3036
|
-
hook("nitro:init", (nitro) => {
|
|
3037
|
-
nitroUnimport = nitro.unimport;
|
|
3038
|
-
});
|
|
3039
|
-
hook("eslint:config:addons", (addons) => {
|
|
3040
|
-
addons.push({
|
|
3041
|
-
name: "skill-hub:no-redundant-import",
|
|
3042
|
-
async getConfigs() {
|
|
3043
|
-
const imports = [
|
|
3044
|
-
...await unimport?.getImports() || [],
|
|
3045
|
-
...await nitroUnimport?.getImports() || []
|
|
3046
|
-
];
|
|
3047
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3048
|
-
const entries = imports.filter((i) => {
|
|
3049
|
-
const key = `${i.as || i.name}:${i.from}:${i.type ? "type" : "value"}`;
|
|
3050
|
-
if (seen.has(key)) return false;
|
|
3051
|
-
seen.add(key);
|
|
3052
|
-
return true;
|
|
3053
|
-
}).map((i) => ({ name: i.name, ...i.as && i.as !== i.name ? { as: i.as } : {}, from: i.from, ...i.type ? { type: true } : {} })).sort((a, b) => a.from.localeCompare(b.from) || a.name.localeCompare(b.name));
|
|
3054
|
-
return {
|
|
3055
|
-
imports: [{ from: "nuxt-skill-hub/eslint-plugin", name: "default", as: "skillHubPlugin" }],
|
|
3056
|
-
configs: [
|
|
3057
|
-
[
|
|
3058
|
-
"{",
|
|
3059
|
-
` name: 'skill-hub/no-redundant-import',`,
|
|
3060
|
-
` plugins: { 'skill-hub': skillHubPlugin },`,
|
|
3061
|
-
` settings: { 'skill-hub/autoImports': ${JSON.stringify(entries)} },`,
|
|
3062
|
-
` rules: { 'skill-hub/no-redundant-import': 'warn' },`,
|
|
3063
|
-
"}"
|
|
3064
|
-
].join("\n")
|
|
3065
|
-
]
|
|
3066
|
-
};
|
|
3067
|
-
}
|
|
3068
|
-
});
|
|
3069
|
-
});
|
|
3070
|
-
}
|
|
3071
|
-
|
|
3072
3029
|
const module$1 = defineNuxtModule({
|
|
3073
3030
|
meta: {
|
|
3074
3031
|
name: "nuxt-skill-hub",
|
|
@@ -3089,8 +3046,6 @@ const module$1 = defineNuxtModule({
|
|
|
3089
3046
|
},
|
|
3090
3047
|
async setup(options, nuxt) {
|
|
3091
3048
|
const logger = useLogger("nuxt-skill-hub");
|
|
3092
|
-
if (options.eslint !== false)
|
|
3093
|
-
createAutoImportAddon(nuxt);
|
|
3094
3049
|
if (isCI && !isTest) {
|
|
3095
3050
|
logger.info("Skipping skill generation in CI");
|
|
3096
3051
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-skill-hub",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Teach your AI agent the Nuxt way with best practices and module guidance.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"types": "./dist/types.d.mts",
|
|
14
14
|
"import": "./dist/module.mjs",
|
|
15
15
|
"default": "./dist/module.mjs"
|
|
16
|
-
},
|
|
17
|
-
"./eslint-plugin": {
|
|
18
|
-
"import": "./dist/runtime/eslint/plugin.js"
|
|
19
16
|
}
|
|
20
17
|
},
|
|
21
18
|
"main": "./dist/module.mjs",
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
const SETTINGS_KEY = "skill-hub/autoImports";
|
|
2
|
-
export const noRedundantImport = {
|
|
3
|
-
meta: {
|
|
4
|
-
type: "suggestion",
|
|
5
|
-
docs: {
|
|
6
|
-
description: "Disallow explicit imports of auto-imported identifiers in Nuxt"
|
|
7
|
-
},
|
|
8
|
-
fixable: "code",
|
|
9
|
-
schema: [],
|
|
10
|
-
messages: {
|
|
11
|
-
redundant: "'{{ name }}' is auto-imported by Nuxt. Remove this explicit import."
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
create(context) {
|
|
15
|
-
const entries = context.settings[SETTINGS_KEY];
|
|
16
|
-
if (!entries?.length)
|
|
17
|
-
return {};
|
|
18
|
-
const lookup = /* @__PURE__ */ new Map();
|
|
19
|
-
for (const entry of entries) {
|
|
20
|
-
const localName = entry.as || entry.name;
|
|
21
|
-
const existing = lookup.get(entry.from) || { type: /* @__PURE__ */ new Map(), value: /* @__PURE__ */ new Map() };
|
|
22
|
-
addAutoImportName(existing[entry.type ? "type" : "value"], localName, entry.name);
|
|
23
|
-
lookup.set(entry.from, existing);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
ImportDeclaration(node) {
|
|
27
|
-
const importNode = node;
|
|
28
|
-
if (!importNode.specifiers.length) return;
|
|
29
|
-
const source = typeof importNode.source.value === "string" ? importNode.source.value : void 0;
|
|
30
|
-
if (!source) return;
|
|
31
|
-
const autoImported = lookup.get(source);
|
|
32
|
-
if (!autoImported) return;
|
|
33
|
-
if (isDeclarationFile(context.filename)) return;
|
|
34
|
-
const specInfos = [];
|
|
35
|
-
for (const spec of importNode.specifiers) {
|
|
36
|
-
if (spec.type !== "ImportSpecifier") {
|
|
37
|
-
specInfos.push({ spec, localName: "", isRedundant: false });
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const localName = spec.local.name;
|
|
41
|
-
const names = isTypeOnlyImport(importNode, spec) ? autoImported.type : autoImported.value;
|
|
42
|
-
const importedName = getImportedName(spec);
|
|
43
|
-
specInfos.push({ spec, localName, isRedundant: importedName ? names.get(localName)?.has(importedName) === true : false });
|
|
44
|
-
}
|
|
45
|
-
const redundant = specInfos.filter((s) => s.isRedundant);
|
|
46
|
-
if (!redundant.length) return;
|
|
47
|
-
const kept = specInfos.filter((s) => !s.isRedundant);
|
|
48
|
-
const sourceText = context.sourceCode.getText();
|
|
49
|
-
if (!kept.length) {
|
|
50
|
-
context.report({
|
|
51
|
-
node: importNode,
|
|
52
|
-
messageId: "redundant",
|
|
53
|
-
data: { name: redundant.map((s) => s.localName).join(", ") },
|
|
54
|
-
fix: (fixer) => fixer.removeRange(importRemovalRange(sourceText, importNode.range))
|
|
55
|
-
});
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
context.report({
|
|
59
|
-
node: importNode,
|
|
60
|
-
messageId: "redundant",
|
|
61
|
-
data: { name: redundant.map((s) => s.localName).join(", ") },
|
|
62
|
-
fix: (fixer) => fixer.replaceText(importNode, rebuildImportDeclaration(context, importNode, kept))
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
function isDeclarationFile(filename) {
|
|
69
|
-
return /\.d\.(?:cts|mts|ts)$/.test(filename);
|
|
70
|
-
}
|
|
71
|
-
function importRemovalRange(text, range) {
|
|
72
|
-
let end = range[1];
|
|
73
|
-
while (text[end] === " " || text[end] === " ") {
|
|
74
|
-
end++;
|
|
75
|
-
}
|
|
76
|
-
if (text.startsWith("\r\n", end)) {
|
|
77
|
-
return [range[0], end + 2];
|
|
78
|
-
}
|
|
79
|
-
if (text[end] === "\n") {
|
|
80
|
-
return [range[0], end + 1];
|
|
81
|
-
}
|
|
82
|
-
return [range[0], end];
|
|
83
|
-
}
|
|
84
|
-
function isTypeOnlyImport(node, spec) {
|
|
85
|
-
return node.importKind === "type" || spec.importKind === "type";
|
|
86
|
-
}
|
|
87
|
-
function addAutoImportName(lookup, localName, importedName) {
|
|
88
|
-
const importedNames = lookup.get(localName) || /* @__PURE__ */ new Set();
|
|
89
|
-
importedNames.add(importedName);
|
|
90
|
-
lookup.set(localName, importedNames);
|
|
91
|
-
}
|
|
92
|
-
function getImportedName(spec) {
|
|
93
|
-
return typeof spec.imported.name === "string" ? spec.imported.name : typeof spec.imported.value === "string" ? spec.imported.value : void 0;
|
|
94
|
-
}
|
|
95
|
-
function rebuildImportDeclaration(context, node, kept) {
|
|
96
|
-
const defaultSpecifiers = kept.filter(({ spec }) => spec.type === "ImportDefaultSpecifier");
|
|
97
|
-
const namespaceSpecifiers = kept.filter(({ spec }) => spec.type === "ImportNamespaceSpecifier");
|
|
98
|
-
const namedSpecifiers = kept.filter(({ spec }) => spec.type === "ImportSpecifier").map(({ spec }) => spec);
|
|
99
|
-
const useTypeKeyword = node.importKind !== "type" && !defaultSpecifiers.length && !namespaceSpecifiers.length && namedSpecifiers.length > 0 && namedSpecifiers.every((spec) => spec.importKind === "type");
|
|
100
|
-
const specifierTexts = [
|
|
101
|
-
...defaultSpecifiers.map(({ spec }) => context.sourceCode.getText(spec)),
|
|
102
|
-
...namespaceSpecifiers.map(({ spec }) => context.sourceCode.getText(spec))
|
|
103
|
-
];
|
|
104
|
-
if (namedSpecifiers.length) {
|
|
105
|
-
const namedTexts = namedSpecifiers.map((spec) => {
|
|
106
|
-
const text = context.sourceCode.getText(spec);
|
|
107
|
-
return useTypeKeyword ? text.replace(/^type\s+/, "") : text;
|
|
108
|
-
});
|
|
109
|
-
specifierTexts.push(`{ ${namedTexts.join(", ")} }`);
|
|
110
|
-
}
|
|
111
|
-
const sourceRange = node.source.range;
|
|
112
|
-
const suffix = context.sourceCode.text.slice(sourceRange[1], node.range[1]);
|
|
113
|
-
return `import${node.importKind === "type" || useTypeKeyword ? " type" : ""} ${specifierTexts.join(", ")} from ${context.sourceCode.getText(node.source)}${suffix}`;
|
|
114
|
-
}
|