Skip to content

Commit

Permalink
Start work on stylelint 16
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Feb 3, 2024
1 parent 1178045 commit 7d1b847
Show file tree
Hide file tree
Showing 44 changed files with 166 additions and 587 deletions.
257 changes: 7 additions & 250 deletions packages/crafty-preset-stylelint/build.config.js
Original file line number Diff line number Diff line change
@@ -1,258 +1,15 @@
const fs = require("fs");
const path = require("path");

const { getExternals } = require("../../utils/externals");

const singlePackages = [
"balanced-match",
"color-convert",
"gulp-postcss",
"gulp-rename",
"is-fullwidth-code-point",
"is-plain-object",
"postcss-media-query-parser",
"resolve-from",
"slice-ansi",
"string-width",
"style-search",
"supports-color",
"supports-hyperlinks",
"table",
"css-tree",
"@csstools/selector-specificity",
"mathml-tag-names",
"colord",
"known-css-properties",
"svg-tags",
"has-flag"
];
import { getExternals } from "../../utils/externals.js";

const externals = {
// Provided by other Crafty packages
...getExternals(),

...Object.fromEntries(
singlePackages.map((pkg) => [pkg, `../${pkg}/index.js`])
),

"@ronilaukkarinen/gulp-stylelint": "../ronilaukkarinen-gulp-stylelint/index.js",

"schema-utils": "schema-utils",
postcss: "postcss",
"postcss/package.json": "postcss/package.json",
"/postcss/lib(/.*)/": "postcss/lib$1",
"@babel/code-frame": "@babel/code-frame",

// Provide a simplified package data normalizer
"normalize-package-data": "../../packages/normalize-package-data.js",

// Not used as we pass the configuration directly, can be excluded from the bundle
"postcss-load-config": "../../src/dummy.js",
cosmiconfig: "../../src/dummy.js",
stylelint: "stylelint"
};

const ruleExternals = {
...externals,
"@csstools/media-query-list-parser": "../csstools/media-query-list-parser.js",
"@csstools/css-tokenizer": "../csstools/css-tokenizer.js",
"@csstools/css-parser-algorithms": "../csstools/css-parser-algorithms.js",
}

const stylelintSource = [];

stylelintSource.push({
pkg: "stylelint",
name: "stylelint",
entryFile: `dist/stylelint/index.js`,
});

stylelintSource.push({
pkg: "stylelint/bin/stylelint",
name: "stylelintBin",
entryFile: `dist/stylelint/bin.js`,
});

stylelintSource.push({
pkg: "stylelint/lib/reference/atKeywords.js",
name: "libReferenceAtKeywords",
entryFile: `dist/stylelint/reference-atKeywords.js`,
});
ruleExternals["../../reference/atKeywords"] = "./reference-atKeywords.js";

stylelintSource.push({
pkg: "stylelint/lib/reference/functions.js",
name: "libReferenceFunctions",
entryFile: `dist/stylelint/reference-functions.js`,
});
ruleExternals["../../reference/functions"] = "./reference-functions.js";

stylelintSource.push({
pkg: "stylelint/lib/reference/keywords.js",
name: "libReferenceKeywords",
entryFile: `dist/stylelint/reference-keywords.js`,
});
ruleExternals["../../reference/keywords"] = "./reference-keywords.js";

stylelintSource.push({
pkg: "stylelint/lib/reference/mediaFeatures.js",
name: "libReferenceMediaFeatures",
entryFile: `dist/stylelint/reference-mediaFeatures.js`,
});
ruleExternals["../../reference/mediaFeatures"] = "./reference-mediaFeatures.js";

stylelintSource.push({
pkg: "stylelint/lib/reference/properties.js",
name: "libReferenceProperties",
entryFile: `dist/stylelint/reference-properties.js`,
});
ruleExternals["../../reference/properties"] = "./reference-properties.js";

stylelintSource.push({
pkg: "stylelint/lib/reference/selectors.js",
name: "libReferenceSelectors",
entryFile: `dist/stylelint/reference-selectors.js`,
});
ruleExternals["../../reference/selectors"] = "./reference-selectors.js";

stylelintSource.push({
pkg: "stylelint/lib/reference/units.js",
name: "libReferenceUnits",
entryFile: `dist/stylelint/reference-units.js`,
});
ruleExternals["../../reference/units"] = "./reference-units.js";

// Extract all formatters
// ----------------------
const formatters = fs
.readdirSync(
path.dirname(require.resolve("stylelint/lib/formatters/index.js"))
)
.filter((file) => file != "index.js")
.map((file) => {
ruleExternals[`./${file.replace(".js", "")}`] = `./${file}`;

return (builder) => builder(`stylelint-formatters-${file.replace(".js", "")}`)
.source(
path.relative(
process.cwd(),
require.resolve(`stylelint/lib/formatters/${file}`)
)
)
.destination(`dist/stylelint/${file}`)
.options({
sourceMap: false,
externals: ruleExternals,
});
}
);

// Extract linting rules and utilities
// -----------------------------------

