@platformos/platformos-graph 0.0.6 → 0.0.8

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 (59) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/getWebComponentMap.js +1 -1
  3. package/dist/getWebComponentMap.js.map +1 -1
  4. package/dist/graph/augment.js +0 -3
  5. package/dist/graph/augment.js.map +1 -1
  6. package/dist/graph/build.d.ts +2 -2
  7. package/dist/graph/build.js +11 -8
  8. package/dist/graph/build.js.map +1 -1
  9. package/dist/graph/module.d.ts +6 -9
  10. package/dist/graph/module.js +53 -117
  11. package/dist/graph/module.js.map +1 -1
  12. package/dist/graph/serialize.d.ts +2 -2
  13. package/dist/graph/serialize.js +2 -2
  14. package/dist/graph/serialize.js.map +1 -1
  15. package/dist/graph/test-helpers.d.ts +0 -13
  16. package/dist/graph/test-helpers.js +0 -10
  17. package/dist/graph/test-helpers.js.map +1 -1
  18. package/dist/graph/traverse.d.ts +3 -3
  19. package/dist/graph/traverse.js +19 -349
  20. package/dist/graph/traverse.js.map +1 -1
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +4 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/toSourceCode.d.ts +1 -4
  25. package/dist/toSourceCode.js +8 -52
  26. package/dist/toSourceCode.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/dist/types.d.ts +21 -78
  29. package/dist/types.js.map +1 -1
  30. package/dist/utils/index.d.ts +0 -3
  31. package/dist/utils/index.js +0 -18
  32. package/dist/utils/index.js.map +1 -1
  33. package/fixtures/skeleton/{layout/theme.liquid → app/views/layouts/application.liquid} +3 -4
  34. package/fixtures/skeleton/app/views/pages/index.liquid +5 -0
  35. package/fixtures/skeleton/app/views/partials/header.liquid +3 -0
  36. package/package.json +7 -7
  37. package/src/getWebComponentMap.ts +1 -1
  38. package/src/graph/augment.ts +1 -13
  39. package/src/graph/build.spec.ts +31 -171
  40. package/src/graph/build.ts +18 -14
  41. package/src/graph/module.ts +59 -135
  42. package/src/graph/serialize.spec.ts +22 -29
  43. package/src/graph/serialize.ts +2 -2
  44. package/src/graph/test-helpers.ts +1 -18
  45. package/src/graph/traverse.ts +28 -501
  46. package/src/index.ts +3 -3
  47. package/src/toSourceCode.ts +14 -55
  48. package/src/types.ts +23 -100
  49. package/src/utils/index.ts +0 -24
  50. package/fixtures/skeleton/blocks/_private.liquid +0 -1
  51. package/fixtures/skeleton/blocks/_static.liquid +0 -10
  52. package/fixtures/skeleton/blocks/group.liquid +0 -27
  53. package/fixtures/skeleton/blocks/render-static.liquid +0 -22
  54. package/fixtures/skeleton/blocks/text.liquid +0 -14
  55. package/fixtures/skeleton/jsconfig.json +0 -9
  56. package/fixtures/skeleton/sections/custom-section.liquid +0 -6
  57. package/fixtures/skeleton/sections/header-group.json +0 -36
  58. package/fixtures/skeleton/sections/header.liquid +0 -1
  59. package/fixtures/skeleton/templates/index.json +0 -20
@@ -4,52 +4,9 @@ import {
4
4
  UriString,
5
5
  } from '@platformos/platformos-check-common';
6
6
  import { parse as acornParse, Program } from 'acorn';
7
- import {
8
- CssSourceCode,
9
- FileSourceCode,
10
- ImageSourceCode,
11
- JsSourceCode,
12
- SUPPORTED_ASSET_IMAGE_EXTENSIONS,
13
- SvgSourceCode,
14
- } from './types';
7
+ import { AssetSourceCode, FileSourceCode, SUPPORTED_ASSET_IMAGE_EXTENSIONS } from './types';
15
8
  import { extname } from './utils';
16
9
 
