New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/theme-language-server-common

Package Overview
Dependencies
Maintainers
24
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/theme-language-server-common - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

44

CHANGELOG.md
# @shopify/theme-language-server-common
## 1.10.0
### Minor Changes
- 767d223: Breaking: Redesign `jsonValidationSet` public API
(Only breaking for in-browser packages, node packages are still batteries-included)
Before:
```ts
type JsonValidationSet = {
sectionSchema(): Promise<string>;
translationSchema(): Promise<string>;
validateSectionSchema(): Promise<ValidateFunction>;
};
```
After:
```ts
type URI = string;
type SchemaDefinition = {
uri: string;
fileMatch?: string[];
schema: Promise<string>;
};
type JsonValidationSet = {
schemas: SchemaDefinition[];
};
```
We’re getting rid of [ajv](https://ajv.js.org/) and we’ll use [vscode-json-languageservice](https://github.com/microsoft/vscode-json-languageservice) in Theme Check instead. That dependency is required by the language server anyway, might as well reuse it instead of depending on a totally different solution for validation. We'll also get better reporting of Syntax Errors because the parser used by `vscode-json-languageservice` is better.
Moreover, this new design leaves space for `$ref` support.
### Patch Changes
- Updated dependencies [767d223]
- Updated dependencies [767d223]
- @shopify/theme-check-common@2.4.0
## 1.9.0

@@ -4,0 +48,0 @@

1

dist/json/JSONLanguageService.d.ts

@@ -10,2 +10,3 @@ import { JsonValidationSet } from '@shopify/theme-check-common';

private service;
private schemas;
constructor(documentManager: DocumentManager, jsonValidationSet: JsonValidationSet, getDefaultSchemaTranslations: GetTranslationsForURI);

@@ -12,0 +13,0 @@ setup(clientCapabilities: LSPClientCapabilities): void;

35

dist/json/JSONLanguageService.js

@@ -11,4 +11,2 @@ "use strict";

const SchemaTranslationContributions_1 = require("./SchemaTranslationContributions");
const SectionSchemaURI = 'https://raw.githubusercontent.com/Shopify/theme-liquid-docs/main/schemas/theme/section_schema.json';
const TranslationFileURI = 'https://raw.githubusercontent.com/Shopify/theme-liquid-docs/main/schemas/theme/translations_schema.json';
class JSONLanguageService {

@@ -20,2 +18,3 @@ constructor(documentManager, jsonValidationSet, getDefaultSchemaTranslations) {

this.service = null;
this.schemas = (0, theme_check_common_1.indexBy)((x) => x.uri, this.jsonValidationSet.schemas);
}

@@ -32,17 +31,6 @@ setup(clientCapabilities) {

this.service.configure({
schemas: [
{
uri: SectionSchemaURI,
fileMatch: ['**/sections/*.liquid'],
},
{
uri: TranslationFileURI,
fileMatch: [
'**/locales/*.json',
'**/locales/*.default.json',
'**/locales/*.schema.json',
'**/locales/*.default.schema.json',
],
},
],
schemas: this.jsonValidationSet.schemas.map((schemaDefinition) => ({
uri: schemaDefinition.uri,
fileMatch: schemaDefinition.fileMatch,
})),
});

@@ -102,10 +90,7 @@ }

async getSchemaForURI(uri) {
switch (uri) {
case SectionSchemaURI:
return this.jsonValidationSet.sectionSchema();
case TranslationFileURI:
return this.jsonValidationSet.translationSchema();
default:
throw new Error(`No schema for ${uri}`);
}
var _a;
const promise = (_a = this.schemas[uri]) === null || _a === void 0 ? void 0 : _a.schema;
if (!promise)
return `Could not get schema for '${uri}'`;
return promise;
}

@@ -112,0 +97,0 @@ }

@@ -13,2 +13,2 @@ import { Connection } from 'vscode-languageserver';

*/
export declare function startServer(connection: Connection, { fileExists, fileSize, filesForURI, findRootURI: findConfigurationRootURI, getDefaultLocaleFactory, getDefaultTranslationsFactory, getDefaultSchemaLocaleFactory, getDefaultSchemaTranslationsFactory, getThemeSettingsSchemaForRootURI, loadConfig, log, jsonValidationSet: remoteSchemaValidators, themeDocset: remoteThemeDocset, }: Dependencies): void;
export declare function startServer(connection: Connection, { fileExists, fileSize, filesForURI, findRootURI: findConfigurationRootURI, getDefaultLocaleFactory, getDefaultTranslationsFactory, getDefaultSchemaLocaleFactory, getDefaultSchemaTranslationsFactory, getThemeSettingsSchemaForRootURI, loadConfig, log, jsonValidationSet, themeDocset: remoteThemeDocset, }: Dependencies): void;

@@ -32,3 +32,3 @@ "use strict";

*/
function startServer(connection, { fileExists, fileSize, filesForURI, findRootURI: findConfigurationRootURI, getDefaultLocaleFactory, getDefaultTranslationsFactory, getDefaultSchemaLocaleFactory, getDefaultSchemaTranslationsFactory, getThemeSettingsSchemaForRootURI, loadConfig, log = defaultLogger, jsonValidationSet: remoteSchemaValidators, themeDocset: remoteThemeDocset, }) {
function startServer(connection, { fileExists, fileSize, filesForURI, findRootURI: findConfigurationRootURI, getDefaultLocaleFactory, getDefaultTranslationsFactory, getDefaultSchemaLocaleFactory, getDefaultSchemaTranslationsFactory, getThemeSettingsSchemaForRootURI, loadConfig, log = defaultLogger, jsonValidationSet, themeDocset: remoteThemeDocset, }) {
const clientCapabilities = new ClientCapabilities_1.ClientCapabilities();

@@ -51,3 +51,2 @@ const configuration = new Configuration_1.Configuration(connection, clientCapabilities);

const themeDocset = new theme_check_common_1.AugmentedThemeDocset(remoteThemeDocset);
const jsonValidationSet = new theme_check_common_1.AugmentedJsonValidationSet(remoteSchemaValidators);
const runChecks = (0, utils_1.debounce)((0, diagnostics_1.makeRunChecks)(documentManager, diagnosticsManager, {

@@ -54,0 +53,0 @@ fileExists,

{
"name": "@shopify/theme-language-server-common",
"version": "1.9.0",
"version": "1.10.0",
"main": "dist/index.js",

@@ -31,5 +31,5 @@ "types": "dist/index.d.ts",

"@shopify/liquid-html-parser": "^2.0.3",
"@shopify/theme-check-common": "2.3.0",
"@shopify/theme-check-common": "2.4.0",
"@vscode/web-custom-data": "^0.4.6",
"vscode-json-languageservice": "^5.3.9",
"vscode-json-languageservice": "^5.3.10",
"vscode-languageserver": "^8.0.2",

@@ -36,0 +36,0 @@ "vscode-languageserver-textdocument": "^1.0.8",

@@ -7,3 +7,2 @@ import { vi, expect, describe, it, beforeEach } from 'vitest';

SourceCodeType,
ValidateFunction,
} from '@shopify/theme-check-common';

@@ -75,5 +74,3 @@ import { Connection } from 'vscode-languageserver';

jsonValidationSet: {
validateSectionSchema: async () => ({} as ValidateFunction),
sectionSchema: async () => '{}',
translationSchema: async () => '{}',
schemas: [],
},

@@ -234,5 +231,3 @@ });

jsonValidationSet: {
validateSectionSchema: async () => ({} as ValidateFunction),
sectionSchema: async () => '{}',
translationSchema: async () => '{}',
schemas: [],
},

@@ -239,0 +234,0 @@ });

@@ -1,2 +0,2 @@

import { Translations, ValidateFunction } from '@shopify/theme-check-common';
import { Translations } from '@shopify/theme-check-common';
import { assert, beforeEach, describe, expect, it } from 'vitest';

@@ -69,17 +69,14 @@ import { CompletionParams, HoverParams } from 'vscode-languageserver';

{
async validateSectionSchema() {
const mockValidator: ValidateFunction = () => {
mockValidator.errors = [];
return false;
};
return mockValidator;
},
async sectionSchema() {
return simplifiedSectionSchema;
},
async translationSchema() {
return simplifiedTranslationSchema;
},
schemas: [
{
uri: 'https://shopify.dev/section-schema.json',
schema: Promise.resolve(simplifiedSectionSchema),
fileMatch: ['**/sections/*.liquid'],
},
{
uri: 'https://shopify.dev/translation-schema.json',
schema: Promise.resolve(simplifiedTranslationSchema),
fileMatch: ['**/locales/*.json'],
},
],
},

@@ -86,0 +83,0 @@ () => Promise.resolve(schemaTranslations),

import { LiquidRawTag, NodeTypes } from '@shopify/liquid-html-parser';
import { JsonValidationSet, SourceCodeType } from '@shopify/theme-check-common';
import {
JsonValidationSet,
SchemaDefinition,
SourceCodeType,
indexBy,
} from '@shopify/theme-check-common';
import { JSONDocument, LanguageService, getLanguageService } from 'vscode-json-languageservice';

@@ -19,10 +24,5 @@ import {

const SectionSchemaURI =
'https://raw.githubusercontent.com/Shopify/theme-liquid-docs/main/schemas/theme/section_schema.json';
const TranslationFileURI =
'https://raw.githubusercontent.com/Shopify/theme-liquid-docs/main/schemas/theme/translations_schema.json';
export class JSONLanguageService {
private service: LanguageService | null = null;
private schemas: Record<string, SchemaDefinition>;

@@ -33,3 +33,5 @@ constructor(

private getDefaultSchemaTranslations: GetTranslationsForURI,
) {}
) {
this.schemas = indexBy((x) => x.uri, this.jsonValidationSet.schemas);
}

@@ -46,17 +48,6 @@ setup(clientCapabilities: LSPClientCapabilities) {

this.service.configure({
schemas: [
{
uri: SectionSchemaURI,
fileMatch: ['**/sections/*.liquid'],
},
{
uri: TranslationFileURI,
fileMatch: [
'**/locales/*.json',
'**/locales/*.default.json',
'**/locales/*.schema.json',
'**/locales/*.default.schema.json',
],
},
],
schemas: this.jsonValidationSet.schemas.map((schemaDefinition) => ({
uri: schemaDefinition.uri,
fileMatch: schemaDefinition.fileMatch,
})),
});

@@ -127,11 +118,6 @@ }

private async getSchemaForURI(uri: string): Promise<string> {
switch (uri) {
case SectionSchemaURI:
return this.jsonValidationSet.sectionSchema();
case TranslationFileURI:
return this.jsonValidationSet.translationSchema();
default:
throw new Error(`No schema for ${uri}`);
}
const promise = this.schemas[uri]?.schema;
if (!promise) return `Could not get schema for '${uri}'`;
return promise;
}
}

@@ -11,3 +11,3 @@ import { vi, expect, describe, it, beforeEach, afterEach, assert } from 'vitest';

} from 'vscode-languageserver';
import { ValidateFunction, allChecks } from '@shopify/theme-check-common';
import { allChecks } from '@shopify/theme-check-common';
import { Dependencies } from '../types';

@@ -377,5 +377,3 @@ import { CHECK_ON_CHANGE, CHECK_ON_OPEN, CHECK_ON_SAVE } from './Configuration';

jsonValidationSet: {
validateSectionSchema: async () => ({} as ValidateFunction),
sectionSchema: async () => '{}',
translationSchema: async () => '{}',
schemas: [],
},

@@ -382,0 +380,0 @@ } as Dependencies;

@@ -1,2 +0,2 @@

import { AugmentedJsonValidationSet, AugmentedThemeDocset } from '@shopify/theme-check-common';
import { AugmentedThemeDocset } from '@shopify/theme-check-common';
import {

@@ -56,3 +56,3 @@ Connection,

log = defaultLogger,
jsonValidationSet: remoteSchemaValidators,
jsonValidationSet,
themeDocset: remoteThemeDocset,

@@ -80,3 +80,2 @@ }: Dependencies,

const themeDocset = new AugmentedThemeDocset(remoteThemeDocset);
const jsonValidationSet = new AugmentedJsonValidationSet(remoteSchemaValidators);
const runChecks = debounce(

@@ -83,0 +82,0 @@ makeRunChecks(documentManager, diagnosticsManager, {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc