@snipl/core 1.0.0-next.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/LICENSE +21 -0
- package/dist/src/config/loader.d.ts +23 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +45 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/install/plan.d.ts +20 -0
- package/dist/src/install/plan.d.ts.map +1 -0
- package/dist/src/install/plan.js +48 -0
- package/dist/src/install/plan.js.map +1 -0
- package/dist/src/install/writer.d.ts +10 -0
- package/dist/src/install/writer.d.ts.map +1 -0
- package/dist/src/install/writer.js +106 -0
- package/dist/src/install/writer.js.map +1 -0
- package/dist/src/manifest/loader.d.ts +7 -0
- package/dist/src/manifest/loader.d.ts.map +1 -0
- package/dist/src/manifest/loader.js +36 -0
- package/dist/src/manifest/loader.js.map +1 -0
- package/dist/src/paths/index.d.ts +7 -0
- package/dist/src/paths/index.d.ts.map +1 -0
- package/dist/src/paths/index.js +39 -0
- package/dist/src/paths/index.js.map +1 -0
- package/dist/src/registry/resolver.d.ts +16 -0
- package/dist/src/registry/resolver.d.ts.map +1 -0
- package/dist/src/registry/resolver.js +34 -0
- package/dist/src/registry/resolver.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Snippet CLI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ValidationError } from '@snipl/registry-schema';
|
|
2
|
+
import type { SnippetConfig } from '@snipl/registry-schema';
|
|
3
|
+
declare const CONFIG_FILENAME = "snippets.json";
|
|
4
|
+
export interface ConfigLoader {
|
|
5
|
+
findConfigPath(projectRoot: string): string;
|
|
6
|
+
loadConfig(projectRoot: string): SnippetConfig;
|
|
7
|
+
writeConfig(projectRoot: string, config: SnippetConfig): void;
|
|
8
|
+
configExists(projectRoot: string): boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function findConfigPath(projectRoot: string): string;
|
|
11
|
+
export declare function loadConfig(projectRoot: string): SnippetConfig;
|
|
12
|
+
export declare function writeConfig(projectRoot: string, config: SnippetConfig): void;
|
|
13
|
+
export declare function configExists(projectRoot: string): boolean;
|
|
14
|
+
export declare class ConfigNotFoundError extends Error {
|
|
15
|
+
readonly projectRoot: string;
|
|
16
|
+
constructor(projectRoot: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class ConfigValidationError extends Error {
|
|
19
|
+
readonly errors: ValidationError[];
|
|
20
|
+
constructor(errors: ValidationError[]);
|
|
21
|
+
}
|
|
22
|
+
export { CONFIG_FILENAME };
|
|
23
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/config/loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkC,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,QAAA,MAAM,eAAe,kBAAkB,CAAC;AAExC,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5C,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/C,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9D,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5C;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAW7D;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAG5E;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,WAAW,EAAE,MAAM,CAAC;gBACxB,WAAW,EAAE,MAAM;CAKhC;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;gBAC9B,MAAM,EAAE,eAAe,EAAE;CAMtC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { SnippetConfigSchema, safeParse } from '@snipl/registry-schema';
|
|
4
|
+
const CONFIG_FILENAME = 'snippets.json';
|
|
5
|
+
export function findConfigPath(projectRoot) {
|
|
6
|
+
return path.join(projectRoot, CONFIG_FILENAME);
|
|
7
|
+
}
|
|
8
|
+
export function loadConfig(projectRoot) {
|
|
9
|
+
const configPath = findConfigPath(projectRoot);
|
|
10
|
+
if (!fs.existsSync(configPath)) {
|
|
11
|
+
throw new ConfigNotFoundError(projectRoot);
|
|
12
|
+
}
|
|
13
|
+
const raw = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
14
|
+
const result = safeParse(SnippetConfigSchema, raw);
|
|
15
|
+
if (!result.success) {
|
|
16
|
+
throw new ConfigValidationError(result.errors);
|
|
17
|
+
}
|
|
18
|
+
return result.data;
|
|
19
|
+
}
|
|
20
|
+
export function writeConfig(projectRoot, config) {
|
|
21
|
+
const configPath = findConfigPath(projectRoot);
|
|
22
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
23
|
+
}
|
|
24
|
+
export function configExists(projectRoot) {
|
|
25
|
+
return fs.existsSync(findConfigPath(projectRoot));
|
|
26
|
+
}
|
|
27
|
+
export class ConfigNotFoundError extends Error {
|
|
28
|
+
projectRoot;
|
|
29
|
+
constructor(projectRoot) {
|
|
30
|
+
super(`snippets.json not found in ${projectRoot}. Run \`snipl init\` first.`);
|
|
31
|
+
this.name = 'ConfigNotFoundError';
|
|
32
|
+
this.projectRoot = projectRoot;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ConfigValidationError extends Error {
|
|
36
|
+
errors;
|
|
37
|
+
constructor(errors) {
|
|
38
|
+
const messages = errors.map((e) => `[${e.code}] ${e.path}: ${e.message}`).join('; ');
|
|
39
|
+
super(`Invalid snippets.json: ${messages}`);
|
|
40
|
+
this.name = 'ConfigValidationError';
|
|
41
|
+
this.errors = errors;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export { CONFIG_FILENAME };
|
|
45
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAmB,MAAM,wBAAwB,CAAC;AAGzF,MAAM,eAAe,GAAG,eAAe,CAAC;AASxC,MAAM,UAAU,cAAc,CAAC,WAAmB;IAChD,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,WAAmB;IAC5C,MAAM,UAAU,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,GAAG,GAAY,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,SAAS,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;IACnD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,MAAM,CAAC,IAAqB,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,WAAmB,EAAE,MAAqB;IACpE,MAAM,UAAU,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC/C,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,OAAO,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5B,WAAW,CAAS;IACpC,YAAY,WAAmB;QAC7B,KAAK,CAAC,8BAA8B,WAAW,6BAA6B,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9B,MAAM,CAAoB;IAC1C,YAAY,MAAyB;QACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrF,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { loadConfig, writeConfig, configExists, findConfigPath, ConfigNotFoundError, ConfigValidationError, CONFIG_FILENAME, } from './config/loader.js';
|
|
2
|
+
export type { ConfigLoader } from './config/loader.js';
|
|
3
|
+
export { BuiltinRegistryResolver } from './registry/resolver.js';
|
|
4
|
+
export type { RegistryResolver } from './registry/resolver.js';
|
|
5
|
+
export { buildWritePlan } from './install/plan.js';
|
|
6
|
+
export { executeWritePlan } from './install/writer.js';
|
|
7
|
+
export type { WritePlan, WritePlanEntry } from './install/plan.js';
|
|
8
|
+
export type { WriteResult } from './install/writer.js';
|
|
9
|
+
export { loadManifest, writeManifest, manifestExists, getInstalledItem, manifestPath, } from './manifest/loader.js';
|
|
10
|
+
export { isPathSafe, containsTraversal, resolveOutputPath, PathSafetyError, } from './paths/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { loadConfig, writeConfig, configExists, findConfigPath, ConfigNotFoundError, ConfigValidationError, CONFIG_FILENAME, } from './config/loader.js';
|
|
2
|
+
export { BuiltinRegistryResolver } from './registry/resolver.js';
|
|
3
|
+
export { buildWritePlan } from './install/plan.js';
|
|
4
|
+
export { executeWritePlan } from './install/writer.js';
|
|
5
|
+
export { loadManifest, writeManifest, manifestExists, getInstalledItem, manifestPath, } from './manifest/loader.js';
|
|
6
|
+
export { isPathSafe, containsTraversal, resolveOutputPath, PathSafetyError, } from './paths/index.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RegistryItem } from '@snipl/registry-schema';
|
|
2
|
+
export interface WritePlanEntry {
|
|
3
|
+
type: 'create' | 'overwrite';
|
|
4
|
+
targetPath: string;
|
|
5
|
+
content: string;
|
|
6
|
+
expectedSha256: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WritePlan {
|
|
9
|
+
projectRoot: string;
|
|
10
|
+
itemName: string;
|
|
11
|
+
itemVersion: string;
|
|
12
|
+
registry: string;
|
|
13
|
+
outputDir: string;
|
|
14
|
+
entries: WritePlanEntry[];
|
|
15
|
+
collisions: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare function buildWritePlan(item: RegistryItem, projectRoot: string, outputDir: string, opts?: {
|
|
18
|
+
overwrite?: boolean;
|
|
19
|
+
}): WritePlan;
|
|
20
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/install/plan.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,YAAY,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,SAAS,CAiDX"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as crypto from 'crypto';
|
|
3
|
+
import { resolveOutputPath, isPathSafe, PathSafetyError } from '../paths/index.js';
|
|
4
|
+
export function buildWritePlan(item, projectRoot, outputDir, opts) {
|
|
5
|
+
const entries = [];
|
|
6
|
+
const collisions = [];
|
|
7
|
+
for (const file of item.files) {
|
|
8
|
+
if (!isPathSafe(file.path)) {
|
|
9
|
+
throw new PathSafetyError(`Item "${item.name}" has unsafe path "${file.path}"`);
|
|
10
|
+
}
|
|
11
|
+
const fileSha256 = crypto.createHash('sha256').update(file.content, 'utf-8').digest('hex');
|
|
12
|
+
if (fileSha256 !== file.sha256) {
|
|
13
|
+
throw new PathSafetyError(`Content hash mismatch for "${file.path}": expected ${file.sha256}, computed ${fileSha256}`);
|
|
14
|
+
}
|
|
15
|
+
const targetPath = resolveOutputPath(projectRoot, outputDir, file.path);
|
|
16
|
+
const exists = fs.existsSync(targetPath);
|
|
17
|
+
if (exists) {
|
|
18
|
+
if (!opts?.overwrite) {
|
|
19
|
+
collisions.push(targetPath);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
entries.push({
|
|
23
|
+
type: 'overwrite',
|
|
24
|
+
targetPath,
|
|
25
|
+
content: file.content,
|
|
26
|
+
expectedSha256: fileSha256,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
entries.push({
|
|
31
|
+
type: 'create',
|
|
32
|
+
targetPath,
|
|
33
|
+
content: file.content,
|
|
34
|
+
expectedSha256: fileSha256,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
projectRoot,
|
|
40
|
+
itemName: item.name,
|
|
41
|
+
itemVersion: item.version,
|
|
42
|
+
registry: 'official',
|
|
43
|
+
outputDir,
|
|
44
|
+
entries,
|
|
45
|
+
collisions,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../../src/install/plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAmBnF,MAAM,UAAU,cAAc,CAC5B,IAAkB,EAClB,WAAmB,EACnB,SAAiB,EACjB,IAA8B;IAE9B,MAAM,OAAO,GA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aAC3B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW;QACX,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,WAAW,EAAE,IAAI,CAAC,OAAO;QACzB,QAAQ,EAAE,UAAU;QACpB,SAAS;QACT,OAAO;QACP,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WritePlan } from './plan.js';
|
|
2
|
+
import type { Manifest } from '@snipl/registry-schema';
|
|
3
|
+
export interface WriteResult {
|
|
4
|
+
success: boolean;
|
|
5
|
+
written: string[];
|
|
6
|
+
failed: string[];
|
|
7
|
+
restored: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function executeWritePlan(plan: WritePlan, existingManifest: Manifest): WriteResult;
|
|
10
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../../src/install/writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,wBAAwB,CAAC;AAEtE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAQD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,GAAG,WAAW,CAkGzF"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { writeManifest } from '../manifest/loader.js';
|
|
4
|
+
export function executeWritePlan(plan, existingManifest) {
|
|
5
|
+
const journal = [];
|
|
6
|
+
const written = [];
|
|
7
|
+
const failed = [];
|
|
8
|
+
const restored = [];
|
|
9
|
+
if (plan.collisions.length > 0) {
|
|
10
|
+
return {
|
|
11
|
+
success: false,
|
|
12
|
+
written: [],
|
|
13
|
+
failed: plan.collisions.map((c) => `Collision: ${c}`),
|
|
14
|
+
restored: [],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const tempDir = path.join(plan.projectRoot, '.snipl', '.tmp-' + Date.now());
|
|
18
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
19
|
+
try {
|
|
20
|
+
for (const entry of plan.entries) {
|
|
21
|
+
const journalEntry = {
|
|
22
|
+
originalPath: entry.targetPath,
|
|
23
|
+
backupPath: null,
|
|
24
|
+
originalExists: fs.existsSync(entry.targetPath),
|
|
25
|
+
};
|
|
26
|
+
if (journalEntry.originalExists) {
|
|
27
|
+
const backupPath = path.join(tempDir, path.basename(entry.targetPath) + '.bak');
|
|
28
|
+
fs.copyFileSync(entry.targetPath, backupPath);
|
|
29
|
+
journalEntry.backupPath = backupPath;
|
|
30
|
+
}
|
|
31
|
+
journal.push(journalEntry);
|
|
32
|
+
}
|
|
33
|
+
for (const entry of plan.entries) {
|
|
34
|
+
try {
|
|
35
|
+
fs.mkdirSync(path.dirname(entry.targetPath), { recursive: true });
|
|
36
|
+
const tmpPath = entry.targetPath + '.snipl-tmp';
|
|
37
|
+
fs.writeFileSync(tmpPath, entry.content, 'utf-8');
|
|
38
|
+
fs.renameSync(tmpPath, entry.targetPath);
|
|
39
|
+
written.push(entry.targetPath);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
43
|
+
failed.push(`${entry.targetPath}: ${msg}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (failed.length > 0) {
|
|
47
|
+
for (const jEntry of journal) {
|
|
48
|
+
if (written.includes(jEntry.originalPath))
|
|
49
|
+
continue;
|
|
50
|
+
if (jEntry.originalExists && jEntry.backupPath && fs.existsSync(jEntry.backupPath)) {
|
|
51
|
+
try {
|
|
52
|
+
fs.copyFileSync(jEntry.backupPath, jEntry.originalPath);
|
|
53
|
+
restored.push(jEntry.originalPath);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// best-effort restore
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
cleanupTempDir(tempDir);
|
|
61
|
+
return { success: false, written, failed, restored };
|
|
62
|
+
}
|
|
63
|
+
const installedItem = {
|
|
64
|
+
registry: plan.registry,
|
|
65
|
+
name: plan.itemName,
|
|
66
|
+
version: plan.itemVersion,
|
|
67
|
+
installedAt: new Date().toISOString(),
|
|
68
|
+
files: plan.entries.map((e) => ({
|
|
69
|
+
path: path.relative(plan.projectRoot, e.targetPath),
|
|
70
|
+
sha256: e.expectedSha256,
|
|
71
|
+
})),
|
|
72
|
+
};
|
|
73
|
+
const updatedManifest = {
|
|
74
|
+
schemaVersion: 1,
|
|
75
|
+
items: [
|
|
76
|
+
...existingManifest.items.filter((i) => !(i.name === plan.itemName && i.registry === plan.registry)),
|
|
77
|
+
installedItem,
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
writeManifest(plan.projectRoot, updatedManifest);
|
|
81
|
+
cleanupTempDir(tempDir);
|
|
82
|
+
return { success: true, written, failed: [], restored: [] };
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
cleanupTempDir(tempDir);
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
written,
|
|
89
|
+
failed: [err instanceof Error ? err.message : String(err)],
|
|
90
|
+
restored,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function cleanupTempDir(dir) {
|
|
95
|
+
try {
|
|
96
|
+
const entries = fs.readdirSync(dir);
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
fs.rmSync(path.join(dir, entry), { force: true });
|
|
99
|
+
}
|
|
100
|
+
fs.rmdirSync(dir);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// best-effort cleanup
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../../src/install/writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAgBtD,MAAM,UAAU,gBAAgB,CAAC,IAAe,EAAE,gBAA0B;IAC1E,MAAM,OAAO,GAAmB,EAAE,CAAC;IACnC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;YACrD,QAAQ,EAAE,EAAE;SACb,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5E,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE3C,IAAI,CAAC;QACH,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,MAAM,YAAY,GAAiB;gBACjC,YAAY,EAAE,KAAK,CAAC,UAAU;gBAC9B,UAAU,EAAE,IAAI;gBAChB,cAAc,EAAE,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AC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC,CACnE;gBACD,aAAa;aACd;SACF,CAAC;QAEF,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QACjD,cAAc,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC9D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,cAAc,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO;YACP,MAAM,EAAE,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1D,QAAQ;SACT,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACpC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Manifest, InstalledItem } from '@snipl/registry-schema';
|
|
2
|
+
export declare function manifestPath(projectRoot: string): string;
|
|
3
|
+
export declare function manifestExists(projectRoot: string): boolean;
|
|
4
|
+
export declare function loadManifest(projectRoot: string): Manifest;
|
|
5
|
+
export declare function writeManifest(projectRoot: string, manifest: Manifest): void;
|
|
6
|
+
export declare function getInstalledItem(projectRoot: string, name: string, registry: string): InstalledItem | null;
|
|
7
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/manifest/loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAKtE,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAW1D;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAO3E;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,aAAa,GAAG,IAAI,CAGtB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { ManifestSchema } from '@snipl/registry-schema';
|
|
4
|
+
const MANIFEST_DIR = '.snipl';
|
|
5
|
+
const MANIFEST_FILENAME = 'manifest.json';
|
|
6
|
+
export function manifestPath(projectRoot) {
|
|
7
|
+
return path.join(projectRoot, MANIFEST_DIR, MANIFEST_FILENAME);
|
|
8
|
+
}
|
|
9
|
+
export function manifestExists(projectRoot) {
|
|
10
|
+
return fs.existsSync(manifestPath(projectRoot));
|
|
11
|
+
}
|
|
12
|
+
export function loadManifest(projectRoot) {
|
|
13
|
+
const filePath = manifestPath(projectRoot);
|
|
14
|
+
if (!fs.existsSync(filePath)) {
|
|
15
|
+
return { schemaVersion: 1, items: [] };
|
|
16
|
+
}
|
|
17
|
+
const raw = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
18
|
+
const result = ManifestSchema.safeParse(raw);
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
throw new Error(`Invalid manifest: ${result.error.message}`);
|
|
21
|
+
}
|
|
22
|
+
return result.data;
|
|
23
|
+
}
|
|
24
|
+
export function writeManifest(projectRoot, manifest) {
|
|
25
|
+
const dir = path.join(projectRoot, MANIFEST_DIR);
|
|
26
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
27
|
+
const filePath = path.join(dir, MANIFEST_FILENAME);
|
|
28
|
+
const tmpPath = filePath + '.tmp';
|
|
29
|
+
fs.writeFileSync(tmpPath, JSON.stringify(manifest, null, 2) + '\n');
|
|
30
|
+
fs.renameSync(tmpPath, filePath);
|
|
31
|
+
}
|
|
32
|
+
export function getInstalledItem(projectRoot, name, registry) {
|
|
33
|
+
const manifest = loadManifest(projectRoot);
|
|
34
|
+
return manifest.items.find((i) => i.name === name && i.registry === registry) ?? null;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/manifest/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,MAAM,YAAY,GAAG,QAAQ,CAAC;AAC9B,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAE1C,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,WAAmB;IAChD,OAAO,EAAE,CAAC,UAAU,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gBAAgB,CAC9B,WAAmB,EACnB,IAAY,EACZ,QAAgB;IAEhB,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,IAAI,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class PathSafetyError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare function resolveOutputPath(projectRoot: string, outputDir: string, filePath: string): string;
|
|
5
|
+
export declare function containsTraversal(filePath: string): boolean;
|
|
6
|
+
export declare function isPathSafe(filePath: string): boolean;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/paths/index.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CAOR;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAU3D;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKpD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
export class PathSafetyError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'PathSafetyError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function resolveOutputPath(projectRoot, outputDir, filePath) {
|
|
9
|
+
const resolved = path.resolve(projectRoot, outputDir, filePath);
|
|
10
|
+
const root = path.resolve(projectRoot);
|
|
11
|
+
if (!resolved.startsWith(root + path.sep) && resolved !== root) {
|
|
12
|
+
throw new PathSafetyError(`Path "${filePath}" escapes project root "${root}"`);
|
|
13
|
+
}
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
export function containsTraversal(filePath) {
|
|
17
|
+
const normalized = filePath.split(path.sep).join('/');
|
|
18
|
+
const parts = normalized.split('/');
|
|
19
|
+
let depth = 0;
|
|
20
|
+
for (const part of parts) {
|
|
21
|
+
if (part === '..')
|
|
22
|
+
depth--;
|
|
23
|
+
else if (part !== '.' && part !== '')
|
|
24
|
+
depth++;
|
|
25
|
+
if (depth < 0)
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
export function isPathSafe(filePath) {
|
|
31
|
+
if (filePath.includes('\0'))
|
|
32
|
+
return false;
|
|
33
|
+
if (path.isAbsolute(filePath))
|
|
34
|
+
return false;
|
|
35
|
+
if (containsTraversal(filePath))
|
|
36
|
+
return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/paths/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAC/B,WAAmB,EACnB,SAAiB,EACjB,QAAgB;IAEhB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,OA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
|
5
|
+
getByName(name: string): RegistryItem | undefined;
|
|
6
|
+
search(query: string): RegistryItem[];
|
|
7
|
+
}
|
|
8
|
+
export declare class BuiltinRegistryResolver implements RegistryResolver {
|
|
9
|
+
readonly name = "official";
|
|
10
|
+
private items;
|
|
11
|
+
constructor();
|
|
12
|
+
getAll(): RegistryItem[];
|
|
13
|
+
getByName(name: string): RegistryItem | undefined;
|
|
14
|
+
search(query: string): RegistryItem[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/registry/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,IAAI,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;CACvC;AAED,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,QAAQ,CAAC,IAAI,cAAc;IAC3B,OAAO,CAAC,KAAK,CAAsB;;IAMnC,MAAM,IAAI,YAAY,EAAE;IAIxB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIjD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE;CAetC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { buildRegistryItems } from '@snipl/official-registry';
|
|
2
|
+
export class BuiltinRegistryResolver {
|
|
3
|
+
name = 'official';
|
|
4
|
+
items = [];
|
|
5
|
+
constructor() {
|
|
6
|
+
this.items = buildRegistryItems();
|
|
7
|
+
}
|
|
8
|
+
getAll() {
|
|
9
|
+
return [...this.items];
|
|
10
|
+
}
|
|
11
|
+
getByName(name) {
|
|
12
|
+
return this.items.find((item) => item.name === name);
|
|
13
|
+
}
|
|
14
|
+
search(query) {
|
|
15
|
+
const lowerQuery = query.toLowerCase();
|
|
16
|
+
const scored = this.items.map((item) => {
|
|
17
|
+
let score = 0;
|
|
18
|
+
if (item.name === lowerQuery)
|
|
19
|
+
score += 100;
|
|
20
|
+
else if (item.name.startsWith(lowerQuery))
|
|
21
|
+
score += 50;
|
|
22
|
+
if (item.summary.toLowerCase().includes(lowerQuery))
|
|
23
|
+
score += 10;
|
|
24
|
+
if (item.tags.some((t) => t.toLowerCase().includes(lowerQuery)))
|
|
25
|
+
score += 5;
|
|
26
|
+
return { item, score };
|
|
27
|
+
});
|
|
28
|
+
return scored
|
|
29
|
+
.filter((s) => s.score > 0)
|
|
30
|
+
.sort((a, b) => b.score - a.score || a.item.name.localeCompare(b.item.name))
|
|
31
|
+
.map((s) => s.item);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../src/registry/resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAS9D,MAAM,OAAO,uBAAuB;IACzB,IAAI,GAAG,UAAU,CAAC;IACnB,KAAK,GAAmB,EAAE,CAAC;IAEnC;QACE,IAAI,CAAC,KAAK,GAAG,kBAAkB,EAAE,CAAC;IACpC,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,MAAM,UAAU,GAAG,KAAK,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",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ysr-hameed/snipl.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ysr-hameed/snipl/issues"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/src/index.js",
|
|
15
|
+
"types": "./dist/src/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/src/index.d.ts",
|
|
19
|
+
"default": "./dist/src/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/src",
|
|
24
|
+
"!dist/src/**/*.tsbuildinfo"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@snipl/official-registry": "1.0.0-next.1",
|
|
28
|
+
"@snipl/registry-schema": "1.0.0-next.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.7.0",
|
|
32
|
+
"vitest": "^3.0.0"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22.0.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -b",
|
|
39
|
+
"typecheck": "tsc -b",
|
|
40
|
+
"test": "vitest run"
|
|
41
|
+
}
|
|
42
|
+
}
|