@nshiab/setup-data-project 1.0.37 → 1.0.38

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAgIvD"}
1
+ {"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAgJvD"}
@@ -6,21 +6,23 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
6
6
  let sdaClassesAndMethods = "";
7
7
  let sdaDocsPath = "";
8
8
  let sdaLibraryName = "";
9
+ const journalismFunctionsByPackage = new Map();
9
10
  for (const [pkg, doc] of Object.entries(docsMapping)) {
10
11
  const pkgConfig = SUPPORTED_PACKAGES.find((p) => p.value === pkg);
11
12
  const pkgType = pkgConfig?.type || "other";
12
13
  if (pkgType === "journalism") {
13
14
  const repoName = pkg.split("/")[1];
14
- journalismFunctions += `\n### ${repoName}\n\n`;
15
- journalismFunctions += doc
15
+ const functions = doc
16
16
  .split("\n")
17
17
  .filter((line) => line.trim().startsWith("#"))
18
18
  .filter((line) => {
19
19
  const depth = line.match(/^#+/)?.[0].length || 0;
20
- return depth >= 2; // Match ##, ###, #### etc.
20
+ return depth === 2;
21
21
  })
22
- .map((line) => line.replace(/^#+\s+/, "").trim())
23
- .join("\n") + "\n";
22
+ .map((line) => line.replace(/^#+\s+/, "").trim());
23
+ journalismFunctionsByPackage.set(pkg, functions);
24
+ journalismFunctions += `\n### ${repoName}\n\n`;
25
+ journalismFunctions += functions.join("\n") + "\n";
24
26
  }
25
27
  else if (pkgType === "sda") {
26
28
  const repoName = pkg.split("/")[1];
@@ -31,7 +33,13 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
31
33
  .filter((line) => line.trim().startsWith("#"))
32
34
  .filter((line) => {
33
35
  const depth = line.match(/^#+/)?.[0].length || 0;
34
- return depth === 2 || depth === 4;
36
+ if (depth === 2)
37
+ return true;
38
+ if (depth !== 4)
39
+ return false;
40
+ const heading = line.replace(/^#+\s+/, "").replaceAll("`", "")
41
+ .trim();
42
+ return heading !== "Parameters";
35
43
  })
36
44
  .map((line) => {
37
45
  const depth = line.match(/^#+/)?.[0].length || 0;
@@ -39,8 +47,7 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
39
47
  return "\n" + line.replace(/^#+\s+/, "").trim();
40
48
  }
41
49
  else {
42
- return line.replace(/^#+\s+Parameters/, " - ")
43
- .replace(/^#+\s+/, " - ")
50
+ return line.replace(/^#+\s+/, " - ")
44
51
  .replaceAll("`", "");
45
52
  }
46
53
  })
@@ -60,21 +67,34 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
60
67
  ? "bun run all-tests"
61
68
  : "npm run all-tests";
62
69
  const installedPackageConfigs = getInstalledPackageConfigs(installedPackages);
63
- const importExamples = installedPackageConfigs.map((pkg) => {
64
- const repoName = pkg.value.split("/")[1];
65
- const identifier = repoName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
66
- return `import * as ${identifier} from "${pkg.value}";`;
70
+ const importExamples = installedPackageConfigs.flatMap((pkg) => {
71
+ if (pkg.type === "sda") {
72
+ return [`import { SimpleDB } from "${pkg.value}";`];
73
+ }
74
+ const functionName = journalismFunctionsByPackage.get(pkg.value)
75
+ ?.map((name) => name.replaceAll("`", ""))
76
+ .find((name) => /^[A-Za-z_$][\w$]*$/.test(name));
77
+ return functionName
78
+ ? [`import { ${functionName} } from "${pkg.value}";`]
79
+ : [];
67
80
  });
68
81
  let libraryGuidance = "";
69
82
  if (installedPackageConfigs.length > 0) {
70
- const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.label}"`)
83
+ const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.value}"`)
71
84
  .join(", ");
85
+ const libraryNoun = installedPackageConfigs.length === 1
86
+ ? "library"
87
+ : "libraries";
72
88
  libraryGuidance = `
73
- Always prioritize the installed ${libraryNames} libraries when relevant. They can be imported directly like this:
89
+ Always prioritize the installed ${libraryNames} ${libraryNoun} when relevant.
90
+ `;
91
+ if (importExamples.length > 0) {
92
+ libraryGuidance += `APIs can be imported with named imports like this:
74
93
  \`\`\`typescript
75
94
  ${importExamples.join("\n")}
76
95
  \`\`\`
77
96
  `;
97
+ }
78
98
  }
79
99
  let content = `Always verify if there is a ${configFile} file in the root of the project and familiarize yourself with the scripts available in it and the libraries already installed in the project.
80
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nshiab/setup-data-project",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "Quickly kick off your data project using the simple-data-analysis and journalism libraries.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +1 @@
1
- {"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAgIvD"}
1
+ {"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAgJvD"}
@@ -9,21 +9,23 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
9
9
  let sdaClassesAndMethods = "";
10
10
  let sdaDocsPath = "";
11
11
  let sdaLibraryName = "";
12
+ const journalismFunctionsByPackage = new Map();
12
13
  for (const [pkg, doc] of Object.entries(docsMapping)) {
13
14
  const pkgConfig = packageRegistry_js_1.SUPPORTED_PACKAGES.find((p) => p.value === pkg);
14
15
  const pkgType = pkgConfig?.type || "other";
15
16
  if (pkgType === "journalism") {
16
17
  const repoName = pkg.split("/")[1];
17
- journalismFunctions += `\n### ${repoName}\n\n`;
18
- journalismFunctions += doc
18
+ const functions = doc
19
19
  .split("\n")
20
20
  .filter((line) => line.trim().startsWith("#"))
21
21
  .filter((line) => {
22
22
  const depth = line.match(/^#+/)?.[0].length || 0;
23
- return depth >= 2; // Match ##, ###, #### etc.
23
+ return depth === 2;
24
24
  })
25
- .map((line) => line.replace(/^#+\s+/, "").trim())
26
- .join("\n") + "\n";
25
+ .map((line) => line.replace(/^#+\s+/, "").trim());
26
+ journalismFunctionsByPackage.set(pkg, functions);
27
+ journalismFunctions += `\n### ${repoName}\n\n`;
28
+ journalismFunctions += functions.join("\n") + "\n";
27
29
  }
28
30
  else if (pkgType === "sda") {
29
31
  const repoName = pkg.split("/")[1];
@@ -34,7 +36,13 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
34
36
  .filter((line) => line.trim().startsWith("#"))
35
37
  .filter((line) => {
36
38
  const depth = line.match(/^#+/)?.[0].length || 0;
37
- return depth === 2 || depth === 4;
39
+ if (depth === 2)
40
+ return true;
41
+ if (depth !== 4)
42
+ return false;
43
+ const heading = line.replace(/^#+\s+/, "").replaceAll("`", "")
44
+ .trim();
45
+ return heading !== "Parameters";
38
46
  })
39
47
  .map((line) => {
40
48
  const depth = line.match(/^#+/)?.[0].length || 0;
@@ -42,8 +50,7 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
42
50
  return "\n" + line.replace(/^#+\s+/, "").trim();
43
51
  }
44
52
  else {
45
- return line.replace(/^#+\s+Parameters/, " - ")
46
- .replace(/^#+\s+/, " - ")
53
+ return line.replace(/^#+\s+/, " - ")
47
54
  .replaceAll("`", "");
48
55
  }
49
56
  })
@@ -63,21 +70,34 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
63
70
  ? "bun run all-tests"
64
71
  : "npm run all-tests";
65
72
  const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
66
- const importExamples = installedPackageConfigs.map((pkg) => {
67
- const repoName = pkg.value.split("/")[1];
68
- const identifier = repoName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
69
- return `import * as ${identifier} from "${pkg.value}";`;
73
+ const importExamples = installedPackageConfigs.flatMap((pkg) => {
74
+ if (pkg.type === "sda") {
75
+ return [`import { SimpleDB } from "${pkg.value}";`];
76
+ }
77
+ const functionName = journalismFunctionsByPackage.get(pkg.value)
78
+ ?.map((name) => name.replaceAll("`", ""))
79
+ .find((name) => /^[A-Za-z_$][\w$]*$/.test(name));
80
+ return functionName
81
+ ? [`import { ${functionName} } from "${pkg.value}";`]
82
+ : [];
70
83
  });
71
84
  let libraryGuidance = "";
72
85
  if (installedPackageConfigs.length > 0) {
73
- const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.label}"`)
86
+ const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.value}"`)
74
87
  .join(", ");
88
+ const libraryNoun = installedPackageConfigs.length === 1
89
+ ? "library"
90
+ : "libraries";
75
91
  libraryGuidance = `
76
- Always prioritize the installed ${libraryNames} libraries when relevant. They can be imported directly like this:
92
+ Always prioritize the installed ${libraryNames} ${libraryNoun} when relevant.
93
+ `;
94
+ if (importExamples.length > 0) {
95
+ libraryGuidance += `APIs can be imported with named imports like this:
77
96
  \`\`\`typescript
78
97
  ${importExamples.join("\n")}
79
98
  \`\`\`
80
99
  `;
100
+ }
81
101
  }
82
102
  let content = `Always verify if there is a ${configFile} file in the root of the project and familiarize yourself with the scripts available in it and the libraries already installed in the project.
83
103