Skip to content
Open
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
32 changes: 32 additions & 0 deletions .changeset/tiny-cycles-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'@shopify/theme-language-server-common': major
'@shopify/theme-check-common': major
'theme-check-vscode': patch
---

Define the public entry points with a package `exports` map

- `@shopify/theme-check-common` exports `.`, `./path`, `./test`, and `./package.json`.
- `@shopify/theme-language-server-common` exports `.`, `./types`, and `./package.json`.

Importing a subpath pulls in only that module instead of the whole package. The VS Code extension
uses this to keep the language server out of the client bundle: `browser/extension.js` is 2.1 MB
instead of 6.7 MB, and `node/extension.js` is 1.4 MB instead of 6.5 MB. Barrel imports still work
exactly as before.

**Breaking:** the `exports` map is now the complete public surface of both packages. Any `src/` or
`dist/` deep import that is not listed above no longer resolves — Node and bundlers throw
`ERR_PACKAGE_PATH_NOT_EXPORTED`.

To migrate:

- Replace `@shopify/theme-check-common/src/test` or `.../dist/test` with
`@shopify/theme-check-common/test`.
- Seven symbols previously reachable only through a retired deep import are now exported from the
`@shopify/theme-check-common` barrel: `getPosition`, `createDisabledChecksModule`,
`UNMATCHED_COMMENT_CLOSE_PARSER_ERROR`, `UNMATCHED_RAW_CLOSE_PARSER_ERROR`,
`hasRubyAcceptedInertCommentBodyCloser`, `hasJavascriptClosingTagAfter`, and
`hasRubyAcceptedRawTagCloserWithMarkup`.

Every other symbol those modules exposed is intentionally private. If you depend on one, open an
issue so it can be promoted deliberately.
25 changes: 25 additions & 0 deletions packages/theme-check-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./path": {
"types": "./dist/path.d.ts",
"default": "./dist/path.js"
},
"./test": {
"types": "./dist/test/index.d.ts",
"default": "./dist/test/index.js"
},
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"path": [
"dist/path.d.ts"
],
"test": [
"dist/test/index.d.ts"
]
}
},
"author": "CP Clermont <cp.clermont@shopify.com>",
"homepage": "https://github.com/Shopify/theme-tools/tree/main/packages/theme-check-common#readme",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions packages/theme-check-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ import { visitJSON, visitLiquid } from './visitors';
export * from './AbstractFileSystem';
export * from './AugmentedThemeDocset';
export * from './checks';
export {
UNMATCHED_COMMENT_CLOSE_PARSER_ERROR,
UNMATCHED_RAW_CLOSE_PARSER_ERROR,
hasRubyAcceptedInertCommentBodyCloser,
} from './checks/liquid-syntax-error/comment';
export { hasJavascriptClosingTagAfter } from './checks/liquid-syntax-error/javascript';
export { hasRubyAcceptedRawTagCloserWithMarkup } from './checks/liquid-syntax-error/utils';
export * from './context-utils';
export { createDisabledChecksModule } from './disabled-checks';
export * from './find-root';
export * from './fixes';
export * from './ignore';
Expand All @@ -54,6 +62,7 @@ export * from './types';
export * from './utils/error';
export * from './utils/indexBy';
export * from './utils/memo';
export { getPosition } from './utils/position';
export * from './utils/types';
export * from './utils/object';
export * from './utils/styles';
Expand Down
55 changes: 55 additions & 0 deletions packages/theme-check-common/src/package-exports.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { createRequire } from 'node:module';
import { describe, expect, it } from 'vitest';

const requireFromHere = createRequire(__filename);

function resolutionErrorCode(specifier: string): string | undefined {
try {
requireFromHere.resolve(specifier);
return undefined;
} catch (error) {
return (error as NodeJS.ErrnoException).code;
}
}

