Skip to content

Commit

Permalink
use base ref
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 1, 2021
1 parent 6cdc626 commit d510dcf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -210,7 +210,7 @@ jobs:
run: 'npm run benchmark -- --revs HEAD HEAD~1'

diff-npm-package:
name: Diff context of NPM package
name: Diff content of NPM package
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand All @@ -224,13 +224,14 @@ jobs:
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}

- name: Generate report
run: 'node resources/diff-npm-package.js HEAD~1 HEAD'
run: 'node resources/diff-npm-package.js ${{ github.event.pull_request.base.sha }} HEAD'

- name: Upload generated report
uses: actions/upload-artifact@v2
with:
name: npm-dist-diff.html
path: ./npm-dist-diff.html
if-no-files-found: ignore

deploy-to-npm-branch:
name: Deploy to `npm` branch
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@
# https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
# https://www.gitignore.io/

/diff-npm-package.html
/.eslintcache
/node_modules
/coverage
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
@@ -1,4 +1,5 @@
# Copied from '.gitignore', please keep it in sync.
/diff-npm-package.html
/.eslintcache
/node_modules
/coverage
Expand Down
1 change: 1 addition & 0 deletions cspell.yml
@@ -1,6 +1,7 @@
language: en
ignorePaths:
# Copied from '.gitignore', please keep it in sync.
- diff-npm-package.html
- .eslintcache
- node_modules
- coverage
Expand Down
16 changes: 9 additions & 7 deletions resources/diff-npm-package.js
Expand Up @@ -12,10 +12,13 @@ fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir);

const args = process.argv.slice(2);
const fromRevision = args.pop() ?? 'HEAD';
const toRevision = args.pop() ?? LOCAL;
let [fromRevision, toRevision] = args;
if (args.length < 2) {
console.warn(`Assuming you meant: diff-npm-package ${fromRevision} ${toRevision}`);
fromRevision = fromRevision ?? 'HEAD';
toRevision = toRevision ?? LOCAL;
console.warn(
`Assuming you meant: diff-npm-package ${fromRevision} ${toRevision}`,
);
}

console.log(`📦 Bulding NPM package for ${fromRevision}...`);
Expand All @@ -24,7 +27,7 @@ const fromPackage = prepareNPMPackage(fromRevision);
console.log(`📦 Bulding NPM package for ${toRevision}...`);
const toPackage = prepareNPMPackage(toRevision);

console.log(`➖➕ Generating diff...`);
console.log('➖➕ Generating diff...');
const diff = exec(`npm diff --diff=${fromPackage} --diff=${toPackage}`);

if (diff === '') {
Expand All @@ -35,7 +38,7 @@ if (diff === '') {
console.log('Report saved to: ', reportPath);
}

function generateReport(diff) {
function generateReport(diffString) {
return `
<!DOCTYPE html>
<html lang="en-us">
Expand All @@ -51,7 +54,7 @@ function generateReport(diff) {
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>
</head>
<script>
const diffString = ${JSON.stringify(diff)};
const diffString = ${JSON.stringify(diffString)};
document.addEventListener('DOMContentLoaded', () => {
const targetElement = document.getElementById('myDiffElement');
Expand All @@ -77,7 +80,6 @@ function generateReport(diff) {
</html>
`;
}

function prepareNPMPackage(revision) {
if (revision === LOCAL) {
exec('npm --quiet run build:npm', { cwd: localRepoDir });
Expand Down

0 comments on commit d510dcf

Please sign in to comment.