Skip to content

Commit

Permalink
Merge pull request #162 from marcalexiei/format
Browse files Browse the repository at this point in the history
chore: add prettier as formatter
  • Loading branch information
elycruz authored Oct 7, 2024
2 parents ee8b04a + 8bcb046 commit 337cb2b
Show file tree
Hide file tree
Showing 19 changed files with 547 additions and 440 deletions.
4 changes: 4 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/commitlintrc.json",
"extends": ["@commitlint/config-conventional"]
}
35 changes: 28 additions & 7 deletions .github/workflows/build-and-test.yml → .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# This workflow performs a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build and Test
name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main, dev ]
branches: [main, dev]

jobs:
build-and-test:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,19 +19,41 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- run: npm ci

- run: npm run output-coverage-lcov

- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: "coverage/tests.lcov"
file: 'coverage/tests.lcov'

code-check:
runs-on: ubuntu-latest

strategy:
matrix:
script: ['format']

name: Code check (${{ matrix.script }})
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- run: npm ci --ignore-scripts

- run: npm run ${{matrix.script}}
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ jobs:
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CHANGELOG.md
test/assets/**
test/fixtures/**
test/snapshots/**
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"singleQuote": true
}
103 changes: 51 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
rollup-plugin-sass [![Build and Test](https://github.com/elycruz/rollup-plugin-sass/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/elycruz/rollup-plugin-sass/actions/workflows/build-and-test.yml) [![issues](https://img.shields.io/github/issues/elycruz/rollup-plugin-sass.svg?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-sass) [![npm](https://img.shields.io/npm/v/rollup-plugin-sass.svg?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-sass) [![mit](https://img.shields.io/npm/l/rollup-plugin-sass.svg?style=flat-square)](https://opensource.org/licenses/MIT) [![Coverage Status](https://coveralls.io/repos/github/elycruz/rollup-plugin-sass/badge.svg?branch=main)](https://coveralls.io/github/elycruz/rollup-plugin-sass?branch=main)
=====
# rollup-plugin-sass [![CI](https://github.com/elycruz/rollup-plugin-sass/actions/workflows/CI.yml/badge.svg)](https://github.com/elycruz/rollup-plugin-sass/actions/workflows/CI.yml) [![issues](https://img.shields.io/github/issues/elycruz/rollup-plugin-sass.svg?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-sass) [![npm](https://img.shields.io/npm/v/rollup-plugin-sass.svg?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-sass) [![mit](https://img.shields.io/npm/l/rollup-plugin-sass.svg?style=flat-square)](https://opensource.org/licenses/MIT) [![Coverage Status](https://coveralls.io/repos/github/elycruz/rollup-plugin-sass/badge.svg?branch=main)](https://coveralls.io/github/elycruz/rollup-plugin-sass?branch=main)

## Installation

Expand All @@ -19,10 +18,8 @@ export default {
file: 'bundle.js',
format: 'cjs',
},
plugins: [
sass()
]
}
plugins: [sass()],
};
```

#### rollup.config.ts
Expand Down Expand Up @@ -54,7 +51,7 @@ Profit.

### `output`

+ Type: `Boolean|String|Function` _(default: false)_
- Type: `Boolean|String|Function` _(default: false)_

```js
sass({
Expand All @@ -76,37 +73,37 @@ sass({
// ]
output(styles, styleNodes) {
writeFileSync('bundle.css', styles);
}
})
},
});
```

### `insert`

+ Type: `Boolean` _(default: false)_
- Type: `Boolean` _(default: false)_

If you specify `true`, the plugin will insert compiled CSS into `<head/>` tag, via utility function that it will output
in your build bundle.

```js
sass({
insert: true
})
insert: true,
});
```

**Usage caveat:**

There is a utility function that handles injecting individual style payloads into the page's head, which is output as `___$insertStyle` by the rollup-plugin-sass plugin.

This function is output to `./dist/node_modules/...`, in user-land builds, so you have to make sure that it isn't
ignored by your build tool(s) (E.g., rollup, webpack etc.); As a solution, you'll just have to make sure that the
directory is "included"/not-"excluded" via your build tools facilities/added-plugins/etc.
ignored by your build tool(s) (E.g., rollup, webpack etc.); As a solution, you'll just have to make sure that the
directory is "included"/not-"excluded" via your build tools facilities/added-plugins/etc.

Additionally, if you're publishing an app to an internal registry, or similar, you'll have to
Additionally, if you're publishing an app to an internal registry, or similar, you'll have to
make sure 'dist/node_modules' isn't ignored in this scenario as well.

### `processor`

+ Type: `Function`
- Type: `Function`

If you specify a function as processor which will be called with compiled css before generate phase.

Expand All @@ -118,10 +115,11 @@ sass({
// Processor will be called with two arguments:
// - style: the compiled css
// - id: import id
processor: css => postcss([autoprefixer])
.process(css)
.then(result => result.css)
})
processor: (css) =>
postcss([autoprefixer])
.process(css)
.then((result) => result.css),
});
```

The `processor` also support object result. Reverse `css` filLed for stylesheet, the rest of the properties can be customized.
Expand All @@ -130,12 +128,12 @@ The `processor` also support object result. Reverse `css` filLed for stylesheet,
sass({
processor(code) {
return {
css: '.body {}',
foo: 'foo',
bar: 'bar',
css: '.body {}',
foo: 'foo',
bar: 'bar',
};
},
})
});
```

Otherwise, you could do:
Expand All @@ -144,45 +142,46 @@ Otherwise, you could do:
import style, { foo, bar } from 'stylesheet';
```

#### Exporting sass variable to *.js
#### Exporting sass variable to \*.js

Example showing how to use [icss-utils](https://www.npmjs.com/package/icss-utils) to extract resulting sass vars
to your *.js bundle:
to your \*.js bundle:

```js
const config = {
input: 'test/fixtures/processor-promise/with-icss-exports.js',
plugins: [
sass({
processor: (css) => new Promise((resolve, reject) => {
const pcssRootNodeRslt = postcss.parse(css),
extractedIcss = extractICSS(pcssRootNodeRslt, true),
cleanedCss = pcssRootNodeRslt.toString(),
out = Object.assign({}, extractedIcss.icssExports, {
css: cleanedCss,
});
// console.table(extractedIcss);
// console.log(out);
resolve(out);
}),
processor: (css) =>
new Promise((resolve, reject) => {
const pcssRootNodeRslt = postcss.parse(css),
extractedIcss = extractICSS(pcssRootNodeRslt, true),
cleanedCss = pcssRootNodeRslt.toString(),
out = Object.assign({}, extractedIcss.icssExports, {
css: cleanedCss,
});
// console.table(extractedIcss);
// console.log(out);
resolve(out);
}),
options: sassOptions,
}),
],
}
};
```

See the [Input file](test/fixtures/processor-promise/with-icss-exports.js) for example on how to access
the exported vars.

### `runtime`

+ Type: `Object` _(default: sass)_
- Type: `Object` _(default: sass)_

If you specify an object, it will be used instead of [sass](https://github.com/sass/dart-sass). You can use this to pass a different sass compiler (for example the `node-sass` npm package).

### `options`

+ Type: `Object`
- Type: `Object`

Options for [sass](https://github.com/sass/dart-sass) or your own runtime sass compiler.

Expand All @@ -192,38 +191,38 @@ Since you can inject variables during sass compilation with node.
```js
sass({
options: {
data: '$color: #000;'
}
})
data: '$color: #000;',
},
});
```

### `include`

+ Type: `string | string[]`
+ Default: `['**/*.sass', '**/*.scss']`
- Type: `string | string[]`
- Default: `['**/*.sass', '**/*.scss']`

Glob of sass/css files to be targeted.

```ts
sass({
include: ['**/*.css', '**/*.sass', '**/*.scss']
})
include: ['**/*.css', '**/*.sass', '**/*.scss'],
});
```

### `exclude`

+ Type: `string | string[]`;
+ Default: `'node_modules/**'`
- Type: `string | string[]`;
- Default: `'node_modules/**'`

Globs to exclude from processing.

```ts
sass({
exclude: 'node_modules/**'
})
exclude: 'node_modules/**',
});
```

## License

[MIT](./LICENSE) [elycruz](https://github.com/elycruz),
[MIT](./LICENSE) [elycruz](https://github.com/elycruz),
[BinRui.Guan](mailto:differui@gmail.com)
1 change: 0 additions & 1 deletion commitlint.config.mjs

This file was deleted.

17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"coverage": "nyc report --reporter=text-lcov | coveralls",
"output-coverage-lcov": "nyc report --reporter=text-lcov > coverage/tests.lcov",
"test:rollup.config.spec.ts": "tsc --project tsconfig.spec.json --noEmit",
"commitlint": "commitlint --edit"
"commitlint": "commitlint --edit",
"format": "prettier . --check",
"format:fix": "prettier . --write"
},
"standard": {
"ignore": [
Expand Down Expand Up @@ -51,7 +53,8 @@
],
"ava": {
"files": [
"./test/*.test.ts"
"./test/*.test.ts",
"!./test/rollup.config.test.ts"
],
"extensions": [
"ts"
Expand Down Expand Up @@ -82,6 +85,7 @@
"icss-utils": "^5.1.0",
"nyc": "^17.0.0",
"postcss": "^8.4.16",
"prettier": "^3.3.3",
"rollup": "^1 || ^2 || ^3",
"sinon": "^18.0.0",
"ts-node": "^10.9.1",
Expand Down
6 changes: 0 additions & 6 deletions rollup.config.spec.ts

This file was deleted.

Loading

0 comments on commit 337cb2b

Please sign in to comment.