@suss/contract-storybook 0.34.1 → 0.35.0

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.
package/dist/index.cjs CHANGED
@@ -37,8 +37,8 @@ var import_node_path = __toESM(require("path"), 1);
37
37
  var import_ts_morph = require("ts-morph");
38
38
  var import_adapter_typescript = require("@suss/adapter-typescript");
39
39
  var import_behavioral_ir = require("@suss/behavioral-ir");
40
+ var import_files = require("@suss/behavioral-ir/files");
40
41
  function generateSummariesFromStories(filePaths, options = {}) {
41
- const projectRoot = options.projectRoot ?? process.cwd();
42
42
  const componentModules = options.componentModules ?? true;
43
43
  const byFile = /* @__PURE__ */ new Map();
44
44
  const groups = componentModules ? filesByTsconfig(filePaths) : /* @__PURE__ */ new Map([[null, filePaths]]);
@@ -46,7 +46,11 @@ function generateSummariesFromStories(filePaths, options = {}) {
46
46
  const project = projectFor(tsconfig);
47
47
  const resolution = new import_adapter_typescript.ResolutionStore();
48
48
  for (const sf of files.map((fp) => project.addSourceFileAtPath(fp))) {
49
- const relPath = import_node_path.default.relative(projectRoot, sf.getFilePath());
49
+ const storyFile = sf.getFilePath();
50
+ const relPath = (0, import_files.pathInProject)(
51
+ storyFile,
52
+ options.projectRoot ?? (0, import_files.defaultProjectRoot)(storyFile)
53
+ );
50
54
  const meta = extractMeta(sf, resolution, componentModules);
51
55
  if (meta === null) {
52
56
  continue;
@@ -195,15 +199,10 @@ function declaredModuleOf(component) {
195
199
  if (declaration === void 0) {
196
200
  return void 0;
197
201
  }
198
- const file = declaration.getSourceFile().getFilePath();
199
- const tsconfig = (0, import_adapter_typescript.findNearestTsconfig)(import_node_path.default.dirname(file));
200
- const root = (0, import_adapter_typescript.workspaceRootFor)(
201
- tsconfig === null ? import_node_path.default.dirname(file) : import_node_path.default.dirname(tsconfig)
202
- );
203
- const workspace = (0, import_adapter_typescript.workspaceNameFor)(root);
202
+ const place = (0, import_adapter_typescript.projectPlaceOf)(declaration.getSourceFile().getFilePath());
204
203
  return {
205
- ...workspace === null ? {} : { workspace },
206
- file: import_node_path.default.relative(root, file).replace(/\\/g, "/"),
204
+ ...place.workspace === null ? {} : { workspace: place.workspace },
205
+ file: place.file,
207
206
  name: declaredNameOf(declaration) ?? component.getText()
208
207
  };
209
208
  }
package/dist/index.d.cts CHANGED
@@ -15,7 +15,7 @@ import { BehavioralSummary } from '@suss/behavioral-ir';
15
15
  interface StorybookStubOptions {
16
16
  /**
17
17
  * Each summary's `location.file` is relative to this, so it is the same
18
- * on every machine. Defaults to the working directory.
18
+ * on every machine. Defaults to the repository each story is in.
19
19
  */
20
20
  projectRoot?: string;
21
21
  /**
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ import { BehavioralSummary } from '@suss/behavioral-ir';
15
15
  interface StorybookStubOptions {
16
16
  /**
17
17
  * Each summary's `location.file` is relative to this, so it is the same
18
- * on every machine. Defaults to the working directory.
18
+ * on every machine. Defaults to the repository each story is in.
19
19
  */
20
20
  projectRoot?: string;
21
21
  /**
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  exportedDeclarationsOf,
11
11
  findNearestTsconfig,
12
12
  objectLiteralOf,
13
+ projectPlaceOf,
13
14
  propertiesOf,
14
15
  propertyFunctionOf,
15
16
  propertyNameOf,
@@ -18,13 +19,11 @@ import {
18
19
  ResolutionStore,
19
20
  specifierImportedAs,
20
21
  stringValueOf,
21
- symbolBehind,
22
- workspaceNameFor,
23
- workspaceRootFor
22
+ symbolBehind
24
23
  } from "@suss/adapter-typescript";
25
24
  import { functionCallBinding } from "@suss/behavioral-ir";
25
+ import { defaultProjectRoot, pathInProject } from "@suss/behavioral-ir/files";
26
26
  function generateSummariesFromStories(filePaths, options = {}) {
27
- const projectRoot = options.projectRoot ?? process.cwd();
28
27
  const componentModules = options.componentModules ?? true;
29
28
  const byFile = /* @__PURE__ */ new Map();
30
29
  const groups = componentModules ? filesByTsconfig(filePaths) : /* @__PURE__ */ new Map([[null, filePaths]]);
@@ -32,7 +31,11 @@ function generateSummariesFromStories(filePaths, options = {}) {
32
31
  const project = projectFor(tsconfig);
33
32
  const resolution = new ResolutionStore();
34
33
  for (const sf of files.map((fp) => project.addSourceFileAtPath(fp))) {
35
- const relPath = path.relative(projectRoot, sf.getFilePath());
34
+ const storyFile = sf.getFilePath();
35
+ const relPath = pathInProject(
36
+ storyFile,
37
+ options.projectRoot ?? defaultProjectRoot(storyFile)
38
+ );
36
39
  const meta = extractMeta(sf, resolution, componentModules);
37
40
  if (meta === null) {
38
41
  continue;
@@ -181,15 +184,10 @@ function declaredModuleOf(component) {
181
184
  if (declaration === void 0) {
182
185
  return void 0;
183
186
  }
184
- const file = declaration.getSourceFile().getFilePath();
185
- const tsconfig = findNearestTsconfig(path.dirname(file));
186
- const root = workspaceRootFor(
187
- tsconfig === null ? path.dirname(file) : path.dirname(tsconfig)
188
- );
189
- const workspace = workspaceNameFor(root);
187
+ const place = projectPlaceOf(declaration.getSourceFile().getFilePath());
190
188
  return {
191
- ...workspace === null ? {} : { workspace },
192
- file: path.relative(root, file).replace(/\\/g, "/"),
189
+ ...place.workspace === null ? {} : { workspace: place.workspace },
190
+ file: place.file,
193
191
  name: declaredNameOf(declaration) ?? component.getText()
194
192
  };
195
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-storybook",
3
- "version": "0.34.1",
3
+ "version": "0.35.0",
4
4
  "type": "module",
5
5
  "description": "Turn Storybook CSF stories into a suss contract and check the props they pass against the React components that receive them.",
6
6
  "keywords": [
@@ -47,8 +47,8 @@
47
47
  "typecheck": "tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@suss/adapter-typescript": "0.34.1",
51
- "@suss/behavioral-ir": "0.34.1"
50
+ "@suss/adapter-typescript": "0.35.0",
51
+ "@suss/behavioral-ir": "0.35.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "tsup": "*",