@platformos/platformos-graph 0.0.2

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +83 -0
  3. package/bin/jsconfig.json +18 -0
  4. package/bin/platformos-graph +107 -0
  5. package/dist/getWebComponentMap.d.ts +10 -0
  6. package/dist/getWebComponentMap.js +66 -0
  7. package/dist/getWebComponentMap.js.map +1 -0
  8. package/dist/graph/augment.d.ts +2 -0
  9. package/dist/graph/augment.js +22 -0
  10. package/dist/graph/augment.js.map +1 -0
  11. package/dist/graph/build.d.ts +3 -0
  12. package/dist/graph/build.js +31 -0
  13. package/dist/graph/build.js.map +1 -0
  14. package/dist/graph/module.d.ts +10 -0
  15. package/dist/graph/module.js +181 -0
  16. package/dist/graph/module.js.map +1 -0
  17. package/dist/graph/serialize.d.ts +2 -0
  18. package/dist/graph/serialize.js +18 -0
  19. package/dist/graph/serialize.js.map +1 -0
  20. package/dist/graph/test-helpers.d.ts +33 -0
  21. package/dist/graph/test-helpers.js +49 -0
  22. package/dist/graph/test-helpers.js.map +1 -0
  23. package/dist/graph/traverse.d.ts +14 -0
  24. package/dist/graph/traverse.js +458 -0
  25. package/dist/graph/traverse.js.map +1 -0
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.js +31 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/toSourceCode.d.ts +8 -0
  30. package/dist/toSourceCode.js +76 -0
  31. package/dist/toSourceCode.js.map +1 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -0
  33. package/dist/types.d.ts +144 -0
  34. package/dist/types.js +13 -0
  35. package/dist/types.js.map +1 -0
  36. package/dist/utils/index.d.ts +11 -0
  37. package/dist/utils/index.js +47 -0
  38. package/dist/utils/index.js.map +1 -0
  39. package/docs/graph.png +0 -0
  40. package/docs/how-it-works.md +89 -0
  41. package/fixtures/skeleton/app/views/partials/child.liquid +9 -0
  42. package/fixtures/skeleton/app/views/partials/parent.liquid +9 -0
  43. package/fixtures/skeleton/assets/theme.css +0 -0
  44. package/fixtures/skeleton/assets/theme.js +7 -0
  45. package/fixtures/skeleton/blocks/_private.liquid +1 -0
  46. package/fixtures/skeleton/blocks/_static.liquid +10 -0
  47. package/fixtures/skeleton/blocks/group.liquid +27 -0
  48. package/fixtures/skeleton/blocks/render-static.liquid +22 -0
  49. package/fixtures/skeleton/blocks/text.liquid +14 -0
  50. package/fixtures/skeleton/jsconfig.json +9 -0
  51. package/fixtures/skeleton/layout/theme.liquid +14 -0
  52. package/fixtures/skeleton/sections/custom-section.liquid +6 -0
  53. package/fixtures/skeleton/sections/header-group.json +36 -0
  54. package/fixtures/skeleton/sections/header.liquid +1 -0
  55. package/fixtures/skeleton/templates/index.json +20 -0
  56. package/package.json +41 -0
  57. package/src/getWebComponentMap.ts +81 -0
  58. package/src/graph/augment.ts +34 -0
  59. package/src/graph/build.spec.ts +248 -0
  60. package/src/graph/build.ts +45 -0
  61. package/src/graph/module.ts +212 -0
  62. package/src/graph/serialize.spec.ts +62 -0
  63. package/src/graph/serialize.ts +20 -0
  64. package/src/graph/test-helpers.ts +57 -0
  65. package/src/graph/traverse.ts +639 -0
  66. package/src/index.ts +5 -0
  67. package/src/toSourceCode.ts +80 -0
  68. package/src/types.ts +213 -0
  69. package/src/utils/index.ts +51 -0
  70. package/tsconfig.build.json +20 -0
  71. package/tsconfig.json +37 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # shopify/theme-graph
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Beta release
8
+ - Updated dependencies
9
+ - @platformos/liquid-html-parser@0.0.2
10
+ - @platformos/platformos-check-common@0.0.2
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ <h1 align="center" style="position: relative;" >
2
+ <br>
3
+ <img src="https://github.com/Platform-OS/platformos-tools/blob/main/packages/vscode-extension/images/platformos_logo.png?raw=true" alt="platformOS logo" width="200">
4
+ <br>
5
+ platformOS Graph
6
+ </h1>
7
+
8
+ <h4 align="center">A data structure that represents your platformOS application</h4>
9
+
10
+ A platformOS Graph is a data structure that spans Liquid, JSON, JavaScript and CSS files.
11
+
12
+ It has the following interface:
13
+
14
+ ```ts
15
+ interface ThemeGraph {
16
+ rootUri: UriString; // e.g. 'file:/path/to/horizon'
17
+ entryPoints: ThemeModule[];
18
+ modules: Record<UriString, ThemeModule>
19
+ }
20
+ ```
21
+
22
+ A `ThemeModule` holds _dependencies_ and _references_ of a module. For instance,
23
+
24
+ ```ts
25
+ interface LiquidModule {
26
+ uri: UriString;
27
+ type: 'liquid';
28
+ kind: 'block' | 'layout' | 'section' | 'snippet' | 'template';
29
+ references: Reference[];
30
+ dependencies: Reference[];
31
+ }
32
+ ```
33
+
34
+ For a module $M$,
35
+ - a _reference_ is a backlink to _other_ modules that depend on $M$,
36
+ - a _dependency_ is a dependent link on another module.
37
+
38
+ ```ts
39
+ interface Reference {
40
+ /* The file that initiated the dependency/reference */
41
+ source: { uri: string, range?: Range };
42
+
43
+ /* The file that it points to */
44
+ target: { uri: string, range?: Range };
45
+
46
+ type:
47
+ | 'direct' // e.g. {% render 'child' %}, {{ 'theme.js' | asset_url }}, <custom-element>, etc.
48
+ | 'indirect' // e.g. Sections and blocks that accept theme blocks
49
+ | 'preset' // e.g. Section and block presets
50
+ }
51
+ ```
52
+
53
+ See [types.md](./src/types.ts) for more details and [how-it-works.md](./docs/how-it-works.md) for an overview of the algorithm.
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ npm install @platformos/theme-graph
59
+ ```
60
+
61
+ ## Usage
62
+
63
+ ### Through the VS Code extension
64
+
65
+ The theme graph is used by the VS Code extension to power the dependencies, references and dead code features.
66
+
67
+ ### From the CLI
68
+
69
+ ```
70
+ Usage:
71
+ theme-graph <path-to-theme-directory>
72
+
73
+ Example:
74
+ theme-graph horizon > graph.json
75
+ ```
76
+
77
+ ### As a library
78
+
79
+ [See bin/theme-graph](./bin/theme-graph) for inspiration.
80
+
81
+ ## Contributing
82
+
83
+ See [CONTRIBUTING.md](../../docs/contributing.md).
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "checkJs": true,
6
+ "strict": true,
7
+ "baseUrl": ".",
8
+ "paths": {
9
+ "@platformos/platformos-graph": ["../src"],
10
+ "@platformos/platformos-check-common": ["../../platformos-check-common/src"]
11
+ },
12
+ "allowJs": true,
13
+ "noEmit": true,
14
+ "esModuleInterop": true,
15
+ "skipLibCheck": true
16
+ },
17
+ "files": ["./platformos-graph"]
18
+ }
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { buildThemeGraph, serializeThemeGraph, toSourceCode } = require('@platformos/theme-graph');
4
+ const {
5
+ NodeFileSystem,
6
+ memoize,
7
+ toSchema,
8
+ path: pathUtils,
9
+ recursiveReadDirectory,
10
+ } = require('@platformos/theme-check-node');
11
+ const path = require('path');
12
+ const { URI } = require('vscode-uri');
13
+
14
+ const usage = `
15
+ Usage:
16
+ theme-graph <path-to-theme-directory>
17
+
18
+ Example:
19
+ theme-graph horizon > graph.json
20
+ `;
21
+
22
+ const identity = (/** @type {any} */ x) => x;
23
+
24
+ /**
25
+ * Outputs the JSON representing the theme graph for a Shopify theme directory.
26
+ *
27
+ * @param {string} root
28
+ */
29
+ async function main(root) {
30
+ if (!root) {
31
+ console.error(usage);
32
+ process.exit(1);
33
+ }
34
+
35
+ if (!path.isAbsolute(root)) {
36
+ root = path.resolve(process.cwd(), root);
37
+ }
38
+
39
+ const getSourceCode = makeGetSourceCode();
40
+
41
+ // Preload files to get a sense of what is slow
42
+ const fs = NodeFileSystem;
43
+ const rootUri = URI.file(root).toString(true);
44
+ const filesToPreload = await recursiveReadDirectory(fs, rootUri, ([uri]) =>
45
+ ['.json', '.liquid'].some((ext) => uri.endsWith(ext)),
46
+ );
47
+ await bench('Preloading files', async () => {
48
+ await Promise.all(
49
+ filesToPreload.map(async (uri) => {
50
+ await getSourceCode(uri);
51
+ }),
52
+ );
53
+ });
54
+
55
+ /** @type {import('@platformos/theme-graph').WebComponentMap} */
56
+ const webComponentDefs = new Map();
57
+
58
+ /** @type {import('@platformos/theme-graph').Dependencies} */
59
+ const dependencies = {
60
+ fs,
61
+ // @ts-ignore
62
+ getSectionSchema: memoize(async (name) => {
63
+ const uri = pathUtils.join(rootUri, 'sections', `${name}.liquid`);
64
+ const sourceCode = await getSourceCode(uri);
65
+ return toSchema('theme', uri, /** @type {any} */ (sourceCode), async () => true);
66
+ }, identity),
67
+ // @ts-ignore
68
+ getBlockSchema: memoize(async (name) => {
69
+ const uri = pathUtils.join(rootUri, 'blocks', `${name}.liquid`);
70
+ const sourceCode = await getSourceCode(uri);
71
+ return toSchema('theme', uri, /** @type {any} */ (sourceCode), async () => true);
72
+ }, identity),
73
+ getSourceCode,
74
+ getWebComponentDefinitionReference: (customElementName) =>
75
+ webComponentDefs.get(customElementName),
76
+ };
77
+
78
+ // Build graph
79
+ const graph = await bench('Build graph', () => buildThemeGraph(rootUri, dependencies));
80
+
81
+ // Serialize into JSON
82
+ const serializedGraph = serializeThemeGraph(graph);
83
+
84
+ // Print result to STDOUT
85
+ console.log(JSON.stringify(serializedGraph));
86
+ }
87
+
88
+ function makeGetSourceCode() {
89
+ return memoize(async function getSourceCode(uri) {
90
+ const source = await NodeFileSystem.readFile(uri);
91
+ return await toSourceCode(URI.file(uri).toString(), source);
92
+ }, identity);
93
+ }
94
+
95
+ /**
96
+ * @param {string} name
97
+ * @param {(...args: any[]) => Promise<any>} fn
98
+ */
99
+ async function bench(name, fn) {
100
+ const start = performance.now();
101
+ const result = await fn();
102
+ const end = performance.now();
103
+ console.error(`${name} took ${end - start}ms`);
104
+ return result;
105
+ }
106
+
107
+ main(process.argv[2]);
@@ -0,0 +1,10 @@
1
+ import { Dependencies, Void, WebComponentMap } from './types';
2
+ /**
3
+ * Find all the web component definitions from the JavaScript files in the
4
+ * assets directory.
5
+ *
6
+ * From those, we'll be able to map `<custom-element-name>` to the definition in
7
+ * the corresponding asset file.
8
+ */
9
+ export declare function getWebComponentMap(rootUri: string, { fs, getSourceCode }: Pick<Dependencies, 'fs' | 'getSourceCode'>): Promise<WebComponentMap>;
10
+ export declare function findWebComponentReferences(uri: string, assetRoot: string, getSourceCode: Dependencies['getSourceCode'], result: WebComponentMap): Promise<Void>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebComponentMap = getWebComponentMap;
4
+ exports.findWebComponentReferences = findWebComponentReferences;
5
+ const platformos_check_common_1 = require("@platformos/platformos-check-common");
6
+ const acorn_walk_1 = require("acorn-walk");
7
+ /**
8
+ * Regular expression for web component names
9
+ *
10
+ * Based on the HTML specification for valid custom element names.
11
+ *
12
+ * https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
13
+ */
14
+ const wcre = /^[a-z][-.\d_a-z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*([-][-.\d_a-z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*)$/u;
15
+ /**
16
+ * Find all the web component definitions from the JavaScript files in the
17
+ * assets directory.
18
+ *
19
+ * From those, we'll be able to map `<custom-element-name>` to the definition in
20
+ * the corresponding asset file.
21
+ */
22
+ async function getWebComponentMap(rootUri, { fs, getSourceCode }) {
23
+ const webComponentDefs = new Map();
24
+ const assetRoot = platformos_check_common_1.path.join(rootUri, 'assets');
25
+ const jsFiles = await (0, platformos_check_common_1.recursiveReadDirectory)(fs, assetRoot, ([fileName]) => fileName.endsWith('.js'));
26
+ await Promise.all(jsFiles.map((uri) => findWebComponentReferences(uri, assetRoot, getSourceCode, webComponentDefs)));
27
+ return webComponentDefs;
28
+ }
29
+ async function findWebComponentReferences(uri, assetRoot, getSourceCode, result) {
30
+ const sourceCode = await getSourceCode(uri);
31
+ if (sourceCode.type !== 'javascript') {
32
+ return;
33
+ }
34
+ const ast = sourceCode.ast;
35
+ if (ast instanceof Error) {
36
+ return;
37
+ }
38
+ for (const node of ast.body) {
39
+ (0, acorn_walk_1.ancestor)(node, {
40
+ Literal(node, _state, ancestors) {
41
+ if (typeof node.value === 'string' && wcre.test(node.value)) {
42
+ // Making sure we're looking at customElements.define calls
43
+ const parentNode = ancestors.at(-2);
44
+ if (!parentNode)
45
+ return;
46
+ if (parentNode.type !== 'CallExpression')
47
+ return;
48
+ const callee = parentNode.callee;
49
+ if (callee.type !== 'MemberExpression')
50
+ return;
51
+ const property = callee.property;
52
+ if (property.type !== 'Identifier')
53
+ return;
54
+ if (property.name !== 'define')
55
+ return;
56
+ result.set(node.value, {
57
+ assetName: platformos_check_common_1.path.relative(uri, assetRoot),
58
+ range: [property.start, node.end],
59
+ });
60
+ }
61
+ return null;
62
+ },
63
+ });
64
+ }
65
+ }
66
+ //# sourceMappingURL=getWebComponentMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWebComponentMap.js","sourceRoot":"","sources":["../src/getWebComponentMap.ts"],"names":[],"mappings":";;AAsBA,gDAiBC;AAED,gEAuCC;AAhFD,iFAAmF;AACnF,2CAA+C;AAI/C;;;;;;GAMG;AACH,MAAM,IAAI,GACR,+UAA+U,CAAC;AAElV;;;;;;GAMG;AACI,KAAK,UAAU,kBAAkB,CACtC,OAAe,EACf,EAAE,EAAE,EAAE,aAAa,EAA8C;IAEjE,MAAM,gBAAgB,GAAoB,IAAI,GAAG,EAAE,CAAC;IACpD,MAAM,SAAS,GAAG,8BAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/C,MAAM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I,KAAK,kBAAkB;wBAAE,OAAO;oBAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;oBACjC,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY;wBAAE,OAAO;oBAC3C,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ;wBAAE,OAAO;oBAEvC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE;wBACrB,SAAS,EAAE,8BAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;wBACxC,KAAK,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC;qBAClC,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { AugmentedDependencies, IDependencies } from '../types';
2
+ export declare function augmentDependencies(rootUri: string, ideps: IDependencies): AugmentedDependencies;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.augmentDependencies = augmentDependencies;
4
+ const platformos_check_common_1 = require("@platformos/platformos-check-common");
5
+ const toSourceCode_1 = require("../toSourceCode");
6
+ const utils_1 = require("../utils");
7
+ function augmentDependencies(rootUri, ideps) {
8
+ return {
9
+ fs: ideps.fs,
10
+ getBlockSchema: (0, platformos_check_common_1.memoize)(ideps.getBlockSchema, utils_1.identity),
11
+ getSectionSchema: (0, platformos_check_common_1.memoize)(ideps.getSectionSchema, utils_1.identity),
12
+ // parse at most once
13
+ getSourceCode: (0, platformos_check_common_1.memoize)(ideps.getSourceCode ??
14
+ async function defaultGetSourceCode(uri) {
15
+ const contents = await ideps.fs.readFile(uri);
16
+ return (0, toSourceCode_1.toSourceCode)(uri, contents);
17
+ }, utils_1.identity),
18
+ getWebComponentDefinitionReference: ideps.getWebComponentDefinitionReference,
19
+ getThemeBlockNames: (0, platformos_check_common_1.memo)(() => (0, platformos_check_common_1.recursiveReadDirectory)(ideps.fs, platformos_check_common_1.path.join(rootUri, 'blocks'), ([uri]) => uri.endsWith('.liquid')).then((uris) => uris.map((uri) => platformos_check_common_1.path.basename(uri, '.liquid')))),
20
+ };
21
+ }
22
+ //# sourceMappingURL=augment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augment.js","sourceRoot":"","sources":["../../src/graph/augment.ts"],"names":[],"mappings":";;AAUA,kDAuBC;AAjCD,iFAK6C;AAC7C,kDAA+C;AAE/C,oCAAoC;AAEpC,SAAgB,mBAAmB,CAAC,OAAe,EAAE,KAAoB;IACvE,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,cAAc,EAAE,IAAA,iCAAO,EAAC,KAAK,CAAC,cAAc,EAAE,gBAAQ,CAAC;QACvD,gBAAgB,EAAE,IAAA,iCAAO,EAAC,KAAK,CAAC,gBAAgB,EAAE,gBAAQ,CAAC;QAE3D,qBAAqB;QACrB,aAAa,EAAE,IAAA,iCAAO,EACpB,KAAK,CAAC,aAAa;YACjB,KAAK,UAAU,oBAAoB,CAAC,GAAG;gBACrC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC9C,OAAO,IAAA,2BAAY,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACrC,CAAC,EACH,gBAAQ,CACT;QAED,kCAAkC,EAAE,KAAK,CAAC,kCAAkC;QAC5E,kBAAkB,EAAE,IAAA,8BAAI,EAAC,GAAG,EAAE,CAC5B,IAAA,gDAAY,EAAC,KAAK,CAAC,EAAE,EAAE,8BAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAC3F,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,8BAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAC3D,CACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { UriString } from '@platformos/platformos-check-common';
2
+ import { IDependencies, ThemeGraph } from '../types';
3
+ export declare function buildThemeGraph(rootUri: UriString, ideps: IDependencies, entryPoints?: UriString[]): Promise<ThemeGraph>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildThemeGraph = buildThemeGraph;
4
+ const platformos_check_common_1 = require("@platformos/platformos-check-common");
5
+ const augment_1 = require("./augment");
6
+ const module_1 = require("./module");
7
+ const traverse_1 = require("./traverse");
8
+ async function buildThemeGraph(rootUri, ideps, entryPoints) {
9
+ const deps = (0, augment_1.augmentDependencies)(rootUri, ideps);
10
+ entryPoints =
11
+ entryPoints ??
12
+ (await (0, platformos_check_common_1.recursiveReadDirectory)(deps.fs, rootUri, ([uri]) => {
13
+ // Templates are entry points in the theme graph.
14
+ const isTemplateFile = uri.startsWith(platformos_check_common_1.path.join(rootUri, 'templates'));
15
+ // Since any section file can be rendered directly by the Section Rendering API,
16
+ // we consider all section files as entry points.
17
+ const isSectionFile = uri.startsWith(platformos_check_common_1.path.join(rootUri, 'sections')) && uri.endsWith('.liquid');
18
+ return isTemplateFile || isSectionFile;
19
+ }));
20
+ const graph = {
21
+ entryPoints: [],
22
+ modules: {},
23
+ rootUri,
24
+ };
25
+ graph.entryPoints = entryPoints
26
+ .map((uri) => (0, module_1.getModule)(graph, uri))
27
+ .filter((x) => x !== undefined);
28
+ await Promise.all(graph.entryPoints.map((entry) => (0, traverse_1.traverseModule)(entry, graph, deps)));
29
+ return graph;
30
+ }
31
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/graph/build.ts"],"names":[],"mappings":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,CAAC;AACf,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { UriString } from '@platformos/platformos-check-common';
2
+ import { CssModule, ImageModule, JavaScriptModule, JsonModule, LiquidModule, SvgModule, ThemeGraph, ThemeModule } from '../types';
3
+ export declare function getModule(themeGraph: ThemeGraph, uri: UriString): ThemeModule | undefined;
4
+ export declare function getTemplateModule(themeGraph: ThemeGraph, uri: UriString): ThemeModule;
5
+ export declare function getThemeBlockModule(themeGraph: ThemeGraph, blockType: string): LiquidModule;
6
+ export declare function getSectionModule(themeGraph: ThemeGraph, sectionType: string): LiquidModule;
7
+ export declare function getSectionGroupModule(themeGraph: ThemeGraph, sectionGroupType: string): JsonModule;
8
+ export declare function getAssetModule(themeGraph: ThemeGraph, asset: string): JavaScriptModule | CssModule | SvgModule | ImageModule | undefined;
9
+ export declare function getPartialModule(themeGraph: ThemeGraph, partial: string): LiquidModule;
10
+ export declare function getLayoutModule(themeGraph: ThemeGraph, layoutName?: string | false | undefined): LiquidModule | undefined;
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModule = getModule;
4
+ exports.getTemplateModule = getTemplateModule;
5
+ exports.getThemeBlockModule = getThemeBlockModule;
6
+ exports.getSectionModule = getSectionModule;
7
+ exports.getSectionGroupModule = getSectionGroupModule;
8
+ exports.getAssetModule = getAssetModule;
9
+ exports.getPartialModule = getPartialModule;
10
+ exports.getLayoutModule = getLayoutModule;
11
+ const platformos_check_common_1 = require("@platformos/platformos-check-common");
12
+ const types_1 = require("../types");
13
+ const utils_1 = require("../utils");
14
+ /**
15
+ * We're using a ModuleCache to prevent race conditions with traverse.
16
+ *
17
+ * e.g. if we have two modules that depend on the same 'assets/foo.js' file and
18
+ * that they somehow depend on it before it gets traversed (and thus added to the
19
+ * graphs' modules record), we want to avoid creating two different module objects
20
+ * that represent the same file.
21
+ *
22
+ * We're using a WeakMap<ThemeGraph> to cache modules so that if the theme graph
23
+ * gets garbage collected, the module cache will also be garbage collected.
24
+ *
25
+ * This allows us to have a module cache without changing the API of the
26
+ * ThemeGraph (no need for a `visited` property on modules, etc.)
27
+ */
28
+ const ModuleCache = new WeakMap();
29
+ function getModule(themeGraph, uri) {
30
+ const cache = getCache(themeGraph);
31
+ if (cache.has(uri)) {
32
+ return cache.get(uri);
33
+ }
34
+ const relativePath = platformos_check_common_1.path.relative(uri, themeGraph.rootUri);
35
+ switch (true) {
36
+ case relativePath.startsWith('assets'): {
37
+ return getAssetModule(themeGraph, platformos_check_common_1.path.basename(uri));
38
+ }
39
+ case relativePath.startsWith('blocks'): {
40
+ return getThemeBlockModule(themeGraph, platformos_check_common_1.path.basename(uri, '.liquid'));
41
+ }
42
+ case relativePath.startsWith('layout'): {
43
+ return getLayoutModule(themeGraph, platformos_check_common_1.path.basename(uri, '.liquid'));
44
+ }
45
+ case relativePath.startsWith('sections'): {
46
+ if (relativePath.endsWith('.json')) {
47
+ return getSectionGroupModule(themeGraph, platformos_check_common_1.path.basename(uri, '.json'));
48
+ }
49
+ return getSectionModule(themeGraph, platformos_check_common_1.path.basename(uri, '.liquid'));
50
+ }
51
+ case relativePath.includes('/views/partials') || relativePath.includes('/lib/'): {
52
+ return getPartialModule(themeGraph, platformos_check_common_1.path.basename(uri, '.liquid'));
53
+ }
54
+ case relativePath.startsWith('snippets'): {
55
+ return getPartialModule(themeGraph, platformos_check_common_1.path.basename(uri, '.liquid'));
56
+ }
57
+ case relativePath.startsWith('templates'): {
58
+ return getTemplateModule(themeGraph, uri);
59
+ }
60
+ }
61
+ }
62
+ function getTemplateModule(themeGraph, uri) {
63
+ const extension = (0, utils_1.extname)(uri);
64
+ switch (extension) {
65
+ case 'json': {
66
+ return module(themeGraph, {
67
+ type: "JSON" /* ModuleType.Json */,
68
+ kind: "template" /* JsonModuleKind.Template */,
69
+ dependencies: [],
70
+ references: [],
71
+ uri: uri,
72
+ });
73
+ }
74
+ case 'liquid': {
75
+ return module(themeGraph, {
76
+ type: "Liquid" /* ModuleType.Liquid */,
77
+ kind: "template" /* LiquidModuleKind.Template */,
78
+ dependencies: [],
79
+ references: [],
80
+ uri: uri,
81
+ });
82
+ }
83
+ default: {
84
+ throw new Error(`Unknown template type for ${uri}`);
85
+ }
86
+ }
87
+ }
88
+ function getThemeBlockModule(themeGraph, blockType) {
89
+ const uri = platformos_check_common_1.path.join(themeGraph.rootUri, 'blocks', `${blockType}.liquid`);
90
+ return module(themeGraph, {
91
+ type: "Liquid" /* ModuleType.Liquid */,
92
+ kind: "block" /* LiquidModuleKind.Block */,
93
+ dependencies: [],
94
+ references: [],
95
+ uri,
96
+ });
97
+ }
98
+ function getSectionModule(themeGraph, sectionType) {
99
+ const uri = platformos_check_common_1.path.join(themeGraph.rootUri, 'sections', `${sectionType}.liquid`);
100
+ return module(themeGraph, {
101
+ type: "Liquid" /* ModuleType.Liquid */,
102
+ kind: "section" /* LiquidModuleKind.Section */,
103
+ dependencies: [],
104
+ references: [],
105
+ uri,
106
+ });
107
+ }
108
+ function getSectionGroupModule(themeGraph, sectionGroupType) {
109
+ const uri = platformos_check_common_1.path.join(themeGraph.rootUri, 'sections', `${sectionGroupType}.json`);
110
+ return module(themeGraph, {
111
+ type: "JSON" /* ModuleType.Json */,
112
+ kind: "section-group" /* JsonModuleKind.SectionGroup */,
113
+ dependencies: [],
114
+ references: [],
115
+ uri,
116
+ });
117
+ }
118
+ function getAssetModule(themeGraph, asset) {
119
+ const extension = (0, utils_1.extname)(asset);
120
+ let type = undefined;
121
+ if (types_1.SUPPORTED_ASSET_IMAGE_EXTENSIONS.includes(extension)) {
122
+ type = "Image" /* ModuleType.Image */;
123
+ }
124
+ else if (extension === 'js') {
125
+ type = "JavaScript" /* ModuleType.JavaScript */;
126
+ }
127
+ else if (extension === 'css') {
128
+ type = "CSS" /* ModuleType.Css */;
129
+ }
130
+ else if (extension === 'svg') {
131
+ type = "SVG" /* ModuleType.Svg */;
132
+ }
133
+ if (!type) {
134
+ return undefined;
135
+ }
136
+ return module(themeGraph, {
137
+ type,
138
+ kind: 'unused',
139
+ dependencies: [],
140
+ references: [],
141
+ uri: platformos_check_common_1.path.join(themeGraph.rootUri, 'assets', asset),
142
+ });
143
+ }
144
+ function getPartialModule(themeGraph, partial) {
145
+ const uri = platformos_check_common_1.path.join(themeGraph.rootUri, 'app/views/partials', `${partial}.liquid`);
146
+ return module(themeGraph, {
147
+ type: "Liquid" /* ModuleType.Liquid */,
148
+ kind: "partial" /* LiquidModuleKind.Partial */,
149
+ uri: uri,
150
+ dependencies: [],
151
+ references: [],
152
+ });
153
+ }
154
+ function getLayoutModule(themeGraph, layoutName = 'theme') {
155
+ if (layoutName === false)
156
+ return undefined;
157
+ if (layoutName === undefined)
158
+ layoutName = 'theme';
159
+ const uri = platformos_check_common_1.path.join(themeGraph.rootUri, 'layout', `${layoutName}.liquid`);
160
+ return module(themeGraph, {
161
+ type: "Liquid" /* ModuleType.Liquid */,
162
+ kind: "layout" /* LiquidModuleKind.Layout */,
163
+ uri: uri,
164
+ dependencies: [],
165
+ references: [],
166
+ });
167
+ }
168
+ function getCache(themeGraph) {
169
+ if (!ModuleCache.has(themeGraph)) {
170
+ ModuleCache.set(themeGraph, new Map());
171
+ }
172
+ return ModuleCache.get(themeGraph);
173
+ }
174
+ function module(themeGraph, mod) {
175
+ const cache = getCache(themeGraph);
176
+ if (!cache.has(mod.uri)) {
177
+ cache.set(mod.uri, mod);
178
+ }
179
+ return cache.get(mod.uri);
180
+ }
181
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/graph/module.ts"],"names":[],"mappings":";;AAiCA,8BAwCC;AAED,8CA2BC;AAED,kDASC;AAED,4CASC;AAED,sDAYC;AAED,wCA6BC;AAED,4CASC;AAED,0CAcC;AApMD,iFAAsE;AACtE,oCAakB;AAClB,oCAAmC;AAEnC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,GAAkD,IAAI,OAAO,EAAE,CAAC;AAE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C,UAAU,EAAE;QACxB,IAAI,kCAAmB;QACvB,IAAI,wCAAyB;QAC7B,GAAG,EAAE,GAAG;QACR,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE,EAAE;KACf,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,UAAsB;IACtC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,WAAW,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;AACtC,CAAC;AAED,SAAS,MAAM,CAAwB,UAAsB,EAAE,GAAM;IACnE,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAO,CAAC;AAClC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { SerializableGraph, ThemeGraph } from '../types';
2
+ export declare function serializeThemeGraph(graph: ThemeGraph): SerializableGraph;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeThemeGraph = serializeThemeGraph;
4
+ function serializeThemeGraph(graph) {
5
+ const nodes = Object.values(graph.modules).map((module) => ({
6
+ uri: module.uri,
7
+ type: module.type,
8
+ kind: module.kind,
9
+ ...('exists' in module ? { exists: module.exists } : {}),
10
+ }));
11
+ const edges = Object.values(graph.modules).flatMap((module) => module.dependencies);
12
+ return {
13
+ rootUri: graph.rootUri,
14
+ nodes,
15
+ edges,
16
+ };
17
+ }
18
+ //# sourceMappingURL=serialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/graph/serialize.ts"],"names":[],"mappings":";;AAEA,kDAiBC;AAjBD,SAAgB,mBAAmB,CAAC,KAAiB;IACnD,MAAM,KAAK,GAAuB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9E,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzD,CAAC,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAuB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CACpE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAChC,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { SectionSchema, ThemeBlockSchema } from '@platformos/platformos-check-common';
2
+ import { AbstractFileSystem } from '@platformos/platformos-common';
3
+ export declare function makeGetSourceCode(fs: AbstractFileSystem): {
4
+ (x: string): Promise<import("..").FileSourceCode>;
5
+ force(x: string): Promise<import("..").FileSourceCode>;
6
+ invalidate(x: string): void;
7
+ clearCache(): void;
8
+ };
9
+ export declare const fixturesRoot: string;
10
+ export declare const skeleton: string;
11
+ export declare function getDependencies(rootUri: string, fs?: AbstractFileSystem): Promise<{
12
+ fs: AbstractFileSystem;
13
+ getSectionSchema: {
14
+ (x: string): Promise<SectionSchema>;
15
+ force(x: string): Promise<SectionSchema>;
16
+ invalidate(x: string): void;
17
+ clearCache(): void;
18
+ };
19
+ getBlockSchema: {
20
+ (x: string): Promise<ThemeBlockSchema>;
21
+ force(x: string): Promise<ThemeBlockSchema>;
22
+ invalidate(x: string): void;
23
+ clearCache(): void;
24
+ };
25
+ getSourceCode: {
26
+ (x: string): Promise<import("..").FileSourceCode>;
27
+ force(x: string): Promise<import("..").FileSourceCode>;
28
+ invalidate(x: string): void;
29
+ clearCache(): void;
30
+ };
31
+ getWebComponentDefinitionReference: (customElementName: string) => import("..").WebComponentDefinition | undefined;
32
+ }>;
33
+ export declare function mockImpl(obj: any, method: any, callback: any): import("vitest").MockInstance<(this: unknown, ...args: unknown[]) => unknown>;