@teambit/scope 1.0.106 → 1.0.108

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 (47) hide show
  1. package/clear-cache-action.ts +11 -0
  2. package/dist/get-scope-options.d.ts +1 -1
  3. package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
  4. package/dist/scope-aspects-loader.d.ts +4 -4
  5. package/dist/scope-aspects-loader.js +8 -9
  6. package/dist/scope-aspects-loader.js.map +1 -1
  7. package/dist/scope-cmd.d.ts +1 -1
  8. package/dist/scope-component-loader.js +2 -2
  9. package/dist/scope-component-loader.js.map +1 -1
  10. package/dist/scope.composition.d.ts +2 -2
  11. package/dist/scope.graphql.d.ts +4 -4
  12. package/dist/scope.main.runtime.d.ts +30 -22
  13. package/dist/scope.main.runtime.js +37 -15
  14. package/dist/scope.main.runtime.js.map +1 -1
  15. package/dist/scope.ui-root.d.ts +2 -2
  16. package/dist/scope.ui.drawer.d.ts +1 -1
  17. package/dist/scope.ui.drawer.js +6 -8
  18. package/dist/scope.ui.drawer.js.map +1 -1
  19. package/dist/scope.ui.runtime.d.ts +14 -14
  20. package/dist/scope.ui.runtime.js +8 -11
  21. package/dist/scope.ui.runtime.js.map +1 -1
  22. package/dist/staged-config.d.ts +3 -3
  23. package/dist/staged-config.js +2 -3
  24. package/dist/staged-config.js.map +1 -1
  25. package/dist/types.d.ts +3 -3
  26. package/dist/ui/menu/menu.d.ts +4 -4
  27. package/dist/ui/scope-overview/scope-overview.d.ts +5 -5
  28. package/dist/ui/scope-overview/scope-overview.js +2 -4
  29. package/dist/ui/scope-overview/scope-overview.js.map +1 -1
  30. package/dist/ui/scope.d.ts +3 -3
  31. package/dist/ui/scope.js +1 -1
  32. package/dist/ui/scope.js.map +1 -1
  33. package/get-scope-options.ts +16 -0
  34. package/index.ts +11 -0
  35. package/package.json +33 -40
  36. package/scope-aspects-loader.ts +493 -0
  37. package/scope-cmd.ts +17 -0
  38. package/scope-component-loader.ts +208 -0
  39. package/scope.aspect.ts +7 -0
  40. package/scope.graphql.ts +115 -0
  41. package/scope.main.runtime.ts +1263 -0
  42. package/scope.ui-root.ts +43 -0
  43. package/scope.ui.runtime.tsx +1 -0
  44. package/staged-config.ts +79 -0
  45. package/tsconfig.json +16 -21
  46. package/types/asset.d.ts +15 -3
  47. package/types.ts +12 -0