describe('Module: package exports', () => {
it.each([
['@shopify/theme-check-common', 'theme-check-common/dist/index.js'],
['@shopify/theme-check-common/path', 'theme-check-common/dist/path.js'],
['@shopify/theme-check-common/test', 'theme-check-common/dist/test/index.js'],
['@shopify/theme-check-common/package.json', 'theme-check-common/package.json'],
])('resolves %s', (specifier, suffix) => {
expect(requireFromHere.resolve(specifier).replace(/\\/g, '/')).toContain(suffix);
});

it.each([
'@shopify/theme-check-common/src/index',
'@shopify/theme-check-common/src/test',
'@shopify/theme-check-common/dist/index',
'@shopify/theme-check-common/dist/test',
'@shopify/theme-check-common/dist/path',
'@shopify/theme-check-common/dist/utils',
'@shopify/theme-check-common/dist/disabled-checks',
'@shopify/theme-check-common/dist/checks/liquid-syntax-error/comment',
'@shopify/theme-check-common/dist/checks/liquid-syntax-error/javascript',
'@shopify/theme-check-common/dist/checks/liquid-syntax-error/utils',
])('no longer exposes %s', (specifier) => {
expect(resolutionErrorCode(specifier)).toBe('ERR_PACKAGE_PATH_NOT_EXPORTED');
});

it('exposes the promoted symbols on the barrel', () => {
const themeCheckCommon = requireFromHere('@shopify/theme-check-common');

for (const name of [
'getPosition',
'createDisabledChecksModule',
'UNMATCHED_COMMENT_CLOSE_PARSER_ERROR',
'UNMATCHED_RAW_CLOSE_PARSER_ERROR',
'hasRubyAcceptedInertCommentBodyCloser',
'hasJavascriptClosingTagAfter',
'hasRubyAcceptedRawTagCloserWithMarkup',
]) {
expect(themeCheckCommon).toHaveProperty(name);
}
});
});
18 changes: 18 additions & 0 deletions packages/theme-language-server-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
"version": "2.22.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./types": {
"types": "./dist/types.d.ts",
"default": "./dist/types.js"
},
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"types": [
"dist/types.d.ts"
]
}
},
"author": "CP Clermont <cp.clermont@shopify.com>",
"homepage": "https://github.com/Shopify/theme-tools/tree/main/packages/theme-language-server-common#readme",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Severity,
SourceCodeType,
} from '@shopify/theme-check-common';
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { MockFileSystem } from '@shopify/theme-check-common/test';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { Connection } from 'vscode-languageserver';
import { DocumentManager } from '../documents';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ThemeBlock,
ThemeSchemaType,
} from '@shopify/theme-check-common';
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { MockFileSystem } from '@shopify/theme-check-common/test';
import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
import { URI, Utils } from 'vscode-uri';
import { DocumentManager } from './DocumentManager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe, beforeEach, it, expect } from 'vitest';
import { DocumentManager } from '../../documents';
import { HoverProvider } from '../HoverProvider';
import { MetafieldDefinitionMap } from '@shopify/theme-check-common';
import '../../../../theme-check-common/src/test/test-setup';
import { formatLiquidDocTagHandle, SUPPORTED_LIQUID_DOC_TAG_HANDLES } from '../../utils/liquidDoc';

describe('Module: RenderSnippetParameterHoverProvider', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createRequire } from 'node:module';
import { describe, expect, it } from 'vitest';

const requireFromHere = createRequire(__filename);

function resolutionErrorCode(specifier: string): string | undefined {
try {
requireFromHere.resolve(specifier);
return undefined;
} catch (error) {
return (error as NodeJS.ErrnoException).code;
}
}