17
- export async function toCssSourceCode(uri: UriString, source: string): Promise<CssSourceCode> {
18
- return {
19
- type: 'css',
20
- uri,
21
- source,
22
- ast: new Error('File parsing not implemented yet'), // Placeholder for CSS parsing
23
- };
24
- }
25
-
26
- export async function toSvgSourceCode(uri: UriString, source: string): Promise<SvgSourceCode> {
27
- return {
28
- type: 'svg',
29
- uri,
30
- source,
31
- ast: new Error('File parsing not implemented yet'), // Placeholder for SVG parsing
32
- };
33
- }
34
-
35
- async function toImageSourceCode(uri: UriString, source: string): Promise<ImageSourceCode> {
36
- return {
37
- type: 'image',
38
- uri,
39
- source,
40
- ast: new Error('Image files are not parsed'),
41
- };
42
- }
43
-
44
- export async function toJsSourceCode(uri: UriString, source: string): Promise<JsSourceCode> {
45
- return {
46
- type: 'javascript',
47
- uri,
48
- source,
49
- ast: parseJs(source),
50
- };
51
- }
52
-
53
10
  export function parseJs(source: string): Program | Error {
54
11
  try {
55
12
  return acornParse(source, {
@@ -64,17 +21,19 @@ export function parseJs(source: string): Program | Error {
64
21
  export async function toSourceCode(uri: UriString, source: string): Promise<FileSourceCode> {
65
22
  const extension = extname(uri);
66
23
 
67
- if (extension === 'json' || extension === 'liquid' || extension === 'graphql') {
24
+ if (
25
+ extension === 'json' ||
26
+ extension === 'liquid' ||
27
+ extension === 'graphql' ||
28
+ extension === 'yml' ||
29
+ extension === 'yaml'
30
+ ) {
68
31
  return tcToSourceCode(uri, source);
69
- } else if (extension === 'js') {
70
- return toJsSourceCode(uri, source);
71
- } else if (extension === 'css') {
72
- return toCssSourceCode(uri, source);
73
- } else if (extension === 'svg') {
74
- return toCssSourceCode(uri, source);
75
- } else if (SUPPORTED_ASSET_IMAGE_EXTENSIONS.includes(extension)) {
76
- return toImageSourceCode(uri, source);
77
- } else {
78
- throw new Error(`Unknown source code type for ${uri}`);
79
32
  }
33
+
34
+ const ast: Program | Error =
35
+ extension === 'js' ? parseJs(source) : new Error('File parsing not implemented');
36
+
37
+ const assetSourceCode: AssetSourceCode = { type: 'asset', uri, source, ast };
38
+ return assetSourceCode;
80
39
  }
package/src/types.ts CHANGED
@@ -1,29 +1,17 @@
1
1
  import {
2
2
  JSONSourceCode,
3
3
  LiquidSourceCode,
4
- Dependencies as ThemeCheckDependencies,
4
+ Dependencies as CheckDependencies,
5
5
  UriString,
6
6
  Reference,
7
7
  Location,
8
8
  Range,
9
9
  GraphQLSourceCode,
10
+ YAMLSourceCode,
10
11
  } from '@platformos/platformos-check-common';
11
- import { Program } from 'acorn';
12
12
 
13
13
  export interface IDependencies {
14
- fs: ThemeCheckDependencies['fs'];
15
-
16
- /**
17
- * Asynchronously get the block schema for 'blocks/${name}.liquid'
18
- * May return undefined when the theme isn't preloaded.
19
- */
20
- getBlockSchema: NonNullable<ThemeCheckDependencies['getBlockSchema']>;
21
-
22
- /**
23
- * Asynchronously get the section schema for 'section/${name}.liquid'
24
- * May return undefined when the theme isn't preloaded or if there are none.
25
- */
26
- getSectionSchema: NonNullable<ThemeCheckDependencies['getSectionSchema']>;
14
+ fs: CheckDependencies['fs'];
27
15
 
28
16
  /** Optional perf improvement if you somehow have access to pre-computed source code info */
29
17
  getSourceCode?: (uri: UriString) => Promise<FileSourceCode>;
@@ -36,32 +24,22 @@ export interface IDependencies {
36
24
 
37
25
  export type Dependencies = Required<IDependencies>;
38
26
 
39
- export type AugmentedDependencies = Dependencies & {
40
- getThemeBlockNames: () => Promise<string[]>;
41
- };
27
+ export type AugmentedDependencies = Dependencies;
42
28
 
43
- export interface ThemeGraph {
29
+ export interface AppGraph {
44
30
  rootUri: UriString;
45
- entryPoints: ThemeModule[];
46
- modules: Record<UriString, ThemeModule>;
31
+ entryPoints: AppModule[];
32
+ modules: Record<UriString, AppModule>;
47
33
  }
48
34
 
49
- export type ThemeModule =
50
- | LiquidModule
51
- | JsonModule
52
- | JavaScriptModule
53
- | CssModule
54
- | SvgModule
55
- | ImageModule;
35
+ export type AppModule = LiquidModule | AssetModule;
56
36
 
57
37
  export type FileSourceCode =
58
38
  | LiquidSourceCode
59
39
  | JSONSourceCode
60
40
  | GraphQLSourceCode
61
- | JsSourceCode
62
- | CssSourceCode
63
- | SvgSourceCode
64
- | ImageSourceCode;
41
+ | YAMLSourceCode
42
+ | AssetSourceCode;
65
43
 
66
44
  export interface SerializableGraph {
67
45
  rootUri: UriString;
@@ -74,34 +52,18 @@ export interface SerializableEdge {
74
52
  target: Location;
75
53
  }
76
54
 
77
- export type SerializableNode = Pick<ThemeModule, 'uri' | 'type' | 'kind' | 'exists'>;
55
+ export type SerializableNode = Pick<AppModule, 'uri' | 'type' | 'kind' | 'exists'>;
78
56
 
79
- export interface LiquidModule extends IThemeModule<ModuleType.Liquid> {
57
+ export interface LiquidModule extends IAppModule<ModuleType.Liquid> {
80
58
  kind: LiquidModuleKind;
81
59
  }
82
60
 
83
- export interface JsonModule extends IThemeModule<ModuleType.Json> {
84
- kind: JsonModuleKind;
85
- }
86
-
87
- export interface JavaScriptModule extends IThemeModule<ModuleType.JavaScript> {
61
+ export interface AssetModule extends IAppModule<ModuleType.Asset> {
88
62
  kind: 'unused';
89
63
  }
90
64
 
91
- export interface CssModule extends IThemeModule<ModuleType.Css> {
92
- kind: 'unused';
93
- }
94
-
95
- export interface SvgModule extends IThemeModule<ModuleType.Svg> {
96
- kind: 'unused';
97
- }
98
-
99
- export interface ImageModule extends IThemeModule<ModuleType.Image> {
100
- kind: 'unused';
101
- }
102
-
103
- export interface IThemeModule<T extends ModuleType> {
104
- /** Used as a discriminant in the ThemeNode union */
65
+ export interface IAppModule<T extends ModuleType> {
66
+ /** Used as a discriminant in the AppModule union */
105
67
  type: T;
106
68
 
107
69
  /** Should be normalized. Used as key. */
@@ -131,36 +93,18 @@ export interface IThemeModule<T extends ModuleType> {
131
93
 
132
94
  export const enum ModuleType {
133
95
  Liquid = 'Liquid',
134
- JavaScript = 'JavaScript',
135
- Json = 'JSON',
136
- Css = 'CSS',
137
- Svg = 'SVG',
138
- Image = 'Image',
139
- }
140
-
141
- export const enum JsonModuleKind {
142
- /** templates/*.json files */
143
- Template = 'template',
144
-
145
- /** sections/*.json files */
146
- SectionGroup = 'section-group',
96
+ Asset = 'Asset',
147
97
  }
148
98
 
149
99
  export const enum LiquidModuleKind {
150
- /** layout/*.liquid files */
100
+ /** app/views/layouts/*.liquid files */
151
101
  Layout = 'layout',
152
102
 
153
- /** sections/*.liquid files */
154
- Section = 'section',
155
-
156
- /** blocks/*.liquid files */
157
- Block = 'block',
158
-
159
- /** app/views/partials/*.liquid files */
103
+ /** app/views/partials/*.liquid and app/lib/*.liquid files */
160
104
  Partial = 'partial',
161
105
 
162
- /** templates/*.liquid files (forgot those existed...) */
163
- Template = 'template',
106
+ /** app/views/pages/*.liquid files */
107
+ Page = 'page',
164
108
  }
165
109
 
166
110
  export const SUPPORTED_ASSET_IMAGE_EXTENSIONS = [
@@ -173,37 +117,16 @@ export const SUPPORTED_ASSET_IMAGE_EXTENSIONS = [
173
117
  'ico',
174
118
  ];
175
119
 
176
- export interface CssSourceCode {
177
- type: 'css';
178
- uri: UriString;
179
- source: string;
180
- ast: any | Error;
181
- }
182
-
183
- export interface SvgSourceCode {
184
- type: 'svg';
120
+ export interface AssetSourceCode {
121
+ type: 'asset';
185
122
  uri: UriString;
186
123
  source: string;
187
124
  ast: any | Error;
188
125
  }
189
126
 
190
- export interface ImageSourceCode {
191
- type: 'image';
192
- uri: UriString;
193
- source: string;
194
- ast: any | Error;
195
- }
196
-
197
- export interface JsSourceCode {
198
- type: 'javascript';
199
- uri: UriString;
200
- source: string;
201
- ast: Program | Error;
202
- }
203
-
204
127
  export { Reference, Range, Location };
205
128
 
206
- export type Void = void | Void[]; /** e.g. product-element, */
129
+ export type Void = void | Void[];
207
130
 
208
131
  export type WebComponentMap = Map<WebComponentName, WebComponentDefinition>;
209
132
  export type WebComponentName = string;
@@ -1,6 +1,5 @@
1
1
  import { UriString } from '@platformos/platformos-check-common';
2
2
  import { AbstractFileSystem } from '@platformos/platformos-common';
3
- import { AugmentedDependencies } from '../types';
4
3
 
5
4
  export function unique<T>(array: T[]): T[] {
6
5
  return [...new Set(array)];
@@ -10,10 +9,6 @@ export function assertNever(module: never) {
10
9
  throw new Error(`Unknown module type ${module}`);
11
10
  }
12
11
 
13
- export function unexpected(): Error {
14
- return new Error('Unexpected code path encountered');
15
- }
16
-
17
12
  export const identity = <T>(x: T): T => x;
18
13
 
19
14
  export function isString(x: unknown): x is string {
@@ -30,22 +25,3 @@ export async function exists(fs: AbstractFileSystem, uri: UriString): Promise<bo
30
25
  .then(() => true)
31
26
  .catch(() => false);
32
27
  }
33
-
34
- export async function acceptsLocalBlocks(
35
- sectionType: string,
36
- deps: AugmentedDependencies,
37
- ): Promise<boolean | Error> {
38
- const sectionSchema = await deps.getSectionSchema(sectionType).catch((_) => undefined);
39
- if (!sectionSchema) {
40
- return new Error('Section does not exist');
41
- }
42
-
43
- const validSchema = sectionSchema.validSchema;
44
- if (validSchema instanceof Error) {
45
- return validSchema;
46
- }
47
-
48
- return (validSchema.blocks ?? []).some((block) => {
49
- return block.type && 'name' in block && block.name;
50
- });
51
- }
@@ -1 +0,0 @@
1
- hoho I'm private
@@ -1,10 +0,0 @@
1
- {% doc %}
2
- this block is statically rendered
3
-
4
- @param {string} content
5
-
6
- {% enddoc %}
7
-
8
- <div class="static-block">
9
- {{ content }}
10
- </div>
@@ -1,27 +0,0 @@
1
- {% doc %}
2
- Fixture block component that passes its blocks to the parent snippet
3
- {% enddoc %}
4
-
5
- {% capture children %}
6
- {%- content_for "blocks" -%}
7
- {% endcapture %}
8
-
9
- {% render 'parent', children: children %}
10
-
11
- {% schema %}
12
- {
13
- "name": "Group block",
14
- "blocks": [{ "type": "@theme" }],
15
- "presets": [
16
- {
17
- "name": "Group block",
18
- "category": "Group",
19
- "blocks": [
20
- {
21
- "type": "text"
22
- }
23
- ]
24
- }
25
- ]
26
- }
27
- {% endschema %}
@@ -1,22 +0,0 @@
1
- {% doc %}
2
- This block renders the private _static block. Has no schema.
3
- {% enddoc %}
4
-
5
- <div class="static-block-wrapper">
6
- {% content_for 'block',
7
- type: '_static',
8
- id: 'static',
9
- content: 'hello world'
10
- %}
11
- </div>
12
-
13
- {% schema %}
14
- {
15
- "name": "render static block",
16
- "presets": [
17
- {
18
- "name": "Render Static Block"
19
- }
20
- ]
21
- }
22
- {% endschema %}
@@ -1,14 +0,0 @@
1
- hello world
2
-
3
- {% schema %}
4
- {
5
- "name": "Text block",
6
- "settings": [],
7
- "presets": [
8
- {
9
- "name": "Text block",
10
- "category": "Text"
11
- }
12
- ]
13
- }
14
- {% endschema %}
@@ -1,9 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "baseUrl": "./assets",
4
- "lib": ["es2020", "dom"],
5
- "allowJs": true,
6
- "checkJs": true
7
- },
8
- "include": ["./assets/**/*.js"],
9
- }
@@ -1,6 +0,0 @@
1
- {% schema %}
2
- {
3
- "name": "custom section",
4
- "blocks": [{ "type": "@theme" }, { "type": "_private" }]
5
- }
6
- {% endschema %}
@@ -1,36 +0,0 @@
1
- {
2
- "sections": {
3
- "header": {
4
- "type": "custom-section",
5
- "block_order": [
6
- "header",
7
- "render-static",
8
- ],
9
- "blocks": {
10
- "header": {
11
- "type": "group",
12
- "block_order": [
13
- "text"
14
- ],
15
- "blocks": {
16
- "text": {
17
- "type": "text",
18
- }
19
- },
20
- },
21
- "render-static": {
22
- "type": "render-static",
23
- "blocks": {
24
- "static": {
25
- "type": "_static",
26
- "static": true,
27
- }
28
- }
29
- }
30
- }
31
- }
32
- },
33
- "order": [
34
- "header"
35
- ],
36
- }
@@ -1 +0,0 @@
1
- header content
@@ -1,20 +0,0 @@
1
- {
2
- "sections": {
3
- "main": {
4
- "type": "custom-section",
5
- "blocks": [
6
- {
7
- "type": "group",
8
- "blocks": {
9
- "text1": {
10
- "type": "text",
11
- },
12
- },
13
- "block_order": [
14
- "text1"
15
- ]
16
- }
17
- ]
18
- }
19
- }
20
- }