Skip to content

Commit

Permalink
👍🏼 improve: bud stylelint compatibility (#2367)
Browse files Browse the repository at this point in the history
- tries `stylelint.mjs` first
- falls back to `stylelint.js`
- adds integration test for command

## Type of change

**PATCH: backwards compatible change**
  • Loading branch information
kellymears authored Jul 8, 2023
1 parent 711074d commit 5a760b4
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 680 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
platform:
- ubuntu-latest
node:
- 18.12.1
- 18.16.1

name: format-check (node@v${{matrix.node}}/${{matrix.platform}})
runs-on: ${{matrix.platform}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-deprecate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup
uses: actions/setup-node@v3
with:
node-version: 18.12.1
node-version: 18.16.1
cache: yarn

- name: Auth
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 18.16.1
cache: yarn

- run: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 18.16.1
cache: yarn

- run: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 18.16.1
cache: yarn

- run: npm install -g npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
platform:
- ubuntu-latest
node:
- 18.12.1
- 18.16.1

name: test node@${{matrix.node}}/${{matrix.platform}}
runs-on: ${{matrix.platform}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
platform:
- ubuntu-latest
node:
- 18.12.1
- 18.16.1

name: integration test (node@v${{matrix.node}}/${{matrix.platform}})
runs-on: ${{matrix.platform}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
platform:
- ubuntu-latest
node:
- 18.12.1
- 18.16.1

name: unit test (node@v${{matrix.node}}/${{matrix.platform}})
runs-on: ${{matrix.platform}}
Expand Down
4 changes: 2 additions & 2 deletions config/vitest.unit.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default defineConfig({
hookTimeout: 60000,
include: [
`sources/@roots/*/src/**/*.test.{ts,tsx}`,
`sources/@roots/*/test/**/*.{ts,tsx}`,
`sources/@roots/*/tests/**/*.{ts,tsx}`,
`sources/@roots/*/test/**/*.test.{ts,tsx}`,
`sources/@roots/*/tests/**/*.test.{ts,tsx}`,
`tests/unit/**/*.test.ts`,
`tests/reproductions/**/*.test.ts`,
],
Expand Down
3 changes: 1 addition & 2 deletions examples/stylelint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
],
"devDependencies": {
"@roots/bud": "latest",
"@roots/bud-stylelint": "latest",
"@roots/stylelint-config": "latest"
"@roots/bud-stylelint": "latest"
}
}
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"description": "⚡️ Lightning fast frontend build tools combining the best parts of Symfony Encore and Laravel Mix",
"engines": {
"node": "18.12.1",
"node": "18.16.1",
"yarn": "1.22.19",
"npm": "8.19.2"
},
Expand Down Expand Up @@ -61,14 +61,12 @@
"sources/@roots/*/test/**/*",
"sources/@roots/*/src/__fixtures__/*",
"sources/create-bud-app",
"sources/deprecated/bud-terser",
"tests/util/project",
"tests/reproductions/*"
]
},
"volta": {
"node": "18.12.1",
"yarn": "1.22.19",
"npm": "8.19.2"
"node": "18.16.1",
"yarn": "1.22.19"
}
}
27 changes: 27 additions & 0 deletions sources/@repo/test-kit/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,29 @@ interface Entrypoints {
}

class Project {
/**
* Compiled modules keyed by asset name
*/
public assets: Record<string, string> = {}

/**
* entrypoints.json contents
*/
public entrypoints: Entrypoints = {}

/**
* manifest.json contents
*/
public manifest: Record<string, any> = {}

/**
* Class constructor
*/
public constructor(public options: Options) {}

/**
* Build the project
*/
@bind
public async build() {
const build = this.options.buildCommand ?? [
Expand Down Expand Up @@ -65,6 +80,9 @@ class Project {
return this
}

/**
* Get the project directory
*/
public get directory(): string {
return path(
`storage`,
Expand All @@ -73,16 +91,25 @@ class Project {
)
}

/**
* Get an asset by name
*/
@bind
public getAsset(name: string) {
return this.assets[name]
}

/**
* Get an entrypoint by name
*/
@bind
public getEntrypoint(name: string) {
return this.entrypoints[name]
}

/**
* Get the path to a file in the project
*/
@bind
public getPath(...file: Array<string>) {
return join(this.directory, ...file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import {join} from 'node:path'

import {Command, Option} from '@roots/bud-support/clipanion'
import BudCommand from '@roots/bud/cli/commands/bud'
import {dry} from '@roots/bud/cli/decorators/dry'

/**
* Bud stylelint command
*/
@dry
export class BudStylelintCommand extends BudCommand {
/**
* Command paths
* {@link BudCommand.paths}
*/
public static override paths = [
[`lint`, `css`],
Expand All @@ -20,7 +18,7 @@ export class BudStylelintCommand extends BudCommand {
]

/**
* Command usage
* {@link BudCommand.usage}
*/
public static override usage = Command.Usage({
category: `tools`,
Expand All @@ -43,8 +41,18 @@ export class BudStylelintCommand extends BudCommand {
await this.makeBud()
await this.bud.run()

const stylelint = await this.bud.module.getDirectory(`stylelint`)
const bin = join(stylelint, `bin`, `stylelint.js`)
const stylelint = await this.bud.module
.getDirectory(`stylelint`)
.catch(this.catch)

if (!stylelint) {
throw `stylelint can't be resolved. You may need to install it.`
}

let bin = join(stylelint, `bin`, `stylelint.mjs`)
if (!(await this.bud.fs.exists(bin))) {
bin = join(stylelint, `bin`, `stylelint.js`)
}

if (!this.options?.length)
this.options = [this.bud.path(`@src`, `**`, `*.{css,scss,sass}`)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {type Bud} from '@roots/bud'

export default async (bud: Bud) => {
bud.entry(`app`, [`app.js`, `app.css`])

bud.stylelint
.setFailOnError(bud.isProduction)
.setFailOnWarning(false)
.setFix(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@tests/stylelint-command",
"private": true,
"type": "module",
"$schema": "https://bud.js.org/bud.package.json",
"browserslist": [
"extends @roots/browserslist-config"
],
"devDependencies": {
"@roots/bud": "workspace:*",
"@roots/bud-stylelint": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: 'blue';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const target = document.querySelector(`body`)
target.innerHTML = `
<div>
<h1>Hello</h1>
</div>
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: [`@roots/bud-stylelint/config`],
rules: {'no-descending-specificity': null},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["@roots/bud/config/tsconfig.json"],
"compilerOptions": {
"types": ["@roots/bud", "@roots/bud-stylelint"]
},
"files": ["./bud.config.ts"]
}
16 changes: 16 additions & 0 deletions sources/@roots/bud-stylelint/test/command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {describe, expect, it} from 'vitest'
import {execa} from 'execa'

describe(`bud stylelint`, () => {
it('should return 0', async () => {
const result = await execa('yarn', [
'workspace',
'@tests/stylelint-command',
'run',
'bud',
'stylelint',
])

expect(result.exitCode).toBe(0)
})
})
Loading

0 comments on commit 5a760b4

Please sign in to comment.