describe('Module: package exports', () => {
it.each([
['@shopify/theme-language-server-common', 'theme-language-server-common/dist/index.js'],
['@shopify/theme-language-server-common/types', 'theme-language-server-common/dist/types.js'],
[
'@shopify/theme-language-server-common/package.json',
'theme-language-server-common/package.json',
],
])('resolves %s', (specifier, suffix) => {
expect(requireFromHere.resolve(specifier).replace(/\\/g, '/')).toContain(suffix);
});

it.each([
'@shopify/theme-language-server-common/src/index',
'@shopify/theme-language-server-common/src/types',
'@shopify/theme-language-server-common/dist/index',
'@shopify/theme-language-server-common/dist/types',
])('no longer exposes %s', (specifier) => {
expect(resolutionErrorCode(specifier)).toBe('ERR_PACKAGE_PATH_NOT_EXPORTED');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { MockFileSystem } from '@shopify/theme-check-common/test';
import { assert, beforeEach, describe, expect, it } from 'vitest';
import { TextDocumentEdit } from 'vscode-json-languageservice';
import { ApplyWorkspaceEditParams } from 'vscode-languageserver-protocol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { MockFileSystem } from '@shopify/theme-check-common/test';
import { assert, beforeEach, describe, expect, it } from 'vitest';
import { TextDocumentEdit } from 'vscode-json-languageservice';
import { ApplyWorkspaceEditParams } from 'vscode-languageserver-protocol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { MockFileSystem } from '@shopify/theme-check-common/test';
import { assert, beforeEach, describe, expect, it } from 'vitest';
import { TextDocumentEdit } from 'vscode-json-languageservice';
import { ApplyWorkspaceEditParams } from 'vscode-languageserver-protocol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockFileSystem } from '@shopify/theme-check-common/src/test';
import { MockFileSystem } from '@shopify/theme-check-common/test';
import { assert, beforeEach, describe, expect, it } from 'vitest';
import { TextDocumentEdit } from 'vscode-json-languageservice';
import { ApplyWorkspaceEditParams } from 'vscode-languageserver-protocol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { allChecks, path } from '@shopify/theme-check-common';
import { MockFileSystem, MockTheme } from '@shopify/theme-check-common/dist/test';
import { MockFileSystem, MockTheme } from '@shopify/theme-check-common/test';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import {
DidChangeConfigurationNotification,
Expand Down
1 change: 1 addition & 0 deletions packages/theme-language-server-common/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lib": ["es2022", "dom"],
"paths": {
"@shopify/theme-check-common": ["../../theme-check-common/src"],
"@shopify/theme-check-common/test": ["../../theme-check-common/src/test"],
"@shopify/liquid-html-parser": ["../../liquid-html-parser/src"],
"@shopify/theme-graph": ["../../theme-graph/src"]
}
Expand Down
3 changes: 2 additions & 1 deletion packages/vscode-extension/src/browser/extension.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the outcome of this PR but not a huge fan of how we're getting there. Reaching into the dist folder is creating an implicit connection to theme-check-common's build process. I'd rather fix this in theme-check-common itself by adding some public subpath exports that we intend for consumers to use.

Also side note: I don't think the type imports need this? I don't think these are included at runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion Gray.

Type imports - you were totally right so I put it back the way it was.

Instead of reaching into the dist folder they got moved into the packages themselves and they each have an entry point pointing to the actual file. No more weird connections.

I tried the subpath exports but I ran into a couple problems. Our TS setup falls back to the older resolution mode and it ignores exports completely. When I tried setting up the new mode if a path wasn't explicitly listed it stopped resolving. It messed up deep-imports of MockTheme and MockFileSystem`. My concern is if any user of the libraries has deep links we would probably break for them as well.

What do you think about this current method vs the subpath export?

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference lib="webworker" />
import { FileStat, FileTuple, path } from '@shopify/theme-check-common';
import * as path from '@shopify/theme-check-common/path';
import type { FileStat, FileTuple } from '@shopify/theme-check-common';
import { commands, ExtensionContext, languages, Uri, workspace } from 'vscode';
import {
LanguageClient,
Expand Down
7 changes: 3 additions & 4 deletions packages/vscode-extension/src/common/ReferencesProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { path } from '@shopify/theme-check-common';
import * as path from '@shopify/theme-check-common/path';
import {
AugmentedLocation,
AugmentedReference,
ThemeGraphDependenciesRequest,
ThemeGraphDidUpdateNotification,
ThemeGraphReferenceRequest,
ThemeGraphRootRequest,
} from '@shopify/theme-language-server-common';
} from '@shopify/theme-language-server-common/types';
import type { AugmentedLocation, AugmentedReference } from '@shopify/theme-language-server-common';
import {
commands,
Event,
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/common/VsCodeFileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractFileSystem, FileTuple, FileStat } from '@shopify/theme-check-common';
import type { AbstractFileSystem, FileStat, FileTuple } from '@shopify/theme-check-common';
import { Connection } from 'vscode-languageserver';
import { URI } from 'vscode-uri';

Expand Down
6 changes: 3 additions & 3 deletions packages/vscode-extension/src/common/commands.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { path } from '@shopify/theme-check-common';
import * as path from '@shopify/theme-check-common/path';
import {
AugmentedLocation,
ThemeGraphDeadCodeRequest,
ThemeGraphRootRequest,
} from '@shopify/theme-language-server-common';
} from '@shopify/theme-language-server-common/types';
import type { AugmentedLocation } from '@shopify/theme-language-server-common';
import { commands, Position, Range, Uri, window, workspace } from 'vscode';
import { BaseLanguageClient } from 'vscode-languageclient';

Expand Down
3 changes: 2 additions & 1 deletion packages/vscode-extension/src/node/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FileStat, FileTuple, path as pathUtils } from '@shopify/theme-check-common';
import * as pathUtils from '@shopify/theme-check-common/path';
import type { FileStat, FileTuple } from '@shopify/theme-check-common';
import * as path from 'node:path';
import { commands, ExtensionContext, languages, Uri, workspace } from 'vscode';
import {
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@
"@shopify/theme-check-common": [
"./packages/theme-check-common/src/index"
],
"@shopify/theme-check-common/path": [
"./packages/theme-check-common/src/path"
],
"@shopify/theme-check-common/test": [
"./packages/theme-check-common/src/test/index"
],
"@shopify/theme-language-server-common": [
"./packages/theme-language-server-common/src/index"
],
"@shopify/theme-language-server-common/types": [
"./packages/theme-language-server-common/src/types"
]
},
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
Expand Down
Loading