@wixc3/codux-librarian
Advanced tools
Comparing version 0.3.1 to 0.4.0
"use strict"; | ||
/* eslint-disable no-console */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -3,0 +4,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; |
@@ -32,2 +32,3 @@ "use strict"; | ||
const board_parsing_error_1 = require("./board-parsing-error"); | ||
const parse_utils_1 = require("../../utils/parse-utils"); | ||
class BoardParser { | ||
@@ -43,2 +44,3 @@ constructor(boardPath, fs) { | ||
const source = await this.getSourceAST(); | ||
const importedPackages = (0, parse_utils_1.getImportedPackages)(source); | ||
const createBoardExpression = this.findCreateBoardExpression(source); | ||
@@ -68,2 +70,3 @@ const boardOptions = createBoardExpression.arguments[0]; | ||
...(boardCover ? { cover: await this.resolveCover(boardCover) } : undefined), | ||
importedPackages | ||
}; | ||
@@ -70,0 +73,0 @@ } |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (!config.manifestOnly) { | ||
this.packageBuilder = new package_builder_1.PackageBuilder({ config, shouldRemoveBuildDir }, this.fs); | ||
this.packageBuilder = new package_builder_1.PackageBuilder({ config, shouldRemoveBuildDir, currentRoot }, this.fs); | ||
} | ||
@@ -23,3 +23,3 @@ this.currentRoot = currentRoot; | ||
const boardPaths = this.findBoards(); | ||
const { boards, errors } = await this.parseBoards(boardPaths); | ||
const { boards, errors, } = await this.parseBoards(boardPaths); | ||
if (errors.length) | ||
@@ -60,3 +60,3 @@ return { errors }; | ||
} | ||
prepareBoardForManifest(board) { | ||
prepareBoardForManifest({ importedPackages: _, ...board }) { | ||
return { | ||
@@ -63,0 +63,0 @@ ...board, |
@@ -6,2 +6,3 @@ import type { IFileSystem } from '@file-services/types'; | ||
shouldRemoveBuildDir?: boolean | undefined; | ||
currentRoot: string; | ||
}; | ||
@@ -12,6 +13,8 @@ export declare class PackageBuilder { | ||
private shouldRemoveBuildDir; | ||
constructor({ config, shouldRemoveBuildDir }: PackageBuilderOptions, fs: IFileSystem); | ||
private currentRoot; | ||
constructor({ config, shouldRemoveBuildDir, currentRoot }: PackageBuilderOptions, fs: IFileSystem); | ||
buildPackage(boards: BoardDetails[]): Promise<void>; | ||
private copyBoards; | ||
private copyBoard; | ||
private getUsedDependencies; | ||
private generatePackageJson; | ||
@@ -18,0 +21,0 @@ } |
@@ -6,6 +6,7 @@ "use strict"; | ||
class PackageBuilder { | ||
constructor({ config, shouldRemoveBuildDir }, fs) { | ||
constructor({ config, shouldRemoveBuildDir, currentRoot }, fs) { | ||
this.fs = fs; | ||
this.config = config; | ||
this.shouldRemoveBuildDir = shouldRemoveBuildDir; | ||
this.currentRoot = currentRoot; | ||
} | ||
@@ -17,4 +18,8 @@ async buildPackage(boards) { | ||
} | ||
const allImportedPackages = new Set(); | ||
boards.forEach(({ importedPackages }) => { | ||
importedPackages.forEach((dep) => allImportedPackages.add(dep)); | ||
}); | ||
this.fs.ensureDirectorySync(buildDir); | ||
await Promise.all([this.copyBoards(boards), this.generatePackageJson()]); | ||
await Promise.all([this.copyBoards(boards), this.generatePackageJson(allImportedPackages)]); | ||
} | ||
@@ -29,3 +34,22 @@ async copyBoards(boards) { | ||
} | ||
async generatePackageJson() { | ||
getUsedDependencies(allImportedPackages) { | ||
const packageJsonPath = this.fs.join(this.currentRoot, 'package.json'); | ||
const packageJson = JSON.parse(this.fs.readFileSync(packageJsonPath, 'utf8')); | ||
const dependencies = packageJson.dependencies || {}; | ||
const peerDependencies = packageJson.peerDependencies || {}; | ||
const usedDependencies = {}; | ||
allImportedPackages.forEach(dep => { | ||
if (dependencies[dep]) { | ||
usedDependencies[dep] = dependencies[dep]; | ||
} | ||
else if (peerDependencies[dep]) { | ||
usedDependencies[dep] = peerDependencies[dep]; | ||
} | ||
else { | ||
throw new Error(`Dependency "${dep}" is used in the board but not listed in package.json dependencies or peerDependencies.`); | ||
} | ||
}); | ||
return usedDependencies; | ||
} | ||
async generatePackageJson(allImportedPackages) { | ||
const { packageName, packageVersion } = this.config; | ||
@@ -38,5 +62,6 @@ const packageJson = { | ||
}, | ||
dependencies: this.getUsedDependencies(allImportedPackages), | ||
}; | ||
const packageJsonPath = this.fs.join(this.config.buildDir, 'package.json'); | ||
await this.fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)); | ||
const outputPackageJsonPath = this.fs.join(this.config.buildDir, 'package.json'); | ||
await this.fs.promises.writeFile(outputPackageJsonPath, JSON.stringify(packageJson, null, 2)); | ||
} | ||
@@ -43,0 +68,0 @@ } |
@@ -8,3 +8,5 @@ export interface BoardDetails { | ||
cover?: string; | ||
/** A set of imported packages used in the board. */ | ||
importedPackages: Set<string>; | ||
} | ||
//# sourceMappingURL=board-details.d.ts.map |
@@ -7,3 +7,5 @@ export interface PackageJson { | ||
}; | ||
dependencies?: Record<string, string>; | ||
peerDependencies?: Record<string, string>; | ||
} | ||
//# sourceMappingURL=package-json.d.ts.map |
{ | ||
"name": "@wixc3/codux-librarian", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -11,3 +11,3 @@ "main": "dist/index.js", | ||
"build": "tsc --build", | ||
"lint": "eslint .", | ||
"lint": "eslint", | ||
"prettify": "npx prettier . --write", | ||
@@ -18,25 +18,27 @@ "pretest": "npm run lint && npm run build", | ||
"dependencies": { | ||
"@file-services/node": "^9.3.1", | ||
"@file-services/resolve": "^9.3.1", | ||
"@file-services/node": "^9.4.1", | ||
"@file-services/resolve": "^9.4.1", | ||
"commander": "^12.1.0", | ||
"js-base64": "^3.7.7", | ||
"supports-hyperlinks": "^3.0.0", | ||
"typescript": "~5.5.2", | ||
"typescript": "~5.5.4", | ||
"zod": "^3.23.8" | ||
}, | ||
"devDependencies": { | ||
"@file-services/memory": "^9.3.1", | ||
"@file-services/types": "^9.3.1", | ||
"@types/chai": "^4.3.16", | ||
"@eslint/compat": "^1.1.1", | ||
"@eslint/js": "^9.9.0", | ||
"@file-services/memory": "^9.4.1", | ||
"@file-services/types": "^9.4.1", | ||
"@types/chai": "^4.3.17", | ||
"@types/chai-as-promised": "^7.1.8", | ||
"@types/mocha": "^10.0.6", | ||
"@types/mocha": "^10.0.7", | ||
"@types/node": "20", | ||
"@typescript-eslint/eslint-plugin": "^7.13.1", | ||
"chai": "^4.4.1", | ||
"chai-as-promised": "^7.1.1", | ||
"eslint": "^8.57.0", | ||
"eslint": "^9.9.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-no-only-tests": "^3.1.0", | ||
"mocha": "^10.4.0" | ||
"mocha": "^10.7.3", | ||
"typescript-eslint": "^8.0.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78585
103
920
15
Updated@file-services/node@^9.4.1
Updatedtypescript@~5.5.4