@nshiab/setup-data-project 1.0.39 → 2.0.1

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 (60) hide show
  1. package/README.md +12 -5
  2. package/esm/helpers/createFolderStructure.d.ts.map +1 -1
  3. package/esm/helpers/createFolderStructure.js +4 -5
  4. package/esm/helpers/ensureAgents.d.ts +2 -1
  5. package/esm/helpers/ensureAgents.d.ts.map +1 -1
  6. package/esm/helpers/ensureAgents.js +40 -4
  7. package/esm/helpers/ensureManagedSection.d.ts.map +1 -1
  8. package/esm/helpers/ensureManagedSection.js +5 -2
  9. package/esm/helpers/ensureReadme.d.ts.map +1 -1
  10. package/esm/helpers/ensureReadme.js +7 -3
  11. package/esm/helpers/fetchPackageDocs.d.ts +8 -0
  12. package/esm/helpers/fetchPackageDocs.d.ts.map +1 -0
  13. package/esm/helpers/fetchPackageDocs.js +75 -0
  14. package/esm/helpers/getInstalledPackageVersions.d.ts +2 -0
  15. package/esm/helpers/getInstalledPackageVersions.d.ts.map +1 -0
  16. package/esm/helpers/getInstalledPackageVersions.js +91 -0
  17. package/esm/helpers/getProjectTasks.js +1 -1
  18. package/esm/helpers/installPackages.d.ts +7 -0
  19. package/esm/helpers/installPackages.d.ts.map +1 -0
  20. package/esm/helpers/installPackages.js +59 -0
  21. package/esm/helpers/projectManifest.d.ts +1 -0
  22. package/esm/helpers/projectManifest.d.ts.map +1 -1
  23. package/esm/helpers/projectManifest.js +10 -3
  24. package/esm/helpers/syncPackageDocs.d.ts +2 -1
  25. package/esm/helpers/syncPackageDocs.d.ts.map +1 -1
  26. package/esm/helpers/syncPackageDocs.js +31 -12
  27. package/esm/main.js +10 -5
  28. package/package.json +2 -2
  29. package/script/helpers/createFolderStructure.d.ts.map +1 -1
  30. package/script/helpers/createFolderStructure.js +4 -5
  31. package/script/helpers/ensureAgents.d.ts +2 -1
  32. package/script/helpers/ensureAgents.d.ts.map +1 -1
  33. package/script/helpers/ensureAgents.js +40 -4
  34. package/script/helpers/ensureManagedSection.d.ts.map +1 -1
  35. package/script/helpers/ensureManagedSection.js +5 -2
  36. package/script/helpers/ensureReadme.d.ts.map +1 -1
  37. package/script/helpers/ensureReadme.js +7 -3
  38. package/script/helpers/fetchPackageDocs.d.ts +8 -0
  39. package/script/helpers/fetchPackageDocs.d.ts.map +1 -0
  40. package/script/helpers/fetchPackageDocs.js +78 -0
  41. package/script/helpers/getInstalledPackageVersions.d.ts +2 -0
  42. package/script/helpers/getInstalledPackageVersions.d.ts.map +1 -0
  43. package/script/helpers/getInstalledPackageVersions.js +94 -0
  44. package/script/helpers/getProjectTasks.js +1 -1
  45. package/script/helpers/installPackages.d.ts +7 -0
  46. package/script/helpers/installPackages.d.ts.map +1 -0
  47. package/script/helpers/installPackages.js +96 -0
  48. package/script/helpers/projectManifest.d.ts +1 -0
  49. package/script/helpers/projectManifest.d.ts.map +1 -1
  50. package/script/helpers/projectManifest.js +10 -3
  51. package/script/helpers/syncPackageDocs.d.ts +2 -1
  52. package/script/helpers/syncPackageDocs.d.ts.map +1 -1
  53. package/script/helpers/syncPackageDocs.js +30 -11
  54. package/script/main.js +10 -5
  55. package/esm/helpers/installPackagesAndFetchDocs.d.ts +0 -10
  56. package/esm/helpers/installPackagesAndFetchDocs.d.ts.map +0 -1
  57. package/esm/helpers/installPackagesAndFetchDocs.js +0 -100
  58. package/script/helpers/installPackagesAndFetchDocs.d.ts +0 -10
  59. package/script/helpers/installPackagesAndFetchDocs.d.ts.map +0 -1
  60. package/script/helpers/installPackagesAndFetchDocs.js +0 -138
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nshiab/setup-data-project",
3
- "version": "1.0.39",
4
- "description": "Quickly kick off your data project using the simple-data-analysis and journalism libraries.",
3
+ "version": "2.0.1",
4
+ "description": "Quickly kick off a project using simple-data-analysis-core, simple-data-analysis, and journalism libraries.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/nshiab/setup-data-project"
@@ -1 +1 @@
1
- {"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAIA,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UA8C/D"}
1
+ {"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAIA,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UA6C/D"}
@@ -28,12 +28,11 @@ function createFolderStructure(selectedPackages) {
28
28
  const sdb = new SimpleDB();
29
29
  const table = sdb.newTable();
30
30
 
31
- // Do your magic here!
32
- // await table.loadData("./sda/data/...");
31
+ await table
32
+ .loadArray([{ message: "Hello simple-data-analysis!" }])
33
+ .log();
33
34
 
34
- await table.logTable();
35
-
36
- await sdb.done();
35
+ await sdb.close();
37
36
  `;
38
37
  }
39
38
  if ((0, node_fs_1.lstatSync)(mainTsPath, { throwIfNoEntry: false }) === undefined) {
@@ -1,2 +1,3 @@
1
- export declare function ensureAgents(docsMapping: Record<string, string>, runtime: string, installedPackages?: string[]): void;
1
+ import type { PackageDocs } from "./fetchPackageDocs.js";
2
+ export declare function ensureAgents(docsMapping: Record<string, PackageDocs>, runtime: string, installedPackages?: string[]): void;
2
3
  //# sourceMappingURL=ensureAgents.d.ts.map
@@ -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,QAiJvD"}
1
+ {"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOzD,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACxC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAqLvD"}
@@ -8,11 +8,15 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
8
8
  let journalismFunctions = "";
9
9
  let sdaClassesAndMethods = "";
10
10
  let sdaDocsPath = "";
11
+ let sdaReadmePath = "";
11
12
  let sdaLibraryName = "";
12
13
  const journalismFunctionsByPackage = new Map();
13
- for (const [pkg, doc] of Object.entries(docsMapping)) {
14
+ for (const [pkg, docs] of Object.entries(docsMapping)) {
14
15
  const pkgConfig = packageRegistry_js_1.SUPPORTED_PACKAGES.find((p) => p.value === pkg);
15
16
  const pkgType = pkgConfig?.type || "other";
17
+ const doc = docs.llm;
18
+ if (doc === undefined)
19
+ continue;
16
20
  if (pkgType === "journalism") {
17
21
  const repoName = pkg.split("/")[1];
18
22
  const functions = doc
@@ -30,7 +34,10 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
30
34
  }
31
35
  else if (pkgType === "sda") {
32
36
  const repoName = pkg.split("/")[1];
33
- sdaDocsPath = `./docs/${repoName}.md`;
37
+ sdaDocsPath = `./docs/${repoName}/llm.md`;
38
+ sdaReadmePath = docs.readme === undefined
39
+ ? ""
40
+ : `./docs/${repoName}/README.md`;
34
41
  sdaLibraryName = pkgConfig?.label || repoName;
35
42
  sdaClassesAndMethods = doc
36
43
  .split("\n")
@@ -92,6 +99,30 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
92
99
  libraryGuidance = `
93
100
  Always prioritize the installed ${libraryNames} ${libraryNoun} when relevant.
94
101
  `;
102
+ const documentationGuidance = installedPackageConfigs.flatMap((pkg) => {
103
+ const docs = docsMapping[pkg.value];
104
+ if (!docs)
105
+ return [];
106
+ const repoName = pkg.value.split("/")[1];
107
+ const availableDocs = [
108
+ docs.readme === undefined
109
+ ? ""
110
+ : `overview and practical examples at \`./docs/${repoName}/README.md\``,
111
+ docs.llm === undefined
112
+ ? ""
113
+ : `complete API documentation at \`./docs/${repoName}/llm.md\``,
114
+ ].filter(Boolean);
115
+ return availableDocs.length === 0
116
+ ? []
117
+ : [`- \`${pkg.value}\`: ${availableDocs.join("; ")}`];
118
+ });
119
+ if (documentationGuidance.length > 0) {
120
+ libraryGuidance += `
121
+ The following documentation was fetched for the exact installed library versions. Consult it when relevant:
122
+
123
+ ${documentationGuidance.join("\n")}
124
+ `;
125
+ }
95
126
  if (importExamples.length > 0) {
96
127
  libraryGuidance += `APIs can be imported with named imports like this:
97
128
  \`\`\`typescript
@@ -120,12 +151,17 @@ If you need to output data to a file, always put the file in the "sda/output" fo
120
151
  ${libraryGuidance}`;
121
152
  if (journalismFunctions !== "") {
122
153
  content += `
123
- Here are the functions available in the "journalism" libraries. If one of the function might be relevant, read the complete documentation in the "./docs/" folder to properly use it.
154
+ Here are the functions available in the "journalism" libraries. If one of the functions might be relevant, search its complete API documentation in the corresponding \`./docs/<library-name>/llm.md\` file to properly use it.
124
155
  ${journalismFunctions}`;
125
156
  }
126
157
  if (sdaClassesAndMethods !== "") {
158
+ const readmeGuidance = sdaReadmePath === ""
159
+ ? ""
160
+ : ` An overview and practical examples are available at "${sdaReadmePath}".`;
127
161
  content += `
128
- Here are the classes and their methods available in the "${sdaLibraryName}" library. If one of the classes or methods might be relevant, read the complete documentation at "${sdaDocsPath}" to properly use it. Remember that almost all methods are asynchronous, so you need to use \`await\` when calling them.
162
+ Here are the classes and their methods available in the "${sdaLibraryName}" library.${readmeGuidance} If one of the classes or methods might be relevant, search the complete API documentation at "${sdaDocsPath}" to properly use it.
163
+
164
+ Most data-loading and transformation methods are synchronous, chainable builders. Await the final asynchronous observer or export method, such as \`log()\`, \`getData()\`, or \`writeData()\`, to execute the queued operations. If a chain ends without an observer, call \`run()\`. Always call \`await sdb.close()\` when the database is no longer needed. Methods that return an answer or export to an external service can be asynchronous, so verify their documentation before calling them.
129
165
  ${sdaClassesAndMethods}`;
130
166
  }
131
167
  const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
@@ -1 +1 @@
1
- {"version":3,"file":"ensureManagedSection.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureManagedSection.ts"],"names":[],"mappings":"AAGA,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5C;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,iBAAiB,CAqCzD"}
1
+ {"version":3,"file":"ensureManagedSection.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureManagedSection.ts"],"names":[],"mappings":"AAGA,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5C;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,iBAAiB,CAwCzD"}
@@ -11,7 +11,7 @@ function ensureManagedSection(options) {
11
11
  ? `${startMarker}\n${endMarker}`
12
12
  : `${startMarker}\n${trimmedContent}\n${endMarker}`;
13
13
  if (!(0, node_fs_1.existsSync)(options.path)) {
14
- (0, node_fs_1.writeFileSync)(options.path, options.createContent(section));
14
+ (0, node_fs_1.writeFileSync)(options.path, ensureFinalNewline(options.createContent(section)));
15
15
  return "created";
16
16
  }
17
17
  const currentContent = (0, node_fs_1.readFileSync)(options.path, "utf-8");
@@ -28,6 +28,9 @@ function ensureManagedSection(options) {
28
28
  if (nextContent === currentContent) {
29
29
  return "unchanged";
30
30
  }
31
- (0, node_fs_1.writeFileSync)(options.path, nextContent);
31
+ (0, node_fs_1.writeFileSync)(options.path, ensureFinalNewline(nextContent));
32
32
  return "updated";
33
33
  }
34
+ function ensureFinalNewline(content) {
35
+ return content.endsWith("\n") ? content : content + "\n";
36
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"ensureReadme.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureReadme.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAAO,QA4DjC"}
1
+ {"version":3,"file":"ensureReadme.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureReadme.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAAO,QAsEjC"}
@@ -13,17 +13,21 @@ function ensureReadme(runtime, installedPackages = []) {
13
13
  runCommand = "bun run";
14
14
  }
15
15
  const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
16
- const hasSda = installedPackageConfigs.some((pkg) => pkg.type === "sda");
16
+ const hasSdaCore = installedPackageConfigs.some((pkg) => pkg.value === "@nshiab/simple-data-analysis-core");
17
+ const hasFullSda = installedPackageConfigs.some((pkg) => pkg.value === "@nshiab/simple-data-analysis");
17
18
  const hasJournalism = installedPackageConfigs.some((pkg) => pkg.type === "journalism");
18
19
  const libraryLinks = [
19
- hasSda
20
+ hasSdaCore
21
+ ? "[simple-data-analysis-core](https://github.com/nshiab/simple-data-analysis-core)"
22
+ : "",
23
+ hasFullSda
20
24
  ? "[simple-data-analysis](https://github.com/nshiab/simple-data-analysis)"
21
25
  : "",
22
26
  hasJournalism ? "[journalism](https://github.com/nshiab/journalism)" : "",
23
27
  ].filter(Boolean);
24
28
  const librarySection = libraryLinks.length === 0
25
29
  ? ""
26
- : `It has installed ${libraryLinks.join(" and ")} libraries, along with
30
+ : `It has installed ${libraryLinks.join(" and ")} ${libraryLinks.length === 1 ? "library" : "libraries"}, along with
27
31
  up-to-date documentation and AI agent instructions.`;
28
32
  const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
29
33
  path: "README.md",
@@ -0,0 +1,8 @@
1
+ export interface PackageDocs {
2
+ readme?: string;
3
+ llm?: string;
4
+ }
5
+ export declare function fetchPackageDocs(pkg: string, version: string, options?: {
6
+ silent?: boolean;
7
+ }): Promise<PackageDocs>;
8
+ //# sourceMappingURL=fetchPackageDocs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchPackageDocs.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAiBD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,WAAW,CAAC,CA4DtB"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchPackageDocs = fetchPackageDocs;
4
+ const prompts_1 = require("@clack/prompts");
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const PACKAGE_DOCUMENTS = [
8
+ {
9
+ remoteName: "README.md",
10
+ localName: "README.md",
11
+ key: "readme",
12
+ label: "README",
13
+ },
14
+ {
15
+ remoteName: "llm.md",
16
+ localName: "llm.md",
17
+ key: "llm",
18
+ label: "API documentation",
19
+ },
20
+ ];
21
+ async function fetchPackageDocs(pkg, version, options = {}) {
22
+ const repoName = pkg.split("/")[1];
23
+ const docsDirectory = (0, node_path_1.join)("docs", repoName);
24
+ (0, node_fs_1.mkdirSync)(docsDirectory, { recursive: true });
25
+ const sFetch = (0, prompts_1.spinner)();
26
+ if (!options.silent) {
27
+ sFetch.start(`Fetching documentation for ${pkg}@${version}...`);
28
+ }
29
+ const fetchedDocuments = await Promise.all(PACKAGE_DOCUMENTS.map(async (document) => {
30
+ const localPath = (0, node_path_1.join)(docsDirectory, document.localName);
31
+ try {
32
+ const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
33
+ `/refs/tags/v${version}/${document.remoteName}`;
34
+ const response = await fetch(url);
35
+ if (!response.ok) {
36
+ warnAboutFailedFetch(pkg, version, document.label, localPath);
37
+ return { key: document.key, content: undefined };
38
+ }
39
+ const content = await response.text();
40
+ (0, node_fs_1.writeFileSync)(localPath, content);
41
+ return { key: document.key, content };
42
+ }
43
+ catch (error) {
44
+ warnAboutFailedFetch(pkg, version, document.label, localPath);
45
+ console.error(error);
46
+ return { key: document.key, content: undefined };
47
+ }
48
+ }));
49
+ const docs = {};
50
+ for (const document of fetchedDocuments) {
51
+ if (document.content !== undefined) {
52
+ docs[document.key] = document.content;
53
+ }
54
+ }
55
+ const savedCount = fetchedDocuments.filter((document) => document.content !== undefined)
56
+ .length;
57
+ if (!options.silent) {
58
+ if (savedCount === PACKAGE_DOCUMENTS.length) {
59
+ sFetch.stop(`✅ Documentation for ${pkg}@${version} saved!`);
60
+ }
61
+ else if (savedCount > 0) {
62
+ sFetch.stop(`⚠️ Some documentation for ${pkg}@${version} could not be fetched.`);
63
+ }
64
+ else {
65
+ sFetch.stop(`❌ Failed to fetch documentation for ${pkg}@${version}.`);
66
+ }
67
+ }
68
+ return docs;
69
+ }
70
+ function warnAboutFailedFetch(pkg, version, label, localPath) {
71
+ const existingFileGuidance = (0, node_fs_1.existsSync)(localPath)
72
+ ? ` The existing file at ${localPath} was preserved, but it may not ` +
73
+ "match the installed version. Double-check it before relying on it, or " +
74
+ "remove it."
75
+ : "";
76
+ prompts_1.log.warn(`Could not fetch ${label} for ${pkg}@${version} from its GitHub tag.` +
77
+ existingFileGuidance);
78
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getInstalledPackageVersions(packageSpecifiers: Record<string, string>): Record<string, string>;
2
+ //# sourceMappingURL=getInstalledPackageVersions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInstalledPackageVersions.d.ts","sourceRoot":"","sources":["../../src/helpers/getInstalledPackageVersions.ts"],"names":[],"mappings":"AAKA,wBAAgB,2BAA2B,CACzC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuBxB"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInstalledPackageVersions = getInstalledPackageVersions;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ function getInstalledPackageVersions(packageSpecifiers) {
7
+ const denoLock = readJsonFile("deno.lock");
8
+ const packageLock = readJsonFile("package-lock.json");
9
+ const bunLock = (0, node_fs_1.existsSync)("bun.lock")
10
+ ? (0, node_fs_1.readFileSync)("bun.lock", "utf-8")
11
+ : undefined;
12
+ const versions = {};
13
+ for (const [pkg, specifier] of Object.entries(packageSpecifiers)) {
14
+ const version = specifier.startsWith("jsr:")
15
+ ? getDenoLockVersion(pkg, specifier, denoLock) ??
16
+ getExactVersion(specifier)
17
+ : getNodeModulesVersion(pkg) ??
18
+ getPackageLockVersion(pkg, packageLock) ??
19
+ getBunLockVersion(pkg, bunLock) ??
20
+ getExactVersion(specifier);
21
+ if (version !== undefined) {
22
+ versions[pkg] = version;
23
+ }
24
+ }
25
+ return versions;
26
+ }
27
+ function getNodeModulesVersion(pkg) {
28
+ const packageJson = readJsonFile((0, node_path_1.join)("node_modules", ...pkg.split("/"), "package.json"));
29
+ return typeof packageJson?.version === "string"
30
+ ? getExactVersion(packageJson.version)
31
+ : undefined;
32
+ }
33
+ function getDenoLockVersion(pkg, specifier, lock) {
34
+ if (!lock || !specifier.startsWith("jsr:"))
35
+ return undefined;
36
+ const specifiers = asObject(lock.specifiers);
37
+ if (!specifiers)
38
+ return undefined;
39
+ const directVersion = specifiers[specifier];
40
+ if (typeof directVersion === "string")
41
+ return getExactVersion(directVersion);
42
+ const prefix = `jsr:${pkg}@`;
43
+ const matchingVersions = Object.entries(specifiers)
44
+ .filter(([key, value]) => key.startsWith(prefix) && typeof value === "string")
45
+ .flatMap(([, value]) => {
46
+ const version = getExactVersion(value);
47
+ return version === undefined ? [] : [version];
48
+ });
49
+ const uniqueVersions = [...new Set(matchingVersions)];
50
+ return uniqueVersions.length === 1 ? uniqueVersions[0] : undefined;
51
+ }
52
+ function getPackageLockVersion(pkg, lock) {
53
+ if (!lock)
54
+ return undefined;
55
+ const packages = asObject(lock.packages);
56
+ const packageEntry = packages
57
+ ? asObject(packages[`node_modules/${pkg}`])
58
+ : undefined;
59
+ if (typeof packageEntry?.version === "string") {
60
+ return getExactVersion(packageEntry.version);
61
+ }
62
+ const dependencies = asObject(lock.dependencies);
63
+ const dependencyEntry = dependencies
64
+ ? asObject(dependencies[pkg])
65
+ : undefined;
66
+ return typeof dependencyEntry?.version === "string"
67
+ ? getExactVersion(dependencyEntry.version)
68
+ : undefined;
69
+ }
70
+ function getBunLockVersion(pkg, lock) {
71
+ if (!lock)
72
+ return undefined;
73
+ const escapedPackage = pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
74
+ const match = lock.match(new RegExp(`"${escapedPackage}"\\s*:\\s*\\[\\s*"${escapedPackage}@(\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?)"`));
75
+ return match?.[1];
76
+ }
77
+ function getExactVersion(specifier) {
78
+ return specifier.match(/(?:^|@)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/)?.[1];
79
+ }
80
+ function readJsonFile(path) {
81
+ if (!(0, node_fs_1.existsSync)(path))
82
+ return undefined;
83
+ try {
84
+ return asObject(JSON.parse((0, node_fs_1.readFileSync)(path, "utf-8")));
85
+ }
86
+ catch {
87
+ return undefined;
88
+ }
89
+ }
90
+ function asObject(value) {
91
+ return value !== null && typeof value === "object" && !Array.isArray(value)
92
+ ? value
93
+ : undefined;
94
+ }
@@ -11,7 +11,7 @@ function getProjectTasks() {
11
11
  ? "bun run --watch sda/main.ts"
12
12
  : "node --env-file-if-exists=.env --watch --experimental-strip-types sda/main.ts",
13
13
  "all-tests": runtime === "deno"
14
- ? "deno fmt --check && deno lint && deno check sda/main.ts && deno test -A"
14
+ ? "deno fmt --check sda && deno lint && deno check sda/main.ts && deno test -A --permit-no-files"
15
15
  : runtime === "bun"
16
16
  ? "bun test --pass-with-no-tests"
17
17
  : "node --env-file-if-exists=.env --experimental-strip-types --test",
@@ -0,0 +1,7 @@
1
+ export declare const commandRunner: {
2
+ exec: any;
3
+ };
4
+ export declare function installPackages(selectedPackages: string[], options?: {
5
+ silent?: boolean;
6
+ }): Promise<void>;
7
+ //# sourceMappingURL=installPackages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installPackages.d.ts","sourceRoot":"","sources":["../../src/helpers/installPackages.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa;;CAEzB,CAAC;AASF,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,IAAI,CAAC,CAmDf"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.commandRunner = void 0;
37
+ exports.installPackages = installPackages;
38
+ const prompts_1 = require("@clack/prompts");
39
+ const childProcess = __importStar(require("node:child_process"));
40
+ const getRuntime_js_1 = require("./getRuntime.js");
41
+ exports.commandRunner = {
42
+ exec: childProcess.exec,
43
+ };
44
+ // Temporary: remove this bypass after the 2.0 release window.
45
+ // https://github.com/nshiab/setup-data-project/issues/15
46
+ const PACKAGES_WITH_FRESH_DENO_RELEASES = new Set([
47
+ "@nshiab/simple-data-analysis-core",
48
+ "@nshiab/simple-data-analysis",
49
+ ]);
50
+ async function installPackages(selectedPackages, options = {}) {
51
+ const runtime = (0, getRuntime_js_1.getRuntime)();
52
+ for (const selectedPackage of selectedPackages) {
53
+ const packagesToInstall = [selectedPackage];
54
+ if (selectedPackage === "@nshiab/simple-data-analysis" ||
55
+ selectedPackage === "@nshiab/journalism-dataviz") {
56
+ packagesToInstall.push("@observablehq/plot");
57
+ }
58
+ for (const pkg of packagesToInstall) {
59
+ const s = (0, prompts_1.spinner)();
60
+ const isObservablePlot = pkg === "@observablehq/plot";
61
+ const minimumDependencyAgeOption = PACKAGES_WITH_FRESH_DENO_RELEASES.has(pkg) ? " --min-dep-age=0" : "";
62
+ const installCmd = runtime === "deno"
63
+ ? (isObservablePlot
64
+ ? "deno add npm:" + pkg
65
+ : "deno add" + minimumDependencyAgeOption + " jsr:" +
66
+ pkg)
67
+ : runtime === "bun"
68
+ ? "bun add " + pkg
69
+ : "npm install " + pkg;
70
+ if (!options.silent) {
71
+ s.start("Installing " + pkg + " via " + runtime + "...");
72
+ }
73
+ try {
74
+ await new Promise((resolve, reject) => {
75
+ exports.commandRunner.exec(installCmd, (error) => {
76
+ if (error) {
77
+ reject(error);
78
+ }
79
+ else {
80
+ resolve();
81
+ }
82
+ });
83
+ });
84
+ if (!options.silent) {
85
+ s.stop("✅ " + pkg + " installed!");
86
+ }
87
+ }
88
+ catch (error) {
89
+ if (!options.silent) {
90
+ s.stop("❌ Failed to install " + pkg + ".");
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ }
96
+ }
@@ -5,6 +5,7 @@ export declare class ProjectManifest {
5
5
  static open(runtime: Runtime): ProjectManifest;
6
6
  reload(): void;
7
7
  getInstalledPackages(): string[];
8
+ getInstalledPackageSpecifiers(): Record<string, string>;
8
9
  updateTasks(tasks: Record<string, string>): void;
9
10
  }
10
11
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"projectManifest.d.ts","sourceRoot":"","sources":["../../src/helpers/projectManifest.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAGvC,qBAAa,eAAe;;IAM1B,OAAO;IAYP,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IA6B9C,MAAM,IAAI,IAAI;IAId,oBAAoB,IAAI,MAAM,EAAE;IAgBhC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAUjD"}
1
+ {"version":3,"file":"projectManifest.d.ts","sourceRoot":"","sources":["../../src/helpers/projectManifest.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAGvC,qBAAa,eAAe;;IAM1B,OAAO;IAYP,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IA6B9C,MAAM,IAAI,IAAI;IAId,oBAAoB,IAAI,MAAM,EAAE;IAIhC,6BAA6B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAoBvD,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAcjD"}
@@ -40,12 +40,19 @@ class ProjectManifest {
40
40
  __classPrivateFieldSet(this, _ProjectManifest_config, readManifest(__classPrivateFieldGet(this, _ProjectManifest_path, "f")), "f");
41
41
  }
42
42
  getInstalledPackages() {
43
- const installed = [];
43
+ return Object.keys(this.getInstalledPackageSpecifiers());
44
+ }
45
+ getInstalledPackageSpecifiers() {
46
+ const installed = {};
44
47
  for (const key of __classPrivateFieldGet(this, _ProjectManifest_dependencyKeys, "f")) {
45
48
  const dependencies = __classPrivateFieldGet(this, _ProjectManifest_config, "f")[key];
46
49
  if (dependencies && typeof dependencies === "object" &&
47
50
  !Array.isArray(dependencies)) {
48
- installed.push(...Object.keys(dependencies));
51
+ for (const [name, specifier] of Object.entries(dependencies)) {
52
+ if (typeof specifier === "string") {
53
+ installed[name] = specifier;
54
+ }
55
+ }
49
56
  }
50
57
  }
51
58
  return installed;
@@ -57,7 +64,7 @@ class ProjectManifest {
57
64
  ? currentTasks
58
65
  : {};
59
66
  __classPrivateFieldGet(this, _ProjectManifest_config, "f")[__classPrivateFieldGet(this, _ProjectManifest_taskKey, "f")] = { ...existingTasks, ...tasks };
60
- (0, node_fs_1.writeFileSync)(__classPrivateFieldGet(this, _ProjectManifest_path, "f"), JSON.stringify(__classPrivateFieldGet(this, _ProjectManifest_config, "f"), null, 2), "utf-8");
67
+ (0, node_fs_1.writeFileSync)(__classPrivateFieldGet(this, _ProjectManifest_path, "f"), JSON.stringify(__classPrivateFieldGet(this, _ProjectManifest_config, "f"), null, 2) + "\n", "utf-8");
61
68
  }
62
69
  }
63
70
  exports.ProjectManifest = ProjectManifest;
@@ -1,2 +1,3 @@
1
- export declare function syncPackageDocs(installedPackages: string[], docsAlreadyRefreshed?: string[]): Promise<Record<string, string>>;
1
+ import { type PackageDocs } from "./fetchPackageDocs.js";
2
+ export declare function syncPackageDocs(installedPackages: string[], installedVersions: Record<string, string>): Promise<Record<string, PackageDocs>>;
2
3
  //# sourceMappingURL=syncPackageDocs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"syncPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/syncPackageDocs.ts"],"names":[],"mappings":"AAMA,wBAAsB,eAAe,CACnC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,GAAE,MAAM,EAAO,GAClC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0BjC"}
1
+ {"version":3,"file":"syncPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/syncPackageDocs.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG3E,wBAAsB,eAAe,CACnC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CA+CtC"}
@@ -4,26 +4,45 @@ exports.syncPackageDocs = syncPackageDocs;
4
4
  const prompts_1 = require("@clack/prompts");
5
5
  const node_fs_1 = require("node:fs");
6
6
  const node_path_1 = require("node:path");
7
- const installPackagesAndFetchDocs_js_1 = require("./installPackagesAndFetchDocs.js");
7
+ const fetchPackageDocs_js_1 = require("./fetchPackageDocs.js");
8
8
  const packageRegistry_js_1 = require("./packageRegistry.js");
9
- async function syncPackageDocs(installedPackages, docsAlreadyRefreshed = []) {
9
+ async function syncPackageDocs(installedPackages, installedVersions) {
10
10
  const installedSet = new Set(installedPackages);
11
- const refreshedSet = new Set(docsAlreadyRefreshed);
12
11
  const docsMapping = {};
13
12
  for (const pkg of packageRegistry_js_1.SUPPORTED_PACKAGES) {
14
- const docPath = (0, node_path_1.join)("docs", pkg.value.split("/")[1] + ".md");
13
+ const repoName = pkg.value.split("/")[1];
14
+ const docsDirectory = (0, node_path_1.join)("docs", repoName);
15
+ const llmDocsPath = (0, node_path_1.join)(docsDirectory, "llm.md");
16
+ const legacyDocsPath = (0, node_path_1.join)("docs", repoName + ".md");
15
17
  if (!installedSet.has(pkg.value)) {
16
- if ((0, node_fs_1.existsSync)(docPath)) {
17
- (0, node_fs_1.rmSync)(docPath);
18
- prompts_1.log.info(`Removed stale documentation at ${docPath}.`);
18
+ for (const path of [docsDirectory, legacyDocsPath]) {
19
+ if ((0, node_fs_1.existsSync)(path)) {
20
+ (0, node_fs_1.rmSync)(path, { recursive: true });
21
+ prompts_1.log.info(`Removed stale documentation at ${path}.`);
22
+ }
19
23
  }
20
24
  continue;
21
25
  }
22
- if (!(0, node_fs_1.existsSync)(docPath) && !refreshedSet.has(pkg.value)) {
23
- await (0, installPackagesAndFetchDocs_js_1.fetchPackageDocs)(pkg.value, { silent: true });
26
+ if ((0, node_fs_1.existsSync)(legacyDocsPath)) {
27
+ if (!(0, node_fs_1.existsSync)(llmDocsPath)) {
28
+ (0, node_fs_1.mkdirSync)(docsDirectory, { recursive: true });
29
+ (0, node_fs_1.renameSync)(legacyDocsPath, llmDocsPath);
30
+ prompts_1.log.info(`Moved documentation to ${llmDocsPath}.`);
31
+ }
32
+ else {
33
+ (0, node_fs_1.rmSync)(legacyDocsPath);
34
+ }
35
+ }
36
+ const version = installedVersions[pkg.value];
37
+ if (version === undefined) {
38
+ prompts_1.log.warn(`Could not determine the exact installed version of ${pkg.value}. ` +
39
+ "Existing local documentation was preserved but will not be " +
40
+ "included in AGENTS.md.");
41
+ continue;
24
42
  }
25
- if ((0, node_fs_1.existsSync)(docPath)) {
26
- docsMapping[pkg.value] = (0, node_fs_1.readFileSync)(docPath, "utf-8");
43
+ const docs = await (0, fetchPackageDocs_js_1.fetchPackageDocs)(pkg.value, version, { silent: true });
44
+ if (docs.readme !== undefined || docs.llm !== undefined) {
45
+ docsMapping[pkg.value] = docs;
27
46
  }
28
47
  }
29
48
  return docsMapping;