Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/web-components-without-assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme-graph': patch
---

Build the theme graph for a theme without an `assets` folder. `getWebComponentMap` used to reject, so the language server never had a graph for that theme, even after the folder was created.
14 changes: 14 additions & 0 deletions packages/theme-graph/src/getWebComponentMap.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { path } from '@shopify/theme-check-common';
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { describe, expect, it } from 'vitest';
import { getWebComponentMap } from './getWebComponentMap';
import { makeGetSourceCode } from './graph/test-helpers';

describe('Unit: getWebComponentMap', () => {
it('returns an empty map for a theme without an assets folder', async () => {
const rootUri = path.normalize('file:/');
const fs = new MockFileSystem({ 'sections/main.liquid': '<price-tag></price-tag>' }, rootUri);
const map = await getWebComponentMap(rootUri, { fs, getSourceCode: makeGetSourceCode(fs) });
expect(map.size).toBe(0);
});
});
3 changes: 3 additions & 0 deletions packages/theme-graph/src/getWebComponentMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { path, recursiveReadDirectory } from '@shopify/theme-check-common';
import { ancestor as visit } from 'acorn-walk';
import { Dependencies, Void, WebComponentMap } from './types';
import { CallExpression } from 'acorn';
import { exists } from './utils';

/**
* Regular expression for web component names
Expand All @@ -26,6 +27,8 @@ export async function getWebComponentMap(
): Promise<WebComponentMap> {
const webComponentDefs: WebComponentMap = new Map();
const assetRoot = path.join(rootUri, 'assets');
if (!(await exists(fs, assetRoot))) return webComponentDefs;

const jsFiles = await recursiveReadDirectory(fs, assetRoot, ([fileName]) =>
fileName.endsWith('.js'),
);
Expand Down
Loading