feat: ✨ pass packages from cli argument
This commit is contained in:
36
fixtures/monorepo/.gitignore
vendored
Normal file
36
fixtures/monorepo/.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
node_modules
|
||||
.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
coverage
|
||||
|
||||
# next.js
|
||||
.next/
|
||||
out/
|
||||
build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# turbo
|
||||
.turbo
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
15
fixtures/monorepo/package.json
Normal file
15
fixtures/monorepo/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test:cli": "pnpm cli"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslit/cli": "workspace:*"
|
||||
},
|
||||
"packageManager": "pnpm@8.6.10",
|
||||
"name": "monorepo",
|
||||
"workspaces": [
|
||||
"apps/*",
|
||||
"packages/*"
|
||||
]
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
"bin": "./src/index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"commander": "^11.0.0",
|
||||
"magic-string": "^0.30.2",
|
||||
"nanospinner": "^1.1.0",
|
||||
"picocolors": "^1.0.0",
|
||||
|
||||
@@ -12,19 +12,20 @@ export default class Cli {
|
||||
/** @type {import('./types').Config[]} */
|
||||
configs;
|
||||
|
||||
/** @type {string[] | undefined} */
|
||||
#packagesPatterns;
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* configs: import('./types').Config[]
|
||||
* configs: import('./types').Config[],
|
||||
* packages?: string[],
|
||||
* workspace?: import('./types').Package[],
|
||||
* directory?: string,
|
||||
* debug?: boolean,
|
||||
* }} options - Cli options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.#packagesPatterns = options.packages;
|
||||
this.configs = options?.configs;
|
||||
this.dir = path.normalize(options.directory ?? this.dir);
|
||||
this.debug = options.debug ?? this.debug;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +137,7 @@ export default class Cli {
|
||||
}
|
||||
|
||||
async run() {
|
||||
let packages = await new Workspace(this.dir).getPackages();
|
||||
let packages = await new Workspace(this.dir, this.#packagesPatterns).getPackages();
|
||||
|
||||
packages = packages.map(
|
||||
pkg => {
|
||||
@@ -144,8 +145,7 @@ export default class Cli {
|
||||
},
|
||||
);
|
||||
|
||||
console.log(packages.length);
|
||||
console.log(this.generateConfigMap(packages));
|
||||
console.log(packages);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import Cli from './cli.js';
|
||||
import configs from './configs.js';
|
||||
import { program } from 'commander';
|
||||
|
||||
const cli = new Cli({ configs });
|
||||
program.option('--packages <string...>');
|
||||
|
||||
program.parse(process.argv);
|
||||
/** @type {{ packages?: string[] } & import('commander').OptionValues} */
|
||||
const options = program.opts();
|
||||
|
||||
const cli = new Cli({ configs, packages: options.packages });
|
||||
await cli.run();
|
||||
|
||||
@@ -56,14 +56,14 @@ async function getPackageName(directory) {
|
||||
}
|
||||
|
||||
export default class Workspace {
|
||||
/** @type {{files: string[], directories: string[]} | undefined} */
|
||||
paths;
|
||||
|
||||
/**
|
||||
* @param {string} directory - The directory to get the workspace from
|
||||
* @param {string[]} [packagePatterns] - List of package patterns
|
||||
*/
|
||||
constructor(directory) {
|
||||
constructor(directory, packagePatterns) {
|
||||
this.dir = directory;
|
||||
this.packagePatterns = packagePatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +109,6 @@ export default class Workspace {
|
||||
};
|
||||
}
|
||||
|
||||
/** @type {string[] | undefined} */
|
||||
packages;
|
||||
|
||||
/**
|
||||
* @returns {Promise<string[]>} - List of packages on a directory;
|
||||
*/
|
||||
@@ -160,11 +157,9 @@ export default class Workspace {
|
||||
async getPackages() {
|
||||
|
||||
const paths = await this.getPaths();
|
||||
const packagePatterns = await this.getPackagePatterns();
|
||||
const packagePatterns = this.packagePatterns ?? await this.getPackagePatterns();
|
||||
const packagePaths = paths.directories.filter(d => picomatch.isMatch(d, packagePatterns));
|
||||
|
||||
console.log(packagePatterns);
|
||||
|
||||
/** @type {import('./types').Package} */
|
||||
const rootPackage = {
|
||||
root: true,
|
||||
|
||||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@@ -43,6 +43,12 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/cli
|
||||
|
||||
fixtures/monorepo:
|
||||
devDependencies:
|
||||
'@eslit/cli':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/cli
|
||||
|
||||
fixtures/svelte:
|
||||
devDependencies:
|
||||
'@eslit/cli':
|
||||
@@ -93,6 +99,9 @@ importers:
|
||||
|
||||
packages/cli:
|
||||
dependencies:
|
||||
commander:
|
||||
specifier: ^11.0.0
|
||||
version: 11.0.0
|
||||
magic-string:
|
||||
specifier: ^0.30.2
|
||||
version: 0.30.2
|
||||
@@ -1426,6 +1435,11 @@ packages:
|
||||
/color-name@1.1.4:
|
||||
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
|
||||
|
||||
/commander@11.0.0:
|
||||
resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==}
|
||||
engines: {node: '>=16'}
|
||||
dev: false
|
||||
|
||||
/comment-parser@1.3.1:
|
||||
resolution: {integrity: sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA==}
|
||||
engines: {node: '>= 12.0.0'}
|
||||
|
||||
Reference in New Issue
Block a user