Skip to content

Commit

Permalink
Merge 42fe4d1 into a3af829
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 26, 2024
2 parents a3af829 + 42fe4d1 commit d8922d9
Show file tree
Hide file tree
Showing 11 changed files with 1,612 additions and 1,478 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: monthly
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,36 @@
name: Lint

on:
push:
branches:
- main
- "!dependabot/**"
pull_request:
workflow_dispatch:

env:
FORCE_COLOR: 2
NODE: 20 # The Node.js version to run lint on

jobs:
run:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
cache: npm

- name: Install npm dependencies
run: npm ci

- name: Run lint
run: npm run lint
60 changes: 24 additions & 36 deletions .github/workflows/test.yml
@@ -1,61 +1,49 @@
name: Tests
on: [push, pull_request]

on:
push:
branches:
- main
- "!dependabot/**"
pull_request:
workflow_dispatch:

env:
CI: true
FORCE_COLOR: 2
NODE_COV: 20 # The Node.js version to run coveralls on

jobs:
run:
test:
name: Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node: [18,20]
node: [18, 20]
os: [ubuntu-latest, windows-latest]

steps:
- name: Clone repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- run: node --version
- run: npm --version

- name: Set up npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-v${{ matrix.node }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-v${{ matrix.node }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
${{ runner.OS }}-node-v${{ matrix.node }}-
architecture: ${{ matrix.architecture }}
cache: npm

- name: Install npm dependencies
run: npm ci

- name: Run tests
run: npm test
run: npm run jest

- name: Coveralls Parallel
uses: coverallsapp/github-action@master
env:
NODE_COVERALLS_DEBUG: 1
- name: Run Coveralls
uses: coverallsapp/github-action@v2
if: startsWith(matrix.os, 'ubuntu') && matrix.node == env.NODE_COV
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.os }}-${{ matrix.node }}
parallel: true

finish:
needs: run
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
github-token: "${{ secrets.GITHUB_TOKEN }}"
4 changes: 2 additions & 2 deletions cli.js
Expand Up @@ -155,15 +155,15 @@ function run(data) {
}
}

(cli.input || []).forEach((file) => {
for (const file of cli.input || []) {
const temporary = read(file);
try {
parse(temporary);
options_.css = temporary;
} catch {
options_.html = temporary;
}
});
}

if (!options_.html || !options_.css) {
cli.showHelp();
Expand Down
14 changes: 7 additions & 7 deletions index.js
Expand Up @@ -107,7 +107,7 @@ export function inline(html, styles, options) {
);

// Add link tags before old links
o.replaceStylesheets.forEach((href) => {
for (const href of o.replaceStylesheets) {
const link = document.createElement('link');

link.setAttribute('rel', 'stylesheet');
Expand Down Expand Up @@ -139,26 +139,26 @@ export function inline(html, styles, options) {
document.remove(link);
}
}
});
}

// Remove old links
removable.forEach((link) => {
for (const link of removable) {
if (link.parentElement.tagName === 'NOSCRIPT') {
document.remove(link.parentElement);
} else {
document.remove(link);
}
});
}
} else {
// Modify links and add clones to noscript block
links.forEach((link) => {
for (const link of links) {
const href = link.getAttribute('href');
const media = link.getAttribute('media');
const type = link.getAttribute('type');
const integrity = link.getAttribute('integrity');

if (['print', 'speech'].includes(media)) {
return;
continue;
}

if (o.extract) {
Expand Down Expand Up @@ -218,7 +218,7 @@ export function inline(html, styles, options) {
document.remove(link);
}
}
});
}
}

return Buffer.from(document.serialize());
Expand Down
8 changes: 8 additions & 0 deletions jest.config.js
@@ -0,0 +1,8 @@
const config = {
coverageProvider: 'v8',
coverageReporters: ['html', 'lcov', 'text'],
collectCoverageFrom: ['cli.js', 'index.js', 'src/*.js', '!**/node_modules/**'],
roots: [''],
};

export default config;

0 comments on commit d8922d9

Please sign in to comment.