const stylelintRules = fs
.readdirSync(path.dirname(require.resolve("stylelint/lib/rules/index.js")))
.filter((file) => file != "index.js");

const rules = stylelintRules
.map((file) => {
// Utilities that are used by many rules
if (file.includes(".js")) {
ruleExternals[`../${file.replace(".js", "")}`] = `./rule-util-${file}`;
//ruleExternals[`./${file.replace(".js", "")}`] = `./rule-util-${file}`;
//ruleExternals[`stylelint/lib/rules/${file}`] = `./${file}`;

const functionName = file.replace(".js", "").replace(/-/g, "_");
stylelintSource.push({
pkg: `stylelint/lib/rules/${file}`,
name: functionName,
entryFile: `dist/stylelint/rule-util-${file}`,
});

return false;
}

// Actual rules are inside folders
ruleExternals[`./${file}`] = `./${file}`;
return (builder) =>
builder(`stylelint-rules-${file}`)
.source(
path.relative(
process.cwd(),
require.resolve(`stylelint/lib/rules/${file}`)
)
)
.destination(
file.includes(".js")
? `dist/stylelint/${file}`
: `dist/stylelint/${file}.js`
)
.options({
sourceMap: false,
externals: ruleExternals,
});
})
.filter(Boolean);

const stylelintUtils = fs
.readdirSync(
path.dirname(require.resolve("stylelint/lib/utils/arrayEqual.js"))
)
.filter((file) => file.includes(".js"));

stylelintUtils.forEach((file) => {
// Create externals to refer to the util
ruleExternals[`../../../utils/${file.replace(".js", "")}`] = `./util-${file}`;
ruleExternals[`../../utils/${file.replace(".js", "")}`] = `./util-${file}`;
ruleExternals[`../utils/${file.replace(".js", "")}`] = `./util-${file}`;

const functionName = file.replace(".js", "").replace(/-/g, "_");

stylelintSource.push({
pkg: `stylelint/lib/utils/${file}`,
name: functionName,
entryFile: `dist/stylelint/util-${file}`,
});
});

module.exports = [
(builder) =>
builder("csstools")
.packages((pkgBuilder) => {
pkgBuilder
.package("@csstools/media-query-list-parser", "mediaQueryListParser", "dist/csstools/media-query-list-parser.js")
.package("@csstools/css-tokenizer", "cssTokenizer", "dist/csstools/css-tokenizer.js")
.package("@csstools/css-parser-algorithms", "cssParserAlgorithms", "dist/csstools/css-parser-algorithms.js")

})
.destination(`dist/csstools/index.js`)
.externals(externals),
(builder) =>
builder("stylelint")
.packages((pkgBuilder) => {
stylelintSource.forEach((entry) => {
pkgBuilder.package(entry.pkg, entry.name, entry.entryFile);
});
})
.destination(`dist/stylelint/stylelint.js`)
.externals(ruleExternals),

(builder) => {
const newExternals = { ...externals };
delete newExternals["@ronilaukkarinen/gulp-stylelint"];

return builder("@ronilaukkarinen/gulp-stylelint")
export default [
(builder) => builder("@ronilaukkarinen/gulp-stylelint")
.rspack()
.esm()
.package()
.externals({ ...newExternals, stylelint: "../stylelint/index.js" });
},
...singlePackages.map((pkg) => {
const newExternals = { ...externals };
delete newExternals[pkg];

return (builder) =>
builder(pkg)
.package()
.externals(newExternals);
}),
...formatters,
...rules
.externals(externals)
];
7 changes: 4 additions & 3 deletions packages/crafty-preset-stylelint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"access": "public"
},
"main": "src/index.js",
"type": "module",
"scripts": {
"lint": "node ../crafty-preset-eslint/src/commands/jsLint.js --preset recommended --preset node src",
"build": "node ../../utils/build.mjs"
Expand All @@ -20,13 +21,13 @@
"@swissquote/crafty-preset-prettier": "1.24.0",
"@swissquote/stylelint-config-swissquote": "1.24.0",
"postcss": "8.4.33",
"postcss-scss": "4.0.9"
"postcss-scss": "4.0.9",
"stylelint": "16.2.1"
},
"devDependencies": {
"@ronilaukkarinen/gulp-stylelint": "14.1.2",
"is-plain-object": "5.0.0",
"resolve-from": "5.0.0",
"stylelint": "15.10.0"
"resolve-from": "5.0.0"
},
"engines": {
"node": ">=18"
Expand Down
1 change: 0 additions & 1 deletion packages/crafty-preset-stylelint/packages/resolve-from.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/crafty-preset-stylelint/packages/stylelint-bin.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/crafty-preset-stylelint/packages/stylelint.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/crafty-preset-stylelint/src/commands/lint_css.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ if (process.argv.indexOf("--custom-syntax") === -1) {
process.argv.push(require.resolve("postcss-scss"));
}

require("../../packages/stylelint-bin");
require("stylelint/bin/stylelint.mjs");
14 changes: 0 additions & 14 deletions packages/crafty-preset-stylelint/src/dummy.js

This file was deleted.

Loading

0 comments on commit 7d1b847

Please sign in to comment.