@@ -0,0 +1,43 @@
1
+ import { ResolveAspectsOptions } from '@teambit/component';
2
+ import { ComponentID } from '@teambit/component-id';
3
+ import { UIRoot } from '@teambit/ui';
4
+
5
+ import type { ScopeMain } from './scope.main.runtime';
6
+
7
+ export class ScopeUIRoot implements UIRoot {
8
+ constructor(
9
+ /**
10
+ * scope extension.
11
+ */
12
+ private scope: ScopeMain
13
+ ) {}
14
+
15
+ get name() {
16
+ return this.scope.name;
17
+ }
18
+
19
+ get path(): string {
20
+ return this.scope.path;
21
+ }
22
+
23
+ get configFile(): string {
24
+ return 'scope.jsonc';
25
+ }
26
+
27
+ get devServers() {
28
+ return Promise.resolve([]);
29
+ }
30
+
31
+ buildOptions = {
32
+ ssr: true,
33
+ prebundle: true,
34
+ };
35
+
36
+ resolveAspects(runtime: string, componentIds?: ComponentID[], opts?: ResolveAspectsOptions) {
37
+ return this.scope.resolveAspects(runtime, componentIds, opts);
38
+ }
39
+
40
+ async resolvePattern() {
41
+ return [];
42
+ }
43
+ }
@@ -246,6 +246,7 @@ export class ScopeUI {
246
246
  const contexts = this.contextSlot.values();
247
247
  // eslint-disable-next-line react/prop-types
248
248
  const ComponentUrlFuncProvider: ScopeContextType = ({ children }) => (
249
+ // @ts-ignore TODO: fix this
249
250
  <ComponentUrlProvider value={componentUrlFn || this.componentUrlFunc}>{children}</ComponentUrlProvider>
250
251
  );
251
252
 
@@ -0,0 +1,79 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { ComponentID } from '@teambit/component-id';
4
+ import { DEFAULT_LANE, LaneId } from '@teambit/lane-id';
5
+ import { Logger } from '@teambit/logger';
6
+
7
+ const STAGED_CONFIG_DIR = 'staged-config';
8
+
9
+ type Config = Record<string, any> | undefined;
10
+ type ComponentConfig = { id: ComponentID; config: Config };
11
+
12
+ export class StagedConfig {
13
+ hasChanged = false;
14
+ constructor(readonly filePath: string, private componentsConfig: ComponentConfig[], private logger: Logger) {}
15
+
16
+ static async load(scopePath: string, logger: Logger, laneId?: LaneId): Promise<StagedConfig> {
17
+ const lanePath = laneId ? path.join(laneId.scope, laneId.name) : DEFAULT_LANE;
18
+ const filePath = path.join(scopePath, STAGED_CONFIG_DIR, `${lanePath}.json`);
19
+ let componentsConfig: ComponentConfig[] = [];
20
+ try {
21
+ const fileContent = await fs.readJson(filePath);
22
+ componentsConfig = fileContent.map((item) => ({ id: ComponentID.fromObject(item.id), config: item.config }));
23
+ } catch (err: any) {
24
+ if (err.code === 'ENOENT') {
25
+ componentsConfig = [];
26
+ } else {
27
+ throw err;
28
+ }
29
+ }
30
+ return new StagedConfig(filePath, componentsConfig, logger);
31
+ }
32
+
33
+ toObject() {
34
+ return this.componentsConfig.map(({ id, config }) => ({ id: id.toObject(), config }));
35
+ }
36
+
37
+ async write() {
38
+ if (!this.hasChanged) return;
39
+ await fs.outputFile(this.filePath, JSON.stringify(this.toObject(), null, 2));
40
+ }
41
+
42
+ getConfigPerId(id: ComponentID): Config {
43
+ return this.componentsConfig.find((c) => c.id.isEqual(id, { ignoreVersion: true }))?.config;
44
+ }
45
+
46
+ getAll() {
47
+ return this.componentsConfig;
48
+ }
49
+
50
+ isEmpty() {
51
+ return this.componentsConfig.length === 0;
52
+ }
53
+
54
+ async deleteFile() {
55
+ this.logger.debug(`staged-config, deleting ${this.filePath}`);
56
+ await fs.remove(this.filePath);
57
+ this.componentsConfig = [];
58
+ }
59
+
60
+ addComponentConfig(id: ComponentID, config: Config) {
61
+ const exists = this.componentsConfig.find((c) => c.id.isEqual(id, { ignoreVersion: true }));
62
+ if (exists) {
63
+ exists.config = config;
64
+ } else {
65
+ this.componentsConfig.push({ id, config });
66
+ }
67
+ this.hasChanged = true;
68
+ }
69
+
70
+ removeComponentConfig(id: ComponentID) {
71
+ const componentsConfigLengthBefore = this.componentsConfig.length;
72
+ this.componentsConfig = this.componentsConfig.filter((c) => !c.id.isEqual(id, { ignoreVersion: true }));
73
+ if (this.componentsConfig.length === componentsConfigLengthBefore) {
74
+ this.logger.debug(`removeComponentConfig: unable to find ${id.toString()}`);
75
+ } else {
76
+ this.hasChanged = true;
77
+ }
78
+ }
79
+ }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
package/types.ts ADDED
@@ -0,0 +1,12 @@
1
+ export type Serializable = {
2
+ toString(): string;
3
+ };
4
+
5
+ export type Metadata = {
6
+ [key: string]: Serializable;
7
+ };
8
+
9
+ export type DataToPersist = {
10
+ metadata: Metadata;
11
+ files: string[];
12
+ };