sku 15.7.1 → 15.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # sku
2
2
 
3
+ ## 15.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - lint|format: Enforce sorted keys in package.json ([#1480](https://github.com/seek-oss/sku/pull/1480))
8
+
9
+ ESLint will now warn if the keys in package.json are not sorted. Running `sku format` will automatically fix the sort order.
10
+
11
+ If you need to, you can disable this rule by using `dangerouslySetESLintConfig` in your sku config (not recommended):
12
+
13
+ ```ts
14
+ const config = {
15
+ ...,
16
+ dangerouslySetESLintConfig: (esLintConfig) => [
17
+ ...esLintConfig,
18
+ {
19
+ files: ['**/package.json'],
20
+ rules: {
21
+ 'package-json/sort': 'off',
22
+ },
23
+ },
24
+ ],
25
+ }
26
+ ```
27
+
3
28
  ## 15.7.1
4
29
 
5
30
  ### Patch Changes
@@ -0,0 +1,12 @@
1
+ import { jsonProcessor, packageJsonPlugin } from "./plugins/package-json.mjs";
2
+
3
+ //#region src/config/eslint/jsonFiles.ts
4
+ const createJsonFilesConfig = () => [{
5
+ plugins: { "package-json": packageJsonPlugin },
6
+ files: ["**/package.json"],
7
+ rules: { "package-json/sort": "warn" },
8
+ processor: jsonProcessor
9
+ }];
10
+
11
+ //#endregion
12
+ export { createJsonFilesConfig };
@@ -0,0 +1,59 @@
1
+ import path from "node:path";
2
+ import { sortPackageJson } from "sort-package-json";
3
+
4
+ //#region src/config/eslint/plugins/package-json.ts
5
+ const sortRule = {
6
+ meta: {
7
+ docs: { description: "Enforce package.json sorting" },
8
+ fixable: "code",
9
+ schema: [{
10
+ type: "object",
11
+ properties: { sortOrder: {
12
+ type: "array",
13
+ minItems: 0,
14
+ items: { type: "string" }
15
+ } },
16
+ additionalProperties: false
17
+ }]
18
+ },
19
+ create(context) {
20
+ const filename = context.filename;
21
+ if (path.basename(filename) !== "package.json") return {};
22
+ const sourceCode = context.sourceCode;
23
+ const options = context.options ? context.options[0] : void 0;
24
+ return { ExportDefaultDeclaration(node) {
25
+ const { declaration } = node;
26
+ if (declaration.type !== "ObjectExpression") return;
27
+ const packageJsonText = sourceCode.getText(declaration);
28
+ const sortedText = sortPackageJson(packageJsonText, options);
29
+ if (packageJsonText !== sortedText) context.report({
30
+ node,
31
+ message: "package.json is not sorted correctly.",
32
+ fix(fixer) {
33
+ return fixer.replaceText(node, sortedText);
34
+ }
35
+ });
36
+ } };
37
+ }
38
+ };
39
+ /**
40
+ * Processor for JSON files.
41
+ * Simply prefixes the text with `export default` so it can be parsed by eslint as javascript.
42
+ */
43
+ const jsonProcessor = {
44
+ meta: {
45
+ name: "json-processor",
46
+ version: "1.0.0"
47
+ },
48
+ preprocess(text) {
49
+ return [`export default ${text}`];
50
+ },
51
+ postprocess(messages) {
52
+ return messages.flat();
53
+ },
54
+ supportsAutofix: true
55
+ };
56
+ const packageJsonPlugin = { rules: { sort: sortRule } };
57
+
58
+ //#endregion
59
+ export { jsonProcessor, packageJsonPlugin };
@@ -1,6 +1,7 @@
1
1
  import { getSkuContext } from "../context/createSkuContext.mjs";
2
2
  import { createImportOrderConfig } from "./eslint/importOrder.mjs";
3
3
  import { createEslintIgnoresConfig } from "./eslint/ignores.mjs";
4
+ import { createJsonFilesConfig } from "./eslint/jsonFiles.mjs";
4
5
 
5
6
  //#region src/config/eslint/config.ts
6
7
  const createEslintConfig = async ({ configPath } = {}) => {
@@ -13,6 +14,7 @@ const createEslintConfig = async ({ configPath } = {}) => {
13
14
  hasLanguagesConfig: Boolean(languages && languages.length > 0),
14
15
  target: relativeTarget
15
16
  }),
17
+ ...createJsonFilesConfig(),
16
18
  ...eslintConfigSeek,
17
19
  createImportOrderConfig(skuContext),
18
20
  ...eslintIgnore && eslintIgnore.length > 0 ? [{ ignores: [...eslintIgnore] }] : []
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "15.7.1";
2
+ var version = "15.8.0";
3
3
  var package_default = {
4
4
  name: "sku",
5
5
  version,
@@ -153,6 +153,7 @@ var package_default = {
153
153
  "semver": "^7.3.4",
154
154
  "serialize-javascript": "^7.0.2",
155
155
  "serve-handler": "^6.1.3",
156
+ "sort-package-json": "^3.6.0",
156
157
  "svgo-loader": "^4.0.0",
157
158
  "terser-webpack-plugin": "^5.1.4",
158
159
  "typescript": "~5.9.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sku",
3
- "version": "15.7.1",
3
+ "version": "15.8.0",
4
4
  "description": "Front-end development toolkit, powered by Webpack, Babel, Vanilla Extract and Jest",
5
5
  "types": "./dist/index.d.mts",
6
6
  "bin": {
@@ -157,6 +157,7 @@
157
157
  "semver": "^7.3.4",
158
158
  "serialize-javascript": "^7.0.2",
159
159
  "serve-handler": "^6.1.3",
160
+ "sort-package-json": "^3.6.0",
160
161
  "svgo-loader": "^4.0.0",
161
162
  "terser-webpack-plugin": "^5.1.4",
162
163
  "typescript": "~5.9.0",