Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rollup to build the configuration files 🛼 #23

Merged
merged 6 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
// "semi": [1, "always"]
},
"parserOptions": {
"ecmaFeatures": {
"modules": true
},
"ecmaVersion": 2018,
"requireConfigFile": false,
"sourceType": "module"
}
}
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ jobs:
- name: Install Dependencies
run: yarn install --immutable

- name: Lint
run: yarn lint --ignore-patterns '**/*.ts'

- name: Run Tests
run: yarn test --coverage

- name: Run Build
run: yarn build

- name: Lint
run: |
yarn lint --ignore-patterns '**/*.ts'
yarn lint --eslint-use-legacy-config --ignore-patterns '**/*.ts'

- name: Depcheck
run: npx depcheck
2 changes: 1 addition & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "./config/markdownlint.json"
"extends": "./lib/markdownlint.json"
}
42 changes: 40 additions & 2 deletions config/all-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
import buildLegacyConfig from './eslint/build-legacy-config'
import { FILE_PATHS } from './eslint/constants'
import Rules from './eslint/rules'

export default buildLegacyConfig()
export default {
env: {
'jest/globals': true,
},
plugins: [
'eslint-comments',
'inclusive-language',
'n',
'promise',
'sort-destructure-keys',
'sort-exports',
],
rules: {
...Rules.ESLintComments,
...Rules.InclusiveLanguage,
...Rules.N,
...Rules.Promise,
...Rules.SortDestructureKeys,
...Rules.SortExports,
},
overrides: [{
files: FILE_PATHS.TESTS,
plugins: [
'jest',
],
rules: {
...Rules.Jest,
},
}, {
files: FILE_PATHS.TESTS_TYPESCRIPT,
plugins: [
'jest',
],
rules: {
...Rules.JestTypescript,
},
}],
}
49 changes: 47 additions & 2 deletions config/all.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
import buildFlatConfig from './eslint/build-flat-config'
import { FILE_PATHS } from './eslint/constants'
import Plugins from './eslint/plugins'
import Rules from './eslint/rules'

export default buildFlatConfig()
export default [{
plugins: {
'eslint-comments': Plugins.EslintComments,
'inclusive-language': Plugins.InclusiveLanguage,
'n': Plugins.N,
'promise': Plugins.Promise,
'sort-destructure-keys': Plugins.SortDestructureKeys,
'sort-exports': Plugins.SortExports,
},
rules: {
...Rules.ESLintComments,
...Rules.InclusiveLanguage,
...Rules.N,
...Rules.Promise,
...Rules.SortDestructureKeys,
...Rules.SortExports,
},
}, {
files: FILE_PATHS.TESTS,
languageOptions: {
globals: {
'jest/globals': true,
},
},
plugins: {
'jest': Plugins.Jest,
},
rules: {
...Rules.Jest,
},
}, {
files: FILE_PATHS.TESTS_TYPESCRIPT,
languageOptions: {
globals: {
'jest/globals': true,
},
},
plugins: {
'jest': Plugins.Jest,
},
rules: {
...Rules.JestTypescript,
},
}]
50 changes: 0 additions & 50 deletions config/eslint/build-flat-config.ts

This file was deleted.

43 changes: 0 additions & 43 deletions config/eslint/build-legacy-config.ts

This file was deleted.

4 changes: 2 additions & 2 deletions config/stylelint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import postcssScss from 'postcss-scss'

import Rules from './stylelint/rules'

export default () => ({
export default {
extends: [
'stylelint-config-property-sort-order-smacss',
],
Expand Down Expand Up @@ -49,4 +49,4 @@ export default () => ({
...Rules.Stylelint,
...Rules.Stylistic,
},
})
}
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import config from './config/all.ts'
import config from './lib/all'

export default [
...config,
{
rules: {
// semi: [2, 'always'],
// semi: [1, 'always'],
}
}
]
15 changes: 8 additions & 7 deletions jest-config/testData.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { type LintError } from 'markdownlint'
import type { LintError } from 'markdownlint'

export const expectedResultThemes = {
const expectedResultThemes = {
messageTheme: expect.any(Function),
positionTheme: expect.any(Function),
ruleTheme: expect.any(Function),
}

/*
* MARKDOWNLINT
*/

export const markdownlintError: LintError = {
const markdownlintError: LintError = {
errorContext: 'test-error-context',
errorDetail: 'test-error-detail',
errorRange: [1, 2],
Expand All @@ -23,3 +19,8 @@ export const markdownlintError: LintError = {
ruleInformation: 'test-rule-information',
ruleNames: ['MD000', 'test-rule-name'],
}

export {
expectedResultThemes,
markdownlintError,
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"lint-pilot": "index.min.js"
},
"scripts": {
"build": "rimraf lib && mkdir lib && rollup -c && yarn buildConfig",
"buildConfig": "tsx ./scripts/build-config.ts",
"lint": "NODE_ENV=development tsx src/index.js --ignore-dirs lib",
"build": "rimraf lib && mkdir lib && rollup -c",
"lint": "tsx src/index.js --ignore-dirs lib",
"publishLib": "yarn test --coverage && yarn build && cd lib && npm publish",
"test": "jest"
},
Expand Down Expand Up @@ -52,7 +51,6 @@
"@babel/preset-env": "7.25.4",
"@babel/preset-typescript": "7.24.7",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-replace": "5.0.7",
"@rollup/plugin-typescript": "11.1.6",
"@types/eslint": "9.6.1",
"@types/jest": "29.5.12",
Expand All @@ -62,6 +60,7 @@
"jest": "29.7.0",
"rimraf": "5.0.10",
"rollup": "4.21.2",
"rollup-plugin-copy": "3.5.0",
"rollup-plugin-terser": "7.0.2",
"ts-jest": "29.2.5",
"ts-node": "10.9.2",
Expand Down
42 changes: 33 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,52 @@ import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'

import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'
import copy from 'rollup-plugin-copy'
import { terser } from 'rollup-plugin-terser'

const packageJSON = JSON.parse(readFileSync(resolve('./package.json'), 'utf-8'))

export default {
const OUTPUT_DIR = 'lib'

const COPY_FILES = [
'config/markdownlint.json',
'package.json',
'README.md',
]

const createConfig = (configFile, format) => ({
external: Object.keys(packageJSON.dependencies),
input: configFile,
output: {
dir: OUTPUT_DIR,
format,
},
plugins: [
nodeResolve(),
typescript(),
],
})

export default [{
external: Object.keys(packageJSON.dependencies),
input: 'src/index.ts',
output: {
file: 'lib/index.min.js',
file: `${OUTPUT_DIR}/index.min.js`,
format: 'es',
},
plugins: [
nodeResolve({
preferBuiltins: true,
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true,
}),
terser(),
typescript(),
terser(),
copy({
targets: COPY_FILES.map(file => ({ src: file, dest: OUTPUT_DIR })),
}),
],
}
},
createConfig('config/all-legacy.ts', 'cjs'),
createConfig('config/all.ts', 'es'),
createConfig('config/stylelint.config.js', 'cjs'),
]
Loading
Loading