Skip to content

Commit

Permalink
feat(npm): smart force scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Jul 3, 2023
1 parent df2f75f commit 22eae2f
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 299 deletions.
560 changes: 276 additions & 284 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"packages/*"
],
"devDependencies": {
"@nice-move/cli": "^0.10.8",
"@nice-move/eslint-config-base": "^0.9.14",
"@nice-move/cli": "^0.10.9",
"@nice-move/eslint-config-base": "^0.9.15",
"@nice-move/prettier-config": "^0.8.1",
"best-shot": "^0.3.6",
"eslint": "^8.43.0",
"best-shot": "^0.4.1",
"eslint": "^8.44.0",
"garou": "^0.6.11",
"playwright-core": "^1.35.1",
"prettier": "^2.8.8"
Expand Down
30 changes: 24 additions & 6 deletions packages/npm/lib/npm/git.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EOL } from 'node:os';
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';

import { logger } from './logger.mjs';
import { Exec } from './utils.mjs';
Expand Down Expand Up @@ -105,15 +105,33 @@ export async function branchCanRelease() {
);
}

export function getFileFromLastCommit(filename) {
export function getFileContentFromLastCommit(filename) {
return Git('show', `HEAD~1:${filename}`);
}

export async function getLastCommitFiles({ force }) {
const fallback = () => Git('ls-files', 'package.json', '*/package.json');
async function getChangedPackages() {
const pkgs = await Git('ls-files', 'package.json', '*/package.json')
.then((raw = '') => raw.split('\n').map((line) => dirname(line)))
.catch(() => []);

const io = [];

for (const pkg of pkgs) {
const check = await Git('diff', '--name-only', 'HEAD~')
.then((raw) => Boolean(raw.trim()))
.catch(() => false);

if (check) {
io.push(pkg);
}
}

return io;
}

export async function getLastCommitFiles({ force }) {
const io = force
? fallback()
? getChangedPackages()
: Git('cat-file', '-t', 'HEAD~1').then(
() =>
Git(
Expand All @@ -128,7 +146,7 @@ export async function getLastCommitFiles({ force }) {
'package.json',
'*/package.json',
),
fallback,
getChangedPackages,
);

const list = await io.then((raw) => (raw ? raw.split('\n') : []));
Expand Down
4 changes: 2 additions & 2 deletions packages/npm/lib/npm/scan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
import { dirname } from 'node:path';

import { filter } from './filter.mjs';
import { getFileFromLastCommit, getLastCommitFiles } from './git.mjs';
import { getFileContentFromLastCommit, getLastCommitFiles } from './git.mjs';
import { logger } from './logger.mjs';
import { Exec } from './utils.mjs';

Expand Down Expand Up @@ -63,7 +63,7 @@ async function versionChanged(list) {
const io = [];

for (const item of list) {
const old = await getFileFromLastCommit(item.pkg)
const old = await getFileContentFromLastCommit(item.pkg)
.then((raw) => JSON.parse(raw))
.catch(() => false);

Expand Down
2 changes: 1 addition & 1 deletion packages/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/npm",
"version": "0.2.4",
"version": "0.2.6",
"description": "Publish npm packages when needed",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"devDependencies": {
"@bring-it/utils": "*",
"cheetor": "^0.13.0",
"globby": "^13.2.0"
"globby": "^13.2.1"
},
"peerDependencies": {
"playwright-core": "^1.33.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/sftp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"devDependencies": {
"@bring-it/utils": "*",
"cheetor": "^0.13.0",
"globby": "^13.2.0",
"globby": "^13.2.1",
"lodash": "^4.17.21",
"node-ssh": "^13.1.0",
"p-all": "^5.0.0",
Expand Down

0 comments on commit 22eae2f

Please sign in to comment.