This commit is contained in:
21
node_modules/@astrojs/yaml2ts/LICENSE
generated
vendored
21
node_modules/@astrojs/yaml2ts/LICENSE
generated
vendored
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 The Astro Technology Company
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1
node_modules/@astrojs/yaml2ts/dist/index.d.ts
generated
vendored
1
node_modules/@astrojs/yaml2ts/dist/index.d.ts
generated
vendored
@@ -1 +0,0 @@
|
||||
export { yaml2ts, VIRTUAL_CODE_ID, type YAML2TSResult } from './yaml2ts';
|
||||
7
node_modules/@astrojs/yaml2ts/dist/index.js
generated
vendored
7
node_modules/@astrojs/yaml2ts/dist/index.js
generated
vendored
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VIRTUAL_CODE_ID = exports.yaml2ts = void 0;
|
||||
var yaml2ts_1 = require("./yaml2ts");
|
||||
Object.defineProperty(exports, "yaml2ts", { enumerable: true, get: function () { return yaml2ts_1.yaml2ts; } });
|
||||
Object.defineProperty(exports, "VIRTUAL_CODE_ID", { enumerable: true, get: function () { return yaml2ts_1.VIRTUAL_CODE_ID; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
8
node_modules/@astrojs/yaml2ts/dist/yaml2ts.d.ts
generated
vendored
8
node_modules/@astrojs/yaml2ts/dist/yaml2ts.d.ts
generated
vendored
@@ -1,8 +0,0 @@
|
||||
import type { VirtualCode } from '@volar/language-core';
|
||||
import type { YAMLError } from 'yaml';
|
||||
export declare const VIRTUAL_CODE_ID = "frontmatter-ts";
|
||||
export type YAML2TSResult = {
|
||||
errors: YAMLError[];
|
||||
virtualCode: VirtualCode;
|
||||
};
|
||||
export declare function yaml2ts(frontmatter: string, collection: string): YAML2TSResult;
|
||||
144
node_modules/@astrojs/yaml2ts/dist/yaml2ts.js
generated
vendored
144
node_modules/@astrojs/yaml2ts/dist/yaml2ts.js
generated
vendored
@@ -1,144 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VIRTUAL_CODE_ID = void 0;
|
||||
exports.yaml2ts = yaml2ts;
|
||||
const yaml_1 = __importStar(require("yaml"));
|
||||
exports.VIRTUAL_CODE_ID = 'frontmatter-ts';
|
||||
const ONLY_NAV_CODE_INFO = {
|
||||
verification: false,
|
||||
completion: false,
|
||||
semantic: false,
|
||||
navigation: true,
|
||||
structure: false,
|
||||
format: false,
|
||||
};
|
||||
function yaml2ts(frontmatter, collection) {
|
||||
const frontmatterMappings = [];
|
||||
const frontmatterContent = (0, yaml_1.parseDocument)(frontmatter, {
|
||||
keepSourceTokens: true,
|
||||
customTags: ['timestamp'], // Handle YAML timestamps
|
||||
// Those two options prevent `yaml` from throwing errors when it encounters parsing errors, which is useful for handling incomplete content
|
||||
strict: false,
|
||||
logLevel: 'silent',
|
||||
});
|
||||
let fullResult = 'import type { InferEntrySchema } from "astro:content";\n\n(\n';
|
||||
let objectContent = frontmatter.trim().length > 0 ? '' : '{}'; // If there's no content, provide an empty object so that there's no syntax error
|
||||
yaml_1.default.visit(frontmatterContent, {
|
||||
Value(key, value) {
|
||||
if ((0, yaml_1.isCollection)(value)) {
|
||||
if ((0, yaml_1.isMap)(value)) {
|
||||
mapMap(value, key);
|
||||
}
|
||||
if ((0, yaml_1.isSeq)(value)) {
|
||||
mapSeq(value);
|
||||
}
|
||||
}
|
||||
// If we didn't hit any of the above, we have a scalar value which in almost all cases is a Pair that's just not fully written yet
|
||||
if ((0, yaml_1.isScalar)(value)) {
|
||||
const itemKey = mapScalarKey(value);
|
||||
// We don't care about values, just keys, since we're only interested in the structure
|
||||
objectContent += `${itemKey}: null\n`;
|
||||
}
|
||||
return yaml_1.default.visit.REMOVE;
|
||||
},
|
||||
});
|
||||
function mapMap(map, key) {
|
||||
objectContent += '{\n';
|
||||
// Go through all the items in the map
|
||||
map.items.forEach((item) => {
|
||||
// Pairs keys are not always scalars (they can even be totally arbitrary nodes), but in practice, it's really rare for them to be anything other than scalars
|
||||
// Anyway, Zod does not support non-scalar keys, so it's fine to just not handle anything other than scalars
|
||||
if ((0, yaml_1.isScalar)(item.key)) {
|
||||
const itemKey = mapScalarKey(item.key);
|
||||
if ((0, yaml_1.isScalar)(item.value) || item.value === null) {
|
||||
objectContent += `${itemKey}: null,\n`; // Don't care about value, just key
|
||||
}
|
||||
if ((0, yaml_1.isMap)(item.value)) {
|
||||
objectContent += `${itemKey}: `;
|
||||
mapMap(item.value);
|
||||
}
|
||||
if ((0, yaml_1.isSeq)(item.value)) {
|
||||
objectContent += `${itemKey}: `;
|
||||
mapSeq(item.value);
|
||||
}
|
||||
}
|
||||
return yaml_1.default.visit.REMOVE;
|
||||
});
|
||||
objectContent += '}';
|
||||
if (key !== null) {
|
||||
objectContent += ',';
|
||||
}
|
||||
objectContent += '\n';
|
||||
return yaml_1.default.visit.REMOVE;
|
||||
}
|
||||
function mapSeq(seq) {
|
||||
objectContent += '[';
|
||||
seq.items.forEach((item) => {
|
||||
if ((0, yaml_1.isScalar)(item)) {
|
||||
objectContent += `null,`;
|
||||
}
|
||||
if ((0, yaml_1.isMap)(item)) {
|
||||
mapMap(item);
|
||||
}
|
||||
if ((0, yaml_1.isSeq)(item)) {
|
||||
mapSeq(item);
|
||||
}
|
||||
return yaml_1.default.visit.REMOVE;
|
||||
});
|
||||
objectContent += '],\n';
|
||||
return yaml_1.default.visit.REMOVE;
|
||||
}
|
||||
function mapScalarKey(scalar) {
|
||||
// Stringify a YAML scalar key, handling invalid JS identifiers, escaping quotes etc. correctly.
|
||||
const itemKey = JSON.stringify(scalar.toJS(frontmatterContent));
|
||||
// Get the length of the original written key
|
||||
// This condition will always be true because we're only handling scalar keys
|
||||
const sourceTokenLength = yaml_1.CST.isScalar(scalar.srcToken) ? scalar.srcToken.source.length : 0;
|
||||
frontmatterMappings.push({
|
||||
generatedOffsets: [fullResult.length + objectContent.length],
|
||||
sourceOffsets: [scalar.range[0]], // For scalar keys, the range is always defined
|
||||
lengths: [sourceTokenLength],
|
||||
generatedLengths: [itemKey.length],
|
||||
data: ONLY_NAV_CODE_INFO,
|
||||
});
|
||||
return itemKey;
|
||||
}
|
||||
fullResult += `${objectContent}) satisfies InferEntrySchema<"${collection}">;\n\n`;
|
||||
return {
|
||||
errors: frontmatterContent.errors,
|
||||
virtualCode: {
|
||||
id: exports.VIRTUAL_CODE_ID,
|
||||
languageId: 'typescript',
|
||||
snapshot: {
|
||||
getText: (start, end) => fullResult.substring(start, end),
|
||||
getLength: () => fullResult.length,
|
||||
getChangeRange: () => undefined,
|
||||
},
|
||||
mappings: frontmatterMappings,
|
||||
},
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=yaml2ts.js.map
|
||||
25
node_modules/@astrojs/yaml2ts/package.json
generated
vendored
25
node_modules/@astrojs/yaml2ts/package.json
generated
vendored
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "@astrojs/yaml2ts",
|
||||
"version": "0.2.2",
|
||||
"description": "Package to convert a YAML string to a Volar VirtualCode, to be used by the Astro language server to provide intellisense",
|
||||
"type": "commonjs",
|
||||
"main": "dist/index.js",
|
||||
"files": [
|
||||
"dist/**/*.js",
|
||||
"dist/**/*.d.ts"
|
||||
],
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"yaml": "^2.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@volar/language-core": "~2.4.7",
|
||||
"typescript": "^5.5